token and ast not in data_singleton()

This commit is contained in:
Jack Halford 2017-03-17 21:02:13 +01:00
parent 8427ab28bf
commit 043b0247b8
6 changed files with 24 additions and 25 deletions

View file

@ -214,7 +214,6 @@ lexer/get_reserved_words.c\
lexer/get_state_global.c\ lexer/get_state_global.c\
lexer/get_state_redir.c\ lexer/get_state_redir.c\
lexer/insert_newline.c\ lexer/insert_newline.c\
lexer/lexer_assignement_word.c\
lexer/lexer_backslash.c\ lexer/lexer_backslash.c\
lexer/lexer_bquote.c\ lexer/lexer_bquote.c\
lexer/lexer_curly_braces.c\ lexer/lexer_curly_braces.c\

View file

@ -6,7 +6,7 @@
/* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */ /* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2016/11/10 13:07:44 by jhalford #+# #+# */ /* Created: 2016/11/10 13:07:44 by jhalford #+# #+# */
/* Updated: 2017/03/17 00:20:53 by ariard ### ########.fr */ /* Updated: 2017/03/17 20:52:27 by jhalford ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -45,8 +45,6 @@ struct s_data
int argc; int argc;
char **argv; char **argv;
t_line line; t_line line;
t_list *token;
t_btree *ast;
t_lexer lexer; t_lexer lexer;
t_parser parser; t_parser parser;
t_comp *comp; t_comp *comp;

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */ /* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2016/12/03 11:56:49 by jhalford #+# #+# */ /* Created: 2016/12/03 11:56:49 by jhalford #+# #+# */
/* Updated: 2017/03/17 20:17:41 by jhalford ### ########.fr */ /* Updated: 2017/03/17 21:01:45 by jhalford ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */ /* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2017/02/09 22:03:48 by jhalford #+# #+# */ /* Created: 2017/02/09 22:03:48 by jhalford #+# #+# */
/* Updated: 2017/03/17 20:07:57 by jhalford ### ########.fr */ /* Updated: 2017/03/17 21:01:50 by jhalford ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */

View file

