__grammar.h 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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. Token *tmp_token; \
  47. popAheadToken(tmp_token, pm); \
  48. freeToken(tmp_token, true, false); \
  49. tmp_token = NULL; \
  50. }while(0)
  51. #define callChild(pm, status, token, call, type, error_) do{ \
  52. call(CALLPASERSSIGNATURE); \
  53. if (!call_success(pm)){ \
  54. goto error_; \
  55. } \
  56. readBackToken(status, pm); \
  57. if (status != type){ \
  58. goto error_; \
  59. } \
  60. popAheadToken(token, pm); \
  61. }while(0)
  62. void parserCommand(PASERSSIGNATURE);
  63. void parserOperation(PASERSSIGNATURE);
  64. void parserPolynomial(PASERSSIGNATURE);
  65. void parserBaseValue(PASERSSIGNATURE);
  66. void parserFactor(PASERSSIGNATURE);
  67. void parserAssignment(PASERSSIGNATURE);
  68. void syntaxError(ParserMessage *pm, char *message, int status);
  69. void twoOperation(PASERSSIGNATURE, void (*callBack)(PASERSSIGNATURE), int (*getSymbol)(PASERSSIGNATURE, int symbol, Statement **st), int, int, char *, char *);
  70. #endif //VIRTUALMATH___GRAMMAR_H