This repository was archived by the owner on Apr 4, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathag.h
More file actions
79 lines (65 loc) · 1.87 KB
/
Copy pathag.h
File metadata and controls
79 lines (65 loc) · 1.87 KB
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
#ifndef AG_H
#define AG_H
enum PrimitiveType{
PrimitiveUndefined,
PrimitiveInt
};
/**
* VariableType
*/
typedef struct _VariableType {
/*
* The rank of the array. A value of 0 means the variable type is the
* primitive type.
*/
int rank;
/*
* The underlying primitive type of the array.
*/
enum PrimitiveType primitive;
} VariableType;
VariableType *newVariableType(int rank);
gboolean eqVariableType(VariableType *left, VariableType *right);
VariableType *downrankVariableType(VariableType *type);
/**
* VariableDeclaration
*/
typedef struct _VariableDeclaration {
char *name;
VariableType *type;
} VariableDeclaration;
VariableDeclaration *newVariableDeclaration(char *name, VariableType *type);
/**
* ScopeFrame
*/
typedef struct _ScopeFrame {
int len;
GSList *declarations;
} ScopeFrame;
ScopeFrame *newScopeFrame();
ScopeFrame *frameAddDeclaration(ScopeFrame *frame, VariableDeclaration *declaration);
void printScopeFrame(ScopeFrame* frame);
/**
* ScopeChain
*/
typedef struct _ScopeChain {
int len;
GSList *frames;
} ScopeChain;
ScopeChain *newScopeChain();
ScopeChain *chainPushFrame(ScopeChain *chain, ScopeFrame *frame);
ScopeChain *chainAddDeclaration(ScopeChain *chain, VariableDeclaration *declaration);
void printScopeChain(ScopeChain* chain);
gboolean _debugScopeChain;
void debugScopeChain(char *label, ScopeChain *chain);
/**
* Semantic checks
*/
void checkDuplicateParameters(char *function_identifier, ScopeFrame *parameters);
void checkIdentifierInScope(char *identifier, ScopeChain *scope);
void checkIsInteger(VariableType *type);
void checkIsArray(VariableType *type);
void checkSameType(VariableType *left, VariableType *right);
VariableDeclaration *findDeclarationInScope(char *identifier, ScopeChain *scope);
VariableType *findTypeInScope(char *identifier, ScopeChain *scope);
#endif