diff options
author | Ryo Nihei <nihei.dev@gmail.com> | 2021-05-19 00:03:03 +0900 |
---|---|---|
committer | Ryo Nihei <nihei.dev@gmail.com> | 2021-05-19 00:03:03 +0900 |
commit | 1f6e9ac5f10e4b0b68c1defaa473b719ee965a3e (patch) | |
tree | 979e56f5fb113ba3070e4328f9a02612d018e0a3 | |
parent | Remove the shorthand for --compression-level option from the compile command (diff) | |
download | tre-1f6e9ac5f10e4b0b68c1defaa473b719ee965a3e.tar.gz tre-1f6e9ac5f10e4b0b68c1defaa473b719ee965a3e.tar.xz |
Fix the initial state number
Since 0 represents an invalid value in a transition table, assign a number greater than or equal to 1 to states.
-rw-r--r-- | compiler/dfa.go | 6 |
1 files changed, 5 insertions, 1 deletions
diff --git a/compiler/dfa.go b/compiler/dfa.go index ad42322..b94fca8 100644 --- a/compiler/dfa.go +++ b/compiler/dfa.go @@ -16,7 +16,9 @@ type DFA struct { func genDFA(root astNode, symTab *symbolTable) *DFA { initialState := root.first() initialStateHash := initialState.hash() - stateMap := map[string]*symbolPositionSet{} + stateMap := map[string]*symbolPositionSet{ + initialStateHash: initialState, + } tranTab := map[string][256]string{} { follow := genFollowTable(root) @@ -104,6 +106,8 @@ func genDFA(root astNode, symTab *symbolTable) *DFA { func genTransitionTable(dfa *DFA) (*spec.TransitionTable, error) { state2Num := map[string]int{} for i, s := range dfa.States { + // Since 0 represents an invalid value in a transition table, + // assign a number greater than or equal to 1 to states. state2Num[s] = i + 1 } |