def main(): statistics = Statistics() parser = Parser(statistics, debug) parser.parse() statistics.generate_statistics() statistics.output_statistics()
def compile_file(file_to_compile): with open(file_to_compile) as f: try: lexer = Lexer(''.join(f.readlines()), file_to_compile) lexer.lex_all() parser = Parser(lexer.tokens) ast_root = parser.parse() ast_root.resolve_includes() error_counter.reset() ast_root.resolve_names(Scope(None)) ast_root.resolve_types() ast_root.check_for_entry_point() is_parsing_successful = error_counter.counter == 0 if not is_parsing_successful: printer.error('', f'{error_counter.counter} errors found', header_len=80) return else: printer.success('', f'Compilation successful', header_len=80) code_writer = CodeWriter() ast_root.write_code(code_writer) with FileOutput('instructions.f12b') as output: code_writer.print_instructions(output) with FileOutput('output.f12b') as output: code_writer.dump_code(output) del ast_root vm = VM(code_writer.code) vm.exec() except ValueError as e: print(e) pass
import sqlite3 import os from metadata.block import Block from parse.parser import Parser from metadata.settings import Settings if __name__ == "__main__": if os.path.isfile(Settings.db_file): os.remove(Settings.db_file) os.system(f'sqlite3 {Settings.db_file} < {Settings.sql_file}') with sqlite3.connect(Settings.db_file) as conn, \ open(Settings.txt_file, 'r') as file: block = Block(conn) for line in file: line = line.strip() if line: Parser.parse(line, block) else: block.store() block.clear() conn.commit()