__parser.h 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. #ifndef AFUN_PARSER_H_
  2. #define AFUN_PARSER_H_
  3. #include <stdio.h>
  4. #include "__reader.h"
  5. #include "token.h"
  6. #include "parser.h"
  7. enum af_LexicalStatus {
  8. lex_begin = 0, // 起始类型
  9. lex_prefix_block_p = 1, // 前缀括号 !
  10. lex_prefix_block_b = 2, // 前缀括号 @
  11. lex_prefix_block_c = 3, // 前缀括号 #
  12. lex_comment_before = 4, // 注释
  13. lex_element_long = 5,
  14. lex_mutli_comment = 6, // 多行注释
  15. lex_uni_comment = 7, // 当行注释
  16. lex_mutli_comment_end_before = 8, // 多行注释遇到;
  17. lex_prefix = -1, // prefix类型
  18. lex_lp = -2,
  19. lex_lb = -3,
  20. lex_lc = -4,
  21. lex_rp = -5,
  22. lex_rb = -6,
  23. lex_rc = -7,
  24. lex_space = -8,
  25. lex_uni_comment_end = -9,
  26. lex_mutli_comment_end = -10,
  27. lex_nul = -11,
  28. lex_element_short = -12,
  29. lex_element_long_end = -13,
  30. };
  31. typedef enum af_LexicalStatus af_LexicalStatus;
  32. typedef struct af_Lexical af_Lexical;
  33. typedef struct af_Syntactic af_Syntactic;
  34. struct af_Parser {
  35. struct af_Reader *reader;
  36. struct af_Lexical *lexical;
  37. struct af_Syntactic *syntactic;
  38. FILE *error;
  39. bool is_error; // Parser遇到错误
  40. };
  41. struct af_Lexical { // 词法匹配器的状态机
  42. enum af_LexicalStatus status;
  43. size_t last; // 最后一次词法匹配的有效长度
  44. enum af_TokenType token; // token类型\
  45. size_t mutli_comment; // 多行注释嵌套等级
  46. bool is_end;
  47. bool is_error;
  48. };
  49. struct af_Syntactic {
  50. bool back;
  51. enum af_TokenType token;
  52. char *text;
  53. };
  54. /* Parser 相关操作 */
  55. AFUN_CORE_EXPORT af_TokenType getTokenFromLexical(char **text, af_Parser *parser);
  56. #endif //AFUN_PARSER_H_