By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
454,622 Members | 1,103 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 454,622 IT Pros & Developers. It's quick & easy.

Need Boolean Expression Evaluation Routine - Reward

P: 18
I am looking for a routine that can evaluate boolean expressions like:

IF/ELSE-IF (X1=X2 AND (Y=1 OR Z1=Z2))

IF/ELSE-IF (A$='Y' AND B=1) OR (C=1 AND D>E)


I can handle determining if the individual terms (X1=X2, etc) are TRUE/FALSE at runtime. I just need the routine that determines if the entire expression is TRUE/FALSE taking into account ANDs, ORs, NOTs and parens.

I would like the routine to be written in BASIC.

If possible, the routine should determine at which point the expression is known TRUE or FALSE and short-circuit for performance.

I'm guessing the routine to do this will need to convert the expression into
reverse polish notation before evaluating it?

If I use your routine I will send a small reward to the Paypal account of your choice.
Apr 7 '07 #1
Share this Question
Share on Google+
5 Replies

Expert 5K+
P: 8,434
Does this have to be VB code? What about, for example, a DLL routine you could call?

I ask because this seems a fascinating problem which I'd like to throw to the wider community at TheScripts, but if they comes up with a lovely simple solution in C++, for example, it may not help you at all.

If we get some decent code, chances are we can convert it to VB. But I seem to recall that some languages/tools include parsers for this kind of thing, and would require very little if any coding to produce a result.
Apr 8 '07 #2

P: 18
The routine will have to be converted into a 4GL that runs on the mainframe. I asked for it in BASIC because I used to code in BASIC years ago and I could probably rewrite the routine if it's written in BASIC but I'll take it in whatever language I can get it in.
Apr 8 '07 #3

P: 18

DLL won't work:) This routine will end up being converted into a 4GL that runs on an mainframe.

I asked for it in BASIC because I used to code in BASIC years ago and I could probably rewrite the routine if it's written in BASIC but I'll take it in whatever language I can get it in.

The routine is needed for a business rules engine I'm working on. It consists of an end-user scripting "language", a "compiler", and a "processor" (The black box that actually executes the "script".

Currently, the language does not support parens in boolean expressions
(compiler will flag them). Expressions are evaluated left to right at runtime.
ANDs are evaluated when the expression is TRUE and can change the
expression to FALSE. ORs are evaluated when the expression is FALSE
and can change the expression to TRUE.

To get around not being able to code parens users write an expression like:

IF (A=1 AND B=1) OR (A=2 AND B=2)
Do Something


IF A=1 AND B=1
Do Something
Do Something

And an expression like:

IF A=1 AND (B=1 OR C=1)


IF A=1
IF B=1 OR C=1
Do Something

The compiler is not really a compiler in the traditional sense. It puts the
offset (address) on the next executable statement if a condition is FALSE
on each line and the offset on the next END-IF on each line. This allows
the processor to "skip" thru the scripts at runtime by branching around FALSE
code. Because the "object" code can run on any platform without being recompiled given a processor exists that platform.

Variables are actually lists that can contain one or more values. References to a variable without a subscript actually apply to any value in the list. So

IF X=1
Do Something

Can be TRUE in this language if the variable X contains two values (1 AND 3).

Treating all variables as lists eliminates the need for end-users to write routines
to loop thru occurences...
Apr 8 '07 #4

Expert 5K+
P: 8,434
Interesting - what language is this? Or is it top secret? :)

If you think you've got problems, you ought to try setting up complex logic in the scripting language in an M/Text document. Not only is it very awkward to write, but if you have nested IFs, and End If closes all of them - argh!

I've posted a message in the Experts forum (most users can't see it) to see whether anyone there can help. Will also post in the miscellaneous discussions area for everyone to see, in the hope someone can help out.
Apr 9 '07 #5

Expert 5K+
P: 8,434
You may be interested to see this thread which I started in the Software Development forum. So far it has drawn a couple of responses.
Apr 9 '07 #6

Post your reply

Sign in to post your reply or Sign up for a free account.