Browse Source

实现基本的运算和变量系统

SongZihuan 5 years ago
parent
commit
c0a2c4f13b
9 changed files with 659 additions and 196 deletions
  1. BIN
      gwarf
  2. 2 2
      gwarf.c
  3. 12 2
      gwarf_interpreter/interprete.h
  4. 150 15
      gwarf_interpreter/interpreter.c
  5. 4 0
      paser/gwarf_lex.l
  6. 121 12
      paser/gwarf_yacc.y
  7. 128 102
      paser/lex.yy.c
  8. 230 59
      paser/y.tab.c
  9. 12 4
      paser/y.tab.h

BIN
gwarf


+ 2 - 2
gwarf.c

@@ -5,9 +5,9 @@
 int main(){
     global_inter = get_inter();  // 拿全局解释器[并声明全局变量]
     parser();
-    var_list *the_var;
+    var_list *the_var = make_var_base(global_inter->global_var);
     printf("----start run----\n");
-    traverse(global_inter->global_code, the_var);
+    traverse(global_inter->global_code, the_var,false);
     printf("code end...\n");
     return 0;
 }

+ 12 - 2
gwarf_interpreter/interprete.h

@@ -1,3 +1,6 @@
+#define false 0
+#define true 1
+#define bool int
 
 // the type of data(GWARF_value)
 typedef enum{
@@ -44,6 +47,12 @@ typedef struct statement{
                 DIV_func,  // /
                 MUL_func,  // *
                 ASSIGMENT_func, // =
+                EQUAL_func,  // ==
+                MORE_func,  // >
+                LESS_func,  // <
+                MOREEQ_func,  // >=
+                LESSEQ_func,  // <=
+                NOTEQ_func,  // <>
             } type;
             struct statement *right_exp;  // the right exp
             struct statement *left_exp;  // the left exp
@@ -67,6 +76,7 @@ typedef struct GWARF_result{
     enum{
         return_def=1,
         break_while,
+        wrong,
     } u;  // the result type[from where]
 } GWARF_result;
 
@@ -74,7 +84,7 @@ typedef struct GWARF_result{
 
 typedef struct var_list{
     var *var_base;
-    var *next;
+    struct var_list *next;
 } var_list;
 
 // ------------------------- inter
@@ -96,7 +106,7 @@ statement *make_statement();
 statement *append_statement(statement *, statement*);
 
 //------- run func
-GWARF_result traverse(statement *, var_list *);
+GWARF_result traverse(statement *, var_list *, bool);
 
 //------- inter func
 inter *get_inter();

+ 150 - 15
gwarf_interpreter/interpreter.c

@@ -9,6 +9,8 @@ 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 *);
+GWARF_result assigment_func(char *, GWARF_result, var_list *);
+GWARF_result equal_func(GWARF_result, GWARF_result, var_list *, int type);
 
 // ------------------------- var func
 
@@ -38,10 +40,10 @@ void append_var(char *name, GWARF_value value, var *base_var){
         tmp->value = value;
         return;
     }
-    var *new_tmp;
-    new_tmp = make_var();  // make a new var
+    var *new_tmp = make_var();
     tmp->next = new_tmp;
-    new_tmp->name = name;
+    new_tmp->name = malloc(sizeof(name));
+    strcpy(new_tmp->name, name);
     new_tmp->value = value;
 }
 
