import sly import sys # for ease of reading, the compiler is broken down to multiple files # parser.py for the parser # lexer.py for the lexer # and helper.py for helper functions(such as print_err) from lexer import Lexer from parser import Parser from helper import print_err print_err('Aviv Romem') if len(sys.argv) != 2 or not sys.argv[1].endswith('.ou'): print('USAGE: python cpq.py .ou') exit(1) file = sys.argv[1] output = file[:-3] + '.qud' f = open(file, 'r') text = f.read() f.close() lexer = Lexer() parser = Parser() file = sys.argv[1] parser.parse(lexer.tokenize(text)) if not parser.had_errors: f = open(output, 'w') f.writelines([l + '\n' for l in parser.lines]) f.close()