multi loop ok, to-do : do as a separator(lexing), in case of multisep after do delete all (parsing), before while inspect after done (parsing)

This commit is contained in:
ariard@student.42.fr 2017-02-03 20:03:54 +01:00
parent fcea6dda9b
commit 0a5143bd69
43 changed files with 203 additions and 346 deletions

View file

@ -130,8 +130,6 @@ lexer/lexer_backslash.c\
lexer/lexer_comment.c\ lexer/lexer_comment.c\
lexer/lexer_default.c\ lexer/lexer_default.c\
lexer/lexer_delim.c\ lexer/lexer_delim.c\
lexer/lexer_do.c\
lexer/lexer_done.c\
lexer/lexer_dquote.c\ lexer/lexer_dquote.c\
lexer/lexer_fi.c\ lexer/lexer_fi.c\
lexer/lexer_great.c\ lexer/lexer_great.c\
@ -139,7 +137,6 @@ lexer/lexer_greatand.c\
lexer/lexer_if.c\ lexer/lexer_if.c\
lexer/lexer_less.c\ lexer/lexer_less.c\
lexer/lexer_lessand.c\ lexer/lexer_lessand.c\
lexer/lexer_list.c\
lexer/lexer_newline.c\ lexer/lexer_newline.c\
lexer/lexer_number.c\ lexer/lexer_number.c\
lexer/lexer_quote.c\ lexer/lexer_quote.c\
@ -147,7 +144,6 @@ lexer/lexer_sep.c\
lexer/lexer_special.c\ lexer/lexer_special.c\
lexer/lexer_then.c\ lexer/lexer_then.c\
lexer/lexer_var.c\ lexer/lexer_var.c\
lexer/lexer_while.c\
lexer/lexer_word.c\ lexer/lexer_word.c\
lexer/reduce_bquotes.c\ lexer/reduce_bquotes.c\
lexer/reduce_parens.c\ lexer/reduce_parens.c\
@ -168,13 +164,13 @@ main/lib_expansion.c\
main/main.c\ main/main.c\
main/read_script.c\ main/read_script.c\
main/shell_exit.c\ main/shell_exit.c\
main/shell_get_ast.c\
main/shell_get_avdata.c\ main/shell_get_avdata.c\
main/shell_get_opts.c\ main/shell_get_opts.c\
main/shell_init.c\ main/shell_init.c\
main/shell_script.c\ main/shell_script.c\
main/sig_handler.c\ main/sig_handler.c\
parser/ft_parse.c\ parser/ft_parse.c\
parser/get_instruction.c \
parser/parse_dgreat.c\ parser/parse_dgreat.c\
parser/parse_dless.c\ parser/parse_dless.c\
parser/parse_do.c\ parser/parse_do.c\

View file

@ -1 +1,9 @@
/Users/ariard/Projects/42sh-2 hello
hello
hello
hello
hello
hello
hello
hello
hello

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/02/03 15:31:45 by ariard ### ########.fr */ /* Updated: 2017/02/03 19:47:09 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/02/03 14:42:21 by ariard ### ########.fr */ /* Updated: 2017/02/03 17:02:27 by ariard ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -26,7 +26,7 @@ typedef long long t_type;
struct s_parser struct s_parser
{ {
t_type type; t_type type;
int (*f)(t_list **list_ast, t_btree **ast, int (*f)(t_btree **ast,
t_list **start, t_list **token); t_list **start, t_list **token);
}; };
@ -59,37 +59,24 @@ struct s_astnode
extern t_parser g_parser[]; extern t_parser g_parser[];
int ft_parse(t_list **list_ast, t_btree **ast, t_list **token); int ft_parse(t_btree **ast, t_list **token);
int parse_newline(t_list **list_ast, t_btree **ast, int get_instruction(t_btree **ast, t_list **start, t_list **lst);
t_list **start, t_list **lst);
int parse_separator(t_list **list_ast, t_btree **ast, int parse_newline(t_btree **ast, t_list **start, t_list **lst);
t_list **start, t_list **lst); int parse_separator(t_btree **ast, t_list **start, t_list **lst);
int parse_less(t_list **list_ast, t_btree **ast, int parse_less(t_btree **ast, t_list **start, t_list **lst);
t_list **start, t_list **lst); int parse_great(t_btree **ast, t_list **start, t_list **lst);
int parse_great(t_list **list_ast, t_btree **ast, int parse_dless(t_btree **ast, t_list **start, t_list **lst);
t_list **start, t_list **lst); int parse_dgreat(t_btree **ast, t_list **start, t_list **lst);
int parse_dless(t_list **list_ast, t_btree **ast, int parse_lessand(t_btree **ast, t_list **start, t_list **lst);
t_list **start, t_list **lst); int parse_greatand(t_btree **ast, t_list **start, t_list **lst);
int parse_dgreat(t_list **list_ast, t_btree **ast, int parse_word(t_btree **ast, t_list **start, t_list **lst);
t_list **start, t_list **lst); int parse_subshell(t_btree **ast, t_list **start, t_list **lst);
int parse_lessand(t_list **list_ast, t_btree **ast, int parse_newline(t_btree **ast, t_list **start, t_list **lst);
t_list **start, t_list **lst); int parse_while(t_btree **ast, t_list **start, t_list **lst);
int parse_greatand(t_list **list_ast, t_btree **ast, int parse_do(t_btree **ast, t_list **start, t_list **lst);
t_list **start, t_list **lst); int parse_done(t_btree **ast, t_list **start, t_list **lst);
int parse_word(t_list **list_ast, t_btree **ast, int parse_list(t_btree **ast, t_list **start, t_list **lst);
t_list **start, t_list **lst);
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 #endif

