update: exec works !

This commit is contained in:
maix0 2024-10-10 17:41:23 +02:00
parent 2363fadd02
commit 77e7f65b41
24 changed files with 192 additions and 499 deletions

View file

@ -6,7 +6,7 @@
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/07/03 20:38:29 by maiboyer #+# #+# */
/* Updated: 2024/08/12 16:34:50 by maiboyer ### ########.fr */
/* Updated: 2024/10/10 17:17:58 by maiboyer ### ########.fr */
/* */
/* ************************************************************************** */
@ -45,14 +45,20 @@ static inline void ast_print_block1(t_ast_node self);
static inline void ast_print_block2(t_ast_node self);
static inline void ast_print_block3(t_ast_node self);
static inline void ast_print_notdone(t_ast_node self)
{
printf(" <ast_print_notdone> ");
(void)(self);
}
static inline void ast_print_block1(t_ast_node self)
{
if (self->kind == AST_ARITHMETIC_EXPANSION)
return (ast_print_node_arithmetic_expansion(self));
if (self->kind == AST_CASE)
return (ast_print_node_case(self));
return (ast_print_notdone(self));
if (self->kind == AST_CASE_ITEM)
return (ast_print_node_case_item(self));
return (ast_print_notdone(self));
if (self->kind == AST_COMMAND)
return (ast_print_node_command(self));
if (self->kind == AST_COMMAND_SUBSTITUTION)
@ -60,9 +66,9 @@ static inline void ast_print_block1(t_ast_node self)
if (self->kind == AST_COMPOUND_STATEMENT)
return (ast_print_node_compound_statement(self));
if (self->kind == AST_ELIF)
return (ast_print_node_elif(self));
return (ast_print_notdone(self));
if (self->kind == AST_ELSE)
return (ast_print_node_else(self));
return (ast_print_notdone(self));
if (self->kind == AST_EMPTY)
return ;
ast_print_block2(self);
@ -77,13 +83,13 @@ static inline void ast_print_block2(t_ast_node self)
if (self->kind == AST_FILE_REDIRECTION)
return (ast_print_node_file_redirection(self));
if (self->kind == AST_FOR)
return (ast_print_node_for(self));
return (ast_print_notdone(self));
if (self->kind == AST_FUNCTION_DEFINITION)
return (ast_print_node_function_definition(self));
if (self->kind == AST_HEREDOC_REDIRECTION)
return (ast_print_node_heredoc_redirection(self));
return (ast_print_notdone(self));
if (self->kind == AST_IF)
return (ast_print_node_if(self));
return (ast_print_notdone(self));
if (self->kind == AST_LIST)
return (ast_print_node_list(self));
ast_print_block3(self);
@ -102,11 +108,11 @@ static inline void ast_print_block3(t_ast_node self)
if (self->kind == AST_SUBSHELL)
return (ast_print_node_subshell(self));
if (self->kind == AST_UNTIL)
return (ast_print_node_until(self));
return (ast_print_notdone(self));
if (self->kind == AST_VARIABLE_ASSIGNMENT)
return (ast_print_node_variable_assignment(self));
if (self->kind == AST_WHILE)
return (ast_print_node_while(self));
return (ast_print_notdone(self));
if (self->kind == AST_WORD)
return (ast_print_node_word(self));
printf("Unknown ast->kind: %#04x\n", self->kind);

View file

@ -1,12 +1,12 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* print_arithmetic.c :+: :+: :+: */
/* ast_print_arithmetic.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/07/26 13:05:36 by rparodi #+# #+# */
/* Updated: 2024/07/26 13:08:22 by rparodi ### ########.fr */
/* Updated: 2024/10/10 16:57:18 by maiboyer ### ########.fr */
/* */
/* ************************************************************************** */
@ -19,7 +19,7 @@ void ast_print_node_arithmetic_expansion(t_ast_node self)
if (self->kind != AST_ARITHMETIC_EXPANSION)
return ;
printf("$((");
ast_print_node(self->data.arithmetic_expansion.expr);
ast_print(self->data.arithmetic_expansion.expr);
printf("))");
}
@ -35,7 +35,7 @@ void ast_print_node_function_definition(t_ast_node self)
i = 0;
while (i < self->data.function_definition.body.len)
{
ast_print_node(self->data.function_definition.body.buffer[i++]);
ast_print(self->data.function_definition.body.buffer[i++]);
printf(" ");
}
}

