comparison python/pyyacc.py @ 340:c7cc54c0dfdf devel

Test featurebranch
author Windel Bouwman
date Sun, 23 Feb 2014 16:24:01 +0100
parents 8d07a4254f04
children 4d204f6f7d4e
comparison
equal deleted inserted replaced
339:6ee17c4dd6b8 340:c7cc54c0dfdf
199 for production in self.productions: 199 for production in self.productions:
200 for symbol in production.symbols: 200 for symbol in production.symbols:
201 if symbol not in self.Symbols: 201 if symbol not in self.Symbols:
202 raise ParserGenerationException('Symbol {0} undefined'.format(symbol)) 202 raise ParserGenerationException('Symbol {0} undefined'.format(symbol))
203 203
204 def genParser(self): 204 def generate_parser(self):
205 """ Generates a parser from the grammar (using a caching algorithm) """ 205 """ Generates a parser from the grammar """
206 action_table, goto_table = self.doGenerate() 206 action_table, goto_table = self.generate_tables()
207 p = LRParser(action_table, goto_table, self.start_symbol) 207 p = LRParser(action_table, goto_table, self.start_symbol)
208 p.grammar = self 208 p.grammar = self
209 return p 209 return p
210 210
211 def doGenerate(self): 211 def generate_tables(self):
212 """ Generate parsing tables """
212 if not self.start_symbol: 213 if not self.start_symbol:
213 self.start_symbol = self.productions[0].name 214 self.start_symbol = self.productions[0].name
214 self.checkSymbols() 215 self.checkSymbols()
215 action_table = {} 216 action_table = {}
216 goto_table = {} 217 goto_table = {}