first birth of the yarn algo
This commit is contained in:
parent
a9a4417919
commit
75581c7ee0
4 changed files with 66 additions and 16 deletions
2
.clangd
2
.clangd
|
|
@ -6,6 +6,8 @@ CompileFlags: # Tweak the parse settings
|
|||
- "-I/nix/store/wxxgsgjxbnkkyczgf8lkbfrsqiywm8bi-clang-17.0.6-lib/lib/clang/17/include/"
|
||||
- "-I/nix/store/3mmvgb08qy8n6n37mnprf77fnp4rssi9-glibc-2.38-27-dev/include/"
|
||||
- "-I/nix/store/3jlclvmii9b6qmpqw9w09cp3zdnngvhk-clang-18.1.8/bin/clanglib/clang/17/include/"
|
||||
- "-I/nix/store/8mh0vrd6ll02j61612wz28vvsww1ps1z-glibc-2.39-52/include/"
|
||||
- "-I/nix/store/8vbzvmsm0iy931mdm4hk2vza7gsyc4gs-clang-17.0.6-lib/lib/clang/17/include/"
|
||||
- "-I/usr/include/"
|
||||
- "-I/home/maiboyer/Documents/ring-2/shcat/vendor/"
|
||||
- "-I/home/maiboyer/Documents/ring-2/shcat/stdme/include/"
|
||||
|
|
|
|||
|
|
@ -33,7 +33,7 @@
|
|||
tree
|
||||
]
|
||||
++ (
|
||||
if system == "x86_64-linux"
|
||||
if system == "x86_64-linux" || system == "aarch64-linux"
|
||||
then [valgrind valgrind.dev]
|
||||
else []
|
||||
);
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/10/07 18:04:13 by rparodi #+# #+# */
|
||||
/* Updated: 2024/10/07 18:14:22 by rparodi ### ########.fr */
|
||||
/* Updated: 2024/10/08 14:20:10 by rparodi ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -15,16 +15,58 @@
|
|||
#include "me/vec/vec_token.h"
|
||||
#include "parser/token.h"
|
||||
|
||||
t_error yarn(t_vec_token *list, enum e_token type, t_vec_token *output)
|
||||
int _get_precedance(t_token *token)
|
||||
{
|
||||
size_t i;
|
||||
|
||||
i = 0;
|
||||
if (!list[0].buffer || !output->buffer)
|
||||
return (ERROR);
|
||||
while (list[i].buffer == NULL)
|
||||
{
|
||||
i++;
|
||||
}
|
||||
return (NO_ERROR);
|
||||
if (!token)
|
||||
return (-1);
|
||||
else if (token->type == TOK_PIPE)
|
||||
return (2);
|
||||
else if (token->type == TOK_AND || token->type == TOK_OR)
|
||||
return (1);
|
||||
return (0);
|
||||
}
|
||||
|
||||
t_error yarn(t_vec_token *list, t_vec_token *output)
|
||||
{
|
||||
t_token tmp;
|
||||
t_token tmp2;
|
||||
t_vec_token output_queue;
|
||||
t_vec_token operator_stack;
|
||||
|
||||
output_queue = vec_token_new(16, token_free);;
|
||||
operator_stack = vec_token_new(16, token_free);;
|
||||
while (!vec_token_pop_front(list, &tmp))
|
||||
{
|
||||
if (tmp.type == TOK_CMD)
|
||||
vec_token_push(&output_queue, tmp);
|
||||
else if (tmp.type == TOK_OR || tmp.type == TOK_AND || tmp.type == TOK_PIPE)
|
||||
{
|
||||
while (vec_token_last(&operator_stack) != NULL && vec_token_last(&operator_stack)->type != TOK_LPAREN && _get_precedance(vec_token_last(&operator_stack)) > _get_precedance(&tmp))
|
||||
{
|
||||
vec_token_pop(&operator_stack, &tmp2);
|
||||
vec_token_push(&output_queue, tmp2);
|
||||
}
|
||||
vec_token_push(&operator_stack, tmp);
|
||||
}
|
||||
else if (tmp.type == TOK_LPAREN)
|
||||
vec_token_push(&operator_stack, tmp);
|
||||
else if (tmp.type == TOK_RPAREN)
|
||||
{
|
||||
while (vec_token_last(&operator_stack) != NULL && vec_token_last(&operator_stack)->type != TOK_LPAREN)
|
||||
{
|
||||
vec_token_pop(&operator_stack, &tmp2);
|
||||
vec_token_push(&output_queue, tmp2);
|
||||
}
|
||||
if (!(vec_token_last(&operator_stack) != NULL && vec_token_last(&operator_stack)->type == TOK_LPAREN))
|
||||
return (ERROR);
|
||||
vec_token_pop(&operator_stack, NULL);
|
||||
}
|
||||
}
|
||||
while (!vec_token_pop(&operator_stack, &tmp))
|
||||
{
|
||||
if (tmp.type == TOK_LPAREN)
|
||||
return (ERROR);
|
||||
vec_token_push(&output_queue, tmp);
|
||||
}
|
||||
return (*output = output_queue, NO_ERROR);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/03/28 14:40:38 by rparodi #+# #+# */
|
||||
/* Updated: 2024/10/08 13:29:30 by maiboyer ### ########.fr */
|
||||
/* Updated: 2024/10/08 14:22:42 by rparodi ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -101,15 +101,21 @@ void print_node_data(t_node *t, t_usize depth)
|
|||
}
|
||||
*/
|
||||
|
||||
t_error yarn(t_vec_token *list, t_vec_token *output);
|
||||
|
||||
void parse_str(t_state *state)
|
||||
{
|
||||
t_vec_token tokens;
|
||||
t_vec_token tok_yarn;
|
||||
|
||||
if (tokenize(state->str_input, &tokens))
|
||||
return ;
|
||||
if (ts_apply_passes(tokens, &tokens))
|
||||
return ;
|
||||
if (yarn(&tokens, &tok_yarn))
|
||||
return ;
|
||||
printf("\n\nEND TOKENS\n");
|
||||
ts_print(&tokens);
|
||||
ts_print(&tok_yarn);
|
||||
vec_token_free(tokens);
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue