Mercurial > 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 wrap: on
line source
/* * baum - an esoteric programming language * * (c) markus schnalke <meillo@marmaro.de> * and julian forster * */ #include <stdio.h> #include <stdlib.h> struct Node { char* name; char value; struct Node* down; struct Node* right; }; struct Node* root; struct Node* newNode(char* name) { struct Node* node; node = (struct Node*) malloc(sizeof(struct Node)); node->name = name; node->value = 0; node->right = 0; node->down = 0; return node; } void init() { root = newNode("print"); root->down = newNode("sum"); } void cleanup(struct Node* node) { if (node->down != NULL) { cleanup(node->down); } if (node->right != NULL) { cleanup(node->right); } free(node); node=0; } void printNode(struct Node* node) { printf("Node: %20s (%c)\n", node->name, node->value); } void printTree(struct Node* root) { printNode(root); if (root->down != NULL) { printTree(root->down); } if (root->right != NULL) { printTree(root->right); } } int main(int argc, char* argv[]) { init(); printTree(root); cleanup(root); return(0); }