diff options
| author | Dominik Kaiser | 2024-06-28 15:09:32 +0200 |
|---|---|---|
| committer | GitHub | 2024-06-28 15:09:32 +0200 |
| commit | 8103cadfc95fb76539bfccc893a2101ccb89ea90 (patch) | |
| tree | b46379099324f76f2496909b4de3cd71de8b772a /src/new_token.c | |
| parent | 031685832d8267acc2fa46ea9732b8e95eb34463 (diff) | |
| download | minishell-8103cadfc95fb76539bfccc893a2101ccb89ea90.tar.gz minishell-8103cadfc95fb76539bfccc893a2101ccb89ea90.zip | |
Add data structures for tokenizing and parsing
* Add data structures and helper functions for ast
* Add data structures for tokenizing
* Add helper functions for token structures
* Include token.h in minishell.h
* Add new/free functions for nodes/tokens to Makefile
* Add UNREACHABLE macro to debug_tools.h
Diffstat (limited to 'src/new_token.c')
| -rw-r--r-- | src/new_token.c | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/src/new_token.c b/src/new_token.c new file mode 100644 index 0000000..92ff421 --- /dev/null +++ b/src/new_token.c @@ -0,0 +1,52 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* new_token.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: dkaiser <dkaiser@student.42heilbronn.de +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2024/06/27 14:29:44 by dkaiser #+# #+# */ +/* Updated: 2024/06/28 14:59:34 by dkaiser ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "token.h" + +t_token *new_token(int type, t_token *previous, t_token *next) +{ + t_token *token; + + token = malloc(sizeof(t_token)); + if (token == NULL) + return (NULL); + token->type = type; + token->previous = previous; + token->next = next; + if (previous != NULL) + token->previous->next = token; + if (next != NULL) + token->next->previous = token; + return (token); +} + +t_token *new_str_token(char *str, t_token *previous, t_token *next) +{ + t_token *token; + + token = new_token(STRING_TOKEN, previous, next); + if (token == NULL) + return (NULL); + token->content.string = str; + return (token); +} + +t_token *new_redir_token(int type, t_token *previous, t_token *next) +{ + t_token *token; + + token = new_token(REDIR_TOKEN, previous, next); + if (token == NULL) + return (NULL); + token->content.redir_type = type; + return (token); +} |
