in reply to Order of Precedence in Parse::RecDescent grammar
P::RD may have other bells & whistles to help with precedence, but this is the only way I can ever remember to do precedence correctly, and it works with any kind of parser (although you may have to factor out left-recursion in right-associative operators).
Update: BTW, you can string together all operations of the same precedence level, which is probably more efficient. I.e, parse (a+b)*c*d*e*(f+g) into a shallow parse tree whose root has 5 children, instead of having a deeper parse tree whose nodes always have 2 children. However, for simplicity/uniformity it's often nice to always know that each node of the parse tree is a simple binary operation.
blokhead
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Order of Precedence in Parse::RecDescent grammar
by suaveant (Parson) on Jun 01, 2005 at 17:12 UTC | |
by blokhead (Monsignor) on Jun 01, 2005 at 18:21 UTC |