This repository has been archived by the owner on Jan 1, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
flexon.h
132 lines (111 loc) · 3.9 KB
/
flexon.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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
#ifndef FLEXON_FLEXON_H
#define FLEXON_FLEXON_H
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <stdarg.h>
#define YYDEBUG 1 // debug mode
extern int yylineno;
extern int yylex();
extern int yyparse();
extern FILE *yyin;
/**
* Struct for all types
*
* Ex)
* If `int`, type = "int" and size = 0
* If `float[5]`, type = "float" and size = 5
*/
typedef struct universal_type {
char *type;
int size;
} UniversalType;
/**
* Struct for the universal type list
*/
typedef struct universal_type_list {
int size;
UniversalType *types[128];
} UniversalTypeList;
/**
* Struct for the non-terminal `identifier_list`
*/
typedef struct id_list {
int size;
char *ids[64];
int decl_lineno;
} IDList;
/**
* Struct for the declared id
*
* Ex)
* If `int[5] num` then name = "num", type->type = "int" and type->size = 5
*/
typedef struct declared_id {
char *name;
UniversalType *type;
} DeclaredID;
/**
* Struct for the declared id list
*/
typedef struct declared_id_list {
int size;
DeclaredID *decl_ids[128];
} DeclaredIDList;
typedef struct declared_function {
char *name;
DeclaredIDList *arguments;
DeclaredIDList *local_vars;
char *return_type;
} DeclaredFunction;
typedef struct declared_function_list {
int size;
DeclaredFunction *decl_funcs[128];
} DeclaredFunctionList;
typedef struct collector {
DeclaredIDList *global_vars; // global variable list
DeclaredIDList *arguments; // function argument list
DeclaredIDList *local_vars; // local variable list
DeclaredFunctionList *funcs; // function & procedure list
} Collector;
void yyerror(const char *);
void yaccError(int lineno, char *s, ...);
IDList* newIDList(int lineno);
UniversalType* newType(char *type, int size);
UniversalTypeList* newTypeList();
DeclaredID* newDeclaredID(char *name, UniversalType *type);
DeclaredIDList* newDeclaredIDList();
DeclaredFunction* newDeclaredFunction(char *name, DeclaredIDList *arguments, DeclaredIDList *local_vars, char *return_type);
DeclaredFunctionList* newDeclaredFunctionList();
Collector* newCollector();
UniversalType* copyType(UniversalType *type);
DeclaredID* copyDeclaredID(DeclaredID *decl_id);
DeclaredIDList* copyDeclaredIDList(DeclaredIDList *list);
void addTypeToList(UniversalTypeList **list, UniversalType *type);
void addIDToList(IDList **list, char *id);
void addDeclaredIDToList(DeclaredIDList **list, DeclaredID *decl_id);
void addDeclaredFunctionToList(DeclaredFunctionList **list, DeclaredFunction *decl_func);
void collectGlobalVars(Collector **collector, UniversalType *type, IDList *id_list);
void collectArguments(Collector **collector, UniversalType *type, IDList *id_list);
void collectLocalVars(Collector **collector, UniversalType *type, IDList *id_list);
void collectFuncs(Collector **collector, char *name, char *return_type, int lineno);
void copyLocalVarsToCurrFunc(Collector **collector);
UniversalType* incompatibleArrayUsageError(UniversalType *type, int lineno);
DeclaredFunction* checkFunc(Collector *collector, char *id, UniversalTypeList *param_type_list, int lineno);
DeclaredID* checkIDInGlobalStmt(Collector *collector, char *id, int is_array, int lineno);
DeclaredID* checkIDInLocalStmt(Collector *collector, char *id, int is_array, int lineno);
int isCompatible(DeclaredID *decl_id, int is_array, int lineno);
void printUniversalType(UniversalType *type);
void printDeclaredID(DeclaredID *decl_id);
void printDeclaredIDList(DeclaredIDList *list);
void printDeclaredFunction(DeclaredFunction *decl_func);
void printDeclaredFunctionList(DeclaredFunctionList *list);
void printCollector(Collector *collector);
void freeUniversalType(UniversalType *type);
void freeIDList(IDList *list);
void freeDeclaredID(DeclaredID *decl_id);
void freeDeclaredIDList(DeclaredIDList *list);
void freeDeclaredFunction(DeclaredFunction *decl_func);
void freeDeclaredFunctionList(DeclaredFunctionList *list);
void freeCollector(Collector *collector);
#endif //FLEXON_FLEXON_H