parsing tk_bang && brace_clause}

This commit is contained in:
Antoine Riard 2017-03-09 19:48:34 +01:00
parent ca55620d71
commit 5e5a4a122a
11 changed files with 23 additions and 43 deletions

View file

@ -1,30 +0,0 @@
42sh
Makefile
STDBUG
TESTSHELL
donovan_segaults_06-02
error
includes
libft
objs
pdf
sample
src
test_framework.sh
testmake
update_makefile.sh
42sh
Makefile
STDBUG
TESTSHELL
donovan_segaults_06-02
error
includes
libft
objs
pdf
sample
src
test_framework.sh
testmake
update_makefile.sh

View file

View file

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/03/08 17:11:35 by jhalford ### ########.fr */ /* Updated: 2017/03/09 18:48:00 by ariard ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -31,6 +31,8 @@ int lexer_sep(t_list **alst, t_lexer *lexer)
token->type = cn == '|' ? TK_OR_IF : TK_PIPE; token->type = cn == '|' ? TK_OR_IF : TK_PIPE;
else if (c == ';') else if (c == ';')
token->type = cn == ';' ? TK_DSEMI : TK_SEMI; token->type = cn == ';' ? TK_DSEMI : TK_SEMI;
else if (c == '!')
token->type = TK_BANG;
if (token->type == TK_AND_IF || token->type == TK_OR_IF if (token->type == TK_AND_IF || token->type == TK_OR_IF
|| token->type == TK_DSEMI) || token->type == TK_DSEMI)
lexer->pos++; lexer->pos++;

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/03/07 23:35:32 by ariard ### ########.fr */ /* Updated: 2017/03/09 18:54:07 by ariard ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -17,8 +17,12 @@ char *ft_putast(void *nodein)
t_astnode *node; t_astnode *node;
node = nodein; node = nodein;
if (node->type == TK_BANG)
return ("TK_BANG");
if (node->type == MATH) if (node->type == MATH)
return ("MATH"); return ("MATH");
if (node->type == MATH_PLUS)
return ("MATH_PLUS");
if (node->type == TK_DSEMI) if (node->type == TK_DSEMI)
return ("TK_DSEMI"); return ("TK_DSEMI");
if (node->type == WORDLIST) if (node->type == WORDLIST)

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/03/09 17:37:38 by ariard ### ########.fr */ /* Updated: 2017/03/09 19:46:24 by ariard ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */

View file

@ -6,7 +6,7 @@
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */ /* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2017/02/15 20:49:15 by ariard #+# #+# */ /* Created: 2017/02/15 20:49:15 by ariard #+# #+# */
/* Updated: 2017/03/09 16:04:46 by ariard ### ########.fr */ /* Updated: 2017/03/09 19:44:51 by ariard ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */

View file

@ -6,7 +6,7 @@
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */ /* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2017/02/24 18:41:50 by ariard #+# #+# */ /* Created: 2017/02/24 18:41:50 by ariard #+# #+# */
/* Updated: 2017/03/07 22:46:36 by ariard ### ########.fr */ /* Updated: 2017/03/09 19:46:44 by ariard ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -23,6 +23,8 @@ int issubshell(t_btree **ast, t_list **lst)
node = (*ast)->item; node = (*ast)->item;
if (node->type == SUBSHELL && node->full == 0) if (node->type == SUBSHELL && node->full == 0)
return (1); return (1);
if (node->type == TK_LBRACE && node->full == 0)
return (1);
} }
return (0); return (0);
} }

View file

@ -97,6 +97,7 @@ t_aggrematch g_aggrematch[] =
{NEWLINE_LIST, TK_ELIF, TK_ELIF, TK_ELIF}, {NEWLINE_LIST, TK_ELIF, TK_ELIF, TK_ELIF},
{NEWLINE_LIST, TK_ELSE, TK_ELSE, TK_ELSE}, {NEWLINE_LIST, TK_ELSE, TK_ELSE, TK_ELSE},
{NEWLINE_LIST, TK_WHILE, TK_WHILE, TK_WHILE}, {NEWLINE_LIST, TK_WHILE, TK_WHILE, TK_WHILE},
{NEWLINE_LIST, TK_LBRACE, TK_LBRACE, TK_LBRACE},
{NEWLINE_LIST, TK_UNTIL, TK_UNTIL, TK_UNTIL}, {NEWLINE_LIST, TK_UNTIL, TK_UNTIL, TK_UNTIL},
{NEWLINE_LIST, CASE_LIST_NS, CASE_LIST_NS, CASE_LIST_NS}, {NEWLINE_LIST, CASE_LIST_NS, CASE_LIST_NS, CASE_LIST_NS},
{NEWLINE_LIST, NEWLINE_LIST, NEWLINE_LIST, NEWLINE}, {NEWLINE_LIST, NEWLINE_LIST, NEWLINE_LIST, NEWLINE},
@ -367,21 +368,21 @@ int aggregate_sym(t_list **stack, t_sym *new_sym, t_parstate *state)
return (1); return (1);
i = 0; i = 0;
head = (*stack)->content; head = (*stack)->content;
// DG("aggregate head %s && sym %s", DG("aggregate head %s && sym %s",
// read_state(*head), read_state(*new_sym)); read_state(*head), read_state(*new_sym));
while (g_aggrematch[i].top) while (g_aggrematch[i].top)
{ {
if (*new_sym == g_aggrematch[i].top if (*new_sym == g_aggrematch[i].top
&& MATCH_STACK(*head, g_aggrematch[i].under)) && MATCH_STACK(*head, g_aggrematch[i].under))
{ {
// DG("MATCH : %s", read_state(g_aggrematch[i].new_sym)); DG("MATCH : %s", read_state(g_aggrematch[i].new_sym));
*new_sym = g_aggrematch[i].new_sym; *new_sym = g_aggrematch[i].new_sym;
if (g_aggrematch[i].erase_sym) if (g_aggrematch[i].erase_sym)
{ {
pop_stack(stack, g_aggrematch[i].erase_sym); pop_stack(stack, g_aggrematch[i].erase_sym);
head = (*stack)->content; head = (*stack)->content;
// DG("stack after pop: %s", read_state(*head)); DG("stack after pop: %s", read_state(*head));
} }
if (eval_sym(stack, *new_sym)) if (eval_sym(stack, *new_sym))
{ {

View file

@ -6,7 +6,7 @@
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */ /* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2017/02/15 18:32:59 by ariard #+# #+# */ /* Created: 2017/02/15 18:32:59 by ariard #+# #+# */
/* Updated: 2017/03/09 18:33:05 by ariard ### ########.fr */ /* Updated: 2017/03/09 19:45:53 by ariard ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */

