Bläddra i källkod

新增True False NULL和函数定义与调用

SongZihuan 5 år sedan
förälder
incheckning
7d88fa085a
8 ändrade filer med 1089 tillägg och 462 borttagningar
  1. BIN
      gwarf
  2. 49 1
      gwarf_interpreter/interprete.h
  3. 298 33
      gwarf_interpreter/interpreter.c
  4. 11 0
      paser/gwarf_lex.l
  5. 156 13
      paser/gwarf_yacc.y
  6. 222 157
      paser/lex.yy.c
  7. 340 256
      paser/y.tab.c
  8. 13 2
      paser/y.tab.h

BIN
gwarf


+ 49 - 1
gwarf_interpreter/interprete.h

@@ -1,13 +1,23 @@
+#include <stdio.h>
 #define false 0
 #define true 1
 #define bool int
 
+// the func
+typedef struct func{
+    char *name;
+    struct parameter *parameter_list;  // def parameter
+    struct statement *done;  // def to do
+} func;
+
 // the type of data(GWARF_value)
 typedef enum{
     NUMBER_value = 1,
     INT_value,  // INT 类型
     BOOL_value,  // bool : true or false
     STRING_value,  // char *
+    NULL_value,
+    FUNC_value,
 } GWARF_value_type;
 
 // all value is GWARF_value
@@ -19,10 +29,20 @@ typedef struct GWARF_value{
         int int_value;
         bool bool_value;
         char *string;  // STRING
+        func *func_value;
     } value;
-    
 } GWARF_value;
 
+// ------------------------- parameter for def
+typedef struct parameter{
+    union
+    {
+        char *name;  // var name
+        struct statement *value;  // or value
+    } u;
+    struct parameter *next;  // for list
+} parameter;
+
 // ------------------------- var
 
 typedef struct var{
@@ -54,6 +74,9 @@ typedef struct statement{
         set_global,
         set_nonlocal,
         code_block,
+        def,  // func
+        call,  // func()
+        return_code,
     } type;  // the statement type
 
     union
@@ -152,6 +175,21 @@ typedef struct statement{
             struct statement *done;  // while to do
         } code_block;
 
+        struct{
+            char *name;
+            parameter *parameter_list;  // def parameter
+            struct statement *done;  // def to do
+        } def;
+
+        struct{
+            parameter *parameter_list;  // def parameter
+            struct statement *func;  // get func value
+        } call;
+
+        struct{
+            struct statement *times;  // 层数
+            struct statement *value;  // return value
+        } return_code;
     } code;
     struct statement *next;
 } statement;
@@ -171,8 +209,10 @@ typedef struct GWARF_result{
         code_restarted,
         code_rego,
         code_rewent,
+        code_return,
         name_no_found,
     } u;  // the result type[from where]
+    int return_times;  // return用
 } GWARF_result;
 
 // ------------------------- default_var [记录默认变量[层]]
@@ -254,6 +294,14 @@ int yyerror(char const *);
 FILE *yyin;
 char *yytext;
 
+// ---- parameter func[形参]
+parameter *make_parameter_name(char *);
+void append_parameter_name(char *, parameter *);
+
+// ---- parameter func[实参]
+parameter *make_parameter_value(statement *);
+void append_parameter_value(statement *, parameter *);
+
 // main
 inter *global_inter;
 statement_list *statement_base;

+ 298 - 33
gwarf_interpreter/interpreter.c

@@ -18,6 +18,7 @@ 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 *);
 GWARF_result negative_func(GWARF_result, var_list *);
+GWARF_result call_back(statement *, var_list *);
 int get_var_list_len(var_list *);
 GWARF_result block_func(statement *, var_list *);
 
@@ -32,6 +33,73 @@ double sqrt_(double base, double num){  // 定义根号sqrt
     return pow(base, (1 / num));
 }
 
