def reads_file(self, dir, file): print("Attempting to compile the following file:") print(f"{file}\n") try: f = open(file, "r") data = f.read() f.close() yacc.parse(data, tracking=True) if error_helper.error_cont is 0: print(f"{file} compiles!\n") _, file_name = file.split("/") quad_helper.print_to_file(f"object_code/{file_name}.obj") run_code(quad_helper.queue_quad, memory.constant_values) vmh.print_to_file(f"{dir}/{file_name}.html") else: print(f"{file} does not compile. Please try harder") print(f"Number of errors: {error_helper.error_cont}") error_helper.print_errors() error_helper.reset() quad_helper.reset() parser_helper.reset() memory.reset() vmh.reset() print("--------------------------------------------") except EOFError: print("EOFError")
def aux_tl_file(file_name, expected_number_of_errors): try: f = open(file_name, "r") data = f.read() f.close() yacc.parse(data, tracking=True) number_of_errors = error_helper.error_cont error_helper.reset() quad_helper.reset() parser_helper.reset() return number_of_errors except EOFError: print("EOFError")
def run(self, data): try: yacc.parse(data, tracking=True) if error_helper.error_cont is 0: run_code(quad_helper.queue_quad, memory.constant_values) for result in vmh.queue_results: print(result) else: print(f"Your code doesn't compile. Please try harder \n") print(f"# of Errors: {error_helper.error_cont}\n") error_helper.print_errors() except: error = f"Error. We couldn't compile successfully.\n" print(error)
def test_5_5_pass_param_queue_function(self): file_name = TESTING_PREFIX + "5_5_pass_param_queue_function.tl" expected_errors = 0 expected_params = [5, 3, 1, 2] try: f = open(file_name, "r") data = f.read() f.close() yacc.parse(data, tracking=True) number_of_errors = error_helper.error_cont queue_params = parser_helper.procedure_directory["param_func"][ "queue_params" ] except EOFError: print("EOFError") print(f"\nTESTING: {file_name}\n") self.assertEqual(number_of_errors, expected_errors) self.assertEqual(queue_params, expected_params)
""" files = sys.argv[1:] if len(files) > 0: print("Attempting to compile the following files:") print(f"{files}\n") for file in files: try: # Read the .tl input file that contains trendlit code f = open(file, "r") data = f.read() f.close() try: yacc.parse(data, tracking=True) if error_helper.error_cont is 0: # No errors were found during compilation print(f"{file} compiles!\n") _, file_name = file.split("/") # Generate the obj file with the quadruples generated during compilation quad_helper.print_to_file( f"object_code/{file_name}.obj") # Start execution in the Virtual Machine (send quads and constants) run_code(quad_helper.queue_quad, memory.constant_values) else: # Could not compile successfully print(f"{file} does not compile. Please try harder") # Pretty print all errors collected during compilation print(f"Number of errors: {error_helper.error_cont}")