doing, parsing newline et generation liste chaine d arbre binaire

This commit is contained in:
ariard@student.42.fr 2017-01-26 22:43:47 +01:00
parent 91ac485169
commit 47a2fdd683
30 changed files with 143 additions and 134 deletions

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/12/01 12:15:50 by jhalford #+# #+# */
/* Updated: 2017/01/26 00:57:09 by ariard ### ########.fr */
/* Updated: 2017/01/26 21:29:07 by ariard ### ########.fr */
/* */
/* ************************************************************************** */

View file

@ -6,7 +6,7 @@
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/11/10 13:07:44 by jhalford #+# #+# */
/* Updated: 2017/01/24 20:04:55 by ariard ### ########.fr */
/* Updated: 2017/01/26 20:57:21 by ariard ### ########.fr */
/* */
/* ************************************************************************** */
@ -50,8 +50,7 @@ struct s_comp
struct s_script
{
char *buffer;
int q_size;
t_list *queue;
int size;
};
typedef struct s_script t_script;

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/12/01 12:15:54 by jhalford #+# #+# */
/* Updated: 2017/01/24 20:08:01 by ariard ### ########.fr */
/* Updated: 2017/01/26 20:57:12 by ariard ### ########.fr */
/* */
/* ************************************************************************** */
@ -25,7 +25,8 @@ typedef long long t_type;
struct s_parser
{
t_type type;
int (*f)(t_btree **ast, t_list **start, t_list **token);
int (*f)(t_list **list_ast, t_btree **ast,
t_list **start, t_list **token);
};
union u_word
@ -56,16 +57,28 @@ struct s_astnode
extern t_parser g_parser[];
int ft_parse(t_btree **ast, t_list **token);
int parse_separator(t_btree **ast, t_list **start, t_list **lst);
int parse_less(t_btree **ast, t_list **start, t_list **lst);
int parse_great(t_btree **ast, t_list **start, t_list **lst);
int parse_dless(t_btree **ast, t_list **start, t_list **lst);
int parse_dgreat(t_btree **ast, t_list **start, t_list **lst);
int parse_lessand(t_btree **ast, t_list **start, t_list **lst);
int parse_greatand(t_btree **ast, t_list **start, t_list **lst);
int parse_word(t_btree **ast, t_list **start, t_list **lst);
int parse_subshell(t_btree **ast, t_list **start, t_list **lst);
int parse_newline(t_btree **ast, t_list **start, t_list **lst);
int ft_parse(t_list **list_ast, t_btree **ast, t_list **token);
int parse_newline(t_list **list_ast, t_btree **ast,
t_list **start, t_list **lst);
int parse_separator(t_list **list_ast, t_btree **ast,
t_list **start, t_list **lst);
int parse_less(t_list **list_ast, t_btree **ast,
t_list **start, t_list **lst);
int parse_great(t_list **list_ast, t_btree **ast,
t_list **start, t_list **lst);
int parse_dless(t_list **list_ast, t_btree **ast,
t_list **start, t_list **lst);
int parse_dgreat(t_list **list_ast, t_btree **ast,
t_list **start, t_list **lst);
int parse_lessand(t_list **list_ast, t_btree **ast,
t_list **start, t_list **lst);
int parse_greatand(t_list **list_ast, t_btree **ast,
t_list **start, t_list **lst);
int parse_word(t_list **list_ast, t_btree **ast,
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);
#endif

View file

@ -1,2 +1,2 @@
ls | wc -l > file1 ; cd
pwd ; echo "hello world"
ls | cat
pwd | cat

View file

@ -1,11 +1,9 @@
#!/bin/bash
echo "debut script"
do
while [ 1 ] ; [ 1 ]
do
while [ 1 ]
do
sleep 1
echo "a"
done

View file

@ -6,7 +6,7 @@
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/11/10 13:37:11 by jhalford #+# #+# */
/* Updated: 2017/01/26 00:56:23 by ariard ### ########.fr */
/* Updated: 2017/01/26 22:27:16 by ariard ### ########.fr */
/* */
/* ************************************************************************** */

