Text based query parsing

Discussion in 'Java' started by puzzlecracker, Jan 9, 2006.

  1. 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
     
    puzzlecracker, Jan 9, 2006
    #1
    1. Advertising

  2. 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)
     
    Stefan Schulz, Jan 9, 2006
    #2
    1. Advertising

  3. puzzlecracker

    Oliver Wong Guest

    "puzzlecracker" <> wrote in message
    news:...
    > 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
     
    Oliver Wong, Jan 10, 2006
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. BLF
    Replies:
    4
    Views:
    1,282
    Mike Treseler
    Aug 7, 2004
  2. Boris Twila
    Replies:
    0
    Views:
    362
    Boris Twila
    Nov 14, 2006
  3. Kai Schlamp
    Replies:
    1
    Views:
    419
    Arne Vajhøj
    Mar 27, 2008
  4. Mike
    Replies:
    1
    Views:
    103
    Thomas 'PointedEars' Lahn
    Aug 21, 2004
  5. Domenico Discepola

    Assistance parsing text file using Text::CSV_XS

    Domenico Discepola, Sep 1, 2004, in forum: Perl Misc
    Replies:
    6
    Views:
    454
    Domenico Discepola
    Sep 2, 2004
Loading...

Share This Page