diff --git a/42sh/includes/builtin.h b/42sh/includes/builtin.h index 094bc086..96fb1253 100644 --- a/42sh/includes/builtin.h +++ b/42sh/includes/builtin.h @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/14 22:59:57 by jhalford #+# #+# */ -/* Updated: 2017/03/20 23:22:19 by ariard ### ########.fr */ +/* Updated: 2017/03/22 17:28:02 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ @@ -22,7 +22,7 @@ # define BT_ENV_LI (1 << 0) # define BT_ENV_LU (1 << 1) -struct s_env_data +struct s_env_data { t_flag flag; char **av_data; diff --git a/42sh/includes/lexer.h b/42sh/includes/lexer.h index 5f60cc83..122b8365 100644 --- a/42sh/includes/lexer.h +++ b/42sh/includes/lexer.h @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/12/01 12:15:50 by jhalford #+# #+# */ -/* Updated: 2017/03/22 17:25:09 by jhalford ### ########.fr */ +/* Updated: 2017/03/22 17:29:24 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/includes/minishell.h b/42sh/includes/minishell.h index 2dd823c0..27fa02d0 100644 --- a/42sh/includes/minishell.h +++ b/42sh/includes/minishell.h @@ -6,12 +6,13 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/10 13:07:44 by jhalford #+# #+# */ -/* Updated: 2017/03/22 17:23:54 by jhalford ### ########.fr */ +/* Updated: 2017/03/22 17:29:53 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ #ifndef MINISHELL_H # define MINISHELL_H + # define SHELL_NAME "minishell" # include diff --git a/42sh/includes/parser.h b/42sh/includes/parser.h index 1a25f778..d3a0cbb7 100644 --- a/42sh/includes/parser.h +++ b/42sh/includes/parser.h @@ -1,11 +1,12 @@ /* ************************************************************************** */ /* */ +/* ::: :::::::: */ /* parser.h :+: :+: :+: */ /* +:+ +:+ +:+ */ -/* By: jhalford +#+ +:+ +#+ */ +/* By: ariard +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ -/* Created: 2016/12/01 12:15:54 by jhalford #+# #+# */ -/* Updated: 2017/03/03 18:18:14 by ariard ### ########.fr */ +/* Created: 2017/03/22 17:22:51 by ariard #+# #+# */ +/* Updated: 2017/03/22 17:25:11 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ @@ -35,10 +36,10 @@ struct s_parser struct s_aggrematch { - t_sym top; - t_sym under; - t_sym new_sym; - int erase_sym; + t_sym top; + t_sym under; + t_sym new_sym; + int erase_sym; }; struct s_prodmatch @@ -64,7 +65,7 @@ int do_parser_routine(t_list **token, t_btree **ast); void parser_init(t_parser *parser); void parser_destroy(t_parser *parser); int stack_init(t_parser *parser); -int redir_init(t_type type, t_redir *redir); +int redir_init(t_type type, t_redir *redir); int ft_parse(t_btree **ast, t_list **token, t_parser *parser); int produce_sym(t_list **stack, t_sym *new_sym, t_list **lst); @@ -82,15 +83,10 @@ int error_eof(void); int ft_read_stack(t_sym *stack); char *read_state(t_sym current); -/* - * Build AST - rewriting - * -*/ - struct s_treematch { t_type type; - int (*add)(t_btree **ast, t_list **lst); + int (*add)(t_btree **ast, t_list **lst); }; int build_tree(t_btree **ast, t_list **lst); @@ -145,7 +141,7 @@ int superflous_token(t_btree **ast, t_list **list); void sym_free(void *data, size_t size); void tree_func_free(void *data, size_t content_size); -struct s_distrostree +struct s_distrostree { int (*test)(t_btree **ast, t_list **lst); int (*add)(t_btree **ast, t_list **lst); diff --git a/42sh/includes/types.h b/42sh/includes/types.h index 6540196b..4ee154f1 100644 --- a/42sh/includes/types.h +++ b/42sh/includes/types.h @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/12/13 17:11:48 by jhalford #+# #+# */ -/* Updated: 2017/03/22 17:22:52 by jhalford ### ########.fr */ +/* Updated: 2017/03/22 17:30:06 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ @@ -196,6 +196,8 @@ enum e_sym OPEN_FUNC, CLOSE_FUNC, CLOSE_LIST, + SEMI_SUBSHELL, + SEMI_BRACE, REDIR, CMD, HEREDOCDATA, diff --git a/42sh/src/main/main.c b/42sh/src/main/main.c index 85575246..41b1100c 100644 --- a/42sh/src/main/main.c +++ b/42sh/src/main/main.c @@ -6,7 +6,7 @@ /* By: gwojda +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/20 14:45:40 by gwojda #+# #+# */ -/* Updated: 2017/03/22 17:35:21 by jhalford ### ########.fr */ +/* Updated: 2017/03/22 17:37:32 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -43,7 +43,7 @@ static int handle_instruction(t_list **token, t_btree **ast) return (ret); if (do_lexer_routine(token, stream) > 0) continue ; - /* token_print(*token); */ + token_print(*token); if ((ret = do_parser_routine(token, ast)) == 1 && SH_NO_INTERACTIVE(data->opts)) return (ret); diff --git a/42sh/src/parser/aggregate_sym.c b/42sh/src/parser/aggregate_sym.c index 9dc025f4..5e8450bc 100644 --- a/42sh/src/parser/aggregate_sym.c +++ b/42sh/src/parser/aggregate_sym.c @@ -6,7 +6,7 @@ /* By: ariard +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/11 15:58:38 by ariard #+# #+# */ -/* Updated: 2017/03/18 19:18:21 by ariard ### ########.fr */ +/* Updated: 2017/03/22 16:54:58 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ @@ -38,6 +38,7 @@ t_aggrematch g_aggrematch[] = {TK_DONE, COMPOUND_LIST, DO_GROUP, TK_DO}, {TK_ESAC, TK_IN, CASE_CLAUSE, TK_CASE}, {TK_ESAC, CASE_LIST_NS, CASE_CLAUSE, TK_CASE}, + {TK_PAREN_CLOSE, SEMI_SUBSHELL, SUBSHELL, TK_PAREN_OPEN}, {TK_PAREN_CLOSE, COMPOUND_LIST, SUBSHELL, TK_PAREN_OPEN}, {TK_PAREN_CLOSE, CMD_SUPERIOR, SUBSHELL, TK_PAREN_OPEN}, {TK_PAREN_CLOSE, PIPE_SEMI_SEQUENCE, SUBSHELL, TK_PAREN_OPEN}, @@ -220,7 +221,9 @@ t_aggrematch g_aggrematch[] = {COMPOUND_LIST, CASE_LIST_NS, CASE_LIST_NS, CASE_LIST_NS}, {CLOSE_LIST, PATTERN, CASE_LIST_NS, PATTERN_CASE}, {CLOSE_LIST, FUNC_NAME, FUNCTION_DEFINITION, FUNC_NAME}, + {SUBSHELL, TK_PAREN_OPEN, SEMI_SUBSHELL, 0}, {SUBSHELL, ALL, COMPOUND_COMMAND, 0}, + {BRACE_CLAUSE, TK_LBRACE, SEMI_BRACE, 0}, {BRACE_CLAUSE, ALL, COMPOUND_COMMAND, 0}, {COMPOUND_COMMAND, FUNC_NAME, COMMAND, FUNC_NAME}, {AND_OR_MINOR, PIPE_SEMI_SEQUENCE, AND_OR_MAJOR, PIPE_SEMI_SEQUENCE}, @@ -379,15 +382,20 @@ int aggregate_sym(t_list **stack, t_sym *new_sym, t_parstate *state) return (1); i = -1; head = (*stack)->content; + 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)); *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)); } if (eval_sym(stack, *new_sym) && !(*state = ERROR)) return (1); diff --git a/42sh/src/parser/eval_sym.c b/42sh/src/parser/eval_sym.c index 458e17c9..82db6598 100644 --- a/42sh/src/parser/eval_sym.c +++ b/42sh/src/parser/eval_sym.c @@ -6,7 +6,7 @@ /* By: ariard +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/11 16:11:21 by ariard #+# #+# */ -/* Updated: 2017/03/22 16:11:11 by ariard ### ########.fr */ +/* Updated: 2017/03/22 16:56:05 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ @@ -578,6 +578,7 @@ t_stackmatch g_stackmatch[] = {TK_PAREN_CLOSE, COMPOUND_LIST}, {TK_PAREN_CLOSE, FUNC_NAME}, {TK_PAREN_CLOSE, OPEN_FUNC}, + {TK_PAREN_CLOSE, SEMI_SUBSHELL}, {TK_RBRACE, TK_SEMI}, {TK_RBRACE, END_COMMAND}, {TK_RBRACE, SEPARATOR_OP}, @@ -1047,6 +1048,7 @@ t_stackmatch g_stackmatch[] = {SUBSHELL, COMPLETE_CONDITION}, {SUBSHELL, CONDITION}, {SUBSHELL, AND_OR_MAJOR}, + {SEMI_SUBSHELL, TK_PAREN_OPEN}, {COMPOUND_COMMAND, LINEBREAK}, {COMPOUND_COMMAND, TK_PAREN_OPEN}, {COMPOUND_COMMAND, TK_LBRACE}, @@ -1271,6 +1273,7 @@ int eval_sym(t_list **stack, t_sym new_sym) return (1); head = (*stack)->content; i = 0; + DG("eval head %s && sym %s", read_state(*head), read_state(new_sym)); while (g_stackmatch[i].top) { if (new_sym == g_stackmatch[i].top && *head == g_stackmatch[i].under) diff --git a/42sh/src/parser/produce_sym.c b/42sh/src/parser/produce_sym.c index 9027522a..090b39cd 100644 --- a/42sh/src/parser/produce_sym.c +++ b/42sh/src/parser/produce_sym.c @@ -6,7 +6,7 @@ /* By: ariard +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/02/09 17:58:34 by ariard #+# #+# */ -/* Updated: 2017/03/22 16:10:09 by ariard ### ########.fr */ +/* Updated: 2017/03/22 16:34:24 by ariard ### ########.fr */ /* */ /* ************************************************************************** */