瀏覽代碼

提交bug

SongZihuan 5 年之前
父節點
當前提交
37a1726835
共有 4 個文件被更改,包括 61 次插入1 次删除
  1. 1 0
      inter/interpreter.c
  2. 2 0
      paser/lexical.c
  3. 54 0
      paser/syntax.c
  4. 4 1
      paser/token.h

+ 1 - 0
inter/interpreter.c

@@ -810,6 +810,7 @@ GWARF_result import_func(statement *the_statement, var_list *the_var){
     
     login(new_the_var);
     
+    printf("ad = %s\n", file.value.string);
     parser(file.value.string);
     printf("----start run----\n");
     traverse_global(global_inter->global_code, new_the_var);

+ 2 - 0
paser/lexical.c

@@ -164,6 +164,8 @@ int paser(int *index, p_status *status){
         match_text(p, global_paser[ASSERT_PASER], "assert");
         match_text_s(p, global_paser[LAMBDA_PASER], "->");
         match_text(p, global_paser[POINT_PASER], ".");
+        match_text(p, global_paser[IMPORT_PASER], "import");
+        match_text(p, global_paser[INCLUDE_PASER], "include");
 
         *index = check_list(global_paser, p, status);  // 检查解析结果
 

+ 54 - 0
paser/syntax.c

@@ -42,6 +42,7 @@ 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 paser_error(char *text);
 
 /*
@@ -149,6 +150,14 @@ void command(p_status *old_status, token_node *list){  // 多项式
         get_stop_token(status, list);
         push_statement(statement_base, new_token);
     }
+    else if(left.type == IMPORT_PASER || left.type == INCLUDE_PASER){
+        fprintf(status_log, "[info][grammar]  (command)back one token to (import_include)\n");
+        back_one_token(list, left);
+        get_base_token(&status, list, import_include, new_token);
+
+        get_stop_token(status, list);
+        push_statement(statement_base, new_token);
+    }
     else if(left.type == RETURN_PASER){
         fprintf(status_log, "[info][grammar]  (command)back one token to (return_)\n");
         back_one_token(list, left);
@@ -663,6 +672,51 @@ void formal_parameter(p_status *status, token_node *list){  // 因试分解
     }
 }
 
+/*
+import “aaa” as AA 和 include 语句
+*/
+void import_include(p_status *status, token_node *list){
+    fprintf(status_log, "[info][grammar]  mode status: while_\n");
+    token type_t, str_t, as_t, var_t, new_token;
+    type_t = pop_node(list);
+    if(type_t.type == IMPORT_PASER || type_t.type == INCLUDE_PASER){
+        get_right_token(status,list,top_exp,str_t);
+        if(str_t.type != NON_top_exp){  // 不是表达式
+            paser_error("Don't get top_exp");
+        }
+
+        statement *tmp =  make_statement();
+        if(type_t.type == IMPORT_PASER){  // import才有as top_exp
+            get_pop_token(status, list, as_t);
+            if(as_t.type != AS_PASER){
+                paser_error("Don't get as");
+            }
+
+            get_right_token(status,list,top_exp,var_t);
+            if(var_t.type != NON_top_exp){  // 不是表达式
+                paser_error("Don't get top_exp");
+            }
+            tmp->type = import_class;
+            tmp->code.import_class.file = str_t.data.statement_value;
+            tmp->code.import_class.var = var_t.data.statement_value;
+        }
+        else{
+            tmp->type = include_import;
+            tmp->code.include_import.file = str_t.data.statement_value;
+        }
+
+        new_token.type = NON_import;
+        new_token.data_type = statement_value;
+        new_token.data.statement_value = tmp;
+        add_node(list, new_token);  // 压入节点[弹出3个压入1个]
+        return;
+    }
+    else{
+        back_one_token(list, type_t);
+        return;
+    }
+}
+
 /*
 while_ : WHILE LB top_exp RB block
 */

+ 4 - 1
paser/token.h

@@ -3,7 +3,7 @@
 
 #include "../inter/interpreter.h"
 
-#define MAX_PASER_SIZE 81
+#define MAX_PASER_SIZE 83
 #define INT_PASER 0
 #define DOUBLE_PASER 1
 #define ENTER_PASER 2
@@ -85,6 +85,8 @@
 #define FSUB_PASER 78
 #define LAMBDA_PASER 79
 #define POINT_PASER 80
+#define IMPORT_PASER 81
+#define INCLUDE_PASER 82
 
 // 获取并返回一个token
 #define get_pop_token(status,list,new_token) \
@@ -265,6 +267,7 @@ typedef enum token_type
     NON_self_exp = -44,
     NON_lambda = -45,
     NON_point = -46,
+    NON_import = -47,
 } token_type;
 
 typedef union token_data