[antlr-interest] This should be easy - but I can't figure it out

Stefan Mätje Stefan.Maetje at esd-electronics.com
Thu Nov 17 05:11:50 PST 2011


Am 17.11.2011 02:39:05 schrieb(en) John B. Brodie:
> On 11/16/2011 12:02 AM, Voelkel, Andy wrote:
> > 
:
: 
:
> > array
> >     : ( l='[' (f+=FLOAT)+  ']' -> ^(ARRAY_FLOAT ["FLT ARY",$l] $f+) )
> >     | ( l='[' (s+=STRING)+ ']' -> ^(ARRAY_STRING["STR ARY",$l] $s+) )
> >   ;
> > 
> > [Andy - This causes compiler errors, and I'm really not sure what you are
> getting at.
> 
> compiler errors are odd here, maybe the C# target does not support the [
> ] notation for initializing an imaginary token?

To be specific on this example only: I believe the order of the parameters (in 
[]) in the rewrite section is wrong. First comes the token reference then 
follows the text for the imaginary node.

array
    : ( l='[' (f+=FLOAT)+  ']' -> ^(ARRAY_FLOAT [$l,"FLT ARY"] $f+) )
    | ( l='[' (s+=STRING)+ ']' -> ^(ARRAY_STRING[$l,"STR ARY"] $s+) )
  ;


See  Chapter 7, p. 176 "Deriving Imaginary Nodes from Real Tokens" in the 
ANTLR Reference Book (print 02).

> 
> > i think this last form will simplify subsequent processing of the tree.
> > note also the proper initialization of the imaginary tokens.
> > 
> > [Andy - what do you mean "proper initialization of the imaginary tokens"]
> 
> the stuff between the [ ] on the right hand side of the -> is
> information used to initialize the imaginary token. in Java, they get
> translated into parameters to its constructor. i refer you to Dr. Parr's
> book to find out more about this feature.

Regards,
	Stefan



More information about the antlr-interest mailing list