diff options
| author | Ryo Nihei <nihei.dev@gmail.com> | 2021-08-18 00:03:59 +0900 |
|---|---|---|
| committer | Ryo Nihei <nihei.dev@gmail.com> | 2021-08-18 00:03:59 +0900 |
| commit | e110a6ff4073799d00c7d3400ac022f758a03e40 (patch) | |
| tree | e194e63debc48a53e5f9ec77075bd8ad0dcfa25f /grammar/lalr1.go | |
| parent | Fix panic on a syntax error (diff) | |
| download | cotia-e110a6ff4073799d00c7d3400ac022f758a03e40.tar.gz cotia-e110a6ff4073799d00c7d3400ac022f758a03e40.tar.xz | |
Set look-ahead symbols to items before generating a SLR(1) parsing table
Diffstat (limited to 'grammar/lalr1.go')
| -rw-r--r-- | grammar/lalr1.go | 19 |
1 files changed, 18 insertions, 1 deletions
diff --git a/grammar/lalr1.go b/grammar/lalr1.go index fc15942..f1b8149 100644 --- a/grammar/lalr1.go +++ b/grammar/lalr1.go @@ -42,7 +42,24 @@ func genLALR1Automaton(lr0 *lr0Automaton, prods *productionSet, first *firstSet) } if p.isEmpty() { - state.emptyProdItems = append(state.emptyProdItems, item) + var reducibleItem *lrItem + for _, it := range state.emptyProdItems { + if it.id != item.id { + continue + } + + reducibleItem = it + break + } + if reducibleItem == nil { + return nil, fmt.Errorf("reducible item not found: %v", item.id) + } + if reducibleItem.lookAhead.symbols == nil { + reducibleItem.lookAhead.symbols = map[symbol]struct{}{} + } + for a := range item.lookAhead.symbols { + reducibleItem.lookAhead.symbols[a] = struct{}{} + } propDests = append(propDests, &stateAndLRItem{ kernelID: state.id, |
