[antlr-interest] Tree grammar: How to handle rule arguments

Stephanie Balzer stephanie.balzer at gmail.com
Fri Oct 15 16:16:56 PDT 2010


Hi Jim,

On Oct 15, 2010, at 7:52 PM, "Jim Idle" <jimi at temporal-wave.com> wrote:

> 
> 
>> -----Original Message-----
>> From: antlr-interest-bounces at antlr.org [mailto:antlr-interest-
>> bounces at antlr.org] On Behalf Of Stephanie
>> Sent: Friday, October 15, 2010 8:05 AM
>> To: antlr-interest at antlr.org
>> Cc: balzers at inf.ethz.ch
>> Subject: [antlr-interest] Tree grammar: How to handle rule arguments
>> 
>> Hello,
>> 
>> I have implemented a parser grammar as well as a tree parser for a
>> little Java-like language. I have encounter difficulties with the
>> following productions
>> 
>> 
>> 
>> identList[Object varType]
>> 
>> : id=Identifier ( ',' Identifier )*
>> 
>> -> ^( VarDecl[$id, "VarDecl"] { $varType } Identifier )+
>> 
> 
> What does Identifier refer to here in your rewrite? It is just the last
> variable that is parsed. When you are looking in Works, you are probably
> looking at the parse tree and not the AST. Why are you trying to rewrite the
> first token to an Imaginary?
> 
> What you want is:
> 
> : id+=Identifier (',' id+=Identifier)*
> 
>  ->^(VarDecl {$varType} $id)+

No, I was looking at the AST in ANTLRWorks and the AST was produced as described. I see that I should have named the starred occurrence of Identifier as well. What is the meaning of id+= above?


> Then reflect that in your tree parser. I have never quite seen the reason
> behind eliding the fact that multiple declarations were made on the same
> type, but if that is what you want, then you need to do it as above.

OK, thanks a lot.

Stephanie
> 
> Jim
> 
> 
> 
> 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