-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathExpr_Tree_Builder.cpp
More file actions
52 lines (41 loc) · 1.25 KB
/
Expr_Tree_Builder.cpp
File metadata and controls
52 lines (41 loc) · 1.25 KB
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
#include "Expr_Tree_Builder.h"
Expr_Tree_Builder::Expr_Tree_Builder ()
: expressions (Stack<Calculator *>())
{
expressions.push(new Calculator());
}
Expr_Tree_Builder::~Expr_Tree_Builder () {
while (!expressions.is_empty()) {
delete expressions.top();
expressions.pop();
}
}
void Expr_Tree_Builder::build_number (int num) {
expressions.top()->addCommand(new Number_Command(num));
}
void Expr_Tree_Builder::build_add_operator () {
expressions.top()->addOp(new Add_Command());
}
void Expr_Tree_Builder::build_subtract_operator () {
expressions.top()->addOp(new Subtract_Command());
}
void Expr_Tree_Builder::build_multiply_operator () {
expressions.top()->addOp(new Multiply_Command());
}
void Expr_Tree_Builder::build_divide_operator () {
expressions.top()->addOp(new Divide_Command());
}
void Expr_Tree_Builder::build_modulus_operator () {
expressions.top()->addOp(new Modulus_Command());
}
void Expr_Tree_Builder::build_open_parenthesis () {
expressions.push(new Calculator());
}
void Expr_Tree_Builder::build_close_parenthesis () {
Expr_Command * head = expressions.top()->get_expression();
expressions.pop();
expressions.top()->addCommand(head);
}
Expr_Command * Expr_Tree_Builder::get_expression () {
return expressions.top()->get_expression();
}