update: added some comments and fixed a bit of code
This commit is contained in:
parent
f6f70f0c53
commit
dbb53d37ab
1 changed files with 24 additions and 14 deletions
|
|
@ -6,15 +6,15 @@
|
||||||
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2024/10/09 12:44:53 by maiboyer #+# #+# */
|
/* Created: 2024/10/09 12:44:53 by maiboyer #+# #+# */
|
||||||
/* Updated: 2024/10/10 15:56:05 by rparodi ### ########.fr */
|
/* Updated: 2024/10/10 16:21:44 by maiboyer ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
#include "ast/ast.h"
|
#include "ast/ast.h"
|
||||||
#include "me/types.h"
|
#include "me/types.h"
|
||||||
#include "parser/token.h"
|
|
||||||
#include "me/vec/vec_ast.h"
|
#include "me/vec/vec_ast.h"
|
||||||
#include "me/vec/vec_token.h"
|
#include "me/vec/vec_token.h"
|
||||||
|
#include "parser/token.h"
|
||||||
|
|
||||||
/// en fonction de op, qui peut etre: TOK_AND TOK_PIPE TOK_OR
|
/// en fonction de op, qui peut etre: TOK_AND TOK_PIPE TOK_OR
|
||||||
/// choisir le bon ast_node a faire (t_ast_node->data.list + set operator ou t_asdt_node->data.pipeline)
|
/// choisir le bon ast_node a faire (t_ast_node->data.list + set operator ou t_asdt_node->data.pipeline)
|
||||||
|
|
@ -26,32 +26,42 @@
|
||||||
/// struct s_ast_list if (tok.type == TOK_AND || tok.type == TOK_OR)
|
/// struct s_ast_list if (tok.type == TOK_AND || tok.type == TOK_OR)
|
||||||
/// struct s_ast_pipeline if (tok.type == TOK_PIPE)
|
/// struct s_ast_pipeline if (tok.type == TOK_PIPE)
|
||||||
/// `ast/include/ast/_raw_structs.h`
|
/// `ast/include/ast/_raw_structs.h`
|
||||||
|
///
|
||||||
|
///
|
||||||
|
/// in the end we should change to using `t_error` and pushing the ast_node directly to output_queue in the function,
|
||||||
|
/// will change that later tho :)
|
||||||
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 ret;
|
||||||
t_ast_node tmp;
|
t_ast_node tmp;
|
||||||
|
|
||||||
|
// this needs have a protection in case output_queue is smaller than 2 elements
|
||||||
|
// otherwise it is good :)
|
||||||
|
// you could also make it so TOK_AND and TOK_OR share the same code to win some lines
|
||||||
if (tok.type == TOK_AND)
|
if (tok.type == TOK_AND)
|
||||||
{
|
{
|
||||||
tmp = ast_alloc(AST_LIST);
|
ret = ast_alloc(AST_LIST);
|
||||||
tmp->data.list.op = AST_LIST_AND;
|
ret->data.list.op = AST_LIST_AND;
|
||||||
vec_ast_pop(output_queue, &tmp->data.list.right);
|
vec_ast_pop(output_queue, &ret->data.list.right);
|
||||||
vec_ast_pop(output_queue, &tmp->data.list.left);
|
vec_ast_pop(output_queue, &ret->data.list.left);
|
||||||
}
|
}
|
||||||
else if (tok.type == TOK_OR)
|
else if (tok.type == TOK_OR)
|
||||||
{
|
{
|
||||||
tmp = ast_alloc(AST_LIST);
|
ret = ast_alloc(AST_LIST);
|
||||||
tmp->data.list.op = AST_LIST_OR;
|
ret->data.list.op = AST_LIST_OR;
|
||||||
vec_ast_pop(output_queue, &tmp->data.list.right);
|
vec_ast_pop(output_queue, &ret->data.list.right);
|
||||||
vec_ast_pop(output_queue, &tmp->data.list.left);
|
vec_ast_pop(output_queue, &ret->data.list.left);
|
||||||
}
|
}
|
||||||
else if (tok.type == TOK_PIPE)
|
else if (tok.type == TOK_PIPE)
|
||||||
{
|
{
|
||||||
tmp = ast_alloc(AST_PIPELINE);
|
// Here there is some kind of optimization that could be done in the future: if one node is already a AST_PIPELINE, just pus the other node into the right place in it and return the non created AST_PIPELINE node !
|
||||||
|
ret = ast_alloc(AST_PIPELINE);
|
||||||
vec_ast_pop(output_queue, &tmp);
|
vec_ast_pop(output_queue, &tmp);
|
||||||
vec_ast_push(&tmp.data.pipeline.statements, tmp);
|
vec_ast_push(&ret->data.pipeline.statements, tmp);
|
||||||
vec_ast_pop(output_queue, &tmp);
|
vec_ast_pop(output_queue, &tmp);
|
||||||
vec_ast_push(&tmp.data.pipeline.statements, tmp);
|
vec_ast_push(&ret->data.pipeline.statements, tmp);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
me_abort("ast_from_op not the good token type gived !\n");
|
me_abort("ast_from_op not the good token type gived !\n");
|
||||||
|
return (ret);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue