-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathboolExpressions.h
78 lines (65 loc) · 1.9 KB
/
boolExpressions.h
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
#ifndef __BOOLEXPRESSIONS_H
#define __BOOLEXPRESSIONS_H
#include "ast.h"
#include "expressions.h"
// this is an abstract class
class BoolExp : public ASTnode
{
public: // some members should be private ...
/* generate code for boolean expression. The code should jump to
truelabel or to falselabel depending on the value of the expression.
truelabel may be FALL_THROUGH meaning code should fall through to
next instruction (rather than jump to a label) when the expression is
true. falselabel may also be FALL_TROUGH */
virtual void genBoolExp(int truelabel, int falselabel) = 0; // every subclass should
// override this (or be abstract too)
};
// nodes for simple boolean expressions having the form
// expression RELOP expression
// for example a < b
// another example: (a + 3) < (z * 5 + y).
class SimpleBoolExp : public BoolExp
{
private:
enum op op;
Exp* left; // left operand
Exp* right; // right operand
public:
SimpleBoolExp(enum op op, Exp* left, Exp* right);
void genBoolExp(int truelabel, int falselabel); // override
};
class Or : public BoolExp
{
private:
BoolExp* left; // left operand
BoolExp* right; // right operand
public:
Or(BoolExp* left, BoolExp* right);
void genBoolExp(int truelabel, int falselabel); // override
};
class And : public BoolExp
{
private:
BoolExp* left; // left operand
BoolExp* right; // right operand
public:
And(BoolExp* left, BoolExp* right);
void genBoolExp(int truelabel, int falselabel); // override
};
class Not : public BoolExp
{
private:
BoolExp* operand;
public:
Not(BoolExp* operand);
void genBoolExp(int truelabel, int falselabel); // override
};
//class Nand : public BoolExp {
//public:
// Nand(BoolExp* left, BoolExp* right) { _left = left; _right = right; }
// void genBoolExp(int truelabel, int falselabel); // override
//
// BoolExp* _left; // left operand
// BoolExp* _right; // right operand
//};
#endif