瀏覽代碼

实现了for循环、global和nonlocal语句

SongZihuan 5 年之前
父節點
當前提交
5e8d75603f
共有 9 個文件被更改,包括 948 次插入400 次删除
  1. 二進制
      gwarf
  2. 1 1
      gwarf.c
  3. 19 0
      gwarf_interpreter/interprete.h
  4. 140 17
      gwarf_interpreter/interpreter.c
  5. 5 2
      paser/gwarf_lex.l
  6. 140 2
      paser/gwarf_yacc.y
  7. 209 179
      paser/lex.yy.c
  8. 424 197
      paser/y.tab.c
  9. 10 2
      paser/y.tab.h

二進制
gwarf


+ 1 - 1
gwarf.c

@@ -9,7 +9,7 @@ int main(){
 
     parser("/home/songzihuan/test.gwf");
     printf("----start run----\n");
-    traverse(global_inter->global_code, the_var,false);
+    traverse_global(global_inter->global_code, the_var);
     printf("code end...\n");
     return 0;
 }

+ 19 - 0
gwarf_interpreter/interprete.h

@@ -36,6 +36,7 @@ typedef struct statement{
         base_var,  // return var address
         base_value,  // return an number or number
         while_cycle,  // while
+        for_cycle,
         if_branch,  // if
         break_cycle,  // break
         broken,  // break_cycle and other {}
@@ -46,6 +47,8 @@ typedef struct statement{
         rego,
         rewent,
         set_default,
+        set_global,
+        set_nonlocal,
     } type;  // the statement type
 
     union
@@ -73,6 +76,13 @@ typedef struct statement{
             struct statement *done;  // while to do
         } while_cycle;
 
+        struct{
+            struct statement *first;  // the first to do 
+            struct statement *condition;  // when to while 
+            struct statement *after;  // what to do after the done
+            struct statement *done;  // while to do
+        } for_cycle;
+        
         struct{
             struct if_list *done;  // if_list
         } if_branch;
@@ -121,6 +131,14 @@ typedef struct statement{
             struct statement *times;  // 层数
         } set_default;
 
+        struct{
+            char *name;
+        } set_global;
+
+        struct{
+            char *name;
+        } set_nonlocal;
+
     } code;
     struct statement *next;
 } statement;
@@ -213,6 +231,7 @@ if_list *append_elif(if_list *, if_list *);
 
 //------- run func
 GWARF_result traverse(statement *, var_list *, bool);
+GWARF_result traverse_global(statement *, var_list *);
 
 //------- inter func
 inter *get_inter();

+ 140 - 17
gwarf_interpreter/interpreter.c

@@ -13,6 +13,8 @@ GWARF_result div_func(GWARF_result, GWARF_result, var_list *);
 GWARF_result assigment_func(char *, GWARF_result, var_list *, int);
 GWARF_result equal_func(GWARF_result, GWARF_result, var_list *, int);
 GWARF_result if_func(if_list *, var_list *);
+GWARF_result for_func(statement *, var_list *);
+int get_var_list_len(var_list *);
 
 // ---- var func
 
@@ -197,13 +199,25 @@ var_list *free_var_list(var_list *var_list_base){  // free one var_list[FILO]
     return tmp;
 }
 
