diff options
author | kdx <kdx@42l.fr> | 2023-03-16 01:55:26 +0100 |
---|---|---|
committer | kdx <kdx@42l.fr> | 2023-03-16 02:04:09 +0100 |
commit | 43e1ebac939e5d83b0e934449a02322ea044a3d1 (patch) | |
tree | d88b0aea10a63b48cf76c4f96a6e70b476b75ff5 | |
parent | b10c69cfe557c821591b046c3e4e75710494f60c (diff) | |
download | golem-43e1ebac939e5d83b0e934449a02322ea044a3d1.tar.gz |
lex characters
-rw-r--r-- | README.md | 1 | ||||
-rw-r--r-- | lexer.c | 14 | ||||
-rw-r--r-- | mvp.golem | 1 | ||||
-rw-r--r-- | token.h | 2 |
4 files changed, 17 insertions, 1 deletions
@@ -19,6 +19,7 @@ main argc argv { g_heap = 8000; hello = (strdup "bonjour");;; + [hello 6] = 'w'; world = (strdup "monde"); (print hello); (print " "); @@ -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; } @@ -12,6 +12,7 @@ main argc argv { g_heap = 8000; hello = (strdup "bonjour");;; + [hello 6] = 'w'; world = (strdup "monde"); (print hello); (print " "); @@ -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', |