[antlr-interest] simple lexical analysis question

Jean-Claude Durand Jean-Claude.Durand at imag.fr
Mon Dec 14 10:18:58 PST 2009


My lexical grammar (I use antlr v3.2):

lexer grammar Lex;
options
{ language=Java; }

WS:	( ' ' | '\t' | '\n' )+ { $channel=HIDDEN; } ;

FIN	:	'-FIN-'	;
Moins	:	'-'		;

// Identifiers:
Idf	:	('A'..'Z')+	;

I want to enumerate the tokens for the following example (Main.java is  
in the archive):

VLEG-XLEG-FCINFZU

And the output is:

~/Soft/Antlr/LexJava: java Main test
  --> [@-1,0:3='VLEG',<7>,1:0]
  --> [@-1,4:4='-',<6>,1:4]
  --> [@-1,5:8='XLEG',<7>,1:5]
line 1:11 mismatched character 'C' expecting 'I'
  --> [@-1,12:16='INFZU',<7>,1:12]
  --> [@-1,17:36='                    ',<4>,channel=99,1:17]
~/Soft/Antlr/LexJava:

The lexer is looking for the keyword -FIN-  and not for minus sign  
followed by an identifier (which begins with an F).



Thanks a lot for your help.

Jean-Claude Durand

LIG, équipe GETALP
385, rue de la Bibliothèque
BP 53
38041 Grenoble cedex 9

Jean-Claude.Durand at imag.fr
tél: +33 (0)4 76 51 43 81
fax: +33 (0)4 76 63 56 86




-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20091214/9ab2fdec/attachment.html 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: TestLexer.tar.gz
Type: application/x-gzip
Size: 830 bytes
Desc: not available
Url : http://www.antlr.org/pipermail/antlr-interest/attachments/20091214/9ab2fdec/attachment.gz 
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20091214/9ab2fdec/attachment-0001.html 


More information about the antlr-interest mailing list