git @ Cat's Eye Technologies Tamsin / 90db1e5
*Theoretically* more efficient (but not on the tests, it isn't.) Cat's Eye Technologies 11 years ago
1 changed file(s) with 6 addition(s) and 6 deletion(s). Raw diff Collapse all Expand all
5454 self.program = program
5555 self.scanner = scanner
5656 self.context = Context(listeners=self.listeners)
57 self.prodmap = {}
5758
5859 def __repr__(self):
5960 return "Interpreter(%r, %r, %r)" % (
6667 mod = prodref[1]
6768 name = prodref[2]
6869 if mod == '':
69 productions = []
70 for ast in self.program[2]:
71 if ast[1] == name:
72 productions.append(ast)
73 if not productions:
70 try:
71 return self.prodmap[name]
72 except KeyError:
7473 raise ValueError("No '%s' production defined" % name)
75 return productions
7674 elif mod == '$':
7775 formals = {
7876 'expect': [Variable('X')],
130128 """
131129 self.event('interpret_ast', ast)
132130 if ast[0] == 'PROGRAM':
131 for prod in ast[2]:
132 self.prodmap.setdefault(prod[1], []).append(prod)
133133 mains = self.find_productions(('PRODREF', '', 'main'))
134134 return self.interpret(mains[0])
135135 elif ast[0] == 'PROD':