new parsing des if
This commit is contained in:
parent
0852e7c807
commit
a2628f4302
15 changed files with 10306 additions and 38 deletions
10245
42sh/file1
Normal file
10245
42sh/file1
Normal file
File diff suppressed because it is too large
Load diff
|
|
@ -6,7 +6,7 @@
|
|||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/11/27 20:29:56 by jhalford #+# #+# */
|
||||
/* Updated: 2017/03/10 16:19:30 by ariard ### ########.fr */
|
||||
/* Updated: 2017/03/10 17:39:42 by ariard ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
|
|||
|
|
@ -124,6 +124,7 @@ 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 add_if(t_btree **ast, t_list **lst);
|
||||
|
||||
int isloop(t_btree **ast, t_list **lst);
|
||||
int isloop_condition(t_btree **ast, t_list **lst);
|
||||
|
|
|
|||
5
42sh/sample/while/while02.sh
Normal file
5
42sh/sample/while/while02.sh
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
ls
|
||||
while [ 1 ] ;
|
||||
do
|
||||
ls | cat
|
||||
done
|
||||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2017/03/10 14:46:27 by ariard #+# #+# */
|
||||
/* Updated: 2017/03/10 15:51:37 by ariard ### ########.fr */
|
||||
/* Updated: 2017/03/10 16:25:35 by ariard ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/11/14 18:18:04 by jhalford #+# #+# */
|
||||
/* Updated: 2017/03/09 18:54:07 by ariard ### ########.fr */
|
||||
/* Updated: 2017/03/10 17:56:38 by ariard ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/12/06 18:40:58 by jhalford #+# #+# */
|
||||
/* Updated: 2017/03/10 16:20:35 by ariard ### ########.fr */
|
||||
/* Updated: 2017/03/10 16:29:09 by ariard ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -72,8 +72,8 @@ int handle_instruction(int fd)
|
|||
}
|
||||
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);
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2017/03/10 14:57:45 by ariard #+# #+# */
|
||||
/* Updated: 2017/03/10 15:43:54 by ariard ### ########.fr */
|
||||
/* Updated: 2017/03/10 17:35:55 by ariard ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2017/03/04 20:42:13 by ariard #+# #+# */
|
||||
/* Updated: 2017/03/09 20:00:19 by ariard ### ########.fr */
|
||||
/* Updated: 2017/03/10 17:34:11 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);
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2017/02/15 20:49:15 by ariard #+# #+# */
|
||||
/* Updated: 2017/03/10 15:22:44 by ariard ### ########.fr */
|
||||
/* Updated: 2017/03/10 17:55:08 by ariard ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -84,7 +84,10 @@ int add_cmd(t_btree **ast, t_list **lst)
|
|||
return (add_cmd(&(*ast)->right, lst));
|
||||
token = (*lst)->content;
|
||||
node = (*ast)->item;
|
||||
if (token->type != TK_WORD)
|
||||
DG("add cmd");
|
||||
if (token->type == TK_IF)
|
||||
add_if(ast, lst);
|
||||
else if (token->type != TK_WORD)
|
||||
node->type = token->type;
|
||||
else
|
||||
node->type = CMD;
|
||||
|
|
|
|||
|
|
@ -1,12 +1,12 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* add_condition.c :+: :+: :+: */
|
||||
/* add_if.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2017/02/19 18:12:52 by ariard #+# #+# */
|
||||
/* Updated: 2017/03/07 22:46:10 by ariard ### ########.fr */
|
||||
/* Created: 2017/03/10 17:06:16 by ariard #+# #+# */
|
||||
/* Updated: 2017/03/10 18:06:27 by ariard ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -15,18 +15,19 @@
|
|||
int iscondition(t_btree **ast, t_list **lst)
|
||||
{
|
||||
t_astnode *node;
|
||||
t_token *token;
|
||||
|
||||
(void)lst;
|
||||
node = NULL;
|
||||
token = (*lst)->content;
|
||||
if (*ast)
|
||||
{
|
||||
node = (*ast)->item;
|
||||
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)
|
||||
return (1);
|
||||
if ((node->type == TK_NEWLINE || node->type == TK_SEMI
|
||||
|| node->type == TK_AMP) && iscondition(&(*ast)->right, lst))
|
||||
return (1);
|
||||
}
|
||||
return (0);
|
||||
}
|
||||
|
|
@ -41,20 +42,19 @@ int iscondition_branch(t_btree **ast, t_list **lst)
|
|||
if (*ast)
|
||||
{
|
||||
node = (*ast)->item;
|
||||
if ((node->type == TK_IF || iscondition(&(*ast)->right, lst))
|
||||
&& (token->type == TK_ELIF || token->type == TK_ELSE)
|
||||
if ((node->type == TK_IF || node->type == TK_ELIF)
|
||||
&& (token->type == TK_ELIF || token->type == TK_ELSE)
|
||||
&& node->nest == 0)
|
||||
return (1);
|
||||
}
|
||||
return (0);
|
||||
}
|
||||
|
||||
int add_condition_cmd(t_btree **ast, t_list **lst)
|
||||
int add_condition_cmd(t_btree **ast, t_list **lst)
|
||||
{
|
||||
t_token *token;
|
||||
t_astnode *node;
|
||||
|
||||
DG("add condition");
|
||||
token = (*lst)->content;
|
||||
node = (*ast)->item;
|
||||
if (token->type == TK_IF && (node->type == TK_IF || node->type == TK_ELIF
|
||||
|
|
@ -64,7 +64,7 @@ int add_condition_cmd(t_btree **ast, t_list **lst)
|
|||
|| 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))
|
||||
|| node->type == TK_ELSE))
|
||||
return ((node->full = 1));
|
||||
if (token->type == TK_THEN)
|
||||
return (add_cmd(&(*ast)->right, lst));
|
||||
|
|
@ -73,9 +73,10 @@ int add_condition_cmd(t_btree **ast, t_list **lst)
|
|||
else
|
||||
return (add_cmd(&(*ast)->right, lst));
|
||||
return (0);
|
||||
}
|
||||
}
|
||||
|
||||
int add_condition_sep(t_btree **ast, t_list **lst)
|
||||
|
||||
int add_condition_sep(t_btree **ast, t_list **lst)
|
||||
{
|
||||
if (!(*ast)->right)
|
||||
return (add_sep(&(*ast)->left, lst));
|
||||
|
|
@ -84,15 +85,16 @@ int add_condition_sep(t_btree **ast, t_list **lst)
|
|||
return (0);
|
||||
}
|
||||
|
||||
int add_branch(t_btree **ast, t_list **lst)
|
||||
int add_if(t_btree **ast, t_list **lst)
|
||||
{
|
||||
t_token *token;
|
||||
t_astnode *node;
|
||||
t_btree *new_node;
|
||||
|
||||
new_node = NULL;
|
||||
gen_node(&new_node);
|
||||
join_ast(ast, &new_node);
|
||||
node = (new_node)->item;
|
||||
node->type = TK_NEWLINE;
|
||||
return (add_cmd(ast, lst));
|
||||
DG("add if");
|
||||
token = (*lst)->content;
|
||||
node = (*ast)->item;
|
||||
node->type = TK_IF;
|
||||
token->type = TK_ELIF;
|
||||
add_cmd(ast, lst);
|
||||
return (0);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2017/02/17 22:17:14 by ariard #+# #+# */
|
||||
/* Updated: 2017/03/07 22:46:20 by ariard ### ########.fr */
|
||||
/* Updated: 2017/03/10 17:14:21 by ariard ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2017/02/15 19:12:07 by ariard #+# #+# */
|
||||
/* Updated: 2017/03/10 15:43:01 by ariard ### ########.fr */
|
||||
/* Updated: 2017/03/10 18:05:35 by ariard ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -18,7 +18,6 @@ int add_sep(t_btree **ast, t_list **lst)
|
|||
t_astnode *node;
|
||||
t_btree *new_node;
|
||||
|
||||
DG("add sep");
|
||||
if (isloop(ast, lst))
|
||||
return (add_loop_sep(ast, lst));
|
||||
else if (iscondition(ast, lst))
|
||||
|
|
@ -33,6 +32,7 @@ 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);
|
||||
|
|
|
|||
|
|
@ -55,7 +55,7 @@ int ft_parse(t_btree **ast, t_list **token, t_parser *parser)
|
|||
else
|
||||
parser->state = UNDEFINED;
|
||||
build_tree(ast, token);
|
||||
// btree_print(STDBUG, *ast, &ft_putast);
|
||||
btree_print(STDBUG, *ast, &ft_putast);
|
||||
if ((end_instruction(&parser->stack) && !(*token)->next))
|
||||
insert_linebreak(token);
|
||||
else
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2017/02/15 18:57:44 by ariard #+# #+# */
|
||||
/* Updated: 2017/03/08 00:02:46 by ariard ### ########.fr */
|
||||
/* Updated: 2017/03/10 17:49:28 by ariard ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -49,3 +49,15 @@ int add_null(t_btree **ast, t_list **lst)
|
|||
return (-1);
|
||||
}
|
||||
|
||||
int add_branch(t_btree **ast, t_list **lst)
|
||||
{
|
||||
t_astnode *node;
|
||||
t_btree *new_node;
|
||||
|
||||
new_node = NULL;
|
||||
gen_node(&new_node);
|
||||
join_ast(ast, &new_node);
|
||||
node = (new_node)->item;
|
||||
node->type = TK_NEWLINE;
|
||||
return (add_cmd(ast, lst));
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue