[antlr-interest] token query
Paul Keir
paul at paulkeir.com
Fri May 11 07:02:36 PDT 2007
Hi there,
First of all, please excuse the newbie. I have read the available docs
and tuts; and intend to buy the antlr book. For now though, I have what
I hope is a simple question.
In the code below, is there a way I can remove the 3 quoted strings in
the rule 'my_rule'? - they seem a little redundant. I'm thinking,
perhaps there's a way to use something _like_ {$name =
tokens.STRING1.getName();}
One other thing, is [String name=null] now permitted? It seems to compile.
Many thanks and best regards,
Paul
tokens {
STRING1='string1';
STRING2='string2';
STRING3='string3';
}
my_rule returns [String name]
@init {
name=null; // for now you must init here rather than in 'returns'
}
: ( 'string1' {$name = "string1";}
| 'string2' {$name = "string2";}
| 'string3' {$name = "string3";}
)
;
--
512k Broadband £14.99 per month
Unlimited Downloads - No extra Costs
£14.99 per month (inc. VAT)
Order Now www.adsl4less.com
More information about the antlr-interest
mailing list