[antlr-interest] Dealing with issues in non-greedy (.)* rules

Gavin Lambert antlr at mirality.co.nz
Mon May 14 14:48:16 PDT 2007


At 02:47 15/05/2007, Marc-André Laverdière wrote:
 >line 21:30 no viable alternative at character '['
 >line 21:32 no viable alternative at character ']'
 >line 21:77 no viable alternative at character ';'
[...]
 >Which means that certain characters are not accepted. Acutally,
 >when I print the resulting token, these are missing!
 >
 >I don't even have a lexer rule that mentions ';'!
 >What am I doing wrong? I'm working with k=2. 
Should I crank it up
 >for that rule?

Actually, that's probably exactly what you're doing wrong :)

The parser cannot and does not deal directly with 
characters.  Any characters you want to be able 
to recognise in the stream must be converted into 
tokens, whether through lexer rules or a tokens 
block, and whether individually or grouped.

(There is a shortcut syntax that makes it look 
like the parser can deal with characters, but in 
reality that just results in internally 
generating tokens, which you have less control over.)



More information about the antlr-interest mailing list