-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFactor.cpp
More file actions
60 lines (51 loc) · 1.12 KB
/
Factor.cpp
File metadata and controls
60 lines (51 loc) · 1.12 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
53
54
55
56
57
58
59
60
#include <stdlib.h>
#include "Factor.h"
#include "Expression.h"
#include "LeftParenthesis.h"
#include "RightParenthesis.h"
#include "Number.h"
Factor::Factor (void)
: leftParenthesis_ (nullptr), rightParenthesis_ (nullptr),
expression_ (nullptr), number_ (nullptr)
{
}
Factor::~Factor (void)
{
delete this->leftParenthesis_;
delete this->rightParenthesis_;
delete this->expression_;
delete this->number_;
}
int Factor::evaluate (void)
{
int result = 0;
if (this->expression_ != nullptr)
{
result = this->expression_->evaluate ();
}
else if (this->number_ != nullptr)
{
result = this->number_->evaluate ();
}
return result;
}
void Factor::accept (SymbolVisitor & visitor)
{
visitor.visitFactor (*this);
}
void Factor::setLeftParenthesis (LeftParenthesis * leftParenthesis)
{
this->leftParenthesis_ = leftParenthesis;
}
void Factor::setExpression (Expression * expression)
{
this->expression_ = expression;
}
void Factor::setRightParenthesis (RightParenthesis * rightParenthesis)
{
this->rightParenthesis_ = rightParenthesis;
}
void Factor::setNumber (Number * number)
{
this->number_ = number;
}