× The internal search function is temporarily non-functional. The current search engine is no longer viable and we are researching alternatives.
As a stop gap measure, we are using Google's custom search engine service.
If you know of an easy to use, open source, search engine ... please contact support@midrange.com.


  • Subject: Re: Evaluate complex conditions
  • From: "Peter Dow" <pcdow@xxxxxxxxxxxxxxx>
  • Date: Mon, 23 Oct 2000 12:16:01 -0700

I remember doing something like this in COBOL back in the punch card days so
no source to go by. But I recall scanning for a right parenthesis, then back
tracking to the matching left paren, then evaluating the expression in
between. Repeat until done.

With RPG IV and recursive procedures, you could use Richard's method without
the array. Every time you hit a left parenthesis, call the same procedure
again.

Peter Dow
Dow Software Services, Inc.
909 425-0194 voice
909 425-0196 fax



----- Original Message -----
From: "Richard Casey" <casey_r@popmail.firn.edu>
To: <MIDRANGE-L@midrange.com>
Sent: Monday, October 23, 2000 10:32 AM
Subject: RE: Evaluate complex conditions


> Hmm. Sounds like fun! I remember a college project to parse an arithmetic
> expression (with parentheses) and return the result; I imagine similar
> logic would work for you. Let me see if I can remember! I don't know how
> you are currently parsing your conditional statement; I just assume you
> wind up with TRUE or FALSE at the end.
>
> To start off, enclose your original conditional statement in parentheses.
> That way you don't have to treat the beginning and end of the statement as
> a special case. As you process the conditional statement, whenever you hit
> a left parenthesis, save your current status and begin processing as
though
> you were examining a new statement. You'll need an array to keep track of
> your status so you can handle multiple levels of parentheses. When you hit
> a right parenthesis, take the value of the statement evaluated so far
(TRUE
> or FALSE) and jump back to the previous level. The TRUE/FALSE value would
> replace the part of the statement that was in parentheses. Continue until
> you get to the end of your conditional statement. You'll need to monitor
> your array counter. Ideally, the array will be empty when you're done!
> Otherwise, you have too many left or right parentheses.
>
> Let's take a look at your example statement
>
> a=b and (c=d or c=e or c=f)
>
> Using the above logic, the program would evaluate "(c=d or c=e or c=f)" as
> an individual statement.
> Let's assume that evaluates as TRUE. Then the program would "see" the
> statement as
>
> a=b and TRUE
>
> To illustrate multiple levels of parentheses, let's try
>
> a=b and (c=d and (e=f or e=g))
>
> The innermost statement "(e=f or e=g)" would be evaluated as an individual
> statement (let's assume TRUE).
> The program would then "see"
>
> a=b and (c=d and TRUE)
>
> The new innermost statement "(c=d and TRUE)" would be evaluated as an
> individual statement (let's assume FALSE).
> The program would then "see"
>
> a=b and FALSE
>
>
> Hopefully this will give you some ideas to work with. Let me know if I
need
> to clarify.
>
> Richard Casey
>
>
> -----Original Message-----
> From: Terry Grider [SMTP:tgrider@arkansas.net]
> Sent: Monday, October 23, 2000 12:44 PM
> To: MIDRANGE-L@midrange.com
> Subject: Re: Evaluate complex conditions
>
> Sorry guys,  I didn't do a very good job of explaining what I was looking
> for.
> I don't mean I want code that is an example of testing for complex
> conditions, I
> mean I'm looking for code that will evaluate statements like the one in my
> original example and determine the truth of the statement.  You see, I'm
> writing
> a query tool and I want the user to be able to provide selection criteria
> in an
> english style IF format similar to cobol or other query tools I've seen.
I
> can
> currently handle simple criteria with "and/or" connectors, but I can't
seem
> to
> come up with a good method for handling multiple levels of parenthesis.
>
> +---
> | This is the Midrange System Mailing List!
> | To submit a new message, send your mail to MIDRANGE-L@midrange.com.
> | To subscribe to this list send email to MIDRANGE-L-SUB@midrange.com.
> | To unsubscribe from this list send email to
MIDRANGE-L-UNSUB@midrange.com.
> | Questions should be directed to the list owner/operator:
david@midrange.com
> +---

+---
| This is the Midrange System Mailing List!
| To submit a new message, send your mail to MIDRANGE-L@midrange.com.
| To subscribe to this list send email to MIDRANGE-L-SUB@midrange.com.
| To unsubscribe from this list send email to MIDRANGE-L-UNSUB@midrange.com.
| Questions should be directed to the list owner/operator: david@midrange.com
+---

As an Amazon Associate we earn from qualifying purchases.

This thread ...

Replies:

Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].

Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.