Browse Source

bug修复

SongZihuan 5 years ago
parent
commit
dfe7c75d67
6 changed files with 20 additions and 21 deletions
  1. 2 6
      README.md
  2. BIN
      gwarf
  3. 5 1
      gwarf.c
  4. 3 3
      inter/cfunc.c
  5. 0 9
      inter/interpreter.c
  6. 10 2
      inter/interpreter.h

+ 2 - 6
README.md

@@ -2,13 +2,12 @@
 ## 语法结构
 ### 保留关键词
 ```
-import 'file'  导入模块
 import 'file' as xxx  导入模块并且明明为xxx
 include 'file' 包含模块,等同于python的 from xxx import *
 
 while  条件循环
 for  循环
-forin  遍历
+for i in xxx  遍历
 
 if  条件分支
 
@@ -16,12 +15,9 @@ block  普通代码块
 
 try  异常捕获
 except  异常捕获
-raise  诱发错误[抛出class时会转换为object, 需要指定ErrorInfo]
+raise  诱发错误[抛出class时会转换为object, 需要指定[ErrorInfo]
 throw  抛出错误
 
-as  引用[强引用]; 异常捕获
-link  引用[弱引用]
-
 break n  跳出n层循环代码快[无视for循环第三表达式]
 broken n  跳出n层代码块[无视for循环第三表达式]
 continue n  重新执行循环代码快

BIN
gwarf


+ 5 - 1
gwarf.c

@@ -43,4 +43,8 @@ void login(var_list *the_var){
     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
-}
+}
+
+// 编译指令:cd "/home/songzihuan/文档/CProject/gwarf/" && gcc gwarf.c -lm -o gwarf && "/home/songzihuan/文档/CProject/gwarf/"gwarf
+// yacc和lex:cd ./paser && yacc -d gwarf_yacc.y && lex gwarf_lex.l
+// 合并编译:cd "/home/songzihuan/文档/CProject/gwarf/" && cd ./paser && yacc -d gwarf_yacc.y && lex gwarf_lex.l && cd .. && gcc gwarf.c -lm -o gwarf && "/home/songzihuan/文档/CProject/gwarf/"gwarf

+ 3 - 3
inter/cfunc.c

@@ -1307,11 +1307,11 @@ GWARF_result list_official_func(func *the_func, parameter *tmp_s, var_list *the_
                 GWARF_result get_value, tmp_result = traverse(tmp_s->u.value, out_var, false);
                 if(is_error(&tmp_result)){  // Name Error错误
                     return_value = tmp_result;
-                    goto return_result;
+                    goto break_down;
                 }
                 else if(is_space(&tmp_result)){
                     return_value = tmp_result;
-                    goto return_result;
+                    goto break_down;
                 }
                 GWARF_value base_the_var = tmp_result.value;  // 只有一个参数
                 get_value = get__value__(&base_the_var, the_var);
@@ -1323,7 +1323,7 @@ GWARF_result list_official_func(func *the_func, parameter *tmp_s, var_list *the_
                 return_value.value.type = NULL_value;
                 return_value.value.value.int_value = 0;
             }
-            break;
+            break_down: break;
         }
         case __slice__func:{  // return index
             var *tmp = find_var(login_var, 0, "value");

+ 0 - 9
inter/interpreter.c

@@ -323,12 +323,6 @@ GWARF_result read_statement(statement *the_statement, var_list *the_var, var_lis
             func_tmp->done = the_statement->code.def.done;
             func_tmp->parameter_list = the_statement->code.def.parameter_list;
             func_tmp->the_var = copy_var_list(the_var);
-            if(find_var(func_tmp->the_var, 0,"int") == NULL){
-                puts("NOT FOUND");
-            }
-            else{
-                puts("FOUND");
-            }
             func_tmp->type = customize;  // func by user
             if(login_var != the_var){  // 定义为类方法
                 func_tmp->is_class = 1;
@@ -366,7 +360,6 @@ GWARF_result read_statement(statement *the_statement, var_list *the_var, var_lis
                     }
                 }
             }
-            printf("[tag 1]def address = %x\n", login_var);
             assigment_func(the_statement->code.def.name, func_value, login_var, from);  // 注册函数到指定的位置
             // 无返回值
             break;
@@ -1464,7 +1457,6 @@ GWARF_result operation_func(statement *the_statement, var_list *the_var, var_lis
                     }
                 }
 
-                printf("[tag 3]name = %s, address = %x, from = %d\n", left, login_var, from);
                 value = assigment_func(left, right_result, login_var, from);
             }
             else if((the_statement->code.operation.left_exp)->type == point){  // 通过point赋值
@@ -1617,7 +1609,6 @@ GWARF_result call_back_core(GWARF_result get, var_list *the_var, parameter *tmp_
 
         if(func_->type == customize){  // 用户定义的方法
             if(tmp_x == NULL){
-                puts("No tmp_x");
                 goto no_tmp_x;  // 无形参
             }
             GWARF_result father;

+ 10 - 2
inter/interpreter.h

@@ -21,7 +21,7 @@ typedef enum{
     FUNC_value,  // 函数 [6]
     CLASS_value,  // 对象 [7]
     OBJECT_value,  // 实例 [8]
-    LIST_value,  // 列表类型 [9]
+    LIST_value,  // 列表类型 [只允许系统使用] [9]
 } GWARF_value_type;
 
 // all value is GWARF_value
@@ -87,13 +87,14 @@ typedef struct statement{
         point,  // a.b  注:返回变量同时返回the_var链表[func 用于回调]
         down,  // a[b]  注:返回变量同时返回the_var链表[func 用于回调]
         slice,
-        return_code,
+        return_code,  // [26]
         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
         import_class,   // import file
         include_import,  // include file
+        for_in_cycle,  // for i in a
     } type;  // the statement type
 
     union
@@ -265,6 +266,13 @@ typedef struct statement{
             struct statement *file;  // get address for file
         } include_import;
 
+        struct
+        {
+            struct statement *name;  // for i in a -> i
+            struct statement *iter;  // for i in a -> a
+            struct statement *done;  // for while to do
+        } for_in_cycle;
+
     } code;
     struct statement *next;
 } statement;