diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..f8c5981 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,6 @@ +{ + "files.associations": { + "ios": "c", + "iterator": "c" + } +} \ No newline at end of file diff --git a/minishell b/minishell new file mode 100755 index 0000000..10509df Binary files /dev/null and b/minishell differ diff --git a/src/process/parser/semantic_analyzer.c b/src/process/parser/semantic_analyzer.c index 8706d91..60db8e0 100644 --- a/src/process/parser/semantic_analyzer.c +++ b/src/process/parser/semantic_analyzer.c @@ -3,10 +3,10 @@ /* ::: :::::::: */ /* semantic_analyzer.c :+: :+: :+: */ /* +:+ +:+ +:+ */ -/* By: moabid +#+ +:+ +#+ */ +/* By: frame +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2022/07/16 17:21:59 by moabid #+# #+# */ -/* Updated: 2022/10/25 21:36:20 by moabid ### ########.fr */ +/* Updated: 2022/10/26 00:43:45 by frame ### ########.fr */ /* */ /* ************************************************************************** */ @@ -55,65 +55,87 @@ struct ast *ast_create_subtree(struct minishell *minishell, return (ast); } -struct ast *semantic_analyzer_create(struct minishell *minishell, - struct token_stream *token_stream) +static struct minishell *semantic_analyzer_helper(struct s_data *d) { - struct ast *ast; - struct token_stream *tmp; - struct token_stream *prev; - char export_fg; - - tmp = token_stream; - prev = tmp; - minishell->start_right = false; - while (is_bracket(minishell, tmp->token_name) == true) - tmp = tmp->next; - ast = ast_create_first_node(minishell, tmp); - tmp = tmp->next; - while (tmp) + while (d->tmp) { - if (ast->value.token_type == 5) - minishell->start_right = true; - if (is_bracket(minishell, tmp->token_name) == true) + if (d->ast->value.token_type == 5) + d->ms->start_right = true; + if (is_bracket(d->ms, d->tmp->token_name) == true) { - tmp = tmp->next; + d->tmp = d->tmp->next; continue ; } - if (!my_strcmp(prev->token_name, "export")) - export_fg = true; - if (prev->token_type == AND || prev->token_type == OR) + if (!my_strcmp(d->prev->token_name, "export")) + d->export_fg = true; + if (d->prev->token_type == AND || d->prev->token_type == OR) { - if (ast_is_assign(ast->left) == true) - minishell_ast_execute(ast->left, minishell); - ast->right = ast_create_subtree(minishell, &prev, &tmp); - if (!tmp || !ast->right) + if (ast_is_assign(d->ast->left) == true) + minishell_ast_execute(d->ast->left, d->ms); + d->ast->right = ast_create_subtree(d->ms, &d->prev, &d->tmp); + if (!d->tmp || !d->ast->right) break ; } - if (is_sub_tree(export_fg, prev, tmp)) + if (is_sub_tree(d->export_fg, d->prev, d->tmp)) { - ast->right = ast_create_subtree(minishell, &prev, &tmp); - if (!tmp || !ast->right) + d->ast->right = ast_create_subtree(d->ms, &d->prev, &d->tmp); + if (!d->tmp || !d->ast->right) break ; } - if (is_child(ast->value.token_type, tmp) == true) - ast_insert_child(node_create_child(tmp, minishell, - prev->token_type), &ast, prev, minishell); + if (is_child(d->ast->value.token_type, d->tmp) == true) + ast_insert_child(node_create_child(d->tmp, d->ms, + d->prev->token_type), &d->ast, d->prev, d->ms); else - ast_insert_parent(node_create_parent(tmp), &ast, minishell); - prev = tmp; - tmp = tmp->next; + ast_insert_parent(node_create_parent(d->tmp), &d->ast, d->ms); + d->prev = d->tmp; + d->tmp = d->tmp->next; } - if (minishell->open != 0) + return (d->ms); +} + +struct s_data +{ + struct token_stream *t_s; + struct ast *ast; + struct token_stream *tmp; + struct token_stream *prev; + struct minishell *ms; + char export_fg; +}; + +struct s_data s_data_init(struct minishell *minishell, + struct token_stream *token_stream) +{ + struct s_data d; + + d.t_s = token_stream; + d.tmp = token_stream; + d.prev = d.tmp; +} + +struct ast *semantic_analyzer_create(struct minishell *minishell, + struct token_stream *token_stream) +{ + struct s_data d; + + d = s_data_init(minishell, token_stream); + d.ms->start_right = false; + while (is_bracket(d.ms, d.tmp->token_name) == true) + d.tmp = d.tmp->next; + d.ast = ast_create_first_node(d.ms, d.tmp); + d.tmp = d.tmp->next; + d.ms = semantic_analyzer_helper(&d); + if (d.ms->open != 0) { - error_exit(minishell, "esh: syntax error near unexpected token \ + error_exit(d.ms, "esh: syntax error near unexpected token \ ')'\n", NULL, 258); return (NULL); } - if (ast_not_right_type(ast) == false) - return (handle_not_right_2(minishell, ast)); - return (ast); + if (ast_not_right_type(d.ast) == false) + return (handle_not_right_2(d.ms, d.ast)); + return (d.ast); } -void semantic_analyzer_destroy(struct minishell *minishell) -{ -} +// void semantic_analyzer_destroy(struct minishell *minishell) +// { +// }