예제 #1
0
def p_expr_union(t):
	'expr : expr UNION expr'
	state = t[1].state
	symbol = t[1].symbol
	trans = t[1].trans 
	
	for i in range(0, len(t[3].state)):
		state.append(t[3].state[i] + t[1].final[0])
	
	state += [t[3].final[0] + t[1].final[0] + 1, t[3].final[0] + t[1].final[0] + 2]
	state.sort()
	
	initial = t[3].final[0] + t[1].final[0] + 1
	final = [t[3].final[0] + t[1].final[0] + 2]

	symbol += t[3].symbol
	symbol = list(set(symbol))
	symbol.sort()

	for i in range(0, len(t[3].trans)):
		trans.append([[t[3].trans[i][0][0] + t[1].final[0], t[3].trans[i][0][1]], t[3].trans[i][1] + t[1].final[0]])
	trans.append([[initial, 'eps'], t[1].initial])
	trans.append([[initial, 'eps'], t[3].initial + t[1].final[0]])
	trans.append([[t[1].final[0], 'eps'], final[0]])
	trans.append([[t[3].final[0] + t[1].final[0], 'eps'], final[0]])

	t[0] = fa.eNFA(state, symbol, trans, initial, final)	
예제 #2
0
def p_expr_closure(t):
	'expr : expr CLOSURE'
	initial = t[1].initial
	state = t[1].state
	symbol = t[1].symbol
	trans = t[1].trans
	final = t[1].final
	
	state += [final[0]+ 1, final[0]+2]
	state.sort()
	
	initial = final[0]+ 1
	final = [final[0] + 2]

	trans += [[[initial, 'eps'], t[1].initial], [[initial, 'eps'], final[0]], [[t[1].final[0], 'eps'], t[1].initial], [[t[1].final[0], 'eps'], final[0]]]

	t[0] = fa.eNFA(state, symbol, trans, initial, final)
예제 #3
0
def p_expr_concate(t):
	'expr : expr CONCATE expr'
	initial = t[1].initial
	state = t[1].state
	symbol = t[1].symbol
	trans = t[1].trans 
	
	for i in range(0, len(t[3].state)):
		state.append(t[3].state[i] + t[1].final[0])
	state.sort()

	symbol += t[3].symbol
	symbol = list(set(symbol))
	symbol.sort()

	for i in range(0, len(t[3].trans)):
		trans.append([[t[3].trans[i][0][0] + t[1].final[0], t[3].trans[i][0][1]], t[3].trans[i][1] + t[1].final[0]])
	trans.append([[t[1].final[0], 'eps'], t[3].initial + t[1].final[0]])
	
	final = [t[3].final[0] + t[1].final[0]]

	t[0] = fa.eNFA(state, symbol, trans, initial, final)
예제 #4
0
def p_expr_sym(t):
	'expr : SIM'
	t[0] = fa.eNFA([1, 2], [t[1]], [[[1, t[1]], 2]], 1, [2])
예제 #5
0
def p_expr_eps(t):
	'expr : EPSILON'
	t[0] = fa.eNFA([1, 2], [], [[[1, 'eps'], 2]], 1, [2])