6
42sh/sample/test.sh Normal file
View file

@ -0,0 +1,6 @@
test=10
while [ $test -gt 1 ]
do
echo hello
((test--))
done > file1 > file2

1
42sh/sample/test2.sh Normal file
View file

@ -0,0 +1 @@
ewf wefwe wf

View file

@ -1,11 +1,20 @@
echo "begin loop"
while [ 1 ] while [ 1 ]
do do
echo "begin inner loop" while pwd
while [ 1 ]
do do
echo "end scd loop" while pwd
do
while pwd
do
echo "hello"
done
done
done done
echo "end inner loop" while pwd
done do
echo "end loop" while pwd
do
echo "bonjour"
done
done
done

View file

@ -6,7 +6,7 @@
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */ /* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2017/01/30 17:33:53 by ariard #+# #+# */ /* Created: 2017/01/30 17:33:53 by ariard #+# #+# */
/* Updated: 2017/02/02 16:30:05 by ariard ### ########.fr */ /* Updated: 2017/02/03 16:58:02 by ariard ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -20,7 +20,7 @@ int exec_while(t_btree **ast)
node = ((*ast)->right)->item; node = ((*ast)->right)->item;
DG("consequent command data '%s'", node->data.str); DG("consequent command data '%s'", node->data.str);
consequent_commands = shell_get_ast(node->data.str); consequent_commands = NULL;
test = 10; test = 10;

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */ /* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2017/02/02 15:30:59 by jhalford #+# #+# */ /* Created: 2017/02/02 15:30:59 by jhalford #+# #+# */
/* Updated: 2017/02/03 15:36:56 by ariard ### ########.fr */ /* Updated: 2017/02/03 19:40:31 by ariard ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -21,8 +21,8 @@ int ft_lexer(t_list **alst, char **command)
ret = 1; ret = 1;
else if (ft_tokenize(alst, *command, DEFAULT)) else if (ft_tokenize(alst, *command, DEFAULT))
ret = 1; ret = 1;
// else if (ft_post_tokenize(alst, command)) else if (ft_post_tokenize(alst, command))
// ret = 1; ret = 1;
ft_strdel(command); ft_strdel(command);
return (ret); return (ret);
} }

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */ /* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2017/01/11 16:11:11 by jhalford #+# #+# */ /* Created: 2017/01/11 16:11:11 by jhalford #+# #+# */
/* Updated: 2017/02/03 14:47:09 by ariard ### ########.fr */ /* Updated: 2017/02/03 19:54:10 by ariard ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -17,8 +17,7 @@ int ft_post_tokenize(t_list **alst, char **str)
int ret; int ret;
t_flag tk; t_flag tk;
get_reserved_words(alst);
// get_reserverd_words(alst, str);
while ((ret = reduce_parens(alst, *str))) while ((ret = reduce_parens(alst, *str)))
if (ret == -1) if (ret == -1)
{ {

View file

@ -6,7 +6,7 @@
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */ /* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2016/11/10 13:37:11 by jhalford #+# #+# */ /* Created: 2016/11/10 13:37:11 by jhalford #+# #+# */
/* Updated: 2017/02/03 14:47:30 by ariard ### ########.fr */ /* Updated: 2017/02/03 19:40:50 by ariard ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */ /* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2017/01/10 13:45:46 by jhalford #+# #+# */ /* Created: 2017/01/10 13:45:46 by jhalford #+# #+# */
/* Updated: 2017/01/27 12:49:24 by ariard ### ########.fr */ /* Updated: 2017/02/03 19:53:20 by ariard ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */

View file

