Пример #1
0
//@Override
func (this *NumVal) GetNFAStates(startState, acceptingState *automata.NFAState, rules map[string]*Rule) {
	if this.values.Len() == 0 {
		startState.AddTransitEpsilon(acceptingState)
		return
	}

	var radix int
	if this.base == "B" || this.base == "b" {
		radix = 2
	} else if this.base == "D" || this.base == "d" {
		radix = 10
	} else if this.base == "X" || this.base == "x" {
		radix = 16
	} else {
		panic("NumVal base can not be handled.")
	}

	current := startState
	e := this.values.Front()
	for j := 0; j < this.values.Len()-1; j++ {
		v := e.Value.(string)
		i, _ := strconv.ParseInt(v, radix, 64)
		current = current.AddTransitInt1(int(i))
		e = e.Next()
	}
	v := e.Value.(string)
	i, _ := strconv.ParseInt(v, radix, 64)
	current.AddTransitInt2(int(i), acceptingState)
}
Пример #2
0
func (this *ProseVal) GetNFAStates(startState, acceptingState *automata.NFAState, rules map[string]*Rule) {
	if len(this.value) == 0 {
		startState.AddTransitEpsilon(acceptingState)
		return
	}

	current := startState
	buffer := []byte(this.value)
	for j := 0; j < len(buffer); j++ {
		if j < len(buffer)-1 {
			current = current.AddTransitByte1(buffer[j])
		} else {
			current = current.AddTransitByte2(buffer[j], acceptingState)
		}
	}
}
Пример #3
0
func (this *Repetition) GetNFAStates(startState, acceptingState *automata.NFAState, rules map[string]*Rule) {
	if this.repeat == nil {
		this.element.GetNFAStates(startState, acceptingState, rules)
		return
	}

	min := this.repeat.GetMin()
	max := this.repeat.GetMax()

	if min < 0 /*|| max < 0*/ {
		panic("Min value of a repeat element can not be less than zero.")
	}

	if max == -1 {
		if min == 0 {
			//              min == 0 && max == -1
			startState.AddTransitEpsilon(acceptingState)
			this.element.GetNFAStates(acceptingState, acceptingState, rules)
			return
		} else {
			//              min > 0 && max == -1
			current := startState
			for j := 0; j < min-1; j++ {
				next := automata.NewNFAState()
				this.element.GetNFAStates(current, next, rules)
				current = next
			}
			this.element.GetNFAStates(current, acceptingState, rules)
			this.element.GetNFAStates(acceptingState, acceptingState, rules)
			return
		}
	} else {
		if min == 0 {
			//              min == 0 && max > 0
			current := startState
			for j := 0; j < max-1; j++ {
				current.AddTransitEpsilon(acceptingState)
				next := automata.NewNFAState()
				this.element.GetNFAStates(current, next, rules)
				current = next
			}
			current.AddTransitEpsilon(acceptingState)
			this.element.GetNFAStates(current, acceptingState, rules)
			return
		} else if min == max {
			//              0 < min == max
			current := startState
			for j := 0; j < max-1; j++ {
				next := automata.NewNFAState()
				this.element.GetNFAStates(current, next, rules)
				current = next
			}
			this.element.GetNFAStates(current, acceptingState, rules)
			return
		} else if min < max {
			//              0 < min < max
			current := startState
			for j := 0; j < min; j++ {
				next := automata.NewNFAState()
				this.element.GetNFAStates(current, next, rules)
				current = next
			}
			for j := 0; j < max-min-1; j++ {
				current.AddTransitEpsilon(acceptingState)
				next := automata.NewNFAState()
				this.element.GetNFAStates(current, next, rules)
				current = next
			}
			current.AddTransitEpsilon(acceptingState)
			this.element.GetNFAStates(current, acceptingState, rules)
			return
		} else {
			panic("Max can not less than min")
		}
	}
}
Пример #4
0
func (this *Option) GetNFAStates(startState, acceptingState *automata.NFAState, rules map[string]*Rule) {
	startState.AddTransitEpsilon(acceptingState)
	this.alternation.GetNFAStates(startState, acceptingState, rules)
}