[antlr-interest] Tokens as keywords
Jim Idle
jimi at temporal-wave.com
Sun May 4 09:30:12 PDT 2008
Whether you need the predicate depends on the presence of optional identifiers that can be keywords. You need the predicate to avoid a warning saying that the upcoming keyword is ambiguous and assuming that the language expects it to be resolved this way. Consider something like:
xxxx id? ONLY?
id
: Identifier
| ONLY -> Identifier[ONLY]
;
The original example just shows the mechanism and we cannot say where the predicates might be needed without the whole grammar.
Jim
> -----Original Message-----
> From: Johannes Luber [mailto:jaluber at gmx.de]
> Sent: Sunday, May 04, 2008 7:35 AM
> To: Jim Idle
> Cc: antlr-interest at antlr.org
> Subject: Re: [antlr-interest] Tokens as keywords
>
> Jim Idle schrieb:
> > statement : FIND tableName whereClause? orderByClause?;
> >
> > tableName
> > : Identifier
> > | (keywords)=>keywords
> > ;
>
> Just one additional comment: Order alternatives in such way that the
> last alternative is the one without a syntactic predicate. Thinking
> about it further, as one would order the lexer rules in such way that
> the keywords are recognized as such, no Identifier will match a keyword
> anyway. So you can remove that predicate anyway.
>
> Johannes
More information about the antlr-interest
mailing list