From 329166705de225bc766e56cc77765430065c456d Mon Sep 17 00:00:00 2001 From: kartofen Date: Sun, 1 Sep 2024 00:44:56 +0300 Subject: linked list and macros --- src/lexer.c | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) (limited to 'src/lexer.c') diff --git a/src/lexer.c b/src/lexer.c index 93c7f44..cd83006 100644 --- a/src/lexer.c +++ b/src/lexer.c @@ -11,6 +11,7 @@ X(('(' == CH(l)), on_separator(l, TOKEN_LP)) \ X((')' == CH(l)), on_separator(l, TOKEN_RP)) \ X(('\''== CH(l)), on_separator(l, TOKEN_QUOTE)) \ + X(('`' == CH(l)), on_separator(l, TOKEN_QUASI)) \ X((',' == CH(l)), on_separator(l, TOKEN_UNQUOTE)) \ X(isspace(CH(l)), on_separator(l, TOKEN_NONE)) \ X(TABLE_ELSE, acc_add_char(l, CH(l))) @@ -31,12 +32,14 @@ X(TOKEN_LAMBDA, "lambda") \ X(TOKEN_DEFINE, "define") \ X(TOKEN_QUOTE_FORM, "quote") \ - X(TOKEN_IF, "if") + X(TOKEN_IF, "if") \ + X(TOKEN_DEFMACRO, "defmacro") #define TOKEN_VALUE_STRING_TABLE(X, tvalue) \ X(TOKEN_LP, "(") \ X(TOKEN_RP, ")") \ X(TOKEN_QUOTE, "'") \ + X(TOKEN_QUASI, "`") \ X(TOKEN_UNQUOTE, ",") \ X(TOKEN_ID, "%s", tvalue.id) \ X(TOKEN_STR, "%s", tvalue.str) \ @@ -167,6 +170,18 @@ void token_dealloc(struct token *token) } } +void toklist_destroy(struct toklist *toklist) +{ + list_for_each_safe(head, &toklist->list) { + toklist = list_entry(head, struct toklist, list); + for(size_t i = 0; i < toklist->tokens_len; i++) { + token_dealloc(&toklist->tokens[i]); + } + free(toklist->tokens); + free(toklist); + } +} + static int on_separator(lexer_t lexer, enum token_type type) { if(lexer->acc_idx > 0) return acc_empty(lexer); -- cgit v1.2.3