1
0
Эх сурвалжийг харах

调整了call back和point的运算级为同级从左到右,修复了无法调用object的__value__方法的问题

SongZihuan 5 жил өмнө
parent
commit
21e47b151b
4 өөрчлөгдсөн 27 нэмэгдсэн , 49 устгасан
  1. 3 1
      README.md
  2. 11 2
      demo/6.gwf
  3. 2 2
      inter/cfunc.c
  4. 11 44
      paser/syntax.c

+ 3 - 1
README.md

@@ -81,6 +81,9 @@ return x n  函数返回值x,返回n层
 * 修改了无法return的bug
 * in 语句
 * 可以捕捉import和include的代码语法异常
+* 疑似bug:``a.__iter__.__next__``会出现内存错误, 已经修复,原因是: 内置函数无self属性
+* ``a.__iter__().__next__()``会出现解析错误, 已经修复,调整了``.``运算符和``call_back``为同级优先级
+* 解决了object的``__value__``无法调用的问题:原因是注册函数的时候使用了数字而不是枚举体[现在,使用``{__value__func, 1}``取代了数字``{3, 1}``]
 ## GWARF计划
 * 类型转换(list, str, int之间的转换)
 * 魔法方法:``__eq__(用于特殊赋值),__int__,__str__,__double__,__repo__,__list__,__tuple__,__dict__,__key__,__in__``
@@ -96,6 +99,5 @@ return x n  函数返回值x,返回n层
 * 宏定义
 * 生成语法树
 * yield生成器和列表推导试
-* 疑似bug:``a.__iter__.__next__``会出现内存错误,``a.__iter__().__next__()``会出现解析错误
 ## 关于GWARF
 最后更新时间 : 2020年05月08日 广州

+ 11 - 2
demo/6.gwf

@@ -1,3 +1,12 @@
-a = [1,2,3,5,6]
-a.__iter__.__next__
+class a()
+{
+def run(self,b=3,c=10)
+{
+b * c
+return self;
+}
+}
+q = a()
+z = q.__value__()
+print(z)
 

+ 2 - 2
inter/cfunc.c

@@ -240,7 +240,7 @@ class_object *object_login_official(var_list *the_var, GWARF_result (*paser)(fun
 
 
     // 注册函数
-    int a[][2] = {{3,1}, {__assignment__func, 1}};
+    int a[][2] = {{__value__func,1}, {__assignment__func, 1}};
     char *name[] = {"__value__", "__assignment__"};
 
     int lenth = sizeof(a)/sizeof(a[0]);
@@ -280,7 +280,7 @@ GWARF_result object_official_func(func *the_func, parameter *tmp_s, var_list *th
             size = (size_t)(9 + len_intx(ad));
             return_value.value.type = STRING_value;
             return_value.value.value.string = (char *)malloc(size);
-            snprintf(return_value.value.value.string, size, "<-%u->", ad);
+            snprintf(return_value.value.value.string, size, "<-%x->", ad);
             break;
         }
         case __assignment__func:

+ 11 - 44
paser/syntax.c

@@ -41,7 +41,6 @@ void try_(p_status *status, token_node *list);
 void out_exception(p_status *status, token_node *list);
 void self_exp(p_status *status, token_node *list);
 void lambda_(p_status *status, token_node *list);
-void attribute(p_status *status, token_node *list);
 void import_include(p_status *status, token_node *list);
 void chose_exp_(p_status *status, token_node *list);
 void svar_token(p_status *status, token_node *list);
@@ -2544,9 +2543,9 @@ void call_back_(p_status *status, token_node *list){  // 因试分解
                 paser_error(status, "Don't get the element");
             }
 
-            get_right_token(status, list, attribute, second_args);
-            if(second_args.type != NON_point){
-                paser_error(status, "Don't get the attribute[1]");
+            get_right_token(status, list, call_down, second_args);
+            if(second_args.type != NON_call_down){
+                paser_error(status, "Don't get the call_down[1]");
             }
 
             parameter *first, *second;
@@ -2570,47 +2569,15 @@ void call_back_(p_status *status, token_node *list){  // 因试分解
             return call_back_(status, list);  // 回调自己            
 
         }
-        else{  // 递归跳出
-            // 回退,也就是让下一次pop的时候读取到的是left而不是symbol
-            fprintf(status_log, "[info][grammar]  (call_back_)out\n");
-            back_one_token(list, left);
-            back_again(list, symbol);
-            return;
-        }
-    }
-    else{  // 模式1
-        fprintf(status_log, "[info][grammar]  (call_back_)back one token to (attribute)\n");
-        back_one_token(list, left);
-        get_base_token(status, list, attribute, new_token);
-        if(new_token.type != NON_point){
-            back_one_token(list, new_token);  // 往回[不匹配类型]
-            return;
-        }
-        new_token.type = NON_call;
-        add_node(list, new_token);
-        return call_back_(status, list);  // 回调自己
-    }
-}
-
-/*
-attribute : bit_or
-          | attribute POINT bit_or
-*/
-void attribute(p_status *status, token_node *list){  // 因试分解
-    fprintf(status_log, "[info][grammar]  mode status: attribute\n");
-    token left, right, symbol, new_token;
-
-    left = pop_node(list);  // 先弹出一个token   检查token的类型:区分是模式1,还是模式2/3
-    if(left.type == NON_point){  // 模式2/3
-        fprintf(status_log, "[info][grammar]  (attribute)reduce right\n");
-        get_pop_token(status, list, symbol);
         if(symbol.type == POINT_PASER){  // 模式2/3
+            token right;
             get_right_token(status, list, call_down, right);  // 回调右边
             if(right.type != NON_call_down){
                 paser_error(status, "Don't get a call_down");
             }
+            fprintf(debug, "[tag 1]\n");
             // 逻辑操作
-            new_token.type = NON_point;
+            new_token.type = NON_call;
             new_token.data_type = statement_value;
 
             statement *code_tmp =  make_statement();
@@ -2620,27 +2587,27 @@ void attribute(p_status *status, token_node *list){  // 因试分解
             
             new_token.data.statement_value = code_tmp;
             add_node(list, new_token);  // 压入节点[弹出3个压入1个]
-            return attribute(status, list);  // 回调自己
+            return call_back_(status, list);  // 回调自己
         }
         else{  // 递归跳出
             // 回退,也就是让下一次pop的时候读取到的是left而不是symbol
-            fprintf(status_log, "[info][grammar]  (attribute)out\n");
+            fprintf(status_log, "[info][grammar]  (call_back_)out\n");
             back_one_token(list, left);
             back_again(list, symbol);
             return;
         }
     }
     else{  // 模式1
-        fprintf(status_log, "[info][grammar]  (attribute)back one token to (call_down)\n");
+        fprintf(status_log, "[info][grammar]  (call_back_)back one token to (call_down)\n");
         back_one_token(list, left);
         get_base_token(status, list, call_down, new_token);
         if(new_token.type != NON_call_down){
             back_one_token(list, new_token);  // 往回[不匹配类型]
             return;
         }
-        new_token.type = NON_point;
+        new_token.type = NON_call;
         add_node(list, new_token);
-        return attribute(status, list);  // 回调自己
+        return call_back_(status, list);  // 回调自己
     }
 }