diff options
author | Ryo Nihei <nihei.dev@gmail.com> | 2022-05-21 14:01:09 +0900 |
---|---|---|
committer | Ryo Nihei <nihei.dev@gmail.com> | 2022-05-22 15:44:47 +0900 |
commit | b5ad1d30df993d68cc64c140bf1005b5490f2605 (patch) | |
tree | 919e3102866b4dcf4ed58c0a48227ee0c81f1f5d /grammar/slr1.go | |
parent | Prohibit applying #left, #right, #assign, and #prec to an error symbol (diff) | |
download | cotia-b5ad1d30df993d68cc64c140bf1005b5490f2605.tar.gz cotia-b5ad1d30df993d68cc64c140bf1005b5490f2605.tar.xz |
Stop supporting SLR(1) and always use LALR(1)
Diffstat (limited to 'grammar/slr1.go')
-rw-r--r-- | grammar/slr1.go | 61 |
1 files changed, 0 insertions, 61 deletions
diff --git a/grammar/slr1.go b/grammar/slr1.go deleted file mode 100644 index b11a66f..0000000 --- a/grammar/slr1.go +++ /dev/null @@ -1,61 +0,0 @@ -package grammar - -import "fmt" - -type slr1Automaton struct { - *lr0Automaton -} - -func genSLR1Automaton(lr0 *lr0Automaton, prods *productionSet, follow *followSet) (*slr1Automaton, error) { - for _, state := range lr0.states { - for prodID := range state.reducible { - prod, ok := prods.findByID(prodID) - if !ok { - return nil, fmt.Errorf("reducible production not found: %v", prodID) - } - - flw, err := follow.find(prod.lhs) - if err != nil { - return nil, err - } - - var reducibleItem *lrItem - for _, item := range state.items { - if item.prod != prodID { - continue - } - - reducibleItem = item - break - } - if reducibleItem == nil { - for _, item := range state.emptyProdItems { - if item.prod != prodID { - continue - } - - reducibleItem = item - break - } - if reducibleItem == nil { - return nil, fmt.Errorf("reducible item not found; state: %v, production: %v", state.num, prodID) - } - } - - if reducibleItem.lookAhead.symbols == nil { - reducibleItem.lookAhead.symbols = map[symbol]struct{}{} - } - - for sym := range flw.symbols { - reducibleItem.lookAhead.symbols[sym] = struct{}{} - } - if flw.eof { - reducibleItem.lookAhead.symbols[symbolEOF] = struct{}{} - } - } - } - - return &slr1Automaton{ - lr0Automaton: lr0, - }, nil -} |