Skip to content

Possible off-by-one in genLR0items startRules #352

@marco-comini

Description

@marco-comini

Hi,

I think there may be an off-by-one bug in genLR0items.

The initial LR(0) kernels are seeded with:

startRules = [ Set.singleton (Lr0 rule 0) | rule <- [0..n_starts] ]

where n_starts = length (starts g).

This creates n_starts + 1 initial kernels.

However, elsewhere start rules seem to be treated as only the first n_starts rules, e.g. with logic like:

isStartRule rule = rule < n_starts

So the two conventions do not appear consistent.

In practice, with multiple %name directives, I observe one extra initial seeded state corresponding to the first ordinary grammar production after the synthetic start rules. This introduces states unrelated to any declared entry point.

It looks like the seed range in genLR0items should perhaps be:

[0 .. n_starts - 1]

instead of:

[0 .. n_starts]

I can provide a minimal reproducer if needed.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions