-
Notifications
You must be signed in to change notification settings - Fork 0
/
symtable.h
executable file
·191 lines (147 loc) · 4.48 KB
/
symtable.h
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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
/**
* Projekt: IFJ2021
*
* @brief Implementace Tabulky symbolu.
*
* @author Vít Janeček [email protected]
*
* @property Kostra je založena na základě IAL DU1 a DU2
*/
#ifndef _SYMTABLE_H
#define _SYMTABLE_H
#include <stdio.h>
#include <stdbool.h>
#include "Dynamic_string.h"
#include "error.h"
#include "instruct_dllist.h"
/**
* @enum Typy promennych.
*/
typedef enum {
TYPE_UNDEFINED,
TYPE_INTEGER,
TYPE_NUMBER,
TYPE_STRING,
TYPE_NIL
}Data_type;
/**
* @struct Struktura reprezentujici data pro seznam parametru.
*/
typedef struct SLLElement_Param {
/** Data parametru*/
Data_type type;
Dynamic_string *name;
/** Ukazatel na nasledujici prvek seznamu. */
struct SLLElement_Param *nextElement;
} *SLLElementPtr_Param;
/**
* @struct Struktura reprezentujici seznam parametru.
*/
typedef struct {
/** Ukazatel na první prvek seznamu. */
SLLElementPtr_Param firstElement;
} SLList_Param;
/**
* @struct Struktura reprezentujici data pro seznam navratovych typu.
*/
typedef struct SLLElement_Return {
/** Data navratove hodnoty*/
Data_type type;
/** Ukazatel na nasledujici prvek seznamu. */
struct SLLElement_Return *nextElement;
} *SLLElementPtr_Return;
/**
* @struct Struktura reprezentujici seznam navratovych typu.
*/
typedef struct {
/** Ukazatel na první prvek seznamu. */
SLLElementPtr_Return firstElement;
} SLList_Return;
/**
* @struct Struktura reprezentujici data pro promenne v BVS.
*/
typedef struct Table_data_var{
/** Data pro promennou. */
Data_type type;
bool init;
bool used;
}Table_data_var_t;
/**
* @struct Struktura reprezentujici data pro funce v BVS.
*/
typedef struct Table_data_func{
/** Ukazatel na seznam parametru*/
SLList_Param *paramList;
/** Ukazatel na seznam navratovych typu*/
SLList_Return *returnList;
/** Fce definovana*/
bool def;
/** Fce deklarovana*/
bool dec;
} Table_data_func_t;
/**
* @struct Struktura reprezentujici uzel v Binarnim vyhledavacim strome.
*/
typedef struct bst_node{
/** Data pro uzel*/
Dynamic_string *name;
bool isFnc;
/** Ukazatel na structuru dat pro promennou*/
struct Table_data_var *varData;
/** Ukazatel na structuru dat pro funkci*/
struct Table_data_func *funcData;
/** Ukazatel na levy podstrom*/
struct bst_node *left;
/** Ukazatel na pravy podstrom*/
struct bst_node *right;
} bst_node_t;
/**
* @struct Struktura reprezentujici data pro Tabulku symbolu.
*/
typedef struct SLLElement_Frame {
/** Ukazatel na koren BVS. */
struct bst_node *node;
/** Ukazatel na predchazejici prvek seznamu. */
struct SLLElement_Frame *previousElement;
} *SLLElementPtr_Frame;
/**
* @struct Struktura reprezentujici Tabulku szmbolu.
*/
typedef struct {
/** Ukazatel na posledni prvek lokalnich Framu seznamu. */
SLLElementPtr_Frame TopLocalElement;
/** Ukazatel na globalni Frame seznamu. */
SLLElementPtr_Frame globalElement;
} SLList_Frame;
void SLL_Param_Init(SLList_Param *listParam);
int SLL_Param_Insert(Data_type type, Dynamic_string *stringName, bst_node_t *tree);
void SLL_Param_Dispose(SLList_Param *listParam);
void SLL_Return_Init(SLList_Return *listReturn);
int SLL_Return_Insert(Data_type type, bst_node_t *tree);
void SLL_Return_Dispose(SLList_Return *listReturn);
void bst_init(bst_node_t **tree);
bst_node_t *bst_search(bst_node_t *tree, Dynamic_string *string);
int bst_insert(bst_node_t **tree, Dynamic_string *string, bool isFnc);
void bst_dispose(bst_node_t **tree);
int bst_by_preorder_add(bst_node_t *tree, DLList_Instruct *listInstruct);
void SLL_Frame_Init(SLList_Frame *listFrame);
int SLL_Frame_Insert(SLList_Frame *listFrame);
void SLL_Frame_Dispose(SLList_Frame *listFrame);
void SLL_Frame_Delete(SLList_Frame *listFrame);
void SLL_Frame_DeleteGlobal(SLList_Frame *listFrame);
bst_node_t *search_Iden(Dynamic_string *, SLList_Frame *listFrame);
int getAllVar(DLList_Instruct *listInstruct, SLList_Frame *listFrame);
void setFncDec(bst_node_t *tree, bool dec);
void setFncDef(bst_node_t *tree, bool def);
void setVarType(bst_node_t *tree, Data_type type);
void setVarInit(bst_node_t *tree, bool init);
void setVarUsed(bst_node_t *tree, bool used);
bool isFnc(bst_node_t *tree);
bool isDecFnc(bst_node_t *tree);
bool isDefFnc(bst_node_t *tree);
bool isInitVar(bst_node_t *tree);
bool isUsedVar(bst_node_t *tree);
Data_type typeVar(bst_node_t *tree);
int setBuildInFuns(SLLElementPtr_Frame globalElement);
#endif
/** @endcode */