Make this branch fully Norm compliant
authorLukas Jiriste <ljiriste@student.42prague.com>
Thu, 28 Nov 2024 10:23:25 +0000 (11:23 +0100)
committerLukas Jiriste <ljiriste@student.42prague.com>
Thu, 28 Nov 2024 10:23:25 +0000 (11:23 +0100)
I needed to split the main file a little yet. The grouping may not make
much sense, I did not want to spend any brain power on this anymore.

Makefile
ft_parse/parsing_table_constructor/ft_parsing_table_generate.c
ft_parse/parsing_table_constructor/helpers.c [new file with mode: 0644]
ft_parse/parsing_table_constructor/helpers_cmp.c
ft_parse/parsing_table_constructor/helpers_void_cmp.c [new file with mode: 0644]
ft_parse/parsing_table_constructor/lookahead.c
ft_parse/parsing_table_constructor/pt_constructor.h

index ddf223df35049acf725f4592006c6fbf5facb392..4cd10a931dc84c2e406f3c44b4ecbf0ef8959cf2 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -34,7 +34,9 @@ SRCparse:=    ft_parse.c                                      \
                        parsing_table_constructor/conversion_helpers.c                  \
                        parsing_table_constructor/conversion_subhelpers.c               \
                        parsing_table_constructor/fill_closure.c                                \
+                       parsing_table_constructor/helpers.c                                             \
                        parsing_table_constructor/helpers_cmp.c                                 \
+                       parsing_table_constructor/helpers_void_cmp.c                    \
                        parsing_table_constructor/helpers_free.c                                \
                        parsing_table_constructor/init_new_row.c                                \
                        parsing_table_constructor/lookahead.c                                   \
index cee4b8063afccb0c393262b5a617549b20809444..3deec3388b4d9f7528711367863ed85d129c9b0e 100644 (file)
@@ -6,7 +6,7 @@
 /*   By: ljiriste <ljiriste@student.42prague.com>   +#+  +:+       +#+        */
 /*                                                +#+#+#+#+#+   +#+           */
 /*   Created: 2024/06/27 11:16:53 by ljiriste          #+#    #+#             */
-/*   Updated: 2024/11/27 11:32:46 by ljiriste         ###   ########.fr       */
+/*   Updated: 2024/11/28 11:19:27 by ljiriste         ###   ########.fr       */
 /*                                                                            */
 /* ************************************************************************** */
 
 #include "libft.h"
 #include <stdlib.h>
 
