-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsymtable.h
139 lines (108 loc) · 3.41 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
/***************************
* PROJECT:
* IFJ20 - Compiler for imperative programming language IFJ20
*
* UNIVERSITY:
* Faculty of Information Technology, Brno University of Technology
*
* FILE:
* symtable.h
*
* DESCRIPTION:
* Header file for symtable.c
*
* AUTHOR:
* Žovinec Martin <[email protected]>
*/
#ifndef SYMTABLE_H
#define SYMTABLE_H
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#include <stdbool.h>
#include "str.h"
#define T_INT 30
#define T_FLOAT 31
#define T_STRING 32
#define EMPTY 33
#define PointerError -1
#define AllGood 0
#define BadType 1
#define BadOrder 2
#define BadTypeAndOrder 3
#define ParamList 1
#define ReturnList 2
#define MAX_LIST_LENGHT 100
/* Variable binary tree structure */
typedef struct varStackElement{
int type;
int scope;
struct varStackElement *previousElement;
} *varStackElement;
typedef struct varNode{
string name;
struct varStackElement *varStack;
struct varNode*LPtr;
struct varNode*RPtr;
} *varNode;
/* Function binary tree structures */
typedef struct funNode{
string name;
bool isDeclared;
bool isCalled;
struct funList *parameters;
struct funList *returnCodes;
struct funNode *LPtr;
struct funNode *RPtr;
} *funNode;
typedef struct funListElement{
int type;
int order;
struct funListElement *NextPtr;
} *funListElement;
typedef struct funList{
funListElement First;
int elementCount;
} funList;
/* Prototypes of variable operations */
void BSTInit (varNode*);
varNode BSTSearch(varNode, string);
void BSTInsert (varNode*, string, int, int);
void BSTDispose (varNode*);
bool isDeclared (varNode, string);
int getType (varNode, string);
void ReplaceByRightmost (varNode PtrReplaced, varNode *RootPtr);
void BSTDelete (varNode *RootPtr, string Key);
void BSTScopeDelete(varNode *RootPtr, int newScope);
/* Prototypes of variable stack operations */
void stackPop(varNode* varTree);
void stackPush(varNode* varTree, int type, int scope);
void stackDelete(varNode *varTree);
/* Prototypes of function operations */
void funInit (funNode *RootPtr);
funNode *funSearch (funNode *RootPtr, string Key);
void addFunToTree(funNode *RootPtr, string Key);
void funActualize (funNode *RootPtr, string Key, bool Declaration, bool Call, int paramCount);
void funDisposeTree (funNode *RootPtr);
void addFunCall(funNode *RootPtr, string Key, varNode varTree, int paramCount);
void addFunDec(funNode *RootPtr, string Key, int paramCount);
void addParam(funNode *RootPtr, string Key, int parameterType, int parameterOrder);
void addReturn(funNode *RootPtr, string Key, int returnType, int returnOrder);
void isFunCallDec(funNode RootPtr);
void funReturnCheck(funNode *RootPtr, string Key, int returnCount);
void funListCompareReturn (funList *list, funNode *RootPtr, string Key, int returnCount);
/*Prototypes of function list operations*/
void funListInit (funList *L);
void funListAdd (funList *L, int val, int order);
funListElement funListSearch (funList *L, int order);
void funListDelete(funList *L);
void checkListElement(funList *list, int type, int order);
void compareLists (funList *list1, funList *list2);
/* Prototypes of datastructure printing functions */
char* printType(int typeNum);
void printVarTree(varNode);
void printVarTree2(varNode, char* sufix, char fromdir);
void printFunList(funList TL);
void printFunTree(funNode TempTree);
void printFunTree2(funNode TempTree, char* sufix, char fromdir);
#endif