1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80
|
/* $Id: example.cpp,v 1.4 2005/02/03 23:26:43 sarrazip Exp $
Testing program for the library.
Written by Pierre Sarrazin <http://sarrazip.com/>
This file is in the public domain.
*/
#include <boolstuff/BoolExprParser.h>
#include <assert.h>
#include <stdlib.h>
using namespace std;
using namespace boolstuff;
static
ostream &
operator << (ostream &out, const set<string> &s)
{
for (set<string>::const_iterator it = s.begin(); it != s.end(); it++)
out << *it << " ";
return out;
}
int main(int argc, char *argv[])
{
BoolExprParser parser;
string line;
while (getline(cin, line))
{
try
{
BoolExpr<string> *expr = parser.parse(line);
cout << "Original expression : " << flush;
assert(expr != NULL);
expr->print(cout);
cout << "\n";
expr = BoolExpr<string>::getDisjunctiveNormalForm(expr);
cout << "Disjunctive normal form : ";
if (expr != NULL)
cout << expr;
else
cout << "FALSE";
cout << "\n";
if (expr != NULL)
{
typedef vector<const BoolExpr<string> *> V;
typedef V::const_iterator IT;
V termRoots;
expr->getDNFTermRoots(inserter(termRoots, termRoots.end()));
for (IT it = termRoots.begin(); it != termRoots.end(); it++)
{
const BoolExpr<string> *term = *it;
set<string> positives, negatives;
term->getTreeVariables(positives, negatives);
cout << "Term : " << term << "\n";
cout << " Positives: " << positives << "\n";
cout << " Negatives: " << negatives << "\n";
}
}
cout << "\n";
delete expr;
}
catch (BoolExprParser::Error &err)
{
cerr << "Column " << err.index + 1
<< ": error #" << err.code << endl;
}
}
return EXIT_SUCCESS;
}
|