From 1f6e9ac5f10e4b0b68c1defaa473b719ee965a3e Mon Sep 17 00:00:00 2001 From: Ryo Nihei Date: Wed, 19 May 2021 00:03:03 +0900 Subject: 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. --- compiler/dfa.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'compiler/dfa.go') 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 } -- cgit v1.2.3