diff 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 wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/actions.c	Thu Feb 07 14:46:27 2008 +0100
@@ -0,0 +1,55 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include "baum.h"
+#include "actions.h"
+
+
+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 {
+		fprintf(stderr, "unknown kind of node");
+		exit(1);
+	}
+}
+
+
+
+char action_print(struct Node* node) {
+	printf("%d\n", action(node->down));
+	return 0;
+}
+
+
+char action_printchar(struct Node* node) {
+	printf("%c\n", action(node->down));
+	return 0;
+}
+
+
+char action_sum(struct Node* node) {
+	struct Node* tp;
+	tp = node->down;
+	while (tp != NULL) {
+		node->value += action(tp);
+		tp = tp->right;
+	}
+	return node->value;
+}
+
+
+char action_number(struct Node* node) {
+	return node->value;
+}
+