def main(): # Load in test code testcode = open("Test/testcode.txt", "r") contents = testcode.read() scan = Scanner() for symbol in contents: Scanner.read_symbol(scan, symbol) print("identifiers:") print(scan.identifiers) print("\n") print("consts:") print(scan.consts) print("________") for line in scan.lineCollection: for token in line: print("type: " + str(token.enum_type) + " id: " + str(token.id), end=' | ') print("") print("________") parser = Parser(Scanner.lineCollection) parsed_block = parser.parse() print("") print("________") print("") Interpreter.consts = scan.consts Interpreter.identifiers = scan.identifiers Interpreter.interpret(parsed_block.statements)
def main(filename): print("----------Parser Debug-------------") tokenizer = Tokenizer(filename) tokenizer.tokenize() lexer = Lexer(tokenizer.getTokens()) lexer.lex() parser = Parser(lexer.getTokens()) parser.parse() print(parser.getTree()) print("\n----------Execution Stack-----------") interpreter = Interpreter(parser.getTree()) interpreter.interpret() print("\n----------Program Output------------") return interpreter.output()
def main(): args = parseArguments() source = FileSource(args['filename']) if args['dump']: dumpAST(source) return Interpreter(source).interpret()
def main(argv): input_stream = FileStream(argv[1]) target_file = sys.argv[2] lexer = like_rubyLexer(input_stream) stream = CommonTokenStream(lexer) parser = like_rubyParser(stream) tree = parser.prog() #print(tree.toStringTree(recog=parser)) visitor = Visitor() visitor.visit(tree) # print(visitor.memory) print("----------------------Programm----------------------") visitor.programm.print_info() print("----------------------Functions----------------------") for func in visitor.programm.functions: func.print_info() interper_programm = Interpreter(visitor.programm, target_file) interper_programm.interper_programm()
def should_fail( tester, string_source, expected_error_code=None, expected_id=None, ): source = StringSource(string_source) with tester.assertRaises(InterpreterError) as e: Interpreter(source).interpret() if expected_error_code is not None: tester.assertEqual(expected_error_code, e.exception.error_code) if expected_id is not None: tester.assertEqual(expected_id, e.exception.id)
def test_something(self): # dumpAST(FileSource('../../examples/perceptron.txt')) Interpreter(FileSource( '../../examples/print_override_test.txt')).interpret().to_py()
import sys from Lexer.Lexer import Lexer from Parser.Parser import Parser from Interpreter.Interpreter import Interpreter from Lexer.LexerHash import LexerHash from Lexer.LexerQueue import LexerQueue Lexer.run(sys.argv) Parser.run() Interpreter.run() for arg in sys.argv: if arg == "-v": print("Tabela de variáveis") LexerHash.shared().verbose() print("\nLista de instruções") LexerQueue.shared().verbose()
def interpret(string_source): source = StringSource(string_source) return Interpreter(source).interpret()