#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_IF) \ 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_clear_line(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); void token_clone(struct token *dest, struct token *src); void token_dealloc(struct token *token); #endif