Live data from Hacker News

How To Write A Calculator in 70 Python Lines

blog.erezsh.com

1–10 of 34 posts

Re: How To Write A Calculator in 70 Python Lines

#10
Very cool.

Thanks 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...

Post reply on HN