예제 #1
0
파일: parser.py 프로젝트: stessaris/coala
	def p_formula(self,t):
		''' formula : term_boolean 
					| term_boolean COMMA formula
					| term_boolean COLON binding_or_range 
					| term_boolean COLON binding_or_range COMMA formula '''
		if len(t) == 4:
			if t[2] == ":":
				if t[1] is None: t[0] = ps.atom_list()
				elif t[1].is_false(): t[0] = t[1]
				else:
					t[1].binding = t[3] 
					t[0] = ps.atom_list(t[1])
			else:
				if t[1] is None: t[0] = t[3]
				elif t[1].is_false(): t[0] = t[1]
				elif t[3].is_false(): t[0] = t[3]
				else:
					t[3].combine(t[1])
					t[0] = t[3]
		elif len(t) == 6:
			if t[1] is None: t[0] = t[5]
			elif t[1].is_false():
				t[0] = t[1]
			elif t[5].is_false(): 
				#t[1].binding = t[5] 
				t[0] = t[5]
			else:
				t[1].binding = t[3]
				t[5].combine(t[1])
				t[0] = t[5]
		else:
			if t[1] is None: t[0] = ps.atom_list()
			elif t[1].is_false(): t[0] = t[1]
			else: t[0] = ps.atom_list(t[1])
예제 #2
0
파일: parser.py 프로젝트: stessaris/coala
	def p_term_number_list(self,t):
		''' term_number_list : term_numeric
					| term_numeric COMMA term_number_list '''
		if len(t) == 2: 
			t[0] = ps.atom_list(t[1])
		else: 
			t[3].combine(t[1],reverse=True)
			t[0] = t[3]
예제 #3
0
파일: parser.py 프로젝트: stessaris/coala
	def p_fluent_formula(self,t): # f_1,...,f_n
		''' fluent_formula : term_equalpart
					| term_equalpart COMMA fluent_formula
					| term_equalpart COLON binding_or_range
					| term_equalpart COLON binding_or_range COMMA fluent_formula'''
		if len(t) == 4:
			if t[2] == ':':
				t[0] = ps.atom_list(ps.fluent_multival(t[1],t[3],int_operator=type(t[3]==list)))
			else:
				t[3].append(t[1])
				t[0] = t[3]
		elif len(t) == 6:
			res = ps.fluent_multival(t[1],t[3],int_operator=type(t[3]==list))
			t[5].append(res)
			t[0] = t[5]
		else:
			t[0] = ps.atom_list(t[1])
예제 #4
0
파일: parser.py 프로젝트: stessaris/coala
	def p_bindings(self,t):
		''' bindings : binding
					| bindings COMMA binding'''
		if len(t) == 2: 
			t[0] = ps.atom_list(t[1])
		else: 
			t[1].combine(t[3])
			t[0] = t[1]