@ -6,7 +6,7 @@
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */ /* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2017/01/26 00:07:05 by ariard #+# #+# */ /* Created: 2017/01/26 00:07:05 by ariard #+# #+# */
/* Updated: 2017/02/03 15:31:41 by ariard ### ########.fr */ /* Updated: 2017/02/03 19:39:01 by ariard ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -14,29 +14,37 @@
int get_reserved_words(t_list **alst) int get_reserved_words(t_list **alst)
{ {
// t_token token; t_token *token;
t_list *temp;
int i;
(void)alst; temp = *alst;
/* i = 0;
while (*alst) while (temp)
{ {
token = (*alst)->content; token = temp->content;
if (token->type = TK_WORD); if (i == 0)
if (token->type == TK_N_WORD)
if (ft_strncmp(token->data, "while", 5) == 0)
token->type = TK_WHILE;
if ((token->type & (TK_NEWLINE | TK_AMP | TK_SEMI)))
{ {
if (ft_strncmp(str, "while", 5) == 0 && ft_isalpha(*(str + 5)) == 0) if ((temp = temp->next))
lexer_while( token = temp->content;
else if (ft_strncmp(str, "done", 4) == 0 && ft_isalpha(*(str + 4)) == 0) else
return (DONE); break;
else if (ft_strncmp(str, "do" , 2) == 0 && ft_isalpha(*(str + 2)) == 0) if (token->type == TK_N_WORD)
return (DO); {
// else if (ft_strncmp(str, "if", 2) == 0 && ft_isalpha(*(str + 2)) == 0) if (ft_strncmp(token->data, "while", 5) == 0)
// return (IF); token->type = TK_WHILE;
// else if (ft_strncmp(str, "then", 4) == 0 && ft_isalpha(*(str + 4)) == 0) else if (ft_strncmp(token->data, "done", 4) == 0)
// return (THEN); token->type = TK_DONE;
// else if (ft_strncmp(str, "fi", 2) == 0 && ft_isalpha(*(str + 2)) == 0) else if (ft_strncmp(token->data, "do" , 2) == 0)
// return (FI); token->type = TK_DO;
}
} }
(*alst) = (*alst)->next; temp = temp->next;
i++;
} }
*/ return (0); return (0);
} }

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */ /* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2016/11/28 18:36:21 by jhalford #+# #+# */ /* Created: 2016/11/28 18:36:21 by jhalford #+# #+# */
/* Updated: 2017/02/03 15:39:45 by ariard ### ########.fr */ /* Updated: 2017/02/03 19:53:49 by ariard ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */ /* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2016/12/03 11:58:44 by jhalford #+# #+# */ /* Created: 2016/12/03 11:58:44 by jhalford #+# #+# */
/* Updated: 2017/02/03 14:48:41 by ariard ### ########.fr */ /* Updated: 2017/02/03 19:53:11 by ariard ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */

View file

@ -1,38 +0,0 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* lexer_do.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/01/31 23:29:09 by ariard #+# #+# */
/* Updated: 2017/01/31 23:32:45 by ariard ### ########.fr */
/* */
/* ************************************************************************** */
#include "lexer.h"
int lexer_do(t_list **alst, char *str)
{
t_token *token;
t_lexstate state;
t_nest *nest;
nest = &data_singleton()->nest;
if (*alst)
{
nest->do_group++;
if (nest->do_group == 1)
return (lexer_do(&(*alst)->next, str));
return (ft_tokenize(alst, str, LIST));
}
else
{
token = token_init();
*alst = ft_lstnew(token, sizeof(*token));
}
token = (*alst)->content;
token->type = TK_DO;
state = LIST;
return (ft_tokenize(&(*alst)->next, str + 2, state));
}

View file

@ -1,38 +0,0 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* lexer_done.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/01/31 20:49:09 by ariard #+# #+# */
/* Updated: 2017/01/31 23:33:03 by ariard ### ########.fr */
/* */
/* ************************************************************************** */
#include "lexer.h"
int lexer_done(t_list **alst, char *str)
{
t_token *token;
t_lexstate state;
t_nest *nest;
nest = &data_singleton()->nest;
if (*alst)
{
nest->do_group--;
if (nest->do_group == 0)
return (lexer_done(&(*alst)->next, str));
return (ft_tokenize(alst, str, LIST));
}
else
{
token = token_init();
*alst = ft_lstnew(token, sizeof(*token));
}
token = (*alst)->content;
token->type = TK_DONE;
state = DEFAULT;
return (ft_tokenize(&(*alst)->next, str + 4, state));
}

View file

@ -1,42 +0,0 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* lexer_list.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/01/26 00:55:33 by ariard #+# #+# */
/* Updated: 2017/02/03 15:12:49 by ariard ### ########.fr */
/* */
/* ************************************************************************** */
#include "lexer.h"
int lexer_list(t_list **alst, char *str)
{
t_token *token;
token = (*alst)->content;
token->type = TK_LIST;
while (*str)
{
if (ft_is_delim_list(*str))
{
token_append(token, *str++, 0);
while (ft_is_delim(*str) || *str == '\n')
str++;
if (ft_strncmp(str, "done", 4) == 0 && ft_isalpha(*(str + 4)) == 0)
return (ft_tokenize(alst, str, DONE));
else if (ft_strncmp(str, "do", 2) == 0 && (ft_is_delim_list(*(str + 2))
|| *(str + 2) == ' '))
return (ft_tokenize(alst, str, DO));
else if (ft_strncmp(str, "then", 4) == 0 && (ft_is_delim_list(*(str + 4))
|| *(str + 4) == ' '))
return (ft_tokenize(alst, str, THEN));
else if (ft_strncmp(str, "fi", 2) == 0 && ft_isalpha(*(str + 2)) == 0)
return (ft_tokenize(alst, str, FI));
}
token_append(token, *str++, 0);
}
return (0);
}

