nesting condition ok
This commit is contained in:
parent
d9375e853a
commit
597afe06d0
12 changed files with 30 additions and 19 deletions
|
|
@ -1,10 +1,9 @@
|
||||||
if ls
|
if ls
|
||||||
then
|
then
|
||||||
|
if ls
|
||||||
|
then
|
||||||
pwd
|
pwd
|
||||||
elif ls
|
else pwd
|
||||||
then
|
fi
|
||||||
pwd
|
else ls
|
||||||
elif ls
|
|
||||||
then
|
|
||||||
pwd
|
|
||||||
fi
|
fi
|
||||||
|
|
|
||||||
BIN
42sh/src/parser/.produce_sym.c.swn
Normal file
BIN
42sh/src/parser/.produce_sym.c.swn
Normal file
Binary file not shown.
|
|
@ -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/02/20 17:03:15 by ariard ### ########.fr */
|
/* Updated: 2017/02/20 18:08:21 by ariard ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
|
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2017/02/19 18:12:52 by ariard #+# #+# */
|
/* Created: 2017/02/19 18:12:52 by ariard #+# #+# */
|
||||||
/* Updated: 2017/02/20 17:23:25 by ariard ### ########.fr */
|
/* Updated: 2017/02/20 18:17:26 by ariard ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -24,7 +24,7 @@ int iscondition(t_btree **ast, t_list **lst)
|
||||||
node = (*ast)->item;
|
node = (*ast)->item;
|
||||||
if ((node->type == TK_IF || iscondition(&(*ast)->right, lst))
|
if ((node->type == TK_IF || iscondition(&(*ast)->right, lst))
|
||||||
&& (token->type == TK_ELIF || token->type == TK_ELSE)
|
&& (token->type == TK_ELIF || token->type == TK_ELSE)
|
||||||
&& node->full == 0)
|
&& node->nest == 0)
|
||||||
return (2);
|
return (2);
|
||||||
if ((node->type == TK_IF || node->type == TK_ELIF || node->type == TK_ELSE)
|
if ((node->type == TK_IF || node->type == TK_ELIF || node->type == TK_ELSE)
|
||||||
&& node->full == 0)
|
&& node->full == 0)
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
|
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2017/02/17 22:17:14 by ariard #+# #+# */
|
/* Created: 2017/02/17 22:17:14 by ariard #+# #+# */
|
||||||
/* Updated: 2017/02/20 17:18:49 by ariard ### ########.fr */
|
/* Updated: 2017/02/20 17:46:39 by ariard ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
|
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2017/02/15 19:12:07 by ariard #+# #+# */
|
/* Created: 2017/02/15 19:12:07 by ariard #+# #+# */
|
||||||
/* Updated: 2017/02/20 17:07:16 by ariard ### ########.fr */
|
/* Updated: 2017/02/20 17:46:54 by ariard ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
|
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2017/02/09 17:39:18 by ariard #+# #+# */
|
/* Created: 2017/02/09 17:39:18 by ariard #+# #+# */
|
||||||
/* Updated: 2017/02/20 16:10:21 by ariard ### ########.fr */
|
/* Updated: 2017/02/20 18:03:21 by ariard ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -172,6 +172,7 @@ t_aggrematch g_aggrematch[] =
|
||||||
{COMMAND, NEWLINE_LIST, PIPE_SEMI_SEQUENCE, 0},
|
{COMMAND, NEWLINE_LIST, PIPE_SEMI_SEQUENCE, 0},
|
||||||
{COMMAND, LINEBREAK, PIPE_SEMI_SEQUENCE, 0},
|
{COMMAND, LINEBREAK, PIPE_SEMI_SEQUENCE, 0},
|
||||||
{COMMAND, AND_OR_MAJOR, PIPE_SEMI_SEQUENCE, 0},
|
{COMMAND, AND_OR_MAJOR, PIPE_SEMI_SEQUENCE, 0},
|
||||||
|
{COMMAND, COMPLETE_CONDITION, PIPE_SEMI_SEQUENCE, 0},
|
||||||
{END_COMMAND, PIPE_SEMI_SEQUENCE, PIPE_SEQUENCE, PIPE_SEMI_SEQUENCE},
|
{END_COMMAND, PIPE_SEMI_SEQUENCE, PIPE_SEQUENCE, PIPE_SEMI_SEQUENCE},
|
||||||
{END_COMMAND, TK_WHILE, PIPE_SEQUENCE, 0},
|
{END_COMMAND, TK_WHILE, PIPE_SEQUENCE, 0},
|
||||||
{END_COMMAND, LINEBREAK, PIPE_SEQUENCE, 0},
|
{END_COMMAND, LINEBREAK, PIPE_SEQUENCE, 0},
|
||||||
|
|
|
||||||
|
|
@ -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/02/20 17:23:48 by ariard ### ########.fr */
|
/* Updated: 2017/02/20 17:46:48 by ariard ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
|
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2017/02/09 16:26:30 by ariard #+# #+# */
|
/* Created: 2017/02/09 16:26:30 by ariard #+# #+# */
|
||||||
/* Updated: 2017/02/20 16:10:06 by ariard ### ########.fr */
|
/* Updated: 2017/02/20 18:03:18 by ariard ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -175,6 +175,7 @@ t_stackmatch g_stackmatch[] =
|
||||||
{TK_IF, TK_DO},
|
{TK_IF, TK_DO},
|
||||||
{TK_IF, TK_ELIF},
|
{TK_IF, TK_ELIF},
|
||||||
{TK_IF, TK_THEN},
|
{TK_IF, TK_THEN},
|
||||||
|
{TK_IF, COMPLETE_CONDITION},
|
||||||
{TK_IF, COMPOUND_LIST},
|
{TK_IF, COMPOUND_LIST},
|
||||||
{TK_THEN, CONDITION},
|
{TK_THEN, CONDITION},
|
||||||
{TK_THEN, COMPOUND_LIST},
|
{TK_THEN, COMPOUND_LIST},
|
||||||
|
|
@ -416,7 +417,9 @@ t_stackmatch g_stackmatch[] =
|
||||||
{LOOP, TK_UNTIL},
|
{LOOP, TK_UNTIL},
|
||||||
{CONDITION, LINEBREAK},
|
{CONDITION, LINEBREAK},
|
||||||
{CONDITION, COMPOUND_LIST},
|
{CONDITION, COMPOUND_LIST},
|
||||||
|
{CONDITION, COMPLETE_CONDITION},
|
||||||
{COMPLETE_CONDITION, LINEBREAK},
|
{COMPLETE_CONDITION, LINEBREAK},
|
||||||
|
{COMPLETE_CONDITION, COMPLETE_CONDITION},
|
||||||
{BRACE_GROUP, LINEBREAK},
|
{BRACE_GROUP, LINEBREAK},
|
||||||
{BRACE_GROUP, TK_BANG},
|
{BRACE_GROUP, TK_BANG},
|
||||||
{BRACE_GROUP, SEPARATOR_OP},
|
{BRACE_GROUP, SEPARATOR_OP},
|
||||||
|
|
@ -466,6 +469,7 @@ t_stackmatch g_stackmatch[] =
|
||||||
{IF_CLAUSE, TK_ELSE},
|
{IF_CLAUSE, TK_ELSE},
|
||||||
{IF_CLAUSE, COMPOUND_LIST},
|
{IF_CLAUSE, COMPOUND_LIST},
|
||||||
{IF_CLAUSE, COMPLETE_COMMAND},
|
{IF_CLAUSE, COMPLETE_COMMAND},
|
||||||
|
{IF_CLAUSE, COMPLETE_CONDITION},
|
||||||
|
|
||||||
{PATTERN, TK_PAREN_OPEN},
|
{PATTERN, TK_PAREN_OPEN},
|
||||||
{PATTERN, CASE_LIST},
|
{PATTERN, CASE_LIST},
|
||||||
|
|
@ -600,7 +604,7 @@ int eval_sym(t_sym stack, t_sym new_sym)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
// DG("eval head %s && sym %s", read_state(stack), read_state(new_sym));
|
DG("eval head %s && sym %s", read_state(stack), read_state(new_sym));
|
||||||
i = 0;
|
i = 0;
|
||||||
while (g_stackmatch[i].top)
|
while (g_stackmatch[i].top)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
|
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2017/02/09 14:30:22 by ariard #+# #+# */
|
/* Created: 2017/02/09 14:30:22 by ariard #+# #+# */
|
||||||
/* Updated: 2017/02/20 16:32:27 by ariard ### ########.fr */
|
/* Updated: 2017/02/20 18:16:44 by ariard ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -63,5 +63,10 @@ int ft_parse2(t_btree **ast, t_list **token)
|
||||||
else
|
else
|
||||||
ft_lst_delif(token, (*token)->content, &ft_addrcmp, &token_free);
|
ft_lst_delif(token, (*token)->content, &ft_addrcmp, &token_free);
|
||||||
}
|
}
|
||||||
|
if (state == UNDEFINED)
|
||||||
|
{
|
||||||
|
ft_putstr("syntax error: unexpected end of file\n");
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
|
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2017/02/09 17:58:34 by ariard #+# #+# */
|
/* Created: 2017/02/09 17:58:34 by ariard #+# #+# */
|
||||||
/* Updated: 2017/02/20 16:09:54 by ariard ### ########.fr */
|
/* Updated: 2017/02/20 18:01:02 by ariard ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
|
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2017/02/09 15:32:10 by ariard #+# #+# */
|
/* Created: 2017/02/09 15:32:10 by ariard #+# #+# */
|
||||||
/* Updated: 2017/02/20 16:09:16 by ariard ### ########.fr */
|
/* Updated: 2017/02/20 18:03:26 by ariard ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -14,6 +14,8 @@
|
||||||
|
|
||||||
char *read_state(t_sym current)
|
char *read_state(t_sym current)
|
||||||
{
|
{
|
||||||
|
if (current == IF_CLAUSE)
|
||||||
|
return ("IF_CLAUSE");
|
||||||
if (current == CONDITION)
|
if (current == CONDITION)
|
||||||
return ("CONDITION");
|
return ("CONDITION");
|
||||||
if (current == COMPLETE_CONDITION)
|
if (current == COMPLETE_CONDITION)
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue