ast with while ok next:execution while

This commit is contained in:
ariard@student.42.fr 2017-01-30 17:23:55 +01:00
parent 42bd66af42
commit 2212c927f8
20 changed files with 148 additions and 20 deletions

View file

@ -1 +0,0 @@
/Users/ariard/Projects/42sh

View file

@ -1 +0,0 @@
/Users/ariard/Projects/42sh

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */ /* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2016/12/01 12:15:50 by jhalford #+# #+# */ /* Created: 2016/12/01 12:15:50 by jhalford #+# #+# */
/* Updated: 2017/01/27 12:49:53 by ariard ### ########.fr */ /* Updated: 2017/01/30 16:32:37 by ariard ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */ /* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2016/12/01 12:15:54 by jhalford #+# #+# */ /* Created: 2016/12/01 12:15:54 by jhalford #+# #+# */
/* Updated: 2017/01/26 20:57:12 by ariard ### ########.fr */ /* Updated: 2017/01/30 17:14:02 by ariard ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -80,5 +80,12 @@ int parse_subshell(t_list **list_ast, t_btree **ast,
t_list **start, t_list **lst); t_list **start, t_list **lst);
int parse_newline(t_list **list_ast, t_btree **ast, int parse_newline(t_list **list_ast, t_btree **ast,
t_list **start, t_list **lst); t_list **start, t_list **lst);
int parse_while(t_list **list_ast, t_btree **ast,
t_list **start, t_list **lst);
int parse_do(t_list **list_ast, t_btree **ast,
t_list **start, t_list **lst);
int parse_done(t_list **list_ast, t_btree **ast,
t_list **start, t_list **lst);
int parse_list(t_list **list_ast, t_btree **ast,
t_list **start, t_list **lst);
#endif #endif

View file

@ -1,3 +1,3 @@
ls ; echo ; pwd | cat > file2 ls ; echo ; pwd | cat > file2
ls | cat ls | cat
pwd > file1 pwd ; echo hello

3
42sh/sample/while.sh Normal file
View file

@ -0,0 +1,3 @@
ls ; while [ 1 ]; do
echo hello
done > file1 ; pwd

View file

@ -1,11 +1,15 @@
#!/bin/bash
echo "debut script" echo "debut script"
do VALUE=3
while [ $VALUE -gt 1 ]
while [ 1 ]
do do
sleep 1 sleep 1
((VALUE--))
echo "a" echo "a"
done done > file1 | cat ; ls
ls -l > file2 | cat
echo "fin script" echo "fin script"

View file

@ -6,7 +6,7 @@
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */ /* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2017/01/24 18:22:35 by ariard #+# #+# */ /* Created: 2017/01/24 18:22:35 by ariard #+# #+# */
/* Updated: 2017/01/24 20:07:14 by ariard ### ########.fr */ /* Updated: 2017/01/30 17:22:48 by ariard ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */

View file

@ -6,7 +6,7 @@
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */ /* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2016/11/14 18:18:04 by jhalford #+# #+# */ /* Created: 2016/11/14 18:18:04 by jhalford #+# #+# */
/* Updated: 2017/01/10 14:18:53 by jhalford ### ########.fr */ /* Updated: 2017/01/30 17:21:06 by ariard ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -32,6 +32,10 @@ char *ft_putast(void *nodein)
return (" | "); return (" | ");
else if (node->type == TK_COMMAND) else if (node->type == TK_COMMAND)
return (" COM "); return (" COM ");
else if (node->type == TK_WHILE)
return (" WHILE ");
else if (node->type == TK_LIST)
return (" LIST ");
else if (node->type == TK_GREAT) else if (node->type == TK_GREAT)
return (" > "); return (" > ");
else if (node->type == TK_LESS) else if (node->type == TK_LESS)

View file

@ -6,7 +6,7 @@
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */ /* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2017/01/22 23:06:34 by ariard #+# #+# */ /* Created: 2017/01/22 23:06:34 by ariard #+# #+# */
/* Updated: 2017/01/28 23:38:10 by ariard ### ########.fr */ /* Updated: 2017/01/30 17:15:37 by ariard ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -40,6 +40,7 @@ int shell_script()
btree_print(STDBUG, *ast2, &ft_putast); btree_print(STDBUG, *ast2, &ft_putast);
tmp2 = tmp2->next; tmp2 = tmp2->next;
} }
return (0);
while (list_ast) while (list_ast)
{ {
if (ft_exec((t_btree **)list_ast->content)) if (ft_exec((t_btree **)list_ast->content))

Binary file not shown.

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */ /* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2016/11/30 17:14:58 by jhalford #+# #+# */ /* Created: 2016/11/30 17:14:58 by jhalford #+# #+# */
/* Updated: 2017/01/28 23:27:39 by ariard ### ########.fr */ /* Updated: 2017/01/30 17:14:19 by ariard ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -26,6 +26,10 @@ t_parser g_parser[] =
{TK_LESSAND, &parse_lessand}, {TK_LESSAND, &parse_lessand},
{TK_GREATAND, &parse_greatand}, {TK_GREATAND, &parse_greatand},
{TK_SUBSHELL, &parse_subshell}, {TK_SUBSHELL, &parse_subshell},
{TK_WHILE, &parse_while},
{TK_DO, &parse_do},
{TK_DONE, &parse_done},
{TK_LIST, &parse_list},
{TK_WORD, &parse_word}, {TK_WORD, &parse_word},
{0, 0}, {0, 0},
}; };

View file

@ -0,0 +1,27 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* parse_do.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/01/30 16:28:41 by ariard #+# #+# */
/* Updated: 2017/01/30 17:15:40 by ariard ### ########.fr */
/* */
/* ************************************************************************** */
#include "parser.h"
int parse_do(t_list **list_ast, t_btree **ast,
t_list **start, t_list **lst)
{
t_astnode *node;
t_token *token;
token = (*lst)->content;
node = (*ast)->item;
node->type = TK_DO;
ft_lst_delif(start, (*lst)->content, &ft_addrcmp, &token_free);
ft_parse(list_ast, ast, start);
return (0);
}

