473,608 Members | 2,479 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Need Boolean Expression Evaluation Routine - Reward

18 New Member
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 3633
Killer42
8,435 Recognized Expert Expert
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
Railgunner
18 New Member
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
Railgunner
18 New Member
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 Recognized Expert Expert
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 Recognized Expert Expert
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
2506
by: greg | last post by:
Discussion is invited on the following proto-PEP. ------------------------------------------------------------- PEP ??? - Overloadable Boolean Operators ======================================== SUMMARY This PEP proposes an extension to permit objects to define their own
25
2377
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 a key occurs with is stored in the list for that key. This code's fine, and seems pretty simple, but thanks to generator
5
3598
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" = "fun") or ( ( 1 = 5 ) or ( 2 < 3 ) ) and (1 <= 6)
9
2383
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 is NULL? This is fine in Java, but I wasn't sure about C++.
2
4118
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 days! Can anyone point me to good resources (or implementations) that do this. Basically is there any way to optimize a boolean expression expressed in RPN (reverse polish notation)? I want to implement the algorithm/data structure in C. If you...
3
8016
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
306
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 in 5.10 Boolean operations: " The expression x and y first evaluates x; if x is false, its value is
32
3291
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 += i + j + k++;
33
2542
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 switch to turn it on/off ? thanks, Stef Mientki
0
8059
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8470
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8145
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8330
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6815
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5475
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
3960
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
1589
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1328
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.