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

Jim Idle jimi at temporal-wave.com
Fri Oct 15 10:52:14 PDT 2010



> -----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)+


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.

Jim
 



More information about the antlr-interest mailing list