summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorkdx <kdx@42l.fr>2023-03-16 01:55:26 +0100
committerkdx <kdx@42l.fr>2023-03-16 02:04:09 +0100
commit43e1ebac939e5d83b0e934449a02322ea044a3d1 (patch)
treed88b0aea10a63b48cf76c4f96a6e70b476b75ff5
parentb10c69cfe557c821591b046c3e4e75710494f60c (diff)
downloadgolem-43e1ebac939e5d83b0e934449a02322ea044a3d1.tar.gz
lex characters
-rw-r--r--README.md1
-rw-r--r--lexer.c14
-rw-r--r--mvp.golem1
-rw-r--r--token.h2
4 files changed, 17 insertions, 1 deletions
diff --git a/README.md b/README.md
index 5c10aa3..5d0d64a 100644
--- a/README.md
+++ b/README.md
@@ -19,6 +19,7 @@ main argc argv {
g_heap = 8000;
hello = (strdup "bonjour");;;
+ [hello 6] = 'w';
world = (strdup "monde");
(print hello);
(print " ");
diff --git a/lexer.c b/lexer.c
index 2297e39..be87bf8 100644
--- a/lexer.c
+++ b/lexer.c
@@ -119,6 +119,20 @@ lexer(Slice slice)
continue;
}
+ // Character token.
+ if (slice.str[i] == '\'') {
+ if (slice.str[i + 1] == '\0' ||
+ slice.str[i + 2] != '\'') {
+ fprintf(stderr, "unclosed character\n");
+ token_destroy(toks);
+ return NULL;
+ }
+ Slice character = slice_sub(slice, i + 1, i + 2);
+ token_append(&toks, token_create(character, TOK_CHAR));
+ i += 3;
+ continue;
+ }
+
printf("skipping '%c'\n", slice.str[i]);
i += 1;
}
diff --git a/mvp.golem b/mvp.golem
index 3432389..6f49f50 100644
--- a/mvp.golem
+++ b/mvp.golem
@@ -12,6 +12,7 @@ main argc argv {
g_heap = 8000;
hello = (strdup "bonjour");;;
+ [hello 6] = 'w';
world = (strdup "monde");
(print hello);
(print " ");
diff --git a/token.h b/token.h
index 5afc8cc..9c4b699 100644
--- a/token.h
+++ b/token.h
@@ -14,7 +14,7 @@ enum {
TOK_ASSIGN = '=',
TOK_END = ';',
TOK_NUMBER = '0',
- TOK_CHARACTER = 'a',
+ TOK_CHAR = 'c',
TOK_STRING = 's',
TOK_WORD = 'w',
TOK_KW_LET = 'L',