[antlr-interest] lexer problem

Gavin Lambert antlr at mirality.co.nz
Mon Nov 3 12:00:44 PST 2008


At 04:59 4/11/2008, Robert Soule wrote:
 >start	
 >	: LSQUARE AB RSQUARE
 >	| A
 >	;
 >AB	:	('a'|'b')+;
 >
 >fragment A: '[a]';
 >LSQUARE
 > :  (A) => A { $type = A; }
 > |  '['
 > ;
 >
 >RSQUARE	:	']';
 >
 >
 >When I test with inputs "[ba]" I pass, but "[ab]" fails.

It works for me (ANTLR 3.0.1).  You are using a real compiled 
parser, though, right (or ANTLRworks' debugger)?  Not the 
interpreter?  Because the interpreter doesn't execute predicates 
(so it almost never works properly).

If I change the start rule given above to this:

start : (LSQUARE AB RSQUARE | A)+ ;

then it'll successfully match the input "[ba][a][ab]".



More information about the antlr-interest mailing list