Skip to content

Bug in LL(1) parse table #151

@ahmedriza

Description

@ahmedriza

I think there's a bug in the LL(1) parse table generation.

Example grammar to demonstrate the issue:

%%

S -> A;
A -> "a" | ;

First and follow sets are created correctly, which are:

First set:

┌────────┬───────────┐
│ Symbol │ First set │
├────────┼───────────┤
│ S      │ "a", ε    │
├────────┼───────────┤
│ A      │ "a", ε    │
└────────┴───────────┘

Follow set:

┌────────┬────────────┐
│ Symbol │ Follow set │
├────────┼────────────┤
│ S      │ $          │
├────────┼────────────┤
│ A      │ $          │
└────────┴────────────┘

However, the parse table is incorrect:

LL(1) parsing table:

┌───┬─────┬───┐
│   │ "a" │ $ │
├───┼─────┼───┤
│ S │ 1   │   │
├───┼─────┼───┤
│ A │ 2   │ 3 │
└───┴─────┴───┘

I think it should be

┌───┬─────┬───┐
│   │ "a" │ $ │
├───┼─────┼───┤
│ S │ 1   │ 1 │
├───┼─────┼───┤
│ A │ 2   │ 3 │
└───┴─────┴───┘

I think this is due to the following line

https://github.com/DmitrySoshnikov/syntax/blob/master/src/ll/ll-parsing-table.js#L190

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions