[antlr-interest] assigning token LABEL

Johannes Luber jaluber at gmx.de
Wed Jun 20 06:50:19 PDT 2007


chintan rao wrote:
> Hi,
> firstly thanks for your time
> 
>> As you haven't sent your grammar with your question I have to improvise
>> the snippets. Create first an imaginary LABEL token and have rules like
>> this:
> 
> What wanted was some thing like this
> input :
> la :
> ouput given by lexer :
> la gets assigned token LABEL
> 
> input:
> la
> ouput given by lexer :
> la gets assigned token ID

Looking at your sample input I discovered that I misread your
specification. I thought that after the label had to come an ID. My
mistake. The following grammar works with ANTLRworks and parses my test
input correctly. Just don't forget a whitespace rule in your actual grammar.

LABEL
	:	('a'..'z'|'A'..'Z')+ ':'
	;
	
ID
	:	('a'..'z'|'A'..'Z')+
	;

test
	:	(LABEL|ID)*
	;

Best regards,
Johannes Luber


More information about the antlr-interest mailing list