-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathOperation.cpp
55 lines (51 loc) · 1.41 KB
/
Operation.cpp
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
/*
* 04.09.2022
*
* Operation.cpp: implementation file for the Operation class
*
*/
#include <sstream>
#include "Operation.h"
/*
* _update_sequence(const Token& t)
* input: a Token object of any type
* output: a character to push to individual sequence string
* goal: determines what kind of character to return based on Token type
*/
char Operation::_update_sequence(const Token& t) {
char ch = '\0';
switch (t._type) {
case OPERATOR: ch = 'O'; break;
case BOOLEAN: ch = 'B'; break;
case NUMERIC: ch = 'N'; break;
}
return ch;
}
/*
* set_operand(const Token& t)
* input: a Token object of non-OPERATOR type
* output: none
* goal:
* - places the decoded token into the _operands vector
* - updates the sequence based on the type of the Token
*/
void Operation::set_operand(const Token& t) {
_operands.push_back(t);
_sequence.push_back(_update_sequence(t));
}
/*
* set_operator
* input: a Token object with type OPERATOR
* output: none
* goal:
* - determines which Operator object to store from the operators vector based on the opcode given in the token
* - updates the sequence string
*/
void Operation::set_operator(const Token& t) {
_operator._name = t._op._name;
_operator._arity = t._op._arity;
_operator._notation = t._op._notation;
_operator._sequence = t._op._sequence;
_operator._id = t._op._id;
Operation::_sequence.push_back(_update_sequence(t));
}