This article states that:
To write a grammar that correctly expresses operator associativity:
- For left associativity, use left recursion.
- For right associativity, use right recursion.
Am I right that left-recursive grammar is the only way to control associativity on the grammar level?
The other way which is mentioned here is Associativity and Precedence Declarations:
%left +
%left *
which as I understand are implemented on the actual parser level implementation.
However, LL parser cannot handle left-recursive grammar. So if I want to implement recursive-descent parser I'll need to somehow work around it in the implementation. Is it correct?
Here what an author implementing recursive-descent parser mentions:
A recursive descent parser can parse grammar that doesn’t contain left-recursion. However, the original ECMAScript grammar contains a bunch of left-recursions that’ll be troublesome for a recursive descent parser. Step one for beginning the parser is to convert the grammar by eliminating left-recursion as I have done so here.
It is interesting to note that the method for eliminating left-recursion also messes with operator associativity, but I’ll deal with it later.