Skip to content

Commit

Permalink
fix: LR(1) items lookahead set calculation
Browse files Browse the repository at this point in the history
  • Loading branch information
igordejanovic committed Feb 14, 2024
1 parent d0aca9e commit 483cfdf
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion parglare/closure.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions parglare/tables/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down

0 comments on commit 483cfdf

Please sign in to comment.