def __init__(self, toklist): self.headsym = symbol.Env() self.cursym = None self.tokens = toklist
def initSymbolTable(self, symtab=None): if symtab == None: self.symtab = sym.Env() else: self.symtab = symtab
# Build the lexer import ply.lex as lex lex.lex() # Parsing rules precedence = ( ('left', '+', '-'), ('left', '*', '/'), ('right', 'UMINUS'), ) # Initialize symbol table symtab = symbol.Env() def p_statement_assign(p): 'statement : ID "=" expression SEMICOLON' # names[p[1]] = p[3] symtab.update(p[1], p[3]) def p_statement_declr_assign(p): 'statement : declaration ID "=" expression SEMICOLON' # names[p[2]] = p[4] symtab.put(p[2], p[1], p[4]) def p_statement_cout(p):
def pushScope(self, symtab=None): if symtab == None: new_symtab = sym.Env() else: new_symtab = copy.deepcopy(symtab) # XXX This looks dangerous... self.symstack.append(new_symtab)
def __init__(self, toklist): self.headsym = symbol.Env() self.cursym = None self.tokens = toklist self.ast = None # this member is set to the root of the AST after parsing