def main(): global result args = args_.manage_arguments() input_location = args.file_location[0] output_location = input_location.partition('.')[0] output_filename = output_location.split('/')[-1] # When lexing, ignore all comments and whitespace lex_ula.t_ignore_WHITESPACE = r'\s+' lex_ula.t_ignore_COMMENT = r'\/\*[^(\*\/);]+\*\/|\/\/.*' lex_ula.t_WHITESPACE = r'a^' lex_ula.t_COMMENT = r'a^' if (__name__ == "__main__"): output_location = output_filename + '.err' with open(output_location, 'w') as file_writer: lex_ula.main(file_writer) result = parse_ula.main(file_writer) apply_semantic_analysis(file_writer, result) else: lex_ula.main() result = parse_ula.main() apply_semantic_analysis(None, result)
def main(argv): source_code_file = open(argv, "r") ans = lex_ula.main() if ans != None: print(ans) if ans == None: parse_ula.main() filename = argv[:-3] filename += "err" output = open(filename, "w") if ans != None: output.write(ans) output.close()
# Copyright 2015 [Brian Mc George] import os import sys import ply.yacc as yacc import lex_command_arguments as args_ import lex_ula # When lexing, ignore all comments and whitespace lex_ula.t_ignore_WHITESPACE = r'\s+' lex_ula.t_ignore_COMMENT = r'\/\*[^(\*\/);]+\*\/|\/\/.*' lex_ula.t_WHITESPACE = r'a^' lex_ula.t_COMMENT = r'a^' lex_ula.main() tokens = lex_ula.tokens parser = None error_file_writer = None def p_start(p): '''start : program''' p[0] = ('Start', p[1]) def p_program(p): '''program : program statement | statement''' if(len(p) == 2 and p[1] is not None): p[0] = ('Program', p[1]) elif(len(p) == 3 and p[1] is not None and p[2] is not None):