comparison actions.c @ 51:7d7abe88e71b

"input" node is now "create" node and can handle more than user input now
author meillo@marmaro.de
date Sun, 02 Mar 2008 16:17:18 +0100
parents 0870e261bf28
children 201b4603671a
comparison
equal deleted inserted replaced
50:0870e261bf28 51:7d7abe88e71b
4 #include "baum.h" 4 #include "baum.h"
5 5
6 unsigned char action_print(struct Node* node); 6 unsigned char action_print(struct Node* node);
7 unsigned char action_sum(struct Node* node); 7 unsigned char action_sum(struct Node* node);
8 unsigned char action_number(struct Node* node); 8 unsigned char action_number(struct Node* node);
9 unsigned char action_input(struct Node* node); 9 unsigned char action_create(struct Node* node);
10 unsigned char action_times(struct Node* node); 10 unsigned char action_times(struct Node* node);
11 unsigned char action_if(struct Node* node); 11 unsigned char action_if(struct Node* node);
12 unsigned char action_while(struct Node* node); 12 unsigned char action_while(struct Node* node);
13 13
14 14
28 return action_sum(node); 28 return action_sum(node);
29 29
30 } else if (strcmp(node->name, "number") == 0) { 30 } else if (strcmp(node->name, "number") == 0) {
31 return action_number(node); 31 return action_number(node);
32 32
33 } else if (strcmp(node->name, "input") == 0) { 33 } else if (strcmp(node->name, "create") == 0) {
34 return action_input(node); 34 return action_create(node);
35 35
36 } else if (strcmp(node->name, "times") == 0) { 36 } else if (strcmp(node->name, "times") == 0) {
37 return action_times(node); 37 return action_times(node);
38 38
39 } else if (strcmp(node->name, "if") == 0) { 39 } else if (strcmp(node->name, "if") == 0) {
79 } 79 }
80 return node->value; 80 return node->value;
81 } 81 }
82 82
83 83
84 unsigned char action_input(struct Node* node) { 84 unsigned char action_create(struct Node* node) {
85 int input; 85 int input;
86 printf("input: "); 86
87 scanf("%d", &input); 87 if (node->down == NULL) {
88 input = input % 256; 88 /* user input */
89 printf("input: ");
90 scanf("%d", &input);
91 input = input % 256;
92 } else {
93 /* return value */
94 input = action(node->down);
95 }
96
89 insertLast(node, newNode("number", (char) input)); 97 insertLast(node, newNode("number", (char) input));
90 return 0; 98 return 0;
91 } 99 }
92 100
93 101