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 \
/* 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;
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;
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;
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)
{
--- /dev/null
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* 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 ;
+}
/* 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 */
/* */
/* ************************************************************************** */
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)
&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)
|| !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));
-}
-
--- /dev/null
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* 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));
+}
/* 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 */
/* */
/* ************************************************************************** */
#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;
/* 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 */
/* */
/* ************************************************************************** */
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