From 26ddbd7146f65a2cf100713f422a9ab5b1890620 Mon Sep 17 00:00:00 2001 From: Charles Date: Sun, 14 Jun 2020 10:36:53 +0200 Subject: Changing ast related struct and fixing functions accordingly --- include/ast.h | 95 ++++++++++++++++++-------------------------------------- include/eval.h | 6 ++-- include/parse.h | 48 ---------------------------- include/parser.h | 48 ++++++++++++++++++++++++++++ 4 files changed, 82 insertions(+), 115 deletions(-) delete mode 100644 include/parse.h create mode 100644 include/parser.h (limited to 'include') diff --git a/include/ast.h b/include/ast.h index 2f3a11d..790ac29 100644 --- a/include/ast.h +++ b/include/ast.h @@ -6,7 +6,7 @@ /* By: charles +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2020/04/01 17:05:38 by charles #+# #+# */ -/* Updated: 2020/06/09 11:44:45 by charles ### ########.fr */ +/* Updated: 2020/06/14 10:28:53 by charles ### ########.fr */ /* */ /* ************************************************************************** */ @@ -20,30 +20,8 @@ # include # include -# include "libft_mem.h" -# include "libft_util.h" - -/* -** \brief Separator type -** \param SEP_END `;` Regular command end -** \param SEP_PIPE `|` Pipe output of left to right -** \param SEP_AND `&&` Execute right if left status == 0 -** \param SEP_OR `||` Execute right if left status != 0 -*/ - -typedef enum e_bool -{ - TRUE, - FALSE, -} t_bool; - -typedef enum e_sep -{ - SEP_END, - SEP_PIPE, - SEP_AND, - SEP_OR, -} t_sep; +# include "libft_lst.h" +# include "lexer.h" struct s_ast; @@ -54,29 +32,12 @@ struct s_ast; ** \param sep Type of separator */ -typedef struct s_line -{ - struct s_ast *left; - struct s_ast *right; - e_token_tag sep; -} t_line; - -/* -** \brief Command struct -** \param argv Array of string, -** all arguments beginning with executable name -** \param in STDIN redirection filename -** \param out STDOUT redirection filename -** \param is_append True if out redirection is append to file -*/ - -typedef struct s_cmd +typedef struct s_line { - t_ftlst *argv; // change to t_ftvec of t_token - t_token *in; // change to t_token - t_token *out; // change to t_token - bool is_append; -} t_cmd; + struct s_ast *left; + struct s_ast *right; + enum e_token_tag sep; +} t_line; /* ** \brief AST node tag (type) @@ -84,37 +45,43 @@ typedef struct s_cmd ** \param TAG_LINE Line AST node */ -typedef enum e_ast_tag +enum e_ast_tag { - TAG_CMD, - TAG_LINE, -} t_ast_tag; + AST_CMD, + AST_LINE, +}; /* ** \brief AST node struct ** \param tag Node tag -** \param cmd Command struct ** \param line Line struct +** \param cmd_argv Array of string tokens +** \param in STDIN redirection string tokens +** \param out STDOUT redirection string tokens +** \param is_append True if out redirection is append to file */ -typedef struct s_ast +typedef struct s_ast { - t_ast_tag tag; + enum e_ast_tag tag; union { - t_line line; - t_cmd cmd; + t_line line; + t_ftlst *cmd_argv; }; -} t_ast; + t_ftlst *in; + t_ftlst *out; + bool is_append; +} t_ast; -typedef struct s_ret +typedef struct s_ret { - t_token *unexpected; - t_ast *ast; - t_ftlst *rest; -} t_ret; + t_token *unexpected; + t_ast *ast; + t_ftlst *rest; +} t_ret; -t_ast *ast_new(t_ast_tag tag, void *data); -void ast_destroy(t_ast *ast); +t_ast *ast_new(enum e_ast_tag tag); +void ast_destroy(t_ast *ast); #endif diff --git a/include/eval.h b/include/eval.h index fc149b2..8fbbb1c 100644 --- a/include/eval.h +++ b/include/eval.h @@ -6,7 +6,7 @@ /* By: charles +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2020/04/01 17:05:30 by charles #+# #+# */ -/* Updated: 2020/05/04 11:58:16 by charles ### ########.fr */ +/* Updated: 2020/06/14 10:33:54 by charles ### ########.fr */ /* */ /* ************************************************************************** */ @@ -75,7 +75,7 @@ char *exec_search_path(t_path path, char *path_var, char *exec_name); ** pipe.c */ -int pipe_setup_parent(t_cmd *cmd, int pipe_in[2], int pipe_out[2]); -int pipe_setup_child(int pipe_in[2], int pipe_out[2]); +// int pipe_setup_parent(t_cmd *cmd, int pipe_in[2], int pipe_out[2]); +// int pipe_setup_child(int pipe_in[2], int pipe_out[2]); #endif diff --git a/include/parse.h b/include/parse.h deleted file mode 100644 index 6cb50b8..0000000 --- a/include/parse.h +++ /dev/null @@ -1,48 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* parse.h :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: cacharle +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2020/02/28 09:00:00 by cacharle #+# #+# */ -/* Updated: 2020/06/13 11:59:47 by charles ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#ifndef PARSE_H -# define PARSE_H - -# include "minishell.h" -# include "ast.h" - -/* -** \file parse.h -** \brief Input parsing and AST manipulation -** -** Context free grammar: -** ``` -** redir_in ::= '<' -** redir_out ::= '>' -** redir_append ::= '>>' -** string ::= '\'' .+ '\'' | '"' .+ '"' | [^ ]+ -** sep ::= '&&' | '||' | '|' | ';' -** expr ::= | | | -** cmd ::= + -** line ::= | -** ``` -*/ - -/* -** lexer.c -*/ - -// char **lexer(char *input); - -/* -** parse.c -*/ - -t_ast *parse(t_ftlst *lst); - -#endif diff --git a/include/parser.h b/include/parser.h new file mode 100644 index 0000000..80d039b --- /dev/null +++ b/include/parser.h @@ -0,0 +1,48 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* parser.h :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: cacharle +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2020/02/28 09:00:00 by cacharle #+# #+# */ +/* Updated: 2020/06/14 10:31:20 by charles ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#ifndef PARSE_H +# define PARSE_H + +# include "minishell.h" +# include "ast.h" + +/* +** \file parse.h +** \brief Input parsing and AST manipulation +** +** Context free grammar: +** ``` +** redir_in ::= '<' +** redir_out ::= '>' +** redir_append ::= '>>' +** string ::= '\'' .+ '\'' | '"' .+ '"' | [^ ]+ +** sep ::= '&&' | '||' | '|' | ';' +** expr ::= | | | +** cmd ::= + +** line ::= | +** ``` +*/ + +/* +** lexer.c +*/ + +// char **lexer(char *input); + +/* +** parse.c +*/ + +t_ret *parse(t_ftlst *input); + +#endif -- cgit