Allowing for Left Associative or Right Associative grammars.
- Left associative: put recursive term before non-recursive term
- Right associative: put recursive term after non-recursive term
Example
Converting a grammar like this into a left associative one
<expn> --> <expn> <add-op> <expn> | <mult-exp>
<mult-exp> --> <mult-exp> <mult-op> <mult-exp> | <pow-exp>
<pow-exp> --> <pow-exp> ^ <pow-exp> | <br-exp>
<pow-exp> --> <pow-exp> ^ <pow-exp> | <br-exp>
<br-exp> --> (<expn>)| <simple>
<simple> --> <identifier> | <literal>
<add-op> --> + | -
<mult-op> --> * | /
We can make it left associative by putting recursive terms before non-recursive ones
<expn> --> <expn> <add-op> <mult-exp> | <mult-exp>
<mult-exp> --> <mult-exp> <mult-op> <pow-exp> | <pow-exp>
<pow-exp> --> <br-exp> ^ <pow-exp> | <br-exp>
<br-exp> --> (<expn>) | <simple>
<simple> --> <identifier> | <literal>
<add-op> --> + | -
<mult-op> --> * | /