2 ms·
Maybe this example will help? https://github.com/SAP/chevrotain/blob/master/examples/grammars/calculator/calculator_pure_grammar.js https://github.com/SAP/chevr
by bd82 8y ago
Maybe this example will help?
https://github.com/SAP/chevrotain/blob/master/examples/grammars/calculator/calculator_pure_grammar.js https://github.com/SAP/chevrotain/blob/master/examples/gramm...
It is implemented using a parsing library so the lookaheads are automatically performed by the library, but the general pattern is still relevant.
Basically each binary precedence level gets a rule (weakest first) and each of these rules will consume as many operators of the current precedence level as it can.