473,396 Members | 1,599 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Need Boolean Expression Evaluation Routine - Reward

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)

etc.

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
5 3625
Killer42
8,435 Expert 8TB
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
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
More...

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
END-IF

As...

IF A=1 AND B=1
Do Something
ELSE-IF A=2 AND B=2
Do Something
END-IF

And an expression like:

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

as:

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

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
AND X=3
Do Something
END-IF

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
Killer42
8,435 Expert 8TB
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
Killer42
8,435 Expert 8TB
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

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

Similar topics

14
by: greg | last post by:
Discussion is invited on the following proto-PEP. ------------------------------------------------------------- PEP ??? - Overloadable Boolean Operators...
25
by: Steven Bethard | last post by:
So I end up writing code like this a fair bit: map = {} for key, value in sequence: map.setdefault(key, ).append(value) This code basically constructs a one-to-many mapping -- each value that...
5
by: Mad Scientist Jr | last post by:
Has anyone worked on code that that can parse evaluation expressions (could be numbers or strings) like ( ( "dog" = "dog" ) or "foo" = "bar" ) and ("cow" = "bat" and "bye" = "hi") or ("math" =...
9
by: John Ratliff | last post by:
Does C++ employ lazy evaluation of boolean conditions, e.g. can I do the following safely if ((obj != NULL) || (obj->someMethod())) { // blah blah } Or will I get a segfault if the obj ptr...
2
by: webposter | last post by:
Hi, I am looking for information on a data structure (and associated algorithm) to do short-circuit evaluation of boolean expressions and haven't found a single one even after googing for two...
3
by: Coco | last post by:
Hi! Does c# has any class method that will be able to evaluate a given string e.g ((True && False) || (True && True)) and return the result in boolean for this case is true Thanks!
4
by: Greg Corradini | last post by:
Hello all, I'm having trouble understanding why the following code evaluates as it does: True -1 In the 2.4 Python Reference Manual, I get the following explanation for the 'and' operator...
32
by: silpau | last post by:
hi, i am a bit confused on expression evaluation order in expressions involving unary increment.decrement operators along with binary operators. For example in the following expression x...
33
by: Stef Mientki | last post by:
hello, I discovered that boolean evaluation in Python is done "fast" (as soon as the condition is ok, the rest of the expression is ignored). Is this standard behavior or is there a compiler...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.