You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

lex.h 1010B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. #ifndef L2_PARSE_LEX_H
  2. #define L2_PARSE_LEX_H
  3. #include "../io.h"
  4. enum l2_token_kind {
  5. L2_TOK_OPEN_PAREN,
  6. L2_TOK_CLOSE_PAREN,
  7. L2_TOK_OPEN_BRACE,
  8. L2_TOK_CLOSE_BRACE,
  9. L2_TOK_OPEN_BRACKET,
  10. L2_TOK_CLOSE_BRACKET,
  11. L2_TOK_COMMA,
  12. L2_TOK_PERIOD,
  13. L2_TOK_COLON_EQ,
  14. L2_TOK_EOF,
  15. L2_TOK_NUMBER,
  16. L2_TOK_STRING,
  17. L2_TOK_IDENT,
  18. L2_TOK_ERROR,
  19. };
  20. const char *l2_token_kind_name(enum l2_token_kind kind);
  21. struct l2_token {
  22. enum l2_token_kind kind;
  23. int line;
  24. int ch;
  25. union {
  26. char *str;
  27. double num;
  28. } v;
  29. };
  30. void l2_token_free(struct l2_token *tok);
  31. char *l2_token_extract_str(struct l2_token *tok);
  32. void l2_token_print(struct l2_token *tok, struct l2_io_writer *w);
  33. struct l2_lexer {
  34. struct l2_token currtok;
  35. struct l2_token toks[4];
  36. int tokidx;
  37. int line;
  38. int ch;
  39. struct l2_bufio_reader reader;
  40. };
  41. void l2_lexer_init(struct l2_lexer *lexer, struct l2_io_reader *r);
  42. struct l2_token *l2_lexer_peek(struct l2_lexer *lexer, int count);
  43. struct l2_token *l2_lexer_get(struct l2_lexer *lexer);
  44. #endif