def makeInterpreter(self, text): from spi import Lexer, Parser, SemanticAnalyzer, Interpreter lexer = Lexer(text) parser = Parser(lexer) tree = parser.parse() semantic_analyzer = SemanticAnalyzer() semantic_analyzer.visit(tree) interpreter = Interpreter(tree) interpreter.call_stack = TestCallStack() return interpreter
def interpreter(text): lexer = Lexer(text) try: parser = Parser(lexer) tree = parser.parse() except (LexerError, ParserError) as e: return (None, e.message) semantic_analyzer = SemanticAnalyzer() try: semantic_analyzer.visit(tree) except SemanticError as e: return (None, e.message) interpreter = Interpreter(tree) interpreter.call_stack = TestCallStack() return interpreter