diff --git a/42sh/includes/parser.h b/42sh/includes/parser.h index 8fa80d31..ba7130e3 100644 --- a/42sh/includes/parser.h +++ b/42sh/includes/parser.h @@ -77,7 +77,7 @@ int pop_stack(t_list **stack, t_sym erase_sym); int pop_heredoc(t_list **lst); int error_syntax(t_list **token, t_parser *parser, t_btree **ast); -int error_EOF(t_list **token, t_parser *parser, t_btree **ast); +int error_eof(t_list **token, t_parser *parser, t_btree **ast); int ft_read_stack(t_sym *stack); char *read_state(t_sym current); diff --git a/42sh/src/main/main.c b/42sh/src/main/main.c index 953b2e30..4f7025fa 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 16:29:09 by ariard ### ########.fr */ +/* Updated: 2017/03/11 16:10:29 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ @@ -33,7 +33,7 @@ int handle_instruction(int fd) { if (ret == -1) return (-1); - return (parser.state == UNDEFINED ? error_EOF(&token, + return (parser.state == UNDEFINED ? error_eof(&token, &parser, &ast) : 1); } if (lexer.state == HEREDOC) @@ -70,10 +70,9 @@ int handle_instruction(int fd) return (error_syntax(&token, &parser, &ast)); } } - DG("Before execution:"); btree_print(STDBUG, ast, &ft_putast); -// if (ft_exec(&ast)) -// return (1); + if (ft_exec(&ast)) + return (1); instruction_free(&token, &parser, &ast); ft_add_str_in_history(lexer.str); return (0); diff --git a/42sh/src/parser/add_bang.c b/42sh/src/parser/add_bang.c index 1481e95d..5ec6d321 100644 --- a/42sh/src/parser/add_bang.c +++ b/42sh/src/parser/add_bang.c @@ -6,7 +6,7 @@ /* By: ariard +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/10 14:57:45 by ariard #+# #+# */ -/* Updated: 2017/03/10 17:35:55 by ariard ### ########.fr */ +/* Updated: 2017/03/11 16:23:26 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ @@ -23,24 +23,25 @@ int isbang(t_btree **ast, t_list **lst) node = (*ast)->item; if ((node->type == TK_NEWLINE || node->type == TK_SEMI || node->type == TK_AMP) && isbang(&(*ast)->right, lst) == 1) - return (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 + 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) @@ -58,12 +59,13 @@ int add_bang(t_btree **ast, t_list **lst) 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) + || 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) + 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)); diff --git a/42sh/src/parser/add_case.c b/42sh/src/parser/add_case.c index a46337da..f4a2c1bc 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/10 18:10:47 by ariard ### ########.fr */ +/* Updated: 2017/03/11 15:33:30 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ @@ -21,7 +21,7 @@ int iscase(t_btree **ast, t_list **lst) if (*ast) { node = (*ast)->item; - if (node->type == TK_CASE|| node->type == TK_PAREN_OPEN) + if (node->type == TK_CASE || node->type == TK_PAREN_OPEN) return (1); } return (0); @@ -74,21 +74,21 @@ int add_case_cmd(t_btree **ast, t_list **lst) if (token->type == TK_ESAC && (node->type == TK_PAREN_OPEN || node->type == TK_CASE) && node->nest > 0) return ((node->nest--)); - else if (token->type == TK_DSEMI && node->type == TK_PAREN_OPEN + else if (token->type == TK_DSEMI && node->type == TK_PAREN_OPEN && node->nest == 0) return ((node->full = 1)); else if ((token->type == TK_ESAC || token->type == TK_PAREN_CLOSE) && node->nest == 0) return (0); return (add_cmd(&(*ast)->right, lst)); -} +} int add_pattern(t_btree **ast, t_list **lst) { t_astnode *node; t_token *token; char **my_tab; - + 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 84e3968c..c0cdadaf 100644 --- a/42sh/src/parser/add_cmd.c +++ b/42sh/src/parser/add_cmd.c @@ -6,13 +6,13 @@ /* By: ariard +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/02/15 20:49:15 by ariard #+# #+# */ -/* Updated: 2017/03/11 15:06:03 by ariard ### ########.fr */ +/* Updated: 2017/03/11 15:34:23 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ #include "minishell.h" -t_distrostree g_distrostree[] = +t_distrostree g_distrostree[] = { {&superflous_token, &add_null}, {&isdir_condition, &add_redir_condition}, @@ -66,7 +66,7 @@ static int no_del_token(t_btree **ast, t_list **lst) return (0); } -int add_cmd(t_btree **ast, t_list **lst) +int add_cmd(t_btree **ast, t_list **lst) { t_token *token; t_astnode *node; @@ -75,10 +75,7 @@ int add_cmd(t_btree **ast, t_list **lst) i = -1; while (++i < 19) if (g_distrostree[i].test(ast, lst) == 1) - { - DG("add : %d", i); return (g_distrostree[i].add(ast, lst)); - } if (!*ast) gen_node(ast); else if (no_del_token(ast, lst)) diff --git a/42sh/src/parser/add_condition.c b/42sh/src/parser/add_condition.c index b7c47762..2825ace2 100644 --- a/42sh/src/parser/add_condition.c +++ b/42sh/src/parser/add_condition.c @@ -6,7 +6,7 @@ /* By: ariard +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/10 17:06:16 by ariard #+# #+# */ -/* Updated: 2017/03/10 18:10:42 by ariard ### ########.fr */ +/* Updated: 2017/03/11 15:36:33 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ @@ -25,8 +25,8 @@ int iscondition(t_btree **ast, t_list **lst) if ((node->type == TK_NEWLINE || node->type == TK_SEMI || node->type == TK_AMP) && iscondition(&(*ast)->right, lst) == 1) return (1); - if ((node->type == TK_IF || node->type == TK_ELIF || node->type == TK_ELSE) - && node->full == 0) + if ((node->type == TK_IF || node->type == TK_ELIF + || node->type == TK_ELSE) && node->full == 0) return (1); } return (0); @@ -63,8 +63,8 @@ int add_condition_cmd(t_btree **ast, t_list **lst) if (token->type == TK_FI && (node->type == TK_IF || node->type == TK_ELIF || node->type == TK_ELSE) && node->nest > 0) node->nest--; - else if (token->type == TK_FI && (node->type == TK_IF || node->type == TK_ELIF - || node->type == TK_ELSE)) + else if (token->type == TK_FI && (node->type == TK_IF + || node->type == TK_ELIF || node->type == TK_ELSE)) return ((node->full = 1)); if (token->type == TK_THEN) return (add_cmd(&(*ast)->right, lst)); @@ -75,7 +75,6 @@ int add_condition_cmd(t_btree **ast, t_list **lst) return (0); } - int add_condition_sep(t_btree **ast, t_list **lst) { if (!(*ast)->right) diff --git a/42sh/src/parser/add_func.c b/42sh/src/parser/add_func.c index e417bcbf..909a915e 100644 --- a/42sh/src/parser/add_func.c +++ b/42sh/src/parser/add_func.c @@ -6,7 +6,7 @@ /* By: ariard +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/02/24 23:43:07 by ariard #+# #+# */ -/* Updated: 2017/03/08 03:21:13 by wescande ### ########.fr */ +/* Updated: 2017/03/11 15:41:11 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ @@ -23,12 +23,12 @@ int isfunc_name(t_btree **ast, t_list **lst) node = (*ast)->item; if (node->type == CMD && token->type == TK_PAREN_OPEN) { - DG("add func name"); node->type = FNAME; node->data.str = ft_strdup(token->data); return (1); } - if (node->type == FNAME && token->type == TK_PAREN_CLOSE && node->nest == 0) + if (node->type == FNAME && token->type == TK_PAREN_CLOSE + && node->nest == 0) return (1); } return (0); @@ -37,7 +37,7 @@ int isfunc_name(t_btree **ast, t_list **lst) int isfunc(t_btree **ast, t_list **lst) { t_astnode *node; - + (void)lst; node = NULL; if (*ast) @@ -57,21 +57,22 @@ int add_func_cmd(t_btree **ast, t_list **lst) t_astnode *node; t_token *token; - DG("add func cmd"); 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 == FNAME) + 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 == FNAME) 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 == FNAME && node->nest > 0) + if ((token->type == TK_DONE || token->type == TK_ESAC + || token->type == TK_FI || token->type == TK_RBRACE + || token->type == TK_PAREN_CLOSE) && node->type == FNAME + && node->nest > 0) 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 == FNAME && node->nest == 0) + if ((token->type == TK_DONE || token->type == TK_ESAC + || token->type == TK_FI || token->type == TK_RBRACE + || token->type == TK_PAREN_CLOSE) && node->type == FNAME + && node->nest == 0) { node->full = 1; add_one_func(ast, lst); @@ -91,6 +92,5 @@ int add_one_func(t_btree **ast, t_list **lst) (void)lst; func_ast = btree_map(*ast, node_copy); ft_lsteadd(&data_singleton()->lst_func, ft_lstnew(&func_ast, sizeof(*ast))); - DG("arbre ajoute"); return (0); } diff --git a/42sh/src/parser/add_loop.c b/42sh/src/parser/add_loop.c index ec5c877c..c49ca8cb 100644 --- a/42sh/src/parser/add_loop.c +++ b/42sh/src/parser/add_loop.c @@ -6,7 +6,7 @@ /* By: ariard +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/02/17 22:17:14 by ariard #+# #+# */ -/* Updated: 2017/03/10 17:14:21 by ariard ### ########.fr */ +/* Updated: 2017/03/11 15:44:47 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ @@ -41,8 +41,8 @@ int isloop_condition(t_btree **ast, t_list **lst) if (*ast) { node = (*ast)->item; - if (node->type == TK_FOR && (token->type == TK_WORD || token->type == TK_NAME) - && node->pattern == 0) + if (node->type == TK_FOR && (token->type == TK_WORD + || token->type == TK_NAME) && node->pattern == 0) return (1); } return (0); @@ -55,16 +55,16 @@ int add_loop_cmd(t_btree **ast, t_list **lst) token = (*lst)->content; node = (*ast)->item; - DG("add loop cmd"); if (token->type == TK_DO && node->type == TK_FOR) node->pattern = 1; - if ((token->type == TK_WHILE || token->type == TK_UNTIL || token->type == TK_FOR) - && (node->type == TK_WHILE || node->type == TK_UNTIL || node->type == TK_FOR)) + if ((token->type == TK_WHILE || token->type == TK_UNTIL + || token->type == TK_FOR) && (node->type == TK_WHILE + || node->type == TK_UNTIL || node->type == TK_FOR)) node->nest++; if (token->type == TK_DONE && (node->type == TK_WHILE || node->type == TK_UNTIL || node->type == TK_FOR) && node->nest > 0) node->nest--; - else if (token->type == TK_DONE && (node->type == TK_WHILE + else if (token->type == TK_DONE && (node->type == TK_WHILE || node->type == TK_UNTIL || node->type == TK_FOR) && node->nest == 0) return ((node->full = 1)); if (token->type == TK_DO && node->nest == 0) @@ -89,18 +89,10 @@ int add_loop_condition(t_btree **ast, t_list **lst) { t_astnode *node; t_token *token; - char **my_tab; token = (*lst)->content; node = (*ast)->item; - DG("add word"); - if ((my_tab = (char **)malloc(sizeof(char *) * 4))) - { - my_tab[0] = ft_strdup(token->data); - my_tab[1] = (char *)dup_char_esc(token->esc, token->size >> 3); - my_tab[2] = (char *)dup_char_esc(token->esc2, token->size >> 3); - my_tab[3] = NULL; - } - ft_ld_pushback(&node->data.cmd.wordlist, my_tab); + ft_ld_pushback(&node->data.cmd.wordlist, + gen_tab(token->data, token->esc, token->esc2, 1)); return (0); } diff --git a/42sh/src/parser/add_math.c b/42sh/src/parser/add_math.c index a309a957..4aa68f2c 100644 --- a/42sh/src/parser/add_math.c +++ b/42sh/src/parser/add_math.c @@ -1,3 +1,15 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* add_math.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: ariard +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2017/03/11 15:44:53 by ariard #+# #+# */ +/* Updated: 2017/03/11 15:45:21 by ariard ### ########.fr */ +/* */ +/* ************************************************************************** */ + #include "minishell.h" int ismath(t_btree **ast, t_list **lst) @@ -21,7 +33,6 @@ int ismath(t_btree **ast, t_list **lst) return (0); } - int ismath_expr(t_btree **ast, t_list **lst) { t_astnode *node; diff --git a/42sh/src/parser/add_number.c b/42sh/src/parser/add_number.c index 67873692..17f55286 100644 --- a/42sh/src/parser/add_number.c +++ b/42sh/src/parser/add_number.c @@ -6,7 +6,7 @@ /* By: ariard +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/05 17:28:31 by ariard #+# #+# */ -/* Updated: 2017/03/06 15:56:00 by ariard ### ########.fr */ +/* Updated: 2017/03/11 15:46:06 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ @@ -14,7 +14,7 @@ int isionumber(t_btree **ast, t_list **lst) { - t_token *token; + t_token *token; t_astnode *node; token = (*lst)->content; @@ -44,7 +44,7 @@ int add_ionumber(t_btree **ast, t_list **lst) token = (*lst)->content; node = (*ast)->item; node->type = token->type; - redir.n = ft_atoi(token->data); + redir.n = ft_atoi(token->data); ft_lsteadd(&node->data.cmd.redir, ft_lstnew(&redir, sizeof(redir))); - return (0); + return (0); } diff --git a/42sh/src/parser/add_redir.c b/42sh/src/parser/add_redir.c index cb8de962..bf9107c6 100644 --- a/42sh/src/parser/add_redir.c +++ b/42sh/src/parser/add_redir.c @@ -6,7 +6,7 @@ /* By: ariard +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/02/17 16:39:05 by ariard #+# #+# */ -/* Updated: 2017/03/11 14:51:00 by ariard ### ########.fr */ +/* Updated: 2017/03/11 15:52:20 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ @@ -25,21 +25,18 @@ int isdir_sep(t_btree **ast, t_list **list) || node->type == TK_WHILE || node->type == TK_IF || node->type == TK_FOR || node->type == SUBSHELL || node->type == TK_CASE || node->type == TK_RBRACE - || node->type == TK_UNTIL) + || node->type == TK_UNTIL) && (token->type == TK_LESS || token->type == TK_GREAT || token->type == TK_GREATAND || token->type == TK_LESSAND || token->type == TK_DLESS || token->type == TK_DGREAT)) return (1); } if (!*ast) - { + { if (token->type == TK_LESS || token->type == TK_GREAT || token->type == TK_GREATAND || token->type == TK_LESSAND || token->type == TK_DLESS || token->type == TK_DGREAT) - { - DG("add dir sep"); return (1); - } } return (0); } @@ -74,9 +71,7 @@ int add_redir_word(t_btree **ast, t_list **lst) node = (*ast)->item; if (node->data.cmd.redir) { - DG("add file"); - redir = (ft_lstlast(node->data.cmd.redir))->content; - DG("now redir.type :%s", read_state(redir->type)); + redir = (ft_lstlast(node->data.cmd.redir))->content; redir->word = ft_strdup(token->data); if (redir->type == TK_DLESS) { @@ -87,40 +82,49 @@ int add_redir_word(t_btree **ast, t_list **lst) return (0); } +static int add_redir_type_number(t_btree **ast, t_list **lst) +{ + t_redir *temp; + t_redir *temp_heredoc; + t_astnode *node; + t_token *token; + + token = (*lst)->content; + node = (*ast)->item; + temp = (ft_lstlast(node->data.cmd.redir))->content; + temp->type = token->type; + if (token->type == TK_DLESS) + { + temp_heredoc = data_singleton()->heredoc_queue->content; + temp_heredoc->n = temp->n; + } + return (0); +} + int add_redir_type(t_btree **ast, t_list **lst) { t_astnode *node; t_token *token; t_redir redir; - t_redir *temp; - t_redir *temp_heredoc; if (!*ast) gen_node(ast); token = (*lst)->content; node = (*ast)->item; - DG("node type is :%s", read_state(node->type)); if (!(node->type == TK_IO_NUMBER)) { redir.n = (token->type == TK_LESS || token->type == TK_DLESS || token->type == TK_LESSAND) ? STDIN : STDOUT; - redir.type = token->type; + redir.type = token->type; redir.heredoc_data = NULL; redir.word = NULL; ft_lsteadd(&node->data.cmd.redir, ft_lstnew(&redir, sizeof(redir))); if (token->type == TK_DLESS) - ft_lsteadd(&data_singleton()->heredoc_queue, ft_lstnew(&redir, sizeof(redir))); + ft_lsteadd(&data_singleton()->heredoc_queue, + ft_lstnew(&redir, sizeof(redir))); } else - { - temp = (ft_lstlast(node->data.cmd.redir))->content; - temp->type = token->type; - if (token->type == TK_DLESS) - { - temp_heredoc = data_singleton()->heredoc_queue->content; - temp_heredoc->n = temp->n; - } - } + add_redir_type_number(ast, lst); node->cache = node->type; node->type = REDIR; return (0); diff --git a/42sh/src/parser/add_redir_condition.c b/42sh/src/parser/add_redir_condition.c index f5782a34..bf1a1ed4 100644 --- a/42sh/src/parser/add_redir_condition.c +++ b/42sh/src/parser/add_redir_condition.c @@ -6,13 +6,13 @@ /* By: ariard +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/11 14:54:18 by ariard #+# #+# */ -/* Updated: 2017/03/11 15:17:58 by ariard ### ########.fr */ +/* Updated: 2017/03/11 15:54:52 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ -#include "minishell.h" +#include "minishell.h" -static int isdir_sep_condition(t_btree **ast, t_list **lst) +static int isdir_sep_condition(t_btree **ast, t_list **lst) { t_token *token; t_astnode *node; @@ -23,11 +23,11 @@ static int isdir_sep_condition(t_btree **ast, t_list **lst) node = (*ast)->item; if (node->type == TK_IF || node->type == TK_CASE) return (1); - } + } return (0); } -static int isdir_word_condition(t_btree **ast, t_list **lst) +static int isdir_word_condition(t_btree **ast, t_list **lst) { t_token *token; t_astnode *node; @@ -38,7 +38,7 @@ static int isdir_word_condition(t_btree **ast, t_list **lst) node = (*ast)->item; if (node->type == REDIR) return (1); - } + } return (0); } @@ -56,12 +56,12 @@ int isdir_condition(t_btree **ast, t_list **lst) || token->type == TK_DLESS || token->type == TK_DGREAT) && isdir_sep_condition(&(*ast)->left, lst) == 1) return (1); - if (token->type == TK_WORD + if (token->type == TK_WORD && isdir_word_condition(&(*ast)->left, lst) == 1) return (1); } return (0); -} +} int add_redir_condition(t_btree **ast, t_list **lst) { diff --git a/42sh/src/parser/add_sep.c b/42sh/src/parser/add_sep.c index b791581b..fd15b298 100644 --- a/42sh/src/parser/add_sep.c +++ b/42sh/src/parser/add_sep.c @@ -6,18 +6,18 @@ /* By: ariard +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/02/15 19:12:07 by ariard #+# #+# */ -/* Updated: 2017/03/10 18:10:55 by ariard ### ########.fr */ +/* Updated: 2017/03/11 15:55:45 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ #include "minishell.h" int add_sep(t_btree **ast, t_list **lst) -{ +{ t_token *token; t_astnode *node; t_btree *new_node; - + if (isloop(ast, lst)) return (add_loop_sep(ast, lst)); else if (iscondition(ast, lst)) @@ -32,12 +32,11 @@ int add_sep(t_btree **ast, t_list **lst) return (add_bang_sep(ast, lst)); if (!*ast) gen_node(ast); - DG(" flag"); token = (*lst)->content; new_node = NULL; gen_node(&new_node); join_ast(ast, &new_node); node = (new_node)->item; - node->type = token->type; + node->type = token->type; return (0); } diff --git a/42sh/src/parser/add_subshell.c b/42sh/src/parser/add_subshell.c index dcbe85f4..1866f3e2 100644 --- a/42sh/src/parser/add_subshell.c +++ b/42sh/src/parser/add_subshell.c @@ -6,7 +6,7 @@ /* By: ariard +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/02/24 18:41:50 by ariard #+# #+# */ -/* Updated: 2017/03/09 19:46:44 by ariard ### ########.fr */ +/* Updated: 2017/03/11 15:56:12 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ @@ -34,7 +34,6 @@ int add_subshell_cmd(t_btree **ast, t_list **lst) t_token *token; t_astnode *node; - DG("add subshell"); token = (*lst)->content; node = (*ast)->item; if (token->type == TK_PAREN_CLOSE && node->type == SUBSHELL) diff --git a/42sh/src/parser/add_var.c b/42sh/src/parser/add_var.c index fe17bb85..82359c89 100644 --- a/42sh/src/parser/add_var.c +++ b/42sh/src/parser/add_var.c @@ -6,7 +6,7 @@ /* By: ariard +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/03 15:08:16 by ariard #+# #+# */ -/* Updated: 2017/03/07 22:47:38 by ariard ### ########.fr */ +/* Updated: 2017/03/11 15:56:38 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ @@ -22,7 +22,8 @@ int isvar(t_btree **ast, t_list **lst) if (*ast) { node = (*ast)->item; - if (node->type != TK_ASSIGNEMENT_WORD && token->type == TK_ASSIGNEMENT_WORD) + if (node->type != TK_ASSIGNEMENT_WORD + && token->type == TK_ASSIGNEMENT_WORD) return (1); } return (0); diff --git a/42sh/src/parser/aggregate_sym.c b/42sh/src/parser/aggregate_sym.c index 90a1236b..596eb9fa 100644 --- a/42sh/src/parser/aggregate_sym.c +++ b/42sh/src/parser/aggregate_sym.c @@ -1,11 +1,12 @@ /* ************************************************************************** */ +/* */ /* ::: :::::::: */ /* aggregate_sym.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: ariard +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ -/* Created: 2017/02/09 17:39:18 by ariard #+# #+# */ -/* Updated: 2017/03/04 16:16:23 by ariard ### ########.fr */ +/* Created: 2017/03/11 15:58:38 by ariard #+# #+# */ +/* Updated: 2017/03/11 16:05:58 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ @@ -13,7 +14,6 @@ /* * In case of grammar error, manange it - * */ t_aggrematch g_aggrematch[] = @@ -23,15 +23,15 @@ t_aggrematch g_aggrematch[] = {TK_WORD, TK_IN, FOR_WORDLIST, TK_IN}, {TK_WORD, FOR_WORDLIST, FOR_WORDLIST, FOR_WORDLIST}, {TK_WORD, MATH, MATH, MATH}, - {TK_SEMI, FOR_WORDLIST, SEQUENTIAL_SEP, 0}, + {TK_SEMI, FOR_WORDLIST, SEQUENTIAL_SEP, 0}, {TK_DSEMI, CMD_SUPERIOR, PIPE_SEQUENCE, CMD_SUPERIOR}, {TK_DSEMI, PIPE_SEMI_SEQUENCE, PIPE_SEQUENCE, PIPE_SEMI_SEQUENCE}, {TK_DSEMI, PIPE_CLOSE_SEQUENCE, PIPE_SEQUENCE, PIPE_CLOSE_SEQUENCE}, {TK_PAREN_OPEN, TK_IN, PATTERN_CASE, 0}, - {TK_PAREN_OPEN, CASE_LIST_NS, PATTERN_CASE, 0}, + {TK_PAREN_OPEN, CASE_LIST_NS, PATTERN_CASE, 0}, {TK_PAREN_OPEN, TK_PAREN_OPEN, MATH, TK_PAREN_OPEN}, {TK_PAREN_OPEN, CMD_SUPERIOR, OPEN_FUNC, 0}, - {TK_ASSIGNEMENT_WORD, CMD_PREFIX,CMD_PREFIX, 0}, + {TK_ASSIGNEMENT_WORD, CMD_PREFIX, CMD_PREFIX, 0}, {TK_PIPE, CMD_SUPERIOR, SEQUENCE, CMD_SUPERIOR}, {TK_PIPE, PIPE_SEMI_SEQUENCE, SEQUENCE, PIPE_SEMI_SEQUENCE}, {TK_PIPE, PIPE_CLOSE_SEQUENCE, SEQUENCE, PIPE_CLOSE_SEQUENCE}, @@ -39,11 +39,10 @@ t_aggrematch g_aggrematch[] = {TK_FI, COMPOUND_LIST, IF_CLAUSE, COMPLETE_CONDITION}, {TK_FI, COMPLETE_CONDITION, IF_CLAUSE, COMPLETE_CONDITION}, {TK_FI, CONDITION, IF_CLAUSE, COMPLETE_CONDITION}, - {TK_THEN, CONDITION, COMPLETE_CONDITION, CONDITION}, + {TK_THEN, CONDITION, COMPLETE_CONDITION, CONDITION}, {TK_DONE, CMD_SUPERIOR, DO_GROUP, TK_DO}, {TK_DONE, COMPOUND_LIST, DO_GROUP, TK_DO}, -//Esac ? - {TK_ESAC, TK_IN, CASE_CLAUSE, TK_CASE}, + {TK_ESAC, TK_IN, CASE_CLAUSE, TK_CASE}, {TK_ESAC, CASE_LIST_NS, CASE_CLAUSE, TK_CASE}, {TK_RBRACE, COMPOUND_LIST, BRACE_GROUP, TK_LBRACE}, {TK_PAREN_CLOSE, MATH, MATH_PLUS, MATH}, @@ -59,13 +58,12 @@ t_aggrematch g_aggrematch[] = {TK_RBRACE, PIPE_SEMI_SEQUENCE, BRACE_CLAUSE, TK_LBRACE}, {TK_RBRACE, PIPE_CLOSE_SEQUENCE, BRACE_CLAUSE, TK_LBRACE}, - {TK_RBRACE, COMPOUND_LIST, BRACE_CLAUSE, TK_LBRACE}, + {TK_RBRACE, COMPOUND_LIST, BRACE_CLAUSE, TK_LBRACE}, {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}, {SEPARATOR_OP, COMPOUND_LIST, SEPARATOR, 0}, @@ -74,17 +72,15 @@ t_aggrematch g_aggrematch[] = {SEPARATOR_OP, PIPE_CLOSE_SEQUENCE, SEPARATOR, 0}, {SEPARATOR, MATH_SUP, CMD_SUPERIOR, MATH_SUP}, {SEPARATOR, CMD_SUPERIOR, END_COMMAND, CMD_SUPERIOR}, - {SEPARATOR, CASE_LIST_NS, CASE_LIST_NS, CASE_LIST_NS}, + {SEPARATOR, CASE_LIST_NS, CASE_LIST_NS, CASE_LIST_NS}, {SEPARATOR, COMPOUND_LIST, COMPOUND_LIST, COMPOUND_LIST}, {SEPARATOR, PIPE_SEMI_SEQUENCE, PIPE_SEQUENCE, PIPE_SEMI_SEQUENCE}, {SEPARATOR, PIPE_CLOSE_SEQUENCE, PIPE_SEQUENCE, PIPE_CLOSE_SEQUENCE}, {LINEBREAK, MATH_SUP, CMD_SUPERIOR, MATH_SUP}, {LINEBREAK, SEPARATOR_OP, SEPARATOR, SEPARATOR_OP}, {LINEBREAK, TK_SEMI, SEQUENTIAL_SEP, TK_SEMI}, - -//to abstract TK_ESAC {LINEBREAK, TK_PAREN_CLOSE, FUNC, FNAME}, - {LINEBREAK, COMPLETE_COMMANDS, PROGRAM, LINEBREAK}, + {LINEBREAK, COMPLETE_COMMANDS, PROGRAM, LINEBREAK}, {LINEBREAK, CMD_SUPERIOR, SEPARATOR_OP, 0}, {LINEBREAK, PIPE_SEMI_SEQUENCE, PIPE_SEQUENCE, PIPE_SEMI_SEQUENCE}, {LINEBREAK, PIPE_CLOSE_SEQUENCE, PIPE_SEQUENCE, PIPE_CLOSE_SEQUENCE}, @@ -92,7 +88,7 @@ t_aggrematch g_aggrematch[] = {LINEBREAK, CASE_LIST_NS, CASE_LIST_NS, CASE_LIST_NS}, {NEWLINE_LIST, MATH_SUP, CMD_SUPERIOR, MATH_SUP}, {NEWLINE_LIST, CMD_NAME, CMD_SUPERIOR, CMD_NAME}, - {NEWLINE_LIST, SEQUENTIAL_SEP, SEQUENTIAL_SEP, SEQUENTIAL_SEP}, + {NEWLINE_LIST, SEQUENTIAL_SEP, SEQUENTIAL_SEP, SEQUENTIAL_SEP}, {NEWLINE_LIST, TK_DO, TK_DO, TK_DO}, {NEWLINE_LIST, TK_PAREN_CLOSE, TK_PAREN_CLOSE, TK_PAREN_CLOSE}, {NEWLINE_LIST, TK_PAREN_OPEN, TK_PAREN_OPEN, TK_PAREN_OPEN}, @@ -120,7 +116,6 @@ t_aggrematch g_aggrematch[] = {NEWLINE_LIST, FOR_WORDLIST, SEQUENTIAL_SEP, 0}, {NEWLINE_LIST, PROGRAM, PROGRAM, PROGRAM}, {SEQUENTIAL_SEP, FOR_WORDLIST, SEQUENTIAL_SEP, FOR_WORDLIST}, -//to check {FILENAME, TK_LESS, IO_FILE, TK_LESS}, {FILENAME, TK_LESSAND, IO_FILE, TK_LESSAND}, {FILENAME, TK_GREAT, IO_FILE, TK_GREAT}, @@ -128,16 +123,15 @@ t_aggrematch g_aggrematch[] = {FILENAME, TK_DGREAT, IO_FILE, TK_DGREAT}, {FILENAME, TK_LESSGREAT, IO_FILE, TK_LESSGREAT}, {FILENAME, TK_CLOBBER, IO_FILE, TK_CLOBBER}, - {HERE_END, TK_DLESS, IO_HERE, TK_DLESS}, -//to check {IO_FILE, TK_IO_NUMBER, IO_REDIRECT, TK_IO_NUMBER}, {IO_FILE, ALL, IO_REDIRECT, 0}, {IO_HERE, TK_IO_NUMBER, IO_REDIRECT, TK_IO_NUMBER}, - {IO_HERE, ALL, IO_REDIRECT, 0}, + {IO_HERE, ALL, IO_REDIRECT, 0}, {IO_REDIRECT, CMD_SUPERIOR, CMD_SUPERIOR, CMD_SUPERIOR}, {IO_REDIRECT, PIPE_SEMI_SEQUENCE, PIPE_SEMI_SEQUENCE, PIPE_SEMI_SEQUENCE}, - {IO_REDIRECT, PIPE_CLOSE_SEQUENCE, PIPE_CLOSE_SEQUENCE, PIPE_CLOSE_SEQUENCE}, + {IO_REDIRECT, PIPE_CLOSE_SEQUENCE, PIPE_CLOSE_SEQUENCE, + PIPE_CLOSE_SEQUENCE}, {IO_REDIRECT, COMPOUND_COMMAND, REDIRECT_LIST, REDIRECT_LIST}, {IO_REDIRECT, CMD_SUFFIX, CMD_SUFFIX, CMD_SUFFIX}, {IO_REDIRECT, CMD_NAME, CMD_SUFFIX, 0}, @@ -158,14 +152,12 @@ t_aggrematch g_aggrematch[] = {IO_REDIRECT, TK_ELIF, CMD_PREFIX, 0}, {IO_REDIRECT, TK_ELSE, CMD_PREFIX, 0}, {IO_REDIRECT, TK_PAREN_CLOSE, CMD_PREFIX, 0}, - {REDIRECT_LIST, COMPOUND_COMMAND, COMPOUND_COMMAND, COMPOUND_COMMAND}, {CMD_SUFFIX, CMD_WORD, SIMPLE_COMMAND, CMD_PREFIX}, {CMD_SUFFIX, CMD_NAME, SIMPLE_COMMAND, CMD_NAME}, {CMD_SUFFIX, CMD_SUPERIOR, CMD_SUPERIOR, CMD_SUPERIOR}, {CMD_SUFFIX, PIPE_SEMI_SEQUENCE, PIPE_SEMI_SEQUENCE, PIPE_SEMI_SEQUENCE}, {CMD_SUFFIX, PIPE_CLOSE_SEQUENCE, PIPE_CLOSE_SEQUENCE, PIPE_CLOSE_SEQUENCE}, -//to abstract {CMD_PREFIX, LINEBREAK, SIMPLE_COMMAND, 0}, {CMD_PREFIX, TK_PAREN_OPEN, SIMPLE_COMMAND, 0}, {CMD_PREFIX, TK_LBRACE, SIMPLE_COMMAND, 0}, @@ -174,7 +166,7 @@ t_aggrematch g_aggrematch[] = {CMD_PREFIX, SEPARATOR_OP, SIMPLE_COMMAND, 0}, {CMD_PREFIX, NEWLINE_LIST, SIMPLE_COMMAND, 0}, {CMD_PREFIX, TK_WHILE, SIMPLE_COMMAND, 0}, - {CMD_PREFIX, TK_UNTIL,SIMPLE_COMMAND, 0}, + {CMD_PREFIX, TK_UNTIL, SIMPLE_COMMAND, 0}, {CMD_PREFIX, TK_DO, SIMPLE_COMMAND, 0}, {CMD_PREFIX, TK_THEN, SIMPLE_COMMAND, TK_BANG}, {CMD_PREFIX, TK_IF, SIMPLE_COMMAND, 0}, @@ -186,9 +178,7 @@ t_aggrematch g_aggrematch[] = {CMD_PREFIX, TK_PIPE, SIMPLE_COMMAND, 0}, {CMD_PREFIX, SEQUENCE, SIMPLE_COMMAND, 0}, {CMD_PREFIX, COMPOUND_LIST, SIMPLE_COMMAND, 0}, - {CMD_WORD, CMD_PREFIX, SIMPLE_COMMAND, CMD_PREFIX}, -//to check {CMD_NAME, LINEBREAK, CMD_SUPERIOR, 0}, {CMD_NAME, TK_PAREN_OPEN, CMD_SUPERIOR, 0}, {CMD_NAME, TK_LBRACE, CMD_SUPERIOR, 0}, @@ -251,9 +241,8 @@ t_aggrematch g_aggrematch[] = {AND_OR_MINOR, AND_OR_MAJOR, 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}, - {COMMAND, CASE_LIST_NS, PIPE_SEMI_SEQUENCE, 0}, + {COMMAND, CASE_LIST_NS, PIPE_SEMI_SEQUENCE, 0}, {COMMAND, TK_WHILE, PIPE_SEMI_SEQUENCE, 0}, {COMMAND, TK_UNTIL, PIPE_SEMI_SEQUENCE, 0}, {COMMAND, TK_DO, PIPE_SEMI_SEQUENCE, 0}, @@ -275,7 +264,7 @@ t_aggrematch g_aggrematch[] = {COMMAND, CONDITION, PIPE_SEMI_SEQUENCE, 0}, {COMPOUND_COMMAND, SEQUENCE, PIPE_CLOSE_SEQUENCE, 0}, {COMPOUND_COMMAND, COMPOUND_LIST, PIPE_CLOSE_SEQUENCE, 0}, - {COMPOUND_COMMAND, CASE_LIST_NS, PIPE_CLOSE_SEQUENCE, 0}, + {COMPOUND_COMMAND, CASE_LIST_NS, PIPE_CLOSE_SEQUENCE, 0}, {COMPOUND_COMMAND, TK_WHILE, PIPE_CLOSE_SEQUENCE, 0}, {COMPOUND_COMMAND, TK_UNTIL, PIPE_CLOSE_SEQUENCE, 0}, {COMPOUND_COMMAND, TK_DO, PIPE_CLOSE_SEQUENCE, 0}, @@ -354,7 +343,6 @@ t_aggrematch g_aggrematch[] = {PIPELINE, TK_PAREN_OPEN, AND_OR, 0}, {PIPELINE, TK_LBRACE, AND_OR, 0}, {PIPELINE, COMPLETE_COMMANDS, AND_OR, 0}, -// {PIPELINE, LINEBREAK, AND_OR, AND_OR}, {PIPELINE, SEPARATOR_OP, AND_OR, 0}, {PIPELINE, COMPLETE_CONDITION, AND_OR, 0}, {PIPELINE, CONDITION, AND_OR, 0}, @@ -383,17 +371,18 @@ t_aggrematch g_aggrematch[] = {LIST, NEWLINE_LIST, COMPLETE_COMMAND, 0}, {LIST, LINEBREAK, COMPLETE_COMMAND, 0}, {LIST, COMPLETE_COMMANDS, COMPLETE_COMMAND, 0}, - {COMPLETE_COMMAND, NEWLINE_LIST, COMPLETE_COMMANDS, COMPLETE_COMMANDS}, + {COMPLETE_COMMAND, NEWLINE_LIST, COMPLETE_COMMANDS, COMPLETE_COMMANDS}, {COMPLETE_COMMAND, LINEBREAK, COMPLETE_COMMANDS, 0}, {COMPLETE_COMMAND, COMPLETE_COMMANDS, COMPLETE_COMMANDS, 0}, - {COMPLETE_COMMANDS, COMPLETE_COMMANDS, COMPLETE_COMMANDS, COMPLETE_COMMANDS}, + {COMPLETE_COMMANDS, COMPLETE_COMMANDS, COMPLETE_COMMANDS, + COMPLETE_COMMANDS}, {0, 0, 0, 0}, }; int aggregate_sym(t_list **stack, t_sym *new_sym, t_parstate *state) { t_sym *head; - int i; + int i; if (!*stack || !*new_sym || !*state) return (1); @@ -405,7 +394,6 @@ int aggregate_sym(t_list **stack, t_sym *new_sym, t_parstate *state) { if (*new_sym == g_aggrematch[i].top && MATCH_STACK(*head, g_aggrematch[i].under)) - { // DG("MATCH : %s", read_state(g_aggrematch[i].new_sym)); *new_sym = g_aggrematch[i].new_sym; diff --git a/42sh/src/parser/build_tree.c b/42sh/src/parser/build_tree.c index fd817a57..747a3e35 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/10 15:34:58 by ariard ### ########.fr */ +/* Updated: 2017/03/11 16:08:26 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ @@ -60,19 +60,17 @@ static int isseparator(t_token *token, int cache) || cache == TK_NEWLINE || cache == TK_THEN || cache == TK_IN || cache == TK_DSEMI)) return (0); -//check cache == WORD return (1); } int build_tree(t_btree **ast, t_list **lst) { - int i; - static int cache; - t_token *token; + int i; + static int cache; + t_token *token; i = 0; token = (*lst)->content; -//check bug de cache case ? if (token->type == TK_PAREN_OPEN && cache != TK_IN && cache != TK_DSEMI && cache != TK_WORD) token->type = SUBSHELL; @@ -80,9 +78,6 @@ int build_tree(t_btree **ast, t_list **lst) { if ((isseparator(token, cache) && g_treematch[i].type == token->type)) { - - DG("func TK : '%s' TK : '%s'", - read_state(g_treematch[i].type) ,read_state(token->type)); cache = token->type; return (g_treematch[i].add(ast, lst)); } diff --git a/42sh/src/parser/error_syntax.c b/42sh/src/parser/error_syntax.c index b9d36a7f..6165e443 100644 --- a/42sh/src/parser/error_syntax.c +++ b/42sh/src/parser/error_syntax.c @@ -6,13 +6,13 @@ /* By: ariard +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/02/09 20:15:35 by ariard #+# #+# */ -/* Updated: 2017/03/09 16:37:14 by ariard ### ########.fr */ +/* Updated: 2017/03/11 16:10:56 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ #include "minishell.h" -t_errormatch g_errormatch[] = +t_errormatch g_errormatch[] = { {TK_NEWLINE, "newline"}, {TK_SEMI, ";"}, @@ -54,7 +54,7 @@ t_errormatch g_errormatch[] = int error_syntax(t_list **lst, t_parser *parser, t_btree **ast) -{ +{ t_token *token; int i; @@ -68,9 +68,9 @@ int error_syntax(t_list **lst, t_parser *parser, { ft_putstr_fd("syntax error near unexpected token `", 2); ft_putstr_fd(g_errormatch[i].error, 2); - ft_putstr_fd("'\n", 2); + ft_putstr_fd("'\n", 2); instruction_free(lst, parser, ast); - return (0); + return (0); } i++; } @@ -81,9 +81,9 @@ int error_syntax(t_list **lst, t_parser *parser, return (0); } -int error_EOF(t_list **lst, t_parser *parser, t_btree **ast) +int error_eof(t_list **lst, t_parser *parser, t_btree **ast) { ft_putstr_fd("syntax error near unexpected EOF", 2); - instruction_free(lst, parser, ast); + instruction_free(lst, parser, ast); return (0); } diff --git a/42sh/src/parser/eval_sym.c b/42sh/src/parser/eval_sym.c index 746b611b..8159698a 100644 --- a/42sh/src/parser/eval_sym.c +++ b/42sh/src/parser/eval_sym.c @@ -5,12 +5,13 @@ /* +:+ +:+ +:+ */ /* By: ariard +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ -/* Created: 2017/02/09 16:26:30 by ariard #+# #+# */ +/* Created: 2017/03/11 16:11:21 by ariard #+# #+# */ +/* Updated: 2017/03/11 16:17:10 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ #include "minishell.h" - + t_stackmatch g_stackmatch[] = { {TK_WORD, CMD_SUFFIX}, @@ -70,7 +71,6 @@ t_stackmatch g_stackmatch[] = {TK_DSEMI, PIPE_SEMI_SEQUENCE}, {TK_DSEMI, PIPE_CLOSE_SEQUENCE}, {TK_DSEMI, SEQUENCE}, -// watch! {TK_LESS, TK_IO_NUMBER}, {TK_LESS, REDIRECT_LIST}, {TK_LESS, CMD_SUFFIX}, @@ -99,7 +99,6 @@ t_stackmatch g_stackmatch[] = {TK_LESS, COMPLETE_CONDITION}, {TK_LESS, CONDITION}, {TK_LESS, COMPOUND_LIST}, -// watch ! {TK_LESS, CMD_SUPERIOR}, {TK_LESS, AND_OR_MAJOR}, {TK_GREAT, TK_IO_NUMBER}, @@ -130,11 +129,8 @@ t_stackmatch g_stackmatch[] = {TK_GREAT, COMPLETE_CONDITION}, {TK_GREAT, CONDITION}, {TK_GREAT, COMPOUND_LIST}, -// watch ! -//duplicate and extend {TK_GREAT, CMD_SUPERIOR}, {TK_GREAT, AND_OR_MAJOR}, - {TK_DLESS, TK_IO_NUMBER}, {TK_DLESS, REDIRECT_LIST}, {TK_DLESS, CMD_SUFFIX}, @@ -163,10 +159,8 @@ t_stackmatch g_stackmatch[] = {TK_DLESS, COMPLETE_CONDITION}, {TK_DLESS, CONDITION}, {TK_DLESS, COMPOUND_LIST}, -// watch ! {TK_DLESS, CMD_SUPERIOR}, {TK_DLESS, AND_OR_MAJOR}, - {TK_DGREAT, TK_IO_NUMBER}, {TK_DGREAT, REDIRECT_LIST}, {TK_DGREAT, CMD_SUFFIX}, @@ -195,10 +189,8 @@ t_stackmatch g_stackmatch[] = {TK_DGREAT, COMPLETE_CONDITION}, {TK_DGREAT, CONDITION}, {TK_DGREAT, COMPOUND_LIST}, -// watch ! {TK_DGREAT, CMD_SUPERIOR}, {TK_DGREAT, AND_OR_MAJOR}, - {TK_LESSAND, TK_IO_NUMBER}, {TK_LESSAND, REDIRECT_LIST}, {TK_LESSAND, CMD_SUFFIX}, @@ -227,10 +219,8 @@ t_stackmatch g_stackmatch[] = {TK_LESSAND, COMPLETE_CONDITION}, {TK_LESSAND, CONDITION}, {TK_LESSAND, COMPOUND_LIST}, -// watch ! {TK_LESSAND, CMD_SUPERIOR}, {TK_LESSAND, AND_OR_MAJOR}, - {TK_GREATAND, TK_IO_NUMBER}, {TK_GREATAND, REDIRECT_LIST}, {TK_GREATAND, CMD_SUFFIX}, @@ -259,11 +249,8 @@ t_stackmatch g_stackmatch[] = {TK_GREATAND, COMPLETE_CONDITION}, {TK_GREATAND, CONDITION}, {TK_GREATAND, COMPOUND_LIST}, -// watch ! {TK_GREATAND, CMD_SUPERIOR}, {TK_GREATAND, AND_OR_MAJOR}, - - {TK_IF, LINEBREAK}, {TK_IF, TK_BANG}, {TK_IF, TK_PAREN_OPEN}, @@ -272,7 +259,6 @@ t_stackmatch g_stackmatch[] = {TK_IF, SEPARATOR_OP}, {TK_IF, NEWLINE_LIST}, {TK_IF, SEQUENCE}, -// watch ! {TK_IF, TK_WHILE}, {TK_IF, FUNC_NAME}, {TK_IF, TK_UNTIL}, @@ -328,7 +314,6 @@ t_stackmatch g_stackmatch[] = {TK_CASE, NEWLINE_LIST}, {TK_CASE, SEPARATOR_OP}, {TK_CASE, SEQUENCE}, -// watch ! {TK_IN, TK_WORD}, {TK_IN, NAME}, {TK_ESAC, CASE_LIST_NS}, @@ -342,7 +327,6 @@ t_stackmatch g_stackmatch[] = {TK_WHILE, SEPARATOR_OP}, {TK_WHILE, NEWLINE_LIST}, {TK_WHILE, SEQUENCE}, -// watch ! {TK_WHILE, TK_DO}, {TK_WHILE, TK_PAREN_CLOSE}, {TK_WHILE, TK_WHILE}, @@ -364,7 +348,6 @@ t_stackmatch g_stackmatch[] = {TK_UNTIL, SEPARATOR_OP}, {TK_UNTIL, NEWLINE_LIST}, {TK_UNTIL, SEQUENCE}, -// watch ! {TK_UNTIL, TK_DO}, {TK_UNTIL, TK_PAREN_CLOSE}, {TK_UNTIL, TK_WHILE}, @@ -386,7 +369,6 @@ t_stackmatch g_stackmatch[] = {TK_FOR, SEPARATOR_OP}, {TK_FOR, NEWLINE_LIST}, {TK_FOR, SEQUENCE}, -// watch ! {TK_FOR, TK_DO}, {TK_FOR, TK_PAREN_CLOSE}, {TK_FOR, TK_WHILE}, @@ -407,7 +389,6 @@ t_stackmatch g_stackmatch[] = {TK_LBRACE, SEPARATOR_OP}, {TK_LBRACE, NEWLINE_LIST}, {TK_LBRACE, SEQUENCE}, -// watch ! {TK_LBRACE, AND_OR_MAJOR}, {TK_LBRACE, TK_WHILE}, {TK_LBRACE, FUNC_NAME}, @@ -476,7 +457,6 @@ t_stackmatch g_stackmatch[] = {TK_PAREN_OPEN, NEWLINE_LIST}, {TK_PAREN_OPEN, SEQUENCE}, {TK_PAREN_OPEN, FUNC_NAME}, -// watch ! {TK_PAREN_OPEN, AND_OR_MAJOR}, {TK_PAREN_OPEN, TK_WHILE}, {TK_PAREN_OPEN, TK_LBRACE}, @@ -663,7 +643,6 @@ t_stackmatch g_stackmatch[] = {IO_HERE, COMPLETE_CONDITION}, {IO_HERE, CONDITION}, {IO_HERE, COMPOUND_LIST}, -// watch ! {FILENAME, TK_LESS}, {FILENAME, TK_LESSAND}, {FILENAME, TK_GREAT}, @@ -698,7 +677,6 @@ t_stackmatch g_stackmatch[] = {IO_FILE, COMPLETE_CONDITION}, {IO_FILE, CONDITION}, {IO_FILE, COMPOUND_LIST}, -// watch ! {IO_REDIRECT, REDIRECT_LIST}, {IO_REDIRECT, CMD_SUPERIOR}, {IO_REDIRECT, CMD_SUFFIX}, @@ -727,7 +705,6 @@ t_stackmatch g_stackmatch[] = {IO_REDIRECT, COMPLETE_CONDITION}, {IO_REDIRECT, CONDITION}, {IO_REDIRECT, COMPOUND_LIST}, -// watch !/ {REDIRECT_LIST, COMPOUND_COMMAND}, {CMD_SUFFIX, CMD_WORD}, {CMD_SUFFIX, CMD_NAME}, @@ -754,7 +731,6 @@ t_stackmatch g_stackmatch[] = {CMD_PREFIX, COMPLETE_CONDITION}, {CMD_PREFIX, CONDITION}, {CMD_PREFIX, COMPOUND_LIST}, -// watch ! {CMD_WORD, CMD_PREFIX}, {CMD_NAME, COMPLETE_COMMANDS}, {CMD_NAME, LINEBREAK}, @@ -768,7 +744,6 @@ t_stackmatch g_stackmatch[] = {CMD_NAME, AND_OR_MAJOR}, {CMD_NAME, CONDITION}, {CMD_NAME, COMPOUND_LIST}, -// watch ! {CMD_NAME, AND_OR_MAJOR}, {CMD_NAME, TK_WHILE}, {CMD_NAME, FUNC_NAME}, @@ -783,7 +758,6 @@ t_stackmatch g_stackmatch[] = {CMD_NAME, CASE_LIST_NS}, {CMD_NAME, COMPLETE_CONDITION}, {CMD_NAME, CONDITION}, - {CMD_SUPERIOR, TK_WHILE}, {CMD_SUPERIOR, FUNC_NAME}, {CMD_SUPERIOR, TK_UNTIL}, @@ -806,9 +780,7 @@ t_stackmatch g_stackmatch[] = {CMD_SUPERIOR, NEWLINE_LIST}, {CMD_SUPERIOR, TK_PIPE}, {CMD_SUPERIOR, SEQUENCE}, -// watch ! {CMD_SUPERIOR, AND_OR_MAJOR}, - {CLOSE_FUNC, CMD_SUPERIOR}, {CLOSE_FUNC, OPEN_FUNC}, {MATH, LINEBREAK}, @@ -823,7 +795,6 @@ t_stackmatch g_stackmatch[] = {MATH_SUP, NEWLINE_LIST}, {MATH_SUP, SEPARATOR}, {MATH_SUP, SEPARATOR_OP}, - {SIMPLE_COMMAND, TK_WHILE}, {SIMPLE_COMMAND, TK_UNTIL}, {SIMPLE_COMMAND, TK_DO}, @@ -844,7 +815,6 @@ t_stackmatch g_stackmatch[] = {SIMPLE_COMMAND, SEPARATOR_OP}, {SIMPLE_COMMAND, NEWLINE_LIST}, {SIMPLE_COMMAND, SEQUENCE}, -// watch ! {SIMPLE_COMMAND, AND_OR_MAJOR}, {DO_GROUP, CMD_SUPERIOR}, {DO_GROUP, COMPOUND_LIST}, @@ -874,7 +844,6 @@ t_stackmatch g_stackmatch[] = {BRACE_GROUP, SEPARATOR_OP}, {BRACE_GROUP, NEWLINE_LIST}, {BRACE_GROUP, SEQUENCE}, -// watch ! {FNAME, LINEBREAK}, {FNAME, TK_PAREN_OPEN}, {FNAME, TK_LBRACE}, @@ -883,7 +852,6 @@ t_stackmatch g_stackmatch[] = {FNAME, SEPARATOR_OP}, {FNAME, NEWLINE_LIST}, {FNAME, SEQUENCE}, -// watch ! {FUNCTION_BODY, FUNC}, {FUNCTION_DEFINITION, LINEBREAK}, {FUNCTION_DEFINITION, TK_PAREN_OPEN}, @@ -893,7 +861,6 @@ t_stackmatch g_stackmatch[] = {FUNCTION_DEFINITION, SEPARATOR_OP}, {FUNCTION_DEFINITION, NEWLINE_LIST}, {FUNCTION_DEFINITION, SEQUENCE}, -// watch ! {UNTIL_CLAUSE, LINEBREAK}, {UNTIL_CLAUSE, TK_PAREN_OPEN}, {UNTIL_CLAUSE, TK_LBRACE}, @@ -901,7 +868,7 @@ t_stackmatch g_stackmatch[] = {UNTIL_CLAUSE, TK_BANG}, {UNTIL_CLAUSE, SEPARATOR_OP}, {UNTIL_CLAUSE, NEWLINE_LIST}, - {UNTIL_CLAUSE, SEQUENCE}, + {UNTIL_CLAUSE, SEQUENCE}, {UNTIL_CLAUSE, TK_DO}, {UNTIL_CLAUSE, TK_PAREN_CLOSE}, {UNTIL_CLAUSE, TK_WHILE}, @@ -922,7 +889,6 @@ t_stackmatch g_stackmatch[] = {WHILE_CLAUSE, SEPARATOR_OP}, {WHILE_CLAUSE, NEWLINE_LIST}, {WHILE_CLAUSE, SEQUENCE}, -// watch ! {WHILE_CLAUSE, TK_DO}, {WHILE_CLAUSE, TK_PAREN_CLOSE}, {WHILE_CLAUSE, TK_WHILE}, @@ -946,7 +912,6 @@ t_stackmatch g_stackmatch[] = {IF_CLAUSE, SEPARATOR_OP}, {IF_CLAUSE, NEWLINE_LIST}, {IF_CLAUSE, SEQUENCE}, -// watch ! {IF_CLAUSE, TK_DO}, {IF_CLAUSE, TK_PAREN_CLOSE}, {IF_CLAUSE, TK_WHILE}, @@ -970,7 +935,6 @@ t_stackmatch g_stackmatch[] = {BRACE_CLAUSE, SEPARATOR_OP}, {BRACE_CLAUSE, NEWLINE_LIST}, {BRACE_CLAUSE, SEQUENCE}, -// watch ! {BRACE_CLAUSE, TK_DO}, {BRACE_CLAUSE, TK_PAREN_CLOSE}, {BRACE_CLAUSE, TK_WHILE}, @@ -999,7 +963,6 @@ t_stackmatch g_stackmatch[] = {CASE_CLAUSE, SEPARATOR_OP}, {CASE_CLAUSE, NEWLINE_LIST}, {CASE_CLAUSE, SEQUENCE}, -// watch ! {CASE_CLAUSE, TK_PAREN_CLOSE}, {CASE_CLAUSE, CASE_LIST_NS}, {CASE_CLAUSE, TK_DO}, @@ -1015,7 +978,6 @@ t_stackmatch g_stackmatch[] = {CASE_CLAUSE, COMPLETE_CONDITION}, {CASE_CLAUSE, CONDITION}, {CASE_CLAUSE, AND_OR_MAJOR}, - {WORDLIST, IN}, {IN, LINEBREAK}, {NAME, TK_FOR}, @@ -1028,7 +990,6 @@ t_stackmatch g_stackmatch[] = {FOR_CLAUSE, SEPARATOR_OP}, {FOR_CLAUSE, NEWLINE_LIST}, {FOR_CLAUSE, SEQUENCE}, -// watch ! {FOR_CLAUSE, TK_DO}, {FOR_CLAUSE, TK_PAREN_CLOSE}, {FOR_CLAUSE, TK_WHILE}, @@ -1066,7 +1027,6 @@ t_stackmatch g_stackmatch[] = {SUBSHELL, NEWLINE_LIST}, {SUBSHELL, SEQUENCE}, {SUBSHELL, TK_LBRACE}, -// watch ! {SUBSHELL, SEPARATOR_OP}, {SUBSHELL, NEWLINE_LIST}, {SUBSHELL, TK_DO}, @@ -1091,7 +1051,6 @@ t_stackmatch g_stackmatch[] = {COMPOUND_COMMAND, SEPARATOR_OP}, {COMPOUND_COMMAND, NEWLINE_LIST}, {COMPOUND_COMMAND, SEQUENCE}, -// watch ! {COMPOUND_COMMAND, FUNC}, {COMPOUND_COMMAND, TK_DO}, {COMPOUND_COMMAND, TK_PAREN_CLOSE}, @@ -1129,7 +1088,6 @@ t_stackmatch g_stackmatch[] = {COMMAND, SEQUENCE}, {COMMAND, AND_OR_MAJOR}, {AND_OR_MINOR, SEQUENCE}, -// watch ! {AND_OR_MINOR, LINEBREAK}, {AND_OR_MINOR, TK_BANG}, {AND_OR_MINOR, TK_PAREN_OPEN}, @@ -1302,8 +1260,8 @@ t_stackmatch g_stackmatch[] = int eval_sym(t_list **stack, t_sym new_sym) { - t_sym *head; - int i; + t_sym *head; + int i; if (!*stack) return (1); diff --git a/42sh/src/parser/ft_parse.c b/42sh/src/parser/ft_parse.c index bc53467d..c7c1b67c 100644 --- a/42sh/src/parser/ft_parse.c +++ b/42sh/src/parser/ft_parse.c @@ -5,7 +5,8 @@ /* +:+ +:+ +:+ */ /* By: ariard +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ -/* Created: 2016/11/30 17:14:58 by jhalford #+# #+# */ +/* Created: 2017/03/11 16:17:38 by ariard #+# #+# */ +/* Updated: 2017/03/11 16:18:35 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ @@ -14,7 +15,7 @@ static void insert_linebreak(t_list **lst) { t_token *token; - + token = (*lst)->content; token->type = LINEBREAK; } @@ -22,7 +23,7 @@ static void insert_linebreak(t_list **lst) static int end_instruction(t_list **stack) { t_sym *head; - + head = (*stack)->content; if (*head == CMD_SUPERIOR || *head == PIPE_SEMI_SEQUENCE || *head == COMPLETE_COMMANDS || *head == END_COMMAND) @@ -30,7 +31,7 @@ static int end_instruction(t_list **stack) return (0); } -int ft_parse(t_btree **ast, t_list **token, t_parser *parser) +int ft_parse(t_btree **ast, t_list **token, t_parser *parser) { t_sym *head; @@ -49,7 +50,6 @@ int ft_parse(t_btree **ast, t_list **token, t_parser *parser) push_stack(&parser->stack, *parser->new_sym); } // ft_read_stack(parser->stack); - DG("\n"); if (*(head = (parser->stack)->content) == PROGRAM) parser->state = SUCCESS; else diff --git a/42sh/src/parser/heredoc_parser.c b/42sh/src/parser/heredoc_parser.c index b8d77513..ae0ea276 100644 --- a/42sh/src/parser/heredoc_parser.c +++ b/42sh/src/parser/heredoc_parser.c @@ -6,7 +6,7 @@ /* By: ariard +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/08 16:21:05 by ariard #+# #+# */ -/* Updated: 2017/03/10 13:33:29 by jhalford ### ########.fr */ +/* Updated: 2017/03/11 16:20:21 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ @@ -25,10 +25,8 @@ int pop_heredoc(t_list **lst) { head = data_singleton()->heredoc_queue->content; temp = data_singleton()->heredoc_queue; - DG("compare %s with %s", (char *)token->data, head->word); if (head && token) { - DG(); if (ft_strcmp((char *)token->data, head->word) == 0) { temp2 = temp->next; @@ -36,10 +34,8 @@ int pop_heredoc(t_list **lst) data_singleton()->heredoc_queue = temp2; } else - { - DG("joining [%s] to heredoc", (char*)token->data); - head->heredoc_data = ft_strjoin(head->heredoc_data, token->data); - } + head->heredoc_data = ft_strjoin(head->heredoc_data, + token->data); } ft_lstdel(lst, &token_free); return (1); diff --git a/42sh/src/parser/parser_init.c b/42sh/src/parser/parser_init.c index 8592d5e6..8b8ca5c1 100644 --- a/42sh/src/parser/parser_init.c +++ b/42sh/src/parser/parser_init.c @@ -6,7 +6,7 @@ /* By: ariard +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/02/21 16:14:04 by ariard #+# #+# */ -/* Updated: 2017/03/09 16:49:14 by ariard ### ########.fr */ +/* Updated: 2017/03/11 16:20:31 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/parser/pop_stack.c b/42sh/src/parser/pop_stack.c index dca7b2f1..440692da 100644 --- a/42sh/src/parser/pop_stack.c +++ b/42sh/src/parser/pop_stack.c @@ -6,7 +6,7 @@ /* By: ariard +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/02/09 19:12:44 by ariard #+# #+# */ -/* Updated: 2017/03/07 15:09:32 by ariard ### ########.fr */ +/* Updated: 2017/03/11 16:21:01 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ @@ -20,9 +20,9 @@ int pop_stack(t_list **stack, t_sym erase_sym) while ((*stack) && (*(head = (*stack)->content) != erase_sym && *head != TERMINUS)) { - temp = *stack; + temp = *stack; (*stack) = (*stack)->next; - ft_lstdelone(&temp, NULL); + ft_lstdelone(&temp, NULL); } if ((*stack) && *(head = (*stack)->content) != TERMINUS) { @@ -33,4 +33,4 @@ int pop_stack(t_list **stack, t_sym erase_sym) else return (1); return (0); -} +} diff --git a/42sh/src/parser/produce_sym.c b/42sh/src/parser/produce_sym.c index 9f649ee4..61aa47f0 100644 --- a/42sh/src/parser/produce_sym.c +++ b/42sh/src/parser/produce_sym.c @@ -6,13 +6,13 @@ /* By: ariard +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/02/09 17:58:34 by ariard #+# #+# */ -/* Updated: 2017/03/10 18:46:59 by ariard ### ########.fr */ +/* Updated: 2017/03/11 16:22:18 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ #include "minishell.h" -t_prodmatch g_prodmatch[] = +t_prodmatch g_prodmatch[] = { {TK_WORD, TK_DLESS, HERE_END}, {TK_WORD, TK_DLESSDASH, HERE_END}, @@ -52,7 +52,7 @@ t_prodmatch g_prodmatch[] = {TK_WORD, TK_PAREN_OPEN, CMD_NAME}, {TK_WORD, TK_LBRACE, CMD_NAME}, {TK_WORD, CASE_LIST, PATTERN}, - {TK_WORD, PATTERN_CASE, PATTERN}, + {TK_WORD, PATTERN_CASE, PATTERN}, {TK_WORD, COMPLETE_COMMANDS, CMD_NAME}, {TK_ASSIGNEMENT_WORD, TK_BANG, CMD_PREFIX}, {TK_ASSIGNEMENT_WORD, LINEBREAK, CMD_PREFIX}, @@ -117,15 +117,14 @@ t_prodmatch g_prodmatch[] = {TK_AMP, LIST, SEPARATOR_OP}, {TK_AMP, PIPE_SEMI_SEQUENCE, SEPARATOR_OP}, {TK_AMP, PIPE_CLOSE_SEQUENCE, SEPARATOR_OP}, - {0, 0, 0}, }; -int produce_sym(t_list **stack, t_sym *new_sym, t_list **lst) +int produce_sym(t_list **stack, t_sym *new_sym, t_list **lst) { t_token *token; t_sym *head; - int i; + int i; if (!*stack || !*lst) return (1); diff --git a/42sh/src/parser/push_stack.c b/42sh/src/parser/push_stack.c index 1f2ba51e..c5d37e12 100644 --- a/42sh/src/parser/push_stack.c +++ b/42sh/src/parser/push_stack.c @@ -6,16 +6,14 @@ /* By: ariard +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/02/09 16:48:30 by ariard #+# #+# */ -/* Updated: 2017/03/03 14:28:09 by ariard ### ########.fr */ +/* Updated: 2017/03/11 16:22:32 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ #include "minishell.h" -//int push_stack(t_sym *stack, t_sym new_sym) int push_stack(t_list **stack, t_sym sym) { ft_lstadd(stack, ft_lstnew(&sym, sizeof(sym))); -// *stack = sym; return (0); } diff --git a/42sh/src/parser/tree_wrapper.c b/42sh/src/parser/tree_wrapper.c index a530614b..ecbf35fe 100644 --- a/42sh/src/parser/tree_wrapper.c +++ b/42sh/src/parser/tree_wrapper.c @@ -6,7 +6,7 @@ /* By: ariard +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/02/15 18:57:44 by ariard #+# #+# */ -/* Updated: 2017/03/10 17:49:28 by ariard ### ########.fr */ +/* Updated: 2017/03/11 16:23:21 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ @@ -14,8 +14,8 @@ int join_ast(t_btree **ast, t_btree **new_node) { - (*new_node)->left = *ast; - *ast = *new_node; + (*new_node)->left = *ast; + *ast = *new_node; return (0); } @@ -33,7 +33,7 @@ int gen_node(t_btree **ast) ((t_astnode *)(*ast)->item)->pattern = 0; } return (0); -} +} int isnull(t_btree **ast, t_list **lst) {