-
Notifications
You must be signed in to change notification settings - Fork 1
/
print_slp.c
73 lines (68 loc) · 1.96 KB
/
print_slp.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
#include <stdio.h>
#include "print_slp.h"
#include "slp.h"
void print_slp_exp(FILE *stream, A_exp exp) {
switch (exp->kind) {
case A_idExp:
fprintf(stream, "%s", exp->u.id);
break;
case A_numExp:
fprintf(stream, "%d", exp->u.num);
break;
case A_opExp:
print_slp_exp(stream, exp->u.op.left);
switch (exp->u.op.oper) {
case A_plus: fprintf(stream, "+"); break;
case A_minus: fprintf(stream, "-"); break;
case A_times: fprintf(stream, "*"); break;
case A_div: fprintf(stream, "/"); break;
}
print_slp_exp(stream, exp->u.op.right);
break;
case A_eseqExp:
fprintf(stream, "(");
print_slp_stmt(stream, exp->u.eseq.stm);
fprintf(stream, ", ");
print_slp_exp(stream, exp->u.eseq.exp);
fprintf(stream, ")");
break;
}
return;
}
void print_slp_expList(FILE *stream, A_expList expList) {
switch (expList->kind) {
case A_pairExpList:
print_slp_exp(stream, expList->u.pair.head);
fprintf(stream, ", ");
print_slp_expList(stream, expList->u.pair.tail);
break;
case A_lastExpList:
print_slp_exp(stream, expList->u.last);
break;
}
return;
}
void print_slp_stmt(FILE *stream, A_stm stm) {
switch (stm->kind) {
case A_compoundStm:
//fprintf (stream, "It's a compoundStm!\n");
print_slp_stmt(stream, stm->u.compound.stm1);
//fprintf(stream, "; ");
print_slp_stmt(stream, stm->u.compound.stm2);
//fprintf(stream, "\n");
break;
case A_assignStm:
//fprintf (stream, "It's an assignStm!\n");
fprintf(stream, "%s:=", stm->u.assign.id);
print_slp_exp(stream, stm->u.assign.exp);
fprintf(stream, "; ");
break;
case A_printStm:
//fprintf (stream, "It's a printStm!\n");
fprintf(stream, "print(");
print_slp_expList(stream, stm->u.print.exps);
fprintf(stream, ")");
break;
}
return;
}