-t_ft_stat      v_token_dup(void *dest, const void *src)
-{
-       if (dest == NULL)
-               return (alloc_fail);
-       *(t_token *)dest = ft_token_dup((t_token *)src);
-       return (success);
-}
-
-t_lr1_item     *duplicate_item(const t_lr1_item *item)
-{
-       t_lr1_item      *res;
-
-       res = malloc(sizeof(*res));
-       if (!res)
-               return (res);
-       if (ft_vec_copy(&res->lookahead, &item->lookahead, v_token_dup,
-                       ft_free_token) != success)
-       {
-               free(res);
-               return (NULL);
-       }
-       res->core = item->core;
-       return (res);
-}
-
-int    is_viable_item(const t_lr1_item *item, const t_token *token)
-{
-       const t_token                   *wanted_token;
-
-       wanted_token
-               = ft_vec_caccess(&item->core.rule->constituents, item->core.position);
-       return (cmp_token_type(wanted_token, token) == 0);
-}
-
-const t_token  *get_next_token(const t_marked_grammar_rule *rule)
-{
-       return (ft_vec_caccess(&rule->rule->constituents, rule->position));
-}
-
-t_ft_stat      init_state(t_generator_state **state)
+static t_ft_stat       init_state(t_generator_state **state)
 {
        t_ft_stat       res;
 
@@ -97,7 +58,7 @@ t_ft_stat     construct_state(t_vec *kernel, t_vec *states,
        return (solve_gotos(state, states, rules, tokens));
 }
 
-t_ft_stat      construct_first_kernel(t_vec *kernel, const t_vec *rules)
+static t_ft_stat       construct_first_kernel(t_vec *kernel, const t_vec *rules)
 {
        t_ft_stat       res;
        t_lr1_item      item;
@@ -123,7 +84,7 @@ t_ft_stat    construct_first_kernel(t_vec *kernel, const t_vec *rules)
        return (res);
 }
 
-t_ft_stat      construct_states(
+static t_ft_stat       construct_states(
                                t_vec *states, const t_vec *rules, const t_vec *tokens)
 {
        t_vec           kernel;
@@ -141,12 +102,6 @@ t_ft_stat  construct_states(
        return (success);
 }
 
-static void    remove_zeroth_rule(t_vec *rules)
-{
-       ft_vec_erase(rules, 0, ft_free_rule);
-       return ;
-}
-
 t_ft_stat      ft_parsing_table_generate(
                                t_parsing_table *table, const char *rules_filename)
 {
diff --git a/ft_parse/parsing_table_constructor/helpers.c b/ft_parse/parsing_table_constructor/helpers.c
new file mode 100644 (file)
index 0000000..cde2405
--- /dev/null
@@ -0,0 +1,61 @@
+/* ************************************************************************** */
+/*                                                                            */
+/*                                                        :::      ::::::::   */
+/*   helpers.c                                          :+:      :+:    :+:   */
+/*                                                    +:+ +:+         +:+     */
+/*   By: ljiriste <ljiriste@student.42prague.com>   +#+  +:+       +#+        */
+/*                                                +#+#+#+#+#+   +#+           */
+/*   Created: 2024/11/28 11:14:16 by ljiriste          #+#    #+#             */
+/*   Updated: 2024/11/28 11:17:22 by ljiriste         ###   ########.fr       */
+/*                                                                            */
+/* ************************************************************************** */
+
+#include "pt_constructor.h"
+#include "../ft_parse_inner.h"
+#include "libft.h"
+#include <stdlib.h>
+
+t_ft_stat      v_token_dup(void *dest, const void *src)
+{
+       if (dest == NULL)
+               return (alloc_fail);
+       *(t_token *)dest = ft_token_dup((t_token *)src);
+       return (success);
+}
+
+t_lr1_item     *duplicate_item(const t_lr1_item *item)
+{
+       t_lr1_item      *res;
+
+       res = malloc(sizeof(*res));
+       if (!res)
+               return (res);
+       if (ft_vec_copy(&res->lookahead, &item->lookahead, v_token_dup,
+                       ft_free_token) != success)
+       {
+               free(res);
+               return (NULL);
+       }
+       res->core = item->core;
+       return (res);
+}
+
+int    is_viable_item(const t_lr1_item *item, const t_token *token)
+{
+       const t_token                   *wanted_token;
+
+       wanted_token
+               = ft_vec_caccess(&item->core.rule->constituents, item->core.position);
+       return (cmp_token_type(wanted_token, token) == 0);
+}
+
+const t_token  *get_next_token(const t_marked_grammar_rule *rule)
+{
+       return (ft_vec_caccess(&rule->rule->constituents, rule->position));
+}
+
+void   remove_zeroth_rule(t_vec *rules)
+{
+       ft_vec_erase(rules, 0, ft_free_rule);
+       return ;
+}
index f4be20f900b784dda16781f47268b5fd19e82eb1..fb2f67bfa1cd62a8805fb201b6e27b90df3f31c5 100644 (file)
@@ -6,7 +6,7 @@
 /*   By: ljiriste <ljiriste@student.42prague.com>   +#+  +:+       +#+        */
 /*                                                +#+#+#+#+#+   +#+           */
 /*   Created: 2024/11/26 16:22:19 by ljiriste          #+#    #+#             */
-/*   Updated: 2024/11/27 11:17:27 by ljiriste         ###   ########.fr       */
+/*   Updated: 2024/11/28 11:12:17 by ljiriste         ###   ########.fr       */
 /*                                                                            */
 /* ************************************************************************** */
 
@@ -26,11 +26,6 @@ int  cmp_token_type(const t_token *token1, const t_token *token2)
        return (ft_strcmp(token1->type, token2->type));
 }
 
-int    void_cmp_token_type(const void *v_token1, const void *v_token2)
-{
-       return (cmp_token_type(v_token1, v_token2));
-}
-
 int    cmp_rules(const t_grammar_rule *rule1, const t_grammar_rule *rule2)
 {
        return (cmp_token_type(&rule1->result, &rule2->result)
@@ -38,11 +33,6 @@ int  cmp_rules(const t_grammar_rule *rule1, const t_grammar_rule *rule2)
                        &rule2->constituents, void_cmp_token_type));
 }
 
-int    void_cmp_rules(const void *v_rule1, const void *v_rule2)
-{
-       return (cmp_rules(v_rule1, v_rule2));
-}
-
 int    cmp_items(const t_lr1_item *item1, const t_lr1_item *item2)
 {
        return (cmp_rules(item1->core.rule, item2->core.rule)
@@ -50,9 +40,3 @@ int   cmp_items(const t_lr1_item *item1, const t_lr1_item *item2)
                || !ft_vec_is_setequal(&item1->lookahead, &item2->lookahead,
                        void_cmp_token_type));
 }
-
-int    void_cmp_items(const void *v_item1, const void *v_item2)
-{
-       return (cmp_items(v_item1, v_item2));
-}
-
diff --git a/ft_parse/parsing_table_constructor/helpers_void_cmp.c b/ft_parse/parsing_table_constructor/helpers_void_cmp.c
new file mode 100644 (file)
index 0000000..2c8e2e3
--- /dev/null
@@ -0,0 +1,28 @@
+/* ************************************************************************** */
+/*                                                                            */
+/*                                                        :::      ::::::::   */
+/*   helpers_void_cmp.c                                 :+:      :+:    :+:   */
+/*                                                    +:+ +:+         +:+     */
+/*   By: ljiriste <ljiriste@student.42prague.com>   +#+  +:+       +#+        */
+/*                                                +#+#+#+#+#+   +#+           */
+/*   Created: 2024/11/28 11:11:32 by ljiriste          #+#    #+#             */
+/*   Updated: 2024/11/28 11:12:54 by ljiriste         ###   ########.fr       */
+/*                                                                            */
+/* ************************************************************************** */
+
+#include "pt_constructor.h"
+
+int    void_cmp_token_type(const void *v_token1, const void *v_token2)
+{
+       return (cmp_token_type(v_token1, v_token2));
+}
+
+int    void_cmp_rules(const void *v_rule1, const void *v_rule2)
+{
+       return (cmp_rules(v_rule1, v_rule2));
+}
+
+int    void_cmp_items(const void *v_item1, const void *v_item2)
+{
+       return (cmp_items(v_item1, v_item2));
+}
index 808903c64cb75d4116abbf0f07592cc433e5304c..4770014667420fd85f4663ea7d8adad6de296308 100644 (file)
@@ -6,7 +6,7 @@
 /*   By: ljiriste <ljiriste@student.42prague.com>   +#+  +:+       +#+        */
 /*                                                +#+#+#+#+#+   +#+           */
 /*   Created: 2024/11/26 16:48:32 by ljiriste          #+#    #+#             */
-/*   Updated: 2024/11/27 11:21:00 by ljiriste         ###   ########.fr       */
+/*   Updated: 2024/11/28 11:13:14 by ljiriste         ###   ########.fr       */
 /*                                                                            */
 /* ************************************************************************** */
 
@@ -14,7 +14,8 @@
 #include "../ft_parse_inner.h"
 #include "libft.h"
 
-static t_ft_stat       add_to_lookahead(const t_vec *lookahead, t_vec *new_lookahead)
+static t_ft_stat       add_to_lookahead(
+                                               const t_vec *lookahead, t_vec *new_lookahead)
 {
        t_ft_stat       res;
        size_t          i;
index 59efd5e04303baed0e61761964c807eda06ed55e..3205910d9a78b12e0a32570b98f40b5d6836841a 100644 (file)
@@ -6,7 +6,7 @@
 /*   By: ljiriste <ljiriste@student.42prague.com>   +#+  +:+       +#+        */
 /*                                                +#+#+#+#+#+   +#+           */
 /*   Created: 2024/11/26 16:57:15 by ljiriste          #+#    #+#             */
-/*   Updated: 2024/11/27 11:32:22 by ljiriste         ###   ########.fr       */
+/*   Updated: 2024/11/28 11:19:11 by ljiriste         ###   ########.fr       */
 /*                                                                            */
 /* ************************************************************************** */
 
@@ -96,4 +96,6 @@ t_ft_stat             prepare_table(
 
 t_ft_stat              convert_to_table(t_parsing_table *table, const t_vec *states);
 
+void                   remove_zeroth_rule(t_vec *rules);
+
 #endif // PT_CONSTRUCTOR_H