-
Notifications
You must be signed in to change notification settings - Fork 0
/
symtable.h
56 lines (42 loc) · 1.16 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
#ifndef SYMTABLE_H
#define SYMTABLE_H
#define MAX_NAME_LENGTH 20
#define MAX_SYMBOLS_PER_TABLE 10
struct symbolAttributes{
int type;
int initialized;
int references;
int scope;
int array;
int arrSize;
/* if symbol is a parameter, parameters is the
* order of the parameter in the function, e.g. 1st, 2nd...
* if symbol is a func, it is the # of parameters. else it is 0
*/
int parameters;
int localVarStackOffset;
int regContainingArrIndex;
};
struct symbolEntry{
char id[MAX_NAME_LENGTH];
int type; /*variable or function*/
struct symbolAttributes attr;
};
struct symbolTable{
struct symbolEntry symTab[MAX_SYMBOLS_PER_TABLE];
struct symbolTable *outerScope;
int numOfSym;
int numOfLocalVar;
};
struct symbolAttributes parsedSymbolAttributes;
struct symbolTable globalSymTab;
struct symbolTable *CurrentScope;
struct symbolEntry *lookUpSym(char *id);
void insertSym(char *id, struct symbolAttributes attr, int type);
void insertGlobalSym(char *id, struct symbolAttributes attr, int type);
void initializeScope();
void finalizeScope();
void printSym(struct symbolEntry sym);
void resetparsedSymbolAttributes();
int inFunctionBody();
#endif