aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormryouse2022-05-20 02:14:18 +0000
committermryouse2022-05-20 02:14:18 +0000
commit0b8f41f417e61f81c15c4495dfbc793dea4ca7a8 (patch)
treee2563401c4cdb976b2540981b40dfde91a7f7335
parent4b0ed7f6b1ddca544a12d0bdb19bd3b503499bd5 (diff)
added (debug) to the repl for noise on-demand
-rw-r--r--repl.py22
1 files changed, 14 insertions, 8 deletions
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}")