From 2d4d6f7c2b06f8484ad4f5833cc513814e1c7142 Mon Sep 17 00:00:00 2001 From: gwojda Date: Fri, 10 Mar 2017 15:49:48 +0100 Subject: [PATCH 1/2] le merge avait remi l'issue #44 au gout du jour --- 42sh/src/line-editing/readline.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/42sh/src/line-editing/readline.c b/42sh/src/line-editing/readline.c index 49079633..5c75131c 100644 --- a/42sh/src/line-editing/readline.c +++ b/42sh/src/line-editing/readline.c @@ -6,7 +6,7 @@ /* By: gwojda +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/12/15 14:19:48 by gwojda #+# #+# */ -/* Updated: 2017/03/09 00:09:19 by ariard ### ########.fr */ +/* Updated: 2017/03/10 15:48:30 by gwojda ### ########.fr */ /* */ /* ************************************************************************** */ @@ -22,6 +22,8 @@ int readline(int fd, int prompt, char **input) } readline_init(prompt); *input = ft_read_stdin(); + if (STR) + ft_current_str(STR, POS); ft_putchar('\n'); if (!prompt) *input = ft_history_parsing(); From e96638aca114352a329d2fa743dc28bcd5f4371e Mon Sep 17 00:00:00 2001 From: Antoine Riard Date: Fri, 10 Mar 2017 16:18:36 +0100 Subject: [PATCH 2/2] execution bang --- 42sh/Makefile | 2 + 42sh/includes/exec.h | 3 +- 42sh/includes/parser.h | 4 ++ 42sh/src/exec/exec_and_if.c | 2 +- 42sh/src/exec/exec_bang.c | 25 ++++++++++ 42sh/src/exec/exec_semi.c | 2 +- 42sh/src/exec/ft_exec.c | 3 +- 42sh/src/exec/launch_while.c | 2 +- 42sh/src/exec/mark_process_status.c | 2 +- 42sh/src/exec/set_process.c | 2 +- 42sh/src/exec/set_process_if.c | 2 +- 42sh/src/exec/set_process_while.c | 2 +- 42sh/src/main/main.c | 2 +- 42sh/src/parser/add_bang.c | 75 +++++++++++++++++++++++++++++ 42sh/src/parser/add_case.c | 4 +- 42sh/src/parser/add_cmd.c | 5 +- 42sh/src/parser/add_sep.c | 5 +- 42sh/src/parser/aggregate_sym.c | 32 ++++++------ 42sh/src/parser/build_tree.c | 4 +- 42sh/src/parser/eval_sym.c | 51 ++------------------ 42sh/src/parser/read_stack.c | 4 +- 21 files changed, 150 insertions(+), 83 deletions(-) create mode 100644 42sh/src/exec/exec_bang.c create mode 100644 42sh/src/parser/add_bang.c diff --git a/42sh/Makefile b/42sh/Makefile index 7fbe5d9f..54f998ee 100644 --- a/42sh/Makefile +++ b/42sh/Makefile @@ -63,6 +63,7 @@ exec/bad_fd.c\ exec/error_badidentifier.c\ exec/exec_ampersand.c\ exec/exec_and_if.c\ +exec/exec_bang.c\ exec/exec_case_branch.c\ exec/exec_elif.c\ exec/exec_else.c\ @@ -265,6 +266,7 @@ main/main.c\ main/shell_get_avdata.c\ main/shell_get_opts.c\ main/shell_init.c\ +parser/add_bang.c\ parser/add_case.c\ parser/add_cmd.c\ parser/add_condition.c\ diff --git a/42sh/includes/exec.h b/42sh/includes/exec.h index dc8504c9..ca7bb4aa 100644 --- a/42sh/includes/exec.h +++ b/42sh/includes/exec.h @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/27 20:29:56 by jhalford #+# #+# */ -/* Updated: 2017/03/10 13:31:17 by jhalford ### ########.fr */ +/* Updated: 2017/03/10 15:45:50 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ @@ -217,5 +217,6 @@ int exec_else(t_btree **ast); int exec_var(t_btree **ast); int exec_case_branch(t_btree **ast); int exec_math(t_btree **ast); +int exec_bang(t_btree **ast); #endif diff --git a/42sh/includes/parser.h b/42sh/includes/parser.h index 52efea58..2348579b 100644 --- a/42sh/includes/parser.h +++ b/42sh/includes/parser.h @@ -122,6 +122,8 @@ int add_pipe(t_btree **ast, t_list **lst); int add_var(t_btree **ast, t_list **lst); int add_null(t_btree **ast, t_list **lst); int add_ionumber(t_btree **ast, t_list **lst); +int add_bang(t_btree **ast, t_list **lst); +int add_bang_sep(t_btree **ast, t_list **lst); int isloop(t_btree **ast, t_list **lst); int isloop_condition(t_btree **ast, t_list **lst); @@ -142,6 +144,8 @@ int isnull(t_btree **ast, t_list **list); int isionumber(t_btree **ast, t_list **lst); int ismath(t_btree **ast, t_list **lst); int ismath_expr(t_btree **ast, t_list **lst); +int isbang(t_btree **ast, t_list **lst); +int isbang_sep(t_btree **ast, t_list **lst); int join_ast(t_btree **ast, t_btree **new_node); int gen_node(t_btree **ast); diff --git a/42sh/src/exec/exec_and_if.c b/42sh/src/exec/exec_and_if.c index b37c2fbc..32267ccf 100644 --- a/42sh/src/exec/exec_and_if.c +++ b/42sh/src/exec/exec_and_if.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/30 20:52:28 by jhalford #+# #+# */ -/* Updated: 2017/03/05 15:18:41 by jhalford ### ########.fr */ +/* Updated: 2017/03/10 14:26:32 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/exec/exec_bang.c b/42sh/src/exec/exec_bang.c new file mode 100644 index 00000000..bbca672a --- /dev/null +++ b/42sh/src/exec/exec_bang.c @@ -0,0 +1,25 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* exec_bang.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: ariard +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2017/03/10 14:46:27 by ariard #+# #+# */ +/* Updated: 2017/03/10 15:51:37 by ariard ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "minishell.h" + +int exec_bang(t_btree **ast) +{ + t_exec *exec; + + exec = &data_singleton()->exec; + push(&exec->op_stack, TK_BANG); + ft_exec(&(*ast)->left); + ft_exec(&(*ast)->right); + set_exitstatus(ft_atoi(ft_getenv(data_singleton()->env, "?")) ? 0 : 1, 1); + return (0); +} diff --git a/42sh/src/exec/exec_semi.c b/42sh/src/exec/exec_semi.c index 7f8b91ce..c042ffb6 100644 --- a/42sh/src/exec/exec_semi.c +++ b/42sh/src/exec/exec_semi.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/30 20:52:05 by jhalford #+# #+# */ -/* Updated: 2017/03/08 16:41:45 by jhalford ### ########.fr */ +/* Updated: 2017/03/10 14:55:05 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/exec/ft_exec.c b/42sh/src/exec/ft_exec.c index 34a242b5..4d5e0762 100644 --- a/42sh/src/exec/ft_exec.c +++ b/42sh/src/exec/ft_exec.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/27 20:30:32 by jhalford #+# #+# */ -/* Updated: 2017/03/08 11:57:19 by jhalford ### ########.fr */ +/* Updated: 2017/03/10 15:45:12 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ @@ -31,6 +31,7 @@ t_itof g_execmap[] = {TK_ASSIGNEMENT_WORD, &exec_var}, {MATH, &exec_math}, {SUBSHELL, &exec_leaf}, + {TK_BANG, &exec_bang}, {CMD, &exec_leaf}, {0, 0}, }; diff --git a/42sh/src/exec/launch_while.c b/42sh/src/exec/launch_while.c index 462edb8b..3b396d76 100644 --- a/42sh/src/exec/launch_while.c +++ b/42sh/src/exec/launch_while.c @@ -6,7 +6,7 @@ /* By: wescande +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/07 17:20:53 by wescande #+# #+# */ -/* Updated: 2017/03/08 15:18:36 by wescande ### ########.fr */ +/* Updated: 2017/03/10 14:28:06 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/exec/mark_process_status.c b/42sh/src/exec/mark_process_status.c index 57b21b34..58c1ab9d 100644 --- a/42sh/src/exec/mark_process_status.c +++ b/42sh/src/exec/mark_process_status.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/12/12 12:41:11 by jhalford #+# #+# */ -/* Updated: 2017/03/10 12:51:05 by jhalford ### ########.fr */ +/* Updated: 2017/03/10 14:32:05 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/exec/set_process.c b/42sh/src/exec/set_process.c index cf7f2fbf..8faa6f7b 100644 --- a/42sh/src/exec/set_process.c +++ b/42sh/src/exec/set_process.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/05 14:54:45 by jhalford #+# #+# */ -/* Updated: 2017/03/08 16:46:51 by jhalford ### ########.fr */ +/* Updated: 2017/03/10 14:54:15 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/exec/set_process_if.c b/42sh/src/exec/set_process_if.c index 3aaac67c..90b173d8 100644 --- a/42sh/src/exec/set_process_if.c +++ b/42sh/src/exec/set_process_if.c @@ -6,7 +6,7 @@ /* By: wescande +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/07 19:19:50 by wescande #+# #+# */ -/* Updated: 2017/03/08 14:59:17 by wescande ### ########.fr */ +/* Updated: 2017/03/10 14:32:31 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/exec/set_process_while.c b/42sh/src/exec/set_process_while.c index 56807c2e..22f9fd60 100644 --- a/42sh/src/exec/set_process_while.c +++ b/42sh/src/exec/set_process_while.c @@ -6,7 +6,7 @@ /* By: wescande +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/07 19:38:10 by wescande #+# #+# */ -/* Updated: 2017/03/08 14:58:54 by wescande ### ########.fr */ +/* Updated: 2017/03/10 14:32:22 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/main/main.c b/42sh/src/main/main.c index c9a68cc8..690c17b1 100644 --- a/42sh/src/main/main.c +++ b/42sh/src/main/main.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/12/06 18:40:58 by jhalford #+# #+# */ -/* Updated: 2017/03/10 13:31:16 by jhalford ### ########.fr */ +/* Updated: 2017/03/10 15:44:35 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/parser/add_bang.c b/42sh/src/parser/add_bang.c new file mode 100644 index 00000000..99283917 --- /dev/null +++ b/42sh/src/parser/add_bang.c @@ -0,0 +1,75 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* add_bang.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: ariard +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2017/03/10 14:57:45 by ariard #+# #+# */ +/* Updated: 2017/03/10 15:43:54 by ariard ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "minishell.h" + +int isbang(t_btree **ast, t_list **lst) +{ + t_astnode *node; + + (void)lst; + node = NULL; + if (*ast) + { + node = (*ast)->item; + if ((node->type == TK_NEWLINE || node->type == TK_SEMI + || node->type == TK_AMP) && isbang(&(*ast)->right, lst) == 1) + return (1); + if (node->type == TK_BANG && node->full == 0) + return (1); + } + return (0); +} + +int isbang_sep(t_btree **ast, t_list **lst) +{ + t_astnode *node; + t_token *token; + + token = (*lst)->content; + if (*ast) + { + node = (*ast)->item; + if ((token->type == TK_SEMI || token->type == TK_AMP || token->type == TK_NEWLINE + || token->type == TK_AND_IF || token->type == TK_OR_IF) && node->type == TK_BANG + && node->nest == 0) + node->full = 1; + if (token->type == TK_PIPE && node->type == TK_BANG && node->full == 0) + return (1); + } + return (0); +} + +int add_bang(t_btree **ast, t_list **lst) +{ + t_astnode *node; + t_token *token; + + DG("add bang"); + token = (*lst)->content; + node = (*ast)->item; + if ((token->type == TK_CASE || token->type == TK_WHILE + || token->type == TK_IF || token->type == TK_UNTIL || token->type == TK_FOR + || token->type == SUBSHELL || token->type == TK_LBRACE) + && node->type == TK_BANG) + node->nest++; + if ((token->type == TK_DONE || token->type == TK_ESAC || token->type == TK_FI + || token->type == TK_RBRACE || token->type == TK_PAREN_CLOSE) + && node->type == TK_BANG && node->nest > 0) + node->nest--; + return (add_cmd(&(*ast)->right, lst)); +} + +int add_bang_sep(t_btree **ast, t_list **lst) +{ + return (add_sep(&(*ast)->right, lst)); +} diff --git a/42sh/src/parser/add_case.c b/42sh/src/parser/add_case.c index bd228540..29ff29a6 100644 --- a/42sh/src/parser/add_case.c +++ b/42sh/src/parser/add_case.c @@ -6,7 +6,7 @@ /* By: ariard +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/04 20:42:13 by ariard #+# #+# */ -/* Updated: 2017/03/07 22:46:00 by ariard ### ########.fr */ +/* Updated: 2017/03/09 20:00:19 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ @@ -32,7 +32,6 @@ int iscase_pattern(t_btree **ast, t_list **lst) t_astnode *node; t_token *token; -// DG(" add pattern"); node = NULL; token = (*lst)->content; if (*ast) @@ -90,7 +89,6 @@ int add_pattern(t_btree **ast, t_list **lst) t_token *token; char **my_tab; - DG("add pattern"); token = (*lst)->content; node = (*ast)->item; if ((my_tab = (char **)malloc(sizeof(char *) * 4))) diff --git a/42sh/src/parser/add_cmd.c b/42sh/src/parser/add_cmd.c index c6c28d3d..28dd5f60 100644 --- a/42sh/src/parser/add_cmd.c +++ b/42sh/src/parser/add_cmd.c @@ -6,7 +6,7 @@ /* By: ariard +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/02/15 20:49:15 by ariard #+# #+# */ -/* Updated: 2017/03/09 19:44:51 by ariard ### ########.fr */ +/* Updated: 2017/03/10 15:22:44 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ @@ -31,6 +31,7 @@ t_distrostree g_distrostree[] = {&isfunc_name, &add_null}, {&isfunc, &add_func_cmd}, {&isionumber, &add_ionumber}, + {&isbang, &add_bang}, {&isnull, &add_null}, }; @@ -71,7 +72,7 @@ int add_cmd(t_btree **ast, t_list **lst) int i; i = -1; - while (++i < 17) + while (++i < 18) if (g_distrostree[i].test(ast, lst) == 1) { DG("add : %d", i); diff --git a/42sh/src/parser/add_sep.c b/42sh/src/parser/add_sep.c index 0a3a2a22..bb337820 100644 --- a/42sh/src/parser/add_sep.c +++ b/42sh/src/parser/add_sep.c @@ -6,7 +6,7 @@ /* By: ariard +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/02/15 19:12:07 by ariard #+# #+# */ -/* Updated: 2017/03/07 22:46:57 by ariard ### ########.fr */ +/* Updated: 2017/03/10 15:43:01 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ @@ -29,10 +29,11 @@ int add_sep(t_btree **ast, t_list **lst) return (add_subshell_sep(ast, lst)); else if (isfunc(ast, lst)) return (add_func_sep(ast, lst)); + else if (isbang_sep(ast, lst)) + return (add_bang_sep(ast, lst)); if (!*ast) gen_node(ast); token = (*lst)->content; -//watch != TK_DO new_node = NULL; gen_node(&new_node); join_ast(ast, &new_node); diff --git a/42sh/src/parser/aggregate_sym.c b/42sh/src/parser/aggregate_sym.c index 4bdf4ec9..eac0d0a7 100644 --- a/42sh/src/parser/aggregate_sym.c +++ b/42sh/src/parser/aggregate_sym.c @@ -58,6 +58,8 @@ t_aggrematch g_aggrematch[] = {TK_RBRACE, CMD_SUPERIOR, BRACE_CLAUSE, TK_LBRACE}, {TK_AND_IF, CMD_SUPERIOR, AND_OR_MINOR, CMD_SUPERIOR}, {TK_OR_IF, CMD_SUPERIOR, AND_OR_MINOR, CMD_SUPERIOR}, + {TK_AND_IF, PIPE_SEMI_SEQUENCE, AND_OR_MINOR, PIPE_SEMI_SEQUENCE}, + {TK_OR_IF, PIPE_SEMI_SEQUENCE, AND_OR_MINOR, PIPE_SEMI_SEQUENCE}, //watch this {SEPARATOR_OP, MATH_SUP, CMD_SUPERIOR, MATH_SUP}, {SEPARATOR_OP, CMD_SUPERIOR, SEPARATOR, 0}, @@ -142,7 +144,7 @@ t_aggrematch g_aggrematch[] = {IO_REDIRECT, TK_PAREN_OPEN, CMD_PREFIX, 0}, {IO_REDIRECT, TK_LBRACE, CMD_PREFIX, 0}, {IO_REDIRECT, COMPLETE_COMMANDS, CMD_PREFIX, 0}, - {IO_REDIRECT, TK_BANG, CMD_PREFIX, 0}, + {IO_REDIRECT, TK_BANG, CMD_PREFIX, TK_BANG}, {IO_REDIRECT, SEPARATOR_OP, CMD_PREFIX, 0}, {IO_REDIRECT, NEWLINE_LIST, CMD_PREFIX, 0}, {REDIRECT_LIST, COMPOUND_COMMAND, COMPOUND_COMMAND, COMPOUND_COMMAND}, @@ -156,7 +158,7 @@ t_aggrematch g_aggrematch[] = {CMD_PREFIX, TK_PAREN_OPEN, SIMPLE_COMMAND, 0}, {CMD_PREFIX, TK_LBRACE, SIMPLE_COMMAND, 0}, {CMD_PREFIX, COMPLETE_COMMANDS, SIMPLE_COMMAND, 0}, - {CMD_PREFIX, TK_BANG, SIMPLE_COMMAND, 0}, + {CMD_PREFIX, TK_BANG, SIMPLE_COMMAND, TK_BANG}, {CMD_PREFIX, SEPARATOR_OP, SIMPLE_COMMAND, 0}, {CMD_PREFIX, NEWLINE_LIST, SIMPLE_COMMAND, 0}, @@ -166,7 +168,7 @@ t_aggrematch g_aggrematch[] = {CMD_NAME, TK_PAREN_OPEN, CMD_SUPERIOR, 0}, {CMD_NAME, TK_LBRACE, CMD_SUPERIOR, 0}, {CMD_NAME, COMPLETE_COMMANDS, CMD_SUPERIOR, 0}, - {CMD_NAME, TK_BANG, CMD_SUPERIOR, 0}, + {CMD_NAME, TK_BANG, CMD_SUPERIOR, TK_BANG}, {CMD_NAME, SEPARATOR_OP, CMD_SUPERIOR, 0}, {CMD_NAME, NEWLINE_LIST, CMD_SUPERIOR, 0}, {CMD_NAME, TK_WHILE, CMD_SUPERIOR, 0}, @@ -224,7 +226,7 @@ t_aggrematch g_aggrematch[] = {AND_OR_MINOR, TK_LBRACE, AND_OR_MAJOR, 0}, {AND_OR_MINOR, COMPLETE_COMMANDS, AND_OR_MAJOR, 0}, {AND_OR_MINOR, AND_OR_MAJOR, AND_OR_MAJOR, 0}, - {AND_OR_MINOR, TK_BANG, AND_OR_MAJOR, 0}, + {AND_OR_MINOR, TK_BANG, AND_OR_MAJOR, TK_BANG}, {COMMAND, SEQUENCE, PIPE_SEMI_SEQUENCE, 0}, // watch {COMMAND, COMPOUND_LIST, PIPE_SEMI_SEQUENCE, 0}, @@ -237,11 +239,11 @@ t_aggrematch g_aggrematch[] = {COMMAND, TK_THEN, PIPE_SEMI_SEQUENCE, 0}, {COMMAND, TK_ELIF, PIPE_SEMI_SEQUENCE, 0}, {COMMAND, TK_ELSE, PIPE_SEMI_SEQUENCE, 0}, - {COMMAND, TK_BANG, PIPE_SEMI_SEQUENCE, 0}, + {COMMAND, TK_BANG, PIPE_SEMI_SEQUENCE, TK_BANG}, {COMMAND, SEPARATOR_OP, PIPE_SEMI_SEQUENCE, 0}, {COMMAND, NEWLINE_LIST, PIPE_SEMI_SEQUENCE, 0}, {COMMAND, LINEBREAK, PIPE_SEMI_SEQUENCE, 0}, - {COMMAND, TK_BANG, PIPE_SEMI_SEQUENCE, 0}, + {COMMAND, TK_BANG, PIPE_SEMI_SEQUENCE, TK_BANG}, {COMMAND, TK_PAREN_OPEN, PIPE_SEMI_SEQUENCE, 0}, {COMMAND, TK_LBRACE, PIPE_SEMI_SEQUENCE, 0}, {COMMAND, COMPLETE_COMMANDS, PIPE_SEMI_SEQUENCE, 0}, @@ -258,11 +260,11 @@ t_aggrematch g_aggrematch[] = {COMPOUND_COMMAND, TK_THEN, PIPE_CLOSE_SEQUENCE, 0}, {COMPOUND_COMMAND, TK_ELIF, PIPE_CLOSE_SEQUENCE, 0}, {COMPOUND_COMMAND, TK_ELSE, PIPE_CLOSE_SEQUENCE, 0}, - {COMPOUND_COMMAND, TK_BANG, PIPE_CLOSE_SEQUENCE, 0}, + {COMPOUND_COMMAND, TK_BANG, PIPE_CLOSE_SEQUENCE, TK_BANG}, {COMPOUND_COMMAND, SEPARATOR_OP, PIPE_CLOSE_SEQUENCE, 0}, {COMPOUND_COMMAND, NEWLINE_LIST, PIPE_CLOSE_SEQUENCE, 0}, {COMPOUND_COMMAND, LINEBREAK, PIPE_CLOSE_SEQUENCE, 0}, - {COMPOUND_COMMAND, TK_BANG, PIPE_CLOSE_SEQUENCE, 0}, + {COMPOUND_COMMAND, TK_BANG, PIPE_CLOSE_SEQUENCE, TK_BANG}, {COMPOUND_COMMAND, TK_PAREN_OPEN, PIPE_CLOSE_SEQUENCE, 0}, {COMPOUND_COMMAND, TK_LBRACE, PIPE_CLOSE_SEQUENCE, 0}, {COMPOUND_COMMAND, COMPLETE_COMMANDS, PIPE_CLOSE_SEQUENCE, 0}, @@ -275,7 +277,7 @@ t_aggrematch g_aggrematch[] = {END_COMMAND, TK_WHILE, PIPE_SEQUENCE, 0}, {END_COMMAND, TK_UNTIL, PIPE_SEQUENCE, 0}, {END_COMMAND, LINEBREAK, PIPE_SEQUENCE, 0}, - {END_COMMAND, TK_BANG, PIPE_SEQUENCE, 0}, + {END_COMMAND, TK_BANG, PIPE_SEQUENCE, TK_BANG}, {END_COMMAND, TK_PAREN_OPEN, PIPE_SEQUENCE, 0}, {END_COMMAND, TK_LBRACE, PIPE_SEQUENCE, 0}, {END_COMMAND, COMPLETE_COMMANDS, PIPE_SEQUENCE, 0}, @@ -321,7 +323,7 @@ t_aggrematch g_aggrematch[] = {PIPELINE, COMPOUND_LIST, AND_OR, 0}, {PIPELINE, CASE_LIST_NS, AND_OR, 0}, {PIPELINE, LINEBREAK, AND_OR, 0}, - {PIPELINE, TK_BANG, AND_OR, 0}, + {PIPELINE, TK_BANG, AND_OR, TK_BANG}, {PIPELINE, TK_PAREN_OPEN, AND_OR, 0}, {PIPELINE, TK_LBRACE, AND_OR, 0}, {PIPELINE, COMPLETE_COMMANDS, AND_OR, 0}, @@ -346,7 +348,7 @@ t_aggrematch g_aggrematch[] = {AND_OR, SEPARATOR_OP, LIST, LIST}, {AND_OR, NEWLINE_LIST, LIST, 0}, {AND_OR, LINEBREAK, LIST, 0}, - {AND_OR, TK_BANG, LIST, 0}, + {AND_OR, TK_BANG, LIST, TK_BANG}, {AND_OR, TK_LBRACE, LIST, 0}, {AND_OR, COMPLETE_COMMANDS, LIST, 0}, {LIST, NEWLINE_LIST, COMPLETE_COMMAND, 0}, @@ -368,21 +370,21 @@ int aggregate_sym(t_list **stack, t_sym *new_sym, t_parstate *state) return (1); i = 0; head = (*stack)->content; - DG("aggregate head %s && sym %s", - read_state(*head), read_state(*new_sym)); +// DG("aggregate head %s && sym %s", +// read_state(*head), read_state(*new_sym)); while (g_aggrematch[i].top) { if (*new_sym == g_aggrematch[i].top && MATCH_STACK(*head, g_aggrematch[i].under)) { - DG("MATCH : %s", read_state(g_aggrematch[i].new_sym)); +// DG("MATCH : %s", read_state(g_aggrematch[i].new_sym)); *new_sym = g_aggrematch[i].new_sym; if (g_aggrematch[i].erase_sym) { pop_stack(stack, g_aggrematch[i].erase_sym); head = (*stack)->content; - DG("stack after pop: %s", read_state(*head)); +// DG("stack after pop: %s", read_state(*head)); } if (eval_sym(stack, *new_sym)) { diff --git a/42sh/src/parser/build_tree.c b/42sh/src/parser/build_tree.c index f8cc9635..fd817a57 100644 --- a/42sh/src/parser/build_tree.c +++ b/42sh/src/parser/build_tree.c @@ -6,7 +6,7 @@ /* By: ariard +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/02/15 18:32:59 by ariard #+# #+# */ -/* Updated: 2017/03/09 19:45:53 by ariard ### ########.fr */ +/* Updated: 2017/03/10 15:34:58 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ @@ -16,7 +16,7 @@ t_treematch g_treematch[] = { {TK_WORD, &add_cmd}, {TK_PIPE, &add_sep}, - {TK_BANG, &add_sep}, + {TK_BANG, &add_cmd}, {TK_SEMI, &add_sep}, {TK_GREAT, &add_cmd}, {TK_LESS, &add_cmd}, diff --git a/42sh/src/parser/eval_sym.c b/42sh/src/parser/eval_sym.c index 9ca21d4a..0c95ec1e 100644 --- a/42sh/src/parser/eval_sym.c +++ b/42sh/src/parser/eval_sym.c @@ -36,7 +36,6 @@ t_stackmatch g_stackmatch[] = {TK_IO_NUMBER, TK_PAREN_OPEN}, {TK_IO_NUMBER, TK_LBRACE}, {TK_IO_NUMBER, COMPLETE_COMMANDS}, - {TK_IO_NUMBER, TK_BANG}, {TK_IO_NUMBER, SEPARATOR_OP}, {TK_IO_NUMBER, NEWLINE_LIST}, {TK_IO_NUMBER, PIPE_SEMI_SEQUENCE}, @@ -47,9 +46,10 @@ t_stackmatch g_stackmatch[] = {TK_IO_NUMBER, AND_OR_MAJOR}, {TK_AND_IF, AND_OR}, {TK_AND_IF, CMD_SUPERIOR}, + {TK_AND_IF, PIPE_SEMI_SEQUENCE}, {TK_OR_IF, AND_OR}, {TK_OR_IF, CMD_SUPERIOR}, - {TK_OR_IF, AND_OR}, + {TK_OR_IF, PIPE_SEMI_SEQUENCE}, {TK_DSEMI, LINEBREAK}, {TK_DSEMI, TK_BANG}, {TK_DSEMI, COMPLETE_COMMANDS}, @@ -67,7 +67,6 @@ t_stackmatch g_stackmatch[] = {TK_LESS, CMD_WORD}, {TK_LESS, CMD_NAME}, {TK_LESS, LINEBREAK}, - {TK_LESS, TK_BANG}, {TK_LESS, TK_PAREN_OPEN}, {TK_LESS, TK_LBRACE}, {TK_LESS, COMPLETE_COMMANDS}, @@ -91,7 +90,6 @@ t_stackmatch g_stackmatch[] = {TK_GREAT, TK_PAREN_OPEN}, {TK_GREAT, TK_LBRACE}, {TK_GREAT, COMPLETE_COMMANDS}, - {TK_GREAT, TK_BANG}, {TK_GREAT, SEPARATOR_OP}, {TK_GREAT, NEWLINE_LIST}, {TK_GREAT, PIPE_SEMI_SEQUENCE}, @@ -109,7 +107,6 @@ t_stackmatch g_stackmatch[] = {TK_DLESS, CMD_WORD}, {TK_DLESS, CMD_NAME}, {TK_DLESS, LINEBREAK}, - {TK_DLESS, TK_BANG}, {TK_DLESS, TK_PAREN_OPEN}, {TK_DLESS, TK_LBRACE}, {TK_DLESS, COMPLETE_COMMANDS}, @@ -123,28 +120,6 @@ t_stackmatch g_stackmatch[] = {TK_DLESS, CMD_SUPERIOR}, {TK_DLESS, AND_OR_MAJOR}, - {TK_DLESSDASH, TK_IO_NUMBER}, - {TK_DLESSDASH, REDIRECT_LIST}, - {TK_DLESSDASH, CMD_SUFFIX}, - {TK_DLESSDASH, CMD_PREFIX}, - {TK_DLESSDASH, CMD_WORD}, - {TK_DLESSDASH, CMD_NAME}, - {TK_DLESSDASH, LINEBREAK}, - {TK_DLESSDASH, TK_BANG}, - {TK_DLESSDASH, TK_PAREN_OPEN}, - {TK_DLESSDASH, TK_LBRACE}, - {TK_DLESSDASH, COMPLETE_COMMANDS}, - {TK_DLESSDASH, TK_BANG}, - {TK_DLESSDASH, TK_BANG}, - {TK_DLESSDASH, SEPARATOR_OP}, - {TK_DLESSDASH, NEWLINE_LIST}, - {TK_DLESSDASH, PIPE_SEMI_SEQUENCE}, - {TK_DLESSDASH, PIPE_CLOSE_SEQUENCE}, - {TK_DLESSDASH, SEQUENCE}, -// watch ! - {TK_DLESSDASH, CMD_SUPERIOR}, - {TK_DLESSDASH, AND_OR_MAJOR}, - {TK_DGREAT, TK_IO_NUMBER}, {TK_DGREAT, REDIRECT_LIST}, {TK_DGREAT, CMD_SUFFIX}, @@ -156,8 +131,6 @@ t_stackmatch g_stackmatch[] = {TK_DGREAT, TK_PAREN_OPEN}, {TK_DGREAT, TK_LBRACE}, {TK_DGREAT, COMPLETE_COMMANDS}, - {TK_DGREAT, TK_BANG}, - {TK_DGREAT, TK_BANG}, {TK_DGREAT, SEPARATOR_OP}, {TK_DGREAT, NEWLINE_LIST}, {TK_DGREAT, PIPE_SEMI_SEQUENCE}, @@ -178,8 +151,6 @@ t_stackmatch g_stackmatch[] = {TK_LESSAND, TK_PAREN_OPEN}, {TK_LESSAND, TK_LBRACE}, {TK_LESSAND, COMPLETE_COMMANDS}, - {TK_LESSAND, TK_BANG}, - {TK_LESSAND, TK_BANG}, {TK_LESSAND, SEPARATOR_OP}, {TK_LESSAND, NEWLINE_LIST}, {TK_LESSAND, PIPE_SEMI_SEQUENCE}, @@ -200,8 +171,6 @@ t_stackmatch g_stackmatch[] = {TK_GREATAND, TK_PAREN_OPEN}, {TK_GREATAND, TK_LBRACE}, {TK_GREATAND, COMPLETE_COMMANDS}, - {TK_LESSAND, TK_BANG}, - {TK_GREATAND, TK_BANG}, {TK_GREATAND, SEPARATOR_OP}, {TK_GREATAND, NEWLINE_LIST}, {TK_GREATAND, PIPE_SEMI_SEQUENCE}, @@ -217,7 +186,6 @@ t_stackmatch g_stackmatch[] = {TK_IF, TK_PAREN_OPEN}, {TK_IF, TK_LBRACE}, {TK_IF, COMPLETE_COMMANDS}, - {TK_IF, TK_BANG}, {TK_IF, SEPARATOR_OP}, {TK_IF, NEWLINE_LIST}, {TK_IF, SEQUENCE}, @@ -260,7 +228,6 @@ t_stackmatch g_stackmatch[] = {TK_CASE, TK_PAREN_OPEN}, {TK_CASE, TK_LBRACE}, {TK_CASE, COMPLETE_COMMANDS}, - {TK_CASE, TK_BANG}, {TK_CASE, TK_DO}, {TK_CASE, TK_THEN}, {TK_CASE, TK_PAREN_CLOSE}, @@ -281,10 +248,8 @@ t_stackmatch g_stackmatch[] = {TK_IN, NAME}, {TK_ESAC, CASE_LIST_NS}, {TK_ESAC, LINEBREAK}, - {TK_ESAC, TK_BANG}, {TK_ESAC, TK_IN}, {TK_WHILE, LINEBREAK}, - {TK_WHILE, TK_BANG}, {TK_WHILE, TK_PAREN_OPEN}, {TK_WHILE, TK_LBRACE}, {TK_WHILE, COMPLETE_COMMANDS}, @@ -306,7 +271,6 @@ t_stackmatch g_stackmatch[] = {TK_WHILE, TK_THEN}, {TK_WHILE, COMPLETE_CONDITION}, {TK_UNTIL, LINEBREAK}, - {TK_UNTIL, TK_BANG}, {TK_UNTIL, TK_PAREN_OPEN}, {TK_UNTIL, TK_LBRACE}, {TK_UNTIL, COMPLETE_COMMANDS}, @@ -332,8 +296,6 @@ t_stackmatch g_stackmatch[] = {TK_FOR, TK_PAREN_OPEN}, {TK_FOR, TK_LBRACE}, {TK_FOR, COMPLETE_COMMANDS}, - {TK_FOR, TK_BANG}, - {TK_FOR, TK_BANG}, {TK_FOR, SEPARATOR_OP}, {TK_FOR, NEWLINE_LIST}, {TK_FOR, SEQUENCE}, @@ -354,7 +316,6 @@ t_stackmatch g_stackmatch[] = {TK_LBRACE, LINEBREAK}, {TK_LBRACE, TK_BANG}, {TK_LBRACE, TK_LBRACE}, - {TK_LBRACE, TK_BANG}, {TK_LBRACE, SEPARATOR_OP}, {TK_LBRACE, NEWLINE_LIST}, {TK_LBRACE, SEQUENCE}, @@ -836,7 +797,6 @@ t_stackmatch g_stackmatch[] = {IF_CLAUSE, TK_PAREN_OPEN}, {IF_CLAUSE, TK_LBRACE}, {IF_CLAUSE, COMPLETE_COMMANDS}, - {IF_CLAUSE, TK_BANG}, {IF_CLAUSE, SEPARATOR_OP}, {IF_CLAUSE, NEWLINE_LIST}, {IF_CLAUSE, SEQUENCE}, @@ -856,7 +816,6 @@ t_stackmatch g_stackmatch[] = {IF_CLAUSE, COMPLETE_CONDITION}, {IF_CLAUSE, AND_OR_MAJOR}, {BRACE_CLAUSE, LINEBREAK}, - {BRACE_CLAUSE, TK_BANG}, {BRACE_CLAUSE, TK_PAREN_OPEN}, {BRACE_CLAUSE, TK_LBRACE}, {BRACE_CLAUSE, COMPLETE_COMMANDS}, @@ -889,7 +848,6 @@ t_stackmatch g_stackmatch[] = {CASE_CLAUSE, TK_PAREN_OPEN}, {CASE_CLAUSE, TK_LBRACE}, {CASE_CLAUSE, COMPLETE_COMMANDS}, - {CASE_CLAUSE, TK_BANG}, {CASE_CLAUSE, SEPARATOR_OP}, {CASE_CLAUSE, NEWLINE_LIST}, {CASE_CLAUSE, SEQUENCE}, @@ -1012,7 +970,6 @@ t_stackmatch g_stackmatch[] = {COMMAND, COMPOUND_LIST}, {COMMAND, CASE_LIST_NS}, {COMMAND, COMPLETE_CONDITION}, - {COMMAND, TK_BANG}, {COMMAND, SEPARATOR_OP}, {COMMAND, NEWLINE_LIST}, {COMMAND, SEQUENCE}, @@ -1042,8 +999,6 @@ t_stackmatch g_stackmatch[] = {PIPE_SEQUENCE, TK_PAREN_OPEN}, {PIPE_SEQUENCE, TK_LBRACE}, {PIPE_SEQUENCE, COMPLETE_COMMANDS}, - {PIPE_SEQUENCE, TK_BANG}, - {PIPE_SEQUENCE, TK_BANG}, {PIPE_SEQUENCE, SEPARATOR_OP}, {PIPE_SEQUENCE, NEWLINE_LIST}, {PIPE_SEQUENCE, AND_OR_MAJOR}, @@ -1192,7 +1147,7 @@ int eval_sym(t_list **stack, t_sym new_sym) if (!*stack) return (1); head = (*stack)->content; - DG("eval head %s && sym %s", read_state(*head), read_state(new_sym)); +// DG("eval head %s && sym %s", read_state(*head), read_state(new_sym)); i = 0; while (g_stackmatch[i].top) { diff --git a/42sh/src/parser/read_stack.c b/42sh/src/parser/read_stack.c index c25ebb3a..65142d78 100644 --- a/42sh/src/parser/read_stack.c +++ b/42sh/src/parser/read_stack.c @@ -6,7 +6,7 @@ /* By: ariard +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/02/09 15:32:10 by ariard #+# #+# */ -/* Updated: 2017/03/09 15:25:25 by ariard ### ########.fr */ +/* Updated: 2017/03/10 14:44:52 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ @@ -14,6 +14,8 @@ char *read_state(t_sym current) { + if (current == TK_BANG) + return ("TK_BANG"); if (current == OPEN_FUNC) return ("OPEN_FUNC"); if (current == CLOSE_FUNC)