[antlr-interest] what does .* match

Wincent Colaiuta win at wincent.com
Mon Jun 25 04:39:56 PDT 2007


El 25/6/2007, a las 13:35, Anders Hessellund escribió:

> Hi,
>
> I just bought the new ANTLR book, but I can not find any good  
> description of
> what the .* notation means. On p.85-6 there is an example of comments:
>
> ML_COMMENT : '/*' .* '*/';
>
>
> According to the book, this matches any character until it  
> encounters */
>
> In my implementation it does however complain about '*' with the  
> 'no viable
> alternative' error. Does '.*' match everything except '*'?

In a parser rule "." matches any token.

In a lexer rule, it matches any character.

Furthermore, ANTLR assumes that when you say ".*" you really want a  
non-greedy match. So in the case of the rule you post above, the ".*"  
means "match any character until you see the thing that lies beyond  
the subrule" (in this case, the "*/").

In order to explain the error you're seeing we'd need to see the  
other rules and the input you're trying to feed in.

Cheers,
Wincent



More information about the antlr-interest mailing list