| delorie.com/archives/browse.cgi | search | 
| From: | sparhawk AT eunet DOT at (Gerhard Gruber) | 
| Newsgroups: | comp.os.msdos.djgpp | 
| Subject: | Re: Q: How to call a function like search(sentence for string1 AND (string2 OR string3)) | 
| Date: | Sat, 16 May 1998 20:09:49 GMT | 
| Organization: | Customer of EUnet Austria | 
| Lines: | 29 | 
| Message-ID: | <35656c7c.3096331@news.Austria.EU.net> | 
| References: | <355c8df9 DOT 92989021 AT news> | 
| NNTP-Posting-Host: | e160.dynamic.vienna.at.eu.net | 
| Mime-Version: | 1.0 | 
| To: | djgpp AT delorie DOT com | 
| DJ-Gateway: | from newsgroup comp.os.msdos.djgpp | 
Destination: random AT NO-FREAKIN'-SPAM.visi.net (Michael Bosley)
From: Gruber Gerhard
Group: comp.os.msdos.djgpp
Date: Fri, 15 May 1998 18:53:21 GMT:
>This would equate to something like:
>int result = search("This is a test sentence", "test AND (this OR
>This)")
>
>But the problem with that is parsing out all of the extraneous data...
The AND is quite easy. Simply go from left to right and check the expression.
If one of them is false then the entire expression is false and you can
return. With the OR statemant you might construct a list of all values that
belong to a particular or and treat it as a list. Then you loop over the list
and check if one of the values is true. On the first true you encounter the
(sub)expression is also true and you can return.
The only problem is that you might have to do a little parsing grouping all
ANDs and ORs together (depending also on brackets).
--
Bye,
   Gerhard
email: sparhawk AT eunet DOT at
       g DOT gruber AT sis DOT co DOT at
Spelling corrections are appreciated.
| webmaster | delorie software privacy | 
| Copyright © 2019 by DJ Delorie | Updated Jul 2019 |