That's pretty nice! I actually got around with just setting a var pLayer to 0. Incrementing it for every open parenthese and decrementing it for every closing parenthese. Then just applied a bias of pLayer*3 to the operator precedence. Would this run in faster time?
How would I manage to get nested parentheses to work
Good question! First, we define the BP of ")" to be a low number that will always be guaranteed to stop the current parse-run. For example:
Next, we define the NUD of "(" to read the next expression, and then eat the closing ")":
For a fully working example, I have implemented this in my JavaScript calculator expression evaluator:
github.com/jrop/pratt-calculator/b...
That's pretty nice! I actually got around with just setting a var pLayer to 0. Incrementing it for every open parenthese and decrementing it for every closing parenthese. Then just applied a bias of pLayer*3 to the operator precedence. Would this run in faster time?
It's hard to say without running some performance benchmarks.