473,657 Members | 2,434 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

boolean expression checker/matcher

Hello,
I have a boolean expression thats specified in pre/in/post fix
notations, lets assume infix for the sake of this argument. The
expression can be in any of the following forms:
Form A:
-------------
(As1&&/||Bs1&&/||Cs1 )|| (As2&&/||Bs2&&/||Cs2)||....(As n&&/||Bsn&&/||
Csn) with following rules:
-Inner ANDs/ORs are optional but if they are specified in one nesting
they must be specified in all nestings with same connector type across
all.
-Each boolean variable is identified by two attributes ex: As1: A is
the condition while s1 is the data on which the condition is operating
(this data could be like instance of same class), so As1 could be
interpreted as
attribute X of Class s1 100
so the list of possible legal expansions for this (for n=2) is:
(As1&&Bs1&&Cs1) ||(As2&&Bs2&&Cs 2).....
(As1||Bs1||Cs1) ||(As2||Bs2||Cs 2)
(As1&&Bs1) || (As2&&Bs2)....
(As1||Bs1) || (As2||Bs2)...
As1&&As2....
As1 || As2...
Form B:
------------
(As1&&/||Bs1)&&(Cs2&&/||Ds2)&&(Es3&&/||Fs3) this has slightly
different rules:
-Inner AND/ORs are optional and if they are specified for one nesting
they need not be specified for another nesting.
-Each boolean variable is identified as before by two attributes:
As1, A:condition s1: data on which condition operates
-max # nestings limited to 3
-max # variables in each nesting is limited to 2
because of rule1, the # of legal expansions is now a lot
so list of possible combinations would include:
-All AND/OR cases:
(As1&&Bs1)&&(Cs 2&&Ds2)&&(Es3&& Fs3)
(As1||Bs1)&&(Cs 2||Ds2)&&(Es3|| Fs3)
-One OR (2 AND) case:
(As1||Bs1)&&(Cs 2&&Ds2)&&(Es3&& Fs3)
(As1&&Bs1)&&(Cs 2||Ds2)&&(Es3&& Fs3)
(As1&&Bs1)&&(Cs 2&&Ds2)&&(Es3|| Fs3)
-Two OR (1 AND) cases:
(As1||Bs1)&&(Cs 2||Ds2)&&(Es3&& Fs3)
(As1&&Bs1)&&(Cs 2||Ds2)&&(Es3|| Fs3)
(As1||Bs1)&&(Cs 2&&Ds2)&&(Es3|| Fs3)
-Partial :
-All AND/OR: (inner)
(As1&&Bs1)&&(Cs 2&&Ds2)
(As1||Bs1)&&(Cs 2||Ds2)
As1&&Cs2
As1&&Cs2&&Es3
-partial some AND,some OR:
(As1||Bs1)&&(As 2&&Bs2)
(AS1&&Bs1)&&(As 2||Bs1)
(As1||Bs1)&&(As 2||Bs2)
(As1||Bs1)&&As2
(As1&&Bs1)&&As2
As1&&(As2&&Bs2)
As1&&(As2||Bs2)
(As1||Bs1)&&Cs2 &&(Es3&&Fs4)
(As1||Bs1)&&Cs2 &&(Es3||Fs4)
As1&&Cs2&&(Es3& &Fs4)
(AS1||BS1)&&Cs2 &&Es3....... . (list may not be complete)
I want to write a C++ program which would take in an expression in one
of the forms: pre/in/post fix forms and would try to check if it
matches one of these forms, the program should tell whats the form
type(A/B) and the expression it has matched with. Whats the best way
to tackle this?

