فهرست منبع

feat & style: 增加了日志系统

可以生成pasers.log,inter.log和lexical.log文件
新增log.h头文件包含log系统的参数
删除了function.h文件
OUT_INTER_LOG定义了是否输出inter日志
OUT_TOKEN_LOG定义了是否输出token日志
OUT_PASERS_LOG定义了是否输出pasers日志
OUT_GRAMMER_LOG定义了是否输出grammar日志

OUT_LOG定义了是否输出日志

命令行参数新增--log参数, --log参数后跟log输出的文件夹。程序.vm文件地址要位与命令行参数最后。
SongZihuan 4 سال پیش
والد
کامیت
e849639667
24فایلهای تغییر یافته به همراه615 افزوده شده و 220 حذف شده
  1. 58 0
      include/__grammar.h
  2. 11 0
      include/__lexical.h
  3. 1 1
      include/__macro.h
  4. 26 0
      include/__run.h
  5. 12 0
      include/__syntax.h
  6. 20 0
      include/__token.h
  7. 12 1
      include/__virtualmath.h
  8. 0 40
      include/function.h
  9. 5 1
      include/grammar.h
  10. 17 0
      include/inter.h
  11. 3 2
      include/lexical.h
  12. 61 0
      include/log.h
  13. 6 9
      include/run.h
  14. 4 52
      include/statement.h
  15. 20 7
      include/token.h
  16. 46 0
      include/value.h
  17. 32 0
      include/var.h
  18. 83 13
      main.c
  19. 63 45
      parser/grammar.c
  20. 14 11
      parser/lexical.c
  21. 29 10
      parser/syntax.c
  22. 76 10
      parser/token.c
  23. 12 1
      src/inter.c
  24. 4 17
      src/run.c

+ 58 - 0
include/__grammar.h

@@ -0,0 +1,58 @@
+#ifndef VIRTUALMATH___GRAMMAR_H
+#define VIRTUALMATH___GRAMMAR_H
+#include "__virtualmath.h"
+
+#if OUT_LOG && OUT_PASERS_LOG
+#define doubleLog(pm, grammar_level, pasers_level, message, ...) do{ \
+writeLog(pm->grammar_debug, grammar_level, message, __VA_ARGS__); \
+writeLog(pm->paser_debug, pasers_level, "\n"message, __VA_ARGS__); \
+} while(0)
+#else
+#define doubleLog(...) PASS
+#endif
+
+#if OUT_LOG && OUT_GRAMMER_LOG
+#define writeLog_(...) writeLog(__VA_ARGS__)
+#else
+#define writeLog_(...) PASS
+#endif
+
+#define readBackToken(status, pm) do{ \
+doubleLog(pm, GRAMMAR_DEBUG, DEBUG, "token operation number : %d\n", pm->count); \
+pm->count ++; \
+status = safeGetToken(pm->tm, pm->paser_debug); \
+if (status == -2){ \
+syntaxError(pm, "lexical make some error", lexical_error); \
+} \
+backToken(pm->tm->ts, pm->paser_debug); \
+} while(0) /*预读token*/
+
+#define popAheadToken(token_var, pm) do{ \
+doubleLog(pm, GRAMMAR_DEBUG, DEBUG, "token operation number : %d\n", pm->count); \
+pm->count ++; \
+safeGetToken(pm->tm, pm->paser_debug); \
+/* 执行popheanToken之前执行readBackToken因此不必再检查status */ \
+token_var = popToken(pm->tm->ts, pm->paser_debug); \
+} while(0) /*弹出预读的token*/
+
+#define addStatementToken(type, st, pm) do{\
+Token *tmp_new_token; \
+tmp_new_token = makeStatementToken(type, st); \
+addToken(pm->tm->ts, tmp_new_token, pm->paser_debug); \
+backToken(pm->tm->ts, pm->paser_debug); \
+} while(0)
+
+#define backToken_(pm, token) do{ \
+addToken(pm->tm->ts, token, pm->paser_debug); \
+backToken(pm->tm->ts, pm->paser_debug); \
+}while(0)
+
+#define call_success(pm) (pm->status == success)
+
+void parserCommand(PASERSSIGNATURE);
+void parserOperation(PASERSSIGNATURE);
+void parserPolynomial(PASERSSIGNATURE);
+void parserBaseValue(PASERSSIGNATURE);
+
+void syntaxError(ParserMessage *pm, char *message, int status);
+#endif //VIRTUALMATH___GRAMMAR_H

+ 11 - 0
include/__lexical.h

@@ -0,0 +1,11 @@
+#ifndef VIRTUALMATH___LEXICAL_H
+#define VIRTUALMATH___LEXICAL_H
+#include "__virtualmath.h"
+
+#if OUT_LOG && OUT_TOKEN_LOG
+#define writeLog_(...) writeLog(__VA_ARGS__)
+#else
+#define writeLog_(...) PASS
+#endif
+
+#endif //VIRTUALMATH___LEXICAL_H

+ 1 - 1
include/__macro.h

@@ -9,7 +9,7 @@
 #define true 1
 #define false 0
 
-#define PASS ;
+#define PASS do{}while(0)
 
 #define NUMBER_TYPE long int
 #define HASH_INDEX unsigned int

+ 26 - 0
include/__run.h

@@ -0,0 +1,26 @@
+#ifndef VIRTUALMATH___RUN_H
+#define VIRTUALMATH___RUN_H
+
+#include "__virtualmath.h"
+
+#if OUT_INTER_LOG && OUT_INTER_LOG
+#define printResult(result, first, last, debug) do{ \
+switch (result.value->value->type){ \
+    case number: \
+        writeLog(debug, INFO, "%s%ld%s\n", first, result.value->value->data.num.num, last); \
+        break; \
+    case string: \
+        writeLog(debug, INFO, "%s%s%s\n", first, result.value->value->data.str.str, last); \
+        break; \
+    default: \
+        writeLog(debug, INFO, "%sdefault%s\n", first, last); \
+        break; \
+} \
+} while(0)
+#define writeLog_(...) writeLog(__VA_ARGS__)
+#else
+#define printResult(...)
+#define writeLog_(...)
+#endif
+
+#endif //VIRTUALMATH___RUN_H

+ 12 - 0
include/__syntax.h

@@ -0,0 +1,12 @@
+#ifndef VIRTUALMATH___SYNTAX_H
+#define VIRTUALMATH___SYNTAX_H
+#include "__virtualmath.h"
+
+#if OUT_LOG && OUT_TOKEN_LOG
+#define writeLog_(...) writeLog(__VA_ARGS__)
+#else
+#define writeLog_(...) PASS
+#undef printTokenEnter
+#define printTokenEnter(...) PASS
+#endif
+#endif //VIRTUALMATH___SYNTAX_H

