[antlr-interest] Grammar seems to produce incorrect parser

mzukowski at yci.com mzukowski at yci.com
Wed Jan 21 17:16:18 PST 2004


You need to set the testLiterals option to true for your identifier rule.  

Monty

-----Original Message-----
From: stanhuff [mailto:stanhuff at yahoo.com] 
Sent: Wednesday, January 21, 2004 4:59 PM
To: antlr-interest at yahoogroups.com
Subject: [antlr-interest] Grammar seems to produce incorrect parser

In the following grammar, I desire to have the "is null" clause 
optional after the 'simpleExpression' non-terminal. The resultant 
parser doesn't work as expected.  The parser generated from my little 
grammar throws exceptions if "is null" is not found. How can I change 
my grammar to get the desired parser?




class ExpressionParser extends Parser;
options {defaultErrorHandler=false;}
expression 
	:	simpleExpression ("is" "null")?
	;

simpleExpression 
	:	Digits
	|	LParen expression RParen
	;
    	
class ExpressionLexer extends Lexer;

Identifier:	('a'..'z' | 'A'..'Z' | '_') ('a'..'z' | 'A'..'Z' 
| '0'..'9' | '_')*;
   
Digits: ('0'..'9')+;

LParen: '(';

RParen: ')';

WS_	:	(' ' | '\t' | '\n' | '\r') 
                { _ttype = antlr::Token::SKIP; }
	;



Thanks,
Stan




 

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/ 


 

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