def main(): type_ = sys.argv[1] quadruples, constants = None, None if type_ == "examples": quadruples, constants = parse(test) else: # Convert diagram to vip code. converted_diagram = convert_diagram(type_=type_) # Generate Object code. quadruples, constants = parse(converted_diagram) if len(sys.argv) > 2: if sys.argv[2] == "1": # Print png diagram and vip converted code. print_diagram(type_) if len(sys.argv) == 4: if sys.argv[3] == "1": # Print quadruples and address table content. print("Quadruples:") for i, q in enumerate(quadruples): print(i, q) print("Constants:") for key, value in constants.items(): print(key, value) print("Virtual Machine output: ") vm = VirtualMachine(quadruples, constants) vm.run()
def p_program(p): '''program : pre_variables functions main | functions main | pre_variables main | main''' generator.export() # debug(generator.printeame()) # debug(functions_directory.printeame()) vm = VirtualMachine(functions_directory) vm.run()
def main(argv): input_stream = FileStream(argv[1]) lexer = CovidLexer(input_stream) stream = CommonTokenStream(lexer) parser = CovidParser(stream) tree = parser.start() if parser.getNumberOfSyntaxErrors() != 0: print("Compilation unsuccessful: Syntax Error(s)") sys.exit() # Create DirFunc using tree walkers dir_func = DirFunc() walker = ParseTreeWalker() walker.walk(dir_func, tree) # Generate list of quads quad_list = QuadrupleList(dir_func) walker = ParseTreeWalker() walker.walk(quad_list, tree) # Instantiate virtual machine virtual_machine = VirtualMachine(dir_func.func_table, quad_list.quad_list, quad_list.cte_address_dir, quad_list.pointer_mem, dir_func.global_address_dir) # Debug flags if len(argv) >= 3: if '-q' in argv: # prints quadruples print(quad_list) if '-d' in argv: # prints dir func print(dir_func) # If no errors and successful compilation, run VM if parser.getNumberOfSyntaxErrors() == 0: print("Successful compilation!") virtual_machine.run()
def main(argv): a = VirtualMachine() a.run(argv[1])