-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathsymbolTableDef.h
134 lines (119 loc) · 3.02 KB
/
symbolTableDef.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
/*
Group Number : 2
1 Dhruv Rawat 2019B3A70537P thedhruvrawat
2 Chirag Gupta 2019B3A70555P Chirag5128
3 Swastik Mantry 2019B1A71019P Swastik-Mantry
4 Shreyas Sheeranali 2019B3A70387P ShreyasSR
5 Vaibhav Prabhu 2019B3A70593P prabhuvaibhav
*/
#ifndef SYMBOL_TABLE_DEF
#define SYMBOL_TABLE_DEF
#include <stdbool.h>
#include <stdlib.h>
#include "ast.h"
#define HASH_TABLE_SIZE 1021
#define SIZEOF_INT 2L
#define SIZEOF_REAL 4L
#define SIZEOF_BOOL 1L
typedef struct Type {
VAR_TYPE varType;
struct array {
VAR_TYPE arrType;
bool isLeftID;
bool leftNegative;
bool isRightID;
bool rightNegative;
union {
char leftID[20];
int left;
};
union {
char rightID[20];
int right;
};
} array;
} Type;
typedef struct Record {
char name[20];
int assigned;
bool iterator;
Type type;
int width;
unsigned int offset;
struct Record* next;
} Record;
typedef struct RecordListNode {
VAR_TYPE type;
bool isMinus;
bool isID;
union {
Record* record;
int num;
double rnum;
bool boolean;
};
struct RecordListNode* next;
struct RecordListNode* prev;
} RecordListNode;
typedef struct RecordList {
RecordListNode* head;
RecordListNode* tail;
int size;
} RecordList;
typedef struct CaseLabel {
char* label;
struct CaseLabel* next;
} CaseLabel;
typedef struct SymbolTableNode {
Record* hashTable[HASH_TABLE_SIZE];
struct SymbolTableNode* children;
int scopeStart;
int scopeEnd;
unsigned int nextOffset;
int nestingLevel;
struct SymbolTableNode* funcInputST;
struct SymbolTableNode* funcOutputST;
struct SymbolTableNode* next;
struct SymbolTableNode* parent;
} SymbolTableNode;
typedef struct DeferCheckNode {
SymbolTableNode* symbolTableNode;
ASTNode* statement;
struct DeferCheckNode* next;
} DeferCheckNode;
typedef struct GlobalRecord { // These are Records at the first layer/row of Symbol Table. They contain only function Symbol Tables as per current grammar but would change if grammar allows Global Variable
char name[20];
int linenum;
bool driver;
bool called;
bool declared;
bool defined;
bool error;
bool checkedRedundancy;
Record* inputList;
unsigned int inputListSize;
Record* outputList;
unsigned int outputListSize;
unsigned int activationRecordSize;
int tempInteger;
SymbolTableNode* funcST;
SymbolTableNode* inputST;
SymbolTableNode* outputST;
struct GlobalRecord* next;
} GlobalRecord;
typedef struct SymbolTable {
GlobalRecord* global[HASH_TABLE_SIZE];
int height;
} SymbolTable;
typedef struct SymbolTableStackNode {
ASTNode* node;
unsigned int offset;
struct SymbolTableStackNode* next;
} SymbolTableStackNode;
typedef struct SymbolTableStack {
SymbolTableStackNode* top;
int size;
} SymbolTableStack;
extern SymbolTable* symbolTable;
extern bool SEMANTIC_ERROR;
#endif