SongZihuan 5 rokov pred
rodič
commit
b3a57f6122
7 zmenil súbory, kde vykonal 250 pridanie a 336 odobranie
  1. BIN
      gwarf
  2. 47 15
      gwarf_interpreter/interpreter.c
  3. 0 207
      include/var_linked.c
  4. 4 1
      paser/gwarf_lex.l
  5. 38 6
      paser/gwarf_yacc.y
  6. 82 72
      paser/lex.yy.c
  7. 79 35
      paser/y.tab.c

BIN
gwarf


+ 47 - 15
gwarf_interpreter/interpreter.c

@@ -6,6 +6,9 @@
 // running code
 // running code
 GWARF_result operation_func(statement *, var_list *);
 GWARF_result operation_func(statement *, var_list *);
 GWARF_result add_func(GWARF_result, GWARF_result, var_list *);
 GWARF_result add_func(GWARF_result, GWARF_result, var_list *);
+GWARF_result sub_func(GWARF_result, GWARF_result, var_list *);
+GWARF_result mul_func(GWARF_result, GWARF_result, var_list *);
+GWARF_result div_func(GWARF_result, GWARF_result, var_list *);
 
 
 // ------------------------- var func
 // ------------------------- var func
 
 
@@ -120,9 +123,10 @@ GWARF_result read_statement_list(statement *the_statement, var_list *the_var){
             break;
             break;
         case 4:
         case 4:
             return_value.value = (the_statement->code).base_value.value;  // code
             return_value.value = (the_statement->code).base_value.value;  // code
+            printf("get value = %f\n", return_value.value.value.double_value);
             break;
             break;
         default:
         default:
-            return_value.value.value.double_value = 10086;
+            puts("default");
             break;
             break;
     }
     }
     return return_value;
     return return_value;
@@ -137,24 +141,62 @@ GWARF_result operation_func(statement *the_statement, var_list *the_var){  // re
         case ADD_func:
         case ADD_func:
             value = add_func(left_result, right_result, the_var);
             value = add_func(left_result, right_result, the_var);
             break;
             break;
+        case SUB_func:
+            value = sub_func(left_result, right_result, the_var);
+            break;
+        case MUL_func:
+            value = mul_func(left_result, right_result, the_var);
+            break;
+        case DIV_func:
+            value = div_func(left_result, right_result, the_var);
+            break;
         default:
         default:
             break;
             break;
     }
     }
     return value;
     return value;
 }
 }
 
 
+// ---------  ADD
 GWARF_result add_func(GWARF_result left_result, GWARF_result right_result, var_list *the_var){  // the func for add and call from read_statement_list
 GWARF_result add_func(GWARF_result left_result, GWARF_result right_result, var_list *the_var){  // the func for add and call from read_statement_list
     GWARF_result return_value;  // the result by call read_statement_list with left and right; value is the result for add
     GWARF_result return_value;  // the result by call read_statement_list with left and right; value is the result for add
-    
-    // 计算左右表达式的值
-    // void traverse(statement *the_statement, var_list *the_var)
-
     if((left_result.value.type = NUMBER_value) && (right_result.value.type = NUMBER_value)){  // all is NUMBER
     if((left_result.value.type = NUMBER_value) && (right_result.value.type = NUMBER_value)){  // all is NUMBER
         return_value.u = return_def;
         return_value.u = return_def;
         return_value.value.type = NUMBER_value;
         return_value.value.type = NUMBER_value;
         return_value.value.value.double_value = left_result.value.value.double_value + right_result.value.value.double_value;  // 数值相加运算
         return_value.value.value.double_value = left_result.value.value.double_value + right_result.value.value.double_value;  // 数值相加运算
     }
     }
+    return return_value;
+}
+
+// ---------  SUB
+GWARF_result sub_func(GWARF_result left_result, GWARF_result right_result, var_list *the_var){  // the func for sub and call from read_statement_list
+    GWARF_result return_value;  // the result by call read_statement_list with left and right; value is the result for add
+    if((left_result.value.type = NUMBER_value) && (right_result.value.type = NUMBER_value)){  // all is NUMBER
+        return_value.u = return_def;
+        return_value.value.type = NUMBER_value;
+        return_value.value.value.double_value = left_result.value.value.double_value - right_result.value.value.double_value;  // 数值相减运算
+    }
+    return return_value;
+}
+
+// ---------  MUL
+GWARF_result mul_func(GWARF_result left_result, GWARF_result right_result, var_list *the_var){  // the func for mul and call from read_statement_list
+    GWARF_result return_value;  // the result by call read_statement_list with left and right; value is the result for add
+    if((left_result.value.type = NUMBER_value) && (right_result.value.type = NUMBER_value)){  // all is NUMBER
+        return_value.u = return_def;
+        return_value.value.type = NUMBER_value;
+        return_value.value.value.double_value = left_result.value.value.double_value * right_result.value.value.double_value;  // 数值相乘运算
+    }
+    return return_value;
+}
 
 
+// ---------  DIV
+GWARF_result div_func(GWARF_result left_result, GWARF_result right_result, var_list *the_var){  // the func for div and call from read_statement_list
+    GWARF_result return_value;  // the result by call read_statement_list with left and right; value is the result for add
+    if((left_result.value.type = NUMBER_value) && (right_result.value.type = NUMBER_value)){  // all is NUMBER
+        return_value.u = return_def;
+        return_value.value.type = NUMBER_value;
+        return_value.value.value.double_value = left_result.value.value.double_value / right_result.value.value.double_value;  // 数值相除运算
+    }
     return return_value;
     return return_value;
 }
 }
 
 
