Mercurial > baum
changeset 50:0870e261bf28
added first implementation of "if" and "while" (but they are not perfect yet)
author | meillo@marmaro.de |
---|---|
date | Sun, 02 Mar 2008 15:54:35 +0100 |
parents | 00de718c8590 |
children | 7d7abe88e71b |
files | actions.c |
diffstat | 1 files changed, 54 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/actions.c Sun Mar 02 13:35:42 2008 +0100 +++ b/actions.c Sun Mar 02 15:54:35 2008 +0100 @@ -8,6 +8,8 @@ unsigned char action_number(struct Node* node); unsigned char action_input(struct Node* node); unsigned char action_times(struct Node* node); +unsigned char action_if(struct Node* node); +unsigned char action_while(struct Node* node); @@ -34,6 +36,12 @@ } else if (strcmp(node->name, "times") == 0) { return action_times(node); + } else if (strcmp(node->name, "if") == 0) { + return action_if(node); + + } else if (strcmp(node->name, "while") == 0) { + return action_while(node); + } else { fprintf(stderr, "unknown kind of node\n"); exit(4); @@ -90,3 +98,49 @@ } return 0; } + + +unsigned char action_if(struct Node* node) { + int result = 0; + char return1; + char return2; + + if (node->down == NULL || node->down->right == NULL) { + fprintf(stderr, "error: while requires two sons"); + exit(1); /* FIXME other error code */ + } + + return1 = action(node->down); + return2 = action(node->down->right); + + if (node->value == '!') { /* 33 */ + if (return1 != return2) { + result = 1; + } + } else if (node->value == '<') { /* 60 */ + if (return1 < return2) { + result = 1; + } + } else if (node->value == '>') { /* 62 */ + if (return1 > return2) { + result = 1; + } + } else { + if (return1 == return2) { + result = 1; + } + } + return result; +} + + +unsigned char action_while(struct Node* node) { + if (node->down == NULL || node->down->right == NULL) { + fprintf(stderr, "error: while requires two sons"); + exit(1); /* FIXME other error code */ + } + while (action(node->down)) { + action(node->down->right); + } + return 0; +}