View file

@ -6,7 +6,7 @@
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */ /* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2017/01/23 23:19:46 by ariard #+# #+# */ /* Created: 2017/01/23 23:19:46 by ariard #+# #+# */
/* Updated: 2017/01/27 12:51:12 by ariard ### ########.fr */ /* Updated: 2017/02/03 19:53:03 by ariard ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */ /* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2016/11/30 16:29:57 by jhalford #+# #+# */ /* Created: 2016/11/30 16:29:57 by jhalford #+# #+# */
/* Updated: 2017/02/02 16:30:03 by ariard ### ########.fr */ /* Updated: 2017/02/03 19:53:31 by ariard ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */ /* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2016/12/03 12:07:11 by jhalford #+# #+# */ /* Created: 2016/12/03 12:07:11 by jhalford #+# #+# */
/* Updated: 2017/02/03 15:40:21 by ariard ### ########.fr */ /* Updated: 2017/02/03 19:52: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/30 17:21:06 by ariard ### ########.fr */ /* Updated: 2017/02/03 19:35:03 by ariard ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -34,6 +34,8 @@ char *ft_putast(void *nodein)
return (" COM "); return (" COM ");
else if (node->type == TK_WHILE) else if (node->type == TK_WHILE)
return (" WHILE "); return (" WHILE ");
else if (node->type == TK_NEWLINE)
return ("NEW");
else if (node->type == TK_LIST) else if (node->type == TK_LIST)
return (" LIST "); return (" LIST ");
else if (node->type == TK_GREAT) else if (node->type == TK_GREAT)

View file

@ -6,7 +6,7 @@
/* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */ /* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2016/12/06 18:40:58 by jhalford #+# #+# */ /* Created: 2016/12/06 18:40:58 by jhalford #+# #+# */
/* Updated: 2017/02/03 15:40:10 by ariard ### ########.fr */ /* Updated: 2017/02/03 16:33:52 by ariard ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */

View file

