aboutsummaryrefslogtreecommitdiff
path: root/grammar/grammar.go
diff options
context:
space:
mode:
authorRyo Nihei <nihei.dev@gmail.com>2022-05-21 14:01:09 +0900
committerRyo Nihei <nihei.dev@gmail.com>2022-05-22 15:44:47 +0900
commitb5ad1d30df993d68cc64c140bf1005b5490f2605 (patch)
tree919e3102866b4dcf4ed58c0a48227ee0c81f1f5d /grammar/grammar.go
parentProhibit applying #left, #right, #assign, and #prec to an error symbol (diff)
downloadcotia-b5ad1d30df993d68cc64c140bf1005b5490f2605.tar.gz
cotia-b5ad1d30df993d68cc64c140bf1005b5490f2605.tar.xz
Stop supporting SLR(1) and always use LALR(1)
Diffstat (limited to 'grammar/grammar.go')
-rw-r--r--grammar/grammar.go49
1 files changed, 4 insertions, 45 deletions
diff --git a/grammar/grammar.go b/grammar/grammar.go
index 410236b..368ede6 100644
--- a/grammar/grammar.go
+++ b/grammar/grammar.go
@@ -1286,16 +1286,8 @@ func (b *GrammarBuilder) genPrecAndAssoc(symTab *symbolTable, errSym symbol, pro
}, nil
}
-type Class string
-
-const (
- ClassSLR Class = "SLR(1)"
- ClassLALR Class = "LALR(1)"
-)
-
type compileConfig struct {
reportFileName string
- class Class
}
type CompileOption func(config *compileConfig)
@@ -1306,16 +1298,8 @@ func EnableReporting(fileName string) CompileOption {
}
}
-func SpecifyClass(class Class) CompileOption {
- return func(config *compileConfig) {
- config.class = class
- }
-}
-
func Compile(gram *Grammar, opts ...CompileOption) (*spec.CompiledGrammar, error) {
- config := &compileConfig{
- class: ClassLALR,
- }
+ config := &compileConfig{}
for _, opt := range opts {
opt(config)
}
@@ -1385,39 +1369,15 @@ func Compile(gram *Grammar, opts ...CompileOption) (*spec.CompiledGrammar, error
return nil, err
}
- var class string
- var automaton *lr0Automaton
- switch config.class {
- case ClassSLR:
- class = "slr"
-
- followSet, err := genFollowSet(gram.productionSet, firstSet)
- if err != nil {
- return nil, err
- }
-
- slr1, err := genSLR1Automaton(lr0, gram.productionSet, followSet)
- if err != nil {
- return nil, err
- }
-
- automaton = slr1.lr0Automaton
- case ClassLALR:
- class = "lalr"
-
+ var tab *ParsingTable
+ {
lalr1, err := genLALR1Automaton(lr0, gram.productionSet, firstSet)
if err != nil {
return nil, err
}
- automaton = lalr1.lr0Automaton
- }
-
- var tab *ParsingTable
- {
b := &lrTableBuilder{
- class: config.class,
- automaton: automaton,
+ automaton: lalr1.lr0Automaton,
prods: gram.productionSet,
termCount: len(terms),
nonTermCount: len(nonTerms),
@@ -1520,7 +1480,6 @@ func Compile(gram *Grammar, opts ...CompileOption) (*spec.CompiledGrammar, error
},
},
ParsingTable: &spec.ParsingTable{
- Class: class,
Action: action,
GoTo: goTo,
StateCount: tab.stateCount,