dcsimg
Beginner question: Keywords vs. Identifier not working
0 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Bharat_Khatri
Posted On:   Monday, June 14, 2004 07:01 AM

I just started learning ANTLR (version 2.7.2) and am stuck in a simple grammer where keywords vs. identifiers stuff as described at many places is not working as expected. I get a warning about non-determinism between the two rules, even though I have specified testLiterals to be true. My grammer is given below. Any help will be appreciated class MyLexer extends Lexer; options { k=2; // needed for newline junk charVocabulary='u0000'..'u007F'; // allow ascii testLiterals=false; } protected LETTER : ('a'..'z') ; protected DIGIT : ('0'..'9') ; COMMA: ',' ; INTTYPE : "int";    More>>

I just started learning ANTLR (version 2.7.2) and am stuck in a simple grammer where keywords vs. identifiers stuff as described at many places is not working as expected. I get a warning about non-determinism between the two rules, even though I have specified testLiterals to be true. My grammer is given below.

Any help will be appreciated




class MyLexer extends Lexer;


options {


k=2; // needed for newline junk

charVocabulary='u0000'..'u007F'; // allow ascii

testLiterals=false;

}


protected LETTER : ('a'..'z') ;

protected DIGIT : ('0'..'9') ;

COMMA: ',' ;

INTTYPE : "int";

DOUBLETYPE : "double" ;


ID options {testLiterals=true;}

: ('a'..'z'|'A'..'Z') ('a'..'z'|'A'..'Z'|'0'..'9')*

;



SEMICOLON: ';' ;






class MyParser extends Parser;


declarations : (declaration)*;


declaration :INTTYPE identifier (COMMA identifier)* SEMICOLON

|

DOUBLETYPE identifier (COMMA identifier)* SEMICOLON

;


identifier : ID;

   <<Less
About | Sitemap | Contact