[antlr-interest] Newbie: rule equivalent of a token reference?
tarunkhanna at gmail.com
Tue Jul 19 07:55:14 PDT 2005
You'll have to return the string from the rule constant.
So your two rules would look something like the following. In the variable
declaration rule the x would then contain whatever string constant returns.
You should look at the manual that describes this stuff. One of the getting
started tuts has it. Hoewever they talk abt returning integers.
x=constant type ( COMMA constant type )*
constant returns [String x=""}
type : .....
On 7/19/05, JConner at ssp-uk.com <JConner at ssp-uk.com> wrote:
> Dear all,
> Sorry if this isn't the right place to ask this, and I know that I might
> trying to run before I can walk, but...
> I'm trying to play around and create a simple translator. Getting the
> "text" of a token seems straight forwards - you label the token reference,
> and call xzy.getText() in an action. However, what do I do if I wrap the
> token reference up in another parser rule? Eg, in:
> variable_declaration : constant type ( COMMA constant type )* ;
> constant : INDENTIFIER ;
> type : .....
> Given that COMMA and IDENTIFIER are lexer rules, how would I get the
> from the rule constant into an action in the rule variable_declaration? Am
> I missing something obvious, or am I trying to go about this in the wrong
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the antlr-interest