diff options
author | Ryo Nihei <nihei.dev@gmail.com> | 2021-09-01 23:57:02 +0900 |
---|---|---|
committer | Ryo Nihei <nihei.dev@gmail.com> | 2021-09-02 00:01:35 +0900 |
commit | 8832b64b4227245e45f9a24d543c1b80168c489d (patch) | |
tree | 20ed014caa923254d8e7870241225d8c20f7d2b4 /grammar/grammar.go | |
parent | Remove the expected terminals field from the parsing table (diff) | |
download | urubu-8832b64b4227245e45f9a24d543c1b80168c489d.tar.gz urubu-8832b64b4227245e45f9a24d543c1b80168c489d.tar.xz |
Support LAC (lookahead correction)
Diffstat (limited to 'grammar/grammar.go')
-rw-r--r-- | grammar/grammar.go | 7 |
1 files changed, 7 insertions, 0 deletions
diff --git a/grammar/grammar.go b/grammar/grammar.go index efa0f35..7e86ea8 100644 --- a/grammar/grammar.go +++ b/grammar/grammar.go @@ -1038,9 +1038,12 @@ 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 @@ -1053,6 +1056,8 @@ func Compile(gram *Grammar, opts ...CompileOption) (*spec.CompiledGrammar, error automaton = slr1.lr0Automaton case ClassLALR: + class = "lalr" + lalr1, err := genLALR1Automaton(lr0, gram.productionSet, firstSet) if err != nil { return nil, err @@ -1064,6 +1069,7 @@ func Compile(gram *Grammar, opts ...CompileOption) (*spec.CompiledGrammar, error var tab *ParsingTable { b := &lrTableBuilder{ + class: config.class, automaton: automaton, prods: gram.productionSet, termCount: len(terms), @@ -1150,6 +1156,7 @@ func Compile(gram *Grammar, opts ...CompileOption) (*spec.CompiledGrammar, error }, }, ParsingTable: &spec.ParsingTable{ + Class: class, Action: action, GoTo: goTo, StateCount: tab.stateCount, |