diff --git a/src/lexer/lexer_utils.c b/src/lexer/lexer_utils.c index 9883bf7..07455a7 100644 --- a/src/lexer/lexer_utils.c +++ b/src/lexer/lexer_utils.c @@ -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); } diff --git a/src/lexer/lexer_utils.h b/src/lexer/lexer_utils.h index 29d444d..6b26c74 100644 --- a/src/lexer/lexer_utils.h +++ b/src/lexer/lexer_utils.h @@ -49,7 +49,7 @@ enum token_type TOKEN_LEFT_BRACKET, TOKEN_RIGHT_BRACKET, TOKEN_PIPE, - TOKEN_NEGATION, // TODO handle + TOKEN_NEGATION, // TODO merge into one and use the data field // (Too difficult to handle in the parser because of firsts)