Change the code to accommodate the zeroth rule
authorLukas Jiriste <ljiriste@student.42prague.com>
Thu, 4 Jul 2024 12:45:37 +0000 (14:45 +0200)
committerLukas Jiriste <ljiriste@student.42prague.com>
Sun, 21 Jul 2024 18:21:20 +0000 (20:21 +0200)
ft_parse/ft_parsing_table_generate.c

index 236a0ef6f1928793f91eb1b4636d0c073f75fe8c..e61b67e6913bd95b8379d26c749e6e4ff47f0ff6 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 14:25:35 by ljiriste         ###   ########.fr       */
+/*   Updated: 2024/07/04 14:36:08 by ljiriste         ###   ########.fr       */
 /*                                                                            */
 /* ************************************************************************** */
 
@@ -203,7 +203,7 @@ size_t      find_kernel(const t_vec *kernel, const t_vec *states)
 
 const t_token  *get_next_token(const t_marked_grammar_rule *rule)
 {
-       return (ft_vec_caccess(&rule->rule->constituents, rule->position + 1));
+       return (ft_vec_caccess(&rule->rule->constituents, rule->position));
 }
 
 int    is_terminal_token(const t_token *token, const t_vec *tokens)
@@ -240,7 +240,7 @@ t_ft_stat   add_first(t_vec *lookahead, const t_token *token, const t_vec *rules,
                return (res);
        }
        rule.position = 0;
-       i = 0;
+       i = 1;
        while (i < rules->size)
        {
                rule.rule = ft_vec_caccess(rules, i);
@@ -312,7 +312,7 @@ t_ft_stat   add_predictions(t_vec *closure, const t_lr1_item *item, const t_vec *r
        t_lr1_item                              new_item;
        t_ft_stat                               res;
 
-       i = 0;
+       i = 1;
        while (i < rules->size)
        {
                new_item.core.rule = ft_vec_caccess(rules, i);
@@ -521,7 +521,7 @@ t_ft_stat   add_constituents(t_vec *tokens, const t_vec *constituents, const t_vec
        while (i < constituents->size)
        {
                token = ft_vec_caccess(constituents, i);
-               if (ft_vec_contains(tokens, token, void_cmp_token_type))
+               if (ft_vec_contains(tokens, token, void_cmp_token_type) || !cmp_token_type(token, &empty_token))
                {
                        ++i;
                        continue ;