[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Operator precedence
Hi,
Has anyone got any quick tips on implementing several layers
of operator precedence?
Yacc has %prec which helps reduce conflicts, but SableCC seems
to expect me to do this in the grammar. The thesis includes an
example where * and / take precedence over + and - so I am
going to see if I can extend this to have more "layers"
( http://www.sable.mcgill.ca/sablecc/thesis.html#PAGE26 ), but
if anyone has any simple advice or pointers they would be
appreciated...
To put this in context: I am writing an interpreter (for "fun")
and it needs to parse something like:
z + 2 < 3 * y + 1 and x > y > z
so I need the following precendence:
* > + > ">" > and (and then there's "not" to add in).
Cheers,
Andrew
PS. x > y > z is interesting when it comes to storing temporary results
by node :-)
PPS. I guess one could implement this later using rotations to arrange
the tree as required, but that seems like a lot of work!