-
Notifications
You must be signed in to change notification settings - Fork 0
/
symboltable.h
73 lines (56 loc) · 2.4 KB
/
symboltable.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
#ifndef SYMBOL_TABLE_H
#define SYMBOL_TABLE_H
#include <stdbool.h>
#include "linkedlist.h"
#include "tree.h"
#include "hashtable.h"
#define SymbolTable LinkedList
#define READ_PROCEDURE_ID -2
#define WRITE_PROCEDURE_ID -3
typedef struct SymbolTableScope {
char* name;
HashTable * hashTable;
Tree * scopeLocation;
int maxNumberOfTempRegs;
int numberOfIndexedArrays;
int numberOfWhileLoops;
int numberOfIfStatements;
int numberOfForLoops;
} SymbolTableScope;
typedef struct VariableAttr {
Tree * variableValue;
Tree * variableType;
SymbolTableScope * scope;
} VariableAttr;
typedef struct SearchResult {
char* scopeName;
int searchDepth;
bool foundResult;
VariableAttr * attributes;
} SearchResult;
SymbolTable * symbolTableInit();
bool symbolTablePut(SymbolTable * symbolTable, Tree * variableValue, Tree * variableType);
void symbolTableRemove(SymbolTable * symbolTable, char * variableName);
SymbolTableScope * symbolTablePeakScope(SymbolTable * symbolTable);
bool symbolTableCreateScope(SymbolTable * symbolTable, Tree * properScopeLocation);
void symbolTablePushScope(SymbolTable * symbolTable, char* variableName);
void symbolTablePopScope(SymbolTable * symbolTable);
bool symbolTableSearchScope(SymbolTable * symbolTable, char* variableName, SearchResult * searchResult);
bool symbolTableSearchAll(SymbolTable * symbolTable, char* variableName, SearchResult * searchResult);
char * symbolTableGetScopeName(SymbolTable * symbolTable);
void symbolTableIncrIndexedArrays(SymbolTable * symbolTable);
void symbolTableIncrWhile(SymbolTable * symbolTable);
void symbolTableIncrFor(SymbolTable * symbolTable);
void symbolTableIncrIf(SymbolTable * symbolTable);
void symbolTableUpdateTempRegs(SymbolTable * symbolTable, int newValue);
int symbolTableGetNumIndexedArrays(SymbolTable * symbolTable);
int symbolTableGetNumWhile(SymbolTable * symbolTable);
int symbolTableGetNumFor(SymbolTable * symbolTable);
int symbolTableGetNumIf(SymbolTable * symbolTable);
int symbolTablegetNumTempRegs(SymbolTable * symbolTable);
char* symbolTableScopeTraceString(SymbolTable * symbolTable, ListPrintProperties * listPrintProperties);
char* symbolTableScopeTraceStringAtDepth(SymbolTable * symbolTable, int depth, ListPrintProperties * listPrintProperties);
int symbolTableGetScopeDepth(SymbolTable * symbolTable);
void symbolTablePrint(SymbolTable * symbolTable);
char* symbolTableToString(SymbolTable * symbolTable);
#endif // SYMBOL_TABLE_H