__grammar.h 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. #ifndef VIRTUALMATH___GRAMMAR_H
  2. #define VIRTUALMATH___GRAMMAR_H
  3. #include "__virtualmath.h"
  4. #if OUT_LOG && OUT_PASERS_LOG
  5. #define doubleLog(pm, grammar_level, pasers_level, message, ...) do{ \
  6. writeLog(pm->grammar_debug, grammar_level, message, __VA_ARGS__); \
  7. writeLog(pm->paser_debug, pasers_level, "\n"message, __VA_ARGS__); \
  8. } while(0)
  9. #else
  10. #define doubleLog(...) PASS
  11. #endif
  12. #if OUT_LOG && OUT_GRAMMER_LOG
  13. #define writeLog_(...) writeLog(__VA_ARGS__)
  14. #else
  15. #define writeLog_(...) PASS
  16. #endif
  17. #define readBackToken(status, pm) do{ \
  18. doubleLog(pm, GRAMMAR_DEBUG, DEBUG, "token operation number : %d\n", pm->count); \
  19. pm->count ++; \
  20. status = safeGetToken(pm->tm, pm->paser_debug); \
  21. if (status == -2){ \
  22. syntaxError(pm, "lexical make some error", lexical_error); \
  23. } \
  24. backToken(pm->tm->ts, pm->paser_debug); \
  25. } while(0) /*预读token*/
  26. #define popAheadToken(token_var, pm) do{ \
  27. doubleLog(pm, GRAMMAR_DEBUG, DEBUG, "token operation number : %d\n", pm->count); \
  28. pm->count ++; \
  29. safeGetToken(pm->tm, pm->paser_debug); \
  30. /* 执行popheanToken之前执行readBackToken因此不必再检查status */ \
  31. token_var = popToken(pm->tm->ts, pm->paser_debug); \
  32. } while(0) /*弹出预读的token*/
  33. #define addStatementToken(type, st, pm) do{\
  34. Token *tmp_new_token; \
  35. tmp_new_token = makeStatementToken(type, st); \
  36. addToken(pm->tm->ts, tmp_new_token, pm->paser_debug); \
  37. backToken(pm->tm->ts, pm->paser_debug); \
  38. } while(0)
  39. #define backToken_(pm, token) do{ \
  40. addToken(pm->tm->ts, (token), pm->paser_debug); \
  41. backToken(pm->tm->ts, pm->paser_debug); \
  42. }while(0)
  43. #define addToken_ backToken_
  44. #define call_success(pm) (pm->status == success)
  45. #define delToken(pm) do{ \
  46. delTokenCore(pm, false); \
  47. }while(0)
  48. #define delTokenCore(pm, del_st) do{ \
  49. Token *tmp_token; \
  50. popAheadToken(tmp_token, pm); \
  51. freeToken(tmp_token, true, del_st); \
  52. tmp_token = NULL; \
  53. }while(0)
  54. #define checkToken(pm, type, error_) do{ \
  55. int token; \
  56. readBackToken(token, pm); \
  57. if (token != type){ \
  58. goto error_; \
  59. } \
  60. delToken(pm); \
  61. }while(0)
  62. void parserCommand(PASERSSIGNATURE);
  63. void parserDef(PASERSSIGNATURE);
  64. void parserCode(PASERSSIGNATURE);
  65. void parserOperation(PASERSSIGNATURE);
  66. void parserPolynomial(PASERSSIGNATURE);
  67. void parserBaseValue(PASERSSIGNATURE);
  68. void parserCallBack(PASERSSIGNATURE);
  69. void parserFactor(PASERSSIGNATURE);
  70. void parserAssignment(PASERSSIGNATURE);
  71. void syntaxError(ParserMessage *pm, char *message, int status);
  72. void twoOperation(PASERSSIGNATURE, void (*callBack)(PASERSSIGNATURE), int (*getSymbol)(PASERSSIGNATURE, int symbol, Statement **st), int, int, char *, char *);
  73. void tailOperation(PASERSSIGNATURE, void (*callBack)(PASERSSIGNATURE), int (*tailFunction)(PASERSSIGNATURE, Token *left_token, Statement **st), int , int , char *, char *);
  74. #endif //VIRTUALMATH___GRAMMAR_H