View file

@ -0,0 +1,27 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* parse_done.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/01/30 16:36:28 by ariard #+# #+# */
/* Updated: 2017/01/30 17:15:00 by ariard ### ########.fr */
/* */
/* ************************************************************************** */
#include "parser.h"
int parse_done(t_list **list_ast, t_btree **ast,
t_list **start, t_list **lst)
{
t_astnode *node;
t_token *token;
token = (*lst)->content;
node = (*ast)->item;
node->type = TK_DONE;
ft_lst_delif(start, (*lst)->content, &ft_addrcmp, &token_free);
ft_parse(list_ast, ast, start);
return (0);
}

View file

@ -0,0 +1,28 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* parse_list.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/01/30 16:34:21 by ariard #+# #+# */
/* Updated: 2017/01/30 17:22:54 by ariard ### ########.fr */
/* */
/* ************************************************************************** */
#include "parser.h"
int parse_list(t_list **list_ast, t_btree **ast,
t_list **start, t_list **lst)
{
t_astnode *node;
t_token *token;
(void)list_ast;
token = (*lst)->content;
node = (*ast)->item;
node->type = TK_LIST;
node->data.sstr = ft_sstradd(node->data.sstr, token->data);
ft_lst_delif(start, (*lst)->content, &ft_addrcmp, &token_free);
return (0);
}

View file

@ -6,7 +6,7 @@
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */ /* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2017/01/26 19:26:41 by ariard #+# #+# */ /* Created: 2017/01/26 19:26:41 by ariard #+# #+# */
/* Updated: 2017/01/28 23:24:40 by ariard ### ########.fr */ /* Updated: 2017/01/30 17:14:05 by ariard ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */ /* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2016/11/28 16:21:51 by jhalford #+# #+# */ /* Created: 2016/11/28 16:21:51 by jhalford #+# #+# */
/* Updated: 2017/01/28 23:01:44 by ariard ### ########.fr */ /* Updated: 2017/01/30 17:11:05 by ariard ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */

View file

@ -0,0 +1,28 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* parse_while.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/01/30 16:03:28 by ariard #+# #+# */
/* Updated: 2017/01/30 17:22:36 by ariard ### ########.fr */
/* */
/* ************************************************************************** */
#include "parser.h"
int parse_while(t_list **list_ast, t_btree **ast,
t_list **start, t_list **lst)
{
t_astnode *node;
t_token *token;
token = (*lst)->content;
node = (*ast)->item;
node->type = TK_WHILE;
ft_lst_delif(start, (*lst)->content, &ft_addrcmp, &token_free);
ft_parse(list_ast, &(*ast)->left, start);
ft_parse(list_ast, &(*ast)->right, start);
return (0);
}

View file

@ -6,7 +6,7 @@
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */ /* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2016/11/14 12:49:45 by jhalford #+# #+# */ /* Created: 2016/11/14 12:49:45 by jhalford #+# #+# */
/* Updated: 2017/01/27 13:52:59 by ariard ### ########.fr */ /* Updated: 2017/01/30 16:45:53 by ariard ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -18,8 +18,6 @@ int parse_word(t_list **list_ast, t_btree **ast,
t_astnode *node; t_astnode *node;
t_token *token; t_token *token;
(void)start;
(void)list_ast;
token = (*lst)->content; token = (*lst)->content;
node = (*ast)->item; node = (*ast)->item;
node->type = TK_COMMAND; node->type = TK_COMMAND;

View file

@ -1 +0,0 @@
11