File: non-string-nodes.cpp

package info (click to toggle)
boolstuff 0.1.11-1
  • links: PTS
  • area: main
  • in suites: lenny
  • size: 1,664 kB
  • ctags: 152
  • sloc: sh: 8,653; cpp: 1,435; makefile: 200; ansic: 162; perl: 106
file content (74 lines) | stat: -rw-r--r-- 1,428 bytes parent folder | download | duplicates (2)
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
/*  $Id: non-string-nodes.cpp,v 1.1 2005/02/03 23:28:34 sarrazip Exp $
    Example where the expression tree nodes are not based on strings.

    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;


class Node
{
public:
    Node(int n = 0) : value(n) {}
    int value;
};


ostream &operator << (ostream &out, const Node &n)
{
    return out << n.value;
}

bool operator == (Node a, Node b)
{
    return a.value == b.value;
}

bool operator < (Node a, Node b)
{
    return a.value < b.value;
}


int main(int argc, char *argv[])
{
    {
	try
	{
	    // Form the expression 11 & (22 | 33):
	    BoolExpr<Node> *a = new BoolExpr<Node>(11);
	    BoolExpr<Node> *b = new BoolExpr<Node>(22);
	    BoolExpr<Node> *c = new BoolExpr<Node>(33);
	    BoolExpr<Node> *orOper =
			    new BoolExpr<Node>(BoolExpr<Node>::OR, b, c);
	    BoolExpr<Node> *expr =
			    new BoolExpr<Node>(BoolExpr<Node>::AND, a, orOper);

	    cout << expr << "\n";

	    expr = BoolExpr<Node>::getDisjunctiveNormalForm(expr);
	    if (expr != NULL)
		cout << expr;
	    else
		cout << "FALSE";

	    cout << "\n";

	    delete expr;
	}
	catch (BoolExprParser::Error &err)
	{
	    cerr << "Column " << err.index + 1
		<< ": error #" << err.code << endl;
	}
    }

    return EXIT_SUCCESS;
}