forked from devaigergely81/flex-bison-example
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathimplementation.cc
132 lines (102 loc) · 3.25 KB
/
implementation.cc
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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
#include "implementation.hh"
#include <iostream>
#include <sstream>
mode current_mode;
void error(int line, std::string text) {
std::cerr << "Line " << line << ": Error: " << text << std::endl;
exit(1);
}
expression::~expression() {
}
number_expression::number_expression(std::string text) {
std::stringstream ss(text);
ss >> value;
}
boolean_expression::boolean_expression(bool _value) {
value = _value;
}
long id = 0;
symbol::symbol(int _line, std::string _name, type _type) : line(_line), name(_name), symbol_type(_type) {
label = next_label();
}
id_expression::id_expression(int _line, std::string _name)
: line(_line), name(_name)
{}
binop_expression::~binop_expression() {
delete left;
delete right;
}
binop_expression::binop_expression(int _line, std::string _op, expression* _left, expression* _right)
: line(_line), op(_op), left(_left), right(_right)
{}
trinaryop_expression::trinaryop_expression(int _line, expression* _cond, expression* _left, expression* _right)
: line(_line), cond(_cond), left(_left), right(_right)
{}
trinaryop_expression::~trinaryop_expression() {
delete cond;
delete left;
delete right;
}
not_expression::~not_expression() {
delete operand;
}
not_expression::not_expression(int _line, std::string _op, expression* _operand)
: line(_line), op(_op), operand(_operand)
{}
instruction::instruction(int _line)
: line(_line)
{}
instruction::~instruction() {
}
int instruction::get_line() {
return line;
}
assign_instructions::assign_instructions(int _line, std::list<std::string>* _left, std::list<expression*>* _right)
: instruction(_line), left(_left), right(_right)
{}
assign_instructions::~assign_instructions() {
//TODO: proper free
delete right;
}
read_instruction::read_instruction(int _line, std::string _id)
: instruction(_line), id(_id)
{}
write_instruction::write_instruction(int _line, expression* _exp)
: instruction(_line), exp(_exp)
{}
write_instruction::~write_instruction() {
delete exp;
}
if_instruction::if_instruction(int _line, expression* _condition, std::list<instruction*>* _true_branch, std::list<instruction*>* _false_branch)
: instruction(_line), condition(_condition), true_branch(_true_branch), false_branch(_false_branch)
{}
if_instruction::~if_instruction() {
delete condition;
delete_commands(true_branch);
delete_commands(false_branch);
}
while_instruction::while_instruction(int _line, expression* _condition, std::list<instruction*>* _body)
: instruction(_line), condition(_condition), body(_body)
{}
while_instruction::~while_instruction() {
delete condition;
delete_commands(body);
}
for_instruction::for_instruction(int _line, std::string _id, expression* _lowerlimit, expression* _upperlimit, std::list<instruction*>* _body)
: instruction(_line), id(_id), lowerlimit(_lowerlimit), upperlimit(_upperlimit), body(_body)
{}
for_instruction::~for_instruction() {
delete lowerlimit;
delete upperlimit;
delete_commands(body);
}
void delete_commands(std::list<instruction*>* commands) {
if(!commands) {
return;
}
std::list<instruction*>::iterator it;
for(it = commands->begin(); it != commands->end(); ++it) {
delete (*it);
}
delete commands;
}