baum
diff actions.c @ 3:15d7d6b9766f
added input; added nextNode, lastNode, insertLast
author | meillo@marmaro.de |
---|---|
date | Thu, 07 Feb 2008 16:15:07 +0100 |
parents | 557fa4df2bcd |
children | c202ccccedb5 |
line diff
1.1 --- a/actions.c Thu Feb 07 14:46:27 2008 +0100 1.2 +++ b/actions.c Thu Feb 07 16:15:07 2008 +0100 1.3 @@ -5,19 +5,27 @@ 1.4 #include "actions.h" 1.5 1.6 1.7 -char action(struct Node* node) { 1.8 +unsigned char action(struct Node* node) { 1.9 if (strcmp(node->name, "print") == 0) { 1.10 logit("print-node"); 1.11 return action_print(node); 1.12 + 1.13 } else if (strcmp(node->name, "sum") == 0) { 1.14 logit("sum-node"); 1.15 return action_sum(node); 1.16 + 1.17 } else if (strcmp(node->name, "printchar") == 0) { 1.18 logit("printchar-node"); 1.19 return action_printchar(node); 1.20 + 1.21 } else if (strcmp(node->name, "number") == 0) { 1.22 logit("number-node"); 1.23 return action_number(node); 1.24 + 1.25 + } else if (strcmp(node->name, "input") == 0) { 1.26 + logit("input-node"); 1.27 + return action_input(node); 1.28 + 1.29 } else { 1.30 fprintf(stderr, "unknown kind of node"); 1.31 exit(1); 1.32 @@ -26,19 +34,19 @@ 1.33 1.34 1.35 1.36 -char action_print(struct Node* node) { 1.37 +unsigned char action_print(struct Node* node) { 1.38 printf("%d\n", action(node->down)); 1.39 return 0; 1.40 } 1.41 1.42 1.43 -char action_printchar(struct Node* node) { 1.44 +unsigned char action_printchar(struct Node* node) { 1.45 printf("%c\n", action(node->down)); 1.46 return 0; 1.47 } 1.48 1.49 1.50 -char action_sum(struct Node* node) { 1.51 +unsigned char action_sum(struct Node* node) { 1.52 struct Node* tp; 1.53 tp = node->down; 1.54 while (tp != NULL) { 1.55 @@ -49,7 +57,16 @@ 1.56 } 1.57 1.58 1.59 -char action_number(struct Node* node) { 1.60 +unsigned char action_number(struct Node* node) { 1.61 return node->value; 1.62 } 1.63 1.64 + 1.65 +unsigned char action_input(struct Node* node) { 1.66 + unsigned char input = (unsigned char) getchar(); 1.67 + getchar(); /* catches the newline */ 1.68 + insertLast(node, newNode("number", input)); 1.69 + return 0; 1.70 +} 1.71 + 1.72 +