[antlr-interest] Antlr2 -> antlr 3 tree creation with rule argument as root

Kevin J. Cummings cummings at kjchome.homeip.net
Wed May 18 10:40:27 PDT 2011


On 05/18/2011 12:41 PM, Ben Corne wrote:
> Hello
> 
> I've got this antlr2 rule which I'm trying to convert that goes like this:
> ================================================================
> application![int tokenType, String tokenText]
>     : c:canonical a:annotation { #application = #([tokenType,tokenText], c,
> a); }
>     ;
> ================================================================
> 
> My attempt is:
> ================================================================
> application[int tokenType, String tokenText]
> : c=canonical a=annotation -> ^({$tokenType;}[{$tokenText;}] $c $a)

I would try:

  : c=canonical a=annotation -> ^($tokenType [$tokenText] $c $a)
or
  : c=canonical a=annotation -> ^([$tokenType, $tokenText] $c $a)

I know the first one works when the $tokenType is replaced with a TOKEN
name constant, but I can only find such uses as GOTO["GOTO"] in my code.

The second case works when the first argument inside the [] is a token
reference (as in:
    t=TOKEN -> ^([$t, spelling] ....)
).

I'm not sure if the tool will take any integer in place of an actual
TOKEN name constant.  Certainly the runtime method that it gets
translated into will.  Look at the generated source code.  I'm using
C/C++, are you using JAVA?

>  ;
> ================================================================
> But the ANTLR3 parser returns the following errors:
> 
> syntax error: antlr: AmbientTalk.g:310:46: expecting RPAREN, found
> '{$tokenText}'
> syntax error: antlr: AmbientTalk.g:310:66: expecting SEMI, found ')'
> 
> Any thoughts / suggestions?
> 
> Regards
> Ben C.
> 
> List: http://www.antlr.org/mailman/listinfo/antlr-interest
> Unsubscribe: http://www.antlr.org/mailman/options/antlr-interest/your-email-address


-- 
Kevin J. Cummings
kjchome at verizon.net
cummings at kjchome.homeip.net
cummings at kjc386.framingham.ma.us
Registered Linux User #1232 (http://counter.li.org)


More information about the antlr-interest mailing list