-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathIT.cpp
97 lines (89 loc) · 3.27 KB
/
IT.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
93
94
95
96
97
#include "stdafx.h"
#include "IT.h"
#include "Error.h"
#include<iomanip>
namespace IT
{
IdTable Create(int size)
{
IdTable* tabl = new IdTable;
if (size > TI_MAXSIZE) throw ERROR_THROW(160);
tabl->maxsize = size;
tabl->size = 0;
tabl->table = new Entry[size];
return*tabl;
}
void Add(IdTable& idtable, Entry entry)
{
if (idtable.size + 1 > idtable.maxsize)
throw ERROR_THROW(161);
idtable.table[idtable.size] = entry;
idtable.size += 1;
}
Entry GetEntry(IdTable& idtable, int n)
{
return idtable.table[n];
}
int IsId(IdTable& idtable, char id[ID_MAXSIZE])
{
for (int i = 0; i < idtable.size; i++)
{
if (strcmp(idtable.table[i].id, id) == 0) return i;
}
return TI_NULLIDX;
}
void Delete(IdTable& idtable)
{
delete[] idtable.table;
}
void showTable(IdTable& idtable)
{
int i, j, numberOP = 0;
std::cout << std::setfill('-') << std::setw(87) << '-' << std::endl;
std::cout << " ¹" << " | " << "Èäåíòèôèêàòîð" << " | " << "Òèï äàííûõ" << " | " << "Òèï èäåíòèôèêàòîðà" << " | " << "Èíäåêñ â ÒË" << " | " << "Çíà÷åíèå " << std::endl;
std::cout << std::setw(87) << '-' << std::endl;
for (i = 0, j = 0; i < idtable.size; i++, j++)
{
if (idtable.table[i].idtype == OP)
{
numberOP++;
j--;
continue;
}
std::cout << std::setfill('0') << std::setw(4) << std::right << j << " | ";
std::cout << std::setfill(' ') << std::setw(13) << std::left << idtable.table[i].id << " | ";
switch (idtable.table[i].iddatatype)
{
case INT: std::cout << std::setw(10) << std::left;
if (idtable.table[i].idtype == OP) std::cout << "-" << " | ";
else std::cout << "integer" << " | "; break;
case STR: std::cout << std::setw(10) << std::left;
if (idtable.table[i].idtype == OP) std::cout << "-" << " | ";
else std::cout << "string" << " | "; break;
default: std::cout << std::setw(10) << std::left << "unknown" << " | "; break;
}
switch (idtable.table[i].idtype)
{
case V: std::cout << std::setw(18) << std::left << "ïåðåìåííàÿ" << " | "; break;
case F: std::cout << std::setw(18) << std::left << "ôóíêöèÿ" << " | "; break;
case P: std::cout << std::setw(18) << std::left << "ïàðàìåòð" << " | "; break;
case L: std::cout << std::setw(18) << std::left << "ëèòåðàë" << " | "; break;
case OP: std::cout << std::setw(18) << std::left << "îïåðàòîð" << " | ";
numberOP++;
break;
default: std::cout << std::setw(18) << std::left << "unknown" << " | "; break;
}
std::cout << std::setw(11) << std::left << idtable.table[i].idxfirstLE << " | ";
if (idtable.table[i].iddatatype == INT && (idtable.table[i].idtype == V || idtable.table[i].idtype == L))
std::cout << std::setw(18) << std::left << idtable.table[i].value.vint;
else if (idtable.table[i].iddatatype == STR && (idtable.table[i].idtype == V || idtable.table[i].idtype == L))
std::cout << "[" << idtable.table[i].value.vstr.len << "]\"" << idtable.table[i].value.vstr.str << "\"";
else
std::cout << "-";
std::cout << std::endl;
}
std::cout << std::setfill('-') << std::setw(87) << '-' << std::endl;
std::cout << "Êîëè÷åñòâî èäåíòèôèêàòîðîâ: " << i - numberOP << std::endl;
std::cout << std::setw(87) << '-' << std::endl;
}
};