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 wrap: on
line diff
--- a/actions.c	Thu Feb 07 14:46:27 2008 +0100
+++ b/actions.c	Thu Feb 07 16:15:07 2008 +0100
@@ -5,19 +5,27 @@
 #include "actions.h"
 
 
-char action(struct Node* node) {
+unsigned char action(struct Node* node) {
 	if (strcmp(node->name, "print") == 0) {
 		logit("print-node");
 		return action_print(node);
+
 	} else if (strcmp(node->name, "sum") == 0) {
 		logit("sum-node");
 		return action_sum(node);
+
 	} else if (strcmp(node->name, "printchar") == 0) {
 		logit("printchar-node");
 		return action_printchar(node);
+
 	} else if (strcmp(node->name, "number") == 0) {
 		logit("number-node");
 		return action_number(node);
+
+	} else if (strcmp(node->name, "input") == 0) {
+		logit("input-node");
+		return action_input(node);
+
 	} else {
 		fprintf(stderr, "unknown kind of node");
 		exit(1);
@@ -26,19 +34,19 @@
 
 
 
-char action_print(struct Node* node) {
+unsigned char action_print(struct Node* node) {
 	printf("%d\n", action(node->down));
 	return 0;
 }
 
 
-char action_printchar(struct Node* node) {
+unsigned char action_printchar(struct Node* node) {
 	printf("%c\n", action(node->down));
 	return 0;
 }
 
 
-char action_sum(struct Node* node) {
+unsigned char action_sum(struct Node* node) {
 	struct Node* tp;
 	tp = node->down;
 	while (tp != NULL) {
@@ -49,7 +57,16 @@
 }
 
 
-char action_number(struct Node* node) {
+unsigned char action_number(struct Node* node) {
 	return node->value;
 }
 
+
+unsigned char action_input(struct Node* node) {
+	unsigned char input = (unsigned char) getchar();
+	getchar();  /* catches the newline */
+	insertLast(node, newNode("number", input));
+	return 0;
+}
+
+