[antlr-interest] unexpected char exception
Loring Craymer
Loring.G.Craymer at jpl.nasa.gov
Sat Feb 26 14:03:51 PST 2005
Replace ABC by "abc" in startRule, and delete the ABC rule.
Any quoted string in the parser grammar (like "abc") is assigned a unique
token type. However, there must be a rule that recognizes that string
(first message) and it must have the testLiterals = true (default case)
option set. Then ANTLR automatically looks up these special case tokens in
a hash table to determine token type. So IDENTIFIER matches "abc" and marks
the returned token as being of type LITERAL_abc (I think that I have the
prefix right).
--Loring
> -----Original Message-----
> From: antlr-interest-bounces at antlr.org [mailto:antlr-interest-
> bounces at antlr.org] On Behalf Of jean.morissette666 at videotron.ca
> Sent: Saturday, February 26, 2005 1:44 PM
> To: antlr-interest at antlr.org
> Subject: Re: [antlr-interest] unexpected char exception
>
> Thank for your reply.
>
> But now I have another kind of error. In my grammar, rule ABC is a
> special
> case of IDENTIFIER and Antlr complain about it:
> warning:lexical nondeterminism between rules ABC and IDENTIFIER
>
> Also, I have read this
> http://www.doc.ic.ac.uk/lab/secondyear/Antlr/options.html#_bb8
> but sadly I don't understand the purpose of the testLiterals option.
>
> Any help would be appreciated.
>
>
> class P extends Parser;
>
> startRule
> : ABC
> ;
>
> class L extends Lexer;
>
> ABC
> : "abc"
> ;
>
> IDENTIFIER
> : ( 'a'..'z' | 'A'..'Z' ) ( 'a'..'z' | 'A'..'Z' | '0'..'9' )*
> ;
>
>
> Le 26 Février 2005 16:17, Loring Craymer a écrit :
> > You need at least a lexer rule which recognizes text; "abc" is a special
> > case for that rule. Also look at the testLiterals option.
More information about the antlr-interest
mailing list