Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / January 2006

Tip: Looking for answers? Try searching our database.

Text based query parsing

Thread view: 
puzzlecracker - 09 Jan 2006 02:45 GMT
Hi group,

I am implementing a fairly simple and  straightforward  text-search (I
display each line that contains required pattern ) that supports
Boolean queries in the following format:

str1 AND str2 NOT str3 -  where not is a unary operation  thus the
following would be equivalent to  str1 AND str ANDNOT str3 by default
unless a user specifies otherwise....

Additionally,  It is left-associative;

I would also like to have parenthesis as well: (str1 AND (str2 OR
str3))

That is it....

Should I write a parser for that followed by walking the AST (abstract
syntax tree) - javacc or antlar? -  or would java regular expressions
suffice? it should  be fast, whereas java regex is known to be slow....

Any suggestions, examples, references would be highly appreciated.

Thx
Stefan Schulz - 09 Jan 2006 13:53 GMT
As soon as you have parenthesis, you will need a context free parser.
Regular expressions can not even check if the expression has
well-formed brackets (see pumping lemma)
Oliver Wong - 10 Jan 2006 21:42 GMT
> Hi group,
>
> I am implementing a fairly simple and  straightforward  text-search (I
> display each line that contains required pattern ) that supports
> Boolean queries in the following format:

[...]

> I would also like to have parenthesis as well: (str1 AND (str2 OR
> str3))

[...]

> Should I write a parser for that followed by walking the AST (abstract
> syntax tree) - javacc or antlar? -  or would java regular expressions
> suffice? it should  be fast, whereas java regex is known to be slow....
>
> Any suggestions, examples, references would be highly appreciated.

   Schulz is correct in saying regular expressions are not sufficiently
powerful. As for references, I recommend you post on comp.compilers to get
your design worked out if need be, and then comp.compilers.tools.javacc for
specific help on implementing your parser.

   - Oliver


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.