diff --git a/src/lexer/lexer.c b/src/lexer/lexer.c index d42df48..00c8fa6 100644 --- a/src/lexer/lexer.c +++ b/src/lexer/lexer.c @@ -3,6 +3,7 @@ #include #include #include +#include #include #include @@ -28,10 +29,9 @@ static void save_state(char *stream, ssize_t i) */ static bool is_special_char(char c) { - return c == '\'' || c == '\n' || c == ';' || c == 'EOF'; + return c == '\'' || c == '\n' || c == ';' || c == EOF; } - /* @brief: if a special character is found at [begin], * [tok->token_type] is set accordingly * @@ -40,7 +40,7 @@ static void set_token_spechar(struct token *tok, char *begin, ssize_t size) { if (size != 1) return; - if (begin[0] == 'EOF') + if (begin[0] == EOF) { tok->type = TOKEN_EOF; } @@ -58,7 +58,6 @@ static void set_token_spechar(struct token *tok, char *begin, ssize_t size) } } - /* @brief: if a keyword is found at [begin], * [tok->token_type] is set accordingly * @@ -90,10 +89,12 @@ static void set_token_keyword(struct token *tok, char *begin, ssize_t size) */ static void set_token_word(struct token *tok, char *begin, ssize_t size) { - if (tok->token_type == TOKEN_NULL) + if (tok->type == TOKEN_NULL) { - char *token_data = calloc(size + 1, sizeof(char)); - strncpy(res, begin, size); + tok->data = calloc(size + 1, sizeof(char)); + if (tok->data == NULL) + return; + strncpy(tok->data, begin, size); } } diff --git a/src/lexer/lexer.h b/src/lexer/lexer.h index fe7a024..9d9ea06 100644 --- a/src/lexer/lexer.h +++ b/src/lexer/lexer.h @@ -20,7 +20,7 @@ enum token_type struct token { enum token_type type; - char* data; + char *data; }; /* @@ -57,7 +57,7 @@ struct token *new_token(char *begin, ssize_t size); /* @brief: frees the token given in argument * */ -void free_token(struct token* tok); +void free_token(struct token *tok); /* * @brief: checks if the stream used for the last token creation is empty.