From 0b8f41f417e61f81c15c4495dfbc793dea4ca7a8 Mon Sep 17 00:00:00 2001 From: mryouse Date: Fri, 20 May 2022 02:14:18 +0000 Subject: added (debug) to the repl for noise on-demand --- repl.py | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) (limited to 'repl.py') diff --git a/repl.py b/repl.py index 831d57d..2846d33 100644 --- a/repl.py +++ b/repl.py @@ -2,28 +2,34 @@ from lexer import lex from parser import parse from interpreter import interpret -def _get_debug(): - return True +prev_lexed = None +prev_parsed = None def main(): print("### neb :)(:") print("version: < 0") idx = 1 + prev_idx = 0 while True: inp = input(f"#{idx}> ") if len(inp.strip()) == 0: continue try: + if inp.strip() == "(debug)": + if prev_lexed is not None: + acc = " ".join([f"{l}" for l in prev_lexed]) + print(f" - LEX: {acc}") + if prev_parsed is not None: + acc = " ".join([f"{p}" for p in prev_parsed]) + print(f" - PARSE: {acc}") + continue lexed = lex(inp) - if _get_debug(): - acc = " ".join([f"{l}" for l in lexed]) - print(f" - LEX: {acc}") + prev_lexed = lexed parsed = parse(lexed) - if _get_debug(): - acc = " ".join([f"{p}" for p in parsed]) - print(f" - PARSE: {acc}") + prev_parsed = parsed inter = interpret(parsed) print(f"=> {inter}") + prev_idx = idx idx += 1 except Exception as e: print(f"panic! {e}") -- cgit v1.2.3