View file

@ -429,6 +429,7 @@ t_stackmatch g_stackmatch[] =
// watch ! // watch !
{TK_PAREN_OPEN, AND_OR_MAJOR}, {TK_PAREN_OPEN, AND_OR_MAJOR},
{TK_PAREN_OPEN, TK_WHILE}, {TK_PAREN_OPEN, TK_WHILE},
{TK_PAREN_OPEN, TK_LBRACE},
{TK_PAREN_OPEN, FUNC_NAME}, {TK_PAREN_OPEN, FUNC_NAME},
{TK_PAREN_OPEN, TK_UNTIL}, {TK_PAREN_OPEN, TK_UNTIL},
{TK_PAREN_OPEN, TK_DO}, {TK_PAREN_OPEN, TK_DO},
@ -817,6 +818,7 @@ t_stackmatch g_stackmatch[] =
{WHILE_CLAUSE, TK_DO}, {WHILE_CLAUSE, TK_DO},
{WHILE_CLAUSE, TK_PAREN_CLOSE}, {WHILE_CLAUSE, TK_PAREN_CLOSE},
{WHILE_CLAUSE, TK_WHILE}, {WHILE_CLAUSE, TK_WHILE},
{WHILE_CLAUSE, TK_LBRACE},
{WHILE_CLAUSE, FUNC_NAME}, {WHILE_CLAUSE, FUNC_NAME},
{WHILE_CLAUSE, TK_UNTIL}, {WHILE_CLAUSE, TK_UNTIL},
{WHILE_CLAUSE, TK_IF}, {WHILE_CLAUSE, TK_IF},
@ -954,6 +956,7 @@ t_stackmatch g_stackmatch[] =
{SUBSHELL, SEPARATOR_OP}, {SUBSHELL, SEPARATOR_OP},
{SUBSHELL, NEWLINE_LIST}, {SUBSHELL, NEWLINE_LIST},
{SUBSHELL, SEQUENCE}, {SUBSHELL, SEQUENCE},
{SUBSHELL, TK_LBRACE},
// watch ! // watch !
{SUBSHELL, SEPARATOR_OP}, {SUBSHELL, SEPARATOR_OP},
{SUBSHELL, NEWLINE_LIST}, {SUBSHELL, NEWLINE_LIST},
@ -1059,8 +1062,6 @@ t_stackmatch g_stackmatch[] =
{TK_BANG, TK_PAREN_OPEN}, {TK_BANG, TK_PAREN_OPEN},
{TK_BANG, TK_LBRACE}, {TK_BANG, TK_LBRACE},
{TK_BANG, COMPLETE_COMMANDS}, {TK_BANG, COMPLETE_COMMANDS},
{TK_BANG, TK_BANG},
{TK_BANG, TK_BANG},
{TK_BANG, SEPARATOR_OP}, {TK_BANG, SEPARATOR_OP},
{TK_BANG, NEWLINE_LIST}, {TK_BANG, NEWLINE_LIST},
{TK_BANG, AND_OR_MAJOR}, {TK_BANG, AND_OR_MAJOR},
@ -1191,7 +1192,7 @@ int eval_sym(t_list **stack, t_sym new_sym)
if (!*stack) if (!*stack)
return (1); return (1);
head = (*stack)->content; head = (*stack)->content;
// DG("eval head %s && sym %s", read_state(*head), read_state(new_sym)); DG("eval head %s && sym %s", read_state(*head), read_state(new_sym));
i = 0; i = 0;
while (g_stackmatch[i].top) while (g_stackmatch[i].top)
{ {