-
Notifications
You must be signed in to change notification settings - Fork 0
/
ast.h
256 lines (202 loc) · 5.13 KB
/
ast.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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
#ifndef AST_H
#define AST_H
#include "util.h"
typedef struct A_Programa_ *A_Programa;
typedef struct A_Bloco_ *A_Bloco;
typedef struct A_LstDecSub_ *A_LstDecSub;
typedef struct A_LstDecVar_ *A_LstDecVar;
typedef struct A_ListaId_ *A_ListaId;
typedef struct A_DecVar_ *A_DecVar;
typedef struct A_LstDecVar_ *A_LstDecVar;
typedef struct A_Exp_ *A_Exp;
typedef struct A_Cmd_ *A_Cmd;
typedef struct A_BlocoSub_ *A_BlocoSub;
typedef struct A_DecParam_ *A_DecParam;
typedef struct A_DecParamList_ *A_DecParamList;
typedef struct A_DecProc_ *A_DecProc;
typedef struct A_LstDecSub_ *A_LstDecSub;
typedef struct A_Bloco_ *A_Bloco;
typedef struct A_Programa_ *A_Programa;
typedef struct A_ListExp_ *A_ListExp;
typedef struct A_ChamFunc_ *A_ChamFunc;
typedef struct A_Var_ *A_Var;
A_Programa A_programa(String _id, A_Bloco _bloco);
A_Bloco A_bloco(A_LstDecVar _secDecVar, A_LstDecSub _secDecSub, A_Cmd _cmdComp);
A_ListaId A_listaId(String _id, A_ListaId _listaId);
A_DecVar A_decVar(String _id, String _tipo);
A_LstDecVar A_lstDecVar(A_DecVar _decVar, A_LstDecVar _lstDecVar);
A_LstDecVar concatLstDecVar(A_LstDecVar _lst1, A_LstDecVar _lst2);
A_LstDecSub A_lstDecSub(A_DecProc _decProc, A_LstDecSub _lstDecSub);
A_Exp A_exp_fator_chamada_funcao(A_ChamFunc _chamadaFuncao);
A_Exp A_exp_fator_variavel(A_Var _variavel);
A_Exp A_exp_fator_int(int _num);
A_Exp A_exp_fator_logico(int _logico);
A_Exp A_exp_fator_expressao(A_Exp _expressao);
A_Exp A_exp_binaria(A_Exp _exp_esquerda, int _relacao, A_Exp _exp_direita);
A_ListExp A_listExp(A_Exp _expressao, A_ListExp _lista_expressoes);
A_Cmd A_cmd_atrib(A_Exp _expressao, String _id);
A_Cmd A_cmd_chamProc(String _identificador, A_ListExp _lista_expressoes);
A_Cmd A_cmd_cond(A_Exp _expressao, A_Cmd _comando_1, A_Cmd _comando_2);
A_Cmd A_cmd_loop(A_Exp _expressao, A_Cmd _comando);
A_Cmd A_cmd_read(A_ListaId _lista_identificadores);
A_Cmd A_cmd_write(A_ListExp _lista_expressoes);
A_Cmd A_cmdComp(A_Cmd _comando, A_Cmd _lista_comandos);
A_BlocoSub A_blocoSub(A_LstDecVar _secDecVar, A_Cmd _cmdComp);
A_DecParam A_decParam(A_ListaId _lista_identificadores, String _tipo);
A_DecParamList A_decParamList(A_DecParam _declaracao_parametros, A_DecParamList _lista_dec_parametros);
A_DecProc A_decProc_proc(String _id, A_DecParamList _parametros_formais, A_BlocoSub _bloco);
A_DecProc A_decProc_func(String _id, A_DecParamList _parametros_formais, A_BlocoSub _bloco, String _tipo);
A_ChamFunc A_chamFunc(String _id, A_ListExp _lista_expressoes);
A_Var A_var(String _id);
struct A_Programa_ {
String id;
A_Bloco bloco;
};
struct A_Bloco_ {
A_LstDecVar secDecVar;
A_LstDecSub secDecSub;
A_Cmd cmdComp;
};
struct A_ListaId_ {
String id;
A_ListaId prox;
};
struct A_DecVar_ {
String id;
String tipo;
};
struct A_LstDecVar_ {
A_DecVar decVar;
A_LstDecVar prox;
};
enum tipo_decProc{
TD_PROC,
TD_FUNC
};
struct DecProc_Proc{
String id;
A_DecParamList parametros_formais;
A_BlocoSub bloco;
};
struct DecProc_Func{
String id;
A_DecParamList parametros_formais;
A_BlocoSub bloco;
String tipo;
};
struct A_DecProc_ {
enum tipo_decProc tipo;
union{
struct DecProc_Proc _decProc_proc;
struct DecProc_Func _decProc_func;
};
};
struct A_LstDecSub_ {
A_DecProc decProc;
A_LstDecSub prox;
};
enum tipo_expressao {
TE_Fator,
TE_Exp_Binaria
};
enum tipo_fator{
TF_Var,
TF_Num,
TF_Logico,
TF_ChamFunc,
TF_Exp
};
struct Exp_Fator {
enum tipo_fator tipo;
union{
A_Var variavel;
int num;
int logico;
A_ChamFunc chamadaFuncao;
A_Exp expressao;
};
};
struct Exp_Binaria {
A_Exp exp_esquerda;
int relacao;
A_Exp exp_direita;
};
struct A_Exp_ {
enum tipo_expressao tipo;
union {
struct Exp_Fator fator;
struct Exp_Binaria binaria;
};
};
struct A_ListExp_ {
A_Exp expressao;
A_ListExp prox;
};
struct A_atrib {
A_Exp expressao;
String id; //id do lado esq da atribuicao
};
struct A_chamProc {
String identificador;
A_ListExp lista_expressoes;
};
struct A_cond {
A_Exp expressao;
A_Cmd comando_1;
A_Cmd comando_2;
};
struct A_loop {
A_Exp expressao;
A_Cmd comando;
};
struct A_read {
A_ListaId _lista_identificadores;
};
struct A_write {
A_ListExp lista_expressoes;
};
struct A_cmdComp {
A_Cmd comando;
A_Cmd prox;
};
enum tipo_cmd{
TC_ATRIB,
TC_CHAMPROC,
TC_COND,
TC_LOOP,
TC_LEITURA,
TC_ESCRITA,
TC_CMDCOMP
};
struct A_Cmd_ {
enum tipo_cmd tipo;
union{
struct A_atrib A_atrib;
struct A_chamProc A_chamProc;
struct A_cond A_cond;
struct A_loop A_loop;
struct A_read A_io_read;
struct A_write A_io_write;
struct A_cmdComp A_cmdComp;
};
};
struct A_BlocoSub_ {
A_LstDecVar secDecVar;
A_Cmd cmdComp;
};
struct A_DecParam_ {
A_ListaId lista_identificadores;
String tipo;
};
struct A_DecParamList_ {
A_DecParam declaracao_parametros;
A_DecParamList prox;
};
struct A_ChamFunc_ {
String id;
A_ListExp lista_expressoes;
};
struct A_Var_ {
String id;
};
#endif