gen func ok, todo: multi branch declaration, probleme lexer sur brackets
This commit is contained in:
parent
a8a06305bb
commit
7b1d505a5b
13 changed files with 105 additions and 16 deletions
|
|
@ -6,7 +6,7 @@
|
||||||
# By: wescande <wescande@student.42.fr> +#+ +:+ +#+ #
|
# By: wescande <wescande@student.42.fr> +#+ +:+ +#+ #
|
||||||
# +#+#+#+#+#+ +#+ #
|
# +#+#+#+#+#+ +#+ #
|
||||||
# Created: 2016/08/29 21:32:58 by wescande #+# #+# #
|
# Created: 2016/08/29 21:32:58 by wescande #+# #+# #
|
||||||
# Updated: 2017/02/24 21:33:24 by ariard ### ########.fr #
|
# Updated: 2017/02/25 00:13:39 by ariard ### ########.fr #
|
||||||
# #
|
# #
|
||||||
# **************************************************************************** #
|
# **************************************************************************** #
|
||||||
|
|
||||||
|
|
@ -233,6 +233,7 @@ parser/add_file.c\
|
||||||
parser/add_loop.c\
|
parser/add_loop.c\
|
||||||
parser/add_sep.c\
|
parser/add_sep.c\
|
||||||
parser/add_case.c\
|
parser/add_case.c\
|
||||||
|
parser/add_func.c\
|
||||||
parser/aggregate_sym.c\
|
parser/aggregate_sym.c\
|
||||||
parser/build_tree.c\
|
parser/build_tree.c\
|
||||||
parser/error_syntax.c\
|
parser/error_syntax.c\
|
||||||
|
|
|
||||||
|
|
@ -226,11 +226,14 @@ int add_case_sep(t_btree **ast, t_list **lst);
|
||||||
int add_pattern(t_btree **ast, t_list **lst);
|
int add_pattern(t_btree **ast, t_list **lst);
|
||||||
int add_subshell_cmd(t_btree **ast, t_list **lst);
|
int add_subshell_cmd(t_btree **ast, t_list **lst);
|
||||||
int add_subshell_sep(t_btree **ast, t_list **lst);
|
int add_subshell_sep(t_btree **ast, t_list **lst);
|
||||||
|
int add_func_cmd(t_btree **ast, t_list **lst);
|
||||||
|
int add_func_sep(t_btree **ast, t_list **lst);
|
||||||
int isloop(t_btree **ast, t_list **lst);
|
int isloop(t_btree **ast, t_list **lst);
|
||||||
int isdir(t_btree **ast);
|
int isdir(t_btree **ast);
|
||||||
int iscase(t_btree **ast, t_list **lst);
|
int iscase(t_btree **ast, t_list **lst);
|
||||||
int iscondition(t_btree **ast, t_list **lst);
|
int iscondition(t_btree **ast, t_list **lst);
|
||||||
int issubshell(t_btree **ast, t_list **lst);
|
int issubshell(t_btree **ast, t_list **lst);
|
||||||
|
int isfunc(t_btree **ast, t_list **lst);
|
||||||
|
|
||||||
int join_ast(t_btree **ast, t_btree **new_node);
|
int join_ast(t_btree **ast, t_btree **new_node);
|
||||||
int gen_node(t_btree **ast);
|
int gen_node(t_btree **ast);
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,6 @@
|
||||||
hello() {
|
hello() {
|
||||||
ls | cat
|
yolo() {
|
||||||
pwd ; cd
|
echo bonjour
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -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/02/24 20:59:07 by ariard ### ########.fr */
|
/* Updated: 2017/02/25 00:17:44 by ariard ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -16,6 +16,13 @@ char *ft_putast(void *nodein)
|
||||||
{
|
{
|
||||||
t_astnode *node;
|
t_astnode *node;
|
||||||
node = nodein;
|
node = nodein;
|
||||||
|
|
||||||
|
if (node->type == CLOSE_LIST)
|
||||||
|
return ("CLOSE_LIST");
|
||||||
|
if (node->type == FNAME)
|
||||||
|
return ("FNAME");
|
||||||
|
if (node->type == TK_LBRACE)
|
||||||
|
return ("TK_LBRACE");
|
||||||
if (node->type == TK_ASSIGNEMENT_WORD)
|
if (node->type == TK_ASSIGNEMENT_WORD)
|
||||||
return ("ASSIGNEMENT_WORD");
|
return ("ASSIGNEMENT_WORD");
|
||||||
if (node->type == SUBSHELL)
|
if (node->type == SUBSHELL)
|
||||||
|
|
|
||||||
|
|
@ -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/02/24 21:48:51 by ariard ### ########.fr */
|
/* Updated: 2017/02/25 00:00:16 by ariard ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -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/24 19:40:07 by ariard ### ########.fr */
|
/* Updated: 2017/02/25 00:11:05 by ariard ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -19,7 +19,7 @@ int add_cmd(t_btree **ast, t_list **lst)
|
||||||
char **my_tab;
|
char **my_tab;
|
||||||
|
|
||||||
DG("add cmd");
|
DG("add cmd");
|
||||||
if ((token = (*lst)->content)->type == TK_IN)
|
if ((token = (*lst)->content)->type == TK_IN || token->type == TK_PAREN_OPEN)
|
||||||
return (0);
|
return (0);
|
||||||
else if (!*ast)
|
else if (!*ast)
|
||||||
gen_node(ast);
|
gen_node(ast);
|
||||||
|
|
@ -41,6 +41,8 @@ int add_cmd(t_btree **ast, t_list **lst)
|
||||||
return (add_branch(ast, lst));
|
return (add_branch(ast, lst));
|
||||||
else if (issubshell(ast, lst))
|
else if (issubshell(ast, lst))
|
||||||
return (add_subshell_cmd(ast, lst));
|
return (add_subshell_cmd(ast, lst));
|
||||||
|
else if (isfunc(ast, lst))
|
||||||
|
return (add_func_cmd(ast, lst));
|
||||||
else if ((node = (*ast)->item)->type != TK_DO && node->type != TK_THEN
|
else if ((node = (*ast)->item)->type != TK_DO && node->type != TK_THEN
|
||||||
&& node->type != TK_PAREN_CLOSE)
|
&& node->type != TK_PAREN_CLOSE)
|
||||||
return (add_cmd(&(*ast)->right, lst));
|
return (add_cmd(&(*ast)->right, lst));
|
||||||
|
|
|
||||||
|
|
@ -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/24 15:45:39 by ariard ### ########.fr */
|
/* Updated: 2017/02/25 00:11:09 by ariard ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
|
||||||
65
42sh/src/parser/add_func.c
Normal file
65
42sh/src/parser/add_func.c
Normal file
|
|
@ -0,0 +1,65 @@
|
||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* add_func.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2017/02/24 23:43:07 by ariard #+# #+# */
|
||||||
|
/* Updated: 2017/02/25 00:28:35 by ariard ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "parser.h"
|
||||||
|
|
||||||
|
int isfunc(t_btree **ast, t_list **lst)
|
||||||
|
{
|
||||||
|
t_astnode *node;
|
||||||
|
t_token *token;
|
||||||
|
|
||||||
|
node = NULL;
|
||||||
|
token = (*lst)->content;
|
||||||
|
if (*ast)
|
||||||
|
{
|
||||||
|
node = (*ast)->item;
|
||||||
|
if (node->type == TK_WORD && token->type == CLOSE_LIST)
|
||||||
|
node->type = FNAME;
|
||||||
|
if (node->type == FNAME && node->full == 0)
|
||||||
|
return (1);
|
||||||
|
if (isfunc(&(*ast)->right, lst) == 1)
|
||||||
|
return (1);
|
||||||
|
}
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
|
|
||||||
|
int add_func_cmd(t_btree **ast, t_list **lst)
|
||||||
|
{
|
||||||
|
t_astnode *node;
|
||||||
|
t_token *token;
|
||||||
|
|
||||||
|
token = (*lst)->content;
|
||||||
|
node = (*ast)->item;
|
||||||
|
if (token->type == CLOSE_LIST && node->nest == 0)
|
||||||
|
return (0);
|
||||||
|
if ((token->type == TK_CASE || token->type == TK_WHILE || token->type == TK_IF
|
||||||
|
|| token->type == TK_UNTIL || token->type == TK_FOR
|
||||||
|
|| token->type == SUBSHELL || token->type == TK_LBRACE)
|
||||||
|
&& node->type == FNAME)
|
||||||
|
node->nest++;
|
||||||
|
if ((token->type == TK_DONE || token->type == TK_ESAC || token->type == TK_FI
|
||||||
|
|| token->type == TK_RBRACE || token->type == TK_PAREN_OPEN)
|
||||||
|
&& node->type == FNAME && node->nest > 0)
|
||||||
|
node->nest--;
|
||||||
|
if ((token->type == TK_DONE || token->type == TK_ESAC || token->type == TK_FI
|
||||||
|
|| token->type == TK_RBRACE || token->type == TK_PAREN_OPEN)
|
||||||
|
&& node->type == FNAME && node->nest == 0)
|
||||||
|
node->full = 1;
|
||||||
|
return (add_cmd(&(*ast)->right, lst));
|
||||||
|
}
|
||||||
|
|
||||||
|
int add_func_sep(t_btree **ast, t_list **lst)
|
||||||
|
{
|
||||||
|
return (add_sep(&(*ast)->right, lst));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -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/24 19:40:12 by ariard ### ########.fr */
|
/* Updated: 2017/02/25 00:13:07 by ariard ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -27,6 +27,8 @@ int add_sep(t_btree **ast, t_list **lst)
|
||||||
return (add_case_sep(ast, lst));
|
return (add_case_sep(ast, lst));
|
||||||
else if (issubshell(ast, lst))
|
else if (issubshell(ast, lst))
|
||||||
return (add_subshell_sep(ast, lst));
|
return (add_subshell_sep(ast, lst));
|
||||||
|
else if (isfunc(ast, lst))
|
||||||
|
return (add_func_sep(ast, lst));
|
||||||
if (!*ast)
|
if (!*ast)
|
||||||
gen_node(ast);
|
gen_node(ast);
|
||||||
token = (*lst)->content;
|
token = (*lst)->content;
|
||||||
|
|
|
||||||
|
|
@ -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/02/24 23:15:24 by ariard ### ########.fr */
|
/* Updated: 2017/02/24 23:38:40 by ariard ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -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/24 23:14:00 by ariard ### ########.fr */
|
/* Updated: 2017/02/24 23:58:10 by ariard ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -40,6 +40,9 @@ t_treematch g_treematch[] =
|
||||||
{TK_FOR, &add_cmd},
|
{TK_FOR, &add_cmd},
|
||||||
{TK_ASSIGNEMENT_WORD, &add_cmd},
|
{TK_ASSIGNEMENT_WORD, &add_cmd},
|
||||||
{SUBSHELL, &add_cmd},
|
{SUBSHELL, &add_cmd},
|
||||||
|
{TK_LBRACE, &add_cmd},
|
||||||
|
{TK_RBRACE, &add_cmd},
|
||||||
|
{CLOSE_LIST, &add_cmd},
|
||||||
{0, NULL},
|
{0, NULL},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -47,8 +50,9 @@ static int isseparator(t_token *token, int cache)
|
||||||
{
|
{
|
||||||
if (token->type == TK_NEWLINE && (cache == TK_WHILE || cache == TK_DO
|
if (token->type == TK_NEWLINE && (cache == TK_WHILE || cache == TK_DO
|
||||||
|| cache == TK_NEWLINE || cache == TK_THEN || cache == TK_IN
|
|| cache == TK_NEWLINE || cache == TK_THEN || cache == TK_IN
|
||||||
|| cache == TK_WORD || cache == TK_DSEMI))
|
|| cache == TK_DSEMI))
|
||||||
return (0);
|
return (0);
|
||||||
|
//check cache == WORD
|
||||||
return (1);
|
return (1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -62,8 +66,11 @@ int build_tree(t_btree **ast, t_list **lst)
|
||||||
token = (*lst)->content;
|
token = (*lst)->content;
|
||||||
//check bug de cache case ?
|
//check bug de cache case ?
|
||||||
// cache = token->type;
|
// cache = token->type;
|
||||||
if (token->type == TK_PAREN_OPEN && cache != TK_IN && cache != TK_DSEMI)
|
if (token->type == TK_PAREN_OPEN && cache != TK_IN && cache != TK_DSEMI
|
||||||
|
&& cache != TK_WORD)
|
||||||
token->type = SUBSHELL;
|
token->type = SUBSHELL;
|
||||||
|
if (token->type == TK_PAREN_CLOSE && cache == TK_PAREN_OPEN)
|
||||||
|
token->type = CLOSE_LIST;
|
||||||
while (g_treematch[i].type)
|
while (g_treematch[i].type)
|
||||||
{
|
{
|
||||||
if ((isseparator(token, cache) && g_treematch[i].type == token->type))
|
if ((isseparator(token, cache) && g_treematch[i].type == token->type))
|
||||||
|
|
|
||||||
|
|
@ -49,8 +49,8 @@ int ft_parse(t_btree **ast, t_list **token, t_parser *parser)
|
||||||
parser->state = SUCCESS;
|
parser->state = SUCCESS;
|
||||||
else
|
else
|
||||||
parser->state = UNDEFINED;
|
parser->state = UNDEFINED;
|
||||||
// build_tree(ast, token);
|
build_tree(ast, token);
|
||||||
// btree_print(STDBUG, *ast, &ft_putast);
|
btree_print(STDBUG, *ast, &ft_putast);
|
||||||
if ((end_instruction(*parser->stack) && !(*token)->next))
|
if ((end_instruction(*parser->stack) && !(*token)->next))
|
||||||
insert_linebreak(token);
|
insert_linebreak(token);
|
||||||
else
|
else
|
||||||
|
|
|
||||||
|
|
@ -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/24 22:59:52 by ariard ### ########.fr */
|
/* Updated: 2017/02/25 00:15:00 by ariard ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue