From 483cfdfd48511479f8e82519ff865326258eb054 Mon Sep 17 00:00:00 2001 From: Igor Dejanovic Date: Tue, 13 Feb 2024 23:15:06 +0100 Subject: [PATCH] fix: LR(1) items lookahead set calculation --- CHANGELOG.md | 1 + parglare/closure.py | 2 +- parglare/tables/__init__.py | 4 ++-- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 823e202..67f331d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -21,6 +21,7 @@ backward incompatible changes will start to apply when the projects goes 1.0 ### Fixed - Fix `to_str` failure when calculating the number of solutions in the context of optional match ([#147]). Thanks @LVrecar for the report and fix. +- Fix lookahead calculation in closure ### Changed - Drop support for Python 3.6/3.7 diff --git a/parglare/closure.py b/parglare/closure.py index 1199930..18315c5 100644 --- a/parglare/closure.py +++ b/parglare/closure.py @@ -30,7 +30,7 @@ def closure(state, itemset_type, first_sets=None): for prod in [p for p in state.grammar.productions if p.symbol == symbol]: new_item = LRItem(prod, 0, - follow if itemset_type is LR_1 else None) + set(follow) if itemset_type is LR_1 else None) if new_item not in state.items: # If the item doesn't exists yet add it and reprocess it. state.items.append(new_item) diff --git a/parglare/tables/__init__.py b/parglare/tables/__init__.py index 2711883..f981b62 100644 --- a/parglare/tables/__init__.py +++ b/parglare/tables/__init__.py @@ -238,10 +238,10 @@ def create_table(grammar, itemset_type=LR_1, start_production=1, update = False for state in states: - - # First refresh current state's follows + # First refresh state's follows closure(state, LR_1, first_sets) + for state in states: # Propagate follows to next states. GOTOs/ACTIONs keep # information about states created from this state inc_items = [i.get_pos_inc() for i in state.items]