Fix bug, where NULLs appear inside tree
authorLukas Jiriste <ljiriste@student.42prague.com>
Fri, 21 Jun 2024 08:57:50 +0000 (10:57 +0200)
committerLukas Jiriste <ljiriste@student.42prague.com>
Fri, 21 Jun 2024 08:57:50 +0000 (10:57 +0200)
This bug was caused because the tree nodes are filled from the end
when reducing. Instead of just inserting to the start it was inserting
at the final position.
When inserting to vector outside of range all the nonexistent entries
are initialized to 0. If another insertion happes after that, the
0 entries are not filled but moved to make space for the new entry.

ft_parse/ft_parse.c

index e101c5cf60c14b1351b250633243f56eb08f2627..bd1cf9ddb7448dbe902960643f7d5f84b18e69f6 100644 (file)
@@ -6,7 +6,7 @@
 /*   By: ljiriste <ljiriste@student.42prague.com>   +#+  +:+       +#+        */
 /*                                                +#+#+#+#+#+   +#+           */
 /*   Created: 2024/05/20 20:51:36 by ljiriste          #+#    #+#             */
-/*   Updated: 2024/06/21 09:39:33 by ljiriste         ###   ########.fr       */
+/*   Updated: 2024/06/21 10:56:32 by ljiriste         ###   ########.fr       */
 /*                                                                            */
 /* ************************************************************************** */
 
@@ -107,7 +107,7 @@ int follow_rule(t_stack *stack, size_t rule_num, t_parsing_table *table)
                node = ((t_parser_stack_element *)ft_stack_pop(stack, NULL))->node;
                if (ft_strcmp(node->token.type,
                                        ((t_token *)ft_vec_access(&rule->constituents, i))->type) ||
-                               ft_vec_insert(&element.node->children, node, i) != success)
+                               ft_vec_insert(&element.node->children, node, 0) != success)
                {
                        ft_parse_tree_free(element.node);
                        ft_parse_tree_free(node);