Implement is_at_mark
authorLukas Jiriste <ljiriste@student.42prague.com>
Thu, 4 Jul 2024 12:25:53 +0000 (14:25 +0200)
committerLukas Jiriste <ljiriste@student.42prague.com>
Sun, 21 Jul 2024 18:21:20 +0000 (20:21 +0200)
I've probably just forgotten to implement this function earlier.

ft_parse/ft_parsing_table_generate.c

index 5a61463891217cebc50485fa387e31be133c4d1d..236a0ef6f1928793f91eb1b4636d0c073f75fe8c 100644 (file)
@@ -6,7 +6,7 @@
 /*   By: ljiriste <ljiriste@student.42prague.com>   +#+  +:+       +#+        */
 /*                                                +#+#+#+#+#+   +#+           */
 /*   Created: 2024/06/27 11:16:53 by ljiriste          #+#    #+#             */
-/*   Updated: 2024/07/04 13:24:49 by ljiriste         ###   ########.fr       */
+/*   Updated: 2024/07/04 14:25:35 by ljiriste         ###   ########.fr       */
 /*                                                                            */
 /* ************************************************************************** */
 
@@ -389,10 +389,27 @@ t_ft_stat construct_state(t_vec *kernel, t_vec *states, const t_vec *rules, cons
        return (solve_gotos(state, states, rules, tokens));
 }
 
-int    is_at_mark(__attribute__((unused))const t_token *token, __attribute__((unused))const t_generator_state *state)
+int    is_at_mark(const t_token *token, const t_generator_state *state)
 {
-       ft_printf("is_at_mark is not yet implemented\n");
-       return (1);
+       size_t                          i;
+       const t_lr1_item        *item;
+
+       i = 0;
+       while (i < state->kernel.size)
+       {
+               item = ft_vec_caccess(&state->kernel, i);
+               if (!cmp_token_type(token, ft_vec_caccess(&item->core.rule->constituents, item->core.position)))
+                       return (1);
+               ++i;
+       }
+       while (i < state->closure.size)
+       {
+               item = ft_vec_caccess(&state->closure, i);
+               if (!cmp_token_type(token, ft_vec_caccess(&item->core.rule->constituents, item->core.position)))
+                       return (1);
+               ++i;
+       }
+       return (0);
 }
 
 t_ft_stat      solve_gotos(t_generator_state *state, t_vec *states, const t_vec *rules, const t_vec *tokens)