[antlr-interest] Getting token text - simple?

Trey Spiva Trey.Spiva at embarcadero.com
Mon Sep 30 11:04:35 PDT 2002


> I've had some fun with PCCTS 1.33 on a couple of projects and now
> have started with ANTLR 2.7.1 producing C++ code.
> I have a typically trivial (I hope) newbie problem.
> How do I get the token text, where I'm looking at attribute values.
> My code is the html.g as distributed with the following modification:
> 
> protected
> ATTR
> options {ignore=WS_;}
>     :   WORD ('=' (axa:WORD ('%')? | ('-')? INT | bxb:STRING |
> HEXNUM))?
>     {
>         if( axa != NULL )
>             printf( "<<A:attribute>><%s>", axa.getText());
>         if( bxb != NULL )
>             printf( "<<B:attribute>><%s>", bxb.getText());
> 	}
> 	;
> 
> I get the message:
> (file/line) error C2039: 'getText' : is not a member
> of 'RefCount<class antlr::Token>'
> ..should I be deriving my own token class
[Trey Spiva] 
It should be 

axa->getText()
 
axa is an instance of a RefToken which is defined as

typedef RefCount < Token > RefToken;

The template RefCount overrides the -> operator to allow 
access to the token.  Typical smart pointer stuff.

 

Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/ 



More information about the antlr-interest mailing list