-
Notifications
You must be signed in to change notification settings - Fork 0
/
table_label.cpp
92 lines (78 loc) · 1.33 KB
/
table_label.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
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
#include "table_label.h"
using namespace std;
table_label TL(1000);
Label::Label()
{
declare = false;
}
char * Label::get_name()
{
return name;
}
void Label::put_name(const char * n)
{
name = new char[strlen(n) + 1];
strcpy(name, n);
}
bool Label::get_declare()
{
return declare;
}
void Label::put_declare()
{
declare = true;
}
int Label::get_position()
{
return position;
}
void Label::put_position(int p)
{
position = p;
}
table_label::table_label(int max_size)
{
l = new Label[size = max_size];
top = 0;
}
table_label::~table_label()
{
delete []l;
}
Label& table_label::operator[] (int k)
{
return l[k];
}
void table_label::reset()
{
delete []l;
}
void table_label::print()
{
for (int j = 1; j < top;j++)
cout << l[j].get_position();
}
bool table_label::check_TL()
{
for(int i = 0; i < top; i++)
{
if(l[i].get_declare() == false)
{
return false;
}
}
return true;
}
int table_label::put(const char *buf) // проверка слова есть ли оно в таблице идентефикаторов или нужно его добавить в конец таблицы
{
for (int j = 0; j < top; j++)
{
if (!strcmp(buf, l[j].get_name()))
{
return j;
}
}
l[top].put_name(buf);
top++;
return top-1;
}