Przeglądaj źródła

完善了错误捕捉try except raise throw

SongZihuan 5 lat temu
rodzic
commit
0a3c4d432e
10 zmienionych plików z 995 dodań i 591 usunięć
  1. BIN
      gwarf
  2. 5 0
      gwarf.c
  3. 167 79
      inter/cfunc.c
  4. 132 16
      inter/interpreter.c
  5. 37 2
      inter/interpreter.h
  6. 5 0
      paser/gwarf_lex.l
  7. 68 2
      paser/gwarf_yacc.y
  8. 219 181
      paser/lex.yy.c
  9. 350 309
      paser/y.tab.c
  10. 12 2
      paser/y.tab.h

BIN
gwarf


+ 5 - 0
gwarf.c

@@ -30,6 +30,11 @@ int main(){
     bool_login_official(the_var, bool_official_func, tmp_gobject->the_var);  // 注册bool
     bool_login_official(the_var, bool_official_func, tmp_gobject->the_var);  // 注册bool
     list_login_official(the_var, list_official_func, tmp_gobject->the_var);  // 注册list
     list_login_official(the_var, list_official_func, tmp_gobject->the_var);  // 注册list
 
 
+    // 注册错误类型
+    class_object *tmp_BaseException = BaseException_login_official(the_var, BaseException_official_func, tmp_object->the_var);  // 注册goobject
+    class_object *tmp_Exception = Exception_login_official(the_var, tmp_BaseException->the_var);  // 注册goobject
+    NameException_login_official(the_var, tmp_Exception->the_var);  // 注册goobject
+
     parser("/home/songzihuan/test.gwf");
     parser("/home/songzihuan/test.gwf");
     printf("----start run----\n");
     printf("----start run----\n");
     traverse_global(global_inter->global_code, the_var);
     traverse_global(global_inter->global_code, the_var);

+ 167 - 79
inter/cfunc.c

@@ -46,13 +46,12 @@ int len_intx(unsigned int num){  // 16进制
 }
 }
 
 
 GWARF_value to_object(GWARF_value value, var_list *the_var){  // 把GWARF_value封装成objct
 GWARF_value to_object(GWARF_value value, var_list *the_var){  // 把GWARF_value封装成objct
-    GWARF_result return_value;
     if((value.type == CLASS_value) || (value.type == OBJECT_value) || (value.type == FUNC_value) || (value.type == NULL_value)){  // 可以直接返回
     if((value.type == CLASS_value) || (value.type == OBJECT_value) || (value.type == FUNC_value) || (value.type == NULL_value)){  // 可以直接返回
         return value;
         return value;
     }
     }
     GWARF_result func_result;
     GWARF_result func_result;
     func_result.u = statement_end;
     func_result.u = statement_end;
-    func_result.value.type = INT_value;
+    func_result.value.type = NULL_value;
     func_result.value.value.int_value = 0;
     func_result.value.value.int_value = 0;
     var *tmp;
     var *tmp;
     if(value.type == NUMBER_value){
     if(value.type == NUMBER_value){
@@ -83,7 +82,6 @@ GWARF_value to_object(GWARF_value value, var_list *the_var){  // 把GWARF_value
         tmp = find_var(the_var, 0, "list");
         tmp = find_var(the_var, 0, "list");
         if(tmp != NULL){
         if(tmp != NULL){
             func_result.value = tmp->value;
             func_result.value = tmp->value;
-            puts("list");
         }
         }
     }
     }
     else{
     else{
@@ -93,6 +91,33 @@ GWARF_value to_object(GWARF_value value, var_list *the_var){  // 把GWARF_value
 }
 }
 
 
 
 
+GWARF_result to_error(char *error_info, char *error_type, var_list *the_var){  // 把GWARF_value封装成error
+    GWARF_result func_result, return_result;
+    GWARF_value tmp_value;
+
+    tmp_value.type = STRING_value;
+    tmp_value.value.string = error_info;
+
+    func_result.u = statement_end;
+
+    return_result.u = error;
+    return_result.error_info = error_info;
+
+    var *tmp = find_var(the_var, 0, error_type);
+
+    if(tmp != NULL){
+        func_result.value = tmp->value;
+        return_result.value = call_back_core(func_result, the_var, pack_value_parameter(tmp_value)).value;
+    }
+    else{
+        printf("NameError * 2\n");
+        return_result.value.type = NULL_value;
+        return_result.value.value.int_value = 0;
+    }
+    return return_result;
+}
+
+
 void login_official_func(int type, int is_class, var_list *the_var, char *name, GWARF_result (*paser)(func *, parameter *, var_list *, GWARF_result, var_list *)){  // 注册单个official func
 void login_official_func(int type, int is_class, var_list *the_var, char *name, GWARF_result (*paser)(func *, parameter *, var_list *, GWARF_result, var_list *)){  // 注册单个official func
     GWARF_result func_value;
     GWARF_result func_value;
     func *func_tmp = malloc(sizeof(func));
     func *func_tmp = malloc(sizeof(func));
@@ -136,7 +161,7 @@ GWARF_result official_func(func *the_func, parameter *tmp_s, var_list *the_var,
         }
         }
         while(1){
         while(1){
             GWARF_result tmp = traverse(tmp_s->u.value, out_var, false);
             GWARF_result tmp = traverse(tmp_s->u.value, out_var, false);
-            if(tmp.u == name_no_found){  // Name Error错误
+            if(is_error(&tmp)){  // Name Error错误
                 return_value = tmp;
                 return_value = tmp;
                 goto return_result;
                 goto return_result;
             }
             }
@@ -195,9 +220,8 @@ class_object *object_login_official(var_list *the_var, GWARF_result (*paser)(fun
     // 创建对象[空对象]
     // 创建对象[空对象]
     puts("----set class----");
     puts("----set class----");
     GWARF_result class_value;
     GWARF_result class_value;
-    class_object *class_tmp = malloc(sizeof(class_object));
-    class_tmp->the_var = make_var_base(make_var());  // make class var list
-    class_tmp->out_var = append_by_var_list(class_tmp->the_var, copy_var_list(the_var));  // make class var list with out var
+    class_object *class_tmp = make_object(the_var, NULL);
+
     class_value.value.type = CLASS_value;
     class_value.value.type = CLASS_value;
     class_value.value.value.class_value = class_tmp;
     class_value.value.value.class_value = class_tmp;
 
 
@@ -238,18 +262,111 @@ GWARF_result object_official_func(func *the_func, parameter *tmp_s, var_list *th
     return_result: return return_value;
     return_result: return return_value;
 }
 }
 
 
-class_object *gobject_login_official(var_list *the_var, GWARF_result (*paser)(func *, parameter *, var_list *, GWARF_result, var_list *), var_list *father_var_list){  // 内置对象继承的类
-    // 创建对象[空对象]
-    puts("----set class----");
-    GWARF_result class_value;
+class_object *make_object(var_list *the_var, var_list *father_var_list){
     class_object *class_tmp = malloc(sizeof(class_object));
     class_object *class_tmp = malloc(sizeof(class_object));
 
 
     class_tmp->the_var = make_var_base(make_var());  // make class var list
     class_tmp->the_var = make_var_base(make_var());  // make class var list
     if(father_var_list != NULL){
     if(father_var_list != NULL){
-        append_by_var_list(class_tmp->the_var, father_var_list);  // 一切类都需要继承object类[包括set class如果tmp_s == NULL则需要继承object]
+        append_by_var_list(class_tmp->the_var, father_var_list);  // int、double、str等内置类需要继承gobject类
     }
     }
 
 
     class_tmp->out_var = append_by_var_list(class_tmp->the_var, copy_var_list(the_var));  // make class var list with out var
     class_tmp->out_var = append_by_var_list(class_tmp->the_var, copy_var_list(the_var));  // make class var list with out var
+    return class_tmp;
+}
+
+class_object *BaseException_login_official(var_list *the_var, GWARF_result (*paser)(func *, parameter *, var_list *, GWARF_result, var_list *), var_list *father_var_list){
+    // 创建对象[空对象]
+    puts("----set class----");
+    GWARF_result class_value;
+    class_object *class_tmp = make_object(the_var, father_var_list);
+    class_value.value.type = CLASS_value;
+    class_value.value.value.class_value = class_tmp;
+
+    assigment_func("BaseException", class_value, the_var, 0);  // 注册class 的 位置
+    puts("----stop set class----");
+
+    // 注册函数
+    int a[][2] = {{2,1}};
+    char *name[] = {"__init__"};
+
+    int lenth = sizeof(a)/sizeof(a[0]);
+    for(int i = 0;i < lenth;i+=1){
+        login_official_func(a[i][0], a[i][1], class_tmp->the_var, name[i], paser);
+    }
+    return class_tmp;
+}
+
+GWARF_result BaseException_official_func(func *the_func, parameter *tmp_s, var_list *the_var, GWARF_result father, var_list *out_var){  // out_var是外部环境
+    GWARF_result return_value;
+    var_list *login_var;
+    return_value.u = return_def;
+    return_value.return_times = 0;
+    if(father.father->type == CLASS_value){  // is class so that can use "."
+        login_var = father.father->value.class_value->the_var;
+    }
+    else if(father.father->type == OBJECT_value){
+        login_var = father.father->value.object_value->the_var;
+    }
+    else{
+        printf("NO login, father type = %d\n", father.father->type);
+    }
+    switch (the_func->official_func)
+    {
+        case __init__func:{  // printf something
+            GWARF_result tmp, tmp_result = traverse(tmp_s->u.value, out_var, false);
+            if(is_error(&tmp_result)){  // Name Error错误
+                return_value = tmp_result;
+                goto return_result;
+            }
+            else if(is_space(&tmp_result)){
+                return_value = tmp_result;
+                goto return_result;
+            }
+            tmp.value = to_str(tmp_result.value, out_var);  // 只有一个参数[要针对不同数据类型对此处作出处理]
+            assigment_func("ErrorInfo", tmp, login_var, 0);  // 注册到self -> ErrorInfo
+            return_value.u = statement_end;  // __init__没有return
+            break;
+        }
+        default:
+            break;
+    }
+    return_result: return return_value;
+}
+
+class_object *Exception_login_official(var_list *the_var, var_list *father_var_list){
+    // 创建对象[空对象]
+    puts("----set class----");
+    GWARF_result class_value;
+    class_object *class_tmp = make_object(the_var, father_var_list);
+
+    class_value.value.type = CLASS_value;
+    class_value.value.value.class_value = class_tmp;
+
+    assigment_func("Exception", class_value, the_var, 0);  // 注册class 的 位置
+    puts("----stop set class----");
+    return class_tmp;
+}
+
+class_object *NameException_login_official(var_list *the_var, var_list *father_var_list){
+    // 创建对象[空对象]
+    puts("----set class----");
+    GWARF_result class_value;
+    class_object *class_tmp = make_object(the_var, father_var_list);
+
+    class_value.value.type = CLASS_value;
+    class_value.value.value.class_value = class_tmp;
+
+    assigment_func("NameException", class_value, the_var, 0);  // 注册class 的 位置
+    puts("----stop set class----");
+    return class_tmp;
+}
+
+class_object *gobject_login_official(var_list *the_var, GWARF_result (*paser)(func *, parameter *, var_list *, GWARF_result, var_list *), var_list *father_var_list){  // 内置对象继承的类
+    // 创建对象[空对象]
+    puts("----set class----");
+    GWARF_result class_value;
+    class_object *class_tmp = make_object(the_var, father_var_list);
+    
     class_value.value.type = CLASS_value;
     class_value.value.type = CLASS_value;
     class_value.value.value.class_value = class_tmp;
     class_value.value.value.class_value = class_tmp;
 
 
@@ -305,7 +422,7 @@ GWARF_result gobject_official_func(func *the_func, parameter *tmp_s, var_list *t
         }
         }
         case __add__func:{
         case __add__func:{
             GWARF_result reight_tmp, left_tmp, tmp_result = traverse(tmp_s->u.value, out_var, false);
             GWARF_result reight_tmp, left_tmp, tmp_result = traverse(tmp_s->u.value, out_var, false);
-            if(tmp_result.u == name_no_found){  // Name Error错误
+            if(is_error(&tmp_result)){  // Name Error错误
                 return_value = tmp_result;
                 return_value = tmp_result;
                 goto return_result;
                 goto return_result;
             }
             }
@@ -328,7 +445,7 @@ GWARF_result gobject_official_func(func *the_func, parameter *tmp_s, var_list *t
         }
         }
         case __sub__func:{
         case __sub__func:{
             GWARF_result reight_tmp, left_tmp, tmp_result = traverse(tmp_s->u.value, out_var, false);
             GWARF_result reight_tmp, left_tmp, tmp_result = traverse(tmp_s->u.value, out_var, false);
-            if(tmp_result.u == name_no_found){  // Name Error错误
+            if(is_error(&tmp_result)){  // Name Error错误
                 return_value = tmp_result;
                 return_value = tmp_result;
                 goto return_result;
                 goto return_result;
             }
             }
@@ -351,7 +468,7 @@ GWARF_result gobject_official_func(func *the_func, parameter *tmp_s, var_list *t
         }
         }
         case __subr__func:{
         case __subr__func:{
             GWARF_result reight_tmp, left_tmp, tmp_result = traverse(tmp_s->u.value, out_var, false);
             GWARF_result reight_tmp, left_tmp, tmp_result = traverse(tmp_s->u.value, out_var, false);
-            if(tmp_result.u == name_no_found){  // Name Error错误
+            if(is_error(&tmp_result)){  // Name Error错误
                 return_value = tmp_result;
                 return_value = tmp_result;
                 goto return_result;
                 goto return_result;
             }
             }
@@ -374,7 +491,7 @@ GWARF_result gobject_official_func(func *the_func, parameter *tmp_s, var_list *t
         }
         }
         case __mul__func:{
         case __mul__func:{
             GWARF_result reight_tmp, left_tmp, tmp_result = traverse(tmp_s->u.value, out_var, false);
             GWARF_result reight_tmp, left_tmp, tmp_result = traverse(tmp_s->u.value, out_var, false);
-            if(tmp_result.u == name_no_found){  // Name Error错误
+            if(is_error(&tmp_result)){  // Name Error错误
                 return_value = tmp_result;
                 return_value = tmp_result;
                 goto return_result;
                 goto return_result;
             }
             }
@@ -397,7 +514,7 @@ GWARF_result gobject_official_func(func *the_func, parameter *tmp_s, var_list *t
         }
         }
         case __div__func:{
         case __div__func:{
             GWARF_result reight_tmp, left_tmp, tmp_result = traverse(tmp_s->u.value, out_var, false);
             GWARF_result reight_tmp, left_tmp, tmp_result = traverse(tmp_s->u.value, out_var, false);
-            if(tmp_result.u == name_no_found){  // Name Error错误
+            if(is_error(&tmp_result)){  // Name Error错误
                 return_value = tmp_result;
                 return_value = tmp_result;
                 goto return_result;
                 goto return_result;
             }
             }
@@ -420,7 +537,7 @@ GWARF_result gobject_official_func(func *the_func, parameter *tmp_s, var_list *t
         }
         }
         case __divr__func:{
         case __divr__func:{
             GWARF_result reight_tmp, left_tmp, tmp_result = traverse(tmp_s->u.value, out_var, false);
             GWARF_result reight_tmp, left_tmp, tmp_result = traverse(tmp_s->u.value, out_var, false);
-            if(tmp_result.u == name_no_found){  // Name Error错误
+            if(is_error(&tmp_result)){  // Name Error错误
                 return_value = tmp_result;
                 return_value = tmp_result;
                 goto return_result;
                 goto return_result;
             }
             }
@@ -443,7 +560,7 @@ GWARF_result gobject_official_func(func *the_func, parameter *tmp_s, var_list *t
         }
         }
         case __eq__func:{
         case __eq__func:{
             GWARF_result reight_tmp, left_tmp, tmp_result = traverse(tmp_s->u.value, out_var, false);
             GWARF_result reight_tmp, left_tmp, tmp_result = traverse(tmp_s->u.value, out_var, false);
-            if(tmp_result.u == name_no_found){  // Name Error错误
+            if(is_error(&tmp_result)){  // Name Error错误
                 return_value = tmp_result;
                 return_value = tmp_result;
                 goto return_result;
                 goto return_result;
             }
             }
@@ -466,7 +583,7 @@ GWARF_result gobject_official_func(func *the_func, parameter *tmp_s, var_list *t
         }
         }
         case __more__func:{
         case __more__func:{
             GWARF_result reight_tmp, left_tmp, tmp_result = traverse(tmp_s->u.value, out_var, false);
             GWARF_result reight_tmp, left_tmp, tmp_result = traverse(tmp_s->u.value, out_var, false);
-            if(tmp_result.u == name_no_found){  // Name Error错误
+            if(is_error(&tmp_result)){  // Name Error错误
                 return_value = tmp_result;
                 return_value = tmp_result;
                 goto return_result;
                 goto return_result;
             }
             }
@@ -489,7 +606,7 @@ GWARF_result gobject_official_func(func *the_func, parameter *tmp_s, var_list *t
         }
         }
         case __less__func:{
         case __less__func:{
             GWARF_result reight_tmp, left_tmp, tmp_result = traverse(tmp_s->u.value, out_var, false);
             GWARF_result reight_tmp, left_tmp, tmp_result = traverse(tmp_s->u.value, out_var, false);
-            if(tmp_result.u == name_no_found){  // Name Error错误
+            if(is_error(&tmp_result)){  // Name Error错误
                 return_value = tmp_result;
                 return_value = tmp_result;
                 goto return_result;
                 goto return_result;
             }
             }
@@ -512,7 +629,7 @@ GWARF_result gobject_official_func(func *the_func, parameter *tmp_s, var_list *t
         }
         }
         case __eqmore__func:{
         case __eqmore__func:{
             GWARF_result reight_tmp, left_tmp, tmp_result = traverse(tmp_s->u.value, out_var, false);
             GWARF_result reight_tmp, left_tmp, tmp_result = traverse(tmp_s->u.value, out_var, false);
-            if(tmp_result.u == name_no_found){  // Name Error错误
+            if(is_error(&tmp_result)){  // Name Error错误
                 return_value = tmp_result;
                 return_value = tmp_result;
                 goto return_result;
                 goto return_result;
             }
             }
@@ -535,7 +652,7 @@ GWARF_result gobject_official_func(func *the_func, parameter *tmp_s, var_list *t
         }
         }
         case __eqless__func:{
         case __eqless__func:{
             GWARF_result reight_tmp, left_tmp, tmp_result = traverse(tmp_s->u.value, out_var, false);
             GWARF_result reight_tmp, left_tmp, tmp_result = traverse(tmp_s->u.value, out_var, false);
-            if(tmp_result.u == name_no_found){  // Name Error错误
+            if(is_error(&tmp_result)){  // Name Error错误
                 return_value = tmp_result;
                 return_value = tmp_result;
                 goto return_result;
                 goto return_result;
             }
             }
@@ -558,7 +675,7 @@ GWARF_result gobject_official_func(func *the_func, parameter *tmp_s, var_list *t
         }
         }
         case __noteq__func:{
         case __noteq__func:{
             GWARF_result reight_tmp, left_tmp, tmp_result = traverse(tmp_s->u.value, out_var, false);
             GWARF_result reight_tmp, left_tmp, tmp_result = traverse(tmp_s->u.value, out_var, false);
-            if(tmp_result.u == name_no_found){  // Name Error错误
+            if(is_error(&tmp_result)){  // Name Error错误
                 return_value = tmp_result;
                 return_value = tmp_result;
                 goto return_result;
                 goto return_result;
             }
             }
@@ -581,7 +698,7 @@ GWARF_result gobject_official_func(func *the_func, parameter *tmp_s, var_list *t
         }
         }
         case __pow__func:{
         case __pow__func:{
             GWARF_result reight_tmp, left_tmp, tmp_result = traverse(tmp_s->u.value, out_var, false);
             GWARF_result reight_tmp, left_tmp, tmp_result = traverse(tmp_s->u.value, out_var, false);
-            if(tmp_result.u == name_no_found){  // Name Error错误
+            if(is_error(&tmp_result)){  // Name Error错误
                 return_value = tmp_result;
                 return_value = tmp_result;
                 goto return_result;
                 goto return_result;
             }
             }
@@ -604,7 +721,7 @@ GWARF_result gobject_official_func(func *the_func, parameter *tmp_s, var_list *t
         }
         }
         case __log__func:{
         case __log__func:{
             GWARF_result reight_tmp, left_tmp, tmp_result = traverse(tmp_s->u.value, out_var, false);
             GWARF_result reight_tmp, left_tmp, tmp_result = traverse(tmp_s->u.value, out_var, false);
-            if(tmp_result.u == name_no_found){  // Name Error错误
+            if(is_error(&tmp_result)){  // Name Error错误
                 return_value = tmp_result;
                 return_value = tmp_result;
                 goto return_result;
                 goto return_result;
             }
             }
@@ -627,7 +744,7 @@ GWARF_result gobject_official_func(func *the_func, parameter *tmp_s, var_list *t
         }
         }
         case __sqrt__func:{
         case __sqrt__func:{
             GWARF_result reight_tmp, left_tmp, tmp_result = traverse(tmp_s->u.value, out_var, false);
             GWARF_result reight_tmp, left_tmp, tmp_result = traverse(tmp_s->u.value, out_var, false);
-            if(tmp_result.u == name_no_found){  // Name Error错误
+            if(is_error(&tmp_result)){  // Name Error错误
                 return_value = tmp_result;
                 return_value = tmp_result;
                 goto return_result;
                 goto return_result;
             }
             }
@@ -650,7 +767,7 @@ GWARF_result gobject_official_func(func *the_func, parameter *tmp_s, var_list *t
         }
         }
         case __powr__func:{
         case __powr__func:{
             GWARF_result reight_tmp, left_tmp, tmp_result = traverse(tmp_s->u.value, out_var, false);
             GWARF_result reight_tmp, left_tmp, tmp_result = traverse(tmp_s->u.value, out_var, false);
-            if(tmp_result.u == name_no_found){  // Name Error错误
+            if(is_error(&tmp_result)){  // Name Error错误
                 return_value = tmp_result;
                 return_value = tmp_result;
                 goto return_result;
                 goto return_result;
             }
             }
@@ -673,7 +790,7 @@ GWARF_result gobject_official_func(func *the_func, parameter *tmp_s, var_list *t
         }
         }
         case __logr__func:{
         case __logr__func:{
             GWARF_result reight_tmp, left_tmp, tmp_result = traverse(tmp_s->u.value, out_var, false);
             GWARF_result reight_tmp, left_tmp, tmp_result = traverse(tmp_s->u.value, out_var, false);
-            if(tmp_result.u == name_no_found){  // Name Error错误
+            if(is_error(&tmp_result)){  // Name Error错误
                 return_value = tmp_result;
                 return_value = tmp_result;
                 goto return_result;
                 goto return_result;
             }
             }
@@ -696,7 +813,7 @@ GWARF_result gobject_official_func(func *the_func, parameter *tmp_s, var_list *t
         }
         }
         case __sqrtr__func:{
         case __sqrtr__func:{
             GWARF_result reight_tmp, left_tmp, tmp_result = traverse(tmp_s->u.value, out_var, false);
             GWARF_result reight_tmp, left_tmp, tmp_result = traverse(tmp_s->u.value, out_var, false);
-            if(tmp_result.u == name_no_found){  // Name Error错误
+            if(is_error(&tmp_result)){  // Name Error错误
                 return_value = tmp_result;
                 return_value = tmp_result;
                 goto return_result;
                 goto return_result;
             }
             }
@@ -736,20 +853,11 @@ GWARF_result gobject_official_func(func *the_func, parameter *tmp_s, var_list *t
     return_result: return return_value;
     return_result: return return_value;
 }
 }
 
 
-// TODO: 设置反向函数, object的__add__等方法都定义为同一个
-
 class_object *int_login_official(var_list *the_var, GWARF_result (*paser)(func *, parameter *, var_list *, GWARF_result, var_list *), var_list *father_var_list){
 class_object *int_login_official(var_list *the_var, GWARF_result (*paser)(func *, parameter *, var_list *, GWARF_result, var_list *), var_list *father_var_list){
     // 创建对象[空对象]
     // 创建对象[空对象]
     puts("----set class----");
     puts("----set class----");
     GWARF_result class_value;
     GWARF_result class_value;
-    class_object *class_tmp = malloc(sizeof(class_object));
-
-    class_tmp->the_var = make_var_base(make_var());  // make class var list
-    if(father_var_list != NULL){
-        append_by_var_list(class_tmp->the_var, father_var_list);  // int、double、str等内置类需要继承gobject类
-    }
-
-    class_tmp->out_var = append_by_var_list(class_tmp->the_var, copy_var_list(the_var));  // make class var list with out var
+    class_object *class_tmp = make_object(the_var, father_var_list);
     class_value.value.type = CLASS_value;
     class_value.value.type = CLASS_value;
     class_value.value.value.class_value = class_tmp;
     class_value.value.value.class_value = class_tmp;
 
 
@@ -785,7 +893,7 @@ GWARF_result int_official_func(func *the_func, parameter *tmp_s, var_list *the_v
     {
     {
         case __init__func:{  // printf something
         case __init__func:{  // printf something
             GWARF_result tmp, tmp_result = traverse(tmp_s->u.value, out_var, false);
             GWARF_result tmp, tmp_result = traverse(tmp_s->u.value, out_var, false);
-            if(tmp_result.u == name_no_found){  // Name Error错误
+            if(is_error(&tmp_result)){  // Name Error错误
                 return_value = tmp_result;
                 return_value = tmp_result;
                 goto return_result;
                 goto return_result;
             }
             }
@@ -839,14 +947,8 @@ class_object *double_login_official(var_list *the_var, GWARF_result (*paser)(fun
     // 创建对象[空对象]
     // 创建对象[空对象]
     puts("----set class----");
     puts("----set class----");
     GWARF_result class_value;
     GWARF_result class_value;
-    class_object *class_tmp = malloc(sizeof(class_object));
-
-    class_tmp->the_var = make_var_base(make_var());  // make class var list
-    if(father_var_list != NULL){
-        append_by_var_list(class_tmp->the_var, father_var_list);  // 一切类都需要继承object类[包括set class如果tmp_s == NULL则需要继承object]
-    }
+    class_object *class_tmp = make_object(the_var, father_var_list);
 
 
-    class_tmp->out_var = append_by_var_list(class_tmp->the_var, copy_var_list(the_var));  // make class var list with out var
     class_value.value.type = CLASS_value;
     class_value.value.type = CLASS_value;
     class_value.value.value.class_value = class_tmp;
     class_value.value.value.class_value = class_tmp;
 
 
@@ -882,7 +984,7 @@ GWARF_result double_official_func(func *the_func, parameter *tmp_s, var_list *th
     {
     {
         case __init__func:{  // printf something
         case __init__func:{  // printf something
             GWARF_result tmp, tmp_result = traverse(tmp_s->u.value, out_var, false);
             GWARF_result tmp, tmp_result = traverse(tmp_s->u.value, out_var, false);
-            if(tmp_result.u == name_no_found){  // Name Error错误
+            if(is_error(&tmp_result)){  // Name Error错误
                 return_value = tmp_result;
                 return_value = tmp_result;
                 goto return_result;
                 goto return_result;
             }
             }
@@ -934,13 +1036,8 @@ class_object *str_login_official(var_list *the_var, GWARF_result (*paser)(func *
     // 创建对象[空对象]
     // 创建对象[空对象]
     puts("----set class----");
     puts("----set class----");
     GWARF_result class_value;
     GWARF_result class_value;
-    class_object *class_tmp = malloc(sizeof(class_object));
+    class_object *class_tmp = make_object(the_var, father_var_list);
 
 
-    class_tmp->the_var = make_var_base(make_var());  // make class var list
-    if(father_var_list != NULL){
-        append_by_var_list(class_tmp->the_var, father_var_list);  // 一切类都需要继承object类[包括set class如果tmp_s == NULL则需要继承object]
-    }
-    class_tmp->out_var = append_by_var_list(class_tmp->the_var, copy_var_list(the_var));  // make class var list with out var
     class_value.value.type = CLASS_value;
     class_value.value.type = CLASS_value;
     class_value.value.value.class_value = class_tmp;
     class_value.value.value.class_value = class_tmp;
 
 
@@ -976,7 +1073,7 @@ GWARF_result str_official_func(func *the_func, parameter *tmp_s, var_list *the_v
     {
     {
         case __init__func:{  // printf something
         case __init__func:{  // printf something
             GWARF_result tmp, tmp_result = traverse(tmp_s->u.value, out_var, false);
             GWARF_result tmp, tmp_result = traverse(tmp_s->u.value, out_var, false);
-            if(tmp_result.u == name_no_found){  // Name Error错误
+            if(is_error(&tmp_result)){  // Name Error错误
                 return_value = tmp_result;
                 return_value = tmp_result;
                 goto return_result;
                 goto return_result;
             }
             }
@@ -1050,13 +1147,8 @@ class_object *bool_login_official(var_list *the_var, GWARF_result (*paser)(func
     // 创建对象[空对象]
     // 创建对象[空对象]
     puts("----set class----");
     puts("----set class----");
     GWARF_result class_value;
     GWARF_result class_value;
-    class_object *class_tmp = malloc(sizeof(class_object));
+    class_object *class_tmp = make_object(the_var, father_var_list);
 
 
-    class_tmp->the_var = make_var_base(make_var());  // make class var list
-    if(father_var_list != NULL){
-        append_by_var_list(class_tmp->the_var, father_var_list);  // 一切类都需要继承object类[包括set class如果tmp_s == NULL则需要继承object]
-    }
-    class_tmp->out_var = append_by_var_list(class_tmp->the_var, copy_var_list(the_var));  // make class var list with out var
     class_value.value.type = CLASS_value;
     class_value.value.type = CLASS_value;
     class_value.value.value.class_value = class_tmp;
     class_value.value.value.class_value = class_tmp;
 
 
@@ -1092,7 +1184,7 @@ GWARF_result bool_official_func(func *the_func, parameter *tmp_s, var_list *the_
     {
     {
         case __init__func:{  // printf something
         case __init__func:{  // printf something
             GWARF_result tmp, tmp_result = traverse(tmp_s->u.value, out_var, false);
             GWARF_result tmp, tmp_result = traverse(tmp_s->u.value, out_var, false);
-            if(tmp_result.u == name_no_found){  // Name Error错误
+            if(is_error(&tmp_result)){  // Name Error错误
                 return_value = tmp_result;
                 return_value = tmp_result;
                 goto return_result;
                 goto return_result;
             }
             }
@@ -1134,13 +1226,8 @@ class_object *list_login_official(var_list *the_var, GWARF_result (*paser)(func
     // 创建对象[空对象]
     // 创建对象[空对象]
     puts("----set class----");
     puts("----set class----");
     GWARF_result class_value;
     GWARF_result class_value;
-    class_object *class_tmp = malloc(sizeof(class_object));
+    class_object *class_tmp = make_object(the_var, father_var_list);
 
 
-    class_tmp->the_var = make_var_base(make_var());  // make class var list
-    if(father_var_list != NULL){
-        append_by_var_list(class_tmp->the_var, father_var_list);  // 一切类都需要继承object类[包括set class如果tmp_s == NULL则需要继承object]
-    }
-    class_tmp->out_var = append_by_var_list(class_tmp->the_var, copy_var_list(the_var));  // make class var list with out var
     class_value.value.type = CLASS_value;
     class_value.value.type = CLASS_value;
     class_value.value.value.class_value = class_tmp;
     class_value.value.value.class_value = class_tmp;
 
 
@@ -1187,9 +1274,8 @@ GWARF_result list_official_func(func *the_func, parameter *tmp_s, var_list *the_
                 return_value.u = statement_end;  // __init__没有return
                 return_value.u = statement_end;  // __init__没有return
             }
             }
             else{
             else{
-                puts("list.__init__");
                 GWARF_result tmp, tmp_result = traverse(tmp_s->u.value, out_var, false);
                 GWARF_result tmp, tmp_result = traverse(tmp_s->u.value, out_var, false);
-                if(tmp_result.u == name_no_found){  // Name Error错误
+                if(is_error(&tmp_result)){  // Name Error错误
                     return_value = tmp_result;
                     return_value = tmp_result;
                     goto return_result;
                     goto return_result;
                 }
                 }
@@ -1219,7 +1305,7 @@ GWARF_result list_official_func(func *the_func, parameter *tmp_s, var_list *the_
             var *tmp = find_var(login_var, 0, "value");
             var *tmp = find_var(login_var, 0, "value");
             if(tmp != NULL){
             if(tmp != NULL){
                 GWARF_result get_value, tmp_result = traverse(tmp_s->u.value, out_var, false);
                 GWARF_result get_value, tmp_result = traverse(tmp_s->u.value, out_var, false);
-                if(tmp_result.u == name_no_found){  // Name Error错误
+                if(is_error(&tmp_result)){  // Name Error错误
                     return_value = tmp_result;
                     return_value = tmp_result;
                     goto return_result;
                     goto return_result;
                 }
                 }
@@ -1245,7 +1331,7 @@ GWARF_result list_official_func(func *the_func, parameter *tmp_s, var_list *the_
             int start, end;
             int start, end;
             if(tmp != NULL){
             if(tmp != NULL){
                 GWARF_result start_result = traverse(tmp_s->u.value, out_var, false), end_result;
                 GWARF_result start_result = traverse(tmp_s->u.value, out_var, false), end_result;
-                if(start_result.u == name_no_found){  // Name Error错误
+                if(is_error(&start_result)){  // Name Error错误
                     return_value = start_result;
                     return_value = start_result;
                     goto return_result;
                     goto return_result;
                 }
                 }
@@ -1258,7 +1344,7 @@ GWARF_result list_official_func(func *the_func, parameter *tmp_s, var_list *the_
                 tmp_s = tmp_s->next;
                 tmp_s = tmp_s->next;
                 if(tmp_s != NULL){
                 if(tmp_s != NULL){
                     end_result = traverse(tmp_s->u.value, out_var, false);
                     end_result = traverse(tmp_s->u.value, out_var, false);
-                    if(end_result.u == name_no_found){  // Name Error错误
+                    if(is_error(&end_result)){  // Name Error错误
                         return_value = end_result;
                         return_value = end_result;
                         goto return_result;
                         goto return_result;
                     }
                     }
@@ -1288,7 +1374,7 @@ GWARF_result list_official_func(func *the_func, parameter *tmp_s, var_list *the_
             var *tmp = find_var(login_var, 0, "value");
             var *tmp = find_var(login_var, 0, "value");
             if(tmp != NULL){
             if(tmp != NULL){
                 GWARF_result get_value, tmp_result = traverse(tmp_s->u.value, out_var, false);
                 GWARF_result get_value, tmp_result = traverse(tmp_s->u.value, out_var, false);
-                if(tmp_result.u == name_no_found){  // Name Error错误
+                if(is_error(&tmp_result)){  // Name Error错误
                     return_value = tmp_result;
                     return_value = tmp_result;
                     goto return_result;
                     goto return_result;
                 }
                 }
@@ -1302,7 +1388,7 @@ GWARF_result list_official_func(func *the_func, parameter *tmp_s, var_list *the_
 
 
                 tmp_s = tmp_s->next;
                 tmp_s = tmp_s->next;
                 GWARF_result new_value = traverse(tmp_s->u.value, out_var, false);
                 GWARF_result new_value = traverse(tmp_s->u.value, out_var, false);
-                if(new_value.u == name_no_found){  // Name Error错误
+                if(is_error(&new_value)){  // Name Error错误
                     return_value = new_value;
                     return_value = new_value;
                     goto return_result;
                     goto return_result;
                 }
                 }
@@ -1379,7 +1465,7 @@ GWARF_value parameter_to_list(parameter *tmp_s, var_list *the_var){  // 把param
 
 
 GWARF_result get__value__(GWARF_value *base_the_var, var_list *the_var){  // 用于计算的get__value__统一核心
 GWARF_result get__value__(GWARF_value *base_the_var, var_list *the_var){  // 用于计算的get__value__统一核心
     GWARF_result tmp = run_func(base_the_var, the_var, "__value__");
     GWARF_result tmp = run_func(base_the_var, the_var, "__value__");
-    if(tmp.u == name_no_found){
+    if(is_error(&tmp)){
         tmp.u = statement_end;
         tmp.u = statement_end;
         tmp.value.type = NULL_value;
         tmp.value.type = NULL_value;
         tmp.value.value.int_value = 0;
         tmp.value.value.int_value = 0;
@@ -1389,7 +1475,7 @@ GWARF_result get__value__(GWARF_value *base_the_var, var_list *the_var){  // 用
 
 
 GWARF_result get__bool__(GWARF_value *base_the_var, var_list *the_var){  // 用于计算的get__value__统一核心
 GWARF_result get__bool__(GWARF_value *base_the_var, var_list *the_var){  // 用于计算的get__value__统一核心
     GWARF_result tmp = run_func(base_the_var, the_var, "__bool__");
     GWARF_result tmp = run_func(base_the_var, the_var, "__bool__");
-    if(tmp.u == name_no_found){
+    if(is_error(&tmp)){
         tmp.u = statement_end;
         tmp.u = statement_end;
         tmp.value.type = BOOL_value;
         tmp.value.type = BOOL_value;
         tmp.value.value.bool_value = true;
         tmp.value.value.bool_value = true;
@@ -1424,7 +1510,9 @@ GWARF_result run_func(GWARF_value *base_the_var, var_list *the_var, char *name){
             base_the_var = &(reight_tmp.value);  // 重复获取__value__[直到类型不是object或class]
             base_the_var = &(reight_tmp.value);  // 重复获取__value__[直到类型不是object或class]
         }
         }
         else{
         else{
-            reight_tmp.u = name_no_found;
+            char *tmp = malloc((size_t)( 21 + strlen(name)) );
+            sprintf(tmp, "name not found [%s]\n", name);
+            reight_tmp = to_error(tmp, "NameException", the_var);
             goto return_result;
             goto return_result;
         }
         }
     }
     }

+ 132 - 16
inter/interpreter.c

@@ -21,7 +21,7 @@ bool is_space(GWARF_result *tmp){  // 使用指针是不想复制数据
 }
 }
 
 
 bool is_error(GWARF_result *tmp){  // 判断是否为error
 bool is_error(GWARF_result *tmp){  // 判断是否为error
-    if(tmp->u == name_no_found){
+    if(tmp->u == error){
         return true;
         return true;
     }
     }
     return false;
     return false;
@@ -211,10 +211,10 @@ GWARF_result read_statement(statement *the_statement, var_list *the_var, var_lis
                 }
                 }
             }
             }
             var *tmp = find_var(the_var, from, (the_statement->code).base_var.var_name);
             var *tmp = find_var(the_var, from, (the_statement->code).base_var.var_name);
-            if(tmp == NULL){  // 唯一会输出name_no_found的位置
-                return_value.u = name_no_found;  // nameerror
-                return_value.error_info = malloc((size_t)( 21 + strlen(the_statement->code.base_var.var_name) ));
-                sprintf(return_value.error_info, "name not found [%s]\n", (the_statement->code).base_var.var_name);  // 记录错误信息
+            if(tmp == NULL){  // 输出name error[共两处会输出]
+                char *tmp = malloc((size_t)( 21 + strlen(the_statement->code.base_var.var_name) ));
+                sprintf(tmp, "name not found [%s]\n", the_statement->code.base_var.var_name);
+                return_value = to_error(tmp, "NameException", the_var);
             }
             }
             else
             else
             {
             {
@@ -305,14 +305,12 @@ GWARF_result read_statement(statement *the_statement, var_list *the_var, var_lis
                     get.value = tmp->value;
                     get.value = tmp->value;
                     get.father = &base_the_var;  // 设置father
                     get.father = &base_the_var;  // 设置father
                     return_value = call_back_core(get, the_var, pack_value_parameter(child_value.value));
                     return_value = call_back_core(get, the_var, pack_value_parameter(child_value.value));
-                    puts("DOWN");
                     goto the_break_down;
                     goto the_break_down;
                 }
                 }
             }
             }
 
 
             the_break_down: 
             the_break_down: 
             return_value.value = to_object(return_value.value, the_var);  // call_back_core 返回值是object
             return_value.value = to_object(return_value.value, the_var);  // call_back_core 返回值是object
-            printf("down = return_value.value.type = %d\n", return_value.value.type);
             break;
             break;
         }
         }
         case def:{
         case def:{
@@ -686,6 +684,15 @@ GWARF_result read_statement(statement *the_statement, var_list *the_var, var_lis
             return_value = block_func(the_statement, the_var);
             return_value = block_func(the_statement, the_var);
             puts("----stop block code----");
             puts("----stop block code----");
             break;
             break;
+        case try_code:
+            return_value = try_func(the_statement, the_var);
+            break;
+        case raise_e:
+            return_value = raise_func(the_statement, the_var, true);
+            break;
+        case throw_e:
+            return_value = raise_func(the_statement, the_var, false);
+            break;
         default:
         default:
             puts("default");
             puts("default");
             break;
             break;
@@ -970,10 +977,122 @@ GWARF_result for_func(statement *the_statement, var_list *the_var){  // read the
     return value;
     return value;
 }
 }
 
 
+// -----------------raise func
+GWARF_result raise_func(statement *the_statement, var_list *the_var, bool not_class){  // read the statement list with case to run by func
+    GWARF_result error_value;
+    GWARF_value info;
+
+    if(not_class){  // raise
+        error_value = traverse(the_statement->code.raise_e.done, the_var, false);
+        info = to_str(traverse(the_statement->code.raise_e.info, the_var, false).value, the_var);
+    }
+    else{  // raise
+        GWARF_value tmp;
+        tmp.type = STRING_value;
+        tmp.value.string = "throw by user";
+        error_value = traverse(the_statement->code.throw_e.done, the_var, false);
+        info = to_str(tmp, the_var);
+    }
+
+    // restart操作[和continue效果相同]
+
+    if(is_error(&error_value)){  // 遇到错误->执行except语句[不需要再检查break...]
+        goto return_value;  // raise执行时发生错误
+    }
+    if(is_space(&error_value)){
+        goto return_value;
+    }
+
+    error_value.u = error;
+    error_value.error_info = info.value.string;
+
+    if(error_value.value.type == OBJECT_value){
+        ;  // 本身就是object
+    }
+    else if(error_value.value.type == CLASS_value && not_class){  // class类型
+        error_value.value = call_back_core(error_value, the_var, pack_value_parameter(info)).value;
+    }
+    else{
+        error_value.value = to_object(error_value.value, the_var);  // 直接返回
+    }
+
+    return_value: return error_value;
+}
+
+// -----------------try func
+GWARF_result try_func(statement *the_statement, var_list *the_var){  // read the statement list with case to run by func
+    GWARF_result value;
+
+    var *tmp = make_var();  // base_var
+    the_var = append_var_list(tmp, the_var);
+
+    again: 
+    puts("----try----");
+    value = traverse(the_statement->code.try_code.try, the_var, false);
+    puts("----stop try----");
+
+    // restart操作[和continue效果相同]
+
+    if(is_error(&value)){  // 遇到错误->执行except语句[不需要再检查break...]
+        assigment_func(the_statement->code.try_code.name, value, the_var, 0);
+        puts("----except----");
+        value = traverse(the_statement->code.try_code.except, the_var, false);
+        puts("----stop except----");
+    }
+
+    if(value.u == code_restarted){
+        if(value.value.type != INT_value){
+            value.value.type = INT_value;
+            value.value.value.int_value = 0;
+        }
+        if(value.value.value.int_value <= 0){
+            puts("----restarted real----");
+            value.u = statement_end;
+            goto again;
+        }
+        else{
+            value.value.value.int_value -= 1;
+        }
+    }
+    
+    // continued操作
+    if(value.u == code_continued){
+        if(value.value.type != INT_value){
+            value.value.type = INT_value;
+            value.value.value.int_value = 0;
+        }
+        if(value.value.value.int_value <= 0){
+            puts("----block continue real----");
+            value.u = statement_end;
+            goto again;
+        }
+        else{
+            value.value.value.int_value -= 1;
+        }
+    }
+
+    // broken操作
+    if(value.u == code_broken){
+        if(value.value.type != INT_value){
+            value.value.type = INT_value;
+            value.value.value.int_value = 0;
+        }
+        if(value.value.value.int_value <= 0){
+            value.u = statement_end;  // 正常设置[正常语句结束]
+        }
+        else{
+            value.value.value.int_value -= 1;
+        }
+    }
+    the_var = free_var_list(the_var);  // free the new var
+    return value;
+}
+
+
 // -----------------block func
 // -----------------block func
 
 
 GWARF_result block_func(statement *the_statement, var_list *the_var){  // read the statement list with case to run by func
 GWARF_result block_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;
     again: 
     again: 
     puts("----block----");
     puts("----block----");
     value = traverse(the_statement->code.code_block.done, the_var, true);
     value = traverse(the_statement->code.code_block.done, the_var, true);
@@ -1116,7 +1235,6 @@ GWARF_result operation_func(statement *the_statement, var_list *the_var, var_lis
     int func_type = the_statement->code.operation.type;
     int func_type = the_statement->code.operation.type;
     if((func_type != ASSIGMENT_func) && (func_type != NEGATIVE_func)){  // don't run because I don't need[if it's and func ,it will be run twice]
     if((func_type != ASSIGMENT_func) && (func_type != NEGATIVE_func)){  // don't run because I don't need[if it's and func ,it will be run twice]
         left_result = traverse((*the_statement).code.operation.left_exp, the_var, false);
         left_result = traverse((*the_statement).code.operation.left_exp, the_var, false);
-        printf("left_result.value.type = %d\n",left_result.value.type);
         if(is_error(&left_result)){  // Name Error错误
         if(is_error(&left_result)){  // Name Error错误
             // puts("STOP:: Name No Found!");
             // puts("STOP:: Name No Found!");
             return left_result;
             return left_result;
@@ -1569,8 +1687,6 @@ GWARF_result call_back_core(GWARF_result get, var_list *the_var, parameter *tmp_
 
 
 // ---------  ADD
 // ---------  ADD
 GWARF_result add_func(GWARF_result left_result, GWARF_result right_result, var_list *the_var){  // the func for add and call from read_statement_list
 GWARF_result add_func(GWARF_result left_result, GWARF_result right_result, var_list *the_var){  // the func for add and call from read_statement_list
-    puts("come to add");
-    // printf("left_result.value.type = %d\n", left_result.value.type);
     GWARF_result return_value, get;  // the result by call read_statement_list with left and right; value is the result for add
     GWARF_result return_value, get;  // the result by call read_statement_list with left and right; value is the result for add
     if(left_result.value.type == OBJECT_value){  // 调用左add方法
     if(left_result.value.type == OBJECT_value){  // 调用左add方法
         GWARF_result get;
         GWARF_result get;
@@ -1582,7 +1698,6 @@ GWARF_result add_func(GWARF_result left_result, GWARF_result right_result, var_l
             get.value = tmp->value;
             get.value = tmp->value;
             get.father = &base_the_var;  // 设置father
             get.father = &base_the_var;  // 设置father
             return_value = call_back_core(get, the_var, pack_value_parameter(right_result.value));
             return_value = call_back_core(get, the_var, pack_value_parameter(right_result.value));
-            printf("return_value.value.type = %d\n", return_value.value.type);
             goto return_back;
             goto return_back;
         }
         }
         // goto next if
         // goto next if
@@ -2323,7 +2438,7 @@ GWARF_result traverse(statement *the_statement, var_list *the_var, bool new){  /
         result2 = read_statement_list(tmp, the_var);
         result2 = read_statement_list(tmp, the_var);
 
 
         // 错误停止
         // 错误停止
-        if(result2.u == name_no_found){  // Name Error错误
+        if(result2.u == error){  // Name Error错误
             // puts("STOP:: Name No Found!");
             // puts("STOP:: Name No Found!");
             result = result2;
             result = result2;
             break;
             break;
@@ -2360,7 +2475,7 @@ GWARF_result traverse_global(statement *the_statement, var_list *the_var){  // t
             break;  // off
             break;  // off
         }
         }
         result = read_statement_list(tmp, the_var);
         result = read_statement_list(tmp, the_var);
-        if(result.u == name_no_found){  // Name Error错误
+        if(result.u == error){  // Name Error错误
             printf("%s", result.error_info);
             printf("%s", result.error_info);
             break;
             break;
         }
         }
@@ -2377,5 +2492,6 @@ inter *get_inter(){
     return tmp;
     return tmp;
 }
 }
 
 
-// TODO::设置func和NULL均为object,设置object无__add___等方法时的操作:: NULL永远只有一个实例, object回调__call__   malloc返回值检查
-// TODO::错误捕捉
+// TODO::设置func和NULL均为object,设置object无__add___等方法时的操作:: NULL永远只有一个实例, object回调__call__ malloc返回值检查
+// TODO::错误捕捉
+// TODO::使用Var的地方都允许使用层数

+ 37 - 2
inter/interpreter.h

@@ -1,7 +1,7 @@
 #ifndef _INTERPRETER_H
 #ifndef _INTERPRETER_H
 #define _INTERPRETER_H
 #define _INTERPRETER_H
 
 
-// #define malloc(size) safe_malloc(size)
+#define malloc(size) safe_malloc(size)
 #define free(p) p=safe_free(p)
 #define free(p) p=safe_free(p)
 #define realloc(p,size) safe_realloc(p,size)
 #define realloc(p,size) safe_realloc(p,size)
 #define memcpy(p1,p2,size) safe_memcpy(p1,p2,size)
 #define memcpy(p1,p2,size) safe_memcpy(p1,p2,size)
@@ -89,6 +89,9 @@ typedef struct statement{
         slice,
         slice,
         return_code,
         return_code,
         set_class,  // class aaa; b = aaa() is ```call```
         set_class,  // class aaa; b = aaa() is ```call```
+        try_code,  // try to do something except to do something
+        raise_e,  // raise exception
+        throw_e,  // throw the object class func or NULL
     } type;  // the statement type
     } type;  // the statement type
 
 
     union
     union
@@ -228,6 +231,24 @@ typedef struct statement{
             parameter *father_list;  // 继承
             parameter *father_list;  // 继承
         } set_class;
         } set_class;
 
 
+        struct
+        {
+            struct statement *try;
+            struct statement *except;
+            char *name;  // as var
+        } try_code;
+
+        struct
+        {
+            struct statement *done;  // done to get exception object
+            struct statement *info;  // the info
+        } raise_e;
+
+        struct
+        {
+            struct statement *done;  // done to get exception object
+        } throw_e;
+
     } code;
     } code;
     struct statement *next;
     struct statement *next;
 } statement;
 } statement;
@@ -248,7 +269,7 @@ typedef struct GWARF_result{
         code_restarted,
         code_restarted,
         code_rego,
         code_rego,
         code_rewent,
         code_rewent,
-        name_no_found,
+        error,
     } u;  // the result type[from where]
     } u;  // the result type[from where]
     int return_times;  // return用
     int return_times;  // return用
     char *error_info;  // 输出的错误信息
     char *error_info;  // 输出的错误信息
@@ -361,6 +382,8 @@ GWARF_result for_func(statement *, var_list *);
 GWARF_result call_back(statement *, var_list *);
 GWARF_result call_back(statement *, var_list *);
 GWARF_result call_back_core(GWARF_result, var_list *, parameter *);
 GWARF_result call_back_core(GWARF_result, var_list *, parameter *);
 GWARF_result block_func(statement *, var_list *);
 GWARF_result block_func(statement *, var_list *);
+GWARF_result try_func(statement *, var_list *);
+GWARF_result raise_func(statement *, var_list *, bool);
 
 
 GWARF_result add_func(GWARF_result, GWARF_result, var_list *);
 GWARF_result add_func(GWARF_result, GWARF_result, var_list *);
 GWARF_result sub_func(GWARF_result, GWARF_result, var_list *);
 GWARF_result sub_func(GWARF_result, GWARF_result, var_list *);
@@ -393,6 +416,7 @@ int len_double(double num);
 int len_int(int num);
 int len_int(int num);
 int len_intx(unsigned int num);
 int len_intx(unsigned int num);
 GWARF_value to_object(GWARF_value, var_list *);
 GWARF_value to_object(GWARF_value, var_list *);
+class_object *make_object(var_list *the_var, var_list *father_var_list);
 
 
 void login_official_func(int type, int is_class, var_list *the_var, char *name, GWARF_result (*paser)(func *, parameter *, var_list *, GWARF_result, var_list *));
 void login_official_func(int type, int is_class, var_list *the_var, char *name, GWARF_result (*paser)(func *, parameter *, var_list *, GWARF_result, var_list *));
 void login_official(var_list *the_var, GWARF_result (*paser)(func *, parameter *, var_list *, GWARF_result, var_list *));
 void login_official(var_list *the_var, GWARF_result (*paser)(func *, parameter *, var_list *, GWARF_result, var_list *));
@@ -428,6 +452,17 @@ GWARF_result bool_official_func(func *the_func, parameter *tmp_s, var_list *the_
 class_object *list_login_official(var_list *the_var, GWARF_result (*paser)(func *, parameter *, var_list *, GWARF_result, var_list *), var_list *father_var_list);
 class_object *list_login_official(var_list *the_var, GWARF_result (*paser)(func *, parameter *, var_list *, GWARF_result, var_list *), var_list *father_var_list);
 GWARF_result list_official_func(func *the_func, parameter *tmp_s, var_list *the_var, GWARF_result father, var_list *out_var);
 GWARF_result list_official_func(func *the_func, parameter *tmp_s, var_list *the_var, GWARF_result father, var_list *out_var);
 
 
+// 错误内置类
+class_object *BaseException_login_official(var_list *the_var, GWARF_result (*paser)(func *, parameter *, var_list *, GWARF_result, var_list *), var_list *father_var_list);
+GWARF_result BaseException_official_func(func *the_func, parameter *tmp_s, var_list *the_var, GWARF_result father, var_list *out_var);
+
+class_object *Exception_login_official(var_list *the_var, var_list *father_var_list);
+class_object *NameException_login_official(var_list *the_var, var_list *father_var_list);
+
+// 生成错误
+GWARF_result to_error(char *error_info, char *error_type, var_list *the_var);
+
+
 bool is_space(GWARF_result *);
 bool is_space(GWARF_result *);
 bool is_error(GWARF_result *tmp);
 bool is_error(GWARF_result *tmp);
 
 

+ 5 - 0
paser/gwarf_lex.l

@@ -70,6 +70,11 @@
 <INITIAL>' {BEGIN STRING_TEXT;}
 <INITIAL>' {BEGIN STRING_TEXT;}
 <INITIAL>\" {BEGIN STRING_TEXT;}
 <INITIAL>\" {BEGIN STRING_TEXT;}
 
 
+<INITIAL>"try" {return TRY;}
+<INITIAL>[\n]*except {return EXCEPT;}
+<INITIAL>"as" {return AS;}
+<INITIAL>"raise" {return RAISE;}
+<INITIAL>"throw" {return THROW;}
 <INITIAL>"true" {return TRUE;}
 <INITIAL>"true" {return TRUE;}
 <INITIAL>"false" {return FALSE;}
 <INITIAL>"false" {return FALSE;}
 <INITIAL>"True" {return TRUE;}
 <INITIAL>"True" {return TRUE;}

+ 68 - 2
paser/gwarf_yacc.y

@@ -21,13 +21,18 @@
 }
 }
 %token <double_value> NUMBER INT
 %token <double_value> NUMBER INT
 %token <string_value> STRING VAR
 %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 FALSE TRUE
 %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 CLASS POINT COLON
+%token NULL_token DEF RETURN CLASS POINT COLON TRY EXCEPT AS RAISE THROW
+
 %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> 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 call_number def_block def_exp return_exp return_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 block_exp block_block call_number def_block def_exp return_exp return_token
-%type <statement_value> eq_number class_block class_exp slice_arguments_token
+%type <statement_value> eq_number class_block class_exp slice_arguments_token try_block try_exp try_token raise_exp
+
 %type <parameter_list> formal_parameter arguments slice_arguments
 %type <parameter_list> formal_parameter arguments slice_arguments
+
 %type <string_value> base_string
 %type <string_value> base_string
+
 %type <if_list_base> elif_exp
 %type <if_list_base> elif_exp
 %%
 %%
 command_block
 command_block
@@ -132,6 +137,14 @@ command
     {
     {
         $$ = $1;
         $$ = $1;
     }
     }
+    | try_block stop_token
+    {
+        $$ = $1;
+    }
+    | raise_exp stop_token
+    {
+        $$ = $1;
+    }
     ;
     ;
 
 
 top_exp
 top_exp
@@ -676,10 +689,63 @@ for_exp
     }
     }
     ;
     ;
 
 
+raise_exp
+    : RAISE top_exp top_exp
+    {
+        statement *raise_tmp =  make_statement();
+        raise_tmp->type = raise_e;
+        raise_tmp->code.raise_e.done = $2;
+        raise_tmp->code.raise_e.info = $3;
+        $$ = raise_tmp;
+    }
+    | THROW top_exp
+    {
+        statement *raise_tmp =  make_statement();
+        raise_tmp->type = throw_e;
+        raise_tmp->code.throw_e.done = $2;
+        $$ = raise_tmp;
+    }
+    ;
+
+try_block
+    : try_exp block
+    {
+        statement_base = free_statement_list(statement_base);  // new statement_base (FILO)
+        $$ = $1;
+    }
+    ;
+
+try_exp
+    : try_token block EXCEPT AS base_var_
+    {
+        statement_base = free_statement_list(statement_base);  // out statement_base (FILO)
+
+        $1->code.try_code.name = malloc(sizeof($5->code.base_var.var_name));
+        char *name_tmp = $1->code.try_code.name;
+        strcpy(name_tmp, $5->code.base_var.var_name);        
+
+        $1->code.try_code.except = make_statement();
+        statement_base = append_statement_list($1->code.try_code.except, statement_base);  // new statement_base (FILO)
+        $$ = $1;
+    }
+    ;
+
+try_token
+    : TRY
+    {
+        statement *try_tmp =  make_statement();
+        try_tmp->type = try_code;
+        try_tmp->code.try_code.try = make_statement();
+        statement_base = append_statement_list(try_tmp->code.try_code.try, statement_base);  // new statement_base (FILO)
+        $$ = try_tmp;
+    }
+    ;
+
 while_block
 while_block
     : while_exp block
     : while_exp block
     {
     {
         statement_base = free_statement_list(statement_base);  // new statement_base (FILO)
         statement_base = free_statement_list(statement_base);  // new statement_base (FILO)
+        $$ = $1;
     }
     }
     ;
     ;
 
 

+ 219 - 181
paser/lex.yy.c

@@ -351,8 +351,8 @@ static void yynoreturn yy_fatal_error ( const char* msg  );
 	(yy_hold_char) = *yy_cp; \
 	(yy_hold_char) = *yy_cp; \
 	*yy_cp = '\0'; \
 	*yy_cp = '\0'; \
 	(yy_c_buf_p) = yy_cp;
 	(yy_c_buf_p) = yy_cp;
-#define YY_NUM_RULES 73
-#define YY_END_OF_BUFFER 74
+#define YY_NUM_RULES 78
+#define YY_END_OF_BUFFER 79
 /* This struct is not used in this scanner,
 /* This struct is not used in this scanner,
    but its presence is necessary. */
    but its presence is necessary. */
 struct yy_trans_info
 struct yy_trans_info
@@ -360,30 +360,32 @@ struct yy_trans_info
 	flex_int32_t yy_verify;
 	flex_int32_t yy_verify;
 	flex_int32_t yy_nxt;
 	flex_int32_t yy_nxt;
 	};
 	};
-static const flex_int16_t yy_accept[196] =
+static const flex_int16_t yy_accept[217] =
     {   0,
     {   0,
-        0,    0,    0,    0,    0,    0,    0,    0,   74,   65,
-       62,   64,   65,   47,   45,   46,   23,   24,   41,   39,
-       17,   40,   58,   42,   60,   60,   18,   63,   31,   33,
-       30,   61,   61,   61,   61,   43,   44,   35,   61,   61,
-       61,   61,   61,   61,   61,   61,   61,   61,   61,   61,
-       61,   25,   26,   36,   64,   68,   66,   67,   72,   71,
-       70,   69,   73,    0,    0,    0,   25,    0,   29,   34,
-        0,   60,   28,   32,   27,   61,   61,   61,   61,   61,
-       61,   61,   61,   61,   61,   61,   61,   61,   61,    5,
-       61,   61,   61,   61,   61,   61,   61,   25,    0,    0,
-
-        0,    0,   59,   61,   61,   61,   61,   61,   61,   61,
-       61,   61,   55,   61,   61,   61,   16,   61,   37,   61,
-       61,   61,   61,   61,   61,   61,   61,   61,    0,    0,
-        0,    0,    3,   61,   53,   52,   50,   61,   61,   61,
-       61,   61,   61,    6,    7,   61,   61,   61,   54,   14,
-       61,   61,   61,   38,   48,   61,    1,    2,    6,    7,
-       51,   22,    8,   61,   57,   61,   61,    0,   49,   61,
-       61,   61,   61,   61,    4,    2,    9,   61,   61,    7,
-       20,   61,   61,   56,   15,   61,   19,   61,   11,   10,
-       21,   61,   13,   12,    0
-
+        0,    0,    0,    0,    0,    0,    0,    0,   79,   70,
+       67,   69,   70,   47,   45,   46,   23,   24,   41,   39,
+       17,   40,   63,   42,   65,   65,   18,   68,   31,   33,
+       30,   66,   66,   66,   66,   43,   44,   35,   66,   66,
+       66,   66,   66,   66,   66,   66,   66,   66,   66,   66,
+       66,   66,   25,   26,   36,   69,   73,   71,   72,   77,
+       76,   75,   74,   78,    0,    0,    0,   25,    0,   29,
+       34,    0,   65,   28,   32,   27,   66,   66,   66,   66,
+       66,   50,   66,   66,   66,   66,   66,   66,   66,   66,
+       66,   66,    5,   66,   66,   66,   66,   66,   66,   66,
+
+       66,   66,   25,    0,    0,    0,    0,    0,   64,   66,
+       66,   66,   66,   66,   66,   66,   66,   66,   60,   66,
+       66,   66,   66,   16,   66,   37,   66,   66,   66,   66,
+       66,   66,   66,   66,   66,   66,   48,   66,    0,    0,
+        0,    0,    0,    3,   66,   58,   57,   55,   66,   66,
+       66,   66,   66,   66,    6,    7,   66,   66,   66,   66,
+       59,   66,   14,   66,   66,   66,   38,   66,   53,   66,
+        1,    2,    6,    7,    0,   56,   22,    8,   66,   62,
+       66,   66,    0,   66,   54,   66,   66,   51,   66,   66,
+       66,   52,    4,    2,    0,    9,   66,   66,    7,   49,
+
+       20,   66,   66,   61,   15,   49,   66,   19,   66,   11,
+       10,   21,   66,   13,   12,    0
     } ;
     } ;
 
 
 static const YY_CHAR yy_ec[256] =
 static const YY_CHAR yy_ec[256] =
@@ -400,8 +402,8 @@ static const YY_CHAR yy_ec[256] =
        29,    1,   30,   31,   23,    1,   32,   33,   34,   35,
        29,    1,   30,   31,   23,    1,   32,   33,   34,   35,
 
 
        36,   37,   38,   39,   40,   23,   41,   42,   23,   43,
        36,   37,   38,   39,   40,   23,   41,   42,   23,   43,
-       44,   23,   45,   46,   47,   48,   49,   23,   50,   23,
-       23,   23,   51,    1,   52,   53,    1,    1,    1,    1,
+       44,   45,   46,   47,   48,   49,   50,   23,   51,   52,
+       53,   23,   54,    1,   55,   56,    1,    1,    1,    1,
         1,    1,    1,    1,    1,    1,    1,    1,    1,    1,
         1,    1,    1,    1,    1,    1,    1,    1,    1,    1,
         1,    1,    1,    1,    1,    1,    1,    1,    1,    1,
         1,    1,    1,    1,    1,    1,    1,    1,    1,    1,
         1,    1,    1,    1,    1,    1,    1,    1,    1,    1,
         1,    1,    1,    1,    1,    1,    1,    1,    1,    1,
@@ -418,134 +420,144 @@ static const YY_CHAR yy_ec[256] =
         1,    1,    1,    1,    1
         1,    1,    1,    1,    1
     } ;
     } ;
 
 
-static const YY_CHAR yy_meta[54] =
+static const YY_CHAR yy_meta[57] =
     {   0,
     {   0,
         1,    1,    1,    1,    1,    1,    1,    1,    1,    1,
         1,    1,    1,    1,    1,    1,    1,    1,    1,    1,
         1,    1,    1,    1,    1,    2,    2,    1,    1,    1,
         1,    1,    1,    1,    1,    2,    2,    1,    1,    1,
         1,    1,    2,    2,    2,    2,    2,    2,    1,    1,
         1,    1,    2,    2,    2,    2,    2,    2,    1,    1,
         1,    2,    2,    2,    2,    2,    2,    2,    2,    2,
         1,    2,    2,    2,    2,    2,    2,    2,    2,    2,
         2,    2,    2,    2,    2,    2,    2,    2,    2,    2,
         2,    2,    2,    2,    2,    2,    2,    2,    2,    2,
-        1,    1,    1
+        2,    2,    2,    1,    1,    1
     } ;
     } ;
 
 
-static const flex_int16_t yy_base[200] =
+static const flex_int16_t yy_base[221] =
     {   0,
     {   0,
-        0,  214,   52,   53,   55,   59,    0,    0,  216,  218,
-       65,  212,  193,  218,  218,  218,  218,  218,  203,  218,
-      218,  218,  218,  218,  218,   55,  218,  218,  191,  190,
-      189,    0,  177,   35,  162,  218,  218,  218,   28,   31,
-      171,  164,   33,  163,  167,  159,   32,  166,  156,  154,
-      160,  196,  218,  218,  194,  218,  218,  218,  218,  218,
-      218,  218,  218,   81,  193,  153,  192,  190,  218,  218,
-       69,   73,  218,  218,  218,    0,  150,  166,  147,  140,
-      144,   44,  155,  143,  148,   51,  142,  137,  138,    0,
-      143,  137,  137,   55,  132,  128,  136,  173,  171,  170,
-
-       52,  169,   78,  124,  145,  133,  132,  133,  134,  124,
-      117,  115,  130,  124,  124,  112,    0,  125,    0,  115,
-      114,  111,  106,  104,  116,  103,  114,  107,  145,  144,
-      109,  109,  218,  108,    0,    0,    0,  102,  101,  105,
-       93,   99,   82,    0,  122,   93,   96,   83,    0,    0,
-       94,   79,   81,    0,    0,   87,  218,  120,  218,  113,
-        0,    0,    0,   77,    0,   76,   76,  106,    0,   72,
-       79,   66,   68,   62,    0,  107,    0,   59,   59,  218,
-        0,   74,   56,    0,    0,   64,    0,   55,   60,   47,
-        0,   43,    0,    0,  218,  132,  134,  136,   54
-
+        0,  237,   55,   56,   58,   62,    0,    0,  239,  241,
+       68,  235,  216,  241,  241,  241,  241,  241,  226,  241,
+      241,  241,  241,  241,  241,   58,  241,  241,  214,  213,
+      212,    0,  200,   38,  184,  241,  241,  241,  182,   26,
+       34,  193,   35,   47,  186,  190,  182,   36,   49,  179,
+       45,  185,  221,  241,  241,  219,  241,  241,  241,  241,
+      241,  241,  241,  241,   87,  218,   41,  218,  216,  241,
+      241,   78,   82,  241,  241,  241,    0,  176,  192,  173,
+      165,    0,  170,   61,  181,  169,  174,   60,  176,  167,
+      161,  163,    0,  168,  162,  162,  163,   63,  155,  154,
+
+       53,  160,  197,  195,  194,   62,  162,  192,   99,  146,
+      168,  156,  155,  156,  157,  147,  139,  137,  153,  147,
+      147,  146,  133,    0,  147,    0,  137,  136,  129,  132,
+      126,  124,  137,  123,  127,  134,    0,  127,  165,  164,
+      129,  129,  128,  241,  127,    0,    0,    0,  121,  120,
+      124,  111,  118,  107,    0,  148,  110,  118,  121,  108,
+        0,  115,    0,  118,  102,  105,    0,   89,    0,  103,
+      241,  136,  241,  129,   91,    0,    0,    0,   92,    0,
+       91,   91,  123,   82,    0,   88,   95,    0,   81,   84,
+       77,    0,    0,  123,   75,    0,   71,   71,  241,    0,
+
+        0,   87,   69,    0,    0,  241,   81,    0,   71,   73,
+       72,    0,   53,    0,    0,  241,  141,  143,  145,   57
     } ;
     } ;
 
 
-static const flex_int16_t yy_def[200] =
+static const flex_int16_t yy_def[221] =
     {   0,
     {   0,
-      195,    1,  196,  196,  197,  197,  198,  198,  195,  195,
-      195,  195,  195,  195,  195,  195,  195,  195,  195,  195,
-      195,  195,  195,  195,  195,  195,  195,  195,  195,  195,
-      195,  199,  199,  199,  199,  195,  195,  195,  199,  199,
-      199,  199,  199,  199,  199,  199,  199,  199,  199,  199,
-      199,  195,  195,  195,  195,  195,  195,  195,  195,  195,
-      195,  195,  195,  195,  195,  195,  195,  195,  195,  195,
-      195,  195,  195,  195,  195,  199,  199,  199,  199,  199,
-      199,  199,  199,  199,  199,  199,  199,  199,  199,  199,
-      199,  199,  199,  199,  199,  199,  199,  195,  195,  195,
-
-      195,  195,  195,  199,  199,  199,  199,  199,  199,  199,
-      199,  199,  199,  199,  199,  199,  199,  199,  199,  199,
-      199,  199,  199,  199,  199,  199,  199,  199,  195,  195,
-      195,  195,  195,  199,  199,  199,  199,  199,  199,  199,
-      199,  199,  199,  199,  199,  199,  199,  199,  199,  199,
-      199,  199,  199,  199,  199,  199,  195,  195,  195,  195,
-      199,  199,  199,  199,  199,  199,  199,  195,  199,  199,
-      199,  199,  199,  199,  199,  195,  199,  199,  199,  195,
-      199,  199,  199,  199,  199,  199,  199,  199,  199,  199,
-      199,  199,  199,  199,    0,  195,  195,  195,  195
-
+      216,    1,  217,  217,  218,  218,  219,  219,  216,  216,
+      216,  216,  216,  216,  216,  216,  216,  216,  216,  216,
+      216,  216,  216,  216,  216,  216,  216,  216,  216,  216,
+      216,  220,  220,  220,  220,  216,  216,  216,  220,  220,
+      220,  220,  220,  220,  220,  220,  220,  220,  220,  220,
+      220,  220,  216,  216,  216,  216,  216,  216,  216,  216,
+      216,  216,  216,  216,  216,  216,  216,  216,  216,  216,
+      216,  216,  216,  216,  216,  216,  220,  220,  220,  220,
+      220,  220,  220,  220,  220,  220,  220,  220,  220,  220,
+      220,  220,  220,  220,  220,  220,  220,  220,  220,  220,
+
+      220,  220,  216,  216,  216,  216,  216,  216,  216,  220,
+      220,  220,  220,  220,  220,  220,  220,  220,  220,  220,
+      220,  220,  220,  220,  220,  220,  220,  220,  220,  220,
+      220,  220,  220,  220,  220,  220,  220,  220,  216,  216,
+      216,  216,  216,  216,  220,  220,  220,  220,  220,  220,
+      220,  220,  220,  220,  220,  220,  220,  220,  220,  220,
+      220,  220,  220,  220,  220,  220,  220,  220,  220,  220,
+      216,  216,  216,  216,  216,  220,  220,  220,  220,  220,
+      220,  220,  216,  220,  220,  220,  220,  220,  220,  220,
+      220,  220,  220,  216,  216,  220,  220,  220,  216,  220,
+
+      220,  220,  220,  220,  220,  216,  220,  220,  220,  220,
+      220,  220,  220,  220,  220,    0,  216,  216,  216,  216
     } ;
     } ;
 
 
-static const flex_int16_t yy_nxt[272] =
+static const flex_int16_t yy_nxt[298] =
     {   0,
     {   0,
        10,   11,   12,   13,   14,   15,   16,   17,   18,   19,
        10,   11,   12,   13,   14,   15,   16,   17,   18,   19,
        20,   21,   22,   23,   24,   25,   26,   27,   28,   29,
        20,   21,   22,   23,   24,   25,   26,   27,   28,   29,
        30,   31,   32,   33,   32,   34,   35,   32,   36,   37,
        30,   31,   32,   33,   32,   34,   35,   32,   36,   37,
-       38,   32,   39,   40,   41,   42,   43,   44,   32,   45,
-       32,   46,   47,   32,   32,   48,   49,   50,   32,   51,
-       52,   53,   54,   57,   57,   76,   60,   58,   58,   61,
-       60,   62,   78,   61,   87,   62,   64,   65,   71,   81,
-       72,   72,   83,   82,   84,   92,   88,  194,   79,  109,
-       93,  193,   64,   65,  103,  103,   71,  110,   72,   72,
-      114,  131,  122,  103,  103,  192,  191,  115,  132,  190,
-
-       66,  123,  124,  189,  125,  188,  187,  186,  176,  185,
-      184,  183,  182,  181,  180,   67,   66,  179,  178,  177,
-      168,  176,  175,  174,  173,  172,  171,  170,  169,  168,
-      167,   67,   56,   56,   59,   59,   63,   63,  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,  130,  129,   98,  128,  127,  126,  121,  120,
-      119,  118,  117,  116,  113,  112,  111,  108,  107,  106,
-      105,  104,  102,   98,  101,  100,   99,   98,   97,   96,
-
-       95,   94,   91,   90,   89,   86,   85,   80,   77,   75,
-       74,   73,   70,   69,   68,  195,   55,    9,  195,  195,
-      195,  195,  195,  195,  195,  195,  195,  195,  195,  195,
-      195,  195,  195,  195,  195,  195,  195,  195,  195,  195,
-      195,  195,  195,  195,  195,  195,  195,  195,  195,  195,
-      195,  195,  195,  195,  195,  195,  195,  195,  195,  195,
-      195,  195,  195,  195,  195,  195,  195,  195,  195,  195,
-      195
+       38,   39,   40,   41,   42,   43,   44,   45,   32,   46,
+       32,   47,   48,   32,   32,   32,   49,   50,   51,   32,
+       52,   32,   32,   53,   54,   55,   58,   58,   77,   61,
+       59,   59,   62,   61,   63,   79,   62,   83,   63,   65,
+       66,   72,   84,   73,   73,   85,   88,   86,   90,   95,
+       97,   80,  106,  100,   98,   96,   89,  215,   65,   66,
+       91,  101,  107,  109,  109,   72,  115,   73,   73,  120,
+
+      130,  141,  136,   67,  116,  137,  214,  121,  213,  142,
+      131,  132,  212,  133,  109,  109,  211,  210,  209,  208,
+      207,   68,   67,  206,  194,  205,  204,  203,  202,  201,
+      200,  199,  198,  197,  196,  195,  183,  194,  193,  192,
+       68,   57,   57,   60,   60,   64,   64,  191,  190,  189,
+      188,  187,  186,  185,  184,  183,  182,  181,  180,  179,
+      178,  177,  176,  175,  174,  173,  172,  171,  170,  169,
+      168,  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,  140,  139,  103,  138,
+
+      135,  134,  129,  128,  127,  126,  125,  124,  123,  122,
+      119,  118,  117,  114,  113,  112,  111,  110,  108,  103,
+      105,  104,  103,  102,   99,   94,   93,   92,   87,   82,
+       81,   78,   76,   75,   74,   71,   70,   69,  216,   56,
+        9,  216,  216,  216,  216,  216,  216,  216,  216,  216,
+      216,  216,  216,  216,  216,  216,  216,  216,  216,  216,
+      216,  216,  216,  216,  216,  216,  216,  216,  216,  216,
+      216,  216,  216,  216,  216,  216,  216,  216,  216,  216,
+      216,  216,  216,  216,  216,  216,  216,  216,  216,  216,
+      216,  216,  216,  216,  216,  216,  216
+
     } ;
     } ;
 
 
-static const flex_int16_t yy_chk[272] =
+static const flex_int16_t yy_chk[298] =
     {   0,
     {   0,
         1,    1,    1,    1,    1,    1,    1,    1,    1,    1,
         1,    1,    1,    1,    1,    1,    1,    1,    1,    1,
         1,    1,    1,    1,    1,    1,    1,    1,    1,    1,
         1,    1,    1,    1,    1,    1,    1,    1,    1,    1,
         1,    1,    1,    1,    1,    1,    1,    1,    1,    1,
         1,    1,    1,    1,    1,    1,    1,    1,    1,    1,
         1,    1,    1,    1,    1,    1,    1,    1,    1,    1,
         1,    1,    1,    1,    1,    1,    1,    1,    1,    1,
         1,    1,    1,    1,    1,    1,    1,    1,    1,    1,
         1,    1,    1,    1,    1,    1,    1,    1,    1,    1,
-        1,    1,    1,    3,    4,  199,    5,    3,    4,    5,
-        6,    5,   34,    6,   43,    6,   11,   11,   26,   39,
-       26,   26,   40,   39,   40,   47,   43,  192,   34,   82,
-       47,  190,   64,   64,   71,   71,   72,   82,   72,   72,
-       86,  101,   94,  103,  103,  189,  188,   86,  101,  186,
-
-       11,   94,   94,  183,   94,  182,  179,  178,  176,  174,
-      173,  172,  171,  170,  168,   11,   64,  167,  166,  164,
-      160,  158,  156,  153,  152,  151,  148,  147,  146,  145,
-      143,   64,  196,  196,  197,  197,  198,  198,  142,  141,
-      140,  139,  138,  134,  132,  131,  130,  129,  128,  127,
-      126,  125,  124,  123,  122,  121,  120,  118,  116,  115,
-      114,  113,  112,  111,  110,  109,  108,  107,  106,  105,
-      104,  102,  100,   99,   98,   97,   96,   95,   93,   92,
-       91,   89,   88,   87,   85,   84,   83,   81,   80,   79,
-       78,   77,   68,   67,   66,   65,   55,   52,   51,   50,
-
-       49,   48,   46,   45,   44,   42,   41,   35,   33,   31,
-       30,   29,   19,   13,   12,    9,    2,  195,  195,  195,
-      195,  195,  195,  195,  195,  195,  195,  195,  195,  195,
-      195,  195,  195,  195,  195,  195,  195,  195,  195,  195,
-      195,  195,  195,  195,  195,  195,  195,  195,  195,  195,
-      195,  195,  195,  195,  195,  195,  195,  195,  195,  195,
-      195,  195,  195,  195,  195,  195,  195,  195,  195,  195,
-      195
+        1,    1,    1,    1,    1,    1,    3,    4,  220,    5,
+        3,    4,    5,    6,    5,   34,    6,   40,    6,   11,
+       11,   26,   40,   26,   26,   41,   43,   41,   44,   48,
+       49,   34,   67,   51,   49,   48,   43,  213,   65,   65,
+       44,   51,   67,   72,   72,   73,   84,   73,   73,   88,
+
+       98,  106,  101,   11,   84,  101,  211,   88,  210,  106,
+       98,   98,  209,   98,  109,  109,  207,  203,  202,  198,
+      197,   11,   65,  195,  194,  191,  190,  189,  187,  186,
+      184,  183,  182,  181,  179,  175,  174,  172,  170,  168,
+       65,  217,  217,  218,  218,  219,  219,  166,  165,  164,
+      162,  160,  159,  158,  157,  156,  154,  153,  152,  151,
+      150,  149,  145,  143,  142,  141,  140,  139,  138,  136,
+      135,  134,  133,  132,  131,  130,  129,  128,  127,  125,
+      123,  122,  121,  120,  119,  118,  117,  116,  115,  114,
+      113,  112,  111,  110,  108,  107,  105,  104,  103,  102,
+
+      100,   99,   97,   96,   95,   94,   92,   91,   90,   89,
+       87,   86,   85,   83,   81,   80,   79,   78,   69,   68,
+       66,   56,   53,   52,   50,   47,   46,   45,   42,   39,
+       35,   33,   31,   30,   29,   19,   13,   12,    9,    2,
+      216,  216,  216,  216,  216,  216,  216,  216,  216,  216,
+      216,  216,  216,  216,  216,  216,  216,  216,  216,  216,
+      216,  216,  216,  216,  216,  216,  216,  216,  216,  216,
+      216,  216,  216,  216,  216,  216,  216,  216,  216,  216,
+      216,  216,  216,  216,  216,  216,  216,  216,  216,  216,
+      216,  216,  216,  216,  216,  216,  216
+
     } ;
     } ;
 
 
 static yy_state_type yy_last_accepting_state;
 static yy_state_type yy_last_accepting_state;
@@ -573,9 +585,9 @@ char *yytext;
     int flat = 0;
     int flat = 0;
     int is_last = 0;  // 是否\n
     int is_last = 0;  // 是否\n
     int is_stop = 0;  // 针对}需要返回一个}的同时返回一个STOP
     int is_stop = 0;  // 针对}需要返回一个}的同时返回一个STOP
-#line 576 "lex.yy.c"
+#line 588 "lex.yy.c"
 
 
-#line 578 "lex.yy.c"
+#line 590 "lex.yy.c"
 
 
 #define INITIAL 0
 #define INITIAL 0
 #define COMMENT 1
 #define COMMENT 1
@@ -800,7 +812,7 @@ YY_DECL
 	{
 	{
 #line 13 "gwarf_lex.l"
 #line 13 "gwarf_lex.l"
 
 
-#line 803 "lex.yy.c"
+#line 815 "lex.yy.c"
 
 
 	while ( /*CONSTCOND*/1 )		/* loops until end-of-file is reached */
 	while ( /*CONSTCOND*/1 )		/* loops until end-of-file is reached */
 		{
 		{
@@ -828,13 +840,13 @@ yy_match:
 			while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state )
 			while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state )
 				{
 				{
 				yy_current_state = (int) yy_def[yy_current_state];
 				yy_current_state = (int) yy_def[yy_current_state];
-				if ( yy_current_state >= 196 )
+				if ( yy_current_state >= 217 )
 					yy_c = yy_meta[yy_c];
 					yy_c = yy_meta[yy_c];
 				}
 				}
 			yy_current_state = yy_nxt[yy_base[yy_current_state] + yy_c];
 			yy_current_state = yy_nxt[yy_base[yy_current_state] + yy_c];
 			++yy_cp;
 			++yy_cp;
 			}
 			}
-		while ( yy_base[yy_current_state] != 218 );
+		while ( yy_base[yy_current_state] != 241 );
 
 
 yy_find_action:
 yy_find_action:
 		yy_act = yy_accept[yy_current_state];
 		yy_act = yy_accept[yy_current_state];
@@ -1108,152 +1120,178 @@ YY_RULE_SETUP
 case 48:
 case 48:
 YY_RULE_SETUP
 YY_RULE_SETUP
 #line 73 "gwarf_lex.l"
 #line 73 "gwarf_lex.l"
-{return TRUE;}
+{return TRY;}
 	YY_BREAK
 	YY_BREAK
 case 49:
 case 49:
+/* rule 49 can match eol */
 YY_RULE_SETUP
 YY_RULE_SETUP
 #line 74 "gwarf_lex.l"
 #line 74 "gwarf_lex.l"
-{return FALSE;}
+{return EXCEPT;}
 	YY_BREAK
 	YY_BREAK
 case 50:
 case 50:
 YY_RULE_SETUP
 YY_RULE_SETUP
 #line 75 "gwarf_lex.l"
 #line 75 "gwarf_lex.l"
-{return TRUE;}
+{return AS;}
 	YY_BREAK
 	YY_BREAK
 case 51:
 case 51:
 YY_RULE_SETUP
 YY_RULE_SETUP
 #line 76 "gwarf_lex.l"
 #line 76 "gwarf_lex.l"
-{return FALSE;}
+{return RAISE;}
 	YY_BREAK
 	YY_BREAK
 case 52:
 case 52:
 YY_RULE_SETUP
 YY_RULE_SETUP
 #line 77 "gwarf_lex.l"
 #line 77 "gwarf_lex.l"
-{return NULL_token;}
+{return THROW;}
 	YY_BREAK
 	YY_BREAK
 case 53:
 case 53:
 YY_RULE_SETUP
 YY_RULE_SETUP
 #line 78 "gwarf_lex.l"
 #line 78 "gwarf_lex.l"
-{return NULL_token;}
+{return TRUE;}
 	YY_BREAK
 	YY_BREAK
 case 54:
 case 54:
 YY_RULE_SETUP
 YY_RULE_SETUP
 #line 79 "gwarf_lex.l"
 #line 79 "gwarf_lex.l"
-{return NULL_token;}
+{return FALSE;}
 	YY_BREAK
 	YY_BREAK
 case 55:
 case 55:
 YY_RULE_SETUP
 YY_RULE_SETUP
 #line 80 "gwarf_lex.l"
 #line 80 "gwarf_lex.l"
-{return DEF;}
+{return TRUE;}
 	YY_BREAK
 	YY_BREAK
 case 56:
 case 56:
 YY_RULE_SETUP
 YY_RULE_SETUP
 #line 81 "gwarf_lex.l"
 #line 81 "gwarf_lex.l"
-{return RETURN;}
+{return FALSE;}
 	YY_BREAK
 	YY_BREAK
 case 57:
 case 57:
 YY_RULE_SETUP
 YY_RULE_SETUP
 #line 82 "gwarf_lex.l"
 #line 82 "gwarf_lex.l"
-{return CLASS;}
+{return NULL_token;}
 	YY_BREAK
 	YY_BREAK
 case 58:
 case 58:
 YY_RULE_SETUP
 YY_RULE_SETUP
 #line 83 "gwarf_lex.l"
 #line 83 "gwarf_lex.l"
-{return POINT;}
+{return NULL_token;}
 	YY_BREAK
 	YY_BREAK
 case 59:
 case 59:
 YY_RULE_SETUP
 YY_RULE_SETUP
+#line 84 "gwarf_lex.l"
+{return NULL_token;}
+	YY_BREAK
+case 60:
+YY_RULE_SETUP
 #line 85 "gwarf_lex.l"
 #line 85 "gwarf_lex.l"
+{return DEF;}
+	YY_BREAK
+case 61:
+YY_RULE_SETUP
+#line 86 "gwarf_lex.l"
+{return RETURN;}
+	YY_BREAK
+case 62:
+YY_RULE_SETUP
+#line 87 "gwarf_lex.l"
+{return CLASS;}
+	YY_BREAK
+case 63:
+YY_RULE_SETUP
+#line 88 "gwarf_lex.l"
+{return POINT;}
+	YY_BREAK
+case 64:
+YY_RULE_SETUP
+#line 90 "gwarf_lex.l"
 {
 {
     yylval.double_value = atof(yytext);
     yylval.double_value = atof(yytext);
     return NUMBER;
     return NUMBER;
     }
     }
 	YY_BREAK
 	YY_BREAK
-case 60:
+case 65:
 YY_RULE_SETUP
 YY_RULE_SETUP
-#line 89 "gwarf_lex.l"
+#line 94 "gwarf_lex.l"
 {
 {
     yylval.double_value = atof(yytext);
     yylval.double_value = atof(yytext);
     return INT;
     return INT;
     }
     }
 	YY_BREAK
 	YY_BREAK
-case 61:
+case 66:
 YY_RULE_SETUP
 YY_RULE_SETUP
-#line 93 "gwarf_lex.l"
+#line 98 "gwarf_lex.l"
 {
 {
     yylval.string_value = yytext;
     yylval.string_value = yytext;
     return VAR;
     return VAR;
     }
     }
 	YY_BREAK
 	YY_BREAK
-case 62:
-/* rule 62 can match eol */
+case 67:
+/* rule 67 can match eol */
 YY_RULE_SETUP
 YY_RULE_SETUP
-#line 97 "gwarf_lex.l"
+#line 102 "gwarf_lex.l"
 {return STOPN;}
 {return STOPN;}
 	YY_BREAK
 	YY_BREAK
-case 63:
+case 68:
 YY_RULE_SETUP
 YY_RULE_SETUP
-#line 98 "gwarf_lex.l"
+#line 103 "gwarf_lex.l"
 {return STOPF;}
 {return STOPF;}
 	YY_BREAK
 	YY_BREAK
-case 64:
+case 69:
 YY_RULE_SETUP
 YY_RULE_SETUP
-#line 99 "gwarf_lex.l"
+#line 104 "gwarf_lex.l"
 ;
 ;
 	YY_BREAK
 	YY_BREAK
-case 65:
+case 70:
 YY_RULE_SETUP
 YY_RULE_SETUP
-#line 100 "gwarf_lex.l"
+#line 105 "gwarf_lex.l"
 {printf("other text = [%s];\n", yytext);}
 {printf("other text = [%s];\n", yytext);}
 	YY_BREAK
 	YY_BREAK
-case 66:
-/* rule 66 can match eol */
+case 71:
+/* rule 71 can match eol */
 YY_RULE_SETUP
 YY_RULE_SETUP
-#line 102 "gwarf_lex.l"
+#line 107 "gwarf_lex.l"
 {BEGIN INITIAL;}
 {BEGIN INITIAL;}
 	YY_BREAK
 	YY_BREAK
-case 67:
+case 72:
 YY_RULE_SETUP
 YY_RULE_SETUP
-#line 103 "gwarf_lex.l"
+#line 108 "gwarf_lex.l"
 {BEGIN INITIAL;}
 {BEGIN INITIAL;}
 	YY_BREAK
 	YY_BREAK
-case 68:
+case 73:
 YY_RULE_SETUP
 YY_RULE_SETUP
-#line 104 "gwarf_lex.l"
+#line 109 "gwarf_lex.l"
 ;
 ;
 	YY_BREAK
 	YY_BREAK
-case 69:
+case 74:
 YY_RULE_SETUP
 YY_RULE_SETUP
-#line 106 "gwarf_lex.l"
+#line 111 "gwarf_lex.l"
 {BEGIN INITIAL;}
 {BEGIN INITIAL;}
 	YY_BREAK
 	YY_BREAK
-case 70:
+case 75:
 YY_RULE_SETUP
 YY_RULE_SETUP
-#line 107 "gwarf_lex.l"
+#line 112 "gwarf_lex.l"
 {BEGIN INITIAL;}
 {BEGIN INITIAL;}
 	YY_BREAK
 	YY_BREAK
-case 71:
-/* rule 71 can match eol */
+case 76:
+/* rule 76 can match eol */
 YY_RULE_SETUP
 YY_RULE_SETUP
-#line 108 "gwarf_lex.l"
+#line 113 "gwarf_lex.l"
 {
 {
     yylval.string_value = yytext;
     yylval.string_value = yytext;
     return STRING;
     return STRING;
     }
     }
 	YY_BREAK
 	YY_BREAK
-case 72:
+case 77:
 YY_RULE_SETUP
 YY_RULE_SETUP
-#line 112 "gwarf_lex.l"
+#line 117 "gwarf_lex.l"
 {
 {
     yylval.string_value = yytext;
     yylval.string_value = yytext;
     return STRING;
     return STRING;
     }
     }
 	YY_BREAK
 	YY_BREAK
-case 73:
+case 78:
 YY_RULE_SETUP
 YY_RULE_SETUP
-#line 116 "gwarf_lex.l"
+#line 121 "gwarf_lex.l"
 ECHO;
 ECHO;
 	YY_BREAK
 	YY_BREAK
-#line 1256 "lex.yy.c"
+#line 1294 "lex.yy.c"
 case YY_STATE_EOF(INITIAL):
 case YY_STATE_EOF(INITIAL):
 case YY_STATE_EOF(COMMENT):
 case YY_STATE_EOF(COMMENT):
 case YY_STATE_EOF(STRING_TEXT):
 case YY_STATE_EOF(STRING_TEXT):
@@ -1554,7 +1592,7 @@ static int yy_get_next_buffer (void)
 		while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state )
 		while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state )
 			{
 			{
 			yy_current_state = (int) yy_def[yy_current_state];
 			yy_current_state = (int) yy_def[yy_current_state];
-			if ( yy_current_state >= 196 )
+			if ( yy_current_state >= 217 )
 				yy_c = yy_meta[yy_c];
 				yy_c = yy_meta[yy_c];
 			}
 			}
 		yy_current_state = yy_nxt[yy_base[yy_current_state] + yy_c];
 		yy_current_state = yy_nxt[yy_base[yy_current_state] + yy_c];
@@ -1582,11 +1620,11 @@ static int yy_get_next_buffer (void)
 	while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state )
 	while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state )
 		{
 		{
 		yy_current_state = (int) yy_def[yy_current_state];
 		yy_current_state = (int) yy_def[yy_current_state];
-		if ( yy_current_state >= 196 )
+		if ( yy_current_state >= 217 )
 			yy_c = yy_meta[yy_c];
 			yy_c = yy_meta[yy_c];
 		}
 		}
 	yy_current_state = yy_nxt[yy_base[yy_current_state] + yy_c];
 	yy_current_state = yy_nxt[yy_base[yy_current_state] + yy_c];
-	yy_is_jam = (yy_current_state == 195);
+	yy_is_jam = (yy_current_state == 216);
 
 
 		return yy_is_jam ? 0 : yy_current_state;
 		return yy_is_jam ? 0 : yy_current_state;
 }
 }
@@ -2264,7 +2302,7 @@ void yyfree (void * ptr )
 
 
 #define YYTABLES_NAME "yytables"
 #define YYTABLES_NAME "yytables"
 
 
-#line 116 "gwarf_lex.l"
+#line 121 "gwarf_lex.l"
 
 
 int yywrap(void) {
 int yywrap(void) {
     return 1;
     return 1;

Plik diff jest za duży
+ 350 - 309
paser/y.tab.c


+ 12 - 2
paser/y.tab.h

@@ -101,7 +101,12 @@ extern int yydebug;
     RETURN = 307,
     RETURN = 307,
     CLASS = 308,
     CLASS = 308,
     POINT = 309,
     POINT = 309,
-    COLON = 310
+    COLON = 310,
+    TRY = 311,
+    EXCEPT = 312,
+    AS = 313,
+    RAISE = 314,
+    THROW = 315
   };
   };
 #endif
 #endif
 /* Tokens.  */
 /* Tokens.  */
@@ -158,6 +163,11 @@ extern int yydebug;
 #define CLASS 308
 #define CLASS 308
 #define POINT 309
 #define POINT 309
 #define COLON 310
 #define COLON 310
+#define TRY 311
+#define EXCEPT 312
+#define AS 313
+#define RAISE 314
+#define THROW 315
 
 
 /* Value type.  */
 /* Value type.  */
 #if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED
 #if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED
@@ -172,7 +182,7 @@ union YYSTYPE
     struct if_list *if_list_base;
     struct if_list *if_list_base;
     struct parameter *parameter_list;
     struct parameter *parameter_list;
 
 
-#line 176 "y.tab.h"
+#line 186 "y.tab.h"
 
 
 };
 };
 typedef union YYSTYPE YYSTYPE;
 typedef union YYSTYPE YYSTYPE;

Niektóre pliki nie zostały wyświetlone z powodu dużej ilości zmienionych plików