baum

changeset 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
files actions.c baum.1
diffstat 2 files changed, 18 insertions(+), 10 deletions(-) [+]
line diff
     1.1 --- a/actions.c	Sun Mar 02 15:54:35 2008 +0100
     1.2 +++ b/actions.c	Sun Mar 02 16:17:18 2008 +0100
     1.3 @@ -6,7 +6,7 @@
     1.4  unsigned char action_print(struct Node* node);
     1.5  unsigned char action_sum(struct Node* node);
     1.6  unsigned char action_number(struct Node* node);
     1.7 -unsigned char action_input(struct Node* node);
     1.8 +unsigned char action_create(struct Node* node);
     1.9  unsigned char action_times(struct Node* node);
    1.10  unsigned char action_if(struct Node* node);
    1.11  unsigned char action_while(struct Node* node);
    1.12 @@ -30,8 +30,8 @@
    1.13  	} else if (strcmp(node->name, "number") == 0) {
    1.14  		return action_number(node);
    1.15  
    1.16 -	} else if (strcmp(node->name, "input") == 0) {
    1.17 -		return action_input(node);
    1.18 +	} else if (strcmp(node->name, "create") == 0) {
    1.19 +		return action_create(node);
    1.20  
    1.21  	} else if (strcmp(node->name, "times") == 0) {
    1.22  		return action_times(node);
    1.23 @@ -81,11 +81,19 @@
    1.24  }
    1.25  
    1.26  
    1.27 -unsigned char action_input(struct Node* node) {
    1.28 +unsigned char action_create(struct Node* node) {
    1.29  	int input;
    1.30 -	printf("input: ");
    1.31 -	scanf("%d", &input);
    1.32 -	input = input % 256;
    1.33 +
    1.34 +	if (node->down == NULL) {
    1.35 +		/* user input */
    1.36 +		printf("input: ");
    1.37 +		scanf("%d", &input);
    1.38 +		input = input % 256;
    1.39 +	} else {
    1.40 +		/* return value */
    1.41 +		input = action(node->down);
    1.42 +	}
    1.43 +
    1.44  	insertLast(node, newNode("number", (char) input));
    1.45  	return 0;
    1.46  }
     2.1 --- a/baum.1	Sun Mar 02 15:54:35 2008 +0100
     2.2 +++ b/baum.1	Sun Mar 02 16:17:18 2008 +0100
     2.3 @@ -1,4 +1,4 @@
     2.4 -.TH baum 1 "2008-03-01" "baum 0.3"
     2.5 +.TH baum 1 "2008-03-01" "baum 0.4"
     2.6  .SH NAME
     2.7  baum \- an esoteric programming language
     2.8  
     2.9 @@ -74,8 +74,8 @@
    2.10  .SH NODES
    2.11  
    2.12  .TP
    2.13 -.B input
    2.14 -Reads a number from standard input which is treated as ASCII value. It inserts a number node with this value as last brother. Returns 0 always.
    2.15 +.B create
    2.16 +Creates a new number node as last brother. The value of the new node is ether read from standard input (if the node has no son), or the return value of the first son. Returns 0 always.
    2.17  
    2.18  .TP
    2.19  .B number