News for hackers. Stuff that matters.
Re:A Handwritten Math Parser in 100 lines of Python by tgb on Thursday September 17, 2020 @09:38AM (#24504435)
This is pretty clever. There's a video by Jonathan Blow, creator of Braid and currently making a programming language called Jai, that talks about parsing expressions with order of operations. He gives an simple approach that apparently was discovered recently (though he didn't remember the paper name) that does this in a single pass and hardly any more complicated than what you wrote. You can see it here [1]. He also trashes on using yacc/bison before that and on most academic parsing theory.

[1] https://www.youtube.com/watch?v=MnctEW1oL-E&t=4578s

Re:A Handwritten Math Parser in 100 lines of Python by westurner on Thursday September 17, 2020 @10:13AM (#24504857)
Reverse Polish notation (RPN) > Converting from infix notation https://en.wikipedia.org/wiki/Reverse_Polish_notation#Conver... > Shunting-yard algorithm https://en.wikipedia.org/wiki/Shunting-yard_algorithm

Infix notation supports parentheses.

Infix notation: 3 + 4 × (2 − 1)

RPN: 3 4 2 1 − × +

Re:A Handwritten Math Parser in 100 lines of Python by mucinoab on Thursday September 17, 2020 @11:43AM (#24506025)
I would like to know the name of that paper if anyone knows.
Re:A Handwritten Math Parser in 100 lines of Python by lioeters on Friday September 18, 2020 @01:10AM (#24513210)
I believe he was talking about Pratt parsing in the video.

Top Down Operator Precedence - Vaughan R. Pratt - https://tdop.github.io/

What he called "priority" is called "binding power" in the paper.

Re:A Handwritten Math Parser in 100 lines of Python by Leszek on Friday September 18, 2020 @04:50AM (#24514474)
I like Jonathan Blow and all, but he should be careful with trashing academic parsing theory if he thinks that Pratt parsing was only discovered "in the last few years".
Re:A Handwritten Math Parser in 100 lines of Python by ynfnehf on Thursday September 17, 2020 @11:52AM (#24506155)
It sounds a lot like Pratt parsing, or at least the way I usually implement it. But I don't what paper he is referring to.