From 4d56158633fec8644718dd7bc9126cf17b6b12e0 Mon Sep 17 00:00:00 2001 From: Raphael Date: Thu, 10 Oct 2024 15:20:12 +0200 Subject: [PATCH] feat: adding the and / or treatment --- parser/src/yarn/ast_op.c | 29 +++++++++++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) diff --git a/parser/src/yarn/ast_op.c b/parser/src/yarn/ast_op.c index 22192600..2f4e34ff 100644 --- a/parser/src/yarn/ast_op.c +++ b/parser/src/yarn/ast_op.c @@ -6,11 +6,12 @@ /* By: maiboyer +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/10/09 12:44:53 by maiboyer #+# #+# */ -/* Updated: 2024/10/09 12:46:06 by maiboyer ### ########.fr */ +/* Updated: 2024/10/10 15:19:20 by rparodi ### ########.fr */ /* */ /* ************************************************************************** */ #include "ast/ast.h" +#include "me/types.h" #include "parser/token.h" #include "me/vec/vec_ast.h" #include "me/vec/vec_token.h" @@ -25,4 +26,28 @@ /// struct s_ast_list if (tok.type == TOK_AND || tok.type == TOK_OR) /// struct s_ast_pipeline if (tok.type == TOK_PIPE) /// `ast/include/ast/_raw_structs.h` -t_ast_node ast_from_op(t_token tok, t_vec_ast *output_queue); +t_ast_node ast_from_op(t_token tok, t_vec_ast *output_queue) +{ + t_ast_node tmp; + + if (tok.type != TOK_AND && tok.type != TOK_OR && tok.type != TOK_PIPE) + me_abort("ast_from_op not the good token type gived !\n"); + if (tok.type == TOK_AND) + { + tmp = ast_alloc(AST_LIST); + tmp->data.list.op = AST_LIST_AND; + vec_ast_pop(output_queue, &tmp->data.list.right); + vec_ast_pop(output_queue, &tmp->data.list.left); + } + if (tok.type == TOK_OR) + { + tmp = ast_alloc(AST_LIST); + tmp->data.list.op = AST_LIST_OR; + vec_ast_pop(output_queue, &tmp->data.list.right); + vec_ast_pop(output_queue, &tmp->data.list.left); + } + if (tok.type == TOK_PIPE) + { + tmp = ast_alloc(AST_PIPELINE); + } +}