Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 68 lines (63 sloc) 3.049 kb
8c38a60 @5HT Initial Commit
5HT authored
1
2 #include "parser.h"
3
4 static void printid(alfa id)
5 {
6 int i=0;
7 while (i<=IDENTLEN) if (id[i]==' ') break; else { printf("%c", id[i++]); }
8 }
9
10 static void printsy(symbol sy)
11 {
12 switch (sy) {
13 case parallelsy: printf("||"); break;
14 case choicesy: printf("|"); break;
15 case sequencesy: printf("->"); break;
16 case inputsy: printf("?"); break;
17 case outputsy: printf("!"); break;
18 case conssy: printf(":"); break;
19 case orsy: printf("or"); break;
20 case andsy: printf("and"); break;
21 case eq: printf("="); break;
22 case ne: printf("<>"); break;
23 case le: printf("<="); break;
24 case ge: printf(">="); break;
25 case gt: printf(">"); break;
26 case lt: printf("<"); break;
27 case plus: printf("+"); break;
28 case minus: printf("-"); break;
29 case times: printf("*"); break;
30 case over: printf("/"); break;
31 case hdsy: printf("head"); break;
32 case tlsy: printf("tail"); break;
33 case nullsy: printf("null"); break;
34 case notsy: printf("not"); break;
35 }
36 }
37
38 #define TAB 4
39 void print(int deep, tree t)
40 {
41 int i;
42 if (t!=0)
43 {
44 switch (t->tag) {
45 case ident: printid(t->id); break;
46 case intcon: printf("%i", t->n); break;
47 case boolcon: printf("%i", t->b); break;
48 case charcon: printf("\'%c' ", t->ch); break;
49 case emptycon: printf("()"); break;
50 case nilcon: printf("nil"); break;
6a6d963 @5HT working interpreter milestone
5HT authored
51 case newchan: printf("chan"); break;
8c38a60 @5HT Initial Commit
5HT authored
52 case lambdaexp: printf("lambda "); print(deep,t->lambda.parm); printf(". "); print(deep,t->lambda.body); break;
53 case application: print(deep,t->application.func); printf(" "); print(deep,t->application.parm); break;
54 case unexp: printsy(t->expression.op); printf(" "); print(deep,t->expression.left); break;
55 case binexp: print(deep,t->expression.left); printf(" "); printsy(t->expression.op); printf(" "); print(deep,t->expression.right); break;
56 case ifexp: printf("if "); print(deep,t->ifexp.e1); printf(" then "); print(deep,t->ifexp.e2); printf(" else "); print(deep,t->ifexp.e3); break;
57 case declist: print(deep,t->declist.head); if (t->declist.tail != 0) printf(",\n");
58 print(deep,t->declist.tail); break;
59 case decln: for (i=0;i<deep*TAB;i++) printf(" "); printid(t->decln.name); printf(" = "); print(deep,t->decln.value); break;
60 case block: printf("let ");
61 if (t->block.decs->declist.recursive == recsy) printf("rec\n"); else printf("\n");
62 print(deep+1,t->block.decs); printf("\n");
63 for (i=0;i<deep*TAB;i++) printf(" "); printf("in "); print(deep+1,t->block.expr);
64 break;
65 }
66 }
67 }
Something went wrong with that request. Please try again.