def main(): pdb.disable() text = open('a16_1.txt', 'r').read() lexer = Lexer(text) #try: # cur_token = lexer.get_next_token() # while cur_token.type != TokenType.EOF: # print(cur_token) # cur_token = lexer.get_next_token() # print(cur_token) #prints EOF token #except LexerError as e: # print(e.msg) try: parser = Parser(lexer) root = parser.parse() except (LexerError, ParserError) as e: print(e.msg) visualast = VisualAST(root) visualast.buildast() pdb.set_trace() try: analyzer = SemanticAnalyzer(root) analyzer.analyze() except SemanticError as e: print(e.msg)
def fn(): x = 1 pdb.disable() set_trace() x = 2 pdb.enable() set_trace() return x
""" Lesson 19 - Nested Procedure Calls """ from collections import namedtuple from enum import Enum from string import whitespace import sys import pdb pdb.disable() class ErrorCode(Enum): ID_NOT_FOUND = 'ID NOT FOUND' UNEXPECTED_TOKEN = 'UNEXPECTED TOKEN' DUPLICATE_ID = 'DUPLICATE ID' NUM_PARAMS = 'UNEQUAL NUMBER OF PARAMS' class Error(Exception): def __init__(self, error_code=None, token=None, msg=None): self.error_code = error_code self.token = token self.msg = msg def __str__(self): return f'{self.__class__.__name__}: {self.error_code}, msg={self.msg}'
""" Hooks into a SIGUSR1 signal from the os to allow an interactive debugger at a certain point. :param sig: the signal we sent in. should be signal.SIGUSR1 :type sig: signal.SIGUSR1 :param frame: The current frame of execution """ d={'_frame':frame} # Allow access to frame object. d.update(frame.f_globals) # Unless shadowed by global d.update(frame.f_locals) try: import rpdb2; rpdb2.start_embedded_debugger('UNIFIED!!!') except: i = code.InteractiveConsole(d) message = "Signal received : entering python shell.\nTraceback:\n" message += ''.join(traceback.format_stack(frame)) i.interact(message) # Hook our signal hook up to listen for the SIGUSR1 signal signal.signal(signal.SIGUSR1, signal_hook) if settings.DEBUG and getattr(settings, 'PDB_DEBUG', True): # If we're debugging and we're allowing PDB, set exception hook sys.excepthook = except_hook elif not settings.DEBUG and hasattr(pdb, 'disable'): # If DEBUG is not set, disable pdb set_trace, if using pdbpp pdb.disable()
def main(): import sys import argparse parser = argparse.ArgumentParser( description='SPI - Simple Pascal Interpreter') #parser.add_argument('inputfile', help='Pascal souce file') parser.add_argument( '--parser', help='Print parser tokens', action='store_true', ) parser.add_argument( '--scope', help='Print scope information', action='store_true', ) parser.add_argument( '--stack', help='Print call stack', action='store_true', ) parser.add_argument( '--ast', help='Print AST', action='store_true', ) parser.add_argument('--all', help='Print all logs', action='store_true') args = parser.parse_args() global _LOG_PARSER, _LOG_SCOPE, _LOG_STACK, _LOG_AST, _LOG_ALL _LOG_PARSER, _LOG_SCOPE, _LOG_STACK, _LOG_AST, _LOG_ALL = (args.parser, args.scope, args.stack, args.ast, args.all) if _LOG_ALL: _LOG_PARSER = _LOG_SCOPE = _LOG_STACK = _LOG_AST = True pdb.disable() text = open('a17_1.txt', 'r').read() try: lexer = Lexer(text) except LexerError as e: print(e.msg) sys.exit() #cur_token = lexer.get_next_token() #print(cur_token) #while cur_token.type != TokenType.EOF: # cur_token = lexer.get_next_token() # print(cur_token) pdb.set_trace() try: parser = Parser(lexer) root = parser.parse() except ParserError as e: print(e.msg) sys.exit() pdb.set_trace() visualast = VisualAST(root) visualast.build_ast() try: semantic_analyzer = SemanticAnalyzer(root) semantic_analyzer.analyze() except SemanticError as e: print(e.msg) sys.exit() try: interpreter = Interpreter(root) interpreter.interpret() except InterpreterError as e: print(e.msg) sys.exit()