[antlr-interest] Problem with AST rewrite and variable
Jim Idle
jimi at temporal-wave.com
Fri Aug 26 09:28:10 PDT 2011
type:
(ARRAY_OF)* typ1=(t1=simpleType|t2=systemType|t3=objectType)
->^(TYPE ^(ARRAY_OFLIST ARRAY_OF*) $t1? $t2? $t3?)
;
Not that :
^(ARRAY_OFLIST ARRAY_OF*)
Is going to need a rule like this in the tree parser""
: ^(ARRAY_OFLIST ARRAY_OF+)
| ARRAY_OFLIST
;
The node for ARRAY_OFLIST is superfluous and I would just use:
type:
(ARRAY_OF)* typ1=(t1=simpleType|t2=systemType|t3=objectType)
->^(TYPE ARRAY_OF* $t1? $t2? $t3?)
;
Jim
> -----Original Message-----
> From: antlr-interest-bounces at antlr.org [mailto:antlr-interest-
> bounces at antlr.org] On Behalf Of Adam Adamski
> Sent: Friday, August 26, 2011 4:40 AM
> To: antlr-interest at antlr.org
> Subject: [antlr-interest] Problem with AST rewrite and variable
>
> Dear all ANTLR users,
>
> I have question about my rewrite rule - what is wrong with it?
>
> type:
> (ARRAY_OF)* typ1=(simpleType|systemType|objectType)
> ->^(TYPE ^(ARRAY_OFLIST ARRAY_OF*) $typ1)
> ;
>
> I get error when I try to check my rules (with eclipse 3.6).
>
> var i,j:integer;
>
> Console spits out this:
>
> Exception in thread "main" java.lang.reflect.InvocationTargetException
> at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
> at
> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.ja
> va:57)
> at
> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccesso
> rImpl.java:43)
> at java.lang.reflect.Method.invoke(Method.java:616)
> at
> org.deved.antlride.runtime.LaunchParser.invokeRule(LaunchParser.java:20
> 2)
> at
> org.deved.antlride.runtime.LaunchParser.launch(LaunchParser.java:130)
> at
> org.deved.antlride.runtime.LaunchParser.main(LaunchParser.java:228)
>
> Caused by: org.antlr.runtime.tree.RewriteEmptyStreamException: token
> typ1
> at
> org.antlr.runtime.tree.RewriteRuleElementStream._next(RewriteRuleElemen
> tStream.java:157)
> at
> org.antlr.runtime.tree.RewriteRuleTokenStream.nextNode(RewriteRuleToken
> Stream.java:58)
> at Loglan82iParser.type(Loglan82iParser.java:14261)
> at Loglan82iParser.varDecl(Loglan82iParser.java:1464)
> at Loglan82iParser.varDecList(Loglan82iParser.java:1136)
> at Loglan82iParser.declaration(Loglan82iParser.java:892)
> at Loglan82iParser.declarations(Loglan82iParser.java:656)
> at Loglan82iParser.program(Loglan82iParser.java:461)
> ... 7 more
>
> Is it a mistake to use variable like I used? I mean:
>
> rule:
> IDN typ=(type1|type2|typ3)
> ;
>
> My final question: is it wrong to use same var name for many rules ? I
> used variable 'typ' in 4 rules. (I don't think It cause the problem,
> but I'm not sure) Ps. I'm using Eclipse (3.6.2) as my IDE and Antlr
> v3.3
>
> Thank you in advance.
> Adam.
>
> List: http://www.antlr.org/mailman/listinfo/antlr-interest
> Unsubscribe: http://www.antlr.org/mailman/options/antlr-interest/your-
> email-address
More information about the antlr-interest
mailing list