How To Write A Calculator in 70 Python Lines
blog.erezsh.com
How To Write A Calculator in 70 Python Lines
1–10 of 34 posts
Re: How To Write A Calculator in 70 Python Lines
#2 print input()
> 25*4-50
> 50Re: How To Write A Calculator in 70 Python Lines
#3How to Write a Calculator in 1 Python Line print input() > 25*4-50 > 50
>>> print input()
"a"+"b"
abRe: How To Write A Calculator in 70 Python Lines
#4How to Write a Calculator in 1 Python Line print input() > 25*4-50 > 50
Re: How To Write A Calculator in 70 Python Lines
#5How to Write a Calculator in 1 Python Line print input() > 25*4-50 > 50
Re: How To Write A Calculator in 70 Python Lines
#6How to Write a Calculator in 1 Python Line print input() > 25*4-50 > 50
Re: How To Write A Calculator in 70 Python Lines
#7Re: How To Write A Calculator in 70 Python Lines
#8Re: How To Write A Calculator in 70 Python Lines
#9Re: How To Write A Calculator in 70 Python Lines
#10Thanks for the cool post. I am not sure I got the difference between the LL and LR parser. Is what you have above an LR parser?
Also, why did you choose to represent both + and - as "ADD" tokens (and * and / as "MUL") is this to enforce evaluation priority? It would be interesting to see if you can add or ^ as an exponent for this calculator.
Maybe you intended this post strictly as as an educational post, but I think doing parsing right (and from first principles) is a really cool thing to have. Check out how khan-exercises framework uses to parse math expressions into an AST: https://github.com/Khan/khan-exercises/blob/master/utils/mat...