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 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