tags:

views:

773

answers:

2

I am looking for an open source library in Java for parsing and building sql like expressions.

for example to evaluate validity of expressions like:

 "(a = x or y ) and (b != z)"

in addition I want to have an API for building or extending expressions. something like:

Expression exp = new Expression();
exp.addCondition("a",{"x","y"},Operator.OR);

It's not very complicated to implement such library, but aren't we develop in Java to enjoy collaborative development?

Thanks

+1  A: 

I'm pretty sure you can have ANTLR do this for you.

The grammatic looks very simple ( from here ) :P

OscarRyz
Thanks, that was exactly what I was looking for
LiorH
Be sure to note the numerous existing SQL grammars on the sample grammar page: http://www.antlr.org/grammar/list
Dave Ray
A: 
  1. Use script engine.. antlr is not pragmatic unless you have some basic parser knowledge.