473,506 Members | 16,954 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)||....(Asn&&/||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&&Cs2).....
(As1||Bs1||Cs1)||(As2||Bs2||Cs2)
(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)&&(Cs2&&Ds2)&&(Es3&&Fs3)
(As1||Bs1)&&(Cs2||Ds2)&&(Es3||Fs3)
-One OR (2 AND) case:
(As1||Bs1)&&(Cs2&&Ds2)&&(Es3&&Fs3)
(As1&&Bs1)&&(Cs2||Ds2)&&(Es3&&Fs3)
(As1&&Bs1)&&(Cs2&&Ds2)&&(Es3||Fs3)
-Two OR (1 AND) cases:
(As1||Bs1)&&(Cs2||Ds2)&&(Es3&&Fs3)
(As1&&Bs1)&&(Cs2||Ds2)&&(Es3||Fs3)
(As1||Bs1)&&(Cs2&&Ds2)&&(Es3||Fs3)
-Partial :
-All AND/OR: (inner)
(As1&&Bs1)&&(Cs2&&Ds2)
(As1||Bs1)&&(Cs2||Ds2)
As1&&Cs2
As1&&Cs2&&Es3
-partial some AND,some OR:
(As1||Bs1)&&(As2&&Bs2)
(AS1&&Bs1)&&(As2||Bs1)
(As1||Bs1)&&(As2||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)||(As1&&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||Cs2 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 2095
On Aug 27, 10:31 pm, sunil <sunilsreenivas2...@yahoo.comwrote:
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)||....(Asn&&/||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&&Cs2).....
(As1||Bs1||Cs1)||(As2||Bs2||Cs2)
(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)&&(Cs2&&Ds2)&&(Es3&&Fs3)
(As1||Bs1)&&(Cs2||Ds2)&&(Es3||Fs3)
-One OR (2 AND) case:
(As1||Bs1)&&(Cs2&&Ds2)&&(Es3&&Fs3)
(As1&&Bs1)&&(Cs2||Ds2)&&(Es3&&Fs3)
(As1&&Bs1)&&(Cs2&&Ds2)&&(Es3||Fs3)
-Two OR (1 AND) cases:
(As1||Bs1)&&(Cs2||Ds2)&&(Es3&&Fs3)
(As1&&Bs1)&&(Cs2||Ds2)&&(Es3||Fs3)
(As1||Bs1)&&(Cs2&&Ds2)&&(Es3||Fs3)
-Partial :
-All AND/OR: (inner)
(As1&&Bs1)&&(Cs2&&Ds2)
(As1||Bs1)&&(Cs2||Ds2)
As1&&Cs2
As1&&Cs2&&Es3
-partial some AND,some OR:
(As1||Bs1)&&(As2&&Bs2)
(AS1&&Bs1)&&(As2||Bs1)
(As1||Bs1)&&(As2||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
3196
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...
9
10333
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...
4
2192
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 = " ...
6
1534
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...
2
2017
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...
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...
19
2288
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...
20
13701
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...
20
2097
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...
0
7218
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
7370
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...
0
7478
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
5614
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,...
1
5035
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...
0
3188
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...
0
3177
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1532
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
755
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.