do as a sep + multiple newline

This commit is contained in:
ariard@student.42.fr 2017-02-04 15:52:07 +01:00
parent 0a5143bd69
commit 9bbd6d7403
11 changed files with 37 additions and 49 deletions

View file

View file

@ -1,9 +0,0 @@
hello
hello
hello
hello
hello
hello
hello
hello
hello

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/12/01 12:15:50 by jhalford #+# #+# */
/* Updated: 2017/02/03 19:47:09 by ariard ### ########.fr */
/* Updated: 2017/02/04 15:05:41 by ariard ### ########.fr */
/* */
/* ************************************************************************** */
@ -55,6 +55,7 @@ typedef long long t_type;
# define TK_WORD (TK_N_WORD | TK_Q_WORD | TK_DQ_WORD)
# define TK_REDIR (0x1 | 0x2 | 0x4 | 0x8 | 0x10 | 0x20)
# define TK_NON_FREEABLE (TK_PAREN_OPEN | TK_PAREN_CLOSE | TK_BQUOTE)
# define SHELL_SEP (TK_NEWLINE | TK_AMP | TK_SEMI | TK_DO)
enum e_lexstate
{

View file

@ -1,20 +1,9 @@
while [ 1 ]
do
while pwd
do
while pwd
do while pwd
do
while ls
do
while pwd
do
echo "hello"
done
done
done
while pwd
do
while pwd
do
echo "bonjour"
echo hello
done
done
done

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/02/02 15:30:59 by jhalford #+# #+# */
/* Updated: 2017/02/03 19:40:31 by ariard ### ########.fr */
/* Updated: 2017/02/04 15:12:32 by ariard ### ########.fr */
/* */
/* ************************************************************************** */

View file

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

View file

@ -6,7 +6,7 @@
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/11/10 13:37:11 by jhalford #+# #+# */
/* Updated: 2017/02/03 19:40:50 by ariard ### ########.fr */
/* Updated: 2017/02/03 20:04:33 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/02/03 19:39:01 by ariard ### ########.fr */
/* Updated: 2017/02/04 15:27:49 by ariard ### ########.fr */
/* */
/* ************************************************************************** */
@ -15,26 +15,18 @@
int get_reserved_words(t_list **alst)
{
t_token *token;
t_token *previous_token;
t_list *temp;
int i;
temp = *alst;
i = 0;
previous_token = NULL;
while (temp)
{
token = temp->content;
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 (!previous_token || (previous_token->type & SHELL_SEP))
{
if ((temp = temp->next))
token = temp->content;
else
break;
if (token->type == TK_N_WORD)
{
{
if (ft_strncmp(token->data, "while", 5) == 0)
token->type = TK_WHILE;
else if (ft_strncmp(token->data, "done", 4) == 0)
@ -43,8 +35,8 @@ int get_reserved_words(t_list **alst)
token->type = TK_DO;
}
}
previous_token = token;
temp = temp->next;
i++;
}
return (0);
}

View file

@ -6,7 +6,7 @@
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/01/22 23:06:34 by ariard #+# #+# */
/* Updated: 2017/02/03 18:16:01 by ariard ### ########.fr */
/* Updated: 2017/02/04 15:30:00 by ariard ### ########.fr */
/* */
/* ************************************************************************** */

View file

@ -6,7 +6,7 @@
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/01/26 19:26:41 by ariard #+# #+# */
/* Updated: 2017/02/03 17:16:47 by ariard ### ########.fr */
/* Updated: 2017/02/03 20:04:40 by ariard ### ########.fr */
/* */
/* ************************************************************************** */

View file

@ -6,12 +6,28 @@
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/01/30 16:03:28 by ariard #+# #+# */
/* Updated: 2017/02/03 19:48:36 by ariard ### ########.fr */
/* Updated: 2017/02/04 15:51:24 by ariard ### ########.fr */
/* */
/* ************************************************************************** */
#include "parser.h"
static int delete_all_newline(t_list **start, t_list **lst)
{
t_token *token;
while ((*lst))
{
token = (*lst)->content;
if (token->type & TK_NEWLINE)
ft_lst_delif(start, (*lst)->content, &ft_addrcmp, &token_free);
else
break;
(*lst) = (*lst)->next;
}
return (0);
}
int parse_while(t_btree **ast, t_list **start, t_list **lst)
{
t_list *temp;
@ -31,9 +47,8 @@ int parse_while(t_btree **ast, t_list **start, t_list **lst)
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;
delete_all_newline(start, &temp);
(*lst) = temp;
*start = temp;
nest = 1;
@ -46,7 +61,6 @@ int parse_while(t_btree **ast, t_list **start, t_list **lst)
nest--;
if (nest == 0)
break;
DG("nest : '%d'", nest);
}
temp = (*lst)->next;
(*lst)->next = NULL;