[antlr-interest] Pattern to macth if no other match

Gavin Lambert antlr at mirality.co.nz
Wed Dec 24 16:54:51 PST 2008


[Don't forget to use Reply All to keep your responses on-list!]

At 09:37 25/12/2008, Mats Ekberg wrote:
>stat:
>expr{ fh.lit(new BigDecimal($expr.text));}
>|'DUP'{ fh.dup();}
>|'SWAP'{ fh.swap();}
>|'DROP'{ fh.drop();}
>|x=.{ fh.lookup($x.text);}
>;
>
>if I have a input text "1 2 3 BBBB" I get (the 1 2 and 3 is 
>correctly parsed as expr):
>
>line 1:6 no viable alternative at character 'B'
>line 1:7 no viable alternative at character 'B'
>line 1:8 no viable alternative at character 'B'
>line 1:9 no viable alternative at character 'B'

The error indicates that you don't have a lexer rule that can 
match a 'B' (or a sequence of 'B's).

Remember that using the . wildcard in a parser rule means "any 
token" -- you still must have an appropriate lexer rule to 
generate the tokens in the first place. 



More information about the antlr-interest mailing list