View file

@ -6,7 +6,7 @@
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/07/03 20:38:29 by maiboyer #+# #+# */
/* Updated: 2024/08/12 16:33:47 by maiboyer ### ########.fr */
/* Updated: 2024/10/10 16:56:59 by maiboyer ### ########.fr */
/* */
/* ************************************************************************** */
@ -24,7 +24,7 @@ void ast_print_node_command_substitution(t_ast_node self)
i = 0;
while (i < self->data.command_substitution.body.len)
{
ast_print_node(self->data.command_substitution.body.buffer[i++]);
ast_print(self->data.command_substitution.body.buffer[i++]);
}
printf(")");
}
@ -36,13 +36,13 @@ void ast_print_node_command_helper(t_ast_node self)
i = 0;
while (i < self->data.command.cmd_word.len)
{
ast_print_node(self->data.command.cmd_word.buffer[i++]);
ast_print(self->data.command.cmd_word.buffer[i++]);
printf(" ");
}
i = 0;
while (i < self->data.command.suffixes_redirections.len)
{
ast_print_node(self->data.command.suffixes_redirections.buffer[i++]);
ast_print(self->data.command.suffixes_redirections.buffer[i++]);
printf(" ");
}
_print_term(self->data.command.term);
@ -61,7 +61,7 @@ void ast_print_node_command(t_ast_node self)
i = 0;
while (i < self->data.command.prefixes.len)
{
ast_print_node(self->data.command.prefixes.buffer[i++]);
ast_print(self->data.command.prefixes.buffer[i++]);
printf(" ");
}
return (ast_print_node_command_helper(self));
@ -104,6 +104,6 @@ void ast_print_node_expansion(t_ast_node self)
ast_print_node_expansion_choose_op(self);
i = 0;
while (i < self->data.expansion.args.len)
ast_print_node(self->data.expansion.args.buffer[i++]);
ast_print(self->data.expansion.args.buffer[i++]);
printf("}");
}

View file

@ -6,7 +6,7 @@
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/07/26 13:07:12 by rparodi #+# #+# */
/* Updated: 2024/07/26 13:10:06 by rparodi ### ########.fr */
/* Updated: 2024/10/10 17:01:14 by maiboyer ### ########.fr */
/* */
/* ************************************************************************** */
@ -22,7 +22,7 @@ void ast_print_node_variable_assignment(t_ast_node self)
printf("! ");
printf("%s=", self->data.variable_assignment.name);
if (self->data.variable_assignment.value != NULL)
ast_print_node(self->data.variable_assignment.value);
ast_print(self->data.variable_assignment.value);
printf(" ");
}
@ -39,18 +39,18 @@ void ast_print_node_pipeline(t_ast_node self)
if (self->data.pipeline.statements.len != 0)
{
i = 0;
ast_print_node(self->data.pipeline.statements.buffer[i++]);
ast_print(self->data.pipeline.statements.buffer[i++]);
while (i < self->data.pipeline.statements.len)
{
printf(" | ");
ast_print_node(self->data.pipeline.statements.buffer[i++]);
ast_print(self->data.pipeline.statements.buffer[i++]);
}
}
i = 0;
while (i < self->data.pipeline.suffixes_redirections.len)
{
printf(" ");
ast_print_node(self->data.pipeline.suffixes_redirections.buffer[i++]);
ast_print(self->data.pipeline.suffixes_redirections.buffer[i++]);
}
_print_term(self->data.pipeline.term);
}
@ -63,16 +63,16 @@ void ast_print_node_list(t_ast_node self)
return ;
if (self->kind != AST_LIST)
return ;
ast_print_node(self->data.list.left);
ast_print(self->data.list.left);
if (self->data.list.op == AST_LIST_OR)
printf(" || ");
if (self->data.list.op == AST_LIST_AND)
printf(" && ");
ast_print_node(self->data.list.right);
ast_print(self->data.list.right);
i = 0;
while (i < self->data.list.suffixes_redirections.len)
{
ast_print_node(self->data.list.suffixes_redirections.buffer[i++]);
ast_print(self->data.list.suffixes_redirections.buffer[i++]);
printf(" ");
}
_print_term(self->data.list.term);