@ -6,7 +6,7 @@
/* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */ /* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2016/11/28 19:26:32 by jhalford #+# #+# */ /* Created: 2016/11/28 19:26:32 by jhalford #+# #+# */
/* Updated: 2017/03/17 17:41:33 by gwojda ### ########.fr */ /* Updated: 2017/03/17 20:51:06 by jhalford ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -38,8 +38,6 @@ int data_init(int ac, char **av)
data->opts = 0; data->opts = 0;
exec_reset(); exec_reset();
data->lst_func = NULL; data->lst_func = NULL;
data->token = NULL;
data->ast = NULL;
lexer_init(&data->lexer); lexer_init(&data->lexer);
parser_init(&data->parser); parser_init(&data->parser);
if ((term_name = ft_getenv(data->env, "TERM")) == NULL) if ((term_name = ft_getenv(data->env, "TERM")) == NULL)

View file

@ -28,7 +28,7 @@ static int do_readline_routine(char **stream)
return (ret); return (ret);
} }
static int do_lexer_routine(char *stream) static int do_lexer_routine(t_list **token, char *stream)
{ {
t_list *ltoken; t_list *ltoken;
t_data *data; t_data *data;
@ -42,8 +42,8 @@ static int do_lexer_routine(char *stream)
ft_strappend(&data->lexer.str, stream); ft_strappend(&data->lexer.str, stream);
if (get_lexer_stack(data->lexer) == BACKSLASH) if (get_lexer_stack(data->lexer) == BACKSLASH)
pop(&data->lexer.stack); pop(&data->lexer.stack);
ltoken = ft_lstlast(data->token); ltoken = ft_lstlast(*token);
if (lexer_lex(data->token ? &ltoken : &data->token, &data->lexer) < 0) if (lexer_lex(*token ? &ltoken : token, &data->lexer) < 0)
exit(1); exit(1);
if (get_lexer_stack(data->lexer) > 2) if (get_lexer_stack(data->lexer) > 2)
return (1); return (1);
@ -51,24 +51,24 @@ static int do_lexer_routine(char *stream)
return (0); return (0);
} }
static int do_parser_routine(void) static int do_parser_routine(t_list **token, t_btree **ast)
{ {
t_data *data; t_data *data;
data = data_singleton(); data = data_singleton();
if (get_reserved_words(data->token)) if (get_reserved_words(*token))
return (1); return (1);
if (insert_newline(&data->token)) if (insert_newline(token))
return (1); return (1);
if (data->parser.state == SUCCESS && stack_init(&data->parser)) if (data->parser.state == SUCCESS && stack_init(&data->parser))
exit(1); exit(1);
if (ft_parse(&data->ast, &data->token, &data->parser)) if (ft_parse(ast, token, &data->parser))
exit(1); exit(1);
if ((data->lexer.state = data->parser.heredoc_queue ? HEREDOC : DEFAULT)) if ((data->lexer.state = data->parser.heredoc_queue ? HEREDOC : DEFAULT))
return (0); return (0);
if (data->parser.state == ERROR) if (data->parser.state == ERROR)
{ {
error_syntax(&data->token); error_syntax(token);
return (1); return (1);
} }
else if (data->parser.state == SUCCESS) else if (data->parser.state == SUCCESS)
@ -76,7 +76,7 @@ static int do_parser_routine(void)
return (0); return (0);
} }
static int handle_instruction() static int handle_instruction(t_list **token, t_btree **ast)
{ {
int ret; int ret;
char *stream; char *stream;
@ -88,14 +88,14 @@ static int handle_instruction()
{ {
if ((ret = do_readline_routine(&stream)) > 0) if ((ret = do_readline_routine(&stream)) > 0)
return (ret); return (ret);
if (do_lexer_routine(stream) > 0) if (do_lexer_routine(token, stream) > 0)
continue ; continue ;
token_print(data->token); token_print(*token);
if (do_parser_routine() > 0) if (do_parser_routine(token, ast) > 0)
break ; break ;
} }
/* btree_print(STDBUG, ast, &ft_putast); */ /* btree_print(STDBUG, ast, &ft_putast); */
if (data->parser.state == SUCCESS && ft_exec(&data->ast) < 0) if (data->parser.state == SUCCESS && ft_exec(ast) < 0)
exit(1); exit(1);
if (SH_IS_INTERACTIVE(data->opts) && data->lexer.str) if (SH_IS_INTERACTIVE(data->opts) && data->lexer.str)
ft_add_str_in_history(data->lexer.str); ft_add_str_in_history(data->lexer.str);
@ -106,6 +106,8 @@ int main(int ac, char **av)
{ {
int ret; int ret;
t_data *data; t_data *data;
t_list *token;
t_btree *ast;
g_argv = av; g_argv = av;
setlocale(LC_ALL, ""); setlocale(LC_ALL, "");
@ -113,14 +115,16 @@ int main(int ac, char **av)
if (shell_init(ac, av)) if (shell_init(ac, av))
return (1); return (1);
DG("JOBC is %s", SH_HAS_JOBC(data_singleton()->opts)?"ON":"OFF"); DG("JOBC is %s", SH_HAS_JOBC(data_singleton()->opts)?"ON":"OFF");
token = NULL;
ast = NULL;
data = data_singleton(); data = data_singleton();
while (1) while (1)
{ {
ret = handle_instruction(); ret = handle_instruction(&token, &ast);
lexer_destroy(&data->lexer); lexer_destroy(&data->lexer);
parser_destroy(&data->parser); parser_destroy(&data->parser);
ft_lstdel(&data->token, &ft_lst_cfree); ft_lstdel(&token, &token_free);
btree_del(&data->ast, &ft_lst_cfree); btree_del(&ast, &ast_free);
if (ret == 1) if (ret == 1)
break ; break ;
} }