comparison python/yacc.py @ 323:e9fe6988497c

Used burg for generating expressions
author Windel Bouwman
date Thu, 30 Jan 2014 19:03:24 +0100
parents 44f336460c2a
children 6f4753202b9a
comparison
equal deleted inserted replaced
322:44f336460c2a 323:e9fe6988497c
39 import re 39 import re
40 import sys 40 import sys
41 import datetime 41 import datetime
42 import types 42 import types
43 import io 43 import io
44 import logging
44 from pyyacc import Grammar, print_grammar 45 from pyyacc import Grammar, print_grammar
45 46
46 47
47 class XaccLexer: 48 class XaccLexer:
48 def __init__(self): 49 def __init__(self):
199 200
200 201
201 class XaccGenerator: 202 class XaccGenerator:
202 """ Generator that writes generated parser to file """ 203 """ Generator that writes generated parser to file """
203 def __init__(self): 204 def __init__(self):
204 pass 205 self.logger = logging.getLogger('yacc')
205 206
206 def generate(self, grammar, headers, output_file): 207 def generate(self, grammar, headers, output_file):
207 self.output_file = output_file 208 self.output_file = output_file
208 self.grammar = grammar 209 self.grammar = grammar
209 self.headers = headers 210 self.headers = headers
211 self.logger.info('Generating parser for grammar {}'.format(grammar))
210 self.action_table, self.goto_table = grammar.doGenerate() 212 self.action_table, self.goto_table = grammar.doGenerate()
211 self.generate_python_script() 213 self.generate_python_script()
212 214
213 def print(self, *args): 215 def print(self, *args):
214 """ Print helper function that prints to output file """ 216 """ Print helper function that prints to output file """