0
|
1 /*
|
|
2 * baum - an esoteric programming language
|
|
3 *
|
|
4 * (c) markus schnalke <meillo@marmaro.de>
|
|
5 * and julian forster
|
|
6 *
|
|
7 */
|
|
8
|
|
9
|
|
10 #include <stdio.h>
|
|
11 #include <stdlib.h>
|
|
12
|
|
13
|
|
14 struct Node {
|
|
15 char* name;
|
|
16 char value;
|
|
17 struct Node* down;
|
|
18 struct Node* right;
|
|
19 };
|
|
20
|
|
21 struct Node* root;
|
|
22
|
|
23
|
|
24 struct Node* newNode(char* name) {
|
|
25 struct Node* node;
|
|
26 node = (struct Node*) malloc(sizeof(struct Node));
|
|
27 node->name = name;
|
|
28 node->value = 0;
|
|
29 node->right = 0;
|
|
30 node->down = 0;
|
|
31 return node;
|
|
32 }
|
|
33
|
|
34 void init() {
|
|
35 root = newNode("print");
|
|
36 root->down = newNode("sum");
|
|
37 }
|
|
38
|
|
39 void cleanup(struct Node* node) {
|
|
40 if (node->down != NULL) {
|
|
41 cleanup(node->down);
|
|
42 }
|
|
43 if (node->right != NULL) {
|
|
44 cleanup(node->right);
|
|
45 }
|
|
46 free(node); node=0;
|
|
47 }
|
|
48
|
|
49 void printNode(struct Node* node) {
|
|
50 printf("Node: %20s (%c)\n", node->name, node->value);
|
|
51 }
|
|
52
|
|
53 void printTree(struct Node* root) {
|
|
54 printNode(root);
|
|
55 if (root->down != NULL) {
|
|
56 printTree(root->down);
|
|
57 }
|
|
58 if (root->right != NULL) {
|
|
59 printTree(root->right);
|
|
60 }
|
|
61 }
|
|
62
|
|
63
|
|
64 int main(int argc, char* argv[]) {
|
|
65 init();
|
|
66 printTree(root);
|
|
67 cleanup(root);
|
|
68
|
|
69 return(0);
|
|
70 }
|