[antlr-interest] expecting "class", found 'class'

Sven Busse mail at ghost23.de
Sun Feb 11 04:13:01 PST 2007


Hi,

i tried this already with the testLiterals option, but it
doesn't change anything :(
Also, i read, that if you don't set any option, then
testLiterals would be true by default.


-----Ursprüngliche Nachricht-----
Von: Ric Klaren [mailto:ric.klaren at gmail.com] 
Gesendet: Sonntag, 11. Februar 2007 12:16
An: Sven Busse
Cc: antlr-interest at antlr.org
Betreff: Re: [antlr-interest] expecting "class", found 'class'

Hi,

On 2/11/07, Sven Busse <mail at ghost23.de> wrote:
> i am very new to antlr. I am using antlr 2.7.7.
>
> I have a parser rule like this (i am using the c# version):
>
> startRule
>         :       "class" cl:IDENT
>                 {Console.WriteLine("classname: "+cl.getText());}
>         ;
>
> IDENT is my Lexer rule:
>
> IDENT
>         :       ('a'..'z'|'A'..'Z'|'_'|'$')
> ('a'..'z'|'A'..'Z'|'_'|'0'..'9'|'$')*
>         ;
>
> But running the stuff with an example text, i allways get this error
> message:
>
> line 4:1: expecting "class", found 'class'
>
> Can someone explain that to me?

The ident rule gobbles up the 'class' key word, think you have to turn
the testLiterals = yes option on the IDENT rule. Just look at the docs
for testLiterals (or an example like the java grammar)

Cheers,

Ric



More information about the antlr-interest mailing list