diff --git a/42sh/file1 b/42sh/file1 deleted file mode 100644 index ce09b016..00000000 --- a/42sh/file1 +++ /dev/null @@ -1 +0,0 @@ -/Users/ariard/Projects/42sh diff --git a/42sh/file2 b/42sh/file2 deleted file mode 100644 index ce09b016..00000000 --- a/42sh/file2 +++ /dev/null @@ -1 +0,0 @@ -/Users/ariard/Projects/42sh diff --git a/42sh/includes/lexer.h b/42sh/includes/lexer.h index 46500e7c..1e172f76 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/01/27 12:49:53 by ariard ### ########.fr */ +/* Updated: 2017/01/30 16:32:37 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/includes/parser.h b/42sh/includes/parser.h index 5896d348..9a9a7012 100644 --- a/42sh/includes/parser.h +++ b/42sh/includes/parser.h @@ -6,7 +6,7 @@ /* 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); int parse_newline(t_list **list_ast, t_btree **ast, 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 diff --git a/42sh/sample/2lines.sh b/42sh/sample/2lines.sh index b6efb7f2..654889de 100644 --- a/42sh/sample/2lines.sh +++ b/42sh/sample/2lines.sh @@ -1,3 +1,3 @@ ls ; echo ; pwd | cat > file2 ls | cat -pwd > file1 +pwd ; echo hello diff --git a/42sh/sample/while.sh b/42sh/sample/while.sh new file mode 100644 index 00000000..0a69155f --- /dev/null +++ b/42sh/sample/while.sh @@ -0,0 +1,3 @@ +ls ; while [ 1 ]; do + echo hello +done > file1 ; pwd diff --git a/42sh/script.sh b/42sh/script.sh index 9e99f221..a09fa173 100755 --- a/42sh/script.sh +++ b/42sh/script.sh @@ -1,11 +1,15 @@ +#!/bin/bash + echo "debut script" -do - -while [ 1 ] +VALUE=3 +while [ $VALUE -gt 1 ] do sleep 1 + ((VALUE--)) echo "a" -done +done > file1 | cat ; ls + +ls -l > file2 | cat echo "fin script" diff --git a/42sh/src/lexer/lexer_comment.c b/42sh/src/lexer/lexer_comment.c index 613b9acb..844bf507 100644 --- a/42sh/src/lexer/lexer_comment.c +++ b/42sh/src/lexer/lexer_comment.c @@ -6,7 +6,7 @@ /* 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 */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/main/ft_putast.c b/42sh/src/main/ft_putast.c index 89e9f60d..3394bb3e 100644 --- a/42sh/src/main/ft_putast.c +++ b/42sh/src/main/ft_putast.c @@ -6,7 +6,7 @@ /* 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 (" | "); else if (node->type == TK_COMMAND) return (" COM "); + else if (node->type == TK_WHILE) + return (" WHILE "); + else if (node->type == TK_LIST) + return (" LIST "); else if (node->type == TK_GREAT) return (" > "); else if (node->type == TK_LESS) diff --git a/42sh/src/main/shell_script.c b/42sh/src/main/shell_script.c index 7cf6cddd..c13c1b66 100644 --- a/42sh/src/main/shell_script.c +++ b/42sh/src/main/shell_script.c @@ -6,7 +6,7 @@ /* 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); tmp2 = tmp2->next; } + return (0); while (list_ast) { if (ft_exec((t_btree **)list_ast->content)) diff --git a/42sh/src/parser/.ft_parse.c.swn b/42sh/src/parser/.ft_parse.c.swn index 3c43bc8b..4839274b 100644 Binary files a/42sh/src/parser/.ft_parse.c.swn and b/42sh/src/parser/.ft_parse.c.swn differ diff --git a/42sh/src/parser/ft_parse.c b/42sh/src/parser/ft_parse.c index a9e6bc0a..d9da288d 100644 --- a/42sh/src/parser/ft_parse.c +++ b/42sh/src/parser/ft_parse.c @@ -6,7 +6,7 @@ /* 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_GREATAND, &parse_greatand}, {TK_SUBSHELL, &parse_subshell}, + {TK_WHILE, &parse_while}, + {TK_DO, &parse_do}, + {TK_DONE, &parse_done}, + {TK_LIST, &parse_list}, {TK_WORD, &parse_word}, {0, 0}, }; diff --git a/42sh/src/parser/parse_do.c b/42sh/src/parser/parse_do.c new file mode 100644 index 00000000..c66e47c2 --- /dev/null +++ b/42sh/src/parser/parse_do.c @@ -0,0 +1,27 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* parse_do.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: ariard +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* 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); +} diff --git a/42sh/src/parser/parse_done.c b/42sh/src/parser/parse_done.c new file mode 100644 index 00000000..349c6a78 --- /dev/null +++ b/42sh/src/parser/parse_done.c @@ -0,0 +1,27 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* parse_done.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: ariard +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* 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); +} diff --git a/42sh/src/parser/parse_list.c b/42sh/src/parser/parse_list.c new file mode 100644 index 00000000..6b216e5a --- /dev/null +++ b/42sh/src/parser/parse_list.c @@ -0,0 +1,28 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* parse_list.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: ariard +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* 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); +} diff --git a/42sh/src/parser/parse_newline.c b/42sh/src/parser/parse_newline.c index 84b48aa5..0cf3888d 100644 --- a/42sh/src/parser/parse_newline.c +++ b/42sh/src/parser/parse_newline.c @@ -6,7 +6,7 @@ /* 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 */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/parser/parse_separator.c b/42sh/src/parser/parse_separator.c index 783c974c..4453a4ff 100644 --- a/42sh/src/parser/parse_separator.c +++ b/42sh/src/parser/parse_separator.c @@ -6,7 +6,7 @@ /* 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 */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/parser/parse_while.c b/42sh/src/parser/parse_while.c new file mode 100644 index 00000000..58af9101 --- /dev/null +++ b/42sh/src/parser/parse_while.c @@ -0,0 +1,28 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* parse_while.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: ariard +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* 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); +} diff --git a/42sh/src/parser/parse_word.c b/42sh/src/parser/parse_word.c index 84dffdb2..2de64573 100644 --- a/42sh/src/parser/parse_word.c +++ b/42sh/src/parser/parse_word.c @@ -6,7 +6,7 @@ /* 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_token *token; - (void)start; - (void)list_ast; token = (*lst)->content; node = (*ast)->item; node->type = TK_COMMAND; diff --git a/42sh/test b/42sh/test deleted file mode 100644 index 108ac6c1..00000000 --- a/42sh/test +++ /dev/null @@ -1 +0,0 @@ - 11