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

Ric Klaren ric.klaren at gmail.com
Sun Feb 11 03:15:36 PST 2007


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