This commit is contained in:
gwojda 2017-03-29 16:02:47 +02:00
commit 6f0fb666aa
6 changed files with 17 additions and 18 deletions

View file

@ -6,7 +6,7 @@
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */ /* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2017/03/22 17:22:51 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_list *stack;
t_sym *new_sym; t_sym *new_sym;
t_list *heredoc_queue; t_list *heredoc_queue;
int cache;
}; };
struct s_aggrematch struct s_aggrematch
@ -89,7 +90,7 @@ struct s_treematch
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); int build_tree(t_btree **ast, t_list **lst, t_parser *parser);
int add_sep(t_btree **ast, t_list **lst); int add_sep(t_btree **ast, t_list **lst);
int add_cmd(t_btree **ast, t_list **lst); int add_cmd(t_btree **ast, t_list **lst);

View file

@ -6,7 +6,7 @@
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */ /* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2017/02/15 18:32:59 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); 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; int i;
static int cache; // static int cache;
t_token *token; t_token *token;
i = 0; i = 0;
token = (*lst)->content; token = (*lst)->content;
check_cache(token, cache); check_cache(token, parser->cache);
while (g_treematch[i].type) 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)); return (g_treematch[i].add(ast, lst));
} }
i++; i++;

View file

@ -6,7 +6,7 @@
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */ /* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2017/03/11 16:11:21 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, SEPARATOR_OP},
{PIPELINE, AND_OR}, {PIPELINE, AND_OR},
{PIPELINE, NEWLINE_LIST}, {PIPELINE, NEWLINE_LIST},
{AND_OR, TK_DO},
{AND_OR, TK_PAREN_CLOSE}, {AND_OR, TK_PAREN_CLOSE},
{AND_OR, TK_WHILE}, {AND_OR, TK_WHILE},
{AND_OR, TK_UNTIL}, {AND_OR, TK_UNTIL},
{AND_OR, TK_IF}, {AND_OR, TK_IF},
{AND_OR, TK_ELIF}, {AND_OR, TK_ELIF},
{AND_OR, TK_THEN},
{AND_OR, TK_ELSE}, {AND_OR, TK_ELSE},
{AND_OR, CMD_SUPERIOR}, {AND_OR, CMD_SUPERIOR},
{AND_OR, COMPOUND_LIST}, {AND_OR, COMPOUND_LIST},
{AND_OR, PIPE_SEMI_SEQUENCE}, {AND_OR, PIPE_SEMI_SEQUENCE},
{AND_OR, PIPE_CLOSE_SEQUENCE},
{AND_OR, CASE_LIST_NS}, {AND_OR, CASE_LIST_NS},
{AND_OR, COMPLETE_CONDITION},
{AND_OR, CONDITION}, {AND_OR, CONDITION},
{AND_OR, LINEBREAK}, {AND_OR, LINEBREAK},
{AND_OR, TK_BANG}, {AND_OR, TK_BANG},
@ -1285,7 +1283,6 @@ int eval_sym(t_list **stack, t_sym new_sym)
return (1); return (1);
head = (*stack)->content; head = (*stack)->content;
i = 0; i = 0;
DG("eval %s &7 %s", read_state(*head), read_state(new_sym));
while (g_stackmatch[i].top) while (g_stackmatch[i].top)
{ {
if (new_sym == g_stackmatch[i].top && *head == g_stackmatch[i].under) if (new_sym == g_stackmatch[i].top && *head == g_stackmatch[i].under)

View file

@ -6,7 +6,7 @@
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */ /* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2017/03/11 16:17:38 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) while (parser && token && *token)
{ {
produce_sym(&parser->stack, parser->new_sym, 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)) if (parser->new_sym && eval_sym(&parser->stack, *parser->new_sym))
return ((parser->state = ERROR)); return ((parser->state = ERROR));
if (aggregate_sym(&parser->stack, parser->new_sym, &parser->state)) 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; parser->state = SUCCESS;
else else
parser->state = UNDEFINED; parser->state = UNDEFINED;
build_tree(ast, token); build_tree(ast, token, parser);
if ((end_instruction(&parser->stack) && !(*token)->next)) if ((end_instruction(&parser->stack) && !(*token)->next))
insert_linebreak(token); insert_linebreak(token);
else else

View file

@ -6,7 +6,7 @@
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */ /* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2017/03/16 19:30:17 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); ft_lstdel(&parser->heredoc_queue, &ft_lst_cfree);
free(parser->new_sym); free(parser->new_sym);
parser->new_sym = NULL; parser->new_sym = NULL;
parser->cache = 0;
} }

View file

@ -6,7 +6,7 @@
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */ /* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2017/02/21 16:14:04 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->state = SUCCESS;
parser->new_sym = NULL; parser->new_sym = NULL;
parser->cache = 0;
parser->stack = NULL; parser->stack = NULL;
parser->heredoc_queue = NULL; parser->heredoc_queue = NULL;
} }