@ -6,7 +6,7 @@
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */ /* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2017/01/21 22:49:31 by ariard #+# #+# */ /* Created: 2017/01/21 22:49:31 by ariard #+# #+# */
/* Updated: 2017/01/30 20:32:24 by ariard ### ########.fr */ /* Updated: 2017/02/03 19:55:38 by ariard ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -20,13 +20,14 @@ static int rs_loop(char *file, t_script *script)
line = NULL; line = NULL;
if ((fd = open(file, O_RDONLY)) == -1) if ((fd = open(file, O_RDONLY)) == -1)
return (0); return (0);
while (get_next_line(fd, &line) > 0) while ((get_next_line(fd, &line)) > 0)
{ {
ft_strappend(&script->buffer, line); ft_strappend(&script->buffer, line);
ft_strappend(&script->buffer, "\n"); ft_strappend(&script->buffer, "\n");
ft_strdel(&line); ft_strdel(&line);
script->size += ft_strlen(script->buffer); script->size += ft_strlen(script->buffer);
} }
script->buffer[ft_strlen(script->buffer) - 1] = 0;
close(fd); close(fd);
if (script->size > 0) if (script->size > 0)
{ {

View file

@ -1,35 +0,0 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* shell_set_ast.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/01/30 18:19:13 by ariard #+# #+# */
/* Updated: 2017/02/03 15:29:43 by ariard ### ########.fr */
/* */
/* ************************************************************************** */
#include "minishell.h"
t_list **shell_get_ast(char *command)
{
t_list *token;
t_btree *ast;
t_list **list_ast;
token = NULL;
ast = NULL;
list_ast = ft_memalloc(sizeof(*list_ast));
if (ft_tokenize(&token, command, DEFAULT))
return (NULL);
if (!token)
return (NULL);
if (ft_post_tokenize(&token, &command))
return (NULL);
DG("after post_tokenize");
token_print(token);
if (ft_parse(list_ast, &ast, &token))
return (NULL);
return (list_ast);
}

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/02/03 15:37:58 by ariard ### ########.fr */ /* Updated: 2017/02/03 18:16:01 by ariard ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -16,9 +16,7 @@ int shell_script()
{ {
t_list *token; t_list *token;
t_btree *ast; t_btree *ast;
t_btree **ast2;
t_list *list_ast; t_list *list_ast;
t_list *tmp2;
token = NULL; token = NULL;
ast = NULL; ast = NULL;
@ -27,23 +25,14 @@ int shell_script()
return (1); return (1);
DG("after post_tokenize"); DG("after post_tokenize");
token_print(token); token_print(token);
if (ft_parse(&list_ast, &ast, &token))
return (1);
tmp2 = list_ast;
while (tmp2)
{
ast2 = tmp2->content;
btree_print(STDBUG, *ast2, &ft_putast);
tmp2 = tmp2->next;
}
/* while (list_ast)
{
if (ft_exec((t_btree **)list_ast->content))
return (1);
list_ast = list_ast->next;
}
*/ while (token)
loop_exec(list_ast); {
if (ft_parse(&ast, &token))
return (1);
btree_print(STDBUG, ast, &ft_putast);
// if (ft_exec(&ast))
// return (1);
}
return (0); return (0);
} }

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/02/03 14:31:06 by ariard ### ########.fr */ /* Updated: 2017/02/03 19:37:05 by ariard ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -14,7 +14,7 @@
t_parser g_parser[] = t_parser g_parser[] =
{ {
{TK_NEWLINE, &parse_newline}, {TK_NEWLINE | TK_WHILE, &get_instruction},
{TK_SEMI, &parse_separator}, {TK_SEMI, &parse_separator},
{TK_AND_IF | TK_OR_IF, &parse_separator}, {TK_AND_IF | TK_OR_IF, &parse_separator},
{TK_AMP, &parse_separator}, {TK_AMP, &parse_separator},
@ -27,14 +27,11 @@ t_parser g_parser[] =
{TK_GREATAND, &parse_greatand}, {TK_GREATAND, &parse_greatand},
{TK_SUBSHELL, &parse_subshell}, {TK_SUBSHELL, &parse_subshell},
{TK_WHILE, &parse_while}, {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},
}; };
int ft_parse(t_list **list_ast, t_btree **ast, t_list **start) int ft_parse(t_btree **ast, t_list **start)
{ {
t_list *lst; t_list *lst;
t_astnode item; t_astnode item;
@ -48,14 +45,12 @@ int ft_parse(t_list **list_ast, t_btree **ast, t_list **start)
*ast = btree_create_node(&item, sizeof(item)); *ast = btree_create_node(&item, sizeof(item));
((t_astnode *)(*ast)->item)->data.token = NULL; ((t_astnode *)(*ast)->item)->data.token = NULL;
} }
if (!*list_ast)
*list_ast = ft_lstnew(ast, sizeof(t_btree *));
while (g_parser[i].type) while (g_parser[i].type)
{ {
if ((lst = ft_lst_find(*start, &g_parser[i].type, &token_cmp_type))) if ((lst = ft_lst_find(*start, &g_parser[i].type, &token_cmp_type)))
{ {
if (g_parser[i].f) if (g_parser[i].f)
(*g_parser[i].f)(list_ast, ast, start, &lst); (*g_parser[i].f)(ast, start, &lst);
return (0); return (0);
} }
i++; i++;

View file

@ -1,28 +1,25 @@
/* ************************************************************************** */ /* ************************************************************************** */
/* */ /* */
/* ::: :::::::: */ /* ::: :::::::: */
/* lexer_loop.c :+: :+: :+: */ /* get_instruction.c :+: :+: :+: */
/* +:+ +:+ +:+ */ /* +:+ +:+ +:+ */
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */ /* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2017/01/25 21:58:12 by ariard #+# #+# */ /* Created: 2017/02/03 16:56:55 by ariard #+# #+# */
/* Updated: 2017/02/03 15:14:06 by ariard ### ########.fr */ /* Updated: 2017/02/03 17:16:53 by ariard ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
#include "lexer.h" #include "parser.h"
int lexer_while(t_list **alst, char *str) int get_instruction(t_btree **ast, t_list **start, t_list **lst)
{ {
t_token *token; t_token *token;
token = (*alst)->content; token = (*lst)->content;
if (ft_strncmp(str, "while", 5) == 0) if (token->type == TK_NEWLINE)
token->type = TK_WHILE; return (parse_newline(ast, start, lst));
else if (ft_isalnum(*str)) else if (token->type == TK_WHILE)
{ return (parse_while(ast, start, lst));
token_append(token, *str, 0); return (0);
return (ft_tokenize(alst, str + 1, WORD));
}
return (ft_tokenize(&(*alst)->next, str + 6, LIST));
} }

View file

@ -6,14 +6,13 @@
/* 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/26 19:56:38 by ariard ### ########.fr */ /* Updated: 2017/02/03 16:35:32 by ariard ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
#include "parser.h" #include "parser.h"
int parse_dgreat(t_list **list_ast, t_btree **ast, int parse_dgreat(t_btree **ast, t_list **start, t_list **lst)
t_list **start, t_list **lst)
{ {
t_astnode *node; t_astnode *node;
t_token *tok; t_token *tok;
@ -31,6 +30,6 @@ int parse_dgreat(t_list **list_ast, t_btree **ast,
node->data.redir.word.word = ft_strdup(next_tok->data); node->data.redir.word.word = ft_strdup(next_tok->data);
ft_lst_delif(start, (*lst)->content, &ft_addrcmp, &token_free); ft_lst_delif(start, (*lst)->content, &ft_addrcmp, &token_free);
ft_lst_delif(start, (*lst)->next->content, &ft_addrcmp, &token_free); ft_lst_delif(start, (*lst)->next->content, &ft_addrcmp, &token_free);
ft_parse(list_ast, &(*ast)->left, start); ft_parse(&(*ast)->left, start);
return (0); return (0);
} }

View file

@ -6,14 +6,13 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */ /* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2016/12/03 13:31:40 by jhalford #+# #+# */ /* Created: 2016/12/03 13:31:40 by jhalford #+# #+# */
/* Updated: 2017/01/26 19:53:00 by ariard ### ########.fr */ /* Updated: 2017/02/03 16:43:10 by ariard ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
#include "parser.h" #include "parser.h"
int parse_dless(t_list **list_ast, t_btree **ast, int parse_dless(t_btree **ast, t_list **start, t_list **lst)
t_list **start, t_list **lst)
{ {
t_astnode *node; t_astnode *node;
t_token *tok; t_token *tok;
@ -30,6 +29,6 @@ int parse_dless(t_list **list_ast, t_btree **ast,
node->data.redir.word.word = ft_strdup(next_tok->data); node->data.redir.word.word = ft_strdup(next_tok->data);
ft_lst_delif(start, (*lst)->content, &ft_addrcmp, &token_free); ft_lst_delif(start, (*lst)->content, &ft_addrcmp, &token_free);
ft_lst_delif(start, (*lst)->next->content, &ft_addrcmp, &token_free); ft_lst_delif(start, (*lst)->next->content, &ft_addrcmp, &token_free);
ft_parse(list_ast, &(*ast)->left, start); ft_parse(&(*ast)->left, start);
return (0); return (0);
} }

View file

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

View file

@ -6,14 +6,13 @@
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */ /* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2017/01/30 16:36:28 by ariard #+# #+# */ /* Created: 2017/01/30 16:36:28 by ariard #+# #+# */
/* Updated: 2017/02/02 16:44:47 by ariard ### ########.fr */ /* Updated: 2017/02/03 16:47:12 by ariard ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
#include "parser.h" #include "parser.h"
int parse_done(t_list **list_ast, t_btree **ast, int parse_done(t_btree **ast, t_list **start, t_list **lst)
t_list **start, t_list **lst)
{ {
t_astnode *node; t_astnode *node;
t_token *token; t_token *token;
@ -22,6 +21,6 @@ int parse_done(t_list **list_ast, t_btree **ast,
node = (*ast)->item; node = (*ast)->item;
node->type = TK_DONE; node->type = TK_DONE;
ft_lst_delif(start, (*lst)->content, &ft_addrcmp, &token_free); ft_lst_delif(start, (*lst)->content, &ft_addrcmp, &token_free);
ft_parse(list_ast, ast, start); ft_parse(ast, start);
return (0); return (0);
} }

View file

@ -6,14 +6,13 @@
/* 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/26 19:51:06 by ariard ### ########.fr */ /* Updated: 2017/02/03 16:42:45 by ariard ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
#include "parser.h" #include "parser.h"
int parse_great(t_list **list_ast, t_btree **ast, int parse_great(t_btree **ast, t_list **start, t_list **lst)
t_list **start, t_list **lst)
{ {
t_astnode *node; t_astnode *node;
t_token *tok; t_token *tok;
@ -31,6 +30,6 @@ int parse_great(t_list **list_ast, t_btree **ast,
node->data.redir.word.word = ft_strdup(next_tok->data); node->data.redir.word.word = ft_strdup(next_tok->data);
ft_lst_delif(start, (*lst)->content, &ft_addrcmp, &token_free); ft_lst_delif(start, (*lst)->content, &ft_addrcmp, &token_free);
ft_lst_delif(start, (*lst)->next->content, &ft_addrcmp, &token_free); ft_lst_delif(start, (*lst)->next->content, &ft_addrcmp, &token_free);
ft_parse(list_ast, &(*ast)->left, start); ft_parse(&(*ast)->left, start);
return (0); return (0);
} }

View file

@ -6,14 +6,13 @@
/* 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/26 20:39:51 by ariard ### ########.fr */ /* Updated: 2017/02/03 16:44:39 by ariard ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
#include "parser.h" #include "parser.h"
int parse_greatand(t_list **list_ast, t_btree **ast, int parse_greatand(t_btree **ast, t_list **start, t_list **lst)
t_list **start, t_list **lst)
{ {
t_astnode *node; t_astnode *node;
t_token *tok; t_token *tok;
@ -27,6 +26,6 @@ int parse_greatand(t_list **list_ast, t_btree **ast,
node->data.redir.close = node->data.redir.close =
tok->data[ft_strlen(tok->data) - 1] == '-' ? 1 : 0; tok->data[ft_strlen(tok->data) - 1] == '-' ? 1 : 0;
ft_lst_delif(start, (*lst)->content, &ft_addrcmp, &token_free); ft_lst_delif(start, (*lst)->content, &ft_addrcmp, &token_free);
ft_parse(list_ast, &(*ast)->left, start); ft_parse(&(*ast)->left, start);
return (0); return (0);
} }

View file

@ -6,14 +6,13 @@
/* 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/26 19:49:18 by ariard ### ########.fr */ /* Updated: 2017/02/03 17:39:34 by ariard ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
#include "parser.h" #include "parser.h"
int parse_less(t_list **list_ast, t_btree **ast, int parse_less(t_btree **ast, t_list **start, t_list **lst)
t_list **start, t_list **lst)
{ {
t_astnode *node; t_astnode *node;
t_token *tok; t_token *tok;
@ -31,6 +30,6 @@ int parse_less(t_list **list_ast, t_btree **ast,
node->data.redir.word.word = ft_strdup(next_tok->data); node->data.redir.word.word = ft_strdup(next_tok->data);
ft_lst_delif(start, (*lst)->content, &ft_addrcmp, &token_free); ft_lst_delif(start, (*lst)->content, &ft_addrcmp, &token_free);
ft_lst_delif(start, (*lst)->next->content, &ft_addrcmp, &token_free); ft_lst_delif(start, (*lst)->next->content, &ft_addrcmp, &token_free);
ft_parse(list_ast, &(*ast)->left, start); ft_parse(&(*ast)->left, start);
return (0); return (0);
} }

View file

@ -6,14 +6,13 @@
/* 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/26 19:55:51 by ariard ### ########.fr */ /* Updated: 2017/02/03 16:44:09 by ariard ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
#include "parser.h" #include "parser.h"
int parse_lessand(t_list **list_ast, t_btree **ast, int parse_lessand(t_btree **ast, t_list **start, t_list **lst)
t_list **start, t_list **lst)
{ {
t_astnode *node; t_astnode *node;
t_token *tok; t_token *tok;
@ -27,6 +26,6 @@ int parse_lessand(t_list **list_ast, t_btree **ast,
node->data.redir.close = node->data.redir.close =
tok->data[ft_strlen(tok->data) - 1] == '-' ? 1 : 0; tok->data[ft_strlen(tok->data) - 1] == '-' ? 1 : 0;
ft_lst_delif(start, (*lst)->content, &ft_addrcmp, &token_free); ft_lst_delif(start, (*lst)->content, &ft_addrcmp, &token_free);
ft_parse(list_ast, &(*ast)->left, start); ft_parse(&(*ast)->left, start);
return (0); return (0);
} }

View file

@ -6,19 +6,17 @@
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */ /* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2017/01/30 16:34:21 by ariard #+# #+# */ /* Created: 2017/01/30 16:34:21 by ariard #+# #+# */
/* Updated: 2017/01/31 20:20:13 by ariard ### ########.fr */ /* Updated: 2017/02/03 16:51:39 by ariard ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
#include "parser.h" #include "parser.h"
int parse_list(t_list **list_ast, t_btree **ast, int parse_list(t_btree **ast, t_list **start, t_list **lst)
t_list **start, t_list **lst)
{ {
t_astnode *node; t_astnode *node;
t_token *token; t_token *token;
(void)list_ast;
token = (*lst)->content; token = (*lst)->content;
node = (*ast)->item; node = (*ast)->item;
node->type = TK_LIST; node->type = TK_LIST;

View file

@ -6,14 +6,13 @@
/* 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/31 19:35:54 by ariard ### ########.fr */ /* Updated: 2017/02/03 17:16:47 by ariard ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
#include "parser.h" #include "parser.h"
int parse_newline(t_list **list_ast, t_btree **ast, int parse_newline(t_btree **ast, t_list **start, t_list **lst)
t_list **start, t_list **lst)
{ {
t_list *temp; t_list *temp;
t_astnode *node; t_astnode *node;
@ -25,8 +24,7 @@ int parse_newline(t_list **list_ast, t_btree **ast,
temp = (*lst)->next; temp = (*lst)->next;
(*lst)->next = NULL; (*lst)->next = NULL;
ft_lst_delif(start, (*lst)->content, &ft_addrcmp, &token_free); ft_lst_delif(start, (*lst)->content, &ft_addrcmp, &token_free);
ft_parse(list_ast, ast, start); ft_parse(ast, start);
*ast = NULL; *start = temp;
ft_parse(&(*list_ast)->next, ast, &temp);
return (0); return (0);
} }

View file

@ -6,14 +6,13 @@
/* 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/30 20:25:22 by ariard ### ########.fr */ /* Updated: 2017/02/03 17:29:32 by ariard ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
#include "parser.h" #include "parser.h"
int parse_separator(t_list **list_ast, t_btree **ast, int parse_separator(t_btree **ast, t_list **start, t_list **lst)
t_list **start, t_list **lst)
{ {
t_token *token; t_token *token;
t_astnode *node; t_astnode *node;
@ -21,8 +20,8 @@ int parse_separator(t_list **list_ast, t_btree **ast,
token = (*lst)->content; token = (*lst)->content;
node = (*ast)->item; node = (*ast)->item;
node->type = token->type; node->type = token->type;
ft_parse(list_ast, &(*ast)->right, &(*lst)->next); ft_parse(&(*ast)->right, &(*lst)->next);
ft_lst_delif(start, (*lst)->content, &ft_addrcmp, &token_free); ft_lst_delif(start, (*lst)->content, &ft_addrcmp, &token_free);
ft_parse(list_ast, &(*ast)->left, start); ft_parse(&(*ast)->left, start);
return (0); return (0);
} }

View file

@ -6,14 +6,13 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */ /* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2017/01/11 16:52:44 by jhalford #+# #+# */ /* Created: 2017/01/11 16:52:44 by jhalford #+# #+# */
/* Updated: 2017/02/03 14:30:42 by ariard ### ########.fr */ /* Updated: 2017/02/03 16:45:35 by ariard ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
#include "parser.h" #include "parser.h"
int parse_subshell(t_list **list_ast, t_btree **ast, int parse_subshell(t_btree **ast, t_list **start, t_list **lst)
t_list **start, t_list **lst)
{ {
t_astnode *node; t_astnode *node;
t_token *token; t_token *token;
@ -27,7 +26,7 @@ int parse_subshell(t_list **list_ast, t_btree **ast,
node->data.sstr[1] = ft_strdup("-c"); node->data.sstr[1] = ft_strdup("-c");
node->data.sstr[2] = ft_strdup(token->data); node->data.sstr[2] = ft_strdup(token->data);
node->data.sstr[3] = NULL; node->data.sstr[3] = NULL;
ft_parse(list_ast, ast, &(*lst)->next); ft_parse(ast, &(*lst)->next);
ft_lst_delif(start, (*lst)->content, &ft_addrcmp, &token_free); ft_lst_delif(start, (*lst)->content, &ft_addrcmp, &token_free);
return (0); return (0);
} }

View file

@ -6,23 +6,52 @@
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */ /* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2017/01/30 16:03:28 by ariard #+# #+# */ /* Created: 2017/01/30 16:03:28 by ariard #+# #+# */
/* Updated: 2017/02/02 16:30:35 by ariard ### ########.fr */ /* Updated: 2017/02/03 19:48:36 by ariard ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
#include "parser.h" #include "parser.h"
int parse_while(t_list **list_ast, t_btree **ast, int parse_while(t_btree **ast, t_list **start, t_list **lst)
t_list **start, t_list **lst)
{ {
t_list *temp;
t_astnode *node; t_astnode *node;
t_token *token; t_token *token;
int nest;
token = (*lst)->content; token = (*lst)->content;
node = (*ast)->item; node = (*ast)->item;
node->type = TK_WHILE; node->type = TK_WHILE;
ft_lst_delif(start, (*lst)->content, &ft_addrcmp, &token_free); ft_lst_delif(start, (*lst)->content, &ft_addrcmp, &token_free);
ft_parse(list_ast, &(*ast)->left, start); while (((*lst) = (*lst)->next))
ft_parse(list_ast, &(*ast)->right, start); if ((token = (*lst)->content)->type & TK_DO)
return (0); break;
temp = (*lst)->next;
(*lst)->next = NULL;
ft_lst_delif(start, (*lst)->content, &ft_addrcmp, &token_free);
ft_parse(&(*ast)->left, start);
(*lst) = temp;
ft_lst_delif(start, (*lst)->content, &ft_addrcmp, &token_free);
temp = temp->next;
(*lst) = temp;
*start = temp;
nest = 1;
while (((*lst) = (*lst)->next))
{
token = (*lst)->content;
if (token->type & TK_DO)
nest++;
else if (token->type & TK_DONE)
nest--;
if (nest == 0)
break;
DG("nest : '%d'", nest);
}
temp = (*lst)->next;
(*lst)->next = NULL;
ft_lst_delif(start, (*lst)->content, &ft_addrcmp, &token_free);
ft_parse(&(*ast)->right, start);
*start = temp;
return (0);
} }

View file

@ -6,21 +6,18 @@
/* 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/02/03 14:52:09 by ariard ### ########.fr */ /* Updated: 2017/02/03 19:37:29 by ariard ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
#include "parser.h" #include "parser.h"
int parse_word(t_list **list_ast, t_btree **ast, int parse_word(t_btree **ast, t_list **start, t_list **lst)
t_list **start, t_list **lst)
{ {
t_astnode *node; t_astnode *node;
t_token *token; t_token *token;
char **my_tab; char **my_tab;
(void)list_ast;
(void)start;
my_tab = NULL; my_tab = NULL;
token = (*lst)->content; token = (*lst)->content;
node = (*ast)->item; node = (*ast)->item;
@ -28,7 +25,7 @@ int parse_word(t_list **list_ast, t_btree **ast,
my_tab = ft_sstradd(my_tab, token->data); my_tab = ft_sstradd(my_tab, token->data);
my_tab = ft_sstradd(my_tab, (char *)token->esc); my_tab = ft_sstradd(my_tab, (char *)token->esc);
ft_ld_pushback(&node->data.token, my_tab); ft_ld_pushback(&node->data.token, my_tab);
// ft_parse(ast, &(*lst)->next); ft_parse(ast, &(*lst)->next);
ft_lst_delif(start, (*lst)->content, &ft_addrcmp, &token_free); ft_lst_delif(start, (*lst)->content, &ft_addrcmp, &token_free);
return (0); return (0);
} }