-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathinspect.c
298 lines (279 loc) · 6.76 KB
/
inspect.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
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
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
/****************************************************************/
/* This module implements the "inspect" directive, that is used */
/* to visit the graph representing a term. */
/* We plan to integrate the i/o with the YACC specification. */
/* There is only one external function: */
/* - inspect_driver(): this is the driver routine. It is */
/* composed by a main cycle asking for the */
/* next direction to follow in the graph */
/* (the port we must exit the curent form).*/
/* The following function is internal: */
/* - inspect(): it prints informations about the next form */
/* encountered during the inspection of the graph */
/* (its name, index, and the port we arrived to). */
/****************************************************************/
/****************************************************************/
/* Inclusion of header files. */
/****************************************************************/
#include "bohm.h"
#include <inttypes.h>
#include <stdint.h>
#include <stdio.h>
/****************************************************************/
/* Definitions of functions to be exported. */
/****************************************************************/
void inspect_driver(f)
FORM *f;
{
FORM *travel;
int c;
if(f!=NULL){
printf("**** inspection mode ****\n\n");
printf("you are at ROOT node\n");
printf("input next port to visit (0, 1, 2 or 3)\n");
printf("input q to exit\n");
travel = f;
c = getchar();
while (c != 'q')
{
while (c == ' ') c = getchar();
if (c >= '0' && c <= '3')
travel = inspect(c - '0',travel);
c = getchar();
}
printf("**** end of inspection mode ****\n\n");
}else{
printf("******************************************\n");
printf("* No terms inserted yet . . . *\n");
printf("******************************************\n");
}
}
extern FORM *inspect(int p, FORM *f)
{
bool ok=true;
switch(p)
{
case 0:
break;
case 1:
switch(f->name){
case ERASE:
case ROOT:
ok=false;
break;
default:
break;
}
break;
case 2:
switch(f->name){
case ERASE:
case ROOT:
case INT:
case T:
case F:
case NIL:
case TRIANGLE:
case LAMBDAUNB:
case TESTNIL:
case CAR:
case CDR:
case NOT:
case EQ1:
case NOTEQ1:
case LEQ1:
case MEQ1:
case MORE1:
case LESS1:
case ADD1:
case SUB1:
case PROD1:
case DIV1:
case MOD1:
case UNS_FAN1:
case UNS_FAN2:
ok=false;
break;
default:
break;
}
break;
case 3:
switch(f->name){
case IFELSE:
break;
default:
ok=false;
break;
}
break;
default:
ok=false;
break;
}
if (!ok) {
printf("there is nothing there\n");
return(f);
}
else {
FORM *nextform;
int nextport;
nextport = f->nport[p];
if (nextport<0) {
switch(nextport) {
case T:
printf("form = T\n");
break;
case F:
printf("form = F\n");
break;
case INT:
printf("form = INT value = %" PRIdPTR "\n", (intptr_t)f->nform[0]);
break;
case NIL:
printf("form = NIL\n");
break;
}
printf("at port = 0\n\n");
return(f);
}
else {
nextform = f->nform[p];
switch (nextform->name)
{
case FAN:
printf("form = FAN\n");
break;
case TRIANGLE:
printf("form = TRIANGLE\n");
break;
case ROOT:
printf("form = ROOT\n");
break;
case APP:
printf("form = APP\n");
break;
case LAMBDA:
printf("form = LAMBDA\n");
break;
case IFELSE:
printf("form = IFELSE\n");
break;
case AND:
printf("form = AND\n");
break;
case OR:
printf("form = OR\n");
break;
case NOT:
printf("form = NOT\n");
break;
case LESS:
printf("form = LESS\n");
break;
case LESS1:
printf("form = LESS1 value = %" PRIdPTR "\n", (intptr_t)nextform->nform[2]);
break;
case EQ:
printf("form = EQ\n");
break;
case EQ1:
printf("form = EQ1 value = %" PRIdPTR "\n", (intptr_t)nextform->nform[2]);
break;
case NOTEQ:
printf("form = NOTEQ\n");
break;
case NOTEQ1:
printf("form = NOTEQ1 value = %" PRIdPTR "\n", (intptr_t)nextform->nform[2]);
break;
case MORE:
printf("form = MORE\n");
break;
case MORE1:
printf("form = MORE1 value = %" PRIdPTR "\n", (intptr_t)nextform->nform[2]);
break;
case LEQ:
printf("form = LEQ\n");
break;
case LEQ1:
printf("form = LEQ1 value = %" PRIdPTR "\n", (intptr_t)nextform->nform[2]);
break;
case MEQ:
printf("form = MEQ\n");
break;
case MEQ1:
printf("form = MEQ1 value = %" PRIdPTR "\n", (intptr_t)nextform->nform[2]);
break;
case ADD:
printf("form = ADD\n");
break;
case ADD1:
printf("form = ADD1 value = %" PRIdPTR "\n", (intptr_t)nextform->nform[2]);
break;
case SUB:
printf("form = SUB\n");
break;
case SUB1:
printf("form = SUB1 value = %" PRIdPTR "\n", (intptr_t)nextform->nform[2]);
break;
case PROD:
printf("form = PROD\n");
break;
case PROD1:
printf("form = PROD1 value = %" PRIdPTR "\n", (intptr_t)nextform->nform[2]);
break;
case DIV:
printf("form = DIV\n");
break;
case DIV1:
printf("form = DIV1 value = %" PRIdPTR "\n", (intptr_t)nextform->nform[2]);
break;
case MOD:
printf("form = MOD\n");
break;
case MOD1:
printf("form = MOD1 value = %" PRIdPTR "\n", (intptr_t)nextform->nform[2]);
break;
case CONS:
printf("form = CONS\n");
break;
case CAR:
printf("form = CAR\n");
break;
case CDR:
printf("form = CDR\n");
break;
case TESTNIL:
printf("form = TESTNIL\n");
break;
case LAMBDAUNB:
printf("form = LAMBDAUNB\n");
break;
case UNS_FAN1:
printf("form = UNS_FAN1\n");
break;
case UNS_FAN2:
printf("form = UNS_FAN2\n");
break;
case CAR1:
printf("form = CAR1\n");
break;
case CDR1:
printf("form = CDR1\n");
break;
case TESTNIL1:
printf("form = TESTNIL1\n");
break;
case CONS1:
printf("form = CONS1\n");
break;
}
printf("with index = %d\n",nextform->index);
printf("at port = %d\n\n",nextport);
return nextform;
}
}
}
/****************************************************************/
/* Definitions of functions strictly local to the module */
/****************************************************************/