+int get_var_list_len(var_list *var_base){
+    var_list *start = var_base;
+    int tmp = 0;
+    while(1){
+        if(start->next == NULL){
+            break;
+        }
+        start = start->next;
+        tmp += 1;
+    }
+    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;
     from += get_default(name, var_base->default_list);
     printf("find from = %d\n", from);
     for(int i = 0;i < from;i+= 1){
-        printf("the start = %d\n", start);
         if(start->next == NULL){
             break;
         }
@@ -329,16 +343,15 @@ GWARF_result read_statement_list(statement *the_statement, var_list *the_var){
         case while_cycle:
             puts("----while code----");
             return_value = while_func(the_statement, the_var);
-            if((return_value.u == cycle_break) || (return_value.u == code_broken)){
-                printf("cycle_break(broken) %f\n", return_value.value.value.double_value);
-                return_value.value.value.double_value -= 1;
-                if(return_value.value.value.double_value < 0){
-                    return_value.u = statement_end;  // 正常设置[正常语句结束]
-                }
-            }
             printf("while operation value = %f\n", return_value.value.value.double_value);
             puts("----stop while code----");
             break;
+        case for_cycle:
+            puts("----for code----");
+            return_value = for_func(the_statement, the_var);
+            printf("for operation value = %f\n", return_value.value.value.double_value);
+            puts("----for while code----");
+            break;
         case if_branch:
             puts("----if code----");
             return_value = if_func(the_statement->code.if_branch.done, the_var);
@@ -443,6 +456,19 @@ GWARF_result read_statement_list(statement *the_statement, var_list *the_var){
             printf("set_default for %s\n", name);
             break;
         }
+        case set_global:{
+            char *name = the_statement->code.set_global.name;
+            int base_from = get_var_list_len(the_var);
+            append_default_var_base(name, base_from, the_var->default_list);
+            printf("global for %s\n", name);
+            break;
+        }
+        case set_nonlocal:{
+            char *name = the_statement->code.set_global.name;
+            append_default_var_base(name, 1, the_var->default_list);
+            printf("nonlocal for %s\n", name);
+            break;
+        }
         default:
             puts("default");
             break;
@@ -464,7 +490,7 @@ GWARF_result if_func(if_list *if_base, var_list *the_var){  // read the statemen
             value = traverse(start->done, the_var, true);
             puts("----stop else----");
             
-            // restarted
+            // restarted操作
             if(value.u == code_restarted){
                 if(value.value.value.double_value <= 0){
                     puts("----restarted real----");
@@ -477,6 +503,7 @@ GWARF_result if_func(if_list *if_base, var_list *the_var){  // read the statemen
                 }
             }
 
+            // continued操作
             if(value.u == code_continued){
                 if(value.value.value.double_value <= 0){
                     puts("----if continue real----");
@@ -488,6 +515,8 @@ GWARF_result if_func(if_list *if_base, var_list *the_var){  // read the statemen
                 }
                 break;
             }
+
+            // broken操作
             if(value.u == code_broken){
                 value.value.value.double_value -= 1;
                 if(value.value.value.double_value < 0){
@@ -496,6 +525,12 @@ GWARF_result if_func(if_list *if_base, var_list *the_var){  // read the statemen
                 break;
             }
 
+            // rego操作
+            // else层的rego和rewent是可以往上层遗传的[也就是else如果显式指定rego和rewent是会遗传的,但是如果是if或elif指定rego是不会遗传的]
+            if((value.u == code_rewent) || (value.u == code_rego)){
+                ;
+            }
+
             break;  // else not next and don't need rego
         }
         else{  // not else
@@ -507,7 +542,7 @@ GWARF_result if_func(if_list *if_base, var_list *the_var){  // read the statemen
                 value = traverse(start->done, the_var, true);
                 puts("----stop if----");
 
-                // restarted
+                // restarted操作
                 if(value.u == code_restarted){
                     if(value.value.value.double_value <= 0){
                         puts("----restarted real----");
@@ -520,7 +555,7 @@ GWARF_result if_func(if_list *if_base, var_list *the_var){  // read the statemen
                     }
                 }
                 
-                // 设在在rewent和rego前面
+                // continued操作 [设在在rewent和rego前面]
                 if(value.u == code_continued){
                     if(value.value.value.double_value <= 0){
                         puts("----if continue real----");
@@ -532,6 +567,8 @@ GWARF_result if_func(if_list *if_base, var_list *the_var){  // read the statemen
                     }
                     break;
                 }
+
+                // broken操作
                 if(value.u == code_broken){
                     value.value.value.double_value -= 1;
                     if(value.value.value.double_value < 0){
@@ -539,8 +576,10 @@ GWARF_result if_func(if_list *if_base, var_list *the_var){  // read the statemen
                     }
                     break;
                 }
-
+                
+                // rego操作
                 if((value.u == code_rewent) || (value.u == code_rego)){
+                    value.u = statement_end;  // 设置为正常语句
                     rego = true;
                 }
 
@@ -561,24 +600,93 @@ GWARF_result if_func(if_list *if_base, var_list *the_var){  // read the statemen
     return value;
 }
 
+// -----------------for func
+GWARF_result for_func(statement *the_statement, var_list *the_var){  // read the statement list with case to run by func
+    GWARF_result value, condition;
+    if(the_statement->code.for_cycle.first != NULL){
+        traverse(the_statement->code.for_cycle.first, the_var, false); // first to do
+    }
+    while (1){
+        if(the_statement->code.for_cycle.condition != NULL){  // 检查是否存在循环条件
+            condition = traverse(the_statement->code.for_cycle.condition, the_var, false);
+            printf("for condition = %f\n", condition.value.value.double_value);
+            if(!condition.value.value.double_value){
+                break;
+            }
+        }
+        restart_again: 
+        puts("----for----");
+        value = traverse(the_statement->code.for_cycle.done, the_var, true);
+
+        //break操作
+        if((value.u == cycle_break) || (value.u == code_broken)){
+            printf("cycle_break(broken) %f\n", value.value.value.double_value);
+            value.value.value.double_value -= 1;
+            if(value.value.value.double_value < 0){
+                value.u = statement_end;  // 正常设置[正常语句结束]
+            }
+            break;  // break don't need after do
+        }
+        puts("----stop for----");
+
+        // after do
+        if(the_statement->code.for_cycle.after != NULL){
+            traverse(the_statement->code.for_cycle.after, the_var, false);
+        }
+        // continue操作
+        if((value.u == cycle_continue) || (value.u == code_continued)){
+            if(value.value.value.double_value <= 0){
+                puts("----continue real----");
+                value.u = statement_end;
+                continue;
+            }
+            else{
+                value.value.value.double_value -= 1;
+                break;
+            }
+        }
+
+        // restart操作
+        if((value.u == cycle_restart) || (value.u == code_restarted)){
+            if(value.value.value.double_value <= 0){
+                puts("----restart real----");
+                value.u = statement_end;
+                goto restart_again;
+            }
+            else{
+                value.value.value.double_value -= 1;
+                break;
+            }
+        }
+    }
+    return value;
+}
+
 // -----------------while func
 
 GWARF_result while_func(statement *the_statement, var_list *the_var){  // read the statement list with case to run by func
     GWARF_result value, condition;
     while (1){
-        condition = traverse((*the_statement).code.while_cycle.condition, the_var, false);
+        condition = traverse(the_statement->code.while_cycle.condition, the_var, false);
         printf("while condition = %f\n", condition.value.value.double_value);
         if(!condition.value.value.double_value){
             break;
         }
         restart_again: 
         puts("----while----");
-        value = traverse((*the_statement).code.operation.right_exp, the_var, true);
+        value = traverse(the_statement->code.while_cycle.done, the_var, true);
         puts("----stop while----");
-        if((value.u == cycle_break) || (value.u == code_broken)){  // break the while
-            break;
+
+        // break的操作
+        if((value.u == cycle_break) || (value.u == code_broken)){
+            printf("cycle_break(broken) %f\n", value.value.value.double_value);
+            value.value.value.double_value -= 1;
+            if(value.value.value.double_value < 0){
+                value.u = statement_end;  // 正常设置[正常语句结束]
+            }
         }
-        printf("type = %d\n", value.u);
+
+        // continue的操作
         if((value.u == cycle_continue) || (value.u == code_continued)){
             if(value.value.value.double_value <= 0){
                 puts("----continue real----");
@@ -590,6 +698,8 @@ GWARF_result while_func(statement *the_statement, var_list *the_var){  // read t
                 break;
             }
         }
+
+        // restart的操作
         if((value.u == cycle_restart) || (value.u == code_restarted)){
             if(value.value.value.double_value <= 0){
                 puts("----restart real----");
@@ -793,6 +903,19 @@ GWARF_result traverse(statement *the_statement, var_list *the_var, bool new){  /
     return result;
 }
 
+GWARF_result traverse_global(statement *the_statement, var_list *the_var){  // traverse the statement[not break、broken、and others]
+    statement *tmp = the_statement;
+    GWARF_result result;
+    while(1){
+        if(tmp == NULL){
+            break;  // off
+        }
+        result = read_statement_list(tmp, the_var);
+        tmp = tmp->next;
+    }
+    return result;
+}
+
 // -------inter func
 inter *get_inter(){
     inter *tmp;

+ 5 - 2
paser/gwarf_lex.l

@@ -16,7 +16,11 @@
 <INITIAL>"continued" {return CONTINUED;}
 <INITIAL>"rego" {return REGO;}
 <INITIAL>"rewent" {return REWENT;}
-
+<INITIAL>"for" {return FOR;}
+<INITIAL>"," {return COMMA;}
+<INITIAL>"default" {return DEFAULT;}
+<INITIAL>"global" {return GLOBAL;}
+<INITIAL>"nonlocal" {return NONLOCAL;}
 
 <INITIAL>"(" {return LB;}
 <INITIAL>")" {return RB;}
@@ -37,7 +41,6 @@
 <INITIAL>"^" {return POW;}
 <INITIAL>"[" {return LI;}
 <INITIAL>"]" {return RI;}
-<INITIAL>"default" {return DEFAULT;}
 
 <INITIAL>"#" {BEGIN COMMENT;}
 <INITIAL>' {BEGIN STRING_TEXT;}

+ 140 - 2
paser/gwarf_yacc.y

@@ -14,9 +14,9 @@
 }
 %token <double_value> NUMBER
 %token <string_value> STRING VAR
-%token ADD SUB DIV MUL EQ LESS MORE RB LB RP LP WHILE STOP POW EQUAL MOREEQ LESSEQ NOTEQ BREAK IF ELSE ELIF BROKEN CONTINUE CONTINUED RESTART RESTARTED REGO REWENT RI LI DEFAULT
+%token ADD SUB DIV MUL EQ LESS MORE RB LB RP LP WHILE STOP POW EQUAL MOREEQ LESSEQ NOTEQ BREAK IF ELSE ELIF BROKEN CONTINUE CONTINUED RESTART RESTARTED REGO REWENT RI LI DEFAULT FOR COMMA GLOBAL NONLOCAL
 %type <statement_value> base_number base_var_token base_var_ element second_number first_number top_exp command third_number while_block while_exp break_exp if_block if_exp broken_exp break_token broken_token continue_token continue_exp
-%type <statement_value> continued_exp continued_token restart_exp restart_token restarted_exp restarted_token default_token
+%type <statement_value> continued_exp continued_token restart_exp restart_token restarted_exp restarted_token default_token for_exp for_block global_token nonlocal_token
 %type <if_list_base> elif_exp
 %%
 command_block
@@ -104,6 +104,18 @@ command
     {
         $$ = $1;
     }
+    | global_token STOP
+    {
+        $$ = $1;
+    }
+    | for_block STOP
+    {
+        $$ = $1;
+    }
+    | nonlocal_token STOP
+    {
+        $$ = $1;
+    }
     ;
 
 top_exp
@@ -244,6 +256,34 @@ base_number
     }
     ;
 
+nonlocal_token
+    : NONLOCAL base_var_token
+    {
+        statement *code_tmp =  make_statement();
+        code_tmp->type = set_nonlocal;
+        code_tmp->code.set_nonlocal.name = malloc(sizeof($2->code.base_var.var_name));
+        char *name_tmp = code_tmp->code.set_nonlocal.name;
+        strcpy(name_tmp, $2->code.base_var.var_name);
+        free($2->code.base_var.var_name);
+        free($2);
+        $$ = code_tmp;
+    }
+    ;
+
+global_token
+    : GLOBAL base_var_token
+    {
+        statement *code_tmp =  make_statement();
+        code_tmp->type = set_global;
+        code_tmp->code.set_global.name = malloc(sizeof($2->code.base_var.var_name));
+        char *name_tmp = code_tmp->code.set_global.name;
+        strcpy(name_tmp, $2->code.base_var.var_name);
+        free($2->code.base_var.var_name);
+        free($2);
+        $$ = code_tmp;
+    }
+    ;
+
 default_token
     : DEFAULT base_var_token element
     {
@@ -321,6 +361,104 @@ if_exp
     }
     ;
 
+for_block
+    : for_exp block
+    {
+        statement_base = free_statement_list(statement_base);  // new statement_base (FILO)
+    }
+    ;
+
+for_exp
+    : FOR LB COMMA COMMA RB
+    {
+        statement *for_tmp =  make_statement();
+        for_tmp->type = for_cycle;
+        for_tmp->code.for_cycle.first = NULL;
+        for_tmp->code.for_cycle.condition = NULL;
+        for_tmp->code.for_cycle.after = NULL;
+        for_tmp->code.for_cycle.done = make_statement();
+        statement_base = append_statement_list(for_tmp->code.for_cycle.done, statement_base);  // new statement_base (FILO)
+        $$ = for_tmp;
+    }
+    | FOR LB top_exp COMMA COMMA RB
+    {
+        statement *for_tmp =  make_statement();
+        for_tmp->type = for_cycle;
+        for_tmp->code.for_cycle.first = $3;  // 只有初始化
+        for_tmp->code.for_cycle.condition = NULL;
+        for_tmp->code.for_cycle.after = NULL;
+        for_tmp->code.for_cycle.done = make_statement();
+        statement_base = append_statement_list(for_tmp->code.for_cycle.done, statement_base);  // new statement_base (FILO)
+        $$ = for_tmp;
+    }
+    | FOR LB COMMA top_exp COMMA RB
+    {
+        statement *for_tmp =  make_statement();
+        for_tmp->type = for_cycle;
+        for_tmp->code.for_cycle.first = NULL;
+        for_tmp->code.for_cycle.condition = $4;  // 只有条件
+        for_tmp->code.for_cycle.after = NULL;
+        for_tmp->code.for_cycle.done = make_statement();
+        statement_base = append_statement_list(for_tmp->code.for_cycle.done, statement_base);  // new statement_base (FILO)
+        $$ = for_tmp;
+    }
+    | FOR LB COMMA COMMA top_exp RB
+    {
+        statement *for_tmp =  make_statement();
+        for_tmp->type = for_cycle;
+        for_tmp->code.for_cycle.first = NULL;
+        for_tmp->code.for_cycle.condition = NULL;
+        for_tmp->code.for_cycle.after = $5;  // 只有后置操作
+        for_tmp->code.for_cycle.done = make_statement();
+        statement_base = append_statement_list(for_tmp->code.for_cycle.done, statement_base);  // new statement_base (FILO)
+        $$ = for_tmp;
+    }
+    | FOR LB top_exp COMMA COMMA top_exp RB
+    {
+        statement *for_tmp =  make_statement();
+        for_tmp->type = for_cycle;
+        for_tmp->code.for_cycle.first = $3;
+        for_tmp->code.for_cycle.condition = NULL;  // 无条件
+        for_tmp->code.for_cycle.after = $6;
+        for_tmp->code.for_cycle.done = make_statement();
+        statement_base = append_statement_list(for_tmp->code.for_cycle.done, statement_base);  // new statement_base (FILO)
+        $$ = for_tmp;
+    }
+    | FOR LB top_exp COMMA top_exp COMMA RB
+    {
+        statement *for_tmp =  make_statement();
+        for_tmp->type = for_cycle;
+        for_tmp->code.for_cycle.first = $3;
+        for_tmp->code.for_cycle.condition = $5;
+        for_tmp->code.for_cycle.after = NULL;  //无后置操作
+        for_tmp->code.for_cycle.done = make_statement();
+        statement_base = append_statement_list(for_tmp->code.for_cycle.done, statement_base);  // new statement_base (FILO)
+        $$ = for_tmp;
+    }
+    | FOR LB COMMA top_exp COMMA top_exp RB
+    {
+        statement *for_tmp =  make_statement();
+        for_tmp->type = for_cycle;
+        for_tmp->code.for_cycle.first = NULL;  //无初始化
+        for_tmp->code.for_cycle.condition = $4;
+        for_tmp->code.for_cycle.after = $6;
+        for_tmp->code.for_cycle.done = make_statement();
+        statement_base = append_statement_list(for_tmp->code.for_cycle.done, statement_base);  // new statement_base (FILO)
+        $$ = for_tmp;
+    }
+    | FOR LB top_exp COMMA top_exp COMMA top_exp RB
+    {
+        statement *for_tmp =  make_statement();
+        for_tmp->type = for_cycle;
+        for_tmp->code.for_cycle.first = $3;
+        for_tmp->code.for_cycle.condition = $5;
+        for_tmp->code.for_cycle.after = $7;
+        for_tmp->code.for_cycle.done = make_statement();
+        statement_base = append_statement_list(for_tmp->code.for_cycle.done, statement_base);  // new statement_base (FILO)
+        $$ = for_tmp;
+    }
+    ;
+
 while_block
     : while_exp block
     {

+ 209 - 179
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 48
-#define YY_END_OF_BUFFER 49
+#define YY_NUM_RULES 52
+#define YY_END_OF_BUFFER 53
 /* This struct is not used in this scanner,
    but its presence is necessary. */
 struct yy_trans_info
@@ -360,21 +360,23 @@ struct yy_trans_info
 	flex_int32_t yy_verify;
 	flex_int32_t yy_nxt;
 	};
-static const flex_int16_t yy_accept[114] =
+static const flex_int16_t yy_accept[132] =
     {   0,
-        0,    0,    0,    0,    0,    0,   49,   40,   38,   37,
-       40,   34,   32,   33,   13,   14,   26,   24,   25,   27,
-       35,   35,   39,   21,   23,   20,   36,   29,   30,   28,
-       36,   36,   36,   36,   36,   36,   36,   15,   16,   43,
-       41,   42,   47,   46,   45,   44,    0,    0,   15,   19,
-        0,   35,   38,   18,   22,   17,   36,   36,   36,   36,
-       36,    2,   36,   36,   15,    0,   35,   36,   36,   36,
-       36,   36,   36,   36,   36,   36,   36,    0,    0,   36,
-       36,   36,   36,    3,    4,   11,   36,   36,   36,    3,
-        4,    5,   36,   36,   36,    0,   36,   36,    1,    6,
-
-       36,   36,    4,   36,   12,   36,   31,    8,    7,   36,
-       10,    9,    0
+        0,    0,    0,    0,    0,    0,   53,   44,   42,   41,
+       44,   38,   36,   37,   18,   19,   31,   29,   14,   30,
+       32,   39,   39,   43,   26,   28,   25,   40,   34,   35,
+       33,   40,   40,   40,   40,   40,   40,   40,   40,   40,
+       40,   20,   21,   47,   45,   46,   51,   50,   49,   48,
+        0,    0,   20,   24,    0,   39,   42,   23,   27,   22,
+       40,   40,   40,   40,   40,   40,   40,    2,   40,   40,
+       40,   20,    0,   39,   40,   40,   40,   40,   40,   40,
+       13,   40,   40,   40,   40,   40,   40,    0,    0,   40,
+       40,   40,   40,    3,    4,   40,   40,   11,   40,   40,
+
+       40,    3,    4,    5,   40,   40,   40,    0,   40,   40,
+       40,   40,    1,    6,   40,   40,    4,   16,   40,   40,
+       12,   40,   15,   40,    8,    7,   17,   40,   10,    9,
+        0
     } ;
 
 static const YY_CHAR yy_ec[256] =
@@ -383,16 +385,16 @@ static const YY_CHAR yy_ec[256] =
         1,    1,    1,    1,    1,    1,    1,    1,    1,    1,
         1,    1,    1,    1,    1,    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,   17,   18,
-       19,   20,    1,    1,   21,   21,   21,   21,   21,   21,
-       21,   21,   21,   21,   21,   21,   21,   21,   21,   21,
-       21,   21,   21,   21,   21,   21,   21,   21,   21,   21,
-       22,    1,   23,   24,   21,    1,   25,   26,   27,   28,
-
-       29,   30,   31,   32,   33,   21,   34,   35,   21,   36,
-       37,   21,   21,   38,   39,   40,   41,   21,   42,   21,
-       21,   21,   43,    1,   44,    1,    1,    1,    1,    1,
+        9,   10,   11,   12,   13,   14,   15,   16,   17,   17,
+       17,   17,   17,   17,   17,   17,   17,    1,   18,   19,
+       20,   21,    1,    1,   22,   22,   22,   22,   22,   22,
+       22,   22,   22,   22,   22,   22,   22,   22,   22,   22,
+       22,   22,   22,   22,   22,   22,   22,   22,   22,   22,
+       23,    1,   24,   25,   22,    1,   26,   27,   28,   29,
+
+       30,   31,   32,   33,   34,   22,   35,   36,   22,   37,
+       38,   22,   22,   39,   40,   41,   42,   22,   43,   22,
+       22,   22,   44,    1,   45,    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,
@@ -409,95 +411,103 @@ static const YY_CHAR yy_ec[256] =
         1,    1,    1,    1,    1
     } ;
 
-static const YY_CHAR yy_meta[45] =
+static const YY_CHAR yy_meta[46] =
     {   0,
         1,    1,    1,    1,    1,    1,    1,    1,    1,    1,
-        1,    1,    1,    1,    2,    2,    1,    1,    1,    1,
-        2,    1,    1,    1,    2,    2,    2,    2,    2,    2,
+        1,    1,    1,    1,    1,    2,    2,    1,    1,    1,
+        1,    2,    1,    1,    1,    2,    2,    2,    2,    2,
         2,    2,    2,    2,    2,    2,    2,    2,    2,    2,
-        2,    2,    1,    1
+        2,    2,    2,    1,    1
     } ;
 
-static const flex_int16_t yy_base[117] =
+static const flex_int16_t yy_base[135] =
     {   0,
-        0,    0,   43,   44,   46,   50,  138,  139,   45,  139,
-      118,  139,  139,  139,  139,  139,  139,  139,  139,  139,
-      139,   43,  134,  116,  115,  114,    0,  139,  139,  139,
-       94,   94,  101,   94,   98,   98,   94,  123,  139,  139,
-      139,  139,  139,  139,  139,  139,   52,   89,  121,  139,
-       45,   49,  139,  139,  139,  139,    0,   34,   86,   91,
-       33,    0,   36,   87,  117,   37,   53,   93,   83,   76,
-       90,   84,   84,   75,   71,   81,   74,   78,   78,   72,
-       76,   71,   62,    0,   94,    0,   76,   64,   65,  139,
-       85,    0,   56,   55,   55,   80,   49,   46,    0,    0,
-
-       44,   44,  139,   43,    0,   53,    0,   51,   51,   49,
-        0,    0,  139,   95,   97,   71
+        0,    0,   44,   45,   47,   51,  153,  154,   46,  154,
+      132,  154,  154,  154,  154,  154,  154,  154,  154,  154,
+      154,  154,   43,  149,  130,  129,  128,    0,  154,  154,
+      154,  108,  108,  115,  108,  105,  106,  110,  102,  109,
+      105,  135,  154,  154,  154,  154,  154,  154,  154,  154,
+       53,  100,  133,  154,   45,   49,  154,  154,  154,  154,
+        0,   34,   97,  102,   33,   93,   93,    0,   93,   37,
+       95,  126,   34,   54,  101,   91,   84,   98,   92,   92,
+        0,   94,   84,   81,   77,   87,   80,   84,   84,   78,
+       82,   77,   68,    0,  101,   82,   69,    0,   80,   68,
+
+       74,  154,   95,    0,   65,   59,   59,   85,   57,   64,
+       52,   48,    0,    0,   46,   46,  154,    0,   60,   44,
+        0,   54,    0,   46,   51,   50,    0,   49,    0,    0,
+      154,   97,   99,   73
     } ;
 
-static const flex_int16_t yy_def[117] =
+static const flex_int16_t yy_def[135] =
     {   0,
-      113,    1,  114,  114,  115,  115,  113,  113,  113,  113,
-      113,  113,  113,  113,  113,  113,  113,  113,  113,  113,
-      113,  113,  113,  113,  113,  113,  116,  113,  113,  113,
-      116,  116,  116,  116,  116,  116,  116,  113,  113,  113,
-      113,  113,  113,  113,  113,  113,  113,  113,  113,  113,
-      113,  113,  113,  113,  113,  113,  116,  116,  116,  116,
-      116,  116,  116,  116,  113,  113,  113,  116,  116,  116,
-      116,  116,  116,  116,  116,  116,  116,  113,  113,  116,
-      116,  116,  116,  116,  116,  116,  116,  116,  116,  113,
-      113,  116,  116,  116,  116,  113,  116,  116,  116,  116,
-
-      116,  116,  113,  116,  116,  116,  116,  116,  116,  116,
-      116,  116,    0,  113,  113,  113
+      131,    1,  132,  132,  133,  133,  131,  131,  131,  131,
+      131,  131,  131,  131,  131,  131,  131,  131,  131,  131,
+      131,  131,  131,  131,  131,  131,  131,  134,  131,  131,
+      131,  134,  134,  134,  134,  134,  134,  134,  134,  134,
+      134,  131,  131,  131,  131,  131,  131,  131,  131,  131,
+      131,  131,  131,  131,  131,  131,  131,  131,  131,  131,
+      134,  134,  134,  134,  134,  134,  134,  134,  134,  134,
+      134,  131,  131,  131,  134,  134,  134,  134,  134,  134,
+      134,  134,  134,  134,  134,  134,  134,  131,  131,  134,
+      134,  134,  134,  134,  134,  134,  134,  134,  134,  134,
+
+      134,  131,  131,  134,  134,  134,  134,  131,  134,  134,
+      134,  134,  134,  134,  134,  134,  131,  134,  134,  134,
+      134,  134,  134,  134,  134,  134,  134,  134,  134,  134,
+        0,  131,  131,  131
     } ;
 
-static const flex_int16_t yy_nxt[184] =
+static const flex_int16_t yy_nxt[200] =
     {   0,
         8,    9,   10,   11,   12,   13,   14,   15,   16,   17,
-       18,   19,    8,   20,   21,   22,   23,   24,   25,   26,
-       27,   28,   29,   30,   27,   31,   32,   33,   34,   27,
-       27,   27,   35,   27,   27,   27,   27,   36,   27,   27,
-       27,   37,   38,   39,   41,   41,   47,   44,   42,   42,
-       45,   44,   46,   47,   45,   51,   46,   52,   52,   67,
-       67,   51,   68,   52,   52,   72,   74,   67,   67,   78,
-       69,   73,   57,   48,   75,   79,  112,   76,  111,  110,
-       48,  109,  108,  107,  106,  105,  104,   49,  103,  102,
-      101,  100,   96,   99,   49,   40,   40,   43,   43,   98,
-
-       97,   96,   95,   94,   93,   92,   91,   90,   89,   88,
-       87,   86,   85,   84,   83,   82,   81,   80,   65,   77,
-       71,   70,   65,   66,   65,   64,   63,   62,   61,   60,
-       59,   58,   56,   55,   54,   53,   50,  113,    7,  113,
-      113,  113,  113,  113,  113,  113,  113,  113,  113,  113,
-      113,  113,  113,  113,  113,  113,  113,  113,  113,  113,
-      113,  113,  113,  113,  113,  113,  113,  113,  113,  113,
-      113,  113,  113,  113,  113,  113,  113,  113,  113,  113,
-      113,  113,  113
+       18,   19,   20,    8,   21,   22,   23,   24,   25,   26,
+       27,   28,   29,   30,   31,   28,   32,   33,   34,   35,
+       36,   37,   28,   38,   28,   28,   39,   28,   40,   28,
+       28,   28,   41,   42,   43,   45,   45,   51,   48,   46,
+       46,   49,   48,   50,   51,   49,   55,   50,   56,   56,
+       74,   74,   55,   75,   56,   56,   79,   88,   84,   74,
+       74,   76,   80,   89,   61,   52,   85,  130,  129,   86,
+      128,  127,   52,  126,  125,  124,  123,  122,  121,   53,
+      120,  119,  118,  117,  116,  115,   53,   44,   44,   47,
+
+       47,  114,  108,  113,  112,  111,  110,  109,  108,  107,
+      106,  105,  104,  103,  102,  101,  100,   99,   98,   97,
+       96,   95,   94,   93,   92,   91,   90,   72,   87,   83,
+       82,   81,   78,   77,   72,   73,   72,   71,   70,   69,
+       68,   67,   66,   65,   64,   63,   62,   60,   59,   58,
+       57,   54,  131,    7,  131,  131,  131,  131,  131,  131,
+      131,  131,  131,  131,  131,  131,  131,  131,  131,  131,
+      131,  131,  131,  131,  131,  131,  131,  131,  131,  131,
+      131,  131,  131,  131,  131,  131,  131,  131,  131,  131,
+      131,  131,  131,  131,  131,  131,  131,  131,  131
+
     } ;
 
-static const flex_int16_t yy_chk[184] =
+static const flex_int16_t yy_chk[200] =
     {   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,    3,    4,    9,    5,    3,    4,
-        5,    6,    5,   47,    6,   22,    6,   22,   22,   51,
-       51,   52,   58,   52,   52,   61,   63,   67,   67,   66,
-       58,   61,  116,    9,   63,   66,  110,   63,  109,  108,
-       47,  106,  104,  102,  101,   98,   97,    9,   96,   95,
-       94,   93,   91,   89,   47,  114,  114,  115,  115,   88,
-
-       87,   85,   83,   82,   81,   80,   79,   78,   77,   76,
-       75,   74,   73,   72,   71,   70,   69,   68,   65,   64,
-       60,   59,   49,   48,   38,   37,   36,   35,   34,   33,
-       32,   31,   26,   25,   24,   23,   11,    7,  113,  113,
-      113,  113,  113,  113,  113,  113,  113,  113,  113,  113,
-      113,  113,  113,  113,  113,  113,  113,  113,  113,  113,
-      113,  113,  113,  113,  113,  113,  113,  113,  113,  113,
-      113,  113,  113,  113,  113,  113,  113,  113,  113,  113,
-      113,  113,  113
+        1,    1,    1,    1,    1,    3,    4,    9,    5,    3,
+        4,    5,    6,    5,   51,    6,   23,    6,   23,   23,
+       55,   55,   56,   62,   56,   56,   65,   73,   70,   74,
+       74,   62,   65,   73,  134,    9,   70,  128,  126,   70,
+      125,  124,   51,  122,  120,  119,  116,  115,  112,    9,
+      111,  110,  109,  108,  107,  106,   51,  132,  132,  133,
+
+      133,  105,  103,  101,  100,   99,   97,   96,   95,   93,
+       92,   91,   90,   89,   88,   87,   86,   85,   84,   83,
+       82,   80,   79,   78,   77,   76,   75,   72,   71,   69,
+       67,   66,   64,   63,   53,   52,   42,   41,   40,   39,
+       38,   37,   36,   35,   34,   33,   32,   27,   26,   25,
+       24,   11,    7,  131,  131,  131,  131,  131,  131,  131,
+      131,  131,  131,  131,  131,  131,  131,  131,  131,  131,
+      131,  131,  131,  131,  131,  131,  131,  131,  131,  131,
+      131,  131,  131,  131,  131,  131,  131,  131,  131,  131,
+      131,  131,  131,  131,  131,  131,  131,  131,  131
+
     } ;
 
 static yy_state_type yy_last_accepting_state;
@@ -518,9 +528,9 @@ char *yytext;
 #line 2 "gwarf_lex.l"
     #include<stdio.h>
     #include"y.tab.h"
-#line 521 "lex.yy.c"
+#line 531 "lex.yy.c"
 
-#line 523 "lex.yy.c"
+#line 533 "lex.yy.c"
 
 #define INITIAL 0
 #define COMMENT 1
@@ -741,7 +751,7 @@ YY_DECL
 	{
 #line 6 "gwarf_lex.l"
 
-#line 744 "lex.yy.c"
+#line 754 "lex.yy.c"
 
 	while ( /*CONSTCOND*/1 )		/* loops until end-of-file is reached */
 		{
@@ -768,13 +778,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 >= 114 )
+				if ( yy_current_state >= 132 )
 					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] != 139 );
+		while ( yy_base[yy_current_state] != 154 );
 
 yy_find_action:
 		yy_act = yy_accept[yy_current_state];
@@ -862,201 +872,221 @@ YY_RULE_SETUP
 	YY_BREAK
 case 13:
 YY_RULE_SETUP
-#line 21 "gwarf_lex.l"
-{return LB;}
+#line 19 "gwarf_lex.l"
+{return FOR;}
 	YY_BREAK
 case 14:
 YY_RULE_SETUP
-#line 22 "gwarf_lex.l"
-{return RB;}
+#line 20 "gwarf_lex.l"
+{return COMMA;}
 	YY_BREAK
 case 15:
-/* rule 15 can match eol */
 YY_RULE_SETUP
-#line 23 "gwarf_lex.l"
-{return LP;}
+#line 21 "gwarf_lex.l"
+{return DEFAULT;}
 	YY_BREAK
 case 16:
 YY_RULE_SETUP
-#line 24 "gwarf_lex.l"
-{return RP;}
+#line 22 "gwarf_lex.l"
+{return GLOBAL;}
 	YY_BREAK
 case 17:
 YY_RULE_SETUP
-#line 26 "gwarf_lex.l"
-{return MOREEQ;}
+#line 23 "gwarf_lex.l"
+{return NONLOCAL;}
 	YY_BREAK
 case 18:
 YY_RULE_SETUP
-#line 27 "gwarf_lex.l"
-{return LESSEQ;}
+#line 25 "gwarf_lex.l"
+{return LB;}
 	YY_BREAK
 case 19:
 YY_RULE_SETUP
-#line 28 "gwarf_lex.l"
-{return NOTEQ;}
+#line 26 "gwarf_lex.l"
+{return RB;}
 	YY_BREAK
 case 20:
+/* rule 20 can match eol */
 YY_RULE_SETUP
-#line 29 "gwarf_lex.l"
-{return MORE;}
+#line 27 "gwarf_lex.l"
+{return LP;}
 	YY_BREAK
 case 21:
 YY_RULE_SETUP
-#line 30 "gwarf_lex.l"
-{return LESS;}
+#line 28 "gwarf_lex.l"
+{return RP;}
 	YY_BREAK
 case 22:
 YY_RULE_SETUP
-#line 31 "gwarf_lex.l"
-{return EQUAL;}
+#line 30 "gwarf_lex.l"
+{return MOREEQ;}
 	YY_BREAK
 case 23:
 YY_RULE_SETUP
-#line 32 "gwarf_lex.l"
-{return EQ;}
+#line 31 "gwarf_lex.l"
+{return LESSEQ;}
 	YY_BREAK
 case 24:
 YY_RULE_SETUP
-#line 33 "gwarf_lex.l"
-{return ADD;}
+#line 32 "gwarf_lex.l"
+{return NOTEQ;}
 	YY_BREAK
 case 25:
 YY_RULE_SETUP
-#line 34 "gwarf_lex.l"
-{return SUB;}
+#line 33 "gwarf_lex.l"
+{return MORE;}
 	YY_BREAK
 case 26:
 YY_RULE_SETUP
-#line 35 "gwarf_lex.l"
-{return MUL;}
+#line 34 "gwarf_lex.l"
+{return LESS;}
 	YY_BREAK
 case 27:
 YY_RULE_SETUP
-#line 36 "gwarf_lex.l"
-{return DIV;}
+#line 35 "gwarf_lex.l"
+{return EQUAL;}
 	YY_BREAK
 case 28:
 YY_RULE_SETUP
-#line 37 "gwarf_lex.l"
-{return POW;}
+#line 36 "gwarf_lex.l"
+{return EQ;}
 	YY_BREAK
 case 29:
 YY_RULE_SETUP
-#line 38 "gwarf_lex.l"
-{return LI;}
+#line 37 "gwarf_lex.l"
+{return ADD;}
 	YY_BREAK
 case 30:
 YY_RULE_SETUP
-#line 39 "gwarf_lex.l"
-{return RI;}
+#line 38 "gwarf_lex.l"
+{return SUB;}
 	YY_BREAK
 case 31:
 YY_RULE_SETUP
-#line 40 "gwarf_lex.l"
-{return DEFAULT;}
+#line 39 "gwarf_lex.l"
+{return MUL;}
 	YY_BREAK
 case 32:
 YY_RULE_SETUP
-#line 42 "gwarf_lex.l"
-{BEGIN COMMENT;}
+#line 40 "gwarf_lex.l"
+{return DIV;}
 	YY_BREAK
 case 33:
 YY_RULE_SETUP
-#line 43 "gwarf_lex.l"
-{BEGIN STRING_TEXT;}
+#line 41 "gwarf_lex.l"
+{return POW;}
 	YY_BREAK
 case 34:
 YY_RULE_SETUP
-#line 44 "gwarf_lex.l"
-{BEGIN STRING_TEXT;}
+#line 42 "gwarf_lex.l"
+{return LI;}
 	YY_BREAK
 case 35:
 YY_RULE_SETUP
+#line 43 "gwarf_lex.l"
+{return RI;}
+	YY_BREAK
+case 36:
+YY_RULE_SETUP
 #line 45 "gwarf_lex.l"
+{BEGIN COMMENT;}
+	YY_BREAK
+case 37:
+YY_RULE_SETUP
+#line 46 "gwarf_lex.l"
+{BEGIN STRING_TEXT;}
+	YY_BREAK
+case 38:
+YY_RULE_SETUP
+#line 47 "gwarf_lex.l"
+{BEGIN STRING_TEXT;}
+	YY_BREAK
+case 39:
+YY_RULE_SETUP
+#line 48 "gwarf_lex.l"
 {
     yylval.double_value = atof(yytext);
     return NUMBER;
     }
 	YY_BREAK
-case 36:
+case 40:
 YY_RULE_SETUP
-#line 49 "gwarf_lex.l"
+#line 52 "gwarf_lex.l"
 {
     yylval.string_value = yytext;
     return VAR;
     }
 	YY_BREAK
-case 37:
+case 41:
 YY_RULE_SETUP
-#line 54 "gwarf_lex.l"
+#line 57 "gwarf_lex.l"
 ;
 	YY_BREAK
-case 38:
-/* rule 38 can match eol */
+case 42:
+/* rule 42 can match eol */
 YY_RULE_SETUP
-#line 55 "gwarf_lex.l"
+#line 58 "gwarf_lex.l"
 {return STOP;}
 	YY_BREAK
-case 39:
+case 43:
 YY_RULE_SETUP
-#line 56 "gwarf_lex.l"
+#line 59 "gwarf_lex.l"
 {return STOP;}
 	YY_BREAK
-case 40:
+case 44:
 YY_RULE_SETUP
-#line 57 "gwarf_lex.l"
+#line 60 "gwarf_lex.l"
 {printf("text = [%s];\n", yytext);}
 	YY_BREAK
-case 41:
-/* rule 41 can match eol */
+case 45:
+/* rule 45 can match eol */
 YY_RULE_SETUP
-#line 59 "gwarf_lex.l"
+#line 62 "gwarf_lex.l"
 {BEGIN INITIAL;}
 	YY_BREAK
-case 42:
+case 46:
 YY_RULE_SETUP
-#line 60 "gwarf_lex.l"
+#line 63 "gwarf_lex.l"
 {BEGIN INITIAL;}
 	YY_BREAK
-case 43:
+case 47:
 YY_RULE_SETUP
-#line 61 "gwarf_lex.l"
+#line 64 "gwarf_lex.l"
 ;
 	YY_BREAK
-case 44:
+case 48:
 YY_RULE_SETUP
-#line 63 "gwarf_lex.l"
+#line 66 "gwarf_lex.l"
 {BEGIN INITIAL;}
 	YY_BREAK
-case 45:
+case 49:
 YY_RULE_SETUP
-#line 64 "gwarf_lex.l"
+#line 67 "gwarf_lex.l"
 {BEGIN INITIAL;}
 	YY_BREAK
-case 46:
-/* rule 46 can match eol */
+case 50:
+/* rule 50 can match eol */
 YY_RULE_SETUP
-#line 65 "gwarf_lex.l"
+#line 68 "gwarf_lex.l"
 {
     yylval.string_value = yytext;
     return STRING;
     }
 	YY_BREAK
-case 47:
+case 51:
 YY_RULE_SETUP
-#line 69 "gwarf_lex.l"
+#line 72 "gwarf_lex.l"
 {
     yylval.string_value = yytext;
     return STRING;
     }
 	YY_BREAK
-case 48:
+case 52:
 YY_RULE_SETUP
-#line 73 "gwarf_lex.l"
+#line 76 "gwarf_lex.l"
 ECHO;
 	YY_BREAK
-#line 1059 "lex.yy.c"
+#line 1089 "lex.yy.c"
 case YY_STATE_EOF(INITIAL):
 case YY_STATE_EOF(COMMENT):
 case YY_STATE_EOF(STRING_TEXT):
@@ -1355,7 +1385,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 >= 114 )
+			if ( yy_current_state >= 132 )
 				yy_c = yy_meta[yy_c];
 			}
 		yy_current_state = yy_nxt[yy_base[yy_current_state] + yy_c];
@@ -1383,11 +1413,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 >= 114 )
+		if ( yy_current_state >= 132 )
 			yy_c = yy_meta[yy_c];
 		}
 	yy_current_state = yy_nxt[yy_base[yy_current_state] + yy_c];
-	yy_is_jam = (yy_current_state == 113);
+	yy_is_jam = (yy_current_state == 131);
 
 		return yy_is_jam ? 0 : yy_current_state;
 }
@@ -2063,7 +2093,7 @@ void yyfree (void * ptr )
 
 #define YYTABLES_NAME "yytables"
 
-#line 73 "gwarf_lex.l"
+#line 76 "gwarf_lex.l"
 
 int yywrap(void) {
     return 1;

File diff suppressed because it is too large
+ 424 - 197
paser/y.tab.c


+ 10 - 2
paser/y.tab.h

@@ -83,7 +83,11 @@ extern int yydebug;
     REWENT = 289,
     RI = 290,
     LI = 291,
-    DEFAULT = 292
+    DEFAULT = 292,
+    FOR = 293,
+    COMMA = 294,
+    GLOBAL = 295,
+    NONLOCAL = 296
   };
 #endif
 /* Tokens.  */
@@ -122,6 +126,10 @@ extern int yydebug;
 #define RI 290
 #define LI 291
 #define DEFAULT 292
+#define FOR 293
+#define COMMA 294
+#define GLOBAL 295
+#define NONLOCAL 296
 
 /* Value type.  */
 #if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED
@@ -135,7 +143,7 @@ union YYSTYPE
     struct statement *statement_value;
     struct if_list *if_list_base;
 
-#line 139 "y.tab.h"
+#line 147 "y.tab.h"
 
 };
 typedef union YYSTYPE YYSTYPE;

Some files were not shown because too many files changed in this diff