▲ | ogogmad 4 days ago | |
Have people heard of the following top-down parsing algorithm for mathematical expressions:
It's easy to speed up step 2 by keeping a table of all the operators in an expression, sorted by their precedence levels. For this table to work properly, the positions of all the tokens must never change. | ||
▲ | da-bacon 4 days ago | parent [-] | |
For 2, I don’t think you can break ties however you like because this would give you random left or right associativity https://en.m.wikipedia.org/wiki/Operator_associativity For example 2-4-7 would be either (2-4)-7 or 2-(4-7), depending on how you broke the tie. |