View file

@ -6,7 +6,7 @@
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/01/26 00:07:05 by ariard #+# #+# */
/* Updated: 2017/01/26 00:51:26 by ariard ### ########.fr */
/* Updated: 2017/01/26 18:47:52 by ariard ### ########.fr */
/* */
/* ************************************************************************** */

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/11/28 18:36:21 by jhalford #+# #+# */
/* Updated: 2017/01/25 23:01:37 by ariard ### ########.fr */
/* Updated: 2017/01/26 18:16:02 by ariard ### ########.fr */
/* */
/* ************************************************************************** */
@ -30,7 +30,6 @@ int lexer_default(t_list **alst, char *str)
else
state = WORD;
token = (*alst)->content;
token_append(token, *str);
token->type = TK_N_WORD;
return (ft_tokenize(alst, str + 1, state));
return (ft_tokenize(alst, str, state));
}

View file

@ -6,7 +6,7 @@
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/01/26 00:48:48 by ariard #+# #+# */
/* Updated: 2017/01/26 00:59:00 by ariard ### ########.fr */
/* Updated: 2017/01/26 18:49:32 by ariard ### ########.fr */
/* */
/* ************************************************************************** */
@ -16,13 +16,13 @@ int lexer_do_group(t_list **alst, char *str)
{
t_token *token;
t_lexstate state;
int type;
int type;
type = (str[0] == 'd' && str[1] == 'o' && str[2] != 'n' ?
2 : 4);
if (*alst)
{
if (ft_is_delim_list(*(str + type)) || *(str + type) == ' ')
if (ft_is_delim_list(*(str + type)) || *(str + type) == ' ')
return (lexer_do_group(&(*alst)->next, str));
return (ft_tokenize(alst, str + 1, LIST));
}
@ -34,5 +34,5 @@ int lexer_do_group(t_list **alst, char *str)
token = (*alst)->content;
token->type = (type == 2 ? TK_DO : TK_DONE);
state = (token->type == TK_DO) ? LIST : DEFAULT;
return (ft_tokenize(&(*alst)->next, str + 1, state));
return (ft_tokenize(&(*alst)->next, str + type, state));
}

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/12/03 12:06:53 by jhalford #+# #+# */
/* Updated: 2017/01/24 00:45:30 by ariard ### ########.fr */
/* Updated: 2017/01/26 18:26:28 by ariard ### ########.fr */
/* */
/* ************************************************************************** */

View file

