Prechádzať zdrojové kódy

下调了call back优先级

SongZihuan 5 rokov pred
rodič
commit
0b3df7a3ee
1 zmenil súbory, kde vykonal 74 pridanie a 73 odobranie
  1. 74 73
      paser/syntax.c

+ 74 - 73
paser/syntax.c

@@ -1320,9 +1320,9 @@ void hide_list(p_status *status, token_node *list){
     new_status = *status;
 
     new_status.is_left = false;
-    get_base_token(&new_status,list,call_back_,exp);
+    get_base_token(&new_status,list,lambda_,exp);
     new_status.is_left = old_is_left;
-    if(exp.type != NON_call){
+    if(exp.type != NON_lambda){
         back_one_token(list, exp);
         return;
     }
@@ -1355,74 +1355,6 @@ void hide_list(p_status *status, token_node *list){
     add_node(list, exp);  // 压入节点
     return;
 }
-/*
-call_back_ : bool_or
-           | call_back_ LB RB
-*/
-void call_back_(p_status *status, token_node *list){  // 因试分解
-    fprintf(status_log, "[info][grammar]  mode status: call_back_\n");
-    token left, symbol, rb_t, new_token, parameter_t;
-    parameter *p_list;
-
-    left = pop_node(list);  // 先弹出一个token   检查token的类型:区分是模式1,还是模式2/3
-    if(left.type == NON_call){
-        fprintf(status_log, "[info][grammar]  (call_back_)reduce right\n");
-        get_pop_token(status, list, symbol);
-
-        if(symbol.type == LB_PASER && !status->is_func){
-
-            get_pop_token(status, list, rb_t);
-            if(rb_t.type != RB_PASER){  // 带参数
-                back_again(list, rb_t);
-                get_right_token(status,list,formal_parameter,parameter_t);
-                if(parameter_t.type != NON_parameter){
-                    paser_error("Don't get formal_parameter");
-                }
-                printf("rb_t.type = %d\n", rb_t.type);
-                get_pop_token(status, list, rb_t);
-                if(rb_t.type != RB_PASER){
-                    paser_error("Don't get ')'[2]");
-                }
-                p_list = parameter_t.data.parameter_list;
-            }
-            else{
-                p_list = NULL;  // 没参数
-            }
-
-            // 逻辑操作
-            new_token.type = NON_call;
-            new_token.data_type = statement_value;
-
-            statement *code_tmp =  make_statement();
-            code_tmp->type = call;
-            code_tmp->code.call.func = left.data.statement_value;
-            code_tmp->code.call.parameter_list = p_list;
-            
-            new_token.data.statement_value = code_tmp;
-            add_node(list, new_token);  // 压入节点[弹出3个压入1个]
-            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 (lambda_)\n");
-        back_one_token(list, left);
-        get_base_token(status, list, lambda_, new_token);
-        if(new_token.type != NON_lambda){
-            back_one_token(list, new_token);  // 往回[不匹配类型]
-            return;
-        }
-        new_token.type = NON_call;
-        add_node(list, new_token);
-        return call_back_(status, list);  // 回调自己
-    }
-}
 
 void lambda_(p_status *status, token_node *list){
     fprintf(status_log, "[info][grammar]  mode status: lambda_\n");
@@ -2428,10 +2360,10 @@ void call_down(p_status *status, token_node *list){  // 因试分解
         }
     }
     else{  // 模式1
-        fprintf(status_log, "[info][grammar]  (call_down)back one token to (element)\n");
+        fprintf(status_log, "[info][grammar]  (call_down)back one token to (call_back_)\n");
         back_one_token(list, left);
-        get_base_token(status, list, element, new_token);
-        if(new_token.type != NON_element){
+        get_base_token(status, list, call_back_, new_token);
+        if(new_token.type != NON_call){
             back_one_token(list, new_token);  // 往回[不匹配类型]
             return;
         }
@@ -2441,6 +2373,75 @@ void call_down(p_status *status, token_node *list){  // 因试分解
     }
 }
 
+/*
+call_back_ : bool_or
+           | call_back_ LB RB
+*/
+void call_back_(p_status *status, token_node *list){  // 因试分解
+    fprintf(status_log, "[info][grammar]  mode status: call_back_\n");
+    token left, symbol, rb_t, new_token, parameter_t;
+    parameter *p_list;
+
+    left = pop_node(list);  // 先弹出一个token   检查token的类型:区分是模式1,还是模式2/3
+    if(left.type == NON_call){
+        fprintf(status_log, "[info][grammar]  (call_back_)reduce right\n");
+        get_pop_token(status, list, symbol);
+
+        if(symbol.type == LB_PASER && !status->is_func){
+
+            get_pop_token(status, list, rb_t);
+            if(rb_t.type != RB_PASER){  // 带参数
+                back_again(list, rb_t);
+                get_right_token(status,list,formal_parameter,parameter_t);
+                if(parameter_t.type != NON_parameter){
+                    paser_error("Don't get formal_parameter");
+                }
+                printf("rb_t.type = %d\n", rb_t.type);
+                get_pop_token(status, list, rb_t);
+                if(rb_t.type != RB_PASER){
+                    paser_error("Don't get ')'[2]");
+                }
+                p_list = parameter_t.data.parameter_list;
+            }
+            else{
+                p_list = NULL;  // 没参数
+            }
+
+            // 逻辑操作
+            new_token.type = NON_call;
+            new_token.data_type = statement_value;
+
+            statement *code_tmp =  make_statement();
+            code_tmp->type = call;
+            code_tmp->code.call.func = left.data.statement_value;
+            code_tmp->code.call.parameter_list = p_list;
+            
+            new_token.data.statement_value = code_tmp;
+            add_node(list, new_token);  // 压入节点[弹出3个压入1个]
+            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 (element)\n");
+        back_one_token(list, left);
+        get_base_token(status, list, element, new_token);
+        if(new_token.type != NON_element){
+            back_one_token(list, new_token);  // 往回[不匹配类型]
+            return;
+        }
+        new_token.type = NON_call;
+        add_node(list, new_token);
+        return call_back_(status, list);  // 回调自己
+    }
+}
+
 /*
 element : number
         | LB top_exp RB