@@ -179,13 +221,3 @@ inter *get_inter(){
     tmp->global_code = make_statement();
     tmp->global_code = make_statement();
     return tmp;
     return tmp;
 }
 }
-
-// int main(){
-//     global_inter = get_inter();  // 拿全局解释器[并声明全局变量]
-//     parser();
-//     var_list *the_var;
-//     printf("----start run----\n");
-//     traverse(global_inter->global_code, the_var);
-//     printf("code end...\n");
-//     return 0;
-// }

+ 0 - 207
include/var_linked.c

@@ -1,207 +0,0 @@
-#include <stdio.h>
-#include <stdlib.h>
-
-#define true 1
-#define false 0
-
-typedef enum node_type{
-    REAL = 1,
-    INT,
-    STRING,
-    OBJECT,
-    FIRST,
-} node_type;
-
-
-typedef union
-    {
-        double double_value;
-        int int_value;
-        char *string_value;
-        void *object_value;
-    } union_data;
-
-
-typedef struct linked_node
-{
-    struct linked_node *next_link;
-    struct linked_node *self_link;
-    struct linked_node *last_link;
-    char *name;
-    node_type type;
-    union_data data;
-} linked_node;
-
-
-linked_node *make_first_link();
-void append(union_data data,node_type type, char *name, linked_node *first);
-linked_node get_data(char *, linked_node *);
-void free_all(linked_node *);
-void print_all();
-void to_free(void *);
-void del(char *, linked_node *);
-
-
-void del(char *name, linked_node *first){
-    linked_node *last, *next, *self;
-    linked_node *last_link = first;
-    
-    while (true){
-        if (last_link->next_link == NULL){
-            return;
-        }
-        if (last_link->last_link == NULL){
-            last_link = (*last_link).next_link;
-            continue;
-        }
-        else if (last_link->name == name){
-            next = last_link->next_link;
-            last = last_link->last_link;
-            self = last_link;
-            break;
-        }
-        last_link = (*last_link).next_link;
-    }
-
-    last->next_link = next;
-    if(next != NULL){
-        next->last_link = last;
-    }
-    to_free(self);
-}
-
-
-void free_all(linked_node *first){
-    linked_node *next_link = first;
-    while (true){
-        if ((*next_link).next_link == NULL){
-            to_free(next_link);
-            break;
-        }
-        linked_node *tmp = (*next_link).next_link;
-        to_free(next_link);
-        next_link = tmp;
-    }
-}
-
-void to_free(void *address){
-    puts("-------------");
-    printf("free : %u\n", address);
-    free(address);
-}
-
-void print_all(linked_node *first){
-    linked_node *last_link = first;
-    puts("-------------");
-    while (true){
-        if ((*last_link).next_link == NULL){
-            printf("address = %-9u, data = ",last_link);
-            if ((*last_link).type == REAL){
-                printf("%-7f",last_link->data.double_value);
-            }else if ((*last_link).type == INT){
-                printf("%-7d",last_link->data.int_value);
-            }else if ((*last_link).type == STRING){
-                printf("%-7s",last_link->data.string_value);
-            }else if ((*last_link).type == OBJECT){
-                printf("%-7d",last_link->data.object_value);
-            }
-            printf(", name = %-5s\n",(*last_link).name);
-            break;
-        }
-        if (last_link->last_link == NULL){
-            last_link = (*last_link).next_link;
-            continue;
-        }
-        printf("address = %-9u, data = ",last_link);
-        if ((*last_link).type == REAL){
-            printf("%-7f",last_link->data.double_value);
-        }else if ((*last_link).type == INT){
-            printf("%-7d",last_link->data.int_value);
-        }else if ((*last_link).type == STRING){
-            printf("%-7s",last_link->data.string_value);
-        }else if ((*last_link).type == OBJECT){
-            printf("%-7d",last_link->data.object_value);
-        }
-        printf(", name = %-5s\n",(*last_link).name);
-        last_link = (*last_link).next_link;
-    }
-}
-
-linked_node get_data(char *name, linked_node *first){
-    linked_node *last_link = first;
-    while (true){
-        if ((*last_link).next_link == NULL){  // 这个必须要在首位[如果链表为空]
-            return (*first);
-        }
-        if ((*last_link).last_link == NULL){
-            last_link = (*last_link).next_link;
-            continue;
-        }
-        if ((*last_link).name == name){
-            return (*last_link);
-        }
-        last_link = (*last_link).next_link;
-    }
-}
-
-void append(union_data data,node_type type, char *name, linked_node *first){
-    linked_node *last_link = first;
-    int break_type = 1;
-    while (true){
-        if (last_link->next_link == NULL){  // 元素不存在
-            if (last_link->name == name){  // 已经存在元素
-                break_type = 2;
-            }
-            else{
-                break_type = 1;
-            }
-            break;
-        }
-        if ((*last_link).last_link == NULL){  // 忽略首元素[不参与下面的匹配(上面得参与,不然会越界)]
-            last_link = (*last_link).next_link;
-            continue;
-        }
-        if (last_link->name == name){  // 已经存在元素
-            break_type = 2;
-            break;
-        }
-        last_link = last_link->next_link;
-    }
-
-    if(break_type == 2){
-        last_link->data = data;
-        return;
-    }
-
-    linked_node *new_link;
-    new_link = malloc(sizeof(linked_node));
-    if (new_link == NULL){
-        return;
-    }
-    (*new_link).last_link = last_link;
-    (*new_link).next_link = NULL;
-    (*new_link).self_link = new_link;
-    (*new_link).data = data;
-    (*new_link).type = type;
-
-    // 设置节点序号
-    (*new_link).name = name;
-
-    // 修改节点信息
-    (*last_link).next_link = new_link;
-}
-
-linked_node *make_first_link(){
-    linked_node *first;
-    first = malloc(sizeof(linked_node));
-    if (first == NULL){
-        return NULL;
-    }
-    (*first).next_link = NULL;
-    (*first).self_link = first;
-    (*first).last_link = NULL;
-    (*first).name = "";
-    (*first).data.int_value = -1;
-    (*first).type = FIRST;
-    return first;
-}

