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 /include | |
| 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 'include')
| -rw-r--r-- | include/ast.h | 79 | ||||
| -rw-r--r-- | include/debug_tools.h | 3 | ||||
| -rw-r--r-- | include/minishell.h | 4 | ||||
| -rw-r--r-- | include/token.h | 49 |
4 files changed, 133 insertions, 2 deletions
diff --git a/include/ast.h b/include/ast.h new file mode 100644 index 0000000..e6ad25d --- /dev/null +++ b/include/ast.h @@ -0,0 +1,79 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ast.h :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: dkaiser <dkaiser@student.42heilbronn.de +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2024/06/27 11:48:27 by dkaiser #+# #+# */ +/* Updated: 2024/06/28 14:56:55 by dkaiser ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "stdlib.h" +#include "debug_tools.h" + +typedef struct s_sequence +{ + struct s_node **nodes; +} t_sequence; + +enum e_node_type +{ + ASSIGN_NODE, + PIPE_NODE, + CMD_NODE, + STRING_NODE +}; + +typedef struct s_assign +{ + char *var; + char *value; +} t_assign; + +typedef struct s_pipe +{ + struct s_node *left; + struct s_node *right; +} t_pipe; + +enum e_redirection_type +{ + INPUT_FILE, + INPUT_LIMITER, + OUTPUT_OVERRIDE, + OUTPUT_APPEND +}; + +typedef struct s_redirection +{ + int type; + char *specifier; +} t_redirection; + +typedef struct s_cmd +{ + char **args; + struct s_redirection redirs[2]; +} t_cmd; + +union u_node_content +{ + struct s_assign assign; + struct s_pipe pipe; + struct s_cmd cmd; + char *string; +}; + +typedef struct s_node +{ + int type; + union u_node_content content; +} t_node; + +t_node *new_node(int type); +t_node *new_assign_node(char *var, char *value); +t_node *new_pipe_node(t_node *left, t_node *right); +t_node *new_cmd_node(char **args, t_redirection redirs[2]); +t_node *new_string_node(char *string); diff --git a/include/debug_tools.h b/include/debug_tools.h index e831ecc..4a7ff10 100644 --- a/include/debug_tools.h +++ b/include/debug_tools.h @@ -6,7 +6,7 @@ /* By: dkaiser <dkaiser@student.42heilbronn.de +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/06/24 18:34:37 by dkaiser #+# #+# */ -/* Updated: 2024/06/24 18:51:53 by dkaiser ### ########.fr */ +/* Updated: 2024/06/28 15:05:12 by dkaiser ### ########.fr */ /* */ /* ************************************************************************** */ @@ -18,6 +18,7 @@ # ifndef DEBUG # define DEBUG 0 # endif +# define UNREACHABLE "Unreachable." void dbg(char *str); void panic(char *msg); diff --git a/include/minishell.h b/include/minishell.h index 8dab21a..a528e4a 100644 --- a/include/minishell.h +++ b/include/minishell.h @@ -6,7 +6,7 @@ /* By: dkaiser <dkaiser@student.42heilbronn.de +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/06/22 17:14:49 by dkaiser #+# #+# */ -/* Updated: 2024/06/25 15:02:38 by dkaiser ### ########.fr */ +/* Updated: 2024/06/27 18:47:31 by dkaiser ### ########.fr */ /* */ /* ************************************************************************** */ @@ -14,6 +14,8 @@ # define MINISHELL_H # include "debug_tools.h" +# include "ast.h" +# include "token.h" # include "libft.h" # include <stdio.h> # include <readline/readline.h> diff --git a/include/token.h b/include/token.h new file mode 100644 index 0000000..38e758f --- /dev/null +++ b/include/token.h @@ -0,0 +1,49 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* token.h :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: dkaiser <dkaiser@student.42heilbronn.de +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2024/06/27 13:27:18 by dkaiser #+# #+# */ +/* Updated: 2024/06/28 14:59:19 by dkaiser ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#ifndef TOKEN_H +# define TOKEN_H + +# include "stdlib.h" + +enum e_token_type +{ + STRING_TOKEN, + PIPE_TOKEN, + REDIR_TOKEN, + NEWLINE_TOKEN +}; + +union u_token_content +{ + char *string; + int redir_type; +}; + +typedef struct s_token +{ + int type; + union u_token_content content; + struct s_token *previous; + struct s_token *next; +} t_token; + +t_token *new_token(int type, t_token *previous, + t_token *next); +t_token *new_str_token(char *str, t_token *previous, + t_token *next); +t_token *new_redir_token(int type, t_token *previous, + t_token *next); + +void free_token(t_token *token); + +#endif |
