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 980B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  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_EOF,
  14. L2_TOK_NUMBER,
  15. L2_TOK_STRING,
  16. L2_TOK_ERROR,
  17. };
  18. const char *l2_token_kind_name(enum l2_token_kind kind);
  19. struct l2_token {
  20. enum l2_token_kind kind;
  21. int line;
  22. int ch;
  23. union {
  24. char *str;
  25. double num;
  26. } v;
  27. };
  28. void l2_token_free(struct l2_token *tok);
  29. struct l2_token l2_token_move(struct l2_token *tok);
  30. void l2_token_print(struct l2_token *tok, struct l2_io_writer *w);
  31. struct l2_lexer {
  32. struct l2_token currtok;
  33. struct l2_token toks[2];
  34. int tokidx;
  35. int line;
  36. int ch;
  37. struct l2_bufio_reader reader;
  38. };
  39. void l2_lexer_init(struct l2_lexer *lexer, struct l2_io_reader *r);
  40. struct l2_token *l2_lexer_peek(struct l2_lexer *lexer, int count);
  41. struct l2_token *l2_lexer_get(struct l2_lexer *lexer);
  42. #endif