[antlr-interest] Rewrite Problem,
Craig Main
craig at palantir.co.za
Mon Jul 31 09:20:57 PDT 2006
Hi Ter,
I am still battling with this.
I do not understand the rewrite rules.
Given the following simple term, in the standard expression/term/factor
arrangement.
expression : l=term ((op=PLUS|op=MINUS) r=term)*
If I write the expression with the correct tree manipulation operators:
expression : l=term ((op=PLUS^|op=MINUS^) r=term)*
Then I get a complete AST tree when I parse the expression 'a = 90+23-11'
I can match the tree correctly with:
expression:
#(PLUS l=expression r=expression)
| #(MINUS l=expression r=expression)
When I try to do the new stuff (version 3.0)
I leave out the tree manipulation as that produces an error.
I use:
expression : l=term ((op=PLUS|op=MINUS) r=term)*
and then add:
-> ^($op $expression $r)*
And the tree is just a nil node.
I also tried
-> ^($op $l $r)*
And get the same thing.
Am I interpreting the thing wrong?
I have included the grammar in case anyone wants to have a quick squiz.
In its current form, I loose the +23 in 'a = 90+23-11'
Regards
Craig
To: Antlr Interest
Subject: Re: [antlr-interest] Rewrite Problem,
Hi. Try
^($operator $expression $rvalue)*
:)
which means make a new root with left child consisting of old
expression and right child of new operand.
Ter
-------------- next part --------------
A non-text attachment was scrubbed...
Name: rules-3.g
Type: application/octet-stream
Size: 746 bytes
Desc: not available
Url : http://www.antlr.org/pipermail/antlr-interest/attachments/20060731/d698938b/rules-3-0001.obj
More information about the antlr-interest
mailing list