-
Notifications
You must be signed in to change notification settings - Fork 0
/
globalsymboltable.h
78 lines (74 loc) · 3.09 KB
/
globalsymboltable.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
#include "typetable.h"
//Argument List for Functions
struct argList{
char *name;
struct typeTable *type;
struct argList *next;
int isRef;
};
//For Symbol Table
struct Gsymbol{
char *name; //name of the variable or function
struct typeTable *type; //pointer to the Typetable entry of variable type/return type of the function
int size; //size of an array. (The size of all other types of variables is 1)
int binding; //stores static memory address allocated to the variable
struct argList *args;
int numArgs;
struct Lsymbol *lsymbols;
struct Gsymbol *next;
int isDefined;
};
//For Symbol Table
struct Lsymbol{
char *name; //name of the variable or function
struct typeTable *type; //pointer to the Typetable entry of variable type/return type of the function
int size; //size of an array. (The size of all other types of variables is 1)
int binding; //stores static memory address allocated to the variable;
struct Lsymbol *next;
};
//Single Structure for pointing any data type
struct variablePointer{
char * type;
union {
int * intPointer;
char * charPointer;
char * booleanPointer;
};
};
//For storing size and name of variables
struct variableDecl{
char * name;
int size;//No of indexes eg. a[10] has index =10
struct variableDecl * next;
};
//For storing size and name of arguments
struct argumentDecl{
char * name;
struct argumentDecl * next;
int isRef;
};
//Symbol Table Global Variables//
struct Gsymbol *GsymbolHead;
struct Gsymbol *GsymbolTail;
//Functions and Data structures for variables
struct Gsymbol * installVariable(char * name,struct typeTable * typeTableTuple, int arraySize);
struct Gsymbol * installVariableRaw(char * name,char * type, int arraySize);
int findVariableBinding(char * variableName, int shift);
int getVariableBinding(struct Gsymbol * variable, int shift);
struct Gsymbol * getVariable(char * name);
void printAllVariables();
void installAllVariables(struct Gsymbol * idList,struct typeTable * typeTableTuple);
//Functions for 'Functions'
struct argList * saveFarg(char * name,struct typeTable * typeTableTuple);
struct Gsymbol * installFunction(char * name,struct argList * args, struct typeTable * typeTableTuple, struct Lsymbol * lsymbols);
struct Lsymbol * installLocalVariable(char * name,struct typeTable * typeTableTuple, int arraySize);
struct Lsymbol * installAllLocalVariables(struct Lsymbol * idList,struct typeTable * typeTableTuple);
struct Gsymbol * getSymbolTableTuple(char * name);
void writeBindingsAndArgs(struct Lsymbol * localVar,struct argList *argument);
int isCorrectDeclaration(struct argList * argument,struct argList * actualArgument);
int getLocalVariableBinding(char * name,struct Lsymbol * variable);
struct Lsymbol * getLocalTableEntry(char * name,struct Lsymbol * variable);
//
int checkMultipleLocalDeclaration(struct Lsymbol * head1);
int checkMultipleDeclaration();
void initializeRegister();