From 68a62ad356603d64d537e231f06b5d9445e79abe Mon Sep 17 00:00:00 2001 From: kartofen Date: Fri, 23 Aug 2024 19:55:13 +0300 Subject: usefull commit message --- src/lexer.h | 58 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 src/lexer.h (limited to 'src/lexer.h') diff --git a/src/lexer.h b/src/lexer.h new file mode 100644 index 0000000..7c67028 --- /dev/null +++ b/src/lexer.h @@ -0,0 +1,58 @@ +#ifndef LEXER_H +#define LEXER_H + +#include + +#define TOKEN_TYPES(X) \ + X(TOKEN_LP) \ + X(TOKEN_RP) \ + X(TOKEN_ID) \ + X(TOKEN_STR) \ + X(TOKEN_INT) \ + X(TOKEN_DOT) \ + X(TOKEN_QUOTE) \ + X(TOKEN_UNQUOTE) \ + X(TOKEN_LAMBDA) \ + X(TOKEN_DEFINE) \ + X(TOKEN_QUOTE_FORM) \ + X(TOKEN_NONE) + +#define TO_ENUM(type) type, +#define TO_STRING(type) #type, + +extern const char * const token_type_string[]; + +struct token { + enum token_type { + TOKEN_TYPES(TO_ENUM) + } type; + + union { + char *id; + char *str; + int num; + } value; +}; + +typedef struct lexer * lexer_t; +#define LEXER_EMPTY NULL + +struct lexer { + FILE *fp; + size_t line; + + char str[256]; + size_t str_idx; + + struct token token; + char acc[256]; + size_t acc_idx; +}; + +lexer_t lexer_create(FILE *fp); +void lexer_destroy(lexer_t lexer); +int lexer_token_next(lexer_t lexer, struct token *token); + +int token_value_string(struct token *token, size_t buf_sz, char *buf); + +#endif -- cgit v1.2.3