[antlr-interest] Antlr for syntax check - Reposting

Someshwar Halikhede somhalikhede at yahoo.com
Mon Oct 6 04:23:29 PDT 2003


I am reposting it as there was a mistake grammar in
earlier mail.

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			: bool_exprsn;
bool_exprsn		: logic_exprsn (AND^ logic_exprsn)* ;
logic_exprsn	: int_logic_ex ; 
int_logic_ex	: INT_VAR(EQ^ | LT^ | GT^)INT_VAR |

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?


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/ 

More information about the antlr-interest mailing list