def main(): lexer = adalex.make_lexer() tokens = adalex.tokens parser = adaparse.make_parser() fpath = sys.argv[1] #input file path global filepath filepath = fpath program = parser.parse(open(fpath).read()) cwd = os.getcwd() #gettign the current working directory slash, dot = fpath.rfind('/'), fpath.rfind('.') gfilename = fpath[slash+1:dot] # getting the input canonical file name stripping of the rest # Check the program typechecker = typecheck.typecheck() initialize_types(typechecker) env = typechecker.check_goal_symbol(program) if typechecker.get_error_count() > 0: print "Fix the type errors and compile again" sys.exit(0) # If no errors occurred, generate code code = generate_code(program) gen_file = cwd + "/assembly/" + gfilename + ".asm" #forming the output file name try: fd = open(gen_file, "w") fd.write(code) fd.flush() fd.close() except IOError: print "folder cannot be created" print "Done" # Emit the code sequence JumpGenerator().visit(code)
def main(): global DEBUG if(len(sys.argv) > 2): DEBUG = 1 fileName = sys.argv[1] f = open(fileName, 'r') lexer = adalex.make_lexer() tokens = adalex.tokens parser = adaparse.make_parser() tree = parser.parse(f.read()) typechecker = typecheck() typechecker.check_goal_symbol(tree)
def tracefunc(frame, event, arg, indent=[0]): if event == "call": indent[0] += 2 print "-" * indent[0] + "> call function", frame.f_code.co_name elif event == "return": print "<" + "-" * indent[0], "exit function", frame.f_code.co_name indent[0] -= 2 return tracefunc import sys #sys.settrace(tracefunc) def main(): global DEBUG if(len(sys.argv) > 2): DEBUG = 1 fileName = sys.argv[1] f = open(fileName, 'r') lexer = adalex.make_lexer() tokens = adalex.tokens parser = adaparse.make_parser() tree = parser.parse(f.read()) typechecker = typecheck() typechecker.check_goal_symbol(tree) DEBUG = 0 lexer = adalex.make_lexer() tokens = adalex.tokens if __name__ == '__main__': main()