@ -6,7 +6,7 @@
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/01/26 00:55:33 by ariard #+# #+# */
/* Updated: 2017/01/26 00:58:58 by ariard ### ########.fr */
/* Updated: 2017/01/26 19:24:50 by ariard ### ########.fr */
/* */
/* ************************************************************************** */
@ -22,6 +22,7 @@ int lexer_list(t_list **alst, char *str)
{
if (ft_is_delim_list(*str))
{
str++;
while (ft_is_delim(*str) || *str == '\n')
str++;
if (ft_strncmp(str, "done", 4) == 0

View file

@ -6,7 +6,7 @@
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/01/25 21:58:12 by ariard #+# #+# */
/* Updated: 2017/01/26 00:58:57 by ariard ### ########.fr */
/* Updated: 2017/01/26 18:09:46 by ariard ### ########.fr */
/* */
/* ************************************************************************** */

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/12/03 12:07:11 by jhalford #+# #+# */
/* Updated: 2017/01/26 00:58:55 by ariard ### ########.fr */
/* Updated: 2017/01/26 18:25:53 by ariard ### ########.fr */
/* */
/* ************************************************************************** */

View file

@ -6,7 +6,7 @@
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/11/11 17:18:42 by jhalford #+# #+# */
/* Updated: 2017/01/24 00:30:33 by ariard ### ########.fr */
/* Updated: 2017/01/26 18:07:02 by ariard ### ########.fr */
/* */
/* ************************************************************************** */

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/12/03 12:07:30 by jhalford #+# #+# */
/* Updated: 2017/01/12 13:18:46 by jhalford ### ########.fr */
/* Updated: 2017/01/26 22:25:08 by ariard ### ########.fr */
/* */
/* ************************************************************************** */

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/12/06 18:40:58 by jhalford #+# #+# */
/* Updated: 2017/01/25 16:25:43 by ariard ### ########.fr */
/* Updated: 2017/01/26 21:08:49 by ariard ### ########.fr */
/* */
/* ************************************************************************** */
@ -30,8 +30,9 @@ int shell_single_command(char *command)
return (1);
DG("after post_tokenize");
token_print(token);
if (ft_parse(&ast, &token))
return (1);
return (0);
// if (ft_parse(&ast, &token))
// return (1);
btree_print(STDBUG, ast, &ft_putast);
/* /1* ft_dprintf(STDBUG, "\n--- INFIX BREAKDOWN ---\n"); *1/ */
/* /1* btree_apply_infix(ast, &ft_putast2); *1/ */

View file

@ -6,7 +6,7 @@
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/01/21 22:49:31 by ariard #+# #+# */
/* Updated: 2017/01/24 18:50:55 by ariard ### ########.fr */
/* Updated: 2017/01/26 17:52:25 by ariard ### ########.fr */
/* */
/* ************************************************************************** */
@ -15,19 +15,20 @@
static int rs_loop(char *file, t_script *script)
{
int fd;
char *line;
line = NULL;
if ((fd = open(file, O_RDONLY)) == -1)
return (0);
while (get_next_line(fd, &script->buffer) > 0)
while (get_next_line(fd, &line) > 0)
{
ft_lsteadd(&script->queue,
ft_lstnew(script->buffer, ft_strlen(script->buffer)));
ft_strdel(&script->buffer);
ft_lsteadd(&script->queue, ft_lstnew(ft_strdup("\n"), 1));
script->q_size += 2;
ft_strappend(&script->buffer, line);
ft_strappend(&script->buffer, "\n");
ft_strdel(&line);
script->size += ft_strlen(script->buffer);
}
close(fd);
if (script->q_size > 0)
if (script->size > 0)
{
data_singleton()->opts &= ~SHELL_MODE_MASK;
data_singleton()->opts |= SHELL_MODE_SCRIPT;
@ -39,8 +40,7 @@ static int rs_setup(t_script *script)
{
ft_bzero(script, sizeof(script));
script->buffer = NULL;
script->q_size = 0;
script->queue = NULL;
script->size = 0;
return (0);
}
@ -55,7 +55,6 @@ int read_script(char *file)
return (-1);
if (rs_loop(file, script) < 0)
return (-1);
script->buffer = NULL;
DG("{inv}{bol}{gre}read of script{eoc} script detected");
return (1);
}

View file

@ -6,7 +6,7 @@
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/01/22 23:06:34 by ariard #+# #+# */
/* Updated: 2017/01/25 22:54:03 by ariard ### ########.fr */
/* Updated: 2017/01/26 22:42:07 by ariard ### ########.fr */
/* */
/* ************************************************************************** */
@ -15,51 +15,36 @@
int shell_script()
{
t_list *token;
t_list *head;
t_btree *ast;
t_list *list_tmp;
t_list *list_ast;
t_list *tmp2;
token = NULL;
head = NULL;
ast = NULL;
list_tmp = data_singleton()->script.queue;
while (list_tmp)
{
if (ft_tokenize(&token, list_tmp->content , DEFAULT))
return (1);
if (!token && !list_tmp->next)
return (0);
if (ft_post_tokenize(&token, list_tmp->content))
return (1);
list_tmp = list_tmp->next;
ft_lst_merge(&head, token);
token = NULL;
}
list_ast = NULL;
if (ft_tokenize(&token, data_singleton()->script.buffer , DEFAULT))
return (1);
if (!token)
return (0);
if (ft_post_tokenize(&token, data_singleton()->script.buffer))
return (1);
DG("after post_tokenize");
token_print(head);
list_tmp = NULL;
return (0);
while (head)
{
if (ft_parse(&ast, &head))
return (1);
ft_lsteadd(&list_tmp, ft_lstnew(ast, sizeof(*ast)));
ast = NULL;
ft_lst_delif(&head, head->content, &ft_addrcmp, &token_free);
}
tmp2 = list_tmp;
token_print(token);
if (ft_parse(&list_ast, &ast, &token))
return (1);
tmp2 = list_ast;
while (tmp2)
{
{
btree_print(STDBUG, tmp2->content, &ft_putast);
tmp2 = tmp2->next;
}
while (list_tmp)
return (0);
while (list_ast)
{
ast = list_tmp->content;
ast = list_ast->content;
if (ft_exec(&ast))
return (1);
list_tmp = list_tmp->next;
list_ast = list_ast->next;
}
return (0);
}

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/11/30 17:14:58 by jhalford #+# #+# */
/* Updated: 2017/01/24 20:12:50 by ariard ### ########.fr */
/* Updated: 2017/01/26 22:42:09 by ariard ### ########.fr */
/* */
/* ************************************************************************** */
@ -14,6 +14,7 @@
t_parser g_parser[] =
{
{TK_NEWLINE, &parse_newline},
{TK_SEMI, &parse_separator},
{TK_AND_IF | TK_OR_IF, &parse_separator},
{TK_AMP, &parse_separator},
@ -26,11 +27,10 @@ t_parser g_parser[] =
{TK_GREATAND, &parse_greatand},
{TK_SUBSHELL, &parse_subshell},
{TK_WORD, &parse_word},
{TK_NEWLINE, NULL},
{0, 0},
};
int ft_parse(t_btree **ast, t_list **start)
int ft_parse(t_list **list_ast, t_btree **ast, t_list **start)
{
t_list *lst;
t_astnode item;
@ -44,13 +44,14 @@ int ft_parse(t_btree **ast, t_list **start)
*ast = btree_create_node(&item, sizeof(item));
((t_astnode *)(*ast)->item)->data.sstr = NULL;
}
// if (!*list_ast)
// ft_lsteadd(list_ast, ft_lstnew(ast, sizeof(*ast)));
while (g_parser[i].type)
{
if ((lst = ft_lst_find_until(*start, &g_parser[i].type,
&g_parser[12].type, &token_cmp_type)))
if ((lst = ft_lst_find(*start, &g_parser[i].type, &token_cmp_type)))
{
if (g_parser[i].f)
(*g_parser[i].f)(ast, start, &lst);
(*g_parser[i].f)(list_ast, ast, start, &lst);
return (0);
}
i++;

View file

@ -6,13 +6,14 @@
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/11/14 12:49:45 by jhalford #+# #+# */
/* Updated: 2017/01/20 16:23:07 by ariard ### ########.fr */
/* Updated: 2017/01/26 19:56:38 by ariard ### ########.fr */
/* */
/* ************************************************************************** */
#include "parser.h"
int parse_dgreat(t_btree **ast, t_list **start, t_list **lst)
int parse_dgreat(t_list **list_ast, t_btree **ast,
t_list **start, t_list **lst)
{
t_astnode *node;
t_token *tok;
@ -30,6 +31,6 @@ int parse_dgreat(t_btree **ast, t_list **start, t_list **lst)
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)->next->content, &ft_addrcmp, &token_free);
ft_parse(&(*ast)->left, start);
ft_parse(list_ast, &(*ast)->left, start);
return (0);
}

View file

@ -6,13 +6,14 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/12/03 13:31:40 by jhalford #+# #+# */
/* Updated: 2017/01/20 16:23:17 by ariard ### ########.fr */
/* Updated: 2017/01/26 19:53:00 by ariard ### ########.fr */
/* */
/* ************************************************************************** */
#include "parser.h"
int parse_dless(t_btree **ast, t_list **start, t_list **lst)
int parse_dless(t_list **list_ast, t_btree **ast,
t_list **start, t_list **lst)
{
t_astnode *node;
t_token *tok;
@ -29,6 +30,6 @@ int parse_dless(t_btree **ast, t_list **start, t_list **lst)
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)->next->content, &ft_addrcmp, &token_free);
ft_parse(&(*ast)->left, start);
ft_parse(list_ast, &(*ast)->left, start);
return (0);
}

View file

@ -6,13 +6,14 @@
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/11/14 12:49:45 by jhalford #+# #+# */
/* Updated: 2017/01/24 16:06:00 by ariard ### ########.fr */
/* Updated: 2017/01/26 19:51:06 by ariard ### ########.fr */
/* */
/* ************************************************************************** */
#include "parser.h"
int parse_great(t_btree **ast, t_list **start, t_list **lst)
int parse_great(t_list **list_ast, t_btree **ast,
t_list **start, t_list **lst)
{
t_astnode *node;
t_token *tok;
@ -30,6 +31,6 @@ int parse_great(t_btree **ast, t_list **start, t_list **lst)
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)->next->content, &ft_addrcmp, &token_free);
ft_parse(&(*ast)->left, start);
ft_parse(list_ast, &(*ast)->left, start);
return (0);
}

