[antlr-interest] bug in 3.0b6: identifier/keyword or underscore problem?

Martin d'Anjou martin.danjou at neterion.com
Mon Feb 26 04:13:13 PST 2007


Hi,

I've been strugling with this for several days. It looks like 3.0b6 can't 
tell an identifier from a keyword, or has a problem with underscores. Here 
is how I produce the problem:

1) input text

int id;
int int_id;
int _int_id;

2) Lexer

lexer grammar DUMMY_Lexer;
options { filter=true; }

INT          : 'int' ;
SEMI         : ';' ;
WS           :  (  ' '| '\t'| '\r' | '\n' )+ {$channel=HIDDEN;} ;
IDENTIFIER   : ('a'..'z'|'A'..'Z'|'_')+;

3) Parser

parser grammar DUMMY_Parser;
options {
   tokenVocab=DUMMY_Lexer;
}

source_text :
   { System.out.println("Weird lexer"); }
   int_defs+
   ;

int_defs :
   INT            { System.out.print("int "); }
   id=IDENTIFIER  { System.out.print($id.text); }
   SEMI           { System.out.println(";"); }
   ;

4) The output and the error I get

Weird lexer
int id;
int line 2:4 mismatched input 'int' expecting IDENTIFIER
int;
int _int_id;


The lexer is not greedy or something is wrong with the underscore, I don't 
know.

Help!!!
Martin


More information about the antlr-interest mailing list