__grammar.h 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. #ifndef VIRTUALMATH___GRAMMAR_H
  2. #define VIRTUALMATH___GRAMMAR_H
  3. #include "__virtualmath.h"
  4. #define PASERSSIGNATURE ParserMessage *pm, Inter *inter /*pasers函数的统一签名*/
  5. #define CALLPASERSSIGNATURE pm, inter /*pasers函数调用的统一实参*/
  6. #if OUT_LOG && OUT_PASERS_LOG
  7. #define doubleLog(pm, grammar_level, pasers_level, message, ...) do{ \
  8. writeLog(pm->grammar_debug, grammar_level, message, __VA_ARGS__); \
  9. writeLog(pm->paser_debug, pasers_level, "\n"message, __VA_ARGS__); \
  10. } while(0)
  11. #else
  12. #define doubleLog(...) PASS
  13. #endif
  14. #if OUT_LOG && OUT_GRAMMER_LOG
  15. #define writeLog_(...) writeLog(__VA_ARGS__)
  16. #else
  17. #define writeLog_(...) PASS
  18. #endif
  19. #define addStatementToken(type, st, pm) addBackToken(pm->tm->ts, makeStatementToken(type, st), pm->paser_debug)
  20. #define delToken(pm) freeToken(popAheadToken(pm), true, false)
  21. #define backToken_(pm, token) addBackToken(pm->tm->ts, (token), pm->paser_debug)
  22. #define addLexToken(pm, type) backToken_(pm, makeLexToken(type, NULL, NULL))
  23. #define addToken_ backToken_
  24. #define call_success(pm) (pm->status == success)
  25. typedef void (*PasersFunction)(PASERSSIGNATURE);
  26. typedef int (*GetSymbolFunction)(PASERSSIGNATURE, int, Statement **);
  27. typedef Statement *(*MakeControlFunction)(Statement *);
  28. typedef int (*TailFunction)(PASERSSIGNATURE, Token *, Statement **);
  29. void parserCommand(PASERSSIGNATURE);
  30. void parserControl(PASERSSIGNATURE, Statement *(*callBack)(Statement *), int type);
  31. void parserDef(PASERSSIGNATURE);
  32. void parserIf(PASERSSIGNATURE);
  33. void parserWhile(PASERSSIGNATURE);
  34. void parserTry(PASERSSIGNATURE);
  35. void parserCode(PASERSSIGNATURE);
  36. void parserOperation(PASERSSIGNATURE);
  37. void parserPolynomial(PASERSSIGNATURE);
  38. void parserBaseValue(PASERSSIGNATURE);
  39. void parserCallBack(PASERSSIGNATURE);
  40. void parserFactor(PASERSSIGNATURE);
  41. void parserAssignment(PASERSSIGNATURE);
  42. void parserTuple(PASERSSIGNATURE);
  43. void twoOperation(ParserMessage *pm, Inter *inter, PasersFunction callBack, GetSymbolFunction getSymbol,
  44. int type, int self_type, char *call_name, char *self_name, bool is_right);
  45. void tailOperation(PASERSSIGNATURE, PasersFunction callBack, TailFunction tailFunction, int type, int self_type,
  46. char *call_name, char *self_name);
  47. void syntaxError(ParserMessage *pm, int status, int num, ...);
  48. int readBackToken(ParserMessage *pm);
  49. Token *popAheadToken(ParserMessage *pm);
  50. bool checkToken_(ParserMessage *pm, int type);
  51. bool commandCallControl_(PASERSSIGNATURE, MakeControlFunction callBack, int type, Statement **st, char *message);
  52. bool commandCallBack_(PASERSSIGNATURE, PasersFunction callBack, int type, Statement **st, char *message);
  53. bool callParserCode(PASERSSIGNATURE, Statement **st,char *message);
  54. bool callParserAs(PASERSSIGNATURE, Statement **st,char *message);
  55. bool callChildStatement(PASERSSIGNATURE, PasersFunction callBack, int type, Statement **st, char *message);
  56. bool callChildToken(ParserMessage *pm, Inter *inter, PasersFunction callBack, int type, Token **tmp, char *message,
  57. int error_type);
  58. #endif //VIRTUALMATH___GRAMMAR_H