[antlr-interest] Antlr for syntax check

mzukowski at yci.com mzukowski at yci.com
Mon Oct 6 08:22:38 PDT 2003


You didn't explicity recognize EOF, so it never tried to parse the last
parens and get an error.  Try

expr			: int_logic_ex EOF;

Monty

-----Original Message-----
From: Someshwar Halikhede [mailto:somhalikhede at yahoo.com] 
Sent: Monday, October 06, 2003 4:06 AM
To: antlr-interest at yahoogroups.com
Subject: [antlr-interest] Antlr for syntax check

Hi,

I need to write grammar for logical expression. I want
to use antlr to check syntax of the logical expression
entered by user. I was just spiking with Antlr and
following simple grammar I wrote.

-----------   grammer  ------------------------ 

class boolExprsnParser extends Parser;
options {buildAST=true;}

expr			: int_logic_ex;
bool_exprsn		: logic_exprsn (AND^ logic_exprsn)* ;
logic_exprsn	: int_logic_ex ; 
int_logic_ex	: INT_VAR(EQ^ | LT^ | GT^)INT_VAR |
LPAREN expr RPAREN;

class boolExprsnLexer extends Lexer;
 	
AND			: '&';
OR			: '|';
EQ			: "=";
LT			: '<';
GT			: '>';
BOOL_VAR 	: "true"|"false";
LPAREN		: '(';
RPAREN  	: ')';
SEMI		:';';


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

INT_VAR		: (DIGIT)+ | "iVar"(DIGIT)+;


----------------------------------------------------

It works fine with expression such as (iVar1 <
10)&(iVar3 > 4) etc. However it does not throw
exceptions for expression such as 
(iVar1 < 10)))))
I am sure I am missing something. 
Can somebody help me know what all I need to do to
write a expression syntax checker? Do I need to use
TreeParser to catch syntax mistakes?

Regards,
Som

________________________________________________________________________
Want to chat instantly with your online friends?  Get the FREE Yahoo!
Messenger http://mail.messenger.yahoo.co.uk

 

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


 

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




More information about the antlr-interest mailing list