View file

@ -6,13 +6,14 @@
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/11/14 12:49:45 by jhalford #+# #+# */
/* Updated: 2017/01/20 16:24:04 by ariard ### ########.fr */
/* Updated: 2017/01/26 20:39:51 by ariard ### ########.fr */
/* */
/* ************************************************************************** */
#include "parser.h"
int parse_greatand(t_btree **ast, t_list **start, t_list **lst)
int parse_greatand(t_list **list_ast, t_btree **ast,
t_list **start, t_list **lst)
{
t_astnode *node;
t_token *tok;
@ -26,6 +27,6 @@ int parse_greatand(t_btree **ast, t_list **start, t_list **lst)
node->data.redir.close =
tok->data[ft_strlen(tok->data) - 1] == '-' ? 1 : 0;
ft_lst_delif(start, (*lst)->content, &ft_addrcmp, &token_free);
ft_parse(&(*ast)->left, start);
ft_parse(list_ast, &(*ast)->left, start);
return (0);
}

View file

@ -6,13 +6,14 @@
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/11/14 12:49:45 by jhalford #+# #+# */
/* Updated: 2017/01/20 16:24:11 by ariard ### ########.fr */
/* Updated: 2017/01/26 19:49:18 by ariard ### ########.fr */
/* */
/* ************************************************************************** */
#include "parser.h"
int parse_less(t_btree **ast, t_list **start, t_list **lst)
int parse_less(t_list **list_ast, t_btree **ast,
t_list **start, t_list **lst)
{
t_astnode *node;
t_token *tok;
@ -30,6 +31,6 @@ int parse_less(t_btree **ast, t_list **start, t_list **lst)
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)->next->content, &ft_addrcmp, &token_free);
ft_parse(&(*ast)->left, start);
ft_parse(list_ast, &(*ast)->left, start);
return (0);
}

