Fixed calc example

This commit is contained in:
Erez Shinan 2017-02-15 10:00:01 +02:00
parent df80933884
commit 63c8e58e42
1 changed files with 9 additions and 3 deletions

View File

@ -4,6 +4,12 @@
from lark import Lark, InlineTransformer from lark import Lark, InlineTransformer
try:
input = raw_input
except NameError:
pass
calc_grammar = """ calc_grammar = """
?start: sum ?start: sum
| NAME "=" sum -> assign_var | NAME "=" sum -> assign_var
@ -47,7 +53,7 @@ calc = calc_parser.parse
def main(): def main():
while True: while True:
try: try:
s = raw_input('> ') s = input('> ')
except EOFError: except EOFError:
break break
print(calc(s)) print(calc(s))
@ -58,6 +64,6 @@ def test():
print(calc("1+a*-3")) print(calc("1+a*-3"))
if __name__ == '__main__': if __name__ == '__main__':
test() # test()
# main() main()