Also the program should be able to handle conversions, example if user
specifies: (As1&&As2)||(As 1&&Bs2) it should convert it As1&&(As2||Bs2)
which is a supported form. If user specifies an expression thats not
supported it should specify how to break this down into minimal #
groupings: ex:As1||As2||Cs 2 would be broken down as (As1||As2)||Cs2 .
As1||As2 is supported expression... (this could also be broken down as
As1||(As2||Cs2) , it would be enough for it to report one form of
expression)
Thanks in advance,
Sunil
Aug 27 '08 #1
1 2108
On Aug 27, 10:31 pm, sunil <sunilsreenivas 2...@yahoo.comw rote:
Hello,
I have a boolean expression thats specified in pre/in/post fix
notations, lets assume infix for the sake of this argument. The
expression can be in any of the following forms:
Form A:
-------------
(As1&&/||Bs1&&/||Cs1 )|| (As2&&/||Bs2&&/||Cs2)||....(As n&&/||Bsn&&/||
Csn) with following rules:
-Inner ANDs/ORs are optional but if they are specified in one nesting
they must be specified in all nestings with same connector type across
all.
-Each boolean variable is identified by two attributes ex: As1: A is
the condition while s1 is the data on which the condition is operating
(this data could be like instance of same class), so As1 could be
interpreted as
attribute X of Class s1 100
so the list of possible legal expansions for this (for n=2) is:
(As1&&Bs1&&Cs1) ||(As2&&Bs2&&Cs 2).....
(As1||Bs1||Cs1) ||(As2||Bs2||Cs 2)
(As1&&Bs1) || (As2&&Bs2)....
(As1||Bs1) || (As2||Bs2)...
As1&&As2....
As1 || As2...
Form B:
------------
(As1&&/||Bs1)&&(Cs2&&/||Ds2)&&(Es3&&/||Fs3) this has slightly
different rules:
-Inner AND/ORs are optional and if they are specified for one nesting
they need not be specified for another nesting.
-Each boolean variable is identified as before by two attributes:
As1, A:condition s1: data on which condition operates
-max # nestings limited to 3
-max # variables in each nesting is limited to 2
because of rule1, the # of legal expansions is now a lot
so list of possible combinations would include:
-All AND/OR cases:
(As1&&Bs1)&&(Cs 2&&Ds2)&&(Es3&& Fs3)
(As1||Bs1)&&(Cs 2||Ds2)&&(Es3|| Fs3)
-One OR (2 AND) case:
(As1||Bs1)&&(Cs 2&&Ds2)&&(Es3&& Fs3)
(As1&&Bs1)&&(Cs 2||Ds2)&&(Es3&& Fs3)
(As1&&Bs1)&&(Cs 2&&Ds2)&&(Es3|| Fs3)
-Two OR (1 AND) cases:
(As1||Bs1)&&(Cs 2||Ds2)&&(Es3&& Fs3)
(As1&&Bs1)&&(Cs 2||Ds2)&&(Es3|| Fs3)
(As1||Bs1)&&(Cs 2&&Ds2)&&(Es3|| Fs3)
-Partial :
-All AND/OR: (inner)
(As1&&Bs1)&&(Cs 2&&Ds2)
(As1||Bs1)&&(Cs 2||Ds2)
As1&&Cs2
As1&&Cs2&&Es3
-partial some AND,some OR:
(As1||Bs1)&&(As 2&&Bs2)
(AS1&&Bs1)&&(As 2||Bs1)
(As1||Bs1)&&(As 2||Bs2)
(As1||Bs1)&&As2
(As1&&Bs1)&&As2
As1&&(As2&&Bs2)
As1&&(As2||Bs2)
(As1||Bs1)&&Cs2 &&(Es3&&Fs4)
(As1||Bs1)&&Cs2 &&(Es3||Fs4)
As1&&Cs2&&(Es3& &Fs4)
(AS1||BS1)&&Cs2 &&Es3....... . (list may not be complete)
I want to write a C++ program which would take in an expression in one
of the forms: pre/in/post fix forms and would try to check if it
matches one of these forms, the program should tell whats the form
type(A/B) and the expression it has matched with. Whats the best way
to tackle this?
Its not really a C++ issue. Really its about grammar.

For a vulgar American slang parser , try bison.

For a more sophisticated inclusive multicultural parser (niceley
beyond reach of the americans) try slk.

regards
Andy Little

Aug 28 '08 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

23
3220
by: Paul Rubin | last post by:
OK, I want to scan a file for lines matching a certain regexp. I'd like to use an assignment expression, like for line in file: if (g := re.match(pat, line)): croggle(g.group(1)) Since there are no assignment expressions in Python, I have to use a temp var. That's a little more messy, but bearable:
9
10348
by: Ron Adam | last post by:
Is it possible to match a string to regular expression pattern instead of the other way around? For example, instead of finding a match within a string, I want to find out, (pass or fail), if a string is a partial match to an re. Given an re of 'abcd and a bunch of other stuff' This is what i'm looking for:
4
2203
by: pekka niiranen | last post by:
Hi there, I have perl script that uses dynamically constructed regular in this way: ------perl code starts ---- $result ""; $key = AAA\?01; $key = quotemeta $key; $line = " s^\?AAA\?01^BBB^g; #Comment "
6
1541
by: Mark | last post by:
Hi, why oh why doesn't this work as per any other language I have used regexes with; -------- Regex r = new Regex("{2}"); bool test = r.IsMatch("ACD"); -------- The boolean 'test' is true, despite the {2} quantifier
2
2026
by: ajitgoel | last post by:
Hi; I need some simple help with my regular expressions. I want to search my input text for all the boolean variables which do not start with bln. i.e I want to match "bool followed by 1 or more spaces followed by text other than bln" in my input text. Eg: 1. private bool dispose; should be highlighted 2. private bool blndispose; should be not be highlighted
6
489
by: JohnSouth | last post by:
Hi I've been using a Regular expression to test for valid email addresses. It looks like: \w+(\w+)*@\w+(\w+)*\.\w+(\w+)* I've now had 2 occassions where it has rejected and email address with a "&" character in the local part. I know I should be able to work it out myself, but I'd like to ask anyone to suggest the best way to
19
2302
by: Davy | last post by:
Hi all, I am a C/C++/Perl user and want to switch to Python (I found Python is more similar to C). Does Python support robust regular expression like Perl? And Python and Perl's File content manipulation, which is better? Any suggestions will be appreciated!
20
13727
by: Serge Rielau | last post by:
I'm playing with the ICU library (slow weekend :-) and it's quite simple to expose the regular expression functionality for Unicode databases. Presuming that the majority is not on unicode, would a developerWorks article which supports ASCII only for non unicode DBs be useful? (Otherwise I'll have to do some serious digging for translation tables) Here is an example of what I've got: -- validate Canadian postal code:
20
2124
by: TimeHorse | last post by:
I would like to gauge interest in the following proposal: Problem: Assignment statements cannot be used as expressions. Performing a list of mutually exclusive checks that require data processing can cause excessive tabification. For example, consider the following python snipet...
0
8395
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
8826
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8732
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...
0
8605
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...
1
6166
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4155
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...
0
4306
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
1955
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1615
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.