Hi,
I'm trying to rewrite a simple tree where ^(operator op1 op2) -> ^(FUNC
operator op1 op2)
I am having fairly inconsistent behavior when I attempt to do this.

tree grammar MExpr;


options {

  ....

  filter=true;

  rewrite=true;

}


bottomup: mathExpr

 term

: ID

| BOOLEAN | INT | FLOAT | STRING

|   ^(FUNC .);


mathExpr

: ^(m=MINUS x=term) -> ^(FUNC NEGATION $x)

|   ^(t=operator t1=term t2=term) -> ^(FUNC $t $t1 $t2);


operator: PLUS | MINUS | MULTOP;


When defined above I get the following StackTrace:

Exception in thread "main"
org.antlr.runtime.tree.RewriteEmptyStreamException: rule t

at org.antlr.runtime.tree.RewriteRuleElementStream._next(
RewriteRuleElementStream.java:157)

at org.antlr.runtime.tree.RewriteRuleElementStream.nextTree(
RewriteRuleElementStream.java:144)....


I have isolated the reason (I think) to be the code that the "operator" rule
produces...



*            **if** ( (**input**.LA(1)>=**PLUS** && **input**.LA(1)<=**
MULTOP**) ) {*

*                **input**.consume();*


As a result the operator_return has a start at the correct token but a tree
of null which causes this error.

If I switch the mathExpr rule to


|^(PLUS t1=term t2=term) -> ^(FUNC PLUS $t1 $t2);


then everything works fine. Obviously this means I have to specify the
rewrite rule for EVERY operator.

I'm sure I'm missing something basic but I'm unable to figure it out. Any
help is much appreciated.


Another interesting variation is that if I just have


operator: PLUS;


then the toStringTree of the return value goes into an infinite recursion
and blows up.


Thanks,

Adi

List: http://www.antlr.org/mailman/listinfo/antlr-interest
Unsubscribe: 
http://www.antlr.org/mailman/options/antlr-interest/your-email-address

-- 
You received this message because you are subscribed to the Google Groups 
"il-antlr-interest" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/il-antlr-interest?hl=en.

Reply via email to