baum

view actions.c @ 2:557fa4df2bcd

added difference between char and number
author meillo@marmaro.de
date Thu, 07 Feb 2008 14:46:27 +0100
parents
children 15d7d6b9766f
line source
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <string.h>
4 #include "baum.h"
5 #include "actions.h"
8 char action(struct Node* node) {
9 if (strcmp(node->name, "print") == 0) {
10 logit("print-node");
11 return action_print(node);
12 } else if (strcmp(node->name, "sum") == 0) {
13 logit("sum-node");
14 return action_sum(node);
15 } else if (strcmp(node->name, "printchar") == 0) {
16 logit("printchar-node");
17 return action_printchar(node);
18 } else if (strcmp(node->name, "number") == 0) {
19 logit("number-node");
20 return action_number(node);
21 } else {
22 fprintf(stderr, "unknown kind of node");
23 exit(1);
24 }
25 }
29 char action_print(struct Node* node) {
30 printf("%d\n", action(node->down));
31 return 0;
32 }
35 char action_printchar(struct Node* node) {
36 printf("%c\n", action(node->down));
37 return 0;
38 }
41 char action_sum(struct Node* node) {
42 struct Node* tp;
43 tp = node->down;
44 while (tp != NULL) {
45 node->value += action(tp);
46 tp = tp->right;
47 }
48 return node->value;
49 }
52 char action_number(struct Node* node) {
53 return node->value;
54 }