def setup_regen(debug = 1, outputdir='.'): global parser # Remove the old parse table parsetabfile = os.path.join(os.path.abspath(outputdir),'parsetab.py') try: os.remove(parsetabfile) except: pass parser = yacc.yacc(debug=debug, optimize=1, tabmodule='parsetab', write_tables=1, outputdir=os.path.abspath(outputdir)) return parser
def getParser(start_line_no): '''Create the parser for the annotations language''' # set the starting line number global __start_line_no __start_line_no = start_line_no # create the lexer and parser parser = yacc.yacc(method='LALR', debug=0) # return the parser return parser
def __init__(self, lex_optimize=True, lextab='pycparser.lextab', yacc_optimize=True, yacctab='pycparser.yacctab', yacc_debug=False): """ Create a new CParser. Some arguments for controlling the debug/optimization level of the parser are provided. The defaults are tuned for release/performance mode. The simple rules for using them are: *) When tweaking CParser/CLexer, set these to False *) When releasing a stable parser, set to True lex_optimize: Set to False when you're modifying the lexer. Otherwise, changes in the lexer won't be used, if some lextab.py file exists. When releasing with a stable lexer, set to True to save the re-generation of the lexer table on each run. lextab: Points to the lex table that's used for optimized mode. Only if you're modifying the lexer and want some tests to avoid re-generating the table, make this point to a local lex table file (that's been earlier generated with lex_optimize=True) yacc_optimize: Set to False when you're modifying the parser. Otherwise, changes in the parser won't be used, if some parsetab.py file exists. When releasing with a stable parser, set to True to save the re-generation of the parser table on each run. yacctab: Points to the yacc table that's used for optimized mode. Only if you're modifying the parser, make this point to a local yacc table file yacc_debug: Generate a parser.out file that explains how yacc built the parsing table from the grammar. """ self.clex = CLexer(error_func=self._lex_error_func, type_lookup_func=self._lex_type_lookup_func) self.clex.build(optimize=lex_optimize, lextab=lextab) self.tokens = self.clex.tokens rules_with_opt = [ 'abstract_declarator', 'assignment_expression', 'declaration_list', 'declaration_specifiers', 'designation', 'expression', 'identifier_list', 'init_declarator_list', 'parameter_type_list', 'specifier_qualifier_list', 'block_item_list', 'type_qualifier_list', 'struct_declarator_list' ] for rule in rules_with_opt: self._create_opt_rule(rule) self.cparser = yacc.yacc(module=self, start='translation_unit', debug=yacc_debug, optimize=yacc_optimize, tabmodule=yacctab) # Stack of scopes for keeping track of typedefs. _scope_stack[-1] is # the current (topmost) scope. # self._scope_stack = [set()]
def setup(debug = 0, outputdir='.'): global parser parser = yacc.yacc(debug = debug, optimize=1, write_tables=0) return parser
def __init__(self, lex_optimize=False, lexer=MLexer, lextab='lextab', yacc_optimize=False, yacc_debug=True, yacctab='yacctab', taboutputdir='', printToStderr=True): """ Create a new MParser. Some arguments for controlling the debug/optimization level of the parser are provided. The defaults are tuned for release/performance mode. The simple rules for using them are: *) When tweaking MParser/MLexer, set these to False *) When releasing a stable parser, set to True lex_optimize: Set to False when you're modifying the lexer. Otherwise, changes in the lexer won't be used, if some lextab.py file exists. When releasing with a stable lexer, set to True to save the re-generation of the lexer table on each run. lexer: Set this parameter to define the lexer to use if you're not using the default MLexer. lextab: Points to the lex table that's used for optimized mode. Only if you're modifying the lexer and want some tests to avoid re-generating the table, make this point to a local lex table file (that's been earlier generated with lex_optimize=True) yacc_optimize: Set to False when you're modifying the parser. Otherwise, changes in the parser won't be used, if some parsetab.py file exists. When releasing with a stable parser, set to True to save the re-generation of the parser table on each run. yacctab: Points to the yacc table that's used for optimized mode. Only if you're modifying the parser, make this point to a local yacc table file yacc_debug: Generate a parser.out file that explains how yacc built the parsing table from the grammar. taboutputdir: Set this parameter to control the location of generated lextab and yacctab files. """ self.mlex = lexer(error_func=self._lex_error_func, on_lbrace_func=self._lex_on_lbrace_func, on_rbrace_func=self._lex_on_rbrace_func, type_lookup_func=self._lex_type_lookup_func) self.mlex.build(optimize=lex_optimize, lextab=lextab, outputdir=taboutputdir, printToStderr=printToStderr) self.tokens = self.mlex.tokens self.mparser = yacc.yacc(module=self, start="translation_unit_or_empty", tabmodule=yacctab, debug=yacc_debug, optimize=yacc_optimize, outputdir=taboutputdir) self.errorlog = [] self.parser_errors = [] self.debug = yacc_debug # ================================================================= # Get the token map self.baseTypes = {} # this is a simplistic symbol table, a dictionary with # keys: function names # values: dictionary of variable names and types (and intent for parameters) self.matrix_language_vars = {} self.matrix_language_scalar_name_re = re.compile(r'[a-n]\w*') self.matrix_language_typeinference = True
def __init__( self, lex_optimize=True, lextab='pycparser.lextab', yacc_optimize=True, yacctab='pycparser.yacctab', yacc_debug=False): """ Create a new CParser. Some arguments for controlling the debug/optimization level of the parser are provided. The defaults are tuned for release/performance mode. The simple rules for using them are: *) When tweaking CParser/CLexer, set these to False *) When releasing a stable parser, set to True lex_optimize: Set to False when you're modifying the lexer. Otherwise, changes in the lexer won't be used, if some lextab.py file exists. When releasing with a stable lexer, set to True to save the re-generation of the lexer table on each run. lextab: Points to the lex table that's used for optimized mode. Only if you're modifying the lexer and want some tests to avoid re-generating the table, make this point to a local lex table file (that's been earlier generated with lex_optimize=True) yacc_optimize: Set to False when you're modifying the parser. Otherwise, changes in the parser won't be used, if some parsetab.py file exists. When releasing with a stable parser, set to True to save the re-generation of the parser table on each run. yacctab: Points to the yacc table that's used for optimized mode. Only if you're modifying the parser, make this point to a local yacc table file yacc_debug: Generate a parser.out file that explains how yacc built the parsing table from the grammar. """ self.clex = CLexer( error_func=self._lex_error_func, type_lookup_func=self._lex_type_lookup_func) self.clex.build( optimize=lex_optimize, lextab=lextab) self.tokens = self.clex.tokens rules_with_opt = [ 'abstract_declarator', 'assignment_expression', 'declaration_list', 'declaration_specifiers', 'designation', 'expression', 'identifier_list', 'init_declarator_list', 'parameter_type_list', 'specifier_qualifier_list', 'block_item_list', 'type_qualifier_list', 'struct_declarator_list' ] for rule in rules_with_opt: self._create_opt_rule(rule) self.cparser = yacc.yacc( module=self, start='translation_unit', debug=yacc_debug, optimize=yacc_optimize, tabmodule=yacctab) # Stack of scopes for keeping track of typedefs. _scope_stack[-1] is # the current (topmost) scope. # self._scope_stack = [set()]