예제 #5
0
파일: parser.py 프로젝트: stessaris/coala
	def p_flu_fact(self,t): # <fluent> f_1,...,f_n <where> bla.
		''' flu_fact : FLU fluent_formula where_part
					| INT fluent_formula where_part
					| defined_fluent fluent_formula where_part '''		
		line,filename=self.get_meta(t.lineno(1))
		if t[1] == '<int>':
			stuff = []
			if type(t[2]) == ps.atom_list:
				for x in t[2]:
					if type(x) == ps.fluent_multival:
						if type(x.multidomain) == list:
							int_dom = ps.atom_list(x.multidomain)
						else:
							int_dom = x.multidomain
						
						#stuff.append(x.content)
						stuff.append(ps.integer_fact(ps.atom_list(x.content),int_dom,t[3],line=line,filename=filename))
					else:
						stuff.append(ps.integer_fact(ps.atom_list(x),None,t[3],line=line,filename=filename))
				#t[0] = ps.integer_fact(ps.atom_list(stuff),None,t[3],line=line,filename=filename)
				t[0] = ps.atom_list(stuff)
			else:
				t[0] = ps.integer_fact(ps.atom_list(t[2]),None,t[3],line=line,filename=filename)
		elif t[1] not in ['<fluent>','fluent']:
			t[0] = ps.defined_fluent_fact(t[2],t[3],line=line,filename=filename)
		else:
			
			if type(t[2]) == ps.atom_list: # Get integer fluent declarations
				result = []
				previous = []
				t[2].get_children().reverse() # Reverse order that we get them as expected
				for x in t[2]: # accumulate facts until there is a domain statement
					if type(x) == ps.fluent_multival:
						domain = x.multidomain
						if x.is_int:
							if type(x.multidomain) == list:
								domain = ps.atom_list(x.multidomain)
							elif type(x.multidomain) == ps.value_range and len(x.multidomain.content) == 2:
								lower = x.multidomain.content[0]
								upper = x.multidomain.content[1]
								domain = ps.atom_list(lower,upper)
							else:
								domain = x.multidomain
							
							result.append(ps.integer_fact(ps.atom_list(previous+[ps.unknown(x.content)]),domain,t[3],line=line,filename=filename))
						else:
							if type(x.multidomain) == ps.value_range and len(x.multidomain.content) == 2:
								lower = x.multidomain.content[0] #clingo 5..10 domain statement
								upper = x.multidomain.content[1]
								dotted_domain=(lower,upper)
								for y in previous:
									y.dotted_domain = dotted_domain
								result.append(ps.fluent_fact(ps.atom_list(previous+[x]),t[3],dotted_domain=dotted_domain,line=line,filename=filename))
							else:
								for y in previous:
									y.multidomain = domain
								result.append(ps.fluent_fact(ps.atom_list(previous+[x]),t[3],multivalued=domain,line=line,filename=filename))
							#add list for this domain.
						previous = []
					else:
						previous.append(x)
				result.append(ps.fluent_fact(ps.atom_list(previous),t[3],line=line,filename=filename))
				t[0] = ps.atom_list(result)
			
# 			if type(t[2]) == ps.atom_list: # Get integer fluent declarations
# 				others = []
# 				regular = []
# 				for x in t[2]: # This happens if integer and non_integers are mixed in one declaration.
# 					if type(x) == ps.fluent_multival:
# 						if type(x.multidomain) == list:
# 							if x.is_int:
# 								others.append(ps.integer_fact(ps.atom_list(x.content),ps.atom_list(x.multidomain),t[3],line=line,filename=filename))
# 							else:
# 								regular.append(ps.fluent_fact(ps.atom_list(x),t[3],line=line,filename=filename))						 
# 						elif type(x.multidomain)==ps.value_range and len(x.multidomain.content) == 2:
# 							lower = x.multidomain.content[0]
# 							upper = x.multidomain.content[1]
# 							if x.is_int:
# 								others.append(ps.integer_fact(ps.atom_list(x.content),ps.atom_list(lower,upper),t[3],line=line,filename=filename))
# 							else:
# 								others.append(ps.fluent_fact(ps.atom_list(x),t[3],dotted_domain=(lower,upper),line=line,filename=filename))
# 						else:
# 							regular.append(ps.fluent_fact(ps.atom_list(x),t[3],line=line,filename=filename))
# 					else:
# 						regular.append(ps.fluent_fact(ps.atom_list(x),t[3],line=line,filename=filename))
# 				if len(others) > 0:
# 					if len(regular)+len(others)>1:
# 						if len(others) == 1:
# 							int_dom=others[0].domain
# 							t[0] = ps.integer_fact(t[2],int_dom,t[3],line=line,filename=filename)								
# 						else:
# 							t[0] = ps.atom_list(regular,others)
# 					else:
# 						t[0] = others[0]
# 				else:
# 					t[0] = ps.fluent_fact(t[2],t[3],line=line,filename=filename)
			else:
				#print "Do WE even get here? <-- NO."
				t[0] = ps.fluent_fact(t[2],t[3],line=line,filename=filename)