-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsymTable.h
executable file
·72 lines (62 loc) · 1.29 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
#ifndef symTable_h
#define symTable_h
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define TABLE_SIZE 20
int hashIndex=0;
typedef struct {
int index;
char name[10];
int scope;
char datatype[10];
int isFunction;
char returnType[10];
int argCount;
int* argsID;
}TOKEN;
TOKEN* SYMTABLE[TABLE_SIZE];
TOKEN* newToken() {
TOKEN* temp = (TOKEN*)malloc(sizeof(TOKEN));
return temp;
}
TOKEN* initialiseArgs(TOKEN* f, int argCount) {
f->argCount = argCount;
f->argsID = (int*)calloc(argCount,sizeof(int));
int i;
for(i=0; i<argCount; i++) {
f->argsID[i]=-1;
}
}
int hashFunction() {
return hashIndex++;
}
void initialiseTable() {
int i;
for(i=0; i<TABLE_SIZE; i++) {
SYMTABLE[i] = NULL;
}
}
void printToken(TOKEN* t) {
printf("%-12d%-12s%-12s",t->index,t->name,t->datatype);
t->scope==1?printf("\tL\n"): printf("\tG\n");
}
void printSymbolTable() {
int i;
printf("--x--x--x--x--x--x--x--x--x--x--x--x--x--x--x--x--x--x--x--x--\n");
printf("\t\t\tSYMBOL TABLE\n\n");
printf("index\tlexemeName\tDatatype\tscope\n\n");
for(i=0; i<TABLE_SIZE; i++) {
if(SYMTABLE[i]==NULL)
continue;
printToken(SYMTABLE[i]);
}
}
int searchTable(char* item) {
int i;
for(i=0; i<TABLE_SIZE; i++) {
if(SYMTABLE[i]!=NULL && strcmp(SYMTABLE[i]->name,item)==0) return i;
}
return -1;
}
#endif