/* By: ljiriste <ljiriste@student.42prague.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/06/27 11:16:53 by ljiriste #+# #+# */
-/* Updated: 2024/07/11 19:56:28 by ljiriste ### ########.fr */
+/* Updated: 2024/07/11 20:03:26 by ljiriste ### ########.fr */
/* */
/* ************************************************************************** */
void add_reduce(t_vec *lookahead, const t_lr1_item *item, const t_vec *tokens, const t_vec *rules)
{
size_t i;
+ size_t rule_num;
const t_token *token;
t_parser_action *action;
{
token = ft_vec_caccess(&item->lookahead, i);
action = ft_vec_access(lookahead, get_token_position(token, tokens));
- action->type = parser_reduce;
- action->number = get_rule_index(item->core.rule, rules);
+ rule_num = get_rule_index(item->core.rule, rules);
+ if (rule_num == 0)
+ action->type = parser_accept;
+ else
+ {
+ action->type = parser_reduce;
+ action->number = rule_num - 1;
+ }
++i;
}
return ;
res = construct_states(&states, &table->rules, &table->tokens);
if (res != success)
return (res);
- remove_zeroth_rule(&table->rules);
res = translate_to_table(table, &states);
if (res != success)
return (res);
ft_vec_free(&states, void_free_generator_state);
+ remove_zeroth_rule(&table->rules);
return (success);
}