|
|
|
|
|
by tgv
499 days ago
|
|
I think you're not using the word precedence properly. It seems as if you're trying to explicitly instruct a top-down parser. E.g., the precedence in these two grammars (for simple arithmetic expressions) is identical S -> F | S + F
F -> T | F * T
T -> 0 | 1 | 2 | ...
S -> F | F + S
F -> T | T * F
T -> 0 | 1 | 2 | ...
but one recurses on the left side, and the other on the right. |
|
My mistake, that didn't even occur to me! I only ever use parser combinators so I just read grammars as if they were the code, and vice-versa.
e.g. you could implement the grammar on the upper line as the code on the lower line:
The two grammars you posted both 'look good' just by eyeballing them, neither needs 'fixing' (per the article title). They have identical precedence and identical don't-recurse-infinitely properties.