[antlr-interest] How to handle multicharacter delimiters?

Andrew Lentvorski bsder at allcaps.org
Wed Jul 25 18:32:34 PDT 2007


Jim Idle wrote:
> FREETEXT:	{flgFreeText}?=> ( { ! (LA(1) == '$' && LA(2) == 'e' && LA(3) == 'n' && LA(4) == 'd') }?=> .)+;
> 
> Should do it I think?

WHOA!  That rocks.  I need to go check that out.

However, it doesn't compile.

I get:
vcdfile2Lexer.java:82: cannot find symbol
symbol  : method LA(int)
location: class vcdfile2Lexer
                if ( ((LA1_0>='\u0000' && LA1_0<='\uFFFE')) && ( ! (LA(1) == '$' && LA(2) == 'e' && LA(3) == 'n' && LA(4) == 'd') )) {


I'm using the grammar:

grammar vcdfile2;

@lexer::members {
    boolean flgFreeText = false;
}

vcd	:	(declaration_command WS*)+ EOF;

declaration_command:	DATEK FREETEXT ENDK;

DATEK	:	'$date' {flgFreeText = true;};	
ENDK	:	'$end' {flgFreeText = false;};

FREETEXT:	{flgFreeText}?=> ( { ! (LA(1) == '$' && LA(2) == 'e' && LA(3) == 'n' && LA(4) == 'd') }?=> .)+;

WS	:	(' '|'\n'|'\r'|'\t') ;
ANY	:	.;


-a


More information about the antlr-interest mailing list