View file

@ -6,7 +6,7 @@
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/07/26 13:07:12 by rparodi #+# #+# */
/* Updated: 2024/07/26 13:25:29 by rparodi ### ########.fr */
/* Updated: 2024/10/10 16:57:52 by maiboyer ### ########.fr */
/* */
/* ************************************************************************** */
@ -30,7 +30,7 @@ void ast_print_node_file_redirection(t_ast_node self)
if (self->kind != AST_FILE_REDIRECTION)
return ;
if (self->data.file_redirection.input != NULL)
ast_print_node(self->data.file_redirection.input);
ast_print(self->data.file_redirection.input);
if (self->data.file_redirection.op == AST_REDIR_INPUT)
printf("<");
if (self->data.file_redirection.op == AST_REDIR_OUTPUT)
@ -46,6 +46,6 @@ void ast_print_node_file_redirection(t_ast_node self)
if (self->data.file_redirection.op == AST_REDIR_OUTPUT_CLOBBER)
printf(">|");
if (self->data.file_redirection.output != NULL)
ast_print_node(self->data.file_redirection.output);
ast_print(self->data.file_redirection.output);
return ((void) ast_print_node_file_redirection_heredoc(self));
}

View file

@ -6,7 +6,7 @@
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/07/26 13:27:30 by rparodi #+# #+# */
/* Updated: 2024/07/27 13:50:17 by maiboyer ### ########.fr */
/* Updated: 2024/10/10 16:58:13 by maiboyer ### ########.fr */
/* */
/* ************************************************************************** */
@ -26,7 +26,7 @@ void ast_print_node_subshell(t_ast_node self)
printf("( ");
while (i < self->data.subshell.body.len)
{
ast_print_node(self->data.subshell.body.buffer[i++]);
ast_print(self->data.subshell.body.buffer[i++]);
printf(" ");
}
printf(")");
@ -34,7 +34,7 @@ void ast_print_node_subshell(t_ast_node self)
while (i < self->data.subshell.suffixes_redirections.len)
{
printf(" ");
ast_print_node(self->data.subshell.suffixes_redirections.buffer[i++]);
ast_print(self->data.subshell.suffixes_redirections.buffer[i++]);
}
printf(" ");
_print_term(self->data.subshell.term);
@ -51,7 +51,7 @@ void ast_print_node_program(t_ast_node self)
i = 0;
while (i < self->data.program.body.len)
{
ast_print_node(self->data.program.body.buffer[i++]);
ast_print(self->data.program.body.buffer[i++]);
printf(" ");
}
}
@ -70,7 +70,7 @@ void ast_print_node_compound_statement(t_ast_node self)
printf("{ ");
while (i < self->data.compound_statement.body.len)
{
ast_print_node(self->data.compound_statement.body.buffer[i++]);
ast_print(self->data.compound_statement.body.buffer[i++]);
printf(" ");
}
printf("}");
@ -78,7 +78,7 @@ void ast_print_node_compound_statement(t_ast_node self)
while (i < self->data.compound_statement.suffixes_redirections.len)
{
printf(" ");
ast_print_node \
ast_print \
(self->data.compound_statement.suffixes_redirections.buffer[i++]);
}
printf(" ");
@ -102,6 +102,6 @@ void ast_print_node_word(t_ast_node self)
i = 0;
printf("%s", quote_type);
while (i < self->data.word.inner.len)
ast_print_node(self->data.word.inner.buffer[i++]);
ast_print(self->data.word.inner.buffer[i++]);
printf("%s", quote_type);
}