diff --git a/42sh/includes/parser.h b/42sh/includes/parser.h index 0e25ac2f..56af0c8d 100644 --- a/42sh/includes/parser.h +++ b/42sh/includes/parser.h @@ -6,7 +6,7 @@ /* By: ariard +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/22 17:22:51 by ariard #+# #+# */ -/* Updated: 2017/03/29 13:29:26 by ariard ### ########.fr */ +/* Updated: 2017/03/29 15:42:45 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ @@ -32,6 +32,7 @@ struct s_parser t_list *stack; t_sym *new_sym; t_list *heredoc_queue; + int cache; }; struct s_aggrematch @@ -89,7 +90,7 @@ struct s_treematch int (*add)(t_btree **ast, t_list **lst); }; -int build_tree(t_btree **ast, t_list **lst); +int build_tree(t_btree **ast, t_list **lst, t_parser *parser); int add_sep(t_btree **ast, t_list **lst); int add_cmd(t_btree **ast, t_list **lst); diff --git a/42sh/src/parser/build_tree.c b/42sh/src/parser/build_tree.c index 267dffc4..430eec61 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/29 13:28:38 by ariard ### ########.fr */ +/* Updated: 2017/03/29 15:40:57 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ @@ -77,20 +77,20 @@ static int check_cache(t_token *token, int cache) return (0); } -int build_tree(t_btree **ast, t_list **lst) +int build_tree(t_btree **ast, t_list **lst, t_parser *parser) { int i; - static int cache; +// static int cache; t_token *token; i = 0; token = (*lst)->content; - check_cache(token, cache); + check_cache(token, parser->cache); while (g_treematch[i].type) { - if ((isseparator(token, cache) && g_treematch[i].type == token->type)) + if ((isseparator(token, parser->cache) && g_treematch[i].type == token->type)) { - cache = token->type; + parser->cache = token->type; return (g_treematch[i].add(ast, lst)); } i++; diff --git a/42sh/src/parser/eval_sym.c b/42sh/src/parser/eval_sym.c index 2008c214..e6e97cee 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/29 15:19:03 by ariard ### ########.fr */ +/* Updated: 2017/03/29 15:52:29 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ @@ -1245,19 +1245,17 @@ static t_stackmatch g_stackmatch[] = {PIPELINE, SEPARATOR_OP}, {PIPELINE, AND_OR}, {PIPELINE, NEWLINE_LIST}, - {AND_OR, TK_DO}, {AND_OR, TK_PAREN_CLOSE}, {AND_OR, TK_WHILE}, {AND_OR, TK_UNTIL}, {AND_OR, TK_IF}, {AND_OR, TK_ELIF}, - {AND_OR, TK_THEN}, {AND_OR, TK_ELSE}, {AND_OR, CMD_SUPERIOR}, {AND_OR, COMPOUND_LIST}, {AND_OR, PIPE_SEMI_SEQUENCE}, + {AND_OR, PIPE_CLOSE_SEQUENCE}, {AND_OR, CASE_LIST_NS}, - {AND_OR, COMPLETE_CONDITION}, {AND_OR, CONDITION}, {AND_OR, LINEBREAK}, {AND_OR, TK_BANG}, @@ -1285,7 +1283,6 @@ int eval_sym(t_list **stack, t_sym new_sym) return (1); head = (*stack)->content; i = 0; - DG("eval %s &7 %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/ft_parse.c b/42sh/src/parser/ft_parse.c index 9680e92a..596669d4 100644 --- a/42sh/src/parser/ft_parse.c +++ b/42sh/src/parser/ft_parse.c @@ -6,7 +6,7 @@ /* By: ariard +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/11 16:17:38 by ariard #+# #+# */ -/* Updated: 2017/03/29 15:24:01 by jhalford ### ########.fr */ +/* Updated: 2017/03/29 15:43:05 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ @@ -40,7 +40,6 @@ int ft_parse(t_btree **ast, t_list **token, t_parser *parser) while (parser && token && *token) { produce_sym(&parser->stack, parser->new_sym, token); - DG("produce sym %s", read_state(*parser->new_sym)); if (parser->new_sym && eval_sym(&parser->stack, *parser->new_sym)) return ((parser->state = ERROR)); if (aggregate_sym(&parser->stack, parser->new_sym, &parser->state)) @@ -50,7 +49,7 @@ int ft_parse(t_btree **ast, t_list **token, t_parser *parser) parser->state = SUCCESS; else parser->state = UNDEFINED; - build_tree(ast, token); + build_tree(ast, token, parser); if ((end_instruction(&parser->stack) && !(*token)->next)) insert_linebreak(token); else diff --git a/42sh/src/parser/parser_destroy.c b/42sh/src/parser/parser_destroy.c index b81f302a..97c3abe0 100644 --- a/42sh/src/parser/parser_destroy.c +++ b/42sh/src/parser/parser_destroy.c @@ -6,7 +6,7 @@ /* By: ariard +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/16 19:30:17 by ariard #+# #+# */ -/* Updated: 2017/03/29 13:29:01 by ariard ### ########.fr */ +/* Updated: 2017/03/29 15:42:05 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ @@ -19,4 +19,5 @@ void parser_destroy(t_parser *parser) ft_lstdel(&parser->heredoc_queue, &ft_lst_cfree); free(parser->new_sym); parser->new_sym = NULL; + parser->cache = 0; } diff --git a/42sh/src/parser/parser_init.c b/42sh/src/parser/parser_init.c index a61a4414..002b9525 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/29 13:27:45 by ariard ### ########.fr */ +/* Updated: 2017/03/29 15:43:52 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ @@ -16,6 +16,7 @@ void parser_init(t_parser *parser) { parser->state = SUCCESS; parser->new_sym = NULL; + parser->cache = 0; parser->stack = NULL; parser->heredoc_queue = NULL; }