[antlr-interest] expecting IDENT, found 'x'

jc_lelann jc.lelann at wanadoo.fr
Sat Mar 6 06:58:04 PST 2004


Hi !

Could someone explain me why my parser returns the following message ?

java Test < test.txt
line 1:10: expecting IDENT, found 'x'
exception: line 1:12: unexpected char: ':'

I am new to antlr.
Thanks

JC



My grammar :

// content of my test file :

// constant x : integer := 4;
// constant x,y,z : integer := 5;
// constant x,y,z : integer := 5+5*2;


class TestParser extends Parser;
options {
    buildAST = true;
    defaultErrorHandler = true;     // Generate parser error handlers
}

mytext : 
        (constant_declaration)* EOF! ;

constant_declaration : 
        CONSTANT! identifier_list ":"! subtype_indication ":="!
expression ";"!
;
identifier_list : 
        identifier (","! identifier)*
;
identifier : 
        IDENT
;
subtype_indication : 
        IDENT
;
expression:     
        additiveExpression
;
// addition/subtraction
additiveExpression:     
        multiplicativeExpression((PLUS^ | MINUS^)
multiplicativeExpression)*
;
// multiplication/division   
multiplicativeExpression:     
        powerExpression ( (STAR^ | DIV^ ) powerExpression )*
;
powerExpression: 
        unaryExpression ( POWER^ unaryExpression)*
;
unaryExpression:
        MINUS^ unaryExpression
      |     primaryExpression
;
primaryExpression:
        NUMBER
      |     LPAREN! additiveExpression RPAREN!
      ;

class TestLexer extends Lexer;
options {
	exportVocab=Test;      // call the vocabulary "Java"
}

tokens {
    CONSTANT ="constant";
}

WS    :(    ' ' | '\t' | '\n' | '\r' )
        { _ttype = Token.SKIP; }
;
//-------------
// OPERATORS
//-------------
LPAREN      :     '('   ;     
RPAREN      :     ')'   ;
SEMI        :     ';'   ;     
DOT         :     '.'   ;
DIV         :     '/'   ;     
PLUS        :     '+'   ;
MINUS       :     '-'   ;     
STAR        :     '*'   ;
POWER       :     '^'   ;    

// Rule for IDENTIFIER: testLiterals is set to true.
IDENT
	options {testLiterals=true;}
            : ( 'a'..'z' )+
	;

//for both integer and real number

NUMBER : (DIGIT)+ ( '.' (DIGIT)+ )? ;

//for numbers
protected
DIGIT :     '0'..'9' ;







 
Yahoo! Groups Links

<*> To visit your group on the web, go to:
     http://groups.yahoo.com/group/antlr-interest/

<*> To unsubscribe from this group, send an email to:
     antlr-interest-unsubscribe at yahoogroups.com

<*> Your use of Yahoo! Groups is subject to:
     http://docs.yahoo.com/info/terms/
 



More information about the antlr-interest mailing list