Example #1
0
 def _build_first_seq(self, first_set, seq):
     """Fill `first_set` with the current FIRST set of the string of
     symbols `seq`. Returns True if `first_set` is changed and False
     otherwise."""
     change = False
     for symbol in seq:
         for fst in self._non_nullable_head(symbol):
             if set_add_change(first_set, fst):
                 change = True
         if not self._is_nullable(symbol):
             break
     else:
         if set_add_change(first_set, ''):
             change = True
     return change
Example #2
0
 def _build_follow_seq(self, nonterminal, follow_set, seq):
     """Fill `follow_set` with the current FOLLOW set of the string of
     symbols `seq`. Returns True if `follow_set` is changed and False
     otherwise."""
     change = False
     first_seq = self.first(seq)
     for symb in first_seq:
         if symb == '':
             continue
         if set_add_change(follow_set, symb):
             change = True
     if '' in first_seq:
         for symb in self.follow(nonterminal):
             if set_add_change(follow_set, symb):
                 change = True
     return change