Exemplo n.º 1
0
 def __init__(self, AST, start='program'):
     GenericASTBuilder.__init__(self, AST, start)
     # list of tokens that should not be flattened by nonterminal()
     self.primaryTypes = {
             'proc_stmt': 1,
             'param_declaration_block': 1,
             'declaration_stmt': 1,
             'declaration_block': 1,
             'var_name': 1,
             'decl_init_list': 1,
             'decl_init_value': 1,
             'decl_array_dims': 1,
             'array_subscript': 1,
             'list_flag': 1,
             'body_block': 1,
             'statement_block': 1,
             'nonnull_stmt': 1,
             'osescape_stmt': 1,
             'assignment_stmt': 1,
             'task_call_stmt': 1,
             'if_stmt': 1,
             'for_stmt': 1,
             'while_stmt': 1,
             'break_stmt': 1,
             'next_stmt': 1,
             'return_stmt': 1,
             'goto_stmt': 1,
             'label_stmt': 1,
             'switch_stmt': 1,
             'case_block': 1,
             'case_stmt_block': 1,
             'case_value': 1,
             'compound_stmt': 1,
             'empty_compound_stmt': 1,
             'task_arglist': 1,
             'comma_arglist': 1,
             'fn_arglist': 1,
             'arg': 1,
             'empty_arg': 1,
             'non_empty_arg': 1,
             'no_arg': 1,
             'param_name': 1,
             'opt_comma': 1,
             'bool_expr': 1,
             }
     self._currentFname = None
Exemplo n.º 2
0
 def nonterminal(self, atype, args):
     #
     # Flatten AST a bit by not making nodes if there's only
     # one child, but retain a few primary structural
     # elements.
     #
     if len(args) == 1 and not atype in self.primaryTypes:
         return args[0]
     return GenericASTBuilder.nonterminal(self, atype, args)
Exemplo n.º 3
0
 def parse(self, tokens, fname=None):
     """ Override this, only so we can add the optional fname arg.
         Delegate all parse logic to parent. """
     self._currentFname = fname
     return GenericASTBuilder.parse(self, tokens)