aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormryouse2022-05-13 03:02:47 +0000
committermryouse2022-05-13 03:02:47 +0000
commit0ad764d450d8c477c375c2608eaa479c2106253a (patch)
treee2ecf95a6b4aca0f4f9742162cfb97af7d4849d3
parente23178e83e5c390af6b63540e55b3e79e3df92f9 (diff)
initial commit of file reader
-rw-r--r--neb.py59
1 files changed, 59 insertions, 0 deletions
diff --git a/neb.py b/neb.py
new file mode 100644
index 0000000..5e46049
--- /dev/null
+++ b/neb.py
@@ -0,0 +1,59 @@
+from lexer import lex
+from parser import parse
+from runner import evaluate
+from std import _get_debug
+import sys
+
+
+def main():
+
+ if len(sys.argv) != 2:
+ print("usage: neb <file>")
+ sys.exit(1)
+
+ with open(sys.argv[1], "r") as fil:
+ data = fil.read()
+
+ try:
+ lexed = lex(data, [])
+ '''
+ if _get_debug():
+ acc = " ".join([f"{l}" for l in lexed])
+ print(f" - LEX: {acc}")
+ '''
+ parsed = parse(lexed, [])
+ '''
+ if _get_debug():
+ acc = " ".join([f"{p}" for p in parsed])
+ print(f" - PARSE: {acc}")
+ '''
+ ev = evaluate(parsed, [])
+ except Exception as e:
+ print(f"panic! {e}")
+ '''
+ print("### neb :)(:")
+ print("version: < 0")
+ idx = 1
+ while True:
+ inp = input(f"#{idx}> ")
+ if len(inp.strip()) == 0:
+ continue
+ try:
+ lexed = lex(inp, [])
+ if _get_debug():
+ acc = " ".join([f"{l}" for l in lexed])
+ print(f" - LEX: {acc}")
+ parsed = parse(lexed, [])
+ if _get_debug():
+ acc = " ".join([f"{p}" for p in parsed])
+ print(f" - PARSE: {acc}")
+ ev = evaluate(parsed, [])
+ print(f"=> {ev}")
+ idx += 1
+ except Exception as e:
+ print(f"panic! {e}")
+ '''
+
+
+if __name__ == "__main__":
+ main()