[antlr-interest] Rewrite Rules, inline to right side.

Shaun Bogan smbogan at gmail.com
Sun Mar 9 11:24:08 PDT 2008


Could someone tell me how to rewrite the following on the right-hand side:
boolops (firstops^ boolops)*

For example, I would like to know it in the form:
boolops (firstops boolops)* -> ???

The reason I am wondering is because I would like to write out in the
AST that whenever two boolops was found with a firstops, the tree
should look like this:

firstops
|-OPERAND
| |-boolops
|-OPERAND
| |-boolops

(if there are numerous firstops in a row, it should just put the next
one above it.  (Like in the picture below)  It would be fine if the
next firstops was under an OPERAND.   However, it wouldn't have to be.
 (That's easy to figure out in the TreeWalker)

If there is no firstops, then it should not change the tree at all,
and should just go to the boolops rule.  (This is for parsing
expressions, btw)

If you look at the image here:
http://www.uwplatt.edu/~bogans/example.jpg

I would like that rewritten as (I only did the left side, to give an idea):
http://www.uwplatt.edu/~bogans/example2.jpg

You'll see the reason why this would be helpful for me.  My objects
(the items that are returned from a LOOKUP) can have calls or other
actions applied to them.  It is difficult to keep track of which is
applied to the left-hand operand and which are applied to the
right-hand operand.  So I would like the tree to break them apart.
Since the calls happen farther down the tree, simply rewriting above
the boolops should do this, however, I don't know how to rewrite the
above form.  Every time I try, I get a result that is different than
the shape of my tree using the inline style of rewrites.


Thanks for any help,
Shaun


More information about the antlr-interest mailing list