+ 4 - 1
paser/gwarf_lex.l

@@ -17,7 +17,7 @@
 <INITIAL>"+" {return ADD;}
 <INITIAL>"+" {return ADD;}
 <INITIAL>"-" {return SUB;}
 <INITIAL>"-" {return SUB;}
 <INITIAL>"*" {return MUL;}
 <INITIAL>"*" {return MUL;}
-<INITIAL>\\ {return DIV;}
+<INITIAL>"/" {return DIV;}
 <INITIAL>"^" {return POW;}
 <INITIAL>"^" {return POW;}
 
 
 <INITIAL>"#" {BEGIN COMMENT;}
 <INITIAL>"#" {BEGIN COMMENT;}
@@ -31,7 +31,10 @@
     yylval.string_value = yytext;
     yylval.string_value = yytext;
     return VAR;
     return VAR;
     }
     }
+
+<INITIAL>" " ;
 <INITIAL>\n {return STOP;}
 <INITIAL>\n {return STOP;}
+<INITIAL>. {printf("text = [%s];\n", yytext);}
 
 
 <COMMENT>\n {BEGIN INITIAL;}
 <COMMENT>\n {BEGIN INITIAL;}
 <COMMENT>"#" {BEGIN INITIAL;}
 <COMMENT>"#" {BEGIN INITIAL;}

+ 38 - 6
paser/gwarf_yacc.y

@@ -14,7 +14,7 @@
 %token <double_value> NUMBER
 %token <double_value> NUMBER
 %token <string_value> STRING VAR
 %token <string_value> STRING VAR
 %token ADD SUB DIV MUL EQ LESS MORE RB LB RP LP WHILE STOP POW
 %token ADD SUB DIV MUL EQ LESS MORE RB LB RP LP WHILE STOP POW
-%type <statement_value> base_number first_number top_exp
+%type <statement_value> base_number second_number first_number top_exp
 %%
 %%
 command_list
 command_list
     : command
     : command
@@ -22,7 +22,8 @@ command_list
     ;
     ;
 
 
 command
 command
-    : top_exp STOP
+    : STOP
+    | top_exp STOP
     {
     {
         append_statement(global_inter->global_code, $1);
         append_statement(global_inter->global_code, $1);
     }
     }
@@ -36,14 +37,45 @@ top_exp
     ;
     ;
 
 
 first_number
 first_number
-    : base_number
-    | first_number ADD base_number
+    : second_number
+    | first_number ADD second_number
     {
     {
         statement *code_tmp =  make_statement();
         statement *code_tmp =  make_statement();
         code_tmp->type = operation;
         code_tmp->type = operation;
         code_tmp->code.operation.type = ADD_func;
         code_tmp->code.operation.type = ADD_func;
-        code_tmp->code.operation.right_exp = $1;
-        code_tmp->code.operation.left_exp = $3;
+        code_tmp->code.operation.left_exp = $1;
+        code_tmp->code.operation.right_exp = $3;
+        $$ = code_tmp;
+    }
+    | first_number SUB second_number
+    {
+        statement *code_tmp =  make_statement();
+        code_tmp->type = operation;
+        code_tmp->code.operation.type = SUB_func;
+        code_tmp->code.operation.left_exp = $1;
+        code_tmp->code.operation.right_exp = $3;
+        $$ = code_tmp;
+    }
+    ;
+
+second_number
+    : base_number
+    | second_number MUL base_number
+    {
+        statement *code_tmp =  make_statement();
+        code_tmp->type = operation;
+        code_tmp->code.operation.type = MUL_func;
+        code_tmp->code.operation.left_exp = $1;
+        code_tmp->code.operation.right_exp = $3;
+        $$ = code_tmp;
+    }
+    | second_number DIV base_number
+    {
+        statement *code_tmp =  make_statement();
+        code_tmp->type = operation;
+        code_tmp->code.operation.type = DIV_func;
+        code_tmp->code.operation.left_exp = $1;
+        code_tmp->code.operation.right_exp = $3;
         $$ = code_tmp;
         $$ = code_tmp;
     }
     }
     ;
     ;

+ 82 - 72
paser/lex.yy.c

@@ -351,8 +351,8 @@ static void yynoreturn yy_fatal_error ( const char* msg  );
 	(yy_hold_char) = *yy_cp; \
 	(yy_hold_char) = *yy_cp; \
 	*yy_cp = '\0'; \
 	*yy_cp = '\0'; \
 	(yy_c_buf_p) = yy_cp;
 	(yy_c_buf_p) = yy_cp;
-#define YY_NUM_RULES 27
-#define YY_END_OF_BUFFER 28
+#define YY_NUM_RULES 29
+#define YY_END_OF_BUFFER 30
 /* This struct is not used in this scanner,
 /* This struct is not used in this scanner,
    but its presence is necessary. */
    but its presence is necessary. */
 struct yy_trans_info
 struct yy_trans_info
@@ -360,13 +360,13 @@ struct yy_trans_info
 	flex_int32_t yy_verify;
 	flex_int32_t yy_verify;
 	flex_int32_t yy_nxt;
 	flex_int32_t yy_nxt;
 	};
 	};