+ 20 - 0
include/__token.h

@@ -0,0 +1,20 @@
+#ifndef VIRTUALMATH___TOKEN_H
+#define VIRTUALMATH___TOKEN_H
+
+#include "__virtualmath.h"
+
+#if OUT_LOG && OUT_TOKEN_LOG
+#define MACRO_printTokenStream(...) printTokenStream(__VA_ARGS__)
+#else
+#define MACRO_printTokenStream(...) PASS
+#undef printTokenEnter
+#define printTokenEnter(...) PASS
+#endif
+
+#if OUT_LOG && OUT_PASERS_LOG
+#define writeLog_(...) writeLog(__VA_ARGS__)
+#else
+#define writeLog_(...) PASS
+#endif
+
+#endif //VIRTUALMATH___TOKEN_H

+ 12 - 1
include/__virtualmath.h

@@ -1,14 +1,25 @@
 #ifndef VIRTUALMATH___VIRTUALMATH_H
 #define VIRTUALMATH___VIRTUALMATH_H
 
+#define PRIVATE_INCLUDE false
 #include "__macro.h"
 #include "mem.h"
-#include "function.h"
 #include "statement.h"
 #include "run.h"
 #include "syntax.h"
 #include "lexical.h"
 #include "token.h"
 #include "grammar.h"
+#include "var.h"
+#include "value.h"
+#include "inter.h"
+#include "log.h"
+#undef PRIVATE_INCLUDE
+
+struct Args{
+    char *file;
+    char *log_file;
+    int level;
+} args;
 
 #endif //VIRTUALMATH___VIRTUALMATH_H

+ 0 - 40
include/function.h

@@ -1,40 +0,0 @@
-#ifndef VIRTUALMATH_FUNCTION_H
-#define VIRTUALMATH_FUNCTION_H
-#include "__macro.h"
-#include "statement.h"
-#include "run.h"
-
-// 所有statement相关的function都在此处声明
-
-// value的处理
-Value *makeValue(Inter *inter);
-void freeValue(Value *value, Inter *inter);
-LinkValue *makeLinkValue(Value *value, LinkValue *linkValue,Inter *inter);
-void freeLinkValue(LinkValue *value, Inter *inter);
-Value *makeNumberValue(long num, Inter *inter);
-Value *makeStringValue(char *str, Inter *inter);
-
-void setResult(Result *ru, bool link, Inter *inter);
-
-// Inter的处理
-Inter *makeInter();
-void freeInter(Inter *inter, bool self);
-
-// statement的处理
-Statement *makeStatement();
-void connectStatement(Statement *base, Statement *new);
-void freeStatement(Statement *st);
-
-// run的处理
-Result iterStatement(INTER_FUNCTIONSIG);
-Result operationStatement(INTER_FUNCTIONSIG);
-Result globalIterStatement(Inter *inter);
-
-// var的处理
-VarList *makeVarList(Inter *inter);
-VarList *freeVarList(VarList *vl, bool self);
-LinkValue *findFromVarList(char *name, VarList *var_list, NUMBER_TYPE times);
-void addFromVarList(char *name, VarList *var_list, NUMBER_TYPE times, LinkValue *value);
-void freeHashTable(HashTable *ht, Inter *inter);
-
-#endif //VIRTUALMATH_FUNCTION_H

+ 5 - 1
include/grammar.h

@@ -7,15 +7,19 @@
 
 typedef struct ParserMessage{
     struct TokenMessage *tm;
+    FILE *paser_debug;
+    FILE *grammar_debug;
+    int count;
     enum {
         success = 1,
         syntax_error,
         command_list_error,
+        lexical_error,
     } status;
     char *status_message;
 } ParserMessage;
 
-ParserMessage *makeParserMessage(char *file_dir);
+ParserMessage *makeParserMessage(char *file_dir, char *debug);
 void freePasersMessage(ParserMessage *pm, bool self);
 void pasersCommandList(ParserMessage *pm, Inter *inter, bool global, Statement *st);
 #endif //VIRTUALMATH_GRAMMAR_H

+ 17 - 0
include/inter.h

@@ -0,0 +1,17 @@
+#ifndef VIRTUALMATH_INTER_H
+#define VIRTUALMATH_INTER_H
+
+typedef struct globalInterpreter{
+    struct VirtualMathValue *base;
+    struct VirtualMathLinkValue *link_base;
+    struct VirtualMathHashTable *hash_base;
+    Statement *statement;
+    struct VirtualMathVarList *var_list;
+    char *log_dir;  // 记录log文件夹的位置
+    FILE *debug;
+} Inter;
+
+Inter *makeInter(char *debug);
+void freeInter(Inter *inter, bool self);
+
+#endif //VIRTUALMATH_INTER_H

+ 3 - 2
include/lexical.h

@@ -9,6 +9,7 @@ typedef struct LexFile{
         bool is_back;
         char p;
     } back;
