baum

view baum.c @ 0:2f71d692d4f9

initial commit
author meillo@marmaro.de
date Thu, 07 Feb 2008 12:51:54 +0100
parents
children 3da0ff17c8e7
line source
1 /*
2 * baum - an esoteric programming language
3 *
4 * (c) markus schnalke <meillo@marmaro.de>
5 * and julian forster
6 *
7 */
10 #include <stdio.h>
11 #include <stdlib.h>
14 struct Node {
15 char* name;
16 char value;
17 struct Node* down;
18 struct Node* right;
19 };
21 struct Node* root;
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 }
34 void init() {
35 root = newNode("print");
36 root->down = newNode("sum");
37 }
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 }
49 void printNode(struct Node* node) {
50 printf("Node: %20s (%c)\n", node->name, node->value);
51 }
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 }
64 int main(int argc, char* argv[]) {
65 init();
66 printTree(root);
67 cleanup(root);
69 return(0);
70 }