View file

@ -6,13 +6,14 @@
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/11/14 12:49:45 by jhalford #+# #+# */
/* Updated: 2017/01/20 16:24:37 by ariard ### ########.fr */
/* Updated: 2017/01/26 19:55:51 by ariard ### ########.fr */
/* */
/* ************************************************************************** */
#include "parser.h"
int parse_lessand(t_btree **ast, t_list **start, t_list **lst)
int parse_lessand(t_list **list_ast, t_btree **ast,
t_list **start, t_list **lst)
{
t_astnode *node;
t_token *tok;
@ -26,6 +27,6 @@ int parse_lessand(t_btree **ast, t_list **start, t_list **lst)
node->data.redir.close =
tok->data[ft_strlen(tok->data) - 1] == '-' ? 1 : 0;
ft_lst_delif(start, (*lst)->content, &ft_addrcmp, &token_free);
ft_parse(&(*ast)->left, start);
ft_parse(list_ast, &(*ast)->left, start);
return (0);
}

View file

@ -1,28 +1,29 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* lexer_loop.c :+: :+: :+: */
/* parse_newline.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/01/25 21:58:12 by ariard #+# #+# */
/* Updated: 2017/01/26 00:58:57 by ariard ### ########.fr */
/* Created: 2017/01/26 19:26:41 by ariard #+# #+# */
/* Updated: 2017/01/26 22:39:50 by ariard ### ########.fr */
/* */
/* ************************************************************************** */
#include "lexer.h"
#include "parser.h"
int lexer_while(t_list **alst, char *str)
int parse_newline(t_list **list_ast, t_btree **ast,
t_list **start, t_list **lst)
{
t_token *token;
t_list *temp;
token = (*alst)->content;
if (ft_strncmp(str, "while", 5) == 0)
token->type = TK_WHILE;
else if (ft_isalnum(*str))
{
token_append(token, *str);
return (ft_tokenize(alst, str + 1, WORD));
}
return (ft_tokenize(&(*alst)->next, str + 6, LIST));
ft_putstr("newline");
temp = (*lst)->next;
(*lst)->next = NULL;
ft_lst_delif(start, (*lst)->content, &ft_addrcmp, &token_free);
*lst = NULL;
ft_parse(list_ast, ast, start);
*ast = NULL;
ft_parse(list_ast, ast, &temp);
return (0);
}