+// bool[bool逻辑转换]
+bool to_bool(GWARF_value);
+bool to_bool(GWARF_value value){
+    double bool_double = 1;  // if bool_double == 0则返回false其他返回true
+    if(value.type == INT_value || value.type == BOOL_value){
+        bool_double = (double)value.value.int_value;
+    }
+    else if(value.type == NUMBER_value){
+        bool_double = value.value.double_value;
+    }
+    else if(value.type == STRING_value){
+        bool_double = (double)strlen(value.value.string);
+    }
+    else if(value.type == NULL_value){
+        bool_double = 0;
+    }
+    if(bool_double){
+        return true;
+    }
+    else{
+        return false;
+    }
+}
+
+// ---- parameter func[形参]
+parameter *make_parameter_name(char *name){
+    parameter *tmp;
+    tmp = malloc(sizeof(parameter));  // get an address for base var
+    tmp->next = NULL;
+    tmp->u.name = malloc(sizeof(name));
+    strcpy(tmp->u.name, name);
+    return tmp;
+}
+
+void append_parameter_name(char *name, parameter *parameter_base){
+    parameter *tmp = parameter_base;  // iter var
+    while(1){
+        if (tmp->next == NULL){  // the last
+            break;
+        }
+        tmp = tmp->next;  // get the next to iter
+    }
+    parameter *new_tmp = make_parameter_name(name);
+    tmp->next = new_tmp;
+}
+
+// ---- parameter func[实参]
+parameter *make_parameter_value(statement *value){
+    parameter *tmp;
+    tmp = malloc(sizeof(parameter));  // get an address for base var
+    tmp->next = NULL;
+    tmp->u.value = value;
+    return tmp;
+}
+
+void append_parameter_value(statement *value, parameter *parameter_base){
+    parameter *tmp = parameter_base;  // iter var
+    while(1){
+        if (tmp->next == NULL){  // the last
+            break;
+        }
+        tmp = tmp->next;  // get the next to iter
+    }
+    parameter *new_tmp = make_parameter_value(value);
+    tmp->next = new_tmp;
+}
+
 // ---- var func
 
 var *make_var(){  // make var with base
@@ -353,17 +421,34 @@ GWARF_result read_statement_list(statement *the_statement, var_list *the_var){
         case operation:  // 表达式运算
             puts("----code----");
             return_value = operation_func(the_statement, the_var);
-            if((return_value.value.type == INT_value) || (return_value.value.type == BOOL_value)){
+            if((return_value.value.type == INT_value)){
                 printf("operation value = %d\n", return_value.value.value.int_value);
             }
+            else if(return_value.value.type == BOOL_value){
+                if(return_value.value.value.bool_value){
+                    printf("operation value = true\n");
+                }
+                else{
+                    printf("operation value = false\n");
+                } 
+            }
             else if(return_value.value.type == NUMBER_value){
                 printf("operation value = %f\n", return_value.value.value.double_value);
             }
-            else{
+            else if(return_value.value.type == NULL_value){
+                printf("operation value = None\n");
+            }
+            else if(return_value.value.type == STRING_value){
                 printf("operation value = %s\n", return_value.value.value.string);
             }
+            else{
+                    printf("var value = other\n");
+                }
             puts("----stop code----");
             break;
+        case call:
+            return_value = call_back(the_statement, the_var);
+            break;
         case while_cycle:
             puts("----while code----");
             return_value = while_func(the_statement, the_var);
@@ -387,9 +472,15 @@ GWARF_result read_statement_list(statement *the_statement, var_list *the_var){
             else if(return_value.value.type == NUMBER_value){
                 printf("get value = %f\n", return_value.value.value.double_value);
             }
-            else{
+            else if(return_value.value.type == NULL_value){
+                printf("operation value = None\n");
+            }
+            else if(return_value.value.type == STRING_value){
                 printf("get value = %s\n", return_value.value.value.string);
             }
+            else{
+                    printf("var value = other\n");
+                }
             break;
         case base_var:{    // because the var tmp, we should ues a {} to make a block[name space] for the tmp var;
             int from = 0;
@@ -412,12 +503,30 @@ GWARF_result read_statement_list(statement *the_statement, var_list *the_var){
                 else if(return_value.value.type == NUMBER_value){
                     printf("var value = %f\n", return_value.value.value.double_value);
                 }
-                else{
+                else if(return_value.value.type == NULL_value){
+                    printf("operation value = None\n");
+                }
+                else if(return_value.value.type == STRING_value){
                     printf("var value = %s\n", return_value.value.value.string);
                 }
+                else{
+                    printf("var value = other\n");
+                }
             }
             break;
         }
+        case def:{
+            GWARF_result func_value;
+            func *func_tmp = malloc(sizeof(func));
+
+            func_tmp->done = the_statement->code.def.done;
+            func_tmp->parameter_list = the_statement->code.def.parameter_list;
+
+            func_value.value.type = FUNC_value;
+            func_value.value.value.func_value = func_tmp;
+
+            assigment_func(the_statement->code.def.name, func_value, the_var, 0);
+        }
         case break_cycle:
             return_value.u = cycle_break;
             return_value.value.type = INT_value;
@@ -526,6 +635,30 @@ GWARF_result read_statement_list(statement *the_statement, var_list *the_var){
                 return_value.value.value.int_value = int_tmp;
             }
             break;
+        case return_code:
+            return_value.u = code_return;
+            if(the_statement->code.return_code.times == NULL){
+                return_value.return_times = 0;
+            }
+            else{
+                GWARF_result tmp_result = traverse(the_statement->code.return_code.times, the_var, false);
+                int int_tmp;
+                if(tmp_result.value.type == INT_value){
+                    int_tmp = tmp_result.value.value.int_value;
+                }
+                else{
+                    int_tmp = (int)tmp_result.value.value.double_value;
+                }
+                return_value.return_times = int_tmp;
+            }
+            if(the_statement->code.return_code.value == NULL){  // return NULL
+                return_value.value.type = NULL_value;
+                return_value.value.value.double_value = 0;
+            }
+            else{
+                return_value.value = traverse(the_statement->code.return_code.value, the_var, false).value;
+            }
+            break;
         case rewent:
             return_value.u = code_rewent;  // rego but not now
             break;
@@ -629,9 +762,9 @@ GWARF_result if_func(if_list *if_base, var_list *the_var){  // read the statemen
             break;  // else not next and don't need rego
         }
         else{  // not else
-            GWARF_result condition;
-            condition = traverse(start->condition, the_var, false);
-            if(rego || (condition.value.value.double_value)){  // condition run success or rego(condition won't do) bug rewent can
+            bool condition;
+            condition = to_bool(traverse(start->condition, the_var, false).value);
+            if(rego || (condition)){  // condition run success or rego(condition won't do) bug rewent can
                 if_restart:
                 puts("----if----");
                 value = traverse(start->done, the_var, true);
@@ -697,21 +830,26 @@ GWARF_result if_func(if_list *if_base, var_list *the_var){  // read the statemen
 
 // -----------------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;
+    GWARF_result value;
+    printf("----address = %d----\n", the_var);
+    var *tmp = make_var();  // base_var
+    the_var = append_var_list(tmp, the_var);
+    printf("----new address = %d----\n", the_var);
+    bool 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){
+            condition = to_bool(traverse(the_statement->code.for_cycle.condition, the_var, false).value);
+            printf("for condition = %d\n", condition);
+            if(!condition){
                 break;
             }
         }
         restart_again: 
         puts("----for----");
-        value = traverse(the_statement->code.for_cycle.done, the_var, true);
+        value = traverse(the_statement->code.for_cycle.done, the_var, false);
 
         //break操作
         if((value.u == cycle_break) || (value.u == code_broken)){
@@ -754,6 +892,7 @@ GWARF_result for_func(statement *the_statement, var_list *the_var){  // read the
             }
         }
     }
+    the_var = free_var_list(the_var);  // free the new var
     return value;
 }
 
@@ -803,16 +942,21 @@ GWARF_result block_func(statement *the_statement, var_list *the_var){  // read t
 // -----------------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;
+    GWARF_result value;
+    printf("----address = %d----\n", the_var);
+    var *tmp = make_var();  // base_var
+    the_var = append_var_list(tmp, the_var);
+    printf("----new address = %d----\n", the_var);
+    bool condition;
     while (1){
-        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){
+        condition = to_bool(traverse(the_statement->code.while_cycle.condition, the_var, false).value);
+        printf("while condition = %d\n", condition);
+        if(!condition){
             break;
         }
         restart_again: 
         puts("----while----");
-        value = traverse(the_statement->code.while_cycle.done, the_var, true);
+        value = traverse(the_statement->code.while_cycle.done, the_var, false);
         puts("----stop while----");
 
         // break的操作
@@ -850,6 +994,7 @@ GWARF_result while_func(statement *the_statement, var_list *the_var){  // read t
             }
         }
     }
+    the_var = free_var_list(the_var);  // free the new var
     return value;
 }
 
@@ -931,10 +1076,60 @@ GWARF_result operation_func(statement *the_statement, var_list *the_var){  // re
     return value;
 }
 
+GWARF_result call_back(statement *the_statement, var_list *the_var){  // the func for add and call from read_statement_list
+    GWARF_result result, get = traverse(the_statement->code.call.func, the_var, false);
+    if(get.value.type != FUNC_value){
+        goto return_result;
+    }
+
+    func *func_ = get.value.value.func_value;
+    parameter *tmp_x = func_->parameter_list, *tmp_s = the_statement->code.call.parameter_list;
+    // tmp_x:形参,tmp_s:实参
+
+    printf("----address = %d----\n", the_var);
+    var *tmp = make_var();  // base_var
+    the_var = append_var_list(tmp, the_var);
+    printf("----new address = %d----\n", the_var);
+
+    if(tmp_x == NULL){
+        puts("No tmp_x");
+        goto no_tmp_x;  // 无形参
+    }
+    while(1){
+        GWARF_result tmp = traverse(tmp_s->u.value, the_var, false);
+        assigment_func(tmp_x->u.name, tmp, the_var, 0);
+        puts("set func var: tmp_x->u.name");
+        if ((tmp_x->next == NULL)||(tmp_s->next == NULL)){  // the last
+            break;
+        }
+        tmp_x = tmp_x->next;  // get the next to iter
+        tmp_s = tmp_s->next;
+    }
+    no_tmp_x: 
+    puts("run func");
+    result = traverse(func_->done, the_var, false);  // 执行func_value->done
+    the_var = free_var_list(the_var);  // free the new var
+    if(result.u == code_return){
+        if(result.return_times <= 0){
+            result.u = return_def;
+        }
+        else{
+           result.return_times -= 1; 
+        }
+    }
+    return_result: return result;
+}
+
 // ---------  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 == INT_value || left_result.value.type == BOOL_value) && (right_result.value.type == INT_value || right_result.value.type == BOOL_value)){  // all is INT
+    if(left_result.value.type == NULL_value){
+        return_value.value = right_result.value;  // NULL加法相当于0
+    }
+    else if(right_result.value.type == NULL_value){
+        return_value.value = left_result.value;  // NULL加法相当于0
+    }
+    else if((left_result.value.type == INT_value || left_result.value.type == BOOL_value) && (right_result.value.type == INT_value || right_result.value.type == BOOL_value)){  // all is INT
         return_value.u = return_def;
         return_value.value.type = INT_value;
         return_value.value.value.int_value = (int)(left_result.value.value.int_value + right_result.value.value.int_value);
@@ -969,7 +1164,13 @@ 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 sub
-    if((left_result.value.type == INT_value || left_result.value.type == BOOL_value) && (right_result.value.type == INT_value || right_result.value.type == BOOL_value)){  // all is INT
+    if(left_result.value.type == NULL_value){
+        return negative_func(right_result, the_var);  // NULL减法相当于0
+    }
+    else if(right_result.value.type == NULL_value){
+        return_value.value = left_result.value;  // NULL减法相当于0
+    }
+    else if((left_result.value.type == INT_value || left_result.value.type == BOOL_value) && (right_result.value.type == INT_value || right_result.value.type == BOOL_value)){  // all is INT
         return_value.u = return_def;
         return_value.value.type = INT_value;
         return_value.value.value.int_value = (int)(left_result.value.value.int_value - right_result.value.value.int_value);
@@ -995,11 +1196,27 @@ GWARF_result sub_func(GWARF_result left_result, GWARF_result right_result, var_l
 // ---------  negative
 GWARF_result negative_func(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 sub
-    if(right_result.value.type == INT_value || right_result.value.type == BOOL_value){  // all is INT
+    if(right_result.value.type == NULL_value){  // 返回bool true
+        return_value.u = return_def;
+        return_value.value.type = BOOL_value;
+        return_value.value.value.bool_value = true;
+    }
+    else if(right_result.value.type == INT_value){  // all is INT
         return_value.u = return_def;
         return_value.value.type = INT_value;
         return_value.value.value.int_value = (int)(-1 * right_result.value.value.int_value);
     }
+    else if(right_result.value.type == BOOL_value){
+        return_value.u = return_def;
+        return_value.value.type = BOOL_value;
+        if(right_result.value.value.bool_value)
+        {
+            return_value.value.value.bool_value = false;
+        }
+        else{
+            return_value.value.value.bool_value = true;
+        }
+    }
     else if(right_result.value.type == NUMBER_value){  // all is NUMBER
         return_value.u = return_def;
         return_value.value.type = NUMBER_value;
@@ -1022,7 +1239,13 @@ GWARF_result negative_func(GWARF_result right_result, var_list *the_var){  // th
 // ---------  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 mul
-    if((left_result.value.type == INT_value || left_result.value.type == BOOL_value) && (right_result.value.type == INT_value || right_result.value.type == BOOL_value)){  // all is INT
+    if(left_result.value.type == NULL_value){
+        return_value.value = right_result.value;  // NULL乘法相当于1
+    }
+    else if(right_result.value.type == NULL_value){
+        return_value.value = left_result.value;  // NULL乘法相当于1
+    }
+    else if((left_result.value.type == INT_value || left_result.value.type == BOOL_value) && (right_result.value.type == INT_value || right_result.value.type == BOOL_value)){  // all is INT
         return_value.u = return_def;
         return_value.value.type = INT_value;
         return_value.value.value.int_value = (int)(left_result.value.value.int_value * right_result.value.value.int_value);
@@ -1107,33 +1330,50 @@ 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 div
+    if(left_result.value.type == NULL_value){
+        left_result.value.type = INT_value;
+        left_result.value.value.int_value = 1;
+    }
+    else if(right_result.value.type == NULL_value){
+        return_value.value = left_result.value;  // NULL除发相当于1
+        goto return_result;
+    }
+    // 此处不是else if
     if((left_result.value.type == INT_value || left_result.value.type == BOOL_value) && (right_result.value.type == INT_value || right_result.value.type == BOOL_value)){  // all is INT
         return_value.u = return_def;
-        return_value.value.type = INT_value;
-        return_value.value.value.int_value = (int)(left_result.value.value.int_value / right_result.value.value.int_value);
+        return_value.value.type = NUMBER_value;  // 除 无int
+        return_value.value.value.double_value = ((double)left_result.value.value.int_value / (double)right_result.value.value.int_value);
     }
     else 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 = (double)(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);
     }
     else if((left_result.value.type == INT_value || left_result.value.type == BOOL_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 = (double)(left_result.value.value.int_value / right_result.value.value.double_value);
+        return_value.value.value.double_value = ((double)left_result.value.value.int_value / right_result.value.value.double_value);
     }
     else if((left_result.value.type == NUMBER_value) && (right_result.value.type == INT_value || right_result.value.type == BOOL_value)){  // all is NUMBER
         return_value.u = return_def;
         return_value.value.type = NUMBER_value;
-        return_value.value.value.double_value = (double)(left_result.value.value.double_value / right_result.value.value.int_value);
+        return_value.value.value.double_value = (left_result.value.value.double_value / (double)right_result.value.value.int_value);
     }
-    return return_value;
+    return_result: return return_value;
 }
 
 // ---------  POW
 GWARF_result pow_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 div
-    if((left_result.value.type == INT_value || left_result.value.type == BOOL_value) && (right_result.value.type == INT_value || right_result.value.type == BOOL_value)){  // all is INT
+    if(left_result.value.type == NULL_value){
+        return_value.u = return_def;
+        return_value.value.type = INT_value;
+        return_value.value.value.int_value = 1;
+    }
+    else if(right_result.value.type == NULL_value){
+        return_value.value = left_result.value;  // NULL乘方相当于1
+    }
+    else if((left_result.value.type == INT_value || left_result.value.type == BOOL_value) && (right_result.value.type == INT_value || right_result.value.type == BOOL_value)){  // all is INT
         return_value.u = return_def;
         return_value.value.type = INT_value;
         return_value.value.value.int_value = (int)pow((double)left_result.value.value.int_value, (double)right_result.value.value.int_value);
@@ -1159,7 +1399,15 @@ GWARF_result pow_func(GWARF_result left_result, GWARF_result right_result, var_l
 // ---------  LOG
 GWARF_result log_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 div
-    if((left_result.value.type == INT_value || left_result.value.type == BOOL_value) && (right_result.value.type == INT_value || right_result.value.type == BOOL_value)){  // all is INT
+    if(left_result.value.type == NULL_value){
+        return_value.value = left_result.value;  // 返回NULL
+    }
+    else if(right_result.value.type == NULL_value){
+        return_value.u = return_def;
+        return_value.value.type = INT_value;
+        return_value.value.value.int_value = 0;
+    }
+    else if((left_result.value.type == INT_value || left_result.value.type == BOOL_value) && (right_result.value.type == INT_value || right_result.value.type == BOOL_value)){  // all is INT
         return_value.u = return_def;
         return_value.value.type = INT_value;
         return_value.value.value.int_value = (int)log_((double)left_result.value.value.int_value, (double)right_result.value.value.int_value);
@@ -1185,7 +1433,15 @@ GWARF_result log_func(GWARF_result left_result, GWARF_result right_result, var_l
 // ---------  SQRT
 GWARF_result sqrt_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 div
-    if((left_result.value.type == INT_value || left_result.value.type == BOOL_value) && (right_result.value.type == INT_value || right_result.value.type == BOOL_value)){  // all is INT
+    if(left_result.value.type == NULL_value){
+        return_value.u = return_def;
+        return_value.value.type = INT_value;
+        return_value.value.value.int_value = 0;
+    }
+    else if(right_result.value.type == NULL_value){
+        return_value.value = right_result.value;  // 返回NULL
+    }
+    else if((left_result.value.type == INT_value || left_result.value.type == BOOL_value) && (right_result.value.type == INT_value || right_result.value.type == BOOL_value)){  // all is INT
         return_value.u = return_def;
         return_value.value.type = INT_value;
         return_value.value.value.int_value = (int)sqrt_((double)left_result.value.value.int_value, (double)right_result.value.value.int_value);
@@ -1217,9 +1473,12 @@ GWARF_result assigment_func(char *left, GWARF_result right_result, var_list *the
 // ---------  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;
-    int return_bool = 1;
+    int return_bool = false;
     return_value.u = return_def;
-    if((left_result.value.type == INT_value || left_result.value.type == BOOL_value) && (right_result.value.type == INT_value || right_result.value.type == BOOL_value)){  // all is INT
+    if(left_result.value.type == NULL_value || right_result.value.type == NULL_value){
+        return_bool = false;  // 无论什么都返回false NULL != NULL
+    }
+    else if((left_result.value.type == INT_value || left_result.value.type == BOOL_value) && (right_result.value.type == INT_value || right_result.value.type == BOOL_value)){  // all is INT
         return_value.value.type = INT_value;
         if ((left_result.value.value.int_value == right_result.value.value.int_value) && (type == 0)){  // 如果相等
             return_bool = true;  // 返回1 否则(默认)为0
@@ -1337,7 +1596,13 @@ GWARF_result traverse(statement *the_statement, var_list *the_var, bool new){  /
             break;
             }
         if((result2.u == cycle_continue) || (result2.u == code_continued) || (result2.u == cycle_restart) || (result2.u == code_restarted)){
-            printf("----continue/continued or restart/restarted----[%d]", result2.u);
+            printf("----continue/continued or restart/restarted----[%d]\n", result2.u);
+            result = result2;
+            break;
+        }
+
+        if(result2.u == code_return){
+            printf("----return----\n");
             result = result2;
             break;
         }

+ 11 - 0
paser/gwarf_lex.l

@@ -68,6 +68,17 @@
 <INITIAL>"#" {BEGIN COMMENT;}
 <INITIAL>' {BEGIN STRING_TEXT;}
 <INITIAL>\" {BEGIN STRING_TEXT;}
+
+<INITIAL>"true" {return TRUE;}
+<INITIAL>"false" {return FALSE;}
+<INITIAL>"True" {return TRUE;}
+<INITIAL>"False" {return FALSE;}
+<INITIAL>"None" {return NULL_token;}
+<INITIAL>"NULL" {return NULL_token;}
+<INITIAL>"null" {return NULL_token;}
+<INITIAL>"def" {return DEF;}
+<INITIAL>"return" {return RETURN;}
+
 <INITIAL>[1-9][0-9]*\.[0-9]+ {
     yylval.double_value = atof(yytext);
     return NUMBER;

+ 156 - 13
paser/gwarf_yacc.y

@@ -13,12 +13,15 @@
     char *string_value;
     struct statement *statement_value;
     struct if_list *if_list_base;
+    struct parameter *parameter_list;
 }
 %token <double_value> NUMBER INT
 %token <string_value> STRING VAR
-%token ADD SUB DIV MUL EQ LESS MORE RB LB RP LP WHILE POW LOG SQRT EQUAL MOREEQ LESSEQ NOTEQ BREAK IF ELSE ELIF BROKEN CONTINUE CONTINUED RESTART RESTARTED REGO REWENT RI LI DEFAULT FOR COMMA GLOBAL NONLOCAL INDENTA STOPN STOPF BLOCK
+%token ADD SUB DIV MUL EQ LESS MORE RB LB RP LP WHILE POW LOG SQRT EQUAL MOREEQ LESSEQ NOTEQ BREAK IF ELSE ELIF BROKEN CONTINUE CONTINUED RESTART RESTARTED REGO REWENT RI LI DEFAULT FOR COMMA GLOBAL NONLOCAL INDENTA STOPN STOPF BLOCK FALSE TRUE
+%token NULL_token DEF RETURN
 %type <statement_value> base_value base_var_token base_var_ element second_number first_number zero_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 for_exp for_block global_token nonlocal_token block_exp block_block
+%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 block_exp block_block call_number def_block def_exp return_exp return_token
+%type <parameter_list> formal_parameter arguments
 %type <string_value> base_string
 %type <if_list_base> elif_exp
 %%
@@ -41,13 +44,6 @@ command_list
             append_statement(tmp, $2);
         }
     }
-    | while_block
-    {   
-        if($1 != NULL){
-            statement *tmp = find_statement_list(0, statement_base);
-            append_statement(tmp, $1);
-        }
-    }
     ;
 
 command
@@ -119,6 +115,14 @@ command
     {
         $$ = $1;
     }
+    | def_block stop_token
+    {
+        $$ = $1;
+    }
+    | return_exp stop_token
+    {
+        $$ = $1;
+    }
     ;
 
 top_exp
@@ -240,8 +244,8 @@ first_number
     ;
 
 zero_number
-    : element
-    | zero_number POW element
+    : call_number
+    | zero_number POW call_number
     {
         statement *code_tmp =  make_statement();
         code_tmp->type = operation;
@@ -250,7 +254,7 @@ zero_number
         code_tmp->code.operation.right_exp = $3;
         $$ = code_tmp;
     }
-    | zero_number LOG element
+    | zero_number LOG call_number
     {
         statement *code_tmp =  make_statement();
         code_tmp->type = operation;
@@ -259,7 +263,7 @@ zero_number
         code_tmp->code.operation.right_exp = $3;
         $$ = code_tmp;
     }
-    | zero_number SQRT element
+    | zero_number SQRT call_number
     {
         statement *code_tmp =  make_statement();
         code_tmp->type = operation;
@@ -270,6 +274,26 @@ zero_number
     }
     ;
 
+call_number
+    : element
+    | element LB RB
+    {
+        statement *code_tmp =  make_statement();
+        code_tmp->type = call;
+        code_tmp->code.call.func = $1;
+        code_tmp->code.call.parameter_list = NULL;
+        $$ = code_tmp;
+    }
+    | element LB arguments RB
+    {
+        statement *code_tmp =  make_statement();
+        code_tmp->type = call;
+        code_tmp->code.call.func = $1;
+        code_tmp->code.call.parameter_list = $3;
+        $$ = code_tmp;
+    }
+    ;
+
 element
     : base_value
     | base_var_
@@ -313,6 +337,30 @@ base_value
         code_tmp->code.base_value.value.value.string = $1;
         $$ = code_tmp;
     }
+    | TRUE
+    {
+        statement *code_tmp =  make_statement();
+        code_tmp->type = base_value;
+        code_tmp->code.base_value.value.type = BOOL_value;
+        code_tmp->code.base_value.value.value.bool_value = true;
+        $$ = code_tmp;
+    }
+    | FALSE
+    {
+        statement *code_tmp =  make_statement();
+        code_tmp->type = base_value;
+        code_tmp->code.base_value.value.type = BOOL_value;
+        code_tmp->code.base_value.value.value.bool_value = false;
+        $$ = code_tmp;
+    }
+    | NULL_token
+    {
+        statement *code_tmp =  make_statement();
+        code_tmp->type = base_value;
+        code_tmp->code.base_value.value.type = NULL_value;
+        code_tmp->code.base_value.value.value.int_value = 0;
+        $$ = code_tmp;
+    }
     ;
 
 base_var_
@@ -571,10 +619,105 @@ while_exp
     }
     ;
 
+def_block
+    : def_exp block
+    {
+        statement_base = free_statement_list(statement_base);  // new statement_base (FILO)
+    }
+    ;
+
+def_exp
+    : DEF  base_var_ LB RB
+    {   
+        //无参数方法
+        statement *def_tmp =  make_statement();
+        def_tmp->type = def;
+
+        def_tmp->code.def.name = malloc(sizeof($2->code.base_var.var_name));
+        char *name_tmp = def_tmp->code.def.name;
+        strcpy(name_tmp, $2->code.base_var.var_name);
+
+        def_tmp->code.def.parameter_list = NULL;
+        def_tmp->code.def.done = make_statement();
+        statement_base = append_statement_list(def_tmp->code.def.done, statement_base);  // new statement_base (FILO)
+
+        free($2->code.base_var.var_name);
+        free($2);
+        $$ = def_tmp;
+    }
+    | DEF  base_var_ LB formal_parameter RB
+    {   
+        statement *def_tmp =  make_statement();
+        def_tmp->type = def;
+
+        def_tmp->code.def.name = malloc(sizeof($2->code.base_var.var_name));
+        char *name_tmp = def_tmp->code.def.name;
+        strcpy(name_tmp, $2->code.base_var.var_name);
+
+        def_tmp->code.def.parameter_list = $4;
+        def_tmp->code.def.done = make_statement();
+        statement_base = append_statement_list(def_tmp->code.def.done, statement_base);  // new statement_base (FILO)
+
+        free($2->code.base_var.var_name);
+        free($2);
+        $$ = def_tmp;
+    }
+    ;
+
+formal_parameter
+    : base_var_
+    {
+        $$ = make_parameter_name($1->code.base_var.var_name);
+        free($1->code.base_var.var_name);
+        free($1);
+    }
+    | formal_parameter COMMA base_var_
+    {
+        append_parameter_name($3->code.base_var.var_name, $1);
+        $$ = $1;
+    }
+
+arguments
+    : top_exp
+    {
+        $$ = make_parameter_value($1);
+    }
+    | arguments COMMA top_exp
+    {
+        append_parameter_value($3, $1);
+        $$ = $1;
+    }
+
 block
     : LP command_list RP
     ;
 
+return_exp
+    : return_token
+    | return_token top_exp
+    {
+        $1->code.return_code.value = $2;
+        $$ = $1;
+    }
+    | return_token top_exp element
+    {
+        $1->code.return_code.value = $2;
+        $1->code.return_code.times = $3;
+        $$ = $1;
+    }
+    ;
+
+return_token
+    : RETURN
+    {
+        statement *code_tmp =  make_statement();
+        code_tmp->type = return_code;
+        code_tmp->code.return_code.times = NULL;
+        code_tmp->code.return_code.value = NULL;
+        $$ = code_tmp;
+    }
+    ;
+
 restarted_exp
     : restarted_token
     | restarted_token element

+ 222 - 157
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 61
-#define YY_END_OF_BUFFER 62
+#define YY_NUM_RULES 70
+#define YY_END_OF_BUFFER 71
 /* This struct is not used in this scanner,
    but its presence is necessary. */
 struct yy_trans_info
@@ -360,25 +360,28 @@ struct yy_trans_info
 	flex_int32_t yy_verify;
 	flex_int32_t yy_nxt;
 	};
-static const flex_int16_t yy_accept[159] =
+static const flex_int16_t yy_accept[190] =
     {   0,
-        0,    0,    0,    0,    0,    0,    0,    0,   62,   53,
-       50,   52,   53,   46,   44,   45,   22,   23,   40,   38,
-       17,   39,   41,   48,   48,   51,   30,   32,   29,   49,
-       42,   43,   34,   49,   49,   49,   49,   49,   49,   49,
-       49,   49,   49,   49,   49,   24,   25,   35,   52,   56,
-       54,   55,   60,   59,   58,   57,   61,    0,    0,    0,
-       24,    0,   28,   33,    0,   48,   27,   31,   26,   49,
-       49,   49,   49,   49,   49,   49,   49,    5,   49,   49,
-       49,   49,   49,   24,    0,    0,    0,    0,   47,   49,
-       49,   49,   49,   49,   49,   49,   16,   49,   36,   49,
-
-       49,   49,   49,   49,   49,    0,    0,    0,    0,    3,
-       49,   49,   49,   49,   49,    6,    7,   49,   49,   14,
-       49,   49,   37,   49,    1,    2,    6,    7,   21,    8,
-       49,   49,   49,    0,   49,   49,   49,   49,    4,    2,
-        9,   49,   49,    7,   19,   49,   49,   15,   49,   18,
-       49,   11,   10,   20,   49,   13,   12,    0
+        0,    0,    0,    0,    0,    0,    0,    0,   71,   62,
+       59,   61,   62,   46,   44,   45,   22,   23,   40,   38,
+       17,   39,   41,   57,   57,   60,   30,   32,   29,   58,
+       58,   58,   58,   42,   43,   34,   58,   58,   58,   58,
+       58,   58,   58,   58,   58,   58,   58,   58,   58,   24,
+       25,   35,   61,   65,   63,   64,   69,   68,   67,   66,
+       70,    0,    0,    0,   24,    0,   28,   33,    0,   57,
+       27,   31,   26,   58,   58,   58,   58,   58,   58,   58,
+       58,   58,   58,   58,   58,   58,    5,   58,   58,   58,
+       58,   58,   58,   58,   24,    0,    0,    0,    0,   56,
+
+       58,   58,   58,   58,   58,   58,   58,   58,   54,   58,
+       58,   58,   16,   58,   36,   58,   58,   58,   58,   58,
+       58,   58,   58,   58,    0,    0,    0,    0,    3,   58,
+       52,   51,   49,   58,   58,   58,   58,   58,    6,    7,
+       58,   58,   58,   53,   14,   58,   58,   58,   37,   47,
+       58,    1,    2,    6,    7,   50,   21,    8,   58,   58,
+       58,    0,   48,   58,   58,   58,   58,   58,    4,    2,
+        9,   58,   58,    7,   19,   58,   58,   55,   15,   58,
+       18,   58,   11,   10,   20,   58,   13,   12,    0
     } ;
 
 static const YY_CHAR yy_ec[256] =
@@ -389,14 +392,14 @@ static const YY_CHAR yy_ec[256] =
         1,    3,    4,    5,    6,    1,    1,    1,    7,    8,
         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,   39,   40,   41,   42,   43,   22,   44,   22,
-       22,   22,   45,    1,   46,   47,    1,    1,    1,    1,
+       20,   21,    1,    1,   22,   22,   22,   22,   22,   23,
+       22,   22,   22,   22,   22,   24,   22,   25,   22,   22,
+       22,   22,   22,   26,   27,   22,   22,   22,   22,   22,
+       28,    1,   29,   30,   22,    1,   31,   32,   33,   34,
+
+       35,   36,   37,   38,   39,   22,   40,   41,   22,   42,
+       43,   22,   44,   45,   46,   47,   48,   22,   49,   22,
+       22,   22,   50,    1,   51,   52,    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,
@@ -413,115 +416,132 @@ static const YY_CHAR yy_ec[256] =
         1,    1,    1,    1,    1
     } ;
 
-static const YY_CHAR yy_meta[48] =
+static const YY_CHAR yy_meta[53] =
     {   0,
         1,    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,
+        1,    2,    2,    2,    2,    2,    2,    1,    1,    1,
         2,    2,    2,    2,    2,    2,    2,    2,    2,    2,
-        2,    2,    2,    2,    1,    1,    1
+        2,    2,    2,    2,    2,    2,    2,    2,    2,    1,
+        1,    1
     } ;
 
-static const flex_int16_t yy_base[163] =
+static const flex_int16_t yy_base[194] =
     {   0,
-        0,  177,   46,   47,   49,   53,    0,    0,  179,  181,
-       59,  175,  157,  181,  181,  181,  181,  181,  166,  181,
-      181,  181,  181,  181,   49,  181,  155,  154,  153,    0,
-      181,  181,  181,   28,  134,  141,  134,  131,  132,  136,
-      128,  127,  134,  124,  129,  159,  181,  181,  157,  181,
-      181,  181,  181,  181,  181,  181,  181,   67,  156,  122,
-      155,  153,  181,  181,   55,   59,  181,  181,  181,    0,
-      117,   29,  117,  122,   16,  112,  113,    0,  118,  112,
-       42,  108,  113,  144,  142,  141,   43,  140,   62,  114,
-      115,  105,   97,  112,  106,  106,    0,  108,    0,   98,
-
-       95,   90,  101,   88,   93,  125,  124,   95,   95,  181,
-       89,   88,   92,   87,   77,    0,  111,   85,   72,    0,
-       83,   71,    0,   77,  181,  104,  181,   97,    0,    0,
-       66,   65,   65,   91,   63,   70,   56,   53,    0,   92,
-        0,   50,   50,  181,    0,   65,   48,    0,   58,    0,
-       51,   55,   53,    0,   52,    0,    0,  181,  112,  114,
-      116,   78
+        0,  209,   51,   52,   54,   58,    0,    0,  211,  213,
+       64,  207,  189,  213,  213,  213,  213,  213,  198,  213,
+      213,  213,  213,  213,   54,  213,  187,  186,  185,    0,
+      173,   35,  158,  213,  213,  213,   28,  159,  166,  159,
+       33,  158,  162,  154,   29,  161,  151,  149,  155,  190,
+      213,  213,  188,  213,  213,  213,  213,  213,  213,  213,
+      213,   72,  187,  148,  186,  184,  213,  213,   63,   67,
+      213,  213,  213,    0,  145,  161,  142,  135,  139,   47,
+      139,  144,   46,  138,  133,  134,    0,  139,  133,  133,
+       49,  128,  124,  132,  168,  166,  165,   48,  164,   72,
+
+      120,  141,  129,  128,  129,  130,  120,  112,  127,  121,
+      121,  109,    0,  122,    0,  112,  111,  108,  103,  101,
+      113,  100,  111,  104,  141,  140,  106,  106,  213,  105,
+        0,    0,    0,   99,   98,  102,   97,   87,    0,  126,
+       98,  101,   88,    0,    0,   99,   84,   79,    0,    0,
+       85,  213,  117,  213,  110,    0,    0,    0,   75,   74,
+       74,  104,    0,   71,   78,   65,   67,   61,    0,  104,
+        0,   57,   57,  213,    0,   72,   55,    0,    0,   66,
+        0,   59,   62,   59,    0,   57,    0,    0,  213,  122,
+      124,  126,   53
+
     } ;
 
-static const flex_int16_t yy_def[163] =
+static const flex_int16_t yy_def[194] =
     {   0,
-      158,    1,  159,  159,  160,  160,  161,  161,  158,  158,
-      158,  158,  158,  158,  158,  158,  158,  158,  158,  158,
-      158,  158,  158,  158,  158,  158,  158,  158,  158,  162,
-      158,  158,  158,  162,  162,  162,  162,  162,  162,  162,
-      162,  162,  162,  162,  162,  158,  158,  158,  158,  158,
-      158,  158,  158,  158,  158,  158,  158,  158,  158,  158,
-      158,  158,  158,  158,  158,  158,  158,  158,  158,  162,
-      162,  162,  162,  162,  162,  162,  162,  162,  162,  162,
-      162,  162,  162,  158,  158,  158,  158,  158,  158,  162,
-      162,  162,  162,  162,  162,  162,  162,  162,  162,  162,
-
-      162,  162,  162,  162,  162,  158,  158,  158,  158,  158,
-      162,  162,  162,  162,  162,  162,  162,  162,  162,  162,
-      162,  162,  162,  162,  158,  158,  158,  158,  162,  162,
-      162,  162,  162,  158,  162,  162,  162,  162,  162,  158,
-      162,  162,  162,  158,  162,  162,  162,  162,  162,  162,
-      162,  162,  162,  162,  162,  162,  162,    0,  158,  158,
-      158,  158
+      189,    1,  190,  190,  191,  191,  192,  192,  189,  189,
+      189,  189,  189,  189,  189,  189,  189,  189,  189,  189,
+      189,  189,  189,  189,  189,  189,  189,  189,  189,  193,
+      193,  193,  193,  189,  189,  189,  193,  193,  193,  193,
+      193,  193,  193,  193,  193,  193,  193,  193,  193,  189,
+      189,  189,  189,  189,  189,  189,  189,  189,  189,  189,
+      189,  189,  189,  189,  189,  189,  189,  189,  189,  189,
+      189,  189,  189,  193,  193,  193,  193,  193,  193,  193,
+      193,  193,  193,  193,  193,  193,  193,  193,  193,  193,
+      193,  193,  193,  193,  189,  189,  189,  189,  189,  189,
+
+      193,  193,  193,  193,  193,  193,  193,  193,  193,  193,
+      193,  193,  193,  193,  193,  193,  193,  193,  193,  193,
+      193,  193,  193,  193,  189,  189,  189,  189,  189,  193,
+      193,  193,  193,  193,  193,  193,  193,  193,  193,  193,
+      193,  193,  193,  193,  193,  193,  193,  193,  193,  193,
+      193,  189,  189,  189,  189,  193,  193,  193,  193,  193,
+      193,  189,  193,  193,  193,  193,  193,  193,  193,  189,
+      193,  193,  193,  189,  193,  193,  193,  193,  193,  193,
+      193,  193,  193,  193,  193,  193,  193,  193,    0,  189,
+      189,  189,  189
+
     } ;
 
-static const flex_int16_t yy_nxt[229] =
+static const flex_int16_t yy_nxt[266] =
     {   0,
        10,   11,   12,   13,   14,   15,   16,   17,   18,   19,
        20,   21,   22,   10,   23,   24,   25,   26,   27,   28,
-       29,   30,   31,   32,   33,   30,   34,   35,   36,   37,
-       38,   39,   30,   40,   30,   41,   42,   30,   30,   43,
-       44,   30,   30,   45,   46,   47,   48,   51,   51,   95,
-       54,   52,   52,   55,   54,   56,   96,   55,   91,   56,
-       58,   59,   65,   71,   66,   66,   92,   72,   58,   59,
-       89,   89,   65,  101,   66,   66,  108,   89,   89,   70,
-      157,  156,  102,  109,  155,  103,  154,  153,   60,  152,
-      151,  150,  149,  140,  148,  147,   60,  146,  145,  144,
-
-      143,  142,  141,   61,  134,  140,  139,  138,  137,  136,
-      135,   61,   50,   50,   53,   53,   57,   57,  134,  133,
-      132,  131,  130,  129,  128,  127,  126,  125,  124,  123,
-      122,  121,  120,  119,  118,  117,  116,  115,  114,  113,
-      112,  111,  110,  107,  106,   84,  105,  104,  100,   99,
-       98,   97,   94,   93,   90,   88,   84,   87,   86,   85,
-       84,   83,   82,   81,   80,   79,   78,   77,   76,   75,
-       74,   73,   69,   68,   67,   64,   63,   62,  158,   49,
-        9,  158,  158,  158,  158,  158,  158,  158,  158,  158,
-      158,  158,  158,  158,  158,  158,  158,  158,  158,  158,
-
-      158,  158,  158,  158,  158,  158,  158,  158,  158,  158,
-      158,  158,  158,  158,  158,  158,  158,  158,  158,  158,
-      158,  158,  158,  158,  158,  158,  158,  158
+       29,   30,   31,   30,   32,   33,   30,   34,   35,   36,
+       30,   37,   38,   39,   40,   41,   42,   30,   43,   30,
+       44,   45,   30,   30,   46,   47,   48,   30,   49,   50,
+       51,   52,   55,   55,   74,   58,   56,   56,   59,   58,
+       60,   76,   59,   84,   60,   62,   63,   69,   79,   70,
+       70,   89,   80,   62,   63,   85,   90,   77,  100,  100,
+       69,  106,   70,   70,  110,  118,  127,  100,  100,  107,
+      188,  111,  187,  128,  119,  120,  186,  121,   64,  185,
+
+      184,  183,  182,  181,  180,  170,   64,  179,  178,  177,
+      176,  175,  174,   65,  173,  172,  171,  162,  170,  169,
+      168,   65,   54,   54,   57,   57,   61,   61,  167,  166,
+      165,  164,  163,  162,  161,  160,  159,  158,  157,  156,
+      155,  154,  153,  152,  151,  150,  149,  148,  147,  146,
+      145,  144,  143,  142,  141,  140,  139,  138,  137,  136,
+      135,  134,  133,  132,  131,  130,  129,  126,  125,   95,
+      124,  123,  122,  117,  116,  115,  114,  113,  112,  109,
+      108,  105,  104,  103,  102,  101,   99,   95,   98,   97,
+       96,   95,   94,   93,   92,   91,   88,   87,   86,   83,
+
+       82,   81,   78,   75,   73,   72,   71,   68,   67,   66,
+      189,   53,    9,  189,  189,  189,  189,  189,  189,  189,
+      189,  189,  189,  189,  189,  189,  189,  189,  189,  189,
+      189,  189,  189,  189,  189,  189,  189,  189,  189,  189,
+      189,  189,  189,  189,  189,  189,  189,  189,  189,  189,
+      189,  189,  189,  189,  189,  189,  189,  189,  189,  189,
+      189,  189,  189,  189,  189
     } ;
 
-static const flex_int16_t yy_chk[229] =
+static const flex_int16_t yy_chk[266] =
     {   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,    1,    3,    4,   75,
-        5,    3,    4,    5,    6,    5,   75,    6,   72,    6,
-       11,   11,   25,   34,   25,   25,   72,   34,   58,   58,
-       65,   65,   66,   81,   66,   66,   87,   89,   89,  162,
-      155,  153,   81,   87,  152,   81,  151,  149,   11,  147,
-      146,  143,  142,  140,  138,  137,   58,  136,  135,  134,
-
-      133,  132,  131,   11,  128,  126,  124,  122,  121,  119,
-      118,   58,  159,  159,  160,  160,  161,  161,  117,  115,
-      114,  113,  112,  111,  109,  108,  107,  106,  105,  104,
-      103,  102,  101,  100,   98,   96,   95,   94,   93,   92,
-       91,   90,   88,   86,   85,   84,   83,   82,   80,   79,
-       77,   76,   74,   73,   71,   62,   61,   60,   59,   49,
-       46,   45,   44,   43,   42,   41,   40,   39,   38,   37,
-       36,   35,   29,   28,   27,   19,   13,   12,    9,    2,
-      158,  158,  158,  158,  158,  158,  158,  158,  158,  158,
-      158,  158,  158,  158,  158,  158,  158,  158,  158,  158,
-
-      158,  158,  158,  158,  158,  158,  158,  158,  158,  158,
-      158,  158,  158,  158,  158,  158,  158,  158,  158,  158,
-      158,  158,  158,  158,  158,  158,  158,  158
+        1,    1,    1,    1,    1,    1,    1,    1,    1,    1,
+        1,    1,    3,    4,  193,    5,    3,    4,    5,    6,
+        5,   32,    6,   41,    6,   11,   11,   25,   37,   25,
+       25,   45,   37,   62,   62,   41,   45,   32,   69,   69,
+       70,   80,   70,   70,   83,   91,   98,  100,  100,   80,
+      186,   83,  184,   98,   91,   91,  183,   91,   11,  182,
+
+      180,  177,  176,  173,  172,  170,   62,  168,  167,  166,
+      165,  164,  162,   11,  161,  160,  159,  155,  153,  151,
+      148,   62,  190,  190,  191,  191,  192,  192,  147,  146,
+      143,  142,  141,  140,  138,  137,  136,  135,  134,  130,
+      128,  127,  126,  125,  124,  123,  122,  121,  120,  119,
+      118,  117,  116,  114,  112,  111,  110,  109,  108,  107,
+      106,  105,  104,  103,  102,  101,   99,   97,   96,   95,
+       94,   93,   92,   90,   89,   88,   86,   85,   84,   82,
+       81,   79,   78,   77,   76,   75,   66,   65,   64,   63,
+       53,   50,   49,   48,   47,   46,   44,   43,   42,   40,
+
+       39,   38,   33,   31,   29,   28,   27,   19,   13,   12,
+        9,    2,  189,  189,  189,  189,  189,  189,  189,  189,
+      189,  189,  189,  189,  189,  189,  189,  189,  189,  189,
+      189,  189,  189,  189,  189,  189,  189,  189,  189,  189,
+      189,  189,  189,  189,  189,  189,  189,  189,  189,  189,
+      189,  189,  189,  189,  189,  189,  189,  189,  189,  189,
+      189,  189,  189,  189,  189
     } ;
 
 static yy_state_type yy_last_accepting_state;
@@ -549,9 +569,9 @@ char *yytext;
     int flat = 0;
     int is_last = 0;  // 是否\n
     int is_stop = 0;  // 针对}需要返回一个}的同时返回一个STOP
-#line 552 "lex.yy.c"
+#line 572 "lex.yy.c"
 
-#line 554 "lex.yy.c"
+#line 574 "lex.yy.c"
 
 #define INITIAL 0
 #define COMMENT 1
@@ -776,7 +796,7 @@ YY_DECL
 	{
 #line 13 "gwarf_lex.l"
 
-#line 779 "lex.yy.c"
+#line 799 "lex.yy.c"
 
 	while ( /*CONSTCOND*/1 )		/* loops until end-of-file is reached */
 		{
@@ -804,13 +824,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 >= 159 )
+				if ( yy_current_state >= 190 )
 					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] != 181 );
+		while ( yy_base[yy_current_state] != 213 );
 
 yy_find_action:
 		yy_act = yy_accept[yy_current_state];
@@ -1078,98 +1098,143 @@ YY_RULE_SETUP
 	YY_BREAK
 case 47:
 YY_RULE_SETUP
-#line 71 "gwarf_lex.l"
+#line 72 "gwarf_lex.l"
+{return TRUE;}
+	YY_BREAK
+case 48:
+YY_RULE_SETUP
+#line 73 "gwarf_lex.l"
+{return FALSE;}
+	YY_BREAK
+case 49:
+YY_RULE_SETUP
+#line 74 "gwarf_lex.l"
+{return TRUE;}
+	YY_BREAK
+case 50:
+YY_RULE_SETUP
+#line 75 "gwarf_lex.l"
+{return FALSE;}
+	YY_BREAK
+case 51:
+YY_RULE_SETUP
+#line 76 "gwarf_lex.l"
+{return NULL_token;}
+	YY_BREAK
+case 52:
+YY_RULE_SETUP
+#line 77 "gwarf_lex.l"
+{return NULL_token;}
+	YY_BREAK
+case 53:
+YY_RULE_SETUP
+#line 78 "gwarf_lex.l"
+{return NULL_token;}
+	YY_BREAK
+case 54:
+YY_RULE_SETUP
+#line 79 "gwarf_lex.l"
+{return DEF;}
+	YY_BREAK
+case 55:
+YY_RULE_SETUP
+#line 80 "gwarf_lex.l"
+{return RETURN;}
+	YY_BREAK
+case 56:
+YY_RULE_SETUP
+#line 82 "gwarf_lex.l"
 {
     yylval.double_value = atof(yytext);
     return NUMBER;
     }
 	YY_BREAK
-case 48:
+case 57:
 YY_RULE_SETUP
-#line 75 "gwarf_lex.l"
+#line 86 "gwarf_lex.l"
 {
     yylval.double_value = atof(yytext);
     return INT;
     }
 	YY_BREAK
-case 49:
+case 58:
 YY_RULE_SETUP
-#line 79 "gwarf_lex.l"
+#line 90 "gwarf_lex.l"
 {
     yylval.string_value = yytext;
     return VAR;
     }
 	YY_BREAK
-case 50:
-/* rule 50 can match eol */
+case 59:
+/* rule 59 can match eol */
 YY_RULE_SETUP
-#line 83 "gwarf_lex.l"
+#line 94 "gwarf_lex.l"
 {return STOPN;}
 	YY_BREAK
-case 51:
+case 60:
 YY_RULE_SETUP
-#line 84 "gwarf_lex.l"
+#line 95 "gwarf_lex.l"
 {return STOPF;}
 	YY_BREAK
-case 52:
+case 61:
 YY_RULE_SETUP
-#line 85 "gwarf_lex.l"
+#line 96 "gwarf_lex.l"
 ;
 	YY_BREAK
-case 53:
+case 62:
 YY_RULE_SETUP
-#line 86 "gwarf_lex.l"
+#line 97 "gwarf_lex.l"
 {printf("other text = [%s];\n", yytext);}
 	YY_BREAK
-case 54:
-/* rule 54 can match eol */
+case 63:
+/* rule 63 can match eol */
 YY_RULE_SETUP
-#line 88 "gwarf_lex.l"
+#line 99 "gwarf_lex.l"
 {BEGIN INITIAL;}
 	YY_BREAK
-case 55:
+case 64:
 YY_RULE_SETUP
-#line 89 "gwarf_lex.l"
+#line 100 "gwarf_lex.l"
 {BEGIN INITIAL;}
 	YY_BREAK
-case 56:
+case 65:
 YY_RULE_SETUP
-#line 90 "gwarf_lex.l"
+#line 101 "gwarf_lex.l"
 ;
 	YY_BREAK
-case 57:
+case 66:
 YY_RULE_SETUP
-#line 92 "gwarf_lex.l"
+#line 103 "gwarf_lex.l"
 {BEGIN INITIAL;}
 	YY_BREAK
-case 58:
+case 67:
 YY_RULE_SETUP
-#line 93 "gwarf_lex.l"
+#line 104 "gwarf_lex.l"
 {BEGIN INITIAL;}
 	YY_BREAK
-case 59:
-/* rule 59 can match eol */
+case 68:
+/* rule 68 can match eol */
 YY_RULE_SETUP
-#line 94 "gwarf_lex.l"
+#line 105 "gwarf_lex.l"
 {
     yylval.string_value = yytext;
     return STRING;
     }
 	YY_BREAK
-case 60:
+case 69:
 YY_RULE_SETUP
-#line 98 "gwarf_lex.l"
+#line 109 "gwarf_lex.l"
 {
     yylval.string_value = yytext;
     return STRING;
     }
 	YY_BREAK
-case 61:
+case 70:
 YY_RULE_SETUP
-#line 102 "gwarf_lex.l"
+#line 113 "gwarf_lex.l"
 ECHO;
 	YY_BREAK
-#line 1172 "lex.yy.c"
+#line 1237 "lex.yy.c"
 case YY_STATE_EOF(INITIAL):
 case YY_STATE_EOF(COMMENT):
 case YY_STATE_EOF(STRING_TEXT):
@@ -1470,7 +1535,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 >= 159 )
+			if ( yy_current_state >= 190 )
 				yy_c = yy_meta[yy_c];
 			}
 		yy_current_state = yy_nxt[yy_base[yy_current_state] + yy_c];
@@ -1498,11 +1563,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 >= 159 )
+		if ( yy_current_state >= 190 )
 			yy_c = yy_meta[yy_c];
 		}
 	yy_current_state = yy_nxt[yy_base[yy_current_state] + yy_c];
-	yy_is_jam = (yy_current_state == 158);
+	yy_is_jam = (yy_current_state == 189);
 
 		return yy_is_jam ? 0 : yy_current_state;
 }
@@ -2180,7 +2245,7 @@ void yyfree (void * ptr )
 
 #define YYTABLES_NAME "yytables"
 
-#line 102 "gwarf_lex.l"
+#line 113 "gwarf_lex.l"
 
 int yywrap(void) {
     return 1;

Filskillnaden har hållts tillbaka eftersom den är för stor
+ 340 - 256
paser/y.tab.c


+ 13 - 2
paser/y.tab.h

@@ -93,7 +93,12 @@ extern int yydebug;
     INDENTA = 299,
     STOPN = 300,
     STOPF = 301,
-    BLOCK = 302
+    BLOCK = 302,
+    FALSE = 303,
+    TRUE = 304,
+    NULL_token = 305,
+    DEF = 306,
+    RETURN = 307
   };
 #endif
 /* Tokens.  */
@@ -142,6 +147,11 @@ extern int yydebug;
 #define STOPN 300
 #define STOPF 301
 #define BLOCK 302
+#define FALSE 303
+#define TRUE 304
+#define NULL_token 305
+#define DEF 306
+#define RETURN 307
 
 /* Value type.  */
 #if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED
@@ -154,8 +164,9 @@ union YYSTYPE
     char *string_value;
     struct statement *statement_value;
     struct if_list *if_list_base;
+    struct parameter *parameter_list;
 
-#line 159 "y.tab.h"
+#line 170 "y.tab.h"
 
 };
 typedef union YYSTYPE YYSTYPE;

Vissa filer visades inte eftersom för många filer har ändrats