-static const flex_int16_t yy_accept[45] =
+static const flex_int16_t yy_accept[46] =
     {   0,
     {   0,
-        0,    0,    0,    0,    0,    0,   28,   27,   19,   16,
-       14,   15,    2,    3,   11,    9,   10,   17,   17,    7,
-        8,    6,   18,   12,   13,   18,    4,    5,   22,   20,
-       21,   26,   25,   24,   23,    0,   17,   18,   18,   17,
-       18,   18,    1,    0
+        0,    0,    0,    0,    0,    0,   30,   21,   20,   19,
+       16,   14,   15,    2,    3,   11,    9,   10,   12,   17,
+       17,    7,    8,    6,   18,   13,   18,    4,    5,   24,
+       22,   23,   28,   27,   26,   25,    0,   17,   18,   18,
+       17,   18,   18,    1,    0
     } ;
     } ;
 
 
 static const YY_CHAR yy_ec[256] =
 static const YY_CHAR yy_ec[256] =
@@ -374,17 +374,17 @@ static const YY_CHAR yy_ec[256] =
         1,    1,    1,    1,    1,    1,    1,    1,    1,    2,
         1,    1,    1,    1,    1,    1,    1,    1,    1,    2,
         1,    1,    1,    1,    1,    1,    1,    1,    1,    1,
         1,    1,    1,    1,    1,    1,    1,    1,    1,    1,
         1,    1,    1,    1,    1,    1,    1,    1,    1,    1,
         1,    1,    1,    1,    1,    1,    1,    1,    1,    1,
-        1,    1,    1,    3,    4,    1,    1,    1,    5,    6,
-        7,    8,    9,    1,   10,   11,    1,   12,   13,   13,
-       13,   13,   13,   13,   13,   13,   13,    1,    1,   14,
-       15,   16,    1,    1,   17,   17,   17,   17,   17,   17,
-       17,   17,   17,   17,   17,   17,   17,   17,   17,   17,
-       17,   17,   17,   17,   17,   17,   17,   17,   17,   17,
-        1,   18,    1,   19,   17,    1,   17,   17,   17,   17,
-
-       20,   17,   17,   21,   22,   17,   17,   23,   17,   17,
-       17,   17,   17,   17,   17,   17,   17,   17,   24,   17,
-       17,   17,   25,    1,   26,    1,    1,    1,    1,    1,
+        1,    3,    1,    4,    5,    1,    1,    1,    6,    7,
+        8,    9,   10,    1,   11,   12,   13,   14,   15,   15,
+       15,   15,   15,   15,   15,   15,   15,    1,    1,   16,
+       17,   18,    1,    1,   19,   19,   19,   19,   19,   19,
+       19,   19,   19,   19,   19,   19,   19,   19,   19,   19,
+       19,   19,   19,   19,   19,   19,   19,   19,   19,   19,
+        1,    1,    1,   20,   19,    1,   19,   19,   19,   19,
+
+       21,   19,   19,   22,   23,   19,   19,   24,   19,   19,
+       19,   19,   19,   19,   19,   19,   19,   19,   25,   19,
+       19,   19,   26,    1,   27,    1,    1,    1,    1,    1,
         1,    1,    1,    1,    1,    1,    1,    1,    1,    1,
         1,    1,    1,    1,    1,    1,    1,    1,    1,    1,
         1,    1,    1,    1,    1,    1,    1,    1,    1,    1,
         1,    1,    1,    1,    1,    1,    1,    1,    1,    1,
         1,    1,    1,    1,    1,    1,    1,    1,    1,    1,
         1,    1,    1,    1,    1,    1,    1,    1,    1,    1,
@@ -401,55 +401,55 @@ static const YY_CHAR yy_ec[256] =
         1,    1,    1,    1,    1
         1,    1,    1,    1,    1
     } ;
     } ;
 
 
-static const YY_CHAR yy_meta[27] =
+static const YY_CHAR yy_meta[28] =
     {   0,
     {   0,
         1,    1,    1,    1,    1,    1,    1,    1,    1,    1,
         1,    1,    1,    1,    1,    1,    1,    1,    1,    1,
-        1,    2,    2,    1,    1,    1,    2,    1,    1,    2,
-        2,    2,    2,    2,    1,    1
+        1,    1,    1,    2,    2,    1,    1,    1,    2,    1,
+        2,    2,    2,    2,    2,    1,    1
     } ;
     } ;
 
 
-static const flex_int16_t yy_base[48] =
+static const flex_int16_t yy_base[49] =
     {   0,
     {   0,
-        0,    0,   25,   26,   29,   33,   56,   57,   57,   57,
-       57,   57,   57,   57,   57,   57,   57,   57,   28,   57,
-       57,   57,    0,   57,   57,   34,   57,   57,   57,   57,
-       57,   57,   57,   57,   57,   30,   33,    0,   32,   35,
-       30,   17,    0,   57,   48,   50,   31
+        0,    0,   26,   27,   31,   32,   57,   58,   58,   58,
+       58,   58,   58,   58,   58,   58,   58,   58,   58,   58,
+       27,   58,   58,   58,    0,   58,   34,   58,   58,   58,
+       58,   58,   58,   58,   58,   58,   29,   33,    0,   32,
+       35,   22,   19,    0,   58,   50,   52,   28
     } ;
     } ;
 
 
-static const flex_int16_t yy_def[48] =
+static const flex_int16_t yy_def[49] =
     {   0,
     {   0,
-       44,    1,   45,   45,   46,   46,   44,   44,   44,   44,
-       44,   44,   44,   44,   44,   44,   44,   44,   44,   44,
-       44,   44,   47,   44,   44,   47,   44,   44,   44,   44,
-       44,   44,   44,   44,   44,   44,   44,   47,   47,   44,
-       47,   47,   47,    0,   44,   44,   44
+       45,    1,   46,   46,   47,   47,   45,   45,   45,   45,
+       45,   45,   45,   45,   45,   45,   45,   45,   45,   45,
+       45,   45,   45,   45,   48,   45,   48,   45,   45,   45,
+       45,   45,   45,   45,   45,   45,   45,   45,   48,   48,
+       45,   48,   48,   48,    0,   45,   45,   45
     } ;
     } ;
 
 
-static const flex_int16_t yy_nxt[84] =
+static const flex_int16_t yy_nxt[86] =
     {   0,
     {   0,
         8,    9,   10,   11,   12,   13,   14,   15,   16,   17,
         8,    9,   10,   11,   12,   13,   14,   15,   16,   17,
-        8,   18,   19,   20,   21,   22,   23,   24,   25,   23,
-       23,   23,   23,   26,   27,   28,   30,   30,   31,   31,
-       33,   34,   38,   35,   33,   34,   43,   35,   36,   37,
-       37,   40,   40,   36,   37,   37,   40,   40,   29,   29,
-       32,   32,   42,   41,   39,   44,    7,   44,   44,   44,
-       44,   44,   44,   44,   44,   44,   44,   44,   44,   44,
-       44,   44,   44,   44,   44,   44,   44,   44,   44,   44,
-       44,   44,   44
+       18,    8,   19,   20,   21,   22,   23,   24,   25,   26,
+       25,   25,   25,   25,   27,   28,   29,   31,   31,   39,
+       32,   32,   34,   34,   35,   35,   36,   36,   37,   44,
+       38,   38,   41,   41,   37,   43,   38,   38,   41,   41,
+       30,   30,   33,   33,   42,   40,   45,    7,   45,   45,
+       45,   45,   45,   45,   45,   45,   45,   45,   45,   45,
+       45,   45,   45,   45,   45,   45,   45,   45,   45,   45,
+       45,   45,   45,   45,   45
     } ;
     } ;
 
 
-static const flex_int16_t yy_chk[84] =
+static const flex_int16_t yy_chk[86] =
     {   0,
     {   0,
         1,    1,    1,    1,    1,    1,    1,    1,    1,    1,
         1,    1,    1,    1,    1,    1,    1,    1,    1,    1,
         1,    1,    1,    1,    1,    1,    1,    1,    1,    1,
         1,    1,    1,    1,    1,    1,    1,    1,    1,    1,
-        1,    1,    1,    1,    1,    1,    3,    4,    3,    4,
-        5,    5,   47,    5,    6,    6,   42,    6,   19,   19,
-       19,   36,   36,   37,   37,   37,   40,   40,   45,   45,
-       46,   46,   41,   39,   26,    7,   44,   44,   44,   44,
-       44,   44,   44,   44,   44,   44,   44,   44,   44,   44,
-       44,   44,   44,   44,   44,   44,   44,   44,   44,   44,
-       44,   44,   44
+        1,    1,    1,    1,    1,    1,    1,    3,    4,   48,
+        3,    4,    5,    6,    5,    6,    5,    6,   21,   43,
+       21,   21,   37,   37,   38,   42,   38,   38,   41,   41,
+       46,   46,   47,   47,   40,   27,    7,   45,   45,   45,
+       45,   45,   45,   45,   45,   45,   45,   45,   45,   45,
+       45,   45,   45,   45,   45,   45,   45,   45,   45,   45,
+       45,   45,   45,   45,   45
     } ;
     } ;
 
 
 static yy_state_type yy_last_accepting_state;
 static yy_state_type yy_last_accepting_state;
@@ -720,13 +720,13 @@ yy_match:
 			while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state )
 			while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state )
 				{
 				{
 				yy_current_state = (int) yy_def[yy_current_state];
 				yy_current_state = (int) yy_def[yy_current_state];
-				if ( yy_current_state >= 45 )
+				if ( yy_current_state >= 46 )
 					yy_c = yy_meta[yy_c];
 					yy_c = yy_meta[yy_c];
 				}
 				}
 			yy_current_state = yy_nxt[yy_base[yy_current_state] + yy_c];
 			yy_current_state = yy_nxt[yy_base[yy_current_state] + yy_c];
 			++yy_cp;
 			++yy_cp;
 			}
 			}
-		while ( yy_base[yy_current_state] != 57 );
+		while ( yy_base[yy_current_state] != 58 );
 
 
 yy_find_action:
 yy_find_action:
 		yy_act = yy_accept[yy_current_state];
 		yy_act = yy_accept[yy_current_state];
@@ -847,26 +847,26 @@ YY_RULE_SETUP
     }
     }
 	YY_BREAK
 	YY_BREAK
 case 19:
 case 19:
-/* rule 19 can match eol */
 YY_RULE_SETUP
 YY_RULE_SETUP
-#line 34 "gwarf_lex.l"
-{return STOP;}
+#line 35 "gwarf_lex.l"
+;
 	YY_BREAK
 	YY_BREAK
 case 20:
 case 20:
 /* rule 20 can match eol */
 /* rule 20 can match eol */
 YY_RULE_SETUP
 YY_RULE_SETUP
 #line 36 "gwarf_lex.l"
 #line 36 "gwarf_lex.l"
-{BEGIN INITIAL;}
+{return STOP;}
 	YY_BREAK
 	YY_BREAK
 case 21:
 case 21:
 YY_RULE_SETUP
 YY_RULE_SETUP
 #line 37 "gwarf_lex.l"
 #line 37 "gwarf_lex.l"
-{BEGIN INITIAL;}
+{printf("text = [%s];\n", yytext);}
 	YY_BREAK
 	YY_BREAK
 case 22:
 case 22:
+/* rule 22 can match eol */
 YY_RULE_SETUP
 YY_RULE_SETUP
-#line 38 "gwarf_lex.l"
-;
+#line 39 "gwarf_lex.l"
+{BEGIN INITIAL;}
 	YY_BREAK
 	YY_BREAK
 case 23:
 case 23:
 YY_RULE_SETUP
 YY_RULE_SETUP
@@ -876,31 +876,41 @@ YY_RULE_SETUP
 case 24:
 case 24:
 YY_RULE_SETUP
 YY_RULE_SETUP
 #line 41 "gwarf_lex.l"
 #line 41 "gwarf_lex.l"
-{BEGIN INITIAL;}
+;
 	YY_BREAK
 	YY_BREAK
 case 25:
 case 25:
-/* rule 25 can match eol */
 YY_RULE_SETUP
 YY_RULE_SETUP
-#line 42 "gwarf_lex.l"
+#line 43 "gwarf_lex.l"
+{BEGIN INITIAL;}
+	YY_BREAK
+case 26:
+YY_RULE_SETUP
+#line 44 "gwarf_lex.l"
+{BEGIN INITIAL;}
+	YY_BREAK
+case 27:
+/* rule 27 can match eol */
+YY_RULE_SETUP
+#line 45 "gwarf_lex.l"
 {
 {
     yylval.string_value = yytext;
     yylval.string_value = yytext;
     return STRING;
     return STRING;
     }
     }
 	YY_BREAK
 	YY_BREAK
-case 26:
+case 28:
 YY_RULE_SETUP
 YY_RULE_SETUP
-#line 46 "gwarf_lex.l"
+#line 49 "gwarf_lex.l"
 {
 {
     yylval.string_value = yytext;
     yylval.string_value = yytext;
     return STRING;
     return STRING;
     }
     }
 	YY_BREAK
 	YY_BREAK
-case 27:
+case 29:
 YY_RULE_SETUP
 YY_RULE_SETUP
-#line 50 "gwarf_lex.l"
+#line 53 "gwarf_lex.l"
 ECHO;
 ECHO;
 	YY_BREAK
 	YY_BREAK
-#line 903 "lex.yy.c"
+#line 913 "lex.yy.c"
 case YY_STATE_EOF(INITIAL):
 case YY_STATE_EOF(INITIAL):
 case YY_STATE_EOF(COMMENT):
 case YY_STATE_EOF(COMMENT):
 case YY_STATE_EOF(STRING_TEXT):
 case YY_STATE_EOF(STRING_TEXT):
@@ -1199,7 +1209,7 @@ static int yy_get_next_buffer (void)
 		while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state )
 		while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state )
 			{
 			{
 			yy_current_state = (int) yy_def[yy_current_state];
 			yy_current_state = (int) yy_def[yy_current_state];
-			if ( yy_current_state >= 45 )
+			if ( yy_current_state >= 46 )
 				yy_c = yy_meta[yy_c];
 				yy_c = yy_meta[yy_c];
 			}
 			}
 		yy_current_state = yy_nxt[yy_base[yy_current_state] + yy_c];
 		yy_current_state = yy_nxt[yy_base[yy_current_state] + yy_c];
@@ -1227,11 +1237,11 @@ static int yy_get_next_buffer (void)
 	while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state )
 	while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state )
 		{
 		{
 		yy_current_state = (int) yy_def[yy_current_state];
 		yy_current_state = (int) yy_def[yy_current_state];
-		if ( yy_current_state >= 45 )
+		if ( yy_current_state >= 46 )
 			yy_c = yy_meta[yy_c];
 			yy_c = yy_meta[yy_c];
 		}
 		}
 	yy_current_state = yy_nxt[yy_base[yy_current_state] + yy_c];
 	yy_current_state = yy_nxt[yy_base[yy_current_state] + yy_c];
-	yy_is_jam = (yy_current_state == 44);
+	yy_is_jam = (yy_current_state == 45);
 
 
 		return yy_is_jam ? 0 : yy_current_state;
 		return yy_is_jam ? 0 : yy_current_state;
 }
 }
@@ -1907,7 +1917,7 @@ void yyfree (void * ptr )
 
 
 #define YYTABLES_NAME "yytables"
 #define YYTABLES_NAME "yytables"
 
 
-#line 50 "gwarf_lex.l"
+#line 53 "gwarf_lex.l"
 
 
 int yywrap(void) {
 int yywrap(void) {
     return 1;
     return 1;

+ 79 - 35
paser/y.tab.c

@@ -487,18 +487,18 @@ union yyalloc
 #endif /* !YYCOPY_NEEDED */
 #endif /* !YYCOPY_NEEDED */
 
 
 /* YYFINAL -- State number of the termination state.  */
 /* YYFINAL -- State number of the termination state.  */
-#define YYFINAL  7
+#define YYFINAL  9
 /* YYLAST -- Last index in YYTABLE.  */
 /* YYLAST -- Last index in YYTABLE.  */
-#define YYLAST   6
+#define YYLAST   18
 
 
 /* YYNTOKENS -- Number of terminals.  */
 /* YYNTOKENS -- Number of terminals.  */
 #define YYNTOKENS  20
 #define YYNTOKENS  20
 /* YYNNTS -- Number of nonterminals.  */
 /* YYNNTS -- Number of nonterminals.  */
-#define YYNNTS  6
+#define YYNNTS  7
 /* YYNRULES -- Number of rules.  */
 /* YYNRULES -- Number of rules.  */
-#define YYNRULES  8
+#define YYNRULES  13
 /* YYNSTATES -- Number of states.  */
 /* YYNSTATES -- Number of states.  */
-#define YYNSTATES  12
+#define YYNSTATES  20
 
 
 #define YYUNDEFTOK  2
 #define YYUNDEFTOK  2
 #define YYMAXUTOK   274
 #define YYMAXUTOK   274
@@ -547,7 +547,8 @@ static const yytype_int8 yytranslate[] =
   /* YYRLINE[YYN] -- Source line where rule number YYN was defined.  */
   /* YYRLINE[YYN] -- Source line where rule number YYN was defined.  */
 static const yytype_int8 yyrline[] =
 static const yytype_int8 yyrline[] =
 {
 {
-       0,    20,    20,    21,    25,    32,    39,    40,    52
+       0,    20,    20,    21,    25,    26,    33,    40,    41,    50,
+      62,    63,    72,    84
 };
 };
 #endif
 #endif
 
 
@@ -559,7 +560,7 @@ static const char *const yytname[] =
   "$end", "error", "$undefined", "NUMBER", "STRING", "VAR", "ADD", "SUB",
   "$end", "error", "$undefined", "NUMBER", "STRING", "VAR", "ADD", "SUB",
   "DIV", "MUL", "EQ", "LESS", "MORE", "RB", "LB", "RP", "LP", "WHILE",
   "DIV", "MUL", "EQ", "LESS", "MORE", "RB", "LB", "RP", "LP", "WHILE",
   "STOP", "POW", "$accept", "command_list", "command", "top_exp",
   "STOP", "POW", "$accept", "command_list", "command", "top_exp",
-  "first_number", "base_number", YY_NULLPTR
+  "first_number", "second_number", "base_number", YY_NULLPTR
 };
 };
 #endif
 #endif
 
 
@@ -587,8 +588,8 @@ static const yytype_int16 yytoknum[] =
      STATE-NUM.  */
      STATE-NUM.  */
 static const yytype_int8 yypact[] =
 static const yytype_int8 yypact[] =
 {
 {
-      -2,   -17,     0,   -17,   -16,    -1,   -17,   -17,   -17,   -17,
-      -2,   -17
+      -2,   -17,   -17,     0,   -17,   -16,    -1,     1,   -17,   -17,
+     -17,   -17,    10,    10,    10,    10,     1,     1,   -17,   -17
 };
 };
 
 
   /* YYDEFACT[STATE-NUM] -- Default reduction number in state STATE-NUM.
   /* YYDEFACT[STATE-NUM] -- Default reduction number in state STATE-NUM.
@@ -596,20 +597,20 @@ static const yytype_int8 yypact[] =
      means the default is an error.  */
      means the default is an error.  */
 static const yytype_int8 yydefact[] =
 static const yytype_int8 yydefact[] =
 {
 {
-       0,     8,     0,     2,     0,     5,     6,     1,     3,     4,
-       0,     7
+       0,    13,     4,     0,     2,     0,     6,     7,    10,     1,
+       3,     5,     0,     0,     0,     0,     8,     9,    12,    11
 };
 };
 
 
   /* YYPGOTO[NTERM-NUM].  */
   /* YYPGOTO[NTERM-NUM].  */
 static const yytype_int8 yypgoto[] =
 static const yytype_int8 yypgoto[] =
 {
 {
-     -17,   -17,     2,   -17,   -17,    -4
+     -17,   -17,    11,   -17,   -17,    -5,    -3
 };
 };
 
 
   /* YYDEFGOTO[NTERM-NUM].  */
   /* YYDEFGOTO[NTERM-NUM].  */
 static const yytype_int8 yydefgoto[] =
 static const yytype_int8 yydefgoto[] =
 {
 {
-      -1,     2,     3,     4,     5,     6
+      -1,     3,     4,     5,     6,     7,     8
 };
 };
 
 
   /* YYTABLE[YYPACT[STATE-NUM]] -- What to do in state STATE-NUM.  If
   /* YYTABLE[YYPACT[STATE-NUM]] -- What to do in state STATE-NUM.  If
@@ -617,32 +618,36 @@ static const yytype_int8 yydefgoto[] =
      number is the opposite.  If YYTABLE_NINF, syntax error.  */
      number is the opposite.  If YYTABLE_NINF, syntax error.  */
 static const yytype_int8 yytable[] =
 static const yytype_int8 yytable[] =
 {
 {
-       7,     1,     9,     1,     8,    10,    11
+       9,     1,    11,     1,     0,    12,    13,    16,    17,    14,
+      15,    18,    19,     1,    10,     0,     2,     0,     2
 };
 };
 
 
 static const yytype_int8 yycheck[] =
 static const yytype_int8 yycheck[] =
 {
 {
-       0,     3,    18,     3,     2,     6,    10
+       0,     3,    18,     3,    -1,     6,     7,    12,    13,     8,
+       9,    14,    15,     3,     3,    -1,    18,    -1,    18
 };
 };
 
 
   /* YYSTOS[STATE-NUM] -- The (internal number of the) accessing
   /* YYSTOS[STATE-NUM] -- The (internal number of the) accessing
      symbol of state STATE-NUM.  */
      symbol of state STATE-NUM.  */
 static const yytype_int8 yystos[] =
 static const yytype_int8 yystos[] =
 {
 {
-       0,     3,    21,    22,    23,    24,    25,     0,    22,    18,
-       6,    25
+       0,     3,    18,    21,    22,    23,    24,    25,    26,     0,
+      22,    18,     6,     7,     8,     9,    25,    25,    26,    26
 };
 };
 
 
   /* YYR1[YYN] -- Symbol number of symbol that rule YYN derives.  */
   /* YYR1[YYN] -- Symbol number of symbol that rule YYN derives.  */
 static const yytype_int8 yyr1[] =
 static const yytype_int8 yyr1[] =
 {
 {
-       0,    20,    21,    21,    22,    23,    24,    24,    25
+       0,    20,    21,    21,    22,    22,    23,    24,    24,    24,
+      25,    25,    25,    26
 };
 };
 
 
   /* YYR2[YYN] -- Number of symbols on the right hand side of rule YYN.  */
   /* YYR2[YYN] -- Number of symbols on the right hand side of rule YYN.  */
 static const yytype_int8 yyr2[] =
 static const yytype_int8 yyr2[] =
 {
 {
-       0,     2,     1,     2,     2,     1,     1,     3,     1
+       0,     2,     1,     2,     1,     2,     1,     1,     3,     3,
+       1,     3,     3,     1
 };
 };
 
 
 
 
@@ -1337,37 +1342,76 @@ yyreduce:
   YY_REDUCE_PRINT (yyn);
   YY_REDUCE_PRINT (yyn);
   switch (yyn)
   switch (yyn)
     {
     {
-  case 4:
-#line 26 "gwarf_yacc.y"
+  case 5:
+#line 27 "gwarf_yacc.y"
     {
     {
         append_statement(global_inter->global_code, (yyvsp[-1].statement_value));
         append_statement(global_inter->global_code, (yyvsp[-1].statement_value));
     }
     }
-#line 1346 "y.tab.c"
+#line 1351 "y.tab.c"
     break;
     break;
 
 
-  case 5:
-#line 33 "gwarf_yacc.y"
+  case 6:
+#line 34 "gwarf_yacc.y"
     {
     {
         (yyval.statement_value) = (yyvsp[0].statement_value);
         (yyval.statement_value) = (yyvsp[0].statement_value);
     }
     }
-#line 1354 "y.tab.c"
+#line 1359 "y.tab.c"
     break;
     break;
 
 
-  case 7:
-#line 41 "gwarf_yacc.y"
+  case 8:
+#line 42 "gwarf_yacc.y"
     {
     {
         statement *code_tmp =  make_statement();
         statement *code_tmp =  make_statement();
         code_tmp->type = operation;
         code_tmp->type = operation;
         code_tmp->code.operation.type = ADD_func;
         code_tmp->code.operation.type = ADD_func;
-        code_tmp->code.operation.right_exp = (yyvsp[-2].statement_value);
-        code_tmp->code.operation.left_exp = (yyvsp[0].statement_value);
+        code_tmp->code.operation.left_exp = (yyvsp[-2].statement_value);
+        code_tmp->code.operation.right_exp = (yyvsp[0].statement_value);
         (yyval.statement_value) = code_tmp;
         (yyval.statement_value) = code_tmp;
     }
     }
-#line 1367 "y.tab.c"
+#line 1372 "y.tab.c"
     break;
     break;
 
 
-  case 8:
-#line 53 "gwarf_yacc.y"
+  case 9:
+#line 51 "gwarf_yacc.y"
+    {
+        statement *code_tmp =  make_statement();
+        code_tmp->type = operation;
+        code_tmp->code.operation.type = SUB_func;
+        code_tmp->code.operation.left_exp = (yyvsp[-2].statement_value);
+        code_tmp->code.operation.right_exp = (yyvsp[0].statement_value);
+        (yyval.statement_value) = code_tmp;
+    }
+#line 1385 "y.tab.c"
+    break;
+
+  case 11:
+#line 64 "gwarf_yacc.y"
+    {
+        statement *code_tmp =  make_statement();
+        code_tmp->type = operation;
+        code_tmp->code.operation.type = MUL_func;
+        code_tmp->code.operation.left_exp = (yyvsp[-2].statement_value);
+        code_tmp->code.operation.right_exp = (yyvsp[0].statement_value);
+        (yyval.statement_value) = code_tmp;
+    }
+#line 1398 "y.tab.c"
+    break;
+
+  case 12:
+#line 73 "gwarf_yacc.y"
+    {
+        statement *code_tmp =  make_statement();
+        code_tmp->type = operation;
+        code_tmp->code.operation.type = DIV_func;
+        code_tmp->code.operation.left_exp = (yyvsp[-2].statement_value);
+        code_tmp->code.operation.right_exp = (yyvsp[0].statement_value);
+        (yyval.statement_value) = code_tmp;
+    }
+#line 1411 "y.tab.c"
+    break;
+
+  case 13:
+#line 85 "gwarf_yacc.y"
     {
     {
         statement *code_tmp =  make_statement();
         statement *code_tmp =  make_statement();
         code_tmp->type = base_value;
         code_tmp->type = base_value;
@@ -1375,11 +1419,11 @@ yyreduce:
         code_tmp->code.base_value.value.value.double_value = (yyvsp[0].double_value);
         code_tmp->code.base_value.value.value.double_value = (yyvsp[0].double_value);
         (yyval.statement_value) = code_tmp;
         (yyval.statement_value) = code_tmp;
     }
     }
-#line 1379 "y.tab.c"
+#line 1423 "y.tab.c"
     break;
     break;
 
 
 
 
-#line 1383 "y.tab.c"
+#line 1427 "y.tab.c"
 
 
       default: break;
       default: break;
     }
     }
@@ -1611,7 +1655,7 @@ yyreturn:
 #endif
 #endif
   return yyresult;
   return yyresult;
 }
 }
-#line 62 "gwarf_yacc.y"
+#line 94 "gwarf_yacc.y"
 
 
 int yyerror(char const *str)
 int yyerror(char const *str)
 {
 {