pff
This commit is contained in:
4
Makefile
4
Makefile
@@ -44,11 +44,11 @@ TEST_DEPS = $(TEST_OBJS:.o=.d)
|
|||||||
|
|
||||||
$(TEST_OBJDIR)/%.o: $(TEST_SRCDIR)/%.c
|
$(TEST_OBJDIR)/%.o: $(TEST_SRCDIR)/%.c
|
||||||
@mkdir -p $(dir $@)
|
@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)
|
parser: $(LIBFT) $(TEST_OBJS)
|
||||||
@$(CC) $(WFLAGS) $(TEST_OBJS) $(LIBFT) -o parser $(LINK)
|
@$(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
|
# test part end
|
||||||
|
|
||||||
|
|||||||
@@ -29,14 +29,14 @@ int last_tok_subsh(t_node *lst)
|
|||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
|
|
||||||
skip_parentheses(t_node **lst)
|
void skip_parentheses(t_node **lst)
|
||||||
{
|
{
|
||||||
if (!ft_strncmp((*lst)->val, "(", 1))
|
if (!ft_strncmp((*lst)->val, "(", 1))
|
||||||
{
|
{
|
||||||
while ((*lst)->next && ft_strncmp((*lst)->next->val, ")", 1))
|
while ((*lst)->next && ft_strncmp((*lst)->next->val, ")", 1))
|
||||||
{
|
{
|
||||||
if (!ft_strncmp((*lst)->val, "(", 1))
|
if (!ft_strncmp((*lst)->val, "(", 1))
|
||||||
skip_parentheses(&lst);
|
skip_parentheses(&(*lst)->next);
|
||||||
*lst = (*lst)->next;
|
*lst = (*lst)->next;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -56,7 +56,14 @@ typedef struct s_ast_n
|
|||||||
char **env;
|
char **env;
|
||||||
} t_ast_n;
|
} 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_ast_n *get_ast(char **envp, t_node *lst);
|
||||||
|
t_nodell *cutll(t_node *lst, char *expected, size_t limiter);
|
||||||
|
|
||||||
// env TMP
|
// env TMP
|
||||||
char **init_env(char **envp);
|
char **init_env(char **envp);
|
||||||
|
|||||||
54
test/ast/cutll.c
Normal file
54
test/ast/cutll.c
Normal 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);
|
||||||
|
}
|
||||||
21
test/test.c
21
test/test.c
@@ -39,8 +39,9 @@ void truncate_comment(char *str)
|
|||||||
int main(int ac, char **av, char **envp)
|
int main(int ac, char **av, char **envp)
|
||||||
{
|
{
|
||||||
t_node *lst;
|
t_node *lst;
|
||||||
t_ast_n *ast;
|
// t_ast_n *ast;
|
||||||
int dio;
|
int dio;
|
||||||
|
(void)envp;
|
||||||
|
|
||||||
if (ac != 3)
|
if (ac != 3)
|
||||||
{
|
{
|
||||||
@@ -54,16 +55,24 @@ int main(int ac, char **av, char **envp)
|
|||||||
if (DEBUG)
|
if (DEBUG)
|
||||||
{
|
{
|
||||||
dio = drawio_init(av[1]);
|
dio = drawio_init(av[1]);
|
||||||
gen_dio_linked_list(lst, dio);
|
// gen_dio_linked_list(lst, dio);
|
||||||
}
|
}
|
||||||
ast = get_ast(envp, lst);
|
// ast = get_ast(envp, lst);
|
||||||
if (!ast)
|
// if (!ast)
|
||||||
return (1);
|
// return (1);
|
||||||
if (DEBUG)
|
if (DEBUG)
|
||||||
{
|
{
|
||||||
gen_dio_ast(ast, dio);
|
// gen_dio_ast(ast, dio);
|
||||||
drawio_end_file(dio);
|
drawio_end_file(dio);
|
||||||
ft_debug(" draw.io file generated !\n");
|
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);
|
free_linked_list(lst);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -28,14 +28,21 @@ t_node *create_node(char *val, t_token token)
|
|||||||
return (node);
|
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)
|
if (!val)
|
||||||
return (0);
|
return (0);
|
||||||
while (head->next != NULL)
|
if (!(*head))
|
||||||
head = head->next;
|
{
|
||||||
head->next = create_node(val, token);
|
(*head) = create_node(val, token);
|
||||||
if (head->next == NULL)
|
(*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 (0);
|
||||||
return (1);
|
return (1);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -27,7 +27,7 @@ static t_node *tokenize_base(char *str)
|
|||||||
i = 1;
|
i = 1;
|
||||||
while (tab[i])
|
while (tab[i])
|
||||||
{
|
{
|
||||||
if (!add_node_back(head, tab[i], 0))
|
if (!add_node_back(&head, tab[i], 0, 0))
|
||||||
return (free(tab), NULL);
|
return (free(tab), NULL);
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -50,7 +50,7 @@ typedef struct s_node
|
|||||||
|
|
||||||
t_node *tokenize(char *str);
|
t_node *tokenize(char *str);
|
||||||
t_node *create_node(char *val, t_token token);
|
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);
|
int merge_with_next_node(t_node *node);
|
||||||
void free_linked_list(t_node *stack);
|
void free_linked_list(t_node *stack);
|
||||||
t_token get_token(char *str);
|
t_token get_token(char *str);
|
||||||
|
|||||||
Reference in New Issue
Block a user