浏览代码

成员调用

SongZihuan 5 年之前
父节点
当前提交
e0fe445f90
共有 3 个文件被更改,包括 61 次插入3 次删除
  1. 1 0
      paser/lexical.c
  2. 56 2
      paser/syntax.c
  3. 4 1
      paser/token.h

+ 1 - 0
paser/lexical.c

@@ -163,6 +163,7 @@ int paser(int *index, p_status *status){
         match_text(p, global_paser[THROW_PASER], "throw");
         match_text(p, global_paser[THROW_PASER], "throw");
         match_text(p, global_paser[ASSERT_PASER], "assert");
         match_text(p, global_paser[ASSERT_PASER], "assert");
         match_text_s(p, global_paser[LAMBDA_PASER], "->");
         match_text_s(p, global_paser[LAMBDA_PASER], "->");
+        match_text(p, global_paser[POINT_PASER], ".");
 
 
         *index = check_list(global_paser, p, status);  // 检查解析结果
         *index = check_list(global_paser, p, status);  // 检查解析结果
 
 

+ 56 - 2
paser/syntax.c

@@ -41,6 +41,7 @@ void try_(p_status *status, token_node *list);
 void out_exception(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 self_exp(p_status *status, token_node *list);
 void lambda_(p_status *status, token_node *list);
 void lambda_(p_status *status, token_node *list);
+void attribute(p_status *status, token_node *list);
 void paser_error(char *text);
 void paser_error(char *text);
 
 
 /*
 /*
@@ -2156,8 +2157,8 @@ void self_exp(p_status *status, token_node *list){  // 因试分解
     }
     }
     else{  // a--和a++
     else{  // a--和a++
         back_one_token(list,left);
         back_one_token(list,left);
-        get_base_token(status, list, call_down, new_token);
-        if(new_token.type != NON_call_down){
+        get_base_token(status, list, attribute, new_token);
+        if(new_token.type != NON_point){
             back_one_token(list, new_token);  // 往回[不匹配类型]
             back_one_token(list, new_token);  // 往回[不匹配类型]
             return;
             return;
         }
         }
@@ -2167,6 +2168,59 @@ void self_exp(p_status *status, token_node *list){  // 因试分解
     }
     }
 }
 }
 
 
+/*
+attribute : bit_or
+          | attribute POINT bit_or
+*/
+void attribute(p_status *status, token_node *list){  // 因试分解
+    fprintf(status_log, "[info][grammar]  mode status: bit_or\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
+            get_right_token(status, list, call_down, right);  // 回调右边
+            if(right.type != NON_call_down){
+                paser_error("Don't get a call_down");
+            }
+            // 逻辑操作
+            new_token.type = NON_point;
+            new_token.data_type = statement_value;
+
+            statement *code_tmp =  make_statement();
+            code_tmp->type = point;
+            code_tmp->code.point.base_var = left.data.statement_value;
+            code_tmp->code.point.child_var = right.data.statement_value;
+            
+            new_token.data.statement_value = code_tmp;
+            add_node(list, new_token);  // 压入节点[弹出3个压入1个]
+            return attribute(status, list);  // 回调自己
+        }
+        else{  // 递归跳出
+            // 回退,也就是让下一次pop的时候读取到的是left而不是symbol
+            fprintf(status_log, "[info][grammar]  (attribute)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");
+        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;
+        add_node(list, new_token);
+        return attribute(status, list);  // 回调自己
+    }
+}
+
 /*
 /*
 call_down : element
 call_down : element
           | call_down LI top_exp RI
           | call_down LI top_exp RI

+ 4 - 1
paser/token.h

@@ -3,7 +3,7 @@
 
 
 #include "../inter/interpreter.h"
 #include "../inter/interpreter.h"
 
 
-#define MAX_PASER_SIZE 80
+#define MAX_PASER_SIZE 81
 #define INT_PASER 0
 #define INT_PASER 0
 #define DOUBLE_PASER 1
 #define DOUBLE_PASER 1
 #define ENTER_PASER 2
 #define ENTER_PASER 2
@@ -84,6 +84,7 @@
 #define FADD_PASER 77
 #define FADD_PASER 77
 #define FSUB_PASER 78
 #define FSUB_PASER 78
 #define LAMBDA_PASER 79
 #define LAMBDA_PASER 79
+#define POINT_PASER 80
 
 
 // 获取并返回一个token
 // 获取并返回一个token
 #define get_pop_token(status,list,new_token) \
 #define get_pop_token(status,list,new_token) \
@@ -215,6 +216,7 @@ typedef enum token_type
     FADD = FADD_PASER,
     FADD = FADD_PASER,
     FSUB = FSUB_PASER,
     FSUB = FSUB_PASER,
     LAMBDA = LAMBDA_PASER,
     LAMBDA = LAMBDA_PASER,
+    POINT = POINT_PASER,
 
 
     // 特殊符号
     // 特殊符号
     BAD_token = -2,
     BAD_token = -2,
@@ -262,6 +264,7 @@ typedef enum token_type
     NON_exception = -43,
     NON_exception = -43,
     NON_self_exp = -44,
     NON_self_exp = -44,
     NON_lambda = -45,
     NON_lambda = -45,
+    NON_point = -46,
 } token_type;
 } token_type;
 
 
 typedef union token_data
 typedef union token_data