forked from mayankgupta022/compiler
-
Notifications
You must be signed in to change notification settings - Fork 0
/
semantic.c
90 lines (81 loc) · 1.9 KB
/
semantic.c
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
/*
-=-=-=-=-=-=-=-=-=-=-=-=-=
BATCH 26
-=-=-=-=-=-=-=-=-=-=-=-=-=
AAYUSH AHUJA 2010A7PS023P
MAYANK GUPTA 2010A7PS022P
-=-=-=-=-=-=-=-=-=-=-=-=-=
semantic.c
-=-=-=-=-=-=-=-=-=-=-=-=-=
*/
#include<stdio.h>
#include<ctype.h>
#include<string.h>
#include<stdlib.h>
#include<fcntl.h>
#include"lexerDef.h"
#include"lexer.h"
#include"parserDef.h"
#include"parser.h"
#include"symbolTable.h"
#include"semantic.h"
extern bool any_error;
int checkMultift(funTable FT[],char* fname,int recindex,char* name)
{
int hval,hval2,hkey=100;
hval = hash(fname,hkey);
hval2 = hash(name,hkey);
if(FT[hval].table[hval2].filled)
{
printf("ERROR: Variable %s has been declared multiple times in function %s\n",name,fname);
any_error=1;
}
return FT[hval].table[hval2].filled;
}
int checkMultiftN(funTable FT[],char* fname,int recindex,char* name)
{
int hval,hval2,hkey=100;
hval = hash(fname,hkey);
hval2 = hash(name,hkey);
return FT[hval].table[hval2].filled;
}
int checkMultirt(recTable RT[],char* rname,char* name)
{
int hval,hval2,hkey=100;
hval = hash(rname,hkey);
hval2 = hash(name,hkey);
if(RT[hval].table[hval2].filled)
{
printf("ERROR: Variable %s has been declared multiple times in record %s\n",name,rname);
any_error=1;
}
return RT[hval].table[hval2].filled;
}
int checkMultigt(variable GT[],int recindex,char* name)
{
int hval,hkey=100;
hval = hash(name,hkey);
if(GT[hval].filled)
{
printf("ERROR: Variable %s being a global variable, cannot be declared more than once\n", name);
any_error=1;
}
return GT[hval].filled;
}
int checkMultigtN(variable GT[],int recindex,char* name)
{
int hval,hkey=100;
hval = hash(name,hkey);
return GT[hval].filled;
}
int checkMultiFun(funTable FT[], char* fname)
{
int hval,hkey=100;
hval=hash(fname,hkey);
if(FT[hval].filled)
{
printf("ERROR: Function overloading is not allowed. Function %s has been overloaded\n", fname);
any_error=1;
}
return FT[hval].filled;
}