Text based query parsing

P

puzzlecracker

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
 
S

Stefan Schulz

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)
 
O

Oliver Wong

puzzlecracker said:
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top