[antlr-interest] what does .* match

Johannes Luber jaluber at gmx.de
Mon Jun 25 06:34:37 PDT 2007


Anders Hessellund wrote:
>     fragment
>     LETTER    :    'a'..'z'|'A'..'Z'
>         ;
> 
>     fragment
>     INT    :    '0'..'9'+
>         ;
> 
>     WS    :    (' ' | '\t' | '\n' | '\r' )+ { $channel=HIDDEN; }
>         ;
> 
> 
> When I feed my generated lexer/parser the following text
> 
>     PAGE helloWorld {
>         TITLE Hello World
>         CENTER { ere * eryu / sdhjs }
>     }
> 
> 
> it complains:
> 
> line 3:14 no viable alternative at character '*'
> line 3:21 no viable alternative at character '/'
> 
> Why is that?

Looking through your grammar I would say the reason is because the ".*"
are used only in parser rules. So you don't match any characters, but
any tokens. The only lexer rules are ID and WS and those don't recognize
any characters besides the one you have defined. The solution is
probably to change the ".*"-using parser rules into lexer rules through
uppercasing.

Best regards,
Johannes Luber


More information about the antlr-interest mailing list