dumb repl

This commit is contained in:
2022-12-03 01:58:45 +01:00
parent ce78d96a9c
commit 5296396107
4 changed files with 18 additions and 3 deletions

View File

@ -34,7 +34,6 @@ if __name__ == "__main__":
} }
for expression in expressions: for expression in expressions:
try: try:
print(f"[green]== Parsing: [yellow]{expression}[/yellow] ==[/green]")
parse_expression(expression) parse_expression(expression)
except Exception as e: except Exception as e:
print(f"[red]Failed parsing {expression}[/red]: {e}") print(f"[red]Failed on {expression}[/red]: {str(e)[0:40]}...")

16
repl.py Normal file
View File

@ -0,0 +1,16 @@
from ziffers import *
from rich import print
EXIT_CONDITION = ('exit', 'quit', '')
if __name__ == "__main__":
print(f"[purple]== ZIFFERS REPL ==[/purple]")
while True:
expr = input('> ')
if expr not in EXIT_CONDITION:
try:
parse_expression(expr)
except Exception as e:
print(f"[red]Failed:[/red] {e}")
else:
exit()

View File

@ -1,5 +1,5 @@
ebnf = r""" ebnf = r"""
expr = (number ws?)* expr = (number ws?)+
number = factor additive* number = factor additive*
additive = ("+"/"-") factor additive = ("+"/"-") factor
factor = primary multiplicative* factor = primary multiplicative*