示例#1
0
 def next_lookup(self, symbol):
     """Returns the next TerminalSymbols produced by the input symbol within this grammar definition"""
     result = []
     if symbol == self.initialsymbol:
         result.append(EndSymbol())
     for production in self.productions:
         if symbol in production.rightside:
             nextindex = production.rightside.index(symbol) + 1
             while nextindex < len(production.rightside):
                 nextsymbol = production.rightside[nextindex]
                 firstlist = self.first_lookup(nextsymbol)
                 cleanfirstlist = Choice(
                     [x for x in firstlist if x != NullSymbol()])
                 result.append(cleanfirstlist)
                 if NullSymbol() not in firstlist:
                     break
             else:
                 result += self.next_lookup(
                     production.leftside[0]
                 )  #reached the end of the rightside
     return result
示例#2
0
 def test_simple(self):
     alphabet = Choice([String('a')])
     base = Choice([String('a')])
     graph = graph_from_alphabet(alphabet, base)
     self.assertEqual(len(graph.node), 2)