# HG changeset patch # User meillo@marmaro.de # Date 1204469675 -3600 # Node ID 0870e261bf2889f2cdc681d69193adf33da5cc34 # Parent 00de718c8590086f5c8e64ca1ce5715d0ad07c5c added first implementation of "if" and "while" (but they are not perfect yet) diff -r 00de718c8590 -r 0870e261bf28 actions.c --- 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; +}