feat(lexer): negation

This commit is contained in:
Matteo Flebus 2026-01-27 16:44:53 +01:00
parent c48d86c8de
commit 9003675c40
2 changed files with 7 additions and 16 deletions

View file

@ -60,34 +60,22 @@ static void set_token_keyword(struct token *tok, char *begin, ssize_t size)
{
if (tok->type != TOKEN_NULL || size == 0)
return;
if (strncmp(begin, "if", size) == 0 && size == 2)
{
if (strncmp(begin, "!", size) == 0 && size == 1)
tok->type = TOKEN_NEGATION;
else if (strncmp(begin, "if", size) == 0 && size == 2)
tok->type = TOKEN_IF;
}
else if (strncmp(begin, "fi", size) == 0 && size == 2)
{
tok->type = TOKEN_FI;
}
else if (strncmp(begin, "then", size) == 0 && size == 4)
{
tok->type = TOKEN_THEN;
}
else if (strncmp(begin, "else", size) == 0 && size == 4)
{
tok->type = TOKEN_ELSE;
}
else if (strncmp(begin, "elif", size) == 0 && size == 4)
{
tok->type = TOKEN_ELIF;
}
else if (strncmp(begin, "&&", size) == 0 && size == 2)
{
tok->type = TOKEN_AND;
}
else if (strncmp(begin, "||", size) == 0 && size == 2)
{
tok->type = TOKEN_OR;
}
// no keywords found.
if (tok->type == TOKEN_NULL)
@ -95,7 +83,10 @@ static void set_token_keyword(struct token *tok, char *begin, ssize_t size)
tok->data = calloc(size + 1, sizeof(char));
if (tok->data == NULL)
{
perror("could not allocate memory in lexer");
return;
}
strncpy(tok->data, begin, size);
}