diff options
Diffstat (limited to 'lexer.c')
-rw-r--r-- | lexer.c | 21 |
1 files changed, 14 insertions, 7 deletions
@@ -81,28 +81,35 @@ Token *lexer(const char *s) return NULL; } size_t len = end - s - 1; - toks[tok_i].v.s = calloc(1, len + 1); - if (toks[tok_i].v.s == NULL) { + toks[tok_i].s = calloc(1, len + 1); + if (toks[tok_i].s == NULL) { perror("lexer"); lexer_free(toks); return NULL; } toks[tok_i].type = TOK_STRING; - strncpy(toks[tok_i].v.s, s + 1, len); + strncpy(toks[tok_i].s, s + 1, len); tok_i += 1; s = end + 1; } else if (isalpha(*s) || *s == '_') { size_t len = 0; while (isalnum(s[len]) || s[len] == '_') len += 1; - toks[tok_i].v.s = calloc(1, len + 1); - if (toks[tok_i].v.s == NULL) { + toks[tok_i].s = calloc(1, len + 1); + if (toks[tok_i].s == NULL) { perror("lexer"); lexer_free(toks); return NULL; } - strncpy(toks[tok_i].v.s, s, len); - toks[tok_i].type = TOK_WORD; + strncpy(toks[tok_i].s, s, len); + if (strcmp("fn", toks[tok_i].s) == 0) + toks[tok_i].type = TOK_KW_FN; + else if (strcmp("var", toks[tok_i].s) == 0) + toks[tok_i].type = TOK_KW_VAR; + else if (strcmp("const", toks[tok_i].s) == 0) + toks[tok_i].type = TOK_KW_CONST; + else + toks[tok_i].type = TOK_WORD; tok_i += 1; s += len; } else if (isdigit(*s)) { |