baum

diff 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 diff
     1.1 --- a/baum.c	Thu Feb 07 14:31:02 2008 +0100
     1.2 +++ b/baum.c	Thu Feb 07 14:46:27 2008 +0100
     1.3 @@ -12,8 +12,8 @@
     1.4  #include <string.h>
     1.5  
     1.6  #include "baum.h"
     1.7 +#include "actions.h"
     1.8  
     1.9 -char action(struct Node* node);
    1.10  
    1.11  struct Node* root;
    1.12  
    1.13 @@ -49,7 +49,7 @@
    1.14  
    1.15  /* print */
    1.16  void printNode(struct Node* node) {
    1.17 -	printf("Node: %20s (%c)\n", node->name, node->value);
    1.18 +	printf("Node: %20s (%d|%c)\n", node->name, node->value, node->value);
    1.19  }
    1.20  
    1.21  void printTree(struct Node* root) {
    1.22 @@ -69,42 +69,6 @@
    1.23  }
    1.24  
    1.25  
    1.26 -char action_print(struct Node* node) {
    1.27 -	printf("%c\n", action(node->down));
    1.28 -	return 0;
    1.29 -}
    1.30 -
    1.31 -char action_sum(struct Node* node) {
    1.32 -	struct Node* tp;
    1.33 -	tp = node->down;
    1.34 -	while (tp != NULL) {
    1.35 -		node->value += action(tp);
    1.36 -		tp = tp->right;
    1.37 -	}
    1.38 -	return node->value;
    1.39 -}
    1.40 -
    1.41 -char action_number(struct Node* node) {
    1.42 -	return node->value;
    1.43 -}
    1.44 -
    1.45 -char action(struct Node* node) {
    1.46 -	if (strcmp(node->name, "print") == 0) {
    1.47 -		logit("print-node");
    1.48 -		return action_print(node);
    1.49 -	} else if (strcmp(node->name, "sum") == 0) {
    1.50 -		logit("sum-node");
    1.51 -		return action_sum(node);
    1.52 -	} else if (strcmp(node->name, "number") == 0) {
    1.53 -		logit("number-node");
    1.54 -		return action_number(node);
    1.55 -	} else {
    1.56 -		fprintf(stderr, "unknown kind of node");
    1.57 -		exit(1);
    1.58 -	}
    1.59 -}
    1.60 -
    1.61 -
    1.62  
    1.63  /* traverse */
    1.64  void traverse(struct Node* root) {
    1.65 @@ -114,7 +78,7 @@
    1.66  
    1.67  /* init */
    1.68  void init() {
    1.69 -	root = newNode("print");
    1.70 +	root = newNode("printchar");
    1.71  	root->down = newNode("number");
    1.72  	root->down = newNode("sum");
    1.73  	root->down->down = newNode("number");