def interp(input_stream): # initialize the state object state.initialize() # build the AST parser.parse(input_stream, lexer=lexer) # walk the AST walk(state.AST)
def interp(input_stream, dump=False): try: state.initialize() parser.parse(input_stream, lexer=lexer) if dump: dumpast(state.ast) else: walk(state.ast) except Exception as e: print("error: " + str(e)) return None
def pp(input_stream): try: state.initialize() init_indent_level() ast = parse(input_stream) pp1_walk(ast) code = pp2_walk(ast) print(code) except Exception as e: print("error: " + str(e))
def ppjh(input_stream=None): # if no input stream was given read from stdin if not input_stream: input_stream = stdin.read() # initialize the state object and indent level state.initialize() init_indent_level() # build the AST parser.parse(input_stream, lexer=lexer) # walk the AST pp1_walk(state.AST, 0)
def pp(input_stream = None): # if no input stream was given read from stdin if not input_stream: input_stream = stdin.read() # initialize the state object and indent level state.initialize() init_indent_level() # build the AST parser.parse(input_stream, lexer=lexer) # walk the AST pp1_walk(state.AST) code = pp2_walk(state.AST) # output the pretty printed code print(code)
def cc(input_stream, opt=False): # initialize the state object state.initialize() # build the AST parser.parse(input_stream, lexer=lexer) # run the constant fold optimizer if opt: state.AST = fold(state.AST) # generate the list of instruction tuples instr_stream = codegen(state.AST) # run the peephole optimizer if opt: peephole_opt(instr_stream) # output the instruction stream bytecode = output(instr_stream) return bytecode