+    int count;
 } LexFile;
 
 typedef struct LexMather{
@@ -21,7 +22,7 @@ typedef struct LexMather{
         LEXMATHER_ING,
         LEXMATHER_INGPOINT,
         LEXMATHER_INGSECOND,
-        LEXMATHER_PASS,
+        LEXMATHER_INGPASS,
         LEXMATHER_END,
         LEXMATHER_END_SECOND,
         LEXMATHER_MISTAKE,
@@ -46,5 +47,5 @@ void freeMather(LexMather *mather, bool self);
 LexMathers *makeMathers(int size);
 void freeMathers(LexMathers *mathers, bool self);
 void setupMathers(LexMathers *mathers);
-int checkoutMather(LexMathers *mathers, int max);
+int checkoutMather(LexMathers *mathers, int max, FILE *debug);
 #endif //VIRTUALMATH_LEXICAL_H

+ 61 - 0
include/log.h

@@ -0,0 +1,61 @@
+#ifndef VIRTUALMATH_LOG_H
+#define VIRTUALMATH_LOG_H
+#include "__macro.h"
+
+#define DEEP_DEBUG -3
+#define LEXICAL_CHECKOUT_DEBUG -3
+#define LEXICAL_DEBUG -2
+#define GRAMMAR_DEBUG -1
+#define DEBUG 0
+#define INFO 1
+#define WARNING 2
+#define ERROR 3
+
+#ifndef OUT_INTER_LOG
+#define OUT_INTER_LOG true
+#endif
+
+#ifndef OUT_TOKEN_LOG
+#define OUT_TOKEN_LOG true
+#endif
+
+#ifndef OUT_PASERS_LOG
+#define OUT_PASERS_LOG true
+#endif
+
+#ifndef OUT_GRAMMER_LOG
+#define OUT_GRAMMER_LOG true
+#endif
+
+#ifndef OUT_LOG
+#define OUT_LOG true
+#endif
+
+#if OUT_LOG
+#define writeLog(file, info_level, message, ...) do{ \
+if (file == NULL || info_level < args.level){ \
+break; \
+} \
+else{ \
+fprintf(file, message, __VA_ARGS__); \
+} \
+} while(0)
+
+#else
+/* 不输出日志 */
+#define writeLog(...) PASS
+#define doubleLog(...) PASS
+#endif
+
+#ifdef unix
+#define GRAMMAR_LOG "/grammar.log"
+#define PASERS_LOG "/pasers.log"
+#define LEXICAL_LOG "/lexical.log"
+#define INTER_LOG "/inter.log"
+#else
+#define GRAMMAR_LOG "\grammar.log"
+#define PASERS_LOG "\pasers.log"
+#define LEXICAL_LOG "\lexical.log"
+#define INTER_LOG "\inter.log"
+#endif
+#endif //VIRTUALMATH_LOG_H

+ 6 - 9
include/run.h

@@ -1,14 +1,11 @@
 #ifndef VIRTUALMATH_RUN_H
 #define VIRTUALMATH_RUN_H
-#include "statement.h"
-
-typedef struct globalInterpreter{
-    struct VirtualMathValue *base;
-    struct VirtualMathLinkValue *link_base;
-    struct VirtualMathHashTable *hash_base;
-    Statement *statement;
-    VarList *var_list;
-} Inter;
+#include "__macro.h"
+#include "value.h"
+#include "var.h"
 
+Result iterStatement(INTER_FUNCTIONSIG);
+Result operationStatement(INTER_FUNCTIONSIG);
+Result globalIterStatement(Inter *inter);
 
 #endif //VIRTUALMATH_RUN_H

+ 4 - 52
include/statement.h

@@ -1,58 +1,6 @@
 #ifndef VIRTUALMATH_STATEMENT_H
 #define VIRTUALMATH_STATEMENT_H
 #include "__macro.h"
-#define MAX_SIZE (1024)
-
-struct Statement;
-
-typedef struct VirtualMathValue{
-    enum ValueType{
-        number=1,
-        string,
-    } type;
-    union data{
-        struct Number{
-            NUMBER_TYPE num;
-        } num;
-        struct String{
-            char *str;
-        } str;
-    }data;
-    struct VirtualMathValue *next;
-    struct VirtualMathValue *last;
-} Value;
-
-typedef struct VirtualMathLinkValue{
-    struct VirtualMathValue *value;
-    struct VirtualMathLinkValue *father;
-    struct VirtualMathLinkValue *next;
-    struct VirtualMathLinkValue *last;
-} LinkValue;
-
-typedef struct VirtualMathResult{
-    enum ResultType{
-        statement_end = 1,
-    } type;
-    struct VirtualMathLinkValue *value;
-} Result;
-
-typedef struct VirtualMathVar{
-    char *name;
-    struct VirtualMathLinkValue *value;
-    struct VirtualMathVar *next;
-} Var;
-
-typedef struct VirtualMathHashTable{
-    struct VirtualMathVar **hashtable;
-    int count;
-    struct VirtualMathHashTable *next;
-    struct VirtualMathHashTable *last;
-} HashTable;
-
-typedef struct VirtualMathVarList{
-    struct VirtualMathHashTable *hashtable;
-    struct VirtualMathVarList *next;
-} VarList;
 
 typedef struct Statement{
     enum StatementType{
@@ -84,4 +32,8 @@ typedef struct Statement{
     struct Statement *next;
 } Statement;
 
+Statement *makeStatement();
+void connectStatement(Statement *base, Statement *new);
+void freeStatement(Statement *st);
+
 #endif //VIRTUALMATH_STATEMENT_H

+ 20 - 7
include/token.h

@@ -1,6 +1,7 @@
 #ifndef VIRTUALMATH_TOKEN_H
 #define VIRTUALMATH_TOKEN_H
 
+#define MATHER_ERROR_ -1
 #define MATHER_NUMBER 0
 #define MATHER_STRING 1
 #define MATHER_VAR 2
@@ -112,6 +113,7 @@ typedef struct TokenMessage{
     TokenStream *ts;
     struct LexFile *file;
     struct LexMathers *mathers;
+    FILE *debug;
 } TokenMessage;
 
 Token *makeToken();
@@ -119,15 +121,26 @@ Token *makeLexToken(int type, char *str, char *second_str);
 Token *makeStatementToken(int type, struct Statement *st);
 void freeToken(Token *tk, bool self, bool error);
 
-extern Token *getToken(struct LexFile *file, struct LexMathers *mathers);
+extern Token *getToken(LexFile *file, LexMathers *mathers, FILE *debug);
 
 
-int safeGetToken(TokenMessage *tm);
-Token *forwardToken(TokenStream *ts);
-Token *backToken(TokenStream *ts);
-void addToken(TokenStream *ts, Token *new_tk);
-Token *popToken(TokenStream *ts);
+int safeGetToken(TokenMessage *tm, FILE *debug);
+Token *forwardToken(TokenStream *ts, FILE *debug);
+Token *backToken(TokenStream *ts, FILE *debug);
+void addToken(TokenStream *ts, Token *new_tk, FILE *debug);
+Token *popToken(TokenStream *ts, FILE *debug);
 
-TokenMessage *makeTokenMessage(char *file_dir);
+TokenMessage *makeTokenMessage(char *file_dir, char *debug);
 void freeTokenMessage(TokenMessage *tm, bool self);
+
+// token 可视化函数
+void printTokenStream(TokenStream *ts, FILE *debug, int type);
+void printToken(Token *tk, FILE *debug, int type);
+
+#define printTokenEnter(tk, debug, type, message) do{ \
+writeLog(debug, type, message, NULL); \
+printToken(tk, debug, type); \
+writeLog(debug, type, "\n", NULL); \
+} while(0)
+
 #endif //VIRTUALMATH_TOKEN_H

+ 46 - 0
include/value.h

@@ -0,0 +1,46 @@
+#ifndef VIRTUALMATH_VALUE_H
+#define VIRTUALMATH_VALUE_H
+#include "inter.h"
+
+typedef struct VirtualMathValue{
+    enum ValueType{
+        number=1,
+        string,
+    } type;
+    union data{
+        struct Number{
+            NUMBER_TYPE num;
+        } num;
+        struct String{
+            char *str;
+        } str;
+    }data;
+    struct VirtualMathValue *next;
+    struct VirtualMathValue *last;
+} Value;
+
+typedef struct VirtualMathLinkValue{
+    struct VirtualMathValue *value;
+    struct VirtualMathLinkValue *father;
+    struct VirtualMathLinkValue *next;
+    struct VirtualMathLinkValue *last;
+} LinkValue;
+
+typedef struct VirtualMathResult{
+    enum ResultType{
+        statement_end = 1,
+    } type;
+    struct VirtualMathLinkValue *value;
+} Result;
+
+Value *makeValue(Inter *inter);
+void freeValue(Value *value, Inter *inter);
+LinkValue *makeLinkValue(Value *value, LinkValue *linkValue,Inter *inter);
+void freeLinkValue(LinkValue *value, Inter *inter);
+Value *makeNumberValue(long num, Inter *inter);
+Value *makeStringValue(char *str, Inter *inter);
+
+void setResult(Result *ru, bool link, Inter *inter);
+
+
+#endif //VIRTUALMATH_VALUE_H

+ 32 - 0
include/var.h

@@ -0,0 +1,32 @@
+#ifndef VIRTUALMATH_VAR_H
+#define VIRTUALMATH_VAR_H
+#include "inter.h"
+#include "value.h"
+
+#define MAX_SIZE (1024)
+
+typedef struct VirtualMathVar{
+    char *name;
+    struct VirtualMathLinkValue *value;
+    struct VirtualMathVar *next;
+} Var;
+
+typedef struct VirtualMathHashTable{
+    struct VirtualMathVar **hashtable;
+    int count;
+    struct VirtualMathHashTable *next;
+    struct VirtualMathHashTable *last;
+} HashTable;
+
+typedef struct VirtualMathVarList{
+    struct VirtualMathHashTable *hashtable;
+    struct VirtualMathVarList *next;
+} VarList;
+
+VarList *makeVarList(Inter *inter);
+VarList *freeVarList(VarList *vl, bool self);
+LinkValue *findFromVarList(char *name, VarList *var_list, NUMBER_TYPE times);
+void addFromVarList(char *name, VarList *var_list, NUMBER_TYPE times, LinkValue *value);
+void freeHashTable(HashTable *ht, Inter *inter);
+
+#endif //VIRTUALMATH_VAR_H

+ 83 - 13
main.c

@@ -1,22 +1,39 @@
 #include "__virtualmath.h"
+#include <getopt.h>
 
-int testMain(int argc, char *argv[]);
+static const struct option long_option[]={
+        {"input",required_argument,NULL,'i'},
 
-int main(int argc, char *argv[]) {
-    testMain(argc, argv);
-    return 0;
-}
+#if OUT_LOG
+        {"log",required_argument,NULL,'l'},
+        {"debug",no_argument,&args.level,DEBUG},
+        {"ddebug",no_argument,&args.level,DEEP_DEBUG},
+        {"ldebug",no_argument,&args.level,LEXICAL_DEBUG},
+        {"lcdebug",no_argument,&args.level,LEXICAL_CHECKOUT_DEBUG},
+        {"info",no_argument,&args.level,INFO},
+#endif
+        // 最后一个元素应该全为0
+        {NULL,0,NULL,0}
+};
+
+#if OUT_LOG
+static const char *short_option = "i:l:";
+#else
+static const char *short_option = "i:";
+#endif
+int getArgs(int argc, char *argv[]);
+void freeArgs();
 
-int testMain(int argc, char *argv[]) {
-    if (argc != 2) {
-        printf("Too many or little argc\n");
-        goto argc_error_;
+int main(int argc, char *argv[]) {
+    if (getArgs(argc, argv)){
+        goto args_error_;
     }
-    Inter *global_iter = makeInter();
-    ParserMessage *pm = makeParserMessage(argv[1]);
+
+    Inter *global_iter = makeInter(args.log_file);
+    ParserMessage *pm = makeParserMessage(args.file, args.log_file);
     pasersCommandList(pm, global_iter, true, global_iter->statement);
     if (pm->status != success){
-        printf("Syntax Error: %s\n", pm->status_message);
+        writeLog(pm->paser_debug, ERROR, "Syntax Error: %s\n", pm->status_message);
         goto return_;
     }
     globalIterStatement(global_iter);
@@ -24,8 +41,61 @@ int testMain(int argc, char *argv[]) {
     return_:
     freePasersMessage(pm, true);
     freeInter(global_iter, true);
+    freeArgs();
     return 0;
 
-    argc_error_:
+    args_error_:
+    freeArgs();
     return 1;
 }
+
+/**
+ * 参数设置, args是全局结构体, 保存全局的参数设置
+ * @param argc
+ * @param argv
+ * @return
+ */
+int getArgs(int argc, char *argv[])
+{
+    args.file = NULL;
+    args.log_file = NULL;
+    args.level = LEXICAL_CHECKOUT_DEBUG;
+    opterr = false;
+    int opt;
+    while((opt=getopt_long(argc,argv,short_option ,long_option,NULL))!=-1)
+    {
+        switch(opt)
+        {
+            case 0:
+                break;
+            case 'i':
+                args.file = memStrcpy(optarg, 0, false, false);
+                break;
+            case 'l':
+                args.log_file = memStrcpy(optarg, 0, false, false);
+                break;
+            case '?':
+                printf("[Error]: get not success args : -%c\n", (char)optopt);
+                return -1;
+            default:
+                break;
+        }
+    }
+    if (args.file == NULL){
+        if (argc > optind){
+            args.file = memStrcpy(argv[optind], 0, false, false);
+        }
+        else{
+            return -1;
+        }
+    }
+    return 0;
+}
+
+/**
+ * 释放args的成员而不包括其本身
+ */
+void freeArgs(){
+    memFree(args.file);
+    memFree(args.file);
+}

+ 63 - 45
parser/grammar.c

@@ -1,46 +1,38 @@
-#include "__virtualmath.h"
+#include "__grammar.h"
 
-#define readBackToken(status, pm) do{ \
-status = safeGetToken(pm->tm); \
-backToken(pm->tm->ts); \
-} while(0) /*预读token*/
-
-#define popAheadToken(token_var, pm) do{ \
-safeGetToken(pm->tm); \
-token_var = popToken(pm->tm->ts); \
-} while(0) /*弹出预读的token*/
-
-#define addStatementToken(type, st, pm) do{\
-Token *tmp_new_token; \
-tmp_new_token = makeStatementToken(type, st); \
-addToken(pm->tm->ts, tmp_new_token); \
-backToken(pm->tm->ts); \
-} while(0)
-
-#define backToken_(pm, token) do{ \
-addToken(pm->tm->ts, token); \
-backToken(pm->tm->ts); \
-}while(0)
-
-#define call_success(pm) (pm->status == success)
-
-void parserCommand(PASERSSIGNATURE);
-void parserOperation(PASERSSIGNATURE);
-void parserPolynomial(PASERSSIGNATURE);
-void parserBaseValue(PASERSSIGNATURE);
-
-void syntaxError(ParserMessage *pm, char *message, int status);
-
-ParserMessage *makeParserMessage(char *file_dir){
+ParserMessage *makeParserMessage(char *file_dir, char *debug){
     ParserMessage *tmp = memCalloc(1, sizeof(ParserMessage));
-    tmp->tm = makeTokenMessage(file_dir);
+    tmp->tm = makeTokenMessage(file_dir, debug);
     tmp->status = success;
     tmp->status_message = NULL;
+    tmp->count = 0;
+#if OUT_LOG
+    if (debug != NULL){
+        char *debug_dir = memStrcat(debug, PASERS_LOG), *grammar_dir = memStrcat(debug, GRAMMAR_LOG);
+        tmp->paser_debug = fopen(debug_dir, "w");
+        tmp->grammar_debug = fopen(grammar_dir, "w");
+        memFree(debug_dir);
+        memFree(debug_dir);
+    }
+    else{
+        tmp->paser_debug = NULL;
+        tmp->grammar_debug = NULL;
+    }
+#else
+    tmp->paser_debug = NULL;
+    tmp->grammar_debug = NULL;
+#endif
     return tmp;
 }
 
 void freePasersMessage(ParserMessage *pm, bool self) {
     freeTokenMessage(pm->tm, true);
+#if OUT_LOG
+    if (pm->paser_debug != NULL)
+        fclose(pm->paser_debug);
+    if (pm->grammar_debug != NULL)
+        fclose(pm->grammar_debug);
+#endif
     memFree(pm->status_message);
     if (self){
         memFree(pm);
@@ -60,20 +52,21 @@ void pasersCommandList(ParserMessage *pm, Inter *inter, bool global, Statement *
     while (true){
         readBackToken(token_type, pm);
         if (token_type == MATHER_EOF){
-            // printf("get EOF\n");
+            writeLog_(pm->grammar_debug, GRAMMAR_DEBUG, "Command List: <EOF>\n", NULL);
             Token *tmp;
             popAheadToken(tmp, pm);
             freeToken(tmp, true, false);
             goto return_;
         }
         else if (token_type == MATHER_ENTER){
-            // 处理空语句
+            writeLog_(pm->grammar_debug, GRAMMAR_DEBUG, "Command List: <ENTER>\n", NULL);
             Token *tmp;
             popAheadToken(tmp, pm);
             freeToken(tmp, true, false);
             continue;
         }
         else{
+            writeLog_(pm->grammar_debug, GRAMMAR_DEBUG, "Command List: call command\n", NULL);
             Token *command_token,*stop_token;
             parserCommand(CALLPASERSSIGNATURE);
             if (!call_success(pm)){
@@ -98,17 +91,30 @@ void pasersCommandList(ParserMessage *pm, Inter *inter, bool global, Statement *
                 backToken_(pm, stop_token);
             }
             else{
-                syntaxError(pm, "ERROR from parserCommand list(get stop)", command_list_error);
-                freeToken(command_token, true, true);
+                if (global) {
+                    syntaxError(pm, "ERROR from parserCommand list(get stop)", command_list_error);
+                    freeToken(command_token, true, true);
+                }
+                else{
+                    // 若非global模式, 即可以匹配大括号
+                    popAheadToken(stop_token, pm);
+                    backToken_(pm, stop_token);
+                    connectStatement(base_st, command_token->data.st);
+                    freeToken(command_token, true, false);
+                    writeLog_(pm->grammar_debug, GRAMMAR_DEBUG,
+                            "Command List: get command success[at !global end]\n", NULL);
+                }
                 goto return_;
             }
             /*...do something for commandList...*/
             // printf("do something for commandList\n");
             connectStatement(base_st, command_token->data.st);
             freeToken(command_token, true, false);
+            writeLog_(pm->grammar_debug, GRAMMAR_DEBUG, "Command List: get command success\n", NULL);
         }
     }
     return_:
+    writeLog_(pm->grammar_debug, GRAMMAR_DEBUG, "Command List: return\n", NULL);
     addStatementToken(COMMANDLIST, base_st, pm);
 }
 
@@ -122,9 +128,10 @@ void parserCommand(PASERSSIGNATURE){
     Statement *st = NULL;
     readBackToken(token_type, pm);
     if (false){
-        PASS
+        PASS;
     }
     else{
+        writeLog_(pm->grammar_debug, GRAMMAR_DEBUG, "Command: call operation\n", NULL);
         int command_int;
         Token *command_token;
         parserOperation(CALLPASERSSIGNATURE);
@@ -142,9 +149,9 @@ void parserCommand(PASERSSIGNATURE){
         freeToken(command_token, true, false);
     }
     addStatementToken(COMMAND, st, pm);
-
+    writeLog_(pm->grammar_debug, GRAMMAR_DEBUG, "Command: get  command success\n", NULL);
     return_:
-    return;
+    writeLog_(pm->grammar_debug, GRAMMAR_DEBUG, "Command: get return\n", NULL);
 }
 
 /**
@@ -154,6 +161,7 @@ void parserCommand(PASERSSIGNATURE){
  */
 void parserOperation(PASERSSIGNATURE){
     int operation_int;
+    writeLog_(pm->grammar_debug, GRAMMAR_DEBUG, "Operation: call polynomial\n", NULL);
     parserPolynomial(CALLPASERSSIGNATURE);
     if (!call_success(pm)){
         goto return_;
@@ -169,9 +177,10 @@ void parserOperation(PASERSSIGNATURE){
 
     addStatementToken(OPERATION, operation_token->data.st, pm);
     freeToken(operation_token, true, false);
+    writeLog_(pm->grammar_debug, GRAMMAR_DEBUG, "Operation: get polynomial success\n", NULL);
 
     return_:
-    return;
+    writeLog_(pm->grammar_debug, GRAMMAR_DEBUG, "Operation: return\n", NULL);
 }
 
 /**
@@ -188,6 +197,7 @@ void parserPolynomial(PASERSSIGNATURE){
         struct Statement *st = NULL;
         readBackToken(left, pm);
         if (left != POLYNOMIAL){
+            writeLog_(pm->grammar_debug, GRAMMAR_DEBUG, "Polynomial: cal base value(left)\n", NULL);
             // 情况[1]
             parserBaseValue(CALLPASERSSIGNATURE);  // 获得左值
             if (!call_success(pm)){
@@ -200,9 +210,11 @@ void parserPolynomial(PASERSSIGNATURE){
             popAheadToken(left_token, pm);
             addStatementToken(POLYNOMIAL, left_token->data.st, pm);
             freeToken(left_token, true, false);
+            writeLog_(pm->grammar_debug, GRAMMAR_DEBUG,
+                    "Polynomial: get base value(left) success[push polynomial]\n", NULL);
             continue;
-            // printf("polynomial: get base value\n");
         }
+        writeLog_(pm->grammar_debug, GRAMMAR_DEBUG, "Polynomial: call symbol\n", NULL);
         popAheadToken(left_token, pm);
         readBackToken(symbol, pm);
         switch (symbol) {
@@ -231,7 +243,8 @@ void parserPolynomial(PASERSSIGNATURE){
                 backToken_(pm, left_token);
                 goto return_;
         }
-
+        writeLog_(pm->grammar_debug, GRAMMAR_DEBUG,
+                "Polynomial: get symbol success\nPolynomial: call base value[right]\n", NULL);
         parserBaseValue(CALLPASERSSIGNATURE);  // 获得左值
         if (!call_success(pm)){
             freeToken(left_token, true, false);
@@ -253,6 +266,7 @@ void parserPolynomial(PASERSSIGNATURE){
         freeToken(left_token, true, false);
         freeToken(right_token, true, false);
         addStatementToken(POLYNOMIAL, st, pm);
+        writeLog_(pm->grammar_debug, GRAMMAR_DEBUG, "Polynomial: get base value(right) success[push polynomial]\n", NULL);
         // printf("polynomial: push token\n");
     }
     return_:
@@ -270,7 +284,7 @@ void parserBaseValue(PASERSSIGNATURE){
     struct Statement *st = NULL;
     readBackToken(token_type, pm);
     if(MATHER_NUMBER == token_type){
-        // 匹配到正常字面量
+        writeLog_(pm->grammar_debug, GRAMMAR_DEBUG, "Base Value: get number\n", NULL);
         Token *value_token;
         char *stop;
         popAheadToken(value_token, pm);
@@ -280,6 +294,7 @@ void parserBaseValue(PASERSSIGNATURE){
         freeToken(value_token, true, false);
     }
     else if(MATHER_STRING == token_type){
+        writeLog_(pm->grammar_debug, GRAMMAR_DEBUG, "Base Value: get string\n", NULL);
         Token *value_token;
         popAheadToken(value_token, pm);
         st = makeStatement();
@@ -288,6 +303,7 @@ void parserBaseValue(PASERSSIGNATURE){
         freeToken(value_token, true, false);
     }
     else{
+        writeLog_(pm->grammar_debug, GRAMMAR_DEBUG, "Base Value: else\n", NULL);
         goto return_;
     }
     addStatementToken(BASEVALUE, st, pm);
@@ -302,6 +318,8 @@ void parserBaseValue(PASERSSIGNATURE){
  * @param status 错误类型
  */
 void syntaxError(ParserMessage *pm, char *message, int status){
+    if (pm->status != success)
+        return;
     pm->status = status;
     pm->status_message = memStrcpy(message, 0, false, false);
 }

+ 14 - 11
parser/lexical.c

@@ -1,4 +1,4 @@
-#include "__virtualmath.h"
+#include "__lexical.h"
 
 /**
  * 从文件中读取一个字节,并处理is_back
@@ -28,6 +28,7 @@ LexFile *makeLexFile(char *dir){
     tmp->file = fopen(dir, "r");
     tmp->back.is_back = false;
     tmp->back.p = EOF;
+    tmp->count = 0;
     return tmp;
 }
 
@@ -110,14 +111,11 @@ void setupMathers(LexMathers *mathers){
  * @param max
  * @return
  */
-int checkoutMather(LexMathers *mathers, int max) {
+int checkoutMather(LexMathers *mathers, int max, FILE *debug) {
+    bool return_1 = false;
     int mistake_count = 0;
     int end_count = 0, end_index = -1;
     int end_second_count = 0, end_second_index = -1;
-//    printf("CHECKOUT:\n");
-//    for (int i=0;i < mathers->size;i++){
-//        printf("mathers->mathers[%d]->status == %d\n", i, mathers->mathers[i]->status);
-//    }
     for (int i=0;i < mathers->size;i++){
         if(mathers->mathers[i]->status == LEXMATHER_END){
             end_count ++;
@@ -130,10 +128,15 @@ int checkoutMather(LexMathers *mathers, int max) {
         else if(mathers->mathers[i]->status == LEXMATHER_MISTAKE){
             mistake_count ++;
         }
-        else if(mathers->mathers[i]->status == LEXMATHER_ING || mathers->mathers[i]->status == LEXMATHER_START){
-            return -1;
+        else{
+            return_1 = true;
         }
+        writeLog_(debug, LEXICAL_CHECKOUT_DEBUG,"mathers->mathers[%d]->status == %d\n", i, mathers->mathers[i]->status);
     }
+    if (return_1) {
+        goto return_;
+    }
+
     if (mistake_count == max){
         return -2;
     }
@@ -143,7 +146,7 @@ int checkoutMather(LexMathers *mathers, int max) {
     else if(end_second_count == 1){
         return end_second_index;
     }
-    else{
-        return -1;
-    }
+
+    return_:
+    return -1;
 }

+ 29 - 10
parser/syntax.c

@@ -1,4 +1,4 @@
-#include "__virtualmath.h"
+#include "__syntax.h"
 
 /**
  * 匹配一个数字字面量
@@ -97,7 +97,10 @@ void stringMather(char p, LexMather *mather){
     }
     else if (mather->status == LEXMATHER_ING){
         if (mather->string_type == p){
-            mather->status = LEXMATHER_PASS;
+            mather->status = LEXMATHER_INGPASS;
+        }
+        else if (EOF == p){
+            mather->status = LEXMATHER_MISTAKE;
         }
         else{
             mather->str = memStrcpy(mather->str, 1, true, true, p);
@@ -114,7 +117,7 @@ void stringMather(char p, LexMather *mather){
             mather->status = LEXMATHER_END;
         }
     }
-    else if(mather->status == LEXMATHER_PASS){
+    else if(mather->status == LEXMATHER_INGPASS){
         if ('A'<= p && 'Z' >= p ||'a'<= p && 'z' >= p ||'_' == p){
             mather->second_str = memStrcpy(mather->second_str, 1, true, true, p);
             mather->status = LEXMATHER_INGSECOND;
@@ -181,11 +184,17 @@ void charMather(char p, LexMather *mather, char dest_p){
  * @param mathers
  * @return
  */
-int getMatherStatus(LexFile *file, LexMathers *mathers){
+int getMatherStatus(LexFile *file, LexMathers *mathers, FILE *debug) {
     setupMathers(mathers);
     int status = -1;
     while (status == -1){
         char p = readChar(file);
+        if (p == EOF)
+            writeLog_(debug, LEXICAL_DEBUG, "get char: (EOF)\n", NULL);
+        else if (p == '\n')
+            writeLog_(debug, LEXICAL_DEBUG, "get char: (\\n)\n", NULL);
+        else
+            writeLog_(debug, LEXICAL_DEBUG, "get char: '%c'\n", p);
         numberMather(p ,mathers->mathers[MATHER_NUMBER]);
         stringMather(p ,mathers->mathers[MATHER_STRING]);
         varMather(p ,mathers->mathers[MATHER_VAR]);
@@ -273,7 +282,8 @@ int getMatherStatus(LexFile *file, LexMathers *mathers){
 
         strMatherMacro(MATHER_Link, "->");
 
-        status = checkoutMather(mathers, MATHER_MAX);
+        status = checkoutMather(mathers, MATHER_MAX, debug);
+        writeLog_(debug, LEXICAL_DEBUG, "get status: %d\n", status);
     }
     backChar(file);
     return status;
@@ -285,14 +295,23 @@ int getMatherStatus(LexFile *file, LexMathers *mathers){
  * @param mathers
  * @return
  */
-Token *getToken(LexFile *file, LexMathers *mathers){
+Token *getToken(LexFile *file, LexMathers *mathers, FILE *debug) {
+    writeLog_(debug, DEBUG, "get token: [%d]\n", file->count);
     int status = MATHER_SPACE;
     while (status == MATHER_SPACE){
-        status = getMatherStatus(file, mathers);
+        status = getMatherStatus(file, mathers, debug);
     }
+    Token *tmp;
     if (status == -2){
-        status = MATHER_EOF;
-        printf("lexical ERROR\n");
+        status = MATHER_ERROR_;
+        writeLog_(debug, LEXICAL_DEBUG, "lexical ERROR\n", NULL);
+        tmp = makeLexToken(status, NULL, NULL);
+        goto return_;
     }
-    return makeLexToken(status, mathers->mathers[status]->str, mathers->mathers[status]->second_str);
+    tmp = makeLexToken(status, mathers->mathers[status]->str, mathers->mathers[status]->second_str);
+    printTokenEnter(tmp, debug, DEBUG, "new token: ");
+    writeLog_(debug, DEBUG, "\n", NULL);
+    return_:
+    file->count ++;
+    return tmp;
 }

+ 76 - 10
parser/token.c

@@ -1,4 +1,4 @@
-#include "__virtualmath.h"
+#include "__token.h"
 
 Token *makeToken(){
     Token *tmp = memCalloc(1, sizeof(Token));
@@ -58,11 +58,23 @@ void freeToekStream(TokenStream *ts, bool self) {
     }
 }
 
-TokenMessage *makeTokenMessage(char *file_dir){
+TokenMessage *makeTokenMessage(char *file_dir, char *debug) {
     TokenMessage *tm = memCalloc(1, sizeof(TokenMessage));
     tm->file = makeLexFile(file_dir);
     tm->mathers = makeMathers(MATHER_MAX);
     tm->ts = makeTokenStream();
+#if OUT_LOG
+    if (debug != NULL){
+        char *debug_dir = memStrcat(debug, LEXICAL_LOG);
+        tm->debug = fopen(debug_dir, "w");
+        memFree(debug_dir);
+    }
+    else{
+        tm->debug = NULL;
+    }
+#else
+    tm->debug = NULL;
+#endif
     return tm;
 }
 
@@ -70,6 +82,10 @@ void freeTokenMessage(TokenMessage *tm, bool self) {
     freeLexFile(tm->file, true);
     freeToekStream(tm->ts, true);
     freeMathers(tm->mathers, true);
+#if OUT_LOG
+    if (tm->debug != NULL)
+        fclose(tm->debug);
+#endif
     if (self){
         free(tm);
     }
@@ -80,7 +96,8 @@ void freeTokenMessage(TokenMessage *tm, bool self) {
  * @param ts
  * @param new_tk
  */
-void addToken(TokenStream *ts, Token *new_tk){
+void addToken(TokenStream *ts, Token *new_tk, FILE *debug) {
+    printTokenEnter(new_tk, debug, DEBUG, "add Token: ");
     Token **new_list = memCalloc(ts->size + 1, sizeof(Token *));
     for (int i=0; i < ts->size; i++){
         new_list[i] = ts->token_list[i];
@@ -89,6 +106,7 @@ void addToken(TokenStream *ts, Token *new_tk){
     ts->size ++;
     memFree(ts->token_list);
     ts->token_list = new_list;
+    MACRO_printTokenStream(ts, debug, DEEP_DEBUG);
 }
 
 /**
@@ -96,7 +114,7 @@ void addToken(TokenStream *ts, Token *new_tk){
  * @param ts
  * @return
  */
-Token *popToken(TokenStream *ts){
+Token *popToken(TokenStream *ts, FILE *debug) {
     Token **new_list = memCalloc(ts->size - 1, sizeof(Token *));
     for (int i=0; i < ts->size - 1; i++){
         new_list[i] = ts->token_list[i];
@@ -105,6 +123,8 @@ Token *popToken(TokenStream *ts){
     memFree(ts->token_list);
     ts->token_list = new_list;
     ts->size --;
+    printTokenEnter(tmp, debug, DEBUG, "pop Token: ");
+    MACRO_printTokenStream(ts, debug, DEEP_DEBUG);
     return tmp;
 }
 
@@ -113,7 +133,7 @@ Token *popToken(TokenStream *ts){
  * @param ts
  * @return
  */
-Token *backToken(TokenStream *ts){
+Token *backToken(TokenStream *ts, FILE *debug) {
     Token **new_list = memCalloc(ts->size - 1, sizeof(Token *));
     Token **new_ahead = memCalloc(ts->ahead + 1, sizeof(Token *));
     for (int i=0; i < ts->size - 1; i++){
@@ -129,6 +149,8 @@ Token *backToken(TokenStream *ts){
     ts->token_list = new_list;
     ts->size --;
     ts->ahead ++;
+    printTokenEnter(new_ahead[ts->ahead - 1], debug, DEBUG, "back Token: ");
+    MACRO_printTokenStream(ts, debug, DEEP_DEBUG);
     return new_ahead[ts->ahead - 1];
 }
 
@@ -137,7 +159,7 @@ Token *backToken(TokenStream *ts){
  * @param ts
  * @return
  */
-Token *forwardToken(TokenStream *ts){
+Token *forwardToken(TokenStream *ts, FILE *debug) {
     Token **new_list = memCalloc(ts->size + 1, sizeof(Token *));
     Token **new_ahead = memCalloc(ts->ahead - 1, sizeof(Token *));
     for (int i=0; i < ts->size; i++){
@@ -153,6 +175,8 @@ Token *forwardToken(TokenStream *ts){
     ts->token_list = new_list;
     ts->size ++;
     ts->ahead --;
+    printTokenEnter(new_list[ts->size - 1], debug, DEBUG, "forward Token: ");
+    MACRO_printTokenStream(ts, debug, DEEP_DEBUG);
     return new_list[ts->size - 1];
 }
 
@@ -162,14 +186,56 @@ Token *forwardToken(TokenStream *ts){
  * @param tm
  * @return 返回获取token的token_type
  */
-int safeGetToken(TokenMessage *tm){
+int safeGetToken(TokenMessage *tm, FILE *debug) {
+    writeLog_(debug, DEBUG, "safe get token : ", NULL);
     Token *tmp;
     if (tm->ts->ahead == 0){
-        tmp = getToken(tm->file, tm->mathers);
-        addToken(tm->ts, tmp);
+        writeLog_(debug, DEBUG, "get token: %d\n", tm->file->count);
+        tmp = getToken(tm->file, tm->mathers, tm->debug);
+        addToken(tm->ts, tmp, debug);
+        MACRO_printTokenStream(tm->ts, debug, DEBUG);
     }
     else{
-        tmp = forwardToken(tm->ts);
+        // forwardToken 会有详细的日志输出
+        tmp = forwardToken(tm->ts, debug);
     }
     return tmp->token_type;
+}
+
+
+void printToken(Token *tk, FILE *debug, int type) {
+    if (tk->token_type >= 0) {
+        char *tmp = tk->data.str, *second_tmp = tk->data.second_str;
+        if (!strcmp(tmp, "\n")) {
+            tmp = "\\n";
+        }
+        if (!strcmp(second_tmp, "\n")) {
+            second_tmp = "\\n";
+        }
+        if (tmp[0] == EOF) {
+            tmp = "(EOF)";
+        }
+        writeLog_(debug, type, "<token str = ('%s','%s'), type = %d>", tmp, second_tmp, tk->token_type);
+    }
+    else{
+        writeLog_(debug, type, "<token statement, type = %d>", tk->token_type);
+    }
+
+}
+
+void printTokenStream(TokenStream *ts, FILE *debug, int type) {
+    writeLog_(debug, type, "token_list: ", NULL);
+    for (int i=0; i < ts->size; i ++){
+        if (i > 0)
+            writeLog_(debug, type, "-", NULL);
+        printToken(ts->token_list[i], debug, type);
+    }
+    writeLog_(debug, type, "\n", NULL);
+    writeLog_(debug, type, "token_ahead: ", NULL);
+    for (int i=0; i < ts->ahead; i ++){
+        if (i > 0)
+            writeLog_(debug, type, "-", NULL);
+        printToken(ts->token_ahead[i], debug, type);
+    }
+    writeLog_(debug, type, "\n", NULL);
 }

+ 12 - 1
src/inter.c

@@ -1,11 +1,19 @@
 #include "__virtualmath.h"
 
-Inter *makeInter(){
+Inter *makeInter(char *debug){
     Inter *tmp = memCalloc(1, sizeof(Inter));
     tmp->base = NULL;
     tmp->link_base = NULL;
     tmp->statement = makeStatement();
     tmp->var_list = makeVarList(tmp);
+    tmp->log_dir = memStrcpy(debug, 0, false, false);
+    if (debug != NULL){
+        char *debug_dir = memStrcat(debug, INTER_LOG);
+        tmp->debug = fopen(debug_dir, "w");
+        memFree(debug_dir);
+    }
+    else
+        tmp->debug = stdout;
     return tmp;
 }
 
@@ -21,6 +29,9 @@ void freeInter(Inter *inter, bool self){
     }
     freeStatement(inter->statement);
     freeVarList(inter->var_list, true);
+    memFree(inter->log_dir);
+    if (inter->log_dir != NULL)
+        fclose(inter->debug);
     if (self){
         memFree(inter);
     }

+ 4 - 17
src/run.c

@@ -1,17 +1,4 @@
-#include "__virtualmath.h"
-#define printResult(result, first, last) do{ \
-switch (result.value->value->type){ \
-    case number: \
-        printf("%s %ld %s \n", first, result.value->value->data.num.num, last); \
-        break; \
-    case string: \
-        printf("%s %s %s \n", first, result.value->value->data.str.str, last); \
-        break; \
-    default: \
-        printf("%s default %s \n", first, last); \
-        break; \
-} \
-} while(0) \
+#include "__run.h"
 
 Result getBaseVar(INTER_FUNCTIONSIG) {
     Result times, result;
@@ -26,13 +13,13 @@ Result getBaseVar(INTER_FUNCTIONSIG) {
     not_times:
     result.value = findFromVarList(st->u.base_var.name, var_list, int_times);
     if (result.value == NULL){
-        printf("not found[%s]\n", st->u.base_var.name);
+        writeLog_(inter->debug, WARNING, "not found[%s]\n", st->u.base_var.name);
     }
     return result;
 }
 
 /**
- * 运行个statement
+ * 运行个statement
  * @param st
  * @param inter
  * @param var_list
@@ -50,7 +37,7 @@ Result runStatement(INTER_FUNCTIONSIG) {
             break;
         case operation:
             result = operationStatement(CALL_INTER_FUNCTIONSIG(st, var_list));
-            printResult(result, "operation result = ", "");
+            printResult(result, "operation result = ", "", inter->debug);
             break;
         default:
             break;