-
Notifications
You must be signed in to change notification settings - Fork 0
/
Eval_Expr_Tree.h
79 lines (67 loc) · 1.64 KB
/
Eval_Expr_Tree.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
79
// Honor Pledge:
//
// I pledge that I have neither given nor
// received any help on this assignment.
//
// blakbenn
#ifndef _EVAL_EXPR_TREE_H_
#define _EVAL_EXPR_TREE_H_
#include "Stack.h"
#include "Visitor.h"
#include <exception>
//creating our exceptions for divide and mod by zero errors
/**
*@class divide_by_zero_exception
*
*Exception thrown to indicate a divide by zero error
*/
class divide_by_zero_exception : public std::exception
{
public:
divide_by_zero_exception (void):
std::exception()
{
}
};
/**
*@class divide_by_zero_exception
*
*Exception thrown to indicate a divide by zero error
*/
class mod_by_zero_exception : public std::exception
{
public:
mod_by_zero_exception (void):
std::exception()
{
}
};
/**
* @class Eval Expr Tree
*
* Evaluates the expression tree
*/
class Eval_Expr_Tree : public Visitor
{
public:
/// Constructor
Eval_Expr_Tree (void);
/// Destructor
virtual ~Eval_Expr_Tree (void);
/// Visit Add Node
virtual void Visit_Add_Node(Add_Node & add_node);
/// Visit Subtract Node
virtual void Visit_Subtract_Node(Subtract_Node & subtract_node);
/// Visit Multiply Node
virtual void Visit_Multiply_Node(Multiply_Node & multiply_node);
/// Visit Divide Node
virtual void Visit_Divide_Node(Divide_Node & divide_node);
/// Visit Mod Node
virtual void Visit_Mod_Node(Mod_Node & mod_node);
/// Visit Integer Node
virtual void Visit_Integer_Node(Integer_Node & integer_node);
int result();
private:
Stack<int> Result_Stack;
};
#endif // !defined _EVAL_EXPR_TREE_H_