Mercurial > baum
view baum.c @ 2:557fa4df2bcd
added difference between char and number
author | meillo@marmaro.de |
---|---|
date | Thu, 07 Feb 2008 14:46:27 +0100 |
parents | 3da0ff17c8e7 |
children | 15d7d6b9766f |
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> #include <string.h> #include "baum.h" #include "actions.h" struct Node* root; void logit(char* text) { fprintf(stderr, "[%s]\n", text); } /* new */ 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; } /* delete */ void delete(struct Node* node) { if (node->down != NULL) { delete(node->down); } if (node->right != NULL) { delete(node->right); } free(node); node=0; } /* print */ void printNode(struct Node* node) { printf("Node: %20s (%d|%c)\n", node->name, node->value, node->value); } void printTree(struct Node* root) { printNode(root); printf(" down: "); if (root->down != NULL) { printTree(root->down); } else { printf("NULL\n"); } printf(" right: "); if (root->right != NULL) { printTree(root->right); } else { printf("NULL\n"); } } /* traverse */ void traverse(struct Node* root) { /* each node controlls the nodes below itself */ action(root); } /* init */ void init() { root = newNode("printchar"); root->down = newNode("number"); root->down = newNode("sum"); root->down->down = newNode("number"); root->down->down->value = 70; /* 'F' */ root->down->down->right = newNode("number"); root->down->down->right->value = 50; /* '2' */ /* result should be 'x' */ } /* main */ int main(int argc, char* argv[]) { init(); printTree(root); action(root); delete(root); return(0); }