[antlr-interest] Problem with this antlr grammar.

Loring Craymer Loring.G.Craymer at jpl.nasa.gov
Mon Feb 28 23:38:20 PST 2005


DIGIT, UPPER, LOWER, OPENB, and CLOSEB need to be "protected" so that they
can be used inside other lexer rules.  What your grammar encounters is OPENP
SEMI UPPER.

--Loring

> -----Original Message-----
> From: antlr-interest-bounces at antlr.org [mailto:antlr-interest-
> bounces at antlr.org] On Behalf Of doctlo-antlr at yahoo.com
> Sent: Monday, February 28, 2005 11:24 PM
> To: ANTLR Interest
> Subject: [antlr-interest] Problem with this antlr grammar.
> 
> header {
> }
> 
> class MyLexer extends Lexer;
> options
> {
>     k=3;
> }
> WS       : ('\n' | '\r')
>               { _ttype = Token.SKIP; };
> DIGIT        : '0'..'9';
> UPPER        : 'A'..'Z';
> LOWER        : 'a'..'z';
> //NUMBER       : ('+'|'-')(DIGIT)+;
> //REAL         : NUMBER '.' (DIGIT)*;
> OPENP        : '(';
> CLOSEP       : ')';
> SEMI         : ';';
> OPENB        : '[';
> CLOSEB       : ']';
> COLON        : ':';
> PERIOD       : '.';
> ESC          : '\\' ']';
> PROP_VALUE   : OPENB ( ESC | ~']')*   CLOSEB;
> PROP_IDENT   : UPPER (UPPER|DIGIT)?;
> 
> class MyParser extends Parser;
> options
> {
>    k=3;
> }
> collection   : (game_tree)+;
> game_tree    : OPENP sequence (game_tree)* CLOSEP;
> sequence     : (node)+ ;
> node         : SEMI (property)*;
> property     : PROP_IDENT  PROP_VALUE;
> 
> 
> For some reason when I feed it the following:
> 
> (;GM[1])
> 
> line 1:3: expecting CLOSEP but found 'G'.
> 
> I have no idea why.
> Can someone help?
> 
> Thanks
> T.L.Olczyk
> 2.7.4



More information about the antlr-interest mailing list