Bläddra i källkod

设置了args不允许虚解包,更新了README.md

SongZihuan 5 år sedan
förälder
incheckning
56b0d61385
3 ändrade filer med 32 tillägg och 14 borttagningar
  1. 2 1
      README.md
  2. 4 3
      paser/paser.h
  3. 26 10
      paser/syntax.c

+ 2 - 1
README.md

@@ -52,6 +52,7 @@ return x n  函数返回值x,返回n层
 ## GWARF 大事记
 * GWARF立项和完成了基本结构
 * GWARF重写了PASER解析器(至今)
-
+* 修改了解析器中的status的成员的意义,修复了call back的bug[具体参见commit message]
+* 虚解包,允许语法:a,b,\* = 1,2,3,4,5,6。也支持形参表,但不支持实参表。
 ## 关于GWARF
 最后更新时间 : 2020年05月04日 广州

+ 4 - 3
paser/paser.h

@@ -1,7 +1,7 @@
 #ifndef MEM_INCLUDE
 #define MEM_INCLUDE
 
-#define reset_status(status) {status.not_match_eq=false,status.not_match_tuple=false,status.not_match_call=false,status.match_list=false,status.match_dict=false,status.is_left=true,status.is_peq=false,status.is_for=false,status.dict_to_enter=false,status.ignore_enter=false,status.is_slice=false;}
+#define reset_status(status) {status.not_match_eq=false,status.not_match_tuple=false,status.not_match_call=false,status.match_list=false,status.match_dict=false,status.is_left=true,status.is_peq=false,status.is_for=false,status.dict_to_enter=false,status.ignore_enter=false,status.is_slice=false,status.is_args=false;}
 
 FILE *debug = NULL, *status_log = NULL, *token_log = NULL, *token_info = NULL;
 
@@ -15,11 +15,12 @@ typedef struct p_status
     bool is_left;  // 是否为最左边的公式
     bool is_peq;  // 正在使用解包赋值
     bool is_for;  // for循环,用于排除COMMA的使用[top_exp]
-    FILE *file_p;
-    struct word_paser **global_paser;
     bool ignore_enter;  // 忽略回车
     bool dict_to_enter;  // 检查stop的时候把"}"算上
     bool is_slice;  // slice使用:代替
+    bool is_args;  // args不允许虚解包
+    FILE *file_p;
+    struct word_paser **global_paser;
 } p_status;
 
 

+ 26 - 10
paser/syntax.c

@@ -548,12 +548,16 @@ void formal_parameter(p_status *status, token_node *list){  // 因试分解
             new_status.not_match_tuple = true;
             token tmp_next;
             get_right_token(&new_status, list, top_exp, tmp_next);
-            if(tmp_next.type != NON_top_exp){  // 结尾分号 -> xun
-                back_again(list, tmp_next);
-                next.type = NON_top_exp;
-                next.data_type = statement_value;
-                next.data.statement_value = make_statement();  // NULL返回None
-                puts("FFFFFFFFFf");
+            if(tmp_next.type != NON_top_exp){  // 结尾分号 -> 虚解包
+                if(!status->is_args){
+                    back_again(list, tmp_next);
+                    next.type = NON_top_exp;
+                    next.data_type = statement_value;
+                    next.data.statement_value = make_statement();  // NULL返回None
+                }
+                else{
+                    paser_error("args shouldn't get * or ** with not var name");
+                }
             }
             else{
                 next = tmp_next;
@@ -607,10 +611,21 @@ void formal_parameter(p_status *status, token_node *list){  // 因试分解
         new_status = *status;
         new_status.not_match_eq = true;
         new_status.not_match_tuple = true;
-        get_right_token(&new_status, list, top_exp, next);  // 不需要back_one_token
-        if(next.type != NON_top_exp){
-            back_one_token(list, next);  // 往回[不匹配类型]
-            return;
+        token tmp_next;
+        get_right_token(&new_status, list, top_exp, tmp_next);
+        if(tmp_next.type != NON_top_exp){  // 结尾分号 -> 虚解包
+            if(!status->is_args){
+                back_again(list, tmp_next);
+                next.type = NON_top_exp;
+                next.data_type = statement_value;
+                next.data.statement_value = make_statement();  // NULL返回None
+            }
+            else{
+                paser_error("args shouldn't get * or ** with not var name");
+            }
+        }
+        else{
+            next = tmp_next;
         }
         new_token.type = NON_parameter;
         new_token.data_type = parameter_list;
@@ -2400,6 +2415,7 @@ void call_back_(p_status *status, token_node *list){  // 因试分解
                 reset_status(new_status);  // 不会影响 *staus
                 new_status.not_match_tuple = true;
                 new_status.is_left = false;
+                new_status.is_args = true;
                 get_right_token(&new_status,list,formal_parameter,parameter_t);
                 if(parameter_t.type != NON_parameter){
                     paser_error("Don't get formal_parameter");