forked from stanleytangerror/CompilingLab
-
Notifications
You must be signed in to change notification settings - Fork 0
/
semantic.h
86 lines (68 loc) · 1.87 KB
/
semantic.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
#ifndef __SEMANTIC_H__
#define __SEMANTIC_H__
#include "tree.h"
#define MAX_VARIABLE 16384
#define NAME_LEN 32
#define STATE_VARIABLE 0
#define STATE_PARAM 1
typedef struct Type_ Type;
typedef struct FieldList_ FieldList;
typedef struct Func_ Func;
typedef struct StructType StructType;
struct Type_ {
enum {basic, array, structure} kind;
union {
int basic;
struct {
Type* elem;
int size;
} array;
struct {
char name[NAME_LEN];
FieldList* structure;
} structure;
} u;
};
struct Func_ {
int funclineno;
Type * returntype;
char name[NAME_LEN];
FieldList * param;
};
struct FieldList_ {
char name[NAME_LEN];
Type *type;
FieldList *tail;
int state;
};
extern FieldList* varlist[MAX_VARIABLE];
extern Type * typelist[MAX_VARIABLE];
extern Func * funclist[MAX_VARIABLE];
extern Func * funcdeclist[MAX_VARIABLE];
void InitialHashTable();
void initialDefaultFunc();
int addType(Type* type);
int findType(char *name);
int addVar(FieldList* variable);
int addFunc(Func* func);
int addFuncdec(Func* func);
int findFunc(char *name);
int findFuncDec(char *name);
int findVar(char *name);
bool cmpType(Type * p, Type * q) ;
bool cmpFunc(Func * f1, Func * f2);
int subtreeDef(node * p, Type * upperlevel, Func * currentfunc);
int subtreeExtDef(node * p, Type * upperlevel, Func * currentfunc) ;
int subtreeFunctionSpecifier(node *p, Type * upperlevel , Func * currentfunc);
int subtreeStructSpecifier(node * p, Type * upperlevel, Func * currentfunc) ;
int subtreeDecList(node * p, Type * upperlevel, bool isStruct, Func * currentfunc);
int subtreeStmt(node * p, Type * upperlevel, Func * currentfunc);
bool subtreeArgs(node * p , char * funcname);
Type * subtreeExp(node * P);
void semantic(node * p, Type * upperlevel , Func * currentfunc);
void getvarlist() ;
void gettypelist();
void getfunclist() ;
void getfuncdeclist() ;
void checkfunc();
#endif