Example #1
0
// -----------------------------------------------------------------------------------------------------------------------------------------------
// Allocate an DFA tree node
func (dfa *DFA_PoolType) GetDFA() int {
	//fmt.Printf("at %s\n", com.LF())
	tmp := 0
	if dfa.Cur < dfa.Top && !dfa.Pool[dfa.Cur].IsUsed {
		//fmt.Printf("at %s\n", com.LF())
		tmp = dfa.Cur
		dfa.Cur++
	} else if dfa.Cur >= dfa.Top || dfa.NextFree == -1 {
		//fmt.Printf("at %s, dfa.Cur=%d dfa.Top=%d dfa.NextFree=%d\n", com.LF(), dfa.Cur, dfa.Top, dfa.NextFree)
		dfa.Top = 2 * dfa.Top
		newPool := make([]DFA_Type, dfa.Top, dfa.Top) // extend array
		copy(newPool, dfa.Pool)
		dfa.Pool = newPool
		tmp = dfa.Cur
		dfa.Cur++
	} else {
		//fmt.Printf("at %s\n", com.LF())
		tmp = dfa.NextFree
		dfa.NextFree = dfa.Pool[tmp].NextFree
	}
	dfa.Pool[tmp].NextFree = -1
	dfa.Pool[tmp].Rv = 0
	dfa.Pool[tmp].Next2 = dfa.Pool[tmp].Next2[:0]
	dfa.Pool[tmp].IsUsed = true
	dfa.Pool[tmp].A_IAm = tmp
	dfa.Pool[tmp].LineNo = com.LINE(2)
	return tmp
}
Example #2
0
// -----------------------------------------------------------------------------------------------------------------------------------------------
func (dfa *DFA_PoolType) AddEdge(fr, to int, on string) {
	// Check if edge already exists - if so skip this
	if !dfa.EdgeExists(fr, to, on) {
		dfa.Pool[fr].Next2 = append(dfa.Pool[fr].Next2, nfa.TransitionType{IsLambda: false, On: on, To: to, From: fr, LineNo: com.LINE(2)})
	}
}