View file

@ -6,13 +6,14 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/11/28 16:21:51 by jhalford #+# #+# */
/* Updated: 2017/01/25 16:35:50 by ariard ### ########.fr */
/* Updated: 2017/01/26 22:42:17 by ariard ### ########.fr */
/* */
/* ************************************************************************** */
#include "parser.h"
int parse_separator(t_btree **ast, t_list **start, t_list **lst)
int parse_separator(t_list **list_ast, t_btree **ast,
t_list **start, t_list **lst)
{
t_token *token;
t_astnode *node;
@ -20,8 +21,8 @@ int parse_separator(t_btree **ast, t_list **start, t_list **lst)
token = (*lst)->content;
node = (*ast)->item;
node->type = token->type;
ft_parse(&(*ast)->right, &(*lst)->next);
ft_parse(list_ast, &(*ast)->right, &(*lst)->next);
ft_lst_delif(start, (*lst)->content, &ft_addrcmp, &token_free);
ft_parse(&(*ast)->left, start);
ft_parse(list_ast, &(*ast)->left, start);
return (0);
}

View file

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

View file

@ -6,23 +6,26 @@
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/11/14 12:49:45 by jhalford #+# #+# */
/* Updated: 2017/01/24 17:54:40 by ariard ### ########.fr */
/* Updated: 2017/01/26 22:37:26 by ariard ### ########.fr */
/* */
/* ************************************************************************** */
#include "parser.h"
int parse_word(t_btree **ast, t_list **start, t_list **lst)
int parse_word(t_list **list_ast, t_btree **ast,
t_list **start, t_list **lst)
{
t_astnode *node;
t_token *token;
ft_putstr("word");
(void)start;
(void)list_ast;
token = (*lst)->content;
node = (*ast)->item;
node->type = TK_COMMAND;
node->data.sstr = ft_sstradd(node->data.sstr, token->data);
ft_parse(ast, &(*lst)->next);
ft_parse(list_ast, ast, &(*lst)->next);
ft_lst_delif(start, (*lst)->content, &ft_addrcmp, &token_free);
return (0);
}

1
42sh/test Normal file
View file

@ -0,0 +1 @@
11