This commit is contained in:
Nathan Lebrun
2025-01-31 13:09:35 +01:00
parent 2367f6a42d
commit 304eeb73eb
8 changed files with 94 additions and 17 deletions

View File

@@ -44,11 +44,11 @@ TEST_DEPS = $(TEST_OBJS:.o=.d)
$(TEST_OBJDIR)/%.o: $(TEST_SRCDIR)/%.c
@mkdir -p $(dir $@)
@$(CC) $(WFLAGS) -MMD -MP -I$(INCDIR) -c $< -g3 -ggdb -o $@ $(LINK)
@$(CC) $(WFLAGS) -MMD -MP -I$(INCDIR) -c $< -o $@ $(LINK)
parser: $(LIBFT) $(TEST_OBJS)
@$(CC) $(WFLAGS) $(TEST_OBJS) $(LIBFT) -o parser $(LINK)
@echo "$(CYAN)Test build completed: test$(RESET)"
@echo "$(CYAN)Test build completed: parser$(RESET)"
# test part end

View File

@@ -29,14 +29,14 @@ int last_tok_subsh(t_node *lst)
return (0);
}
skip_parentheses(t_node **lst)
void skip_parentheses(t_node **lst)
{
if (!ft_strncmp((*lst)->val, "(", 1))
{
while ((*lst)->next && ft_strncmp((*lst)->next->val, ")", 1))
{
if (!ft_strncmp((*lst)->val, "(", 1))
skip_parentheses(&lst);
skip_parentheses(&(*lst)->next);
*lst = (*lst)->next;
}
}

View File

@@ -56,7 +56,14 @@ typedef struct s_ast_n
char **env;
} t_ast_n;
typedef struct s_nodell
{
t_node *node;
struct s_nodell *next;
} t_nodell;
t_ast_n *get_ast(char **envp, t_node *lst);
t_nodell *cutll(t_node *lst, char *expected, size_t limiter);
// env TMP
char **init_env(char **envp);

54
test/ast/cutll.c Normal file
View File

@@ -0,0 +1,54 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* cutll.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: nalebrun <nalebrun@student.s19.be> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/01/31 09:56:34 by nalebrun #+# #+# */
/* Updated: 2025/01/31 10:32:03 by nalebrun ### ########.fr */
/* */
/* ************************************************************************** */
#include "ast.h"
void add_nodell(t_nodell **nodell, t_node *node)
{
while (*nodell)
*nodell = (*nodell)->next;
(*nodell) = malloc(sizeof(t_nodell));
(*nodell)->node = node;
(*nodell)->next = NULL;
}
t_node *get_node(t_node *lst, char *expected)
{
t_node *node;
node = NULL;
while (lst && ft_strncmp(lst->val, expected, ft_strlen(expected)))
{
add_node_back(&node, lst->val, lst->token, lst->pressision);
lst = lst->next;
}
return (node);
}
t_nodell *cutll(t_node *lst, char *expected, size_t limiter)
{
t_nodell *out;
t_node *node;
size_t i;
i = 0;
out = NULL;
while (i <= limiter)
{
node = get_node(lst, expected);
if (!node)
break;
add_nodell(&out, node);
i++;
}
return (out);
}

View File

@@ -39,8 +39,9 @@ void truncate_comment(char *str)
int main(int ac, char **av, char **envp)
{
t_node *lst;
t_ast_n *ast;
// t_ast_n *ast;
int dio;
(void)envp;
if (ac != 3)
{
@@ -54,16 +55,24 @@ int main(int ac, char **av, char **envp)
if (DEBUG)
{
dio = drawio_init(av[1]);
gen_dio_linked_list(lst, dio);
// gen_dio_linked_list(lst, dio);
}
ast = get_ast(envp, lst);
if (!ast)
return (1);
// ast = get_ast(envp, lst);
// if (!ast)
// return (1);
if (DEBUG)
{
gen_dio_ast(ast, dio);
// gen_dio_ast(ast, dio);
drawio_end_file(dio);
ft_debug(" draw.io file generated !\n");
}
// tmp
t_nodell *lls = cutll(lst, "||", 1);
while (lls)
{
gen_dio_linked_list(lls->node, dio);
lls = lls->next;
}
free_linked_list(lst);
}

View File

@@ -28,14 +28,21 @@ t_node *create_node(char *val, t_token token)
return (node);
}
int add_node_back(t_node *head, char *val, t_token token)
int add_node_back(t_node **head, char *val, t_token token, t_pres pres)
{
if (!val)
return (0);
while (head->next != NULL)
head = head->next;
head->next = create_node(val, token);
if (head->next == NULL)
if (!(*head))
{
(*head) = create_node(val, token);
(*head)->pressision = pres;
return (1);
}
while ((*head)->next != NULL)
(*head) = (*head)->next;
(*head)->next = create_node(val, token);
(*head)->next->pressision = pres;
if ((*head)->next == NULL)
return (0);
return (1);
}

View File

@@ -27,7 +27,7 @@ static t_node *tokenize_base(char *str)
i = 1;
while (tab[i])
{
if (!add_node_back(head, tab[i], 0))
if (!add_node_back(&head, tab[i], 0, 0))
return (free(tab), NULL);
i++;
}

View File

@@ -50,7 +50,7 @@ typedef struct s_node
t_node *tokenize(char *str);
t_node *create_node(char *val, t_token token);
int add_node_back(t_node *head, char *val, t_token token);
int add_node_back(t_node **head, char *val, t_token token, t_pres pres);
int merge_with_next_node(t_node *node);
void free_linked_list(t_node *stack);
t_token get_token(char *str);