dumb repl
This commit is contained in:
3
main.py
3
main.py
@ -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
16
repl.py
Normal 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()
|
||||||
Binary file not shown.
@ -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*
|
||||||
|
|||||||
Reference in New Issue
Block a user