aboutsummaryrefslogtreecommitdiff
path: root/src/lexer.c
diff options
context:
space:
mode:
authorkartofen <mladenovnasko0@gmail.com>2024-09-01 00:44:56 +0300
committerkartofen <mladenovnasko0@gmail.com>2024-09-01 00:44:56 +0300
commit329166705de225bc766e56cc77765430065c456d (patch)
tree050b12b3a202cf43e9850903bd5b8bcc8ec67d7c /src/lexer.c
parente1ceef73192f0300ff9b10ba9a16475fbebeaa5f (diff)
linked list and macros
Diffstat (limited to 'src/lexer.c')
-rw-r--r--src/lexer.c17
1 files changed, 16 insertions, 1 deletions
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);