syntax icon indicating copy to clipboard operation
syntax copied to clipboard

Bug in LL(1) parse table

Open ahmedriza opened this issue 10 months ago • 0 comments

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

ahmedriza avatar Apr 20 '24 21:04 ahmedriza