diff options
Diffstat (limited to 'include')
| -rw-r--r-- | include/ast.h | 88 | ||||
| -rw-r--r-- | include/error.h | 36 | ||||
| -rw-r--r-- | include/eval.h | 4 | ||||
| -rw-r--r-- | include/lexer.h | 3 | ||||
| -rw-r--r-- | include/minishell.h | 20 | ||||
| -rw-r--r-- | include/parser.h | 89 |
6 files changed, 125 insertions, 115 deletions
diff --git a/include/ast.h b/include/ast.h deleted file mode 100644 index 8048dd2..0000000 --- a/include/ast.h +++ /dev/null @@ -1,88 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* ast.h :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: charles <charles@student.42.fr> +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2020/04/01 17:05:38 by charles #+# #+# */ -/* Updated: 2020/08/27 18:38:45 by charles ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#ifndef AST_H -# define AST_H - -/* -** \file ast.h -** \brief AST structs -*/ - -# include <stdlib.h> -# include <stdbool.h> -# include "libft_lst.h" -# include "lexer.h" - -struct s_ast; - -/* -** \brief Operation struct -** \param left AST to the left of separator -** \param right AST to the right of separator -** \param sep Type of separator -*/ - - -typedef struct s_op -{ - struct s_ast *left; - struct s_ast *right; - enum e_tok sep; -} t_op; - -/* -** \brief AST node tag (type) -** \param TAG_CMD Command AST node -** \param TAG_OP Operation AST node -*/ - -enum e_ast -{ - AST_CMD, - AST_OP, - AST_PARENT, -}; - -/* -** \brief AST node struct -** \param tag Node tag -** \param op Operation 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 -{ - enum e_ast tag; - union - { - t_op op; - t_tok_lst *cmd_argv; - struct s_ast *parent_ast; - }; - t_tok_lst *redirs; -} t_ast; - -typedef struct s_parsed -{ - bool syntax_error; - t_ast *ast; - t_tok_lst *rest; -} t_parsed; - -t_ast *ast_new(enum e_ast tag); -void ast_destroy(t_ast *ast); - -#endif diff --git a/include/error.h b/include/error.h new file mode 100644 index 0000000..941f1b2 --- /dev/null +++ b/include/error.h @@ -0,0 +1,36 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* error.h :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: charles <me@cacharle.xyz> +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2020/08/27 20:34:25 by charles #+# #+# */ +/* Updated: 2020/08/27 20:38:52 by charles ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#ifndef ERROR_H +# define ERROR_H + +# include <stdarg.h> +# include "libft_io.h" + +/* +** error.c +*/ + +typedef enum +{ + ERR_FATAL = -1, + ERR_NONE = 0, + ERR_AMBIGUOUS_REDIR = 1, + ERR_OPEN = 1, + ERR_CMD_NOT_FOUND = 127, + ERR_SYNTAX = 2, +} t_err; + +void errorf(const char *format, ...); +void verrorf(const char *format, va_list ap); + +#endif diff --git a/include/eval.h b/include/eval.h index c9adf72..761c152 100644 --- a/include/eval.h +++ b/include/eval.h @@ -6,7 +6,7 @@ /* By: charles <charles@student.42.fr> +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2020/04/01 17:05:30 by charles #+# #+# */ -/* Updated: 2020/08/27 17:15:19 by charles ### ########.fr */ +/* Updated: 2020/08/27 20:31:35 by charles ### ########.fr */ /* */ /* ************************************************************************** */ @@ -20,7 +20,7 @@ # include "minishell.h" # include "lexer.h" -# include "ast.h" +# include "parser.h" typedef struct { diff --git a/include/lexer.h b/include/lexer.h index bdb05da..f8e16bc 100644 --- a/include/lexer.h +++ b/include/lexer.h @@ -6,7 +6,7 @@ /* By: nahaddac <nahaddac@student.42.fr> +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2020/06/19 10:51:26 by nahaddac #+# #+# */ -/* Updated: 2020/08/27 18:44:17 by charles ### ########.fr */ +/* Updated: 2020/08/27 20:55:27 by charles ### ########.fr */ /* */ /* ************************************************************************** */ @@ -60,6 +60,7 @@ void tok_lst_push_back(t_tok_lst **tokens, t_tok_lst *pushed); t_tok_lst *tok_lst_push_front(t_tok_lst **tokens, t_tok_lst *pushed); void *tok_lst_destroy(t_tok_lst **tokens, void (*del)(void*)); t_tok_lst *tok_lst_last(t_tok_lst *tokens); +t_tok_lst *tok_lst_pop_front(t_tok_lst **tokens); /* ** lexer.c diff --git a/include/minishell.h b/include/minishell.h index 1b23952..4bcd681 100644 --- a/include/minishell.h +++ b/include/minishell.h @@ -6,7 +6,7 @@ /* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2020/02/26 15:33:51 by cacharle #+# #+# */ -/* Updated: 2020/08/27 17:18:43 by charles ### ########.fr */ +/* Updated: 2020/08/27 20:34:44 by charles ### ########.fr */ /* */ /* ************************************************************************** */ @@ -38,6 +38,7 @@ # include "libft_dstr.h" # include "lexer.h" +# include "error.h" /* ** \brief Value of pipe entry if closed @@ -113,23 +114,6 @@ char **preprocess(t_tok_lst **tokens, t_env env); char *preprocess_filename(t_tok_lst **tokens, t_env env); /* -** error.c -*/ - -typedef enum -{ - ERR_FATAL = -1, - ERR_NONE = 0, - ERR_AMBIGUOUS_REDIR = 1, - ERR_OPEN = 1, - ERR_CMD_NOT_FOUND = 127, - ERR_SYNTAX = 2, -} t_err; - -void errorf(const char *format, ...); -void verrorf(const char *format, va_list ap); - -/* ** signal.c */ diff --git a/include/parser.h b/include/parser.h index 7103d0b..061d8f2 100644 --- a/include/parser.h +++ b/include/parser.h @@ -6,19 +6,15 @@ /* By: cacharle <cacharle@student.42.fr> +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2020/02/28 09:00:00 by cacharle #+# #+# */ -/* Updated: 2020/08/27 18:40:55 by charles ### ########.fr */ +/* Updated: 2020/08/27 20:38:13 by charles ### ########.fr */ /* */ /* ************************************************************************** */ #ifndef PARSE_H # define PARSE_H -# include "minishell.h" -#include "libft_str.h" -# include "ast.h" - /* -** \file parse.h +** \file parser.h ** \brief Input parsing and AST manipulation ** ** Context free grammar: @@ -34,6 +30,86 @@ ** ``` */ +# include <stdlib.h> +# include <stdbool.h> +# include "libft_lst.h" +# include "lexer.h" +# include "error.h" + +struct s_ast; + +/* +** \brief Operation struct +** \param left AST to the left of separator +** \param right AST to the right of separator +** \param sep Type of separator +*/ + + +typedef struct s_op +{ + struct s_ast *left; + struct s_ast *right; + enum e_tok sep; +} t_op; + +/* +** \brief AST node tag (type) +** \param TAG_CMD Command AST node +** \param TAG_OP Operation AST node +** \param TAG_PARENT Parenthesis AST node +*/ + +enum e_ast +{ + AST_CMD, + AST_OP, + AST_PARENT, +}; + +/* +** \brief AST node struct +** \param tag Node tag +** \param op Operation struct +** \param cmd_argv Command argv tokens +** \param parend_ast AST inside parenthesis +** \param redirs Redirections tokens +*/ + +typedef struct s_ast +{ + enum e_ast tag; + union + { + t_op op; + t_tok_lst *cmd_argv; + struct s_ast *parent_ast; + }; + t_tok_lst *redirs; +} t_ast; + +/* +** ast.c +*/ + +t_ast *ast_new(enum e_ast tag); +void ast_destroy(t_ast *ast); + +/* +** parsed.c +*/ + +typedef struct s_parsed +{ + bool syntax_error; + t_ast *ast; + t_tok_lst *rest; +} t_parsed; + +t_parsed *parsed_new(t_ast *ast, t_tok_lst *rest); +t_parsed *parsed_error(const char *format, ...); + + /* ** parse.c */ @@ -43,4 +119,5 @@ t_parsed *parse_op(t_tok_lst *input); t_parsed *parse_expr(t_tok_lst *input); t_parsed *parse_cmd(t_tok_lst *input); + #endif |
