示例#1
0
 def __init__(self, toklist):
   self.headsym = symbol.Env()
   self.cursym = None
   self.tokens = toklist
示例#2
0
文件: syntax.py 项目: cosc402/project
 def initSymbolTable(self, symtab=None):
     if symtab == None:
         self.symtab = sym.Env()
     else:
         self.symtab = symtab
示例#3
0
文件: inter.py 项目: cosc402/project

# 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):
示例#4
0
文件: syntax.py 项目: cosc402/project
 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)
示例#5
0
 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