[antlr-interest] How to intervene automatic keywords generati
on
mzukowski at yci.com
mzukowski at yci.com
Thu Oct 17 07:39:03 PDT 2002
Since you want to keep "error" out of the literals table, then treat it as
an ID:
on_error_stmt
: "on" ID "goto" label
;
If you want to make sure that it is always "error" you can use a validating
semantic predicate:
on_error_stmt
: "on" { "error".equals(LA(1).getText()) }? ID "goto" label
;
Monty
www.codetransform.com
> -----Original Message-----
> From: Fan Yang [mailto:yhhf_dy at yahoo.com]
> Sent: Wednesday, October 16, 2002 2:17 PM
> To: antlr-interest at yahoogroups.com
> Subject: [antlr-interest] How to intervene automatic keywords
> generation
>
>
> Hi,
>
> According to the manual of ANTLR about Keywords and literals: any
> double-quoted string used in a parser is automatically entered into
> the literals table of the associated lexer. For instance,
>
> on_error_stmt
> : "on" "error" "goto" label)
> ;
>
> So "on", "error" and "goto" will be automatically putted into the
> literals table. But in my target language "error" is not a keyword.
> so "error" can be an "identifier" in a statement as following pseudo
> code line shows.
>
> printf("%s", e.error)
>
> In fact, this line will cause a problem. because the parser will look
> for the identifier -"error" in the literals table first, then
> treat "error" as keyword not an general identifier.
>
> IDENT
> options {testLiterals=true;}
> : ('a'..'z'|'_') ('a'..'z'|'_'|'0'..'9')*
> ;
>
> My question is that may I determine which one ,double-quoted strings,
> can be entered into literals table instead of automatically
> generatation. Or there is an alternative way to deal with this kind
> of problem
>
> Thanks,
>
> Fan
>
>
>
>
>
> Your use of Yahoo! Groups is subject to
http://docs.yahoo.com/info/terms/
Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/
More information about the antlr-interest
mailing list