Re: Writing a Boolean Statement Parser/Engine - Need help



I'm not sure I'm following you. Do you have some code that illustrates this?


"Ulrich Korndoerfer" <ulrich_wants_nospam@xxxxxxxxxxxx> wrote in message
news:%23E0VqUXpIHA.548@xxxxxxxxxxxxxxxxxxxxxxx
Hi,

Paul Engel wrote:

I need to write a boolean search string parser/engine for a scripting
project. In a perfect world:
- A user could enter a properly formatted boolean search string that I
could pass to the parser. For example, they could enter "((wallace OR
walters) AND (fire AND truck)) ANDNOT (water OR wet OR foam)".
- When I passed it to the parser, the parser would return some type of
collection (array, collection, etc.).
- I would iterate through the collection checking each term to see if it
was in the search string and return a similar collection w/ a series of
True/False values.
- The engine would look at the values I returned against the initial
search boolean, and return a collective True or False.

Has anyone written or encountered any or all of the functionality? Would
this be a good regular expression project? If so, does anyone have some
samples they could share?

I currently write an expressions evaluator, which takes a string and
evaluates it. It returns a variant value that is the value of the
expression.

The expressions use a syntax nearly compatible to VB and the evaluator
allows the user to set variables.

So eg

"(($wallace OR $walters) AND ($fire AND $truck)) AND NOT ($water OR $wet
OR $foam)"

returns True or False, depending on the values of the variables $* the
user has set.

When finished (may take one or two weeks), you can download it from my
website.

Otherwise there are some parsers outside in the web.

You could try www.datenhaus.de/Downloads/dh_Parser.zip from Olaf Schmidt,
which is able too to evaluate such expressions.

If you don't mind the extra work, you could write your own parser using
the GOLD parser engine from http://www.devincook.com/goldparser/

It uses an LALR algorithm and has an engine that builds state tables from
the syntax provided in BNF. It includes a VB6 dll that then is able to use
the state tables to parse your scripts.

--
Ulrich Korndoerfer

VB tips, helpers, solutions -> http://www.proSource.de/Downloads/


.



Relevant Pages

  • Re: boolean logic parser - need help
    ... I'm looking to evaluate basic boolean expressions like: ... My old parser can evaluate Expression1 and/or Expression2. ... stored in an associative array or literals. ... It would be nice to have a real parser - YACC looks powerful but it ...
    (comp.programming)
  • Re: softwire for basm?
    ... a parser on top of it, allowing for expressions like you're ... but 'simply' and 'parser' in the same sentence do not usually turn out so simple in the end;) ... fld dword ptr ...
    (borland.public.delphi.language.basm)
  • Re: Writing a Boolean Statement Parser/Engine - Need help
    ... A user could enter a properly formatted boolean search string that I could pass to the parser. ... I would iterate through the collection checking each term to see if it was in the search string and return a similar collection w/ a series of True/False values. ... The expressions use a syntax nearly compatible to VB and the evaluator allows the user to set variables. ...
    (microsoft.public.vb.general.discussion)
  • Re: Default argument values for blocks
    ... >> I'm suggesting that it may be time for a parser change ... > because it would require an arbitrary amount of lookahead. ... bitwise OR expressions in parens in the block param would solve the ...
    (comp.lang.ruby)
  • Re: Popularity of compiler tools, was LRgen
    ... Comparing writing parsing engine ... overflow JVM method size. ... Making a particular parser engine happy does not warrant ... The other limitations: no left recursion, no ambiguity, are all solved ...
    (comp.compilers)