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> +#+ +:+ +#+ */ /* 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/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> +#+ +:+ +#+ */ /* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2016/11/10 13:07:44 by jhalford #+# #+# */ /* 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 struct s_script
{ {
char *buffer; char *buffer;
int q_size; int size;
t_list *queue;
}; };
typedef struct s_script t_script; typedef struct s_script t_script;

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/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 struct s_parser
{ {
t_type type; 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 union u_word
@ -56,16 +57,28 @@ struct s_astnode
extern t_parser g_parser[]; extern t_parser g_parser[];
int ft_parse(t_btree **ast, t_list **token); int ft_parse(t_list **list_ast, t_btree **ast, t_list **token);
int parse_separator(t_btree **ast, t_list **start, t_list **lst); int parse_newline(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_separator(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_less(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_great(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_dless(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_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 #endif

View file

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

View file

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

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/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> +#+ +:+ +#+ */ /* 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/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> +#+ +:+ +#+ */ /* 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/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 else
state = WORD; state = WORD;
token = (*alst)->content; token = (*alst)->content;
token_append(token, *str);
token->type = TK_N_WORD; 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> +#+ +:+ +#+ */ /* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2017/01/26 00:48:48 by ariard #+# #+# */ /* 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 */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -34,5 +34,5 @@ int lexer_do_group(t_list **alst, char *str)
token = (*alst)->content; token = (*alst)->content;
token->type = (type == 2 ? TK_DO : TK_DONE); token->type = (type == 2 ? TK_DO : TK_DONE);
state = (token->type == TK_DO) ? LIST : DEFAULT; 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> +#+ +:+ +#+ */ /* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2016/12/03 12:06:53 by jhalford #+# #+# */ /* 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> +#+ +:+ +#+ */ /* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2017/01/26 00:55:33 by ariard #+# #+# */ /* 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)) if (ft_is_delim_list(*str))
{ {
str++;
while (ft_is_delim(*str) || *str == '\n') while (ft_is_delim(*str) || *str == '\n')
str++; str++;
if (ft_strncmp(str, "done", 4) == 0 if (ft_strncmp(str, "done", 4) == 0

View file

@ -6,7 +6,7 @@
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */ /* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2017/01/25 21:58:12 by ariard #+# #+# */ /* 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> +#+ +:+ +#+ */ /* 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/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> +#+ +:+ +#+ */ /* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2016/11/11 17:18:42 by jhalford #+# #+# */ /* 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> +#+ +:+ +#+ */ /* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2016/12/03 12:07:30 by jhalford #+# #+# */ /* 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> +#+ +:+ +#+ */ /* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2016/12/06 18:40:58 by jhalford #+# #+# */ /* 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); return (1);
DG("after post_tokenize"); DG("after post_tokenize");
token_print(token); token_print(token);
if (ft_parse(&ast, &token)) return (0);
return (1); // if (ft_parse(&ast, &token))
// return (1);
btree_print(STDBUG, ast, &ft_putast); btree_print(STDBUG, ast, &ft_putast);
/* /1* ft_dprintf(STDBUG, "\n--- INFIX BREAKDOWN ---\n"); *1/ */ /* /1* ft_dprintf(STDBUG, "\n--- INFIX BREAKDOWN ---\n"); *1/ */
/* /1* btree_apply_infix(ast, &ft_putast2); *1/ */ /* /1* btree_apply_infix(ast, &ft_putast2); *1/ */

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/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) static int rs_loop(char *file, t_script *script)
{ {
int fd; int fd;
char *line;
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, &script->buffer) > 0) while (get_next_line(fd, &line) > 0)
{ {
ft_lsteadd(&script->queue, ft_strappend(&script->buffer, line);
ft_lstnew(script->buffer, ft_strlen(script->buffer))); ft_strappend(&script->buffer, "\n");
ft_strdel(&script->buffer); ft_strdel(&line);
ft_lsteadd(&script->queue, ft_lstnew(ft_strdup("\n"), 1)); script->size += ft_strlen(script->buffer);
script->q_size += 2;
} }
close(fd); close(fd);
if (script->q_size > 0) if (script->size > 0)
{ {
data_singleton()->opts &= ~SHELL_MODE_MASK; data_singleton()->opts &= ~SHELL_MODE_MASK;
data_singleton()->opts |= SHELL_MODE_SCRIPT; data_singleton()->opts |= SHELL_MODE_SCRIPT;
@ -39,8 +40,7 @@ static int rs_setup(t_script *script)
{ {
ft_bzero(script, sizeof(script)); ft_bzero(script, sizeof(script));
script->buffer = NULL; script->buffer = NULL;
script->q_size = 0; script->size = 0;
script->queue = NULL;
return (0); return (0);
} }
@ -55,7 +55,6 @@ int read_script(char *file)
return (-1); return (-1);
if (rs_loop(file, script) < 0) if (rs_loop(file, script) < 0)
return (-1); return (-1);
script->buffer = NULL;
DG("{inv}{bol}{gre}read of script{eoc} script detected"); DG("{inv}{bol}{gre}read of script{eoc} script detected");
return (1); return (1);
} }

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/25 22:54:03 by ariard ### ########.fr */ /* Updated: 2017/01/26 22:42:07 by ariard ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -15,51 +15,36 @@
int shell_script() int shell_script()
{ {
t_list *token; t_list *token;
t_list *head;
t_btree *ast; t_btree *ast;
t_list *list_tmp; t_list *list_ast;
t_list *tmp2; t_list *tmp2;
token = NULL; token = NULL;
head = NULL;
ast = NULL; ast = NULL;
list_tmp = data_singleton()->script.queue; list_ast = NULL;
while (list_tmp) if (ft_tokenize(&token, data_singleton()->script.buffer , DEFAULT))
{
if (ft_tokenize(&token, list_tmp->content , DEFAULT))
return (1); return (1);
if (!token && !list_tmp->next) if (!token)
return (0); return (0);
if (ft_post_tokenize(&token, list_tmp->content)) if (ft_post_tokenize(&token, data_singleton()->script.buffer))
return (1); return (1);
list_tmp = list_tmp->next;
ft_lst_merge(&head, token);
token = NULL;
}
DG("after post_tokenize"); DG("after post_tokenize");
token_print(head); token_print(token);
list_tmp = NULL; if (ft_parse(&list_ast, &ast, &token))
return (0);
while (head)
{
if (ft_parse(&ast, &head))
return (1); return (1);
ft_lsteadd(&list_tmp, ft_lstnew(ast, sizeof(*ast))); tmp2 = list_ast;
ast = NULL;
ft_lst_delif(&head, head->content, &ft_addrcmp, &token_free);
}
tmp2 = list_tmp;
while (tmp2) while (tmp2)
{ {
btree_print(STDBUG, tmp2->content, &ft_putast); btree_print(STDBUG, tmp2->content, &ft_putast);
tmp2 = tmp2->next; tmp2 = tmp2->next;
} }
while (list_tmp) return (0);
while (list_ast)
{ {
ast = list_tmp->content; ast = list_ast->content;
if (ft_exec(&ast)) if (ft_exec(&ast))
return (1); return (1);
list_tmp = list_tmp->next; list_ast = list_ast->next;
} }
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/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[] = t_parser g_parser[] =
{ {
{TK_NEWLINE, &parse_newline},
{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},
@ -26,11 +27,10 @@ t_parser g_parser[] =
{TK_GREATAND, &parse_greatand}, {TK_GREATAND, &parse_greatand},
{TK_SUBSHELL, &parse_subshell}, {TK_SUBSHELL, &parse_subshell},
{TK_WORD, &parse_word}, {TK_WORD, &parse_word},
{TK_NEWLINE, NULL},
{0, 0}, {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_list *lst;
t_astnode item; t_astnode item;
@ -44,13 +44,14 @@ int ft_parse(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.sstr = NULL; ((t_astnode *)(*ast)->item)->data.sstr = NULL;
} }
// if (!*list_ast)
// ft_lsteadd(list_ast, ft_lstnew(ast, sizeof(*ast)));
while (g_parser[i].type) while (g_parser[i].type)
{ {
if ((lst = ft_lst_find_until(*start, &g_parser[i].type, if ((lst = ft_lst_find(*start, &g_parser[i].type, &token_cmp_type)))
&g_parser[12].type, &token_cmp_type)))
{ {
if (g_parser[i].f) if (g_parser[i].f)
(*g_parser[i].f)(ast, start, &lst); (*g_parser[i].f)(list_ast, ast, start, &lst);
return (0); return (0);
} }
i++; i++;

View file

@ -6,13 +6,14 @@
/* 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/20 16:23:07 by ariard ### ########.fr */ /* Updated: 2017/01/26 19:56:38 by ariard ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
#include "parser.h" #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_astnode *node;
t_token *tok; 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); 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(&(*ast)->left, start); ft_parse(list_ast, &(*ast)->left, start);
return (0); return (0);
} }

View file

@ -6,13 +6,14 @@
/* 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/20 16:23:17 by ariard ### ########.fr */ /* Updated: 2017/01/26 19:53:00 by ariard ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
#include "parser.h" #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_astnode *node;
t_token *tok; 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); 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(&(*ast)->left, start); ft_parse(list_ast, &(*ast)->left, start);
return (0); return (0);
} }

View file

@ -6,13 +6,14 @@
/* 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/24 16:06:00 by ariard ### ########.fr */ /* Updated: 2017/01/26 19:51:06 by ariard ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
#include "parser.h" #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_astnode *node;
t_token *tok; 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); 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(&(*ast)->left, start); ft_parse(list_ast, &(*ast)->left, start);
return (0); return (0);
} }

View file

@ -6,13 +6,14 @@
/* 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/20 16:24:04 by ariard ### ########.fr */ /* Updated: 2017/01/26 20:39:51 by ariard ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
#include "parser.h" #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_astnode *node;
t_token *tok; t_token *tok;
@ -26,6 +27,6 @@ int parse_greatand(t_btree **ast, t_list **start, t_list **lst)
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(&(*ast)->left, start); ft_parse(list_ast, &(*ast)->left, start);
return (0); return (0);
} }

View file

@ -6,13 +6,14 @@
/* 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/20 16:24:11 by ariard ### ########.fr */ /* Updated: 2017/01/26 19:49:18 by ariard ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
#include "parser.h" #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_astnode *node;
t_token *tok; 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); 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(&(*ast)->left, start); ft_parse(list_ast, &(*ast)->left, start);
return (0); return (0);
} }

View file

@ -6,13 +6,14 @@
/* 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/20 16:24:37 by ariard ### ########.fr */ /* Updated: 2017/01/26 19:55:51 by ariard ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
#include "parser.h" #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_astnode *node;
t_token *tok; t_token *tok;
@ -26,6 +27,6 @@ int parse_lessand(t_btree **ast, t_list **start, t_list **lst)
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(&(*ast)->left, start); ft_parse(list_ast, &(*ast)->left, start);
return (0); return (0);
} }

View file

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

View file

@ -6,13 +6,14 @@
/* 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/25 16:35:50 by ariard ### ########.fr */ /* Updated: 2017/01/26 22:42:17 by ariard ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
#include "parser.h" #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_token *token;
t_astnode *node; t_astnode *node;
@ -20,8 +21,8 @@ int parse_separator(t_btree **ast, t_list **start, t_list **lst)
token = (*lst)->content; token = (*lst)->content;
node = (*ast)->item; node = (*ast)->item;
node->type = token->type; 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_lst_delif(start, (*lst)->content, &ft_addrcmp, &token_free);
ft_parse(&(*ast)->left, start); ft_parse(list_ast, &(*ast)->left, start);
return (0); return (0);
} }

View file

@ -6,13 +6,14 @@
/* 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/01/20 16:25:08 by ariard ### ########.fr */ /* Updated: 2017/01/26 19:59:58 by ariard ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
#include "parser.h" #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_astnode *node;
t_token *token; 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[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(ast, &(*lst)->next); ft_parse(list_ast, 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,26 @@
/* 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/24 17:54:40 by ariard ### ########.fr */ /* Updated: 2017/01/26 22:37:26 by ariard ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
#include "parser.h" #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_astnode *node;
t_token *token; t_token *token;
ft_putstr("word");
(void)start; (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;
node->data.sstr = ft_sstradd(node->data.sstr, token->data); 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); ft_lst_delif(start, (*lst)->content, &ft_addrcmp, &token_free);
return (0); return (0);
} }

1
42sh/test Normal file
View file

@ -0,0 +1 @@
11