@@ -61,7 +63,7 @@ void free_var(var *base_var){  // free the address
 var *get_var(char *name, var *base_var){  // get the address
     var *tmp = base_var;  // iter var
     while(1){
-        if (tmp->name == name){
+        if (!strcmp(tmp->name, name)){  // if tmp->name == name , strcmp will return 0, if not strcmp return not 0
             return tmp;
         }
         if (tmp->next == NULL){  // not var name *name
@@ -111,6 +113,65 @@ statement *append_statement(statement *base_statement, statement *new_tmp){  //
     return new_tmp;
 }
 
+// ------------------------- var_list
+
+var_list *make_var_list(){  // make a empty var_list node
+    var_list *tmp;
+    tmp = malloc(sizeof(var_list));  // get an address for base var
+    tmp->next = NULL;
+    tmp->var_base = NULL;
+    return tmp;
+}
+
+var_list *make_var_base(var *gloabl_var){
+    var_list *tmp = make_var_list();
+    tmp->var_base = gloabl_var;
+    return tmp;
+}
+
+
+var_list *append_var_list(var *var_base, var_list *var_list_base){  // make var_list[FILO]
+    var_list *tmp = make_var_list();
+    tmp->var_base = var_base;
+    tmp->next = var_list_base;
+    return tmp;
+}
+
+var *find_var(var_list *var_base,int from, char *name){  // find var by func get_var in var_list[iter to find]
+    var_list *start = var_base;
+    var *return_var;
+    for(int i = 0;i < from;i+= 1){
+        if(start->next = NULL){
+            break;
+        }
+        start = start->next;
+    }
+    while (1)
+    {
+        return_var = get_var(name, start->var_base);
+        if((return_var == NULL) && (start->next == NULL)){  // don't get the var and not next
+            return NULL;
+        }
+        else if((return_var == NULL) && (start->next != NULL)){  // don't get the var but can next
+            start = start->next;
+            continue;
+        }
+        return return_var;  //get var success can or can't next
+    }
+}
+
+void add_var(var_list *var_base,int from, char *name, GWARF_value value){  // add var by func append_var in var_list[iter to find]
+    var_list *start = var_base;
+    var *return_var;
+    for(int i = 0;i < from;i+= 1){
+        if(start->next = NULL){
+            break;
+        }
+        start = start->next;
+    }
+    append_var(name, value, start->var_base);
+}
+
 // ------------------------- run code
 
 GWARF_result read_statement_list(statement *the_statement, var_list *the_var){  // read the statement list with case to run by func
@@ -121,10 +182,22 @@ GWARF_result read_statement_list(statement *the_statement, var_list *the_var){
             return_value = operation_func(the_statement, the_var);
             printf("operation value = %f\n", return_value.value.value.double_value);
             break;
-        case 4:
+        case base_value:
             return_value.value = (the_statement->code).base_value.value;  // code
             printf("get value = %f\n", return_value.value.value.double_value);
             break;
+        case base_var:{    // because the var tmp, we should ues a {} to make a block[name space] for the tmp var;
+            var *tmp = find_var(the_var, 0, (the_statement->code).base_var.var_name);
+            if(tmp == NULL){
+                return_value.u = wrong;  // not var
+            }
+            else
+            {
+                return_value.value = tmp->value;  // get_var
+                printf("var value = %f\n", return_value.value.value.double_value);
+            }
+            break;
+        }
         default:
             puts("default");
             break;
@@ -132,10 +205,12 @@ GWARF_result read_statement_list(statement *the_statement, var_list *the_var){
     return return_value;
 }
 
+// -----------------operation func
+
 GWARF_result operation_func(statement *the_statement, var_list *the_var){  // read the statement list with case to run by func
     GWARF_result value, left_result, right_result;
-    left_result = traverse((*the_statement).code.operation.left_exp, the_var);
-    right_result = traverse((*the_statement).code.operation.right_exp, the_var);
+    left_result = traverse((*the_statement).code.operation.left_exp, the_var, false);
+    right_result = traverse((*the_statement).code.operation.right_exp, the_var, false);
     switch (the_statement->code.operation.type)  // 获取运算类型
     {
         case ADD_func:
@@ -150,6 +225,29 @@ GWARF_result operation_func(statement *the_statement, var_list *the_var){  // re
         case DIV_func:
             value = div_func(left_result, right_result, the_var);
             break;
+        case ASSIGMENT_func:{  // because the var char, we should ues a {} to make a block[name space] for the tmp var;
+            char *left = (the_statement->code.operation.left_exp)->code.base_var.var_name;  // get var name but not value
+            value = assigment_func(left, right_result, the_var);
+            break;
+        }
+        case EQUAL_func:
+            value = equal_func(left_result, right_result, the_var, 0);
+            break;
+        case MORE_func:
+            value = equal_func(left_result, right_result, the_var, 1);
+            break;
+        case LESS_func:
+            value = equal_func(left_result, right_result, the_var, 2);
+            break;
+        case MOREEQ_func:
+            value = equal_func(left_result, right_result, the_var, 3);
+            break;
+        case LESSEQ_func:
+            value = equal_func(left_result, right_result, the_var, 4);
+            break;
+        case NOTEQ_func:
+            value = equal_func(left_result, right_result, the_var, 5);
+            break;
         default:
             break;
     }
@@ -159,7 +257,7 @@ GWARF_result operation_func(statement *the_statement, var_list *the_var){  // re
 // ---------  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 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
+    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;  // 数值相加运算
@@ -169,8 +267,8 @@ GWARF_result add_func(GWARF_result left_result, GWARF_result right_result, var_l
 
 // ---------  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
+    GWARF_result return_value;  // the result by call read_statement_list with left and right; value is the result for sub
+    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;  // 数值相减运算
@@ -180,8 +278,8 @@ GWARF_result sub_func(GWARF_result left_result, GWARF_result right_result, var_l
 
 // ---------  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
+    GWARF_result return_value;  // the result by call read_statement_list with left and right; value is the result for mul
+    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;  // 数值相乘运算
@@ -191,8 +289,8 @@ GWARF_result mul_func(GWARF_result left_result, GWARF_result right_result, var_l
 
 // ---------  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
+    GWARF_result return_value;  // the result by call read_statement_list with left and right; value is the result for div
+    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;  // 数值相除运算
@@ -200,7 +298,44 @@ GWARF_result div_func(GWARF_result left_result, GWARF_result right_result, var_l
     return return_value;
 }
 
-GWARF_result traverse(statement *the_statement, var_list *the_var){  // traverse the statement
+// ---------  ASSIGMENT
+GWARF_result assigment_func(char *left, GWARF_result right_result, var_list *the_var){  // the func for assigment and call from read_statement_list
+    add_var(the_var, 0, left, right_result.value);
+    return right_result;
+}
+
+// ---------  EQUAL
+GWARF_result equal_func(GWARF_result left_result, GWARF_result right_result, var_list *the_var, int type){  // the func for equal and call from read_statement_list
+    GWARF_result return_value;
+    double return_bool = 0;
+    return_value.u = return_def;
+    if((left_result.value.type == NUMBER_value) && (right_result.value.type == NUMBER_value)){  // all is NUMBER
+        return_value.value.type = NUMBER_value;
+        if ((left_result.value.value.double_value == right_result.value.value.double_value) && (type == 0)){  // 如果相等
+            return_bool = 1;  // 返回1 否则(默认)为0
+        }
+        if ((left_result.value.value.double_value > right_result.value.value.double_value) && (type == 1)){  // 如果大于
+            return_bool = 1;  // 返回1 否则(默认)为0
+        }
+        if ((left_result.value.value.double_value < right_result.value.value.double_value) && (type == 2)){  // 如果小于
+            return_bool = 1;  // 返回1 否则(默认)为0
+        }
+        if ((left_result.value.value.double_value >= right_result.value.value.double_value) && (type == 3)){  // 如果大于等于
+            return_bool = 1;  // 返回1 否则(默认)为0
+        }
+        if ((left_result.value.value.double_value <= right_result.value.value.double_value) && (type == 4)){  // 如果小于等于
+            return_bool = 1;  // 返回1 否则(默认)为0
+        }
+        if ((left_result.value.value.double_value != right_result.value.value.double_value) && (type == 5)){  // 如果不相等
+            return_bool = 1;  // 返回1 否则(默认)为0
+        }
+        return_value.value.value.double_value = return_bool;  // 数值相加运算
+    }
+    return return_value;
+}
+
+// --------- traverse[iter]
+GWARF_result traverse(statement *the_statement, var_list *the_var, bool new){  // traverse the statement
     statement *tmp = the_statement;
     GWARF_result result;
     while(1){

+ 4 - 0
paser/gwarf_lex.l

@@ -11,8 +11,12 @@
 <INITIAL>"{" {return LP;}
 <INITIAL>"}" {return RP;}
 
+<INITIAL>">=" {return MOREEQ;}
+<INITIAL>"<=" {return LESSEQ;}
+<INITIAL>"!=" {return NOTEQ;}
 <INITIAL>">" {return MORE;}
 <INITIAL>"<" {return LESS;}
+<INITIAL>"==" {return EQUAL;}
 <INITIAL>"=" {return EQ;}
 <INITIAL>"+" {return ADD;}
 <INITIAL>"-" {return SUB;}

+ 121 - 12
paser/gwarf_yacc.y

@@ -3,6 +3,7 @@
     #include"lex.yy.c"
     #include"../gwarf_interpreter/interprete.h"
     extern int yylex (void);
+    statement *the_global_code, *now_code;
 %}
 
 %union{
@@ -13,32 +14,117 @@
 }
 %token <double_value> NUMBER
 %token <string_value> STRING VAR
-%token ADD SUB DIV MUL EQ LESS MORE RB LB RP LP WHILE STOP POW
-%type <statement_value> base_number second_number first_number top_exp
+%token ADD SUB DIV MUL EQ LESS MORE RB LB RP LP WHILE STOP POW EQUAL MOREEQ LESSEQ NOTEQ
+%type <statement_value> base_number base_var_ element second_number first_number top_exp command third_number
+
 %%
+command_block
+    : command_list
+    ;
+
 command_list
     : command
+    {
+        if($1 != NULL){
+            append_statement(now_code, $1);
+        }
+    }
     | command_list command
+    {   
+        if($2 != NULL){
+            append_statement(global_inter->global_code, $2);
+        }
+    }
     ;
 
 command
     : STOP
+    {
+        $$ = NULL;
+    }
     | top_exp STOP
     {
-        append_statement(global_inter->global_code, $1);
+        $$ = $1;
     }
     ;
 
 top_exp
-    : first_number
+    : third_number
     {
         $$ = $1;
     }
+    | base_var_ EQ top_exp
+    {
+        statement *code_tmp =  make_statement();
+        code_tmp->type = operation;
+        code_tmp->code.operation.type = ASSIGMENT_func;
+        code_tmp->code.operation.left_exp = $1;
+        code_tmp->code.operation.right_exp = $3;
+        $$ = code_tmp;
+    }
     ;
 
-first_number
+third_number
     : second_number
-    | first_number ADD second_number
+    | third_number EQUAL second_number
+    {
+        statement *code_tmp =  make_statement();
+        code_tmp->type = operation;
+        code_tmp->code.operation.type = EQUAL_func;
+        code_tmp->code.operation.left_exp = $1;
+        code_tmp->code.operation.right_exp = $3;
+        $$ = code_tmp;
+    }
+    | third_number MORE second_number
+    {
+        statement *code_tmp =  make_statement();
+        code_tmp->type = operation;
+        code_tmp->code.operation.type = MORE_func;
+        code_tmp->code.operation.left_exp = $1;
+        code_tmp->code.operation.right_exp = $3;
+        $$ = code_tmp;
+    }
+    | third_number LESS second_number
+    {
+        statement *code_tmp =  make_statement();
+        code_tmp->type = operation;
+        code_tmp->code.operation.type = LESS_func;
+        code_tmp->code.operation.left_exp = $1;
+        code_tmp->code.operation.right_exp = $3;
+        $$ = code_tmp;
+    }
+    | third_number MOREEQ second_number
+        {
+        statement *code_tmp =  make_statement();
+        code_tmp->type = operation;
+        code_tmp->code.operation.type = MOREEQ_func;
+        code_tmp->code.operation.left_exp = $1;
+        code_tmp->code.operation.right_exp = $3;
+        $$ = code_tmp;
+    }
+    | third_number LESSEQ second_number
+    {
+        statement *code_tmp =  make_statement();
+        code_tmp->type = operation;
+        code_tmp->code.operation.type = LESSEQ_func;
+        code_tmp->code.operation.left_exp = $1;
+        code_tmp->code.operation.right_exp = $3;
+        $$ = code_tmp;
+    }
+    | third_number NOTEQ second_number
+    {
+        statement *code_tmp =  make_statement();
+        code_tmp->type = operation;
+        code_tmp->code.operation.type = NOTEQ_func;
+        code_tmp->code.operation.left_exp = $1;
+        code_tmp->code.operation.right_exp = $3;
+        $$ = code_tmp;
+    }
+    ;
+
+second_number
+    : first_number
+    | second_number ADD first_number
     {
         statement *code_tmp =  make_statement();
         code_tmp->type = operation;
@@ -47,7 +133,7 @@ first_number
         code_tmp->code.operation.right_exp = $3;
         $$ = code_tmp;
     }
-    | first_number SUB second_number
+    | second_number SUB first_number
     {
         statement *code_tmp =  make_statement();
         code_tmp->type = operation;
@@ -58,9 +144,9 @@ first_number
     }
     ;
 
-second_number
-    : base_number
-    | second_number MUL base_number
+first_number
+    : element
+    | first_number MUL element
     {
         statement *code_tmp =  make_statement();
         code_tmp->type = operation;
@@ -69,7 +155,7 @@ second_number
         code_tmp->code.operation.right_exp = $3;
         $$ = code_tmp;
     }
-    | second_number DIV base_number
+    | first_number DIV element
     {
         statement *code_tmp =  make_statement();
         code_tmp->type = operation;
@@ -80,17 +166,38 @@ second_number
     }
     ;
 
+element
+    : base_number
+    | base_var_
+    | LB top_exp RB
+    {
+        $$ = $2;
+    }
+    ;
+
 base_number
     : NUMBER
     {
         statement *code_tmp =  make_statement();
         code_tmp->type = base_value;
-        code_tmp->code.base_value.value.type = NUMBER;
+        code_tmp->code.base_value.value.type = NUMBER_value;
         code_tmp->code.base_value.value.value.double_value = $1;
         $$ = code_tmp;
     }
     ;
 
+base_var_
+    : VAR
+    {
+        statement *code_tmp =  make_statement();
+        code_tmp->code.base_var.var_name = malloc(sizeof($1));
+        char *name_tmp = code_tmp->code.base_var.var_name;
+        code_tmp->type = base_var;
+        strcpy(name_tmp, $1);
+        $$ = code_tmp;
+    }
+    ;
+
 %%
 int yyerror(char const *str)
 {
@@ -100,6 +207,8 @@ int yyerror(char const *str)
 
 int parser(void)
 {
+    the_global_code = global_inter->global_code;
+    now_code = the_global_code;
     yyin = fopen("/home/songzihuan/test.gwf","r");
     yyparse();
     return 0;

+ 128 - 102
paser/lex.yy.c

@@ -351,8 +351,8 @@ static void yynoreturn yy_fatal_error ( const char* msg  );
 	(yy_hold_char) = *yy_cp; \
 	*yy_cp = '\0'; \
 	(yy_c_buf_p) = yy_cp;
-#define YY_NUM_RULES 29
-#define YY_END_OF_BUFFER 30
+#define YY_NUM_RULES 33
+#define YY_END_OF_BUFFER 34
 /* This struct is not used in this scanner,
    but its presence is necessary. */
 struct yy_trans_info
@@ -360,13 +360,13 @@ struct yy_trans_info
 	flex_int32_t yy_verify;
 	flex_int32_t yy_nxt;
 	};
-static const flex_int16_t yy_accept[46] =
+static const flex_int16_t yy_accept[51] =
     {   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
+        0,    0,    0,    0,    0,    0,   34,   25,   24,   23,
+       25,   20,   18,   19,    2,    3,   15,   13,   14,   16,
+       21,   21,   10,   12,    9,   22,   17,   22,    4,    5,
+       28,   26,   27,   32,   31,   30,   29,    8,    0,   21,
+        7,   11,    6,   22,   22,   21,   22,   22,    1,    0
     } ;
 
 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,    1,
         1,    1,    1,    1,    1,    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,    3,    4,    5,    6,    1,    1,    1,    7,    8,
+        9,   10,   11,    1,   12,   13,   14,   15,   16,   16,
+       16,   16,   16,   16,   16,   16,   16,    1,    1,   17,
+       18,   19,    1,    1,   20,   20,   20,   20,   20,   20,
+       20,   20,   20,   20,   20,   20,   20,   20,   20,   20,
+       20,   20,   20,   20,   20,   20,   20,   20,   20,   20,
+        1,    1,    1,   21,   20,    1,   20,   20,   20,   20,
+
+       22,   20,   20,   23,   24,   20,   20,   25,   20,   20,
+       20,   20,   20,   20,   20,   20,   20,   20,   26,   20,
+       20,   20,   27,    1,   28,    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,61 @@ static const YY_CHAR yy_ec[256] =
         1,    1,    1,    1,    1
     } ;
 
-static const YY_CHAR yy_meta[28] =
+static const YY_CHAR yy_meta[29] =
     {   0,
         1,    1,    1,    1,    1,    1,    1,    1,    1,    1,
-        1,    1,    1,    2,    2,    1,    1,    1,    2,    1,
-        2,    2,    2,    2,    2,    1,    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[49] =
+static const flex_int16_t yy_base[54] =
     {   0,
-        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
+        0,    0,   27,   28,   30,   34,   62,   63,   63,   63,
+       43,   63,   63,   63,   63,   63,   63,   63,   63,   63,
+       63,   27,   42,   41,   40,    0,   63,   34,   63,   63,
+       63,   63,   63,   63,   63,   63,   63,   63,   29,   33,
+       63,   63,   63,    0,   32,   35,   22,   16,    0,   63,
+       51,   53,   29
     } ;
 
-static const flex_int16_t yy_def[49] =
+static const flex_int16_t yy_def[54] =
     {   0,
-       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
+       50,    1,   51,   51,   52,   52,   50,   50,   50,   50,
+       50,   50,   50,   50,   50,   50,   50,   50,   50,   50,
+       50,   50,   50,   50,   50,   53,   50,   53,   50,   50,
+       50,   50,   50,   50,   50,   50,   50,   50,   50,   50,
+       50,   50,   50,   53,   53,   50,   53,   53,   53,    0,
+       50,   50,   50
     } ;
 
-static const flex_int16_t yy_nxt[86] =
+static const flex_int16_t yy_nxt[92] =
     {   0,
         8,    9,   10,   11,   12,   13,   14,   15,   16,   17,
-       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
+       18,   19,    8,   20,   21,   22,   23,   24,   25,   26,
+       27,   26,   26,   26,   26,   28,   29,   30,   32,   32,
+       44,   35,   33,   33,   36,   35,   37,   49,   36,   39,
+       37,   40,   40,   46,   46,   39,   48,   40,   40,   46,
+       46,   31,   31,   34,   34,   47,   45,   43,   42,   41,
+       38,   50,    7,   50,   50,   50,   50,   50,   50,   50,
+       50,   50,   50,   50,   50,   50,   50,   50,   50,   50,
+       50,   50,   50,   50,   50,   50,   50,   50,   50,   50,
+       50
+
     } ;
 
-static const flex_int16_t yy_chk[86] =
+static const flex_int16_t yy_chk[92] =
     {   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,    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
+        1,    1,    1,    1,    1,    1,    1,    1,    3,    4,
+       53,    5,    3,    4,    5,    6,    5,   48,    6,   22,
+        6,   22,   22,   39,   39,   40,   47,   40,   40,   46,
+       46,   51,   51,   52,   52,   45,   28,   25,   24,   23,
+       11,    7,   50,   50,   50,   50,   50,   50,   50,   50,
+       50,   50,   50,   50,   50,   50,   50,   50,   50,   50,
+       50,   50,   50,   50,   50,   50,   50,   50,   50,   50,
+       50
+
     } ;
 
 static yy_state_type yy_last_accepting_state;
@@ -470,9 +476,9 @@ char *yytext;
 #line 2 "gwarf_lex.l"
     #include<stdio.h>
     #include"y.tab.h"
-#line 473 "lex.yy.c"
+#line 479 "lex.yy.c"
 
-#line 475 "lex.yy.c"
+#line 481 "lex.yy.c"
 
 #define INITIAL 0
 #define COMMENT 1
@@ -693,7 +699,7 @@ YY_DECL
 	{
 #line 6 "gwarf_lex.l"
 
-#line 696 "lex.yy.c"
+#line 702 "lex.yy.c"
 
 	while ( /*CONSTCOND*/1 )		/* loops until end-of-file is reached */
 		{
@@ -720,13 +726,13 @@ yy_match:
 			while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state )
 				{
 				yy_current_state = (int) yy_def[yy_current_state];
-				if ( yy_current_state >= 46 )
+				if ( yy_current_state >= 51 )
 					yy_c = yy_meta[yy_c];
 				}
 			yy_current_state = yy_nxt[yy_base[yy_current_state] + yy_c];
 			++yy_cp;
 			}
-		while ( yy_base[yy_current_state] != 58 );
+		while ( yy_base[yy_current_state] != 63 );
 
 yy_find_action:
 		yy_act = yy_accept[yy_current_state];
@@ -778,139 +784,159 @@ YY_RULE_SETUP
 case 6:
 YY_RULE_SETUP
 #line 14 "gwarf_lex.l"
-{return MORE;}
+{return MOREEQ;}
 	YY_BREAK
 case 7:
 YY_RULE_SETUP
 #line 15 "gwarf_lex.l"
-{return LESS;}
+{return LESSEQ;}
 	YY_BREAK
 case 8:
 YY_RULE_SETUP
 #line 16 "gwarf_lex.l"
-{return EQ;}
+{return NOTEQ;}
 	YY_BREAK
 case 9:
 YY_RULE_SETUP
 #line 17 "gwarf_lex.l"
-{return ADD;}
+{return MORE;}
 	YY_BREAK
 case 10:
 YY_RULE_SETUP
 #line 18 "gwarf_lex.l"
-{return SUB;}
+{return LESS;}
 	YY_BREAK
 case 11:
 YY_RULE_SETUP
 #line 19 "gwarf_lex.l"
-{return MUL;}
+{return EQUAL;}
 	YY_BREAK
 case 12:
 YY_RULE_SETUP
 #line 20 "gwarf_lex.l"
-{return DIV;}
+{return EQ;}
 	YY_BREAK
 case 13:
 YY_RULE_SETUP
 #line 21 "gwarf_lex.l"
-{return POW;}
+{return ADD;}
 	YY_BREAK
 case 14:
 YY_RULE_SETUP
-#line 23 "gwarf_lex.l"
-{BEGIN COMMENT;}
+#line 22 "gwarf_lex.l"
+{return SUB;}
 	YY_BREAK
 case 15:
 YY_RULE_SETUP
-#line 24 "gwarf_lex.l"
-{BEGIN STRING_TEXT;}
+#line 23 "gwarf_lex.l"
+{return MUL;}
 	YY_BREAK
 case 16:
 YY_RULE_SETUP
+#line 24 "gwarf_lex.l"
+{return DIV;}
+	YY_BREAK
+case 17:
+YY_RULE_SETUP
 #line 25 "gwarf_lex.l"
+{return POW;}
+	YY_BREAK
+case 18:
+YY_RULE_SETUP
+#line 27 "gwarf_lex.l"
+{BEGIN COMMENT;}
+	YY_BREAK
+case 19:
+YY_RULE_SETUP
+#line 28 "gwarf_lex.l"
 {BEGIN STRING_TEXT;}
 	YY_BREAK
-case 17:
+case 20:
+YY_RULE_SETUP
+#line 29 "gwarf_lex.l"
+{BEGIN STRING_TEXT;}
+	YY_BREAK
+case 21:
 YY_RULE_SETUP
-#line 26 "gwarf_lex.l"
+#line 30 "gwarf_lex.l"
 {
     yylval.double_value = atof(yytext);
     return NUMBER;
     }
 	YY_BREAK
-case 18:
+case 22:
 YY_RULE_SETUP
-#line 30 "gwarf_lex.l"
+#line 34 "gwarf_lex.l"
 {
     yylval.string_value = yytext;
     return VAR;
     }
 	YY_BREAK
-case 19:
+case 23:
 YY_RULE_SETUP
-#line 35 "gwarf_lex.l"
+#line 39 "gwarf_lex.l"
 ;
 	YY_BREAK
-case 20:
-/* rule 20 can match eol */
+case 24:
+/* rule 24 can match eol */
 YY_RULE_SETUP
-#line 36 "gwarf_lex.l"
+#line 40 "gwarf_lex.l"
 {return STOP;}
 	YY_BREAK
-case 21:
+case 25:
 YY_RULE_SETUP
-#line 37 "gwarf_lex.l"
+#line 41 "gwarf_lex.l"
 {printf("text = [%s];\n", yytext);}
 	YY_BREAK
-case 22:
-/* rule 22 can match eol */
+case 26:
+/* rule 26 can match eol */
 YY_RULE_SETUP
-#line 39 "gwarf_lex.l"
+#line 43 "gwarf_lex.l"
 {BEGIN INITIAL;}
 	YY_BREAK
-case 23:
+case 27:
 YY_RULE_SETUP
-#line 40 "gwarf_lex.l"
+#line 44 "gwarf_lex.l"
 {BEGIN INITIAL;}
 	YY_BREAK
-case 24:
+case 28:
 YY_RULE_SETUP
-#line 41 "gwarf_lex.l"
+#line 45 "gwarf_lex.l"
 ;
 	YY_BREAK
-case 25:
+case 29:
 YY_RULE_SETUP
-#line 43 "gwarf_lex.l"
+#line 47 "gwarf_lex.l"
 {BEGIN INITIAL;}
 	YY_BREAK
-case 26:
+case 30:
 YY_RULE_SETUP
-#line 44 "gwarf_lex.l"
+#line 48 "gwarf_lex.l"
 {BEGIN INITIAL;}
 	YY_BREAK
-case 27:
-/* rule 27 can match eol */
+case 31:
+/* rule 31 can match eol */
 YY_RULE_SETUP
-#line 45 "gwarf_lex.l"
+#line 49 "gwarf_lex.l"
 {
     yylval.string_value = yytext;
     return STRING;
     }
 	YY_BREAK
-case 28:
+case 32:
 YY_RULE_SETUP
-#line 49 "gwarf_lex.l"
+#line 53 "gwarf_lex.l"
 {
     yylval.string_value = yytext;
     return STRING;
     }
 	YY_BREAK
-case 29:
+case 33:
 YY_RULE_SETUP
-#line 53 "gwarf_lex.l"
+#line 57 "gwarf_lex.l"
 ECHO;
 	YY_BREAK
-#line 913 "lex.yy.c"
+#line 939 "lex.yy.c"
 case YY_STATE_EOF(INITIAL):
 case YY_STATE_EOF(COMMENT):
 case YY_STATE_EOF(STRING_TEXT):
@@ -1209,7 +1235,7 @@ static int yy_get_next_buffer (void)
 		while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state )
 			{
 			yy_current_state = (int) yy_def[yy_current_state];
-			if ( yy_current_state >= 46 )
+			if ( yy_current_state >= 51 )
 				yy_c = yy_meta[yy_c];
 			}
 		yy_current_state = yy_nxt[yy_base[yy_current_state] + yy_c];
@@ -1237,11 +1263,11 @@ static int yy_get_next_buffer (void)
 	while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state )
 		{
 		yy_current_state = (int) yy_def[yy_current_state];
-		if ( yy_current_state >= 46 )
+		if ( yy_current_state >= 51 )
 			yy_c = yy_meta[yy_c];
 		}
 	yy_current_state = yy_nxt[yy_base[yy_current_state] + yy_c];
-	yy_is_jam = (yy_current_state == 45);
+	yy_is_jam = (yy_current_state == 50);
 
 		return yy_is_jam ? 0 : yy_current_state;
 }
@@ -1917,7 +1943,7 @@ void yyfree (void * ptr )
 
 #define YYTABLES_NAME "yytables"
 
-#line 53 "gwarf_lex.l"
+#line 57 "gwarf_lex.l"
 
 int yywrap(void) {
     return 1;

+ 230 - 59
paser/y.tab.c

@@ -1,4 +1,4 @@
-/* A Bison parser, made by GNU Bison 3.5.3.  */
+/* A Bison parser, made by GNU Bison 3.5.4.  */
 
 /* Bison implementation for Yacc-like parsers in C
 
@@ -48,7 +48,7 @@
 #define YYBISON 1
 
 /* Bison version.  */
-#define YYBISON_VERSION "3.5.3"
+#define YYBISON_VERSION "3.5.4"
 
 /* Skeleton name.  */
 #define YYSKELETON_NAME "yacc.c"
@@ -72,8 +72,9 @@
     #include"lex.yy.c"
     #include"../gwarf_interpreter/interprete.h"
     extern int yylex (void);
+    statement *the_global_code, *now_code;
 
-#line 77 "y.tab.c"
+#line 78 "y.tab.c"
 
 # ifndef YY_CAST
 #  ifdef __cplusplus
@@ -137,7 +138,11 @@ extern int yydebug;
     LP = 271,
     WHILE = 272,
     STOP = 273,
-    POW = 274
+    POW = 274,
+    EQUAL = 275,
+    MOREEQ = 276,
+    LESSEQ = 277,
+    NOTEQ = 278
   };
 #endif
 /* Tokens.  */
@@ -158,19 +163,23 @@ extern int yydebug;
 #define WHILE 272
 #define STOP 273
 #define POW 274
+#define EQUAL 275
+#define MOREEQ 276
+#define LESSEQ 277
+#define NOTEQ 278
 
 /* Value type.  */
 #if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED
 union YYSTYPE
 {
-#line 8 "gwarf_yacc.y"
+#line 9 "gwarf_yacc.y"
 
     int int_value;
     double double_value;
     char *string_value;
     void *statement_value;
 
-#line 174 "y.tab.c"
+#line 183 "y.tab.c"
 
 };
 typedef union YYSTYPE YYSTYPE;
@@ -487,21 +496,21 @@ union yyalloc
 #endif /* !YYCOPY_NEEDED */
 
 /* YYFINAL -- State number of the termination state.  */
-#define YYFINAL  9
+#define YYFINAL  16
 /* YYLAST -- Last index in YYTABLE.  */
-#define YYLAST   18
+#define YYLAST   37
 
 /* YYNTOKENS -- Number of terminals.  */
-#define YYNTOKENS  20
+#define YYNTOKENS  24
 /* YYNNTS -- Number of nonterminals.  */
-#define YYNNTS  7
+#define YYNNTS  11
 /* YYNRULES -- Number of rules.  */
-#define YYNRULES  13
+#define YYNRULES  26
 /* YYNSTATES -- Number of states.  */
-#define YYNSTATES  20
+#define YYNSTATES  43
 
 #define YYUNDEFTOK  2
-#define YYMAXUTOK   274
+#define YYMAXUTOK   278
 
 
 /* YYTRANSLATE(TOKEN-NUM) -- Symbol number corresponding to TOKEN-NUM
@@ -540,15 +549,16 @@ static const yytype_int8 yytranslate[] =
        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
        2,     2,     2,     2,     2,     2,     1,     2,     3,     4,
        5,     6,     7,     8,     9,    10,    11,    12,    13,    14,
-      15,    16,    17,    18,    19
+      15,    16,    17,    18,    19,    20,    21,    22,    23
 };
 
 #if YYDEBUG
   /* YYRLINE[YYN] -- Source line where rule number YYN was defined.  */
-static const yytype_int8 yyrline[] =
+static const yytype_uint8 yyrline[] =
 {
-       0,    20,    20,    21,    25,    26,    33,    40,    41,    50,
-      62,    63,    72,    84
+       0,    22,    22,    26,    32,    41,    45,    52,    56,    68,
+      69,    78,    87,    96,   105,   114,   126,   127,   136,   148,
+     149,   158,   170,   171,   172,   179,   190
 };
 #endif
 
@@ -559,8 +569,9 @@ static const char *const yytname[] =
 {
   "$end", "error", "$undefined", "NUMBER", "STRING", "VAR", "ADD", "SUB",
   "DIV", "MUL", "EQ", "LESS", "MORE", "RB", "LB", "RP", "LP", "WHILE",
-  "STOP", "POW", "$accept", "command_list", "command", "top_exp",
-  "first_number", "second_number", "base_number", YY_NULLPTR
+  "STOP", "POW", "EQUAL", "MOREEQ", "LESSEQ", "NOTEQ", "$accept",
+  "command_block", "command_list", "command", "top_exp", "third_number",
+  "second_number", "first_number", "element", "base_number", "base_var_", YY_NULLPTR
 };
 #endif
 
@@ -570,11 +581,12 @@ static const char *const yytname[] =
 static const yytype_int16 yytoknum[] =
 {
        0,   256,   257,   258,   259,   260,   261,   262,   263,   264,
-     265,   266,   267,   268,   269,   270,   271,   272,   273,   274
+     265,   266,   267,   268,   269,   270,   271,   272,   273,   274,
+     275,   276,   277,   278
 };
 # endif
 
-#define YYPACT_NINF (-17)
+#define YYPACT_NINF (-18)
 
 #define yypact_value_is_default(Yyn) \
   ((Yyn) == YYPACT_NINF)
@@ -588,8 +600,11 @@ static const yytype_int16 yytoknum[] =
      STATE-NUM.  */
 static const yytype_int8 yypact[] =
 {
-      -2,   -17,   -17,     0,   -17,   -16,    -1,     1,   -17,   -17,
-     -17,   -17,    10,    10,    10,    10,     1,     1,   -17,   -17
+      -1,   -18,   -18,     2,   -18,    12,    -1,   -18,    18,     3,
+       4,    10,   -18,   -18,    27,     9,   -18,   -18,   -18,     2,
+       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
+     -18,     4,   -18,     4,     4,     4,     4,     4,    10,    10,
+     -18,   -18,   -18
 };
 
   /* YYDEFACT[STATE-NUM] -- Default reduction number in state STATE-NUM.
@@ -597,20 +612,25 @@ static const yytype_int8 yypact[] =
      means the default is an error.  */
 static const yytype_int8 yydefact[] =
 {
-       0,    13,     4,     0,     2,     0,     6,     7,    10,     1,
-       3,     5,     0,     0,     0,     0,     8,     9,    12,    11
+       0,    25,    26,     0,     5,     0,     2,     3,     0,     7,
+       9,    16,    19,    22,    23,     0,     1,     4,     6,     0,
+       0,     0,     0,     0,     0,     0,     0,     0,     0,     0,
+      24,    12,    23,    11,    10,    13,    14,    15,    17,    18,
+      21,    20,     8
 };
 
   /* YYPGOTO[NTERM-NUM].  */
 static const yytype_int8 yypgoto[] =
 {
-     -17,   -17,    11,   -17,   -17,    -5,    -3
+     -18,   -18,   -18,    22,    -2,   -18,    11,   -17,    -7,   -18,
+       0
 };
 
   /* YYDEFGOTO[NTERM-NUM].  */
 static const yytype_int8 yydefgoto[] =
 {
-      -1,     3,     4,     5,     6,     7,     8
+      -1,     5,     6,     7,     8,     9,    10,    11,    12,    13,
+      32
 };
 
   /* YYTABLE[YYPACT[STATE-NUM]] -- What to do in state STATE-NUM.  If
@@ -618,36 +638,45 @@ static const yytype_int8 yydefgoto[] =
      number is the opposite.  If YYTABLE_NINF, syntax error.  */
 static const yytype_int8 yytable[] =
 {
-       9,     1,    11,     1,     0,    12,    13,    16,    17,    14,
-      15,    18,    19,     1,    10,     0,     2,     0,     2
+      14,    15,     1,    14,     2,     1,    14,     2,    38,    39,
+      25,    26,    16,     3,    19,    20,     3,     4,    27,    28,
+      40,    41,    30,    21,    22,    23,    24,    42,    17,    14,
+      31,    33,    34,    35,    36,    37,    18,    29
 };
 
 static const yytype_int8 yycheck[] =
 {
-       0,     3,    18,     3,    -1,     6,     7,    12,    13,     8,
-       9,    14,    15,     3,     3,    -1,    18,    -1,    18
+       0,     3,     3,     3,     5,     3,     6,     5,    25,    26,
+       6,     7,     0,    14,    11,    12,    14,    18,     8,     9,
+      27,    28,    13,    20,    21,    22,    23,    29,     6,    29,
+      19,    20,    21,    22,    23,    24,    18,    10
 };
 
   /* YYSTOS[STATE-NUM] -- The (internal number of the) accessing
      symbol of state STATE-NUM.  */
 static const yytype_int8 yystos[] =
 {
-       0,     3,    18,    21,    22,    23,    24,    25,    26,     0,
-      22,    18,     6,     7,     8,     9,    25,    25,    26,    26
+       0,     3,     5,    14,    18,    25,    26,    27,    28,    29,
+      30,    31,    32,    33,    34,    28,     0,    27,    18,    11,
+      12,    20,    21,    22,    23,     6,     7,     8,     9,    10,
+      13,    30,    34,    30,    30,    30,    30,    30,    31,    31,
+      32,    32,    28
 };
 
   /* YYR1[YYN] -- Symbol number of symbol that rule YYN derives.  */
 static const yytype_int8 yyr1[] =
 {
-       0,    20,    21,    21,    22,    22,    23,    24,    24,    24,
-      25,    25,    25,    26
+       0,    24,    25,    26,    26,    27,    27,    28,    28,    29,
+      29,    29,    29,    29,    29,    29,    30,    30,    30,    31,
+      31,    31,    32,    32,    32,    33,    34
 };
 
   /* YYR2[YYN] -- Number of symbols on the right hand side of rule YYN.  */
 static const yytype_int8 yyr2[] =
 {
-       0,     2,     1,     2,     1,     2,     1,     1,     3,     3,
-       1,     3,     3,     1
+       0,     2,     1,     1,     2,     1,     2,     1,     3,     1,
+       3,     3,     3,     3,     3,     3,     1,     3,     3,     1,
+       3,     3,     1,     1,     3,     1,     1
 };
 
 
@@ -1342,24 +1371,143 @@ yyreduce:
   YY_REDUCE_PRINT (yyn);
   switch (yyn)
     {
-  case 5:
+  case 3:
 #line 27 "gwarf_yacc.y"
     {
-        append_statement(global_inter->global_code, (yyvsp[-1].statement_value));
+        if((yyvsp[0].statement_value) != NULL){
+            append_statement(now_code, (yyvsp[0].statement_value));
+        }
+    }
+#line 1382 "y.tab.c"
+    break;
+
+  case 4:
+#line 33 "gwarf_yacc.y"
+    {   
+        if((yyvsp[0].statement_value) != NULL){
+            append_statement(global_inter->global_code, (yyvsp[0].statement_value));
+        }
+    }
+#line 1392 "y.tab.c"
+    break;
+
+  case 5:
+#line 42 "gwarf_yacc.y"
+    {
+        (yyval.statement_value) = NULL;
     }
-#line 1351 "y.tab.c"
+#line 1400 "y.tab.c"
     break;
 
   case 6:
-#line 34 "gwarf_yacc.y"
+#line 46 "gwarf_yacc.y"
+    {
+        (yyval.statement_value) = (yyvsp[-1].statement_value);
+    }
+#line 1408 "y.tab.c"
+    break;
+
+  case 7:
+#line 53 "gwarf_yacc.y"
     {
         (yyval.statement_value) = (yyvsp[0].statement_value);
     }
-#line 1359 "y.tab.c"
+#line 1416 "y.tab.c"
     break;
 
   case 8:
-#line 42 "gwarf_yacc.y"
+#line 57 "gwarf_yacc.y"
+    {
+        statement *code_tmp =  make_statement();
+        code_tmp->type = operation;
+        code_tmp->code.operation.type = ASSIGMENT_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 1429 "y.tab.c"
+    break;
+
+  case 10:
+#line 70 "gwarf_yacc.y"
+    {
+        statement *code_tmp =  make_statement();
+        code_tmp->type = operation;
+        code_tmp->code.operation.type = EQUAL_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 1442 "y.tab.c"
+    break;
+
+  case 11:
+#line 79 "gwarf_yacc.y"
+    {
+        statement *code_tmp =  make_statement();
+        code_tmp->type = operation;
+        code_tmp->code.operation.type = MORE_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 1455 "y.tab.c"
+    break;
+
+  case 12:
+#line 88 "gwarf_yacc.y"
+    {
+        statement *code_tmp =  make_statement();
+        code_tmp->type = operation;
+        code_tmp->code.operation.type = LESS_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 1468 "y.tab.c"
+    break;
+
+  case 13:
+#line 97 "gwarf_yacc.y"
+        {
+        statement *code_tmp =  make_statement();
+        code_tmp->type = operation;
+        code_tmp->code.operation.type = MOREEQ_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 1481 "y.tab.c"
+    break;
+
+  case 14:
+#line 106 "gwarf_yacc.y"
+    {
+        statement *code_tmp =  make_statement();
+        code_tmp->type = operation;
+        code_tmp->code.operation.type = LESSEQ_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 1494 "y.tab.c"
+    break;
+
+  case 15:
+#line 115 "gwarf_yacc.y"
+    {
+        statement *code_tmp =  make_statement();
+        code_tmp->type = operation;
+        code_tmp->code.operation.type = NOTEQ_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 1507 "y.tab.c"
+    break;
+
+  case 17:
+#line 128 "gwarf_yacc.y"
     {
         statement *code_tmp =  make_statement();
         code_tmp->type = operation;
@@ -1368,11 +1516,11 @@ yyreduce:
         code_tmp->code.operation.right_exp = (yyvsp[0].statement_value);
         (yyval.statement_value) = code_tmp;
     }
-#line 1372 "y.tab.c"
+#line 1520 "y.tab.c"
     break;
 
-  case 9:
-#line 51 "gwarf_yacc.y"
+  case 18:
+#line 137 "gwarf_yacc.y"
     {
         statement *code_tmp =  make_statement();
         code_tmp->type = operation;
@@ -1381,11 +1529,11 @@ yyreduce:
         code_tmp->code.operation.right_exp = (yyvsp[0].statement_value);
         (yyval.statement_value) = code_tmp;
     }
-#line 1385 "y.tab.c"
+#line 1533 "y.tab.c"
     break;
 
-  case 11:
-#line 64 "gwarf_yacc.y"
+  case 20:
+#line 150 "gwarf_yacc.y"
     {
         statement *code_tmp =  make_statement();
         code_tmp->type = operation;
@@ -1394,11 +1542,11 @@ yyreduce:
         code_tmp->code.operation.right_exp = (yyvsp[0].statement_value);
         (yyval.statement_value) = code_tmp;
     }
-#line 1398 "y.tab.c"
+#line 1546 "y.tab.c"
     break;
 
-  case 12:
-#line 73 "gwarf_yacc.y"
+  case 21:
+#line 159 "gwarf_yacc.y"
     {
         statement *code_tmp =  make_statement();
         code_tmp->type = operation;
@@ -1407,23 +1555,44 @@ yyreduce:
         code_tmp->code.operation.right_exp = (yyvsp[0].statement_value);
         (yyval.statement_value) = code_tmp;
     }
-#line 1411 "y.tab.c"
+#line 1559 "y.tab.c"
     break;
 
-  case 13:
-#line 85 "gwarf_yacc.y"
+  case 24:
+#line 173 "gwarf_yacc.y"
+    {
+        (yyval.statement_value) = (yyvsp[-1].statement_value);
+    }
+#line 1567 "y.tab.c"
+    break;
+
+  case 25:
+#line 180 "gwarf_yacc.y"
     {
         statement *code_tmp =  make_statement();
         code_tmp->type = base_value;
-        code_tmp->code.base_value.value.type = NUMBER;
+        code_tmp->code.base_value.value.type = NUMBER_value;
         code_tmp->code.base_value.value.value.double_value = (yyvsp[0].double_value);
         (yyval.statement_value) = code_tmp;
     }
-#line 1423 "y.tab.c"
+#line 1579 "y.tab.c"
+    break;
+
+  case 26:
+#line 191 "gwarf_yacc.y"
+    {
+        statement *code_tmp =  make_statement();
+        code_tmp->code.base_var.var_name = malloc(sizeof((yyvsp[0].string_value)));
+        char *name_tmp = code_tmp->code.base_var.var_name;
+        code_tmp->type = base_var;
+        strcpy(name_tmp, (yyvsp[0].string_value));
+        (yyval.statement_value) = code_tmp;
+    }
+#line 1592 "y.tab.c"
     break;
 
 
-#line 1427 "y.tab.c"
+#line 1596 "y.tab.c"
 
       default: break;
     }
@@ -1655,7 +1824,7 @@ yyreturn:
 #endif
   return yyresult;
 }
-#line 94 "gwarf_yacc.y"
+#line 201 "gwarf_yacc.y"
 
 int yyerror(char const *str)
 {
@@ -1665,6 +1834,8 @@ int yyerror(char const *str)
 
 int parser(void)
 {
+    the_global_code = global_inter->global_code;
+    now_code = the_global_code;
     yyin = fopen("/home/songzihuan/test.gwf","r");
     yyparse();
     return 0;

+ 12 - 4
paser/y.tab.h

@@ -1,4 +1,4 @@
-/* A Bison parser, made by GNU Bison 3.5.3.  */
+/* A Bison parser, made by GNU Bison 3.5.4.  */
 
 /* Bison interface for Yacc-like parsers in C
 
@@ -65,7 +65,11 @@ extern int yydebug;
     LP = 271,
     WHILE = 272,
     STOP = 273,
-    POW = 274
+    POW = 274,
+    EQUAL = 275,
+    MOREEQ = 276,
+    LESSEQ = 277,
+    NOTEQ = 278
   };
 #endif
 /* Tokens.  */
@@ -86,19 +90,23 @@ extern int yydebug;
 #define WHILE 272
 #define STOP 273
 #define POW 274
+#define EQUAL 275
+#define MOREEQ 276
+#define LESSEQ 277
+#define NOTEQ 278
 
 /* Value type.  */
 #if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED
 union YYSTYPE
 {
-#line 8 "gwarf_yacc.y"
+#line 9 "gwarf_yacc.y"
 
     int int_value;
     double double_value;
     char *string_value;
     void *statement_value;
 
-#line 102 "y.tab.h"
+#line 110 "y.tab.h"
 
 };
 typedef union YYSTYPE YYSTYPE;