|more useful options|
Re: Left-associative binary operators in Parse::RecDescentby blokhead (Monsignor)
|on Dec 14, 2004 at 20:01 UTC||Need Help??|
What you want is grammar stratification to give you precedence levels (as opposed to relying on rule matching order as you do now). Put the lowest precedence stuff at the top/outermost level of the grammar, and the highest-precendence stuff at the bottom/innermost level. This is one standard technique for writing grammars.
The basic structure of stratified rules is like this (at least for binary operations):
You will have many layers of this type of thing (one for each level of precedence). You can think of it as the grammar matching the outermost expressions first (which have the lowest precedence, so are conceptually applied last), and then filling in the higher-precedence details later.
Here's an example for your purposes:
This seems to output the kind of thing you want. Notice how paren_expr must refer all the way back to the lowest-level precedence logical_expr!
Postscript: Refer to
Update: Limbic~Region noticed that I had swapped left & right associativity in my examples. Now fixed.