예제 #1
0
def compile_df(dfcode):
	accumulator = 0
	i = 0
	output = ""
	signal.alarm(10)
	while(i < len(dfcode)):
		if variables.time_counter - variables.init_counter > 0:
				signal.alarm(0)
				irc.send_msg(variables.too_much_time_err, variables.channel)
				return "[NORESULT]"
		if dfcode[i] == 'x' or dfcode[i] == 'i':
			accumulator += 1
		elif dfcode[i] == 'd':
			accumulator -= 1
		elif dfcode[i] == 's' or dfcode[i] == 'k':
			accumulator *= accumulator
		elif dfcode[i] == 'o' or dfcode[i] == 'c':
			if accumulator == 0 or accumulator == 256:
				output += "0 "
			else:
				output += str(accumulator) + " "
		i += 1
	signal.alarm(0)
	output = irc.process_output(output)
	return output
예제 #2
0
파일: bfc.py 프로젝트: Benderx2/athena_bot
def compile_bf(bfcode):
	output = "Output: "
	bf_index = 0
	bfarr = [0] * 3000
	i = 0
	j = 0
	# build brace map i.e. return addresses
	bracestack, bracemap = [], {}
	while j < len(bfcode):
		if bfcode[j] == "[": bracestack.append(j)
		if bfcode[j] == "]":
			if len(bracestack) == 0:
				output = "Missing '['"
				return output
			start = bracestack.pop()
			bracemap[start] = j
			bracemap[j] = start
		j += 1
	if len(bracestack) != 0:
		output = "Missing ']'"
		return output
	signal.alarm(10)
	while i < len(bfcode):
		if variables.time_counter - variables.init_counter > 0:
			irc.send_msg(variables.too_much_timer_err, variables.channel)
			signal.alarm(0)
			return "[NORESULT]"
		if bfcode[i] == '<':
			if bf_index > 0:
				bf_index -= 1
			elif bf_index == 0:
				bf_index = 2999
		elif bfcode[i] == '>':
			if bf_index < 3000:
				bf_index += 1
			elif bf_index >= 2999:
				bf_index = 0
		elif bfcode[i] == '+':
			if bfarr[bf_index] == 255:
				bfarr[bf_index] = 0
			else:
				bfarr[bf_index] += 1
		elif bfcode[i] == '-':
			if bfarr[bf_index] == 0:
				bfarr[bf_index] = 255
			else:
				bfarr[bf_index] -= 1
		elif bfcode[i] == '.':
			if bfarr[bf_index] > 0 and bfarr[bf_index] < 255:
				output = output + chr(bfarr[bf_index])
			else:
				output = output + "[NON EXISTENT CHARACTER: " + str(bfarr[bf_index]) +"]"
		elif bfcode[i] == '[' and bfarr[bf_index] == 0:
			i = bracemap[i]
		elif bfcode[i] == ']' and bfarr[bf_index] != 0:
			i = bracemap[i]
		i += 1
	signal.alarm(0)
	output = irc.process_output(output)
	return output
예제 #3
0
파일: ulc.py 프로젝트: Benderx2/athena_bot
def compile_ul(ulcode):
	output = "Output: "
	ulstack = ["NULL"]
	i = 0
	signal.alarm(10)
	while i < len(ulcode):
		if variables.time_counter - variables.init_counter > 0:
			irc.send_msg(variables.too_much_timer_err, variables.channel)
			signal.alarm(0)
			return "[NORESULT]"
		if ulcode[i] == '~':
			if len(ulstack) < 2:
				output = variables.bestack_2item_err
				return output
			a = ulstack.pop()
			b = ulstack.pop()
			ulstack.append(a)
			ulstack.append(b)
		elif ulcode[i] == ':':
			if len(ulstack) < 1:
				output = variables.bestack_1item_err
				return output
			a = ulstack.pop()
			ulstack.append(a)
			ulstack.append(a)
		elif ulcode[i] == '!':
			if len(ulstack) < 1:
				output = variables.bestack_1item_err
				return output
			ulstack.pop()
		elif ulcode[i] == '*':
			if len(ulstack) < 2:
				output = variables.bestack_2item_err
				return output
			a = ulstack.pop()
			b = ulstack.pop()
			ulstack.append(b+a)
		elif ulcode[i] == 'a':
			if len(ulstack) < 1:
				output = variables.bestack_1item_err
				return output
			a = ulstack.pop()
			ulstack.append("(" + a + ")")
		elif ulcode[i] == '^':
			if len(ulstack) < 1:
				output = variables.bestack_1item_err
				return output
			a = ulstack.pop()
			ulcode = insert_string(ulcode, a, i+1)
		elif ulcode[i] == 'S':
			if len(ulstack) < 1:
				output = variables.bestack_1item_err
				return output
			output = output + ulstack.pop()
		elif ulcode[i] == '(':
			a = ""
			level = 0
			i += 1
			level += 1
			while(level > 0):
				if i > len(ulcode):
					output = "Error! Unterminated parentheses."
					return output
				if ulcode[i] == '(':
					level += 1
				elif ulcode[i] == ')':
					level -= 1
				if level > 0:
					a += ulcode[i]
				i += 1
			i -= 1
			ulstack.append(a)
		i += 1
	signal.alarm(0)
	output = irc.process_output(output)
	return output
예제 #4
0
파일: bec.py 프로젝트: Benderx2/athena_bot
def compile_be(becode):
		output = "Output: "
		bestack = [0]
		pc_dir = variables.right
		i = 0
		signal.alarm(10)
		while becode[i] != '@':
			if variables.time_counter - variables.init_counter > 0:
				signal.alarm(0)
				irc.send_msg(variables.too_much_time_err, variables.channel)
				return "[NORESULT]"
			if becode[i] == '+' or becode[i] == '-' or becode[i] == '/' or becode[i] == '*' or becode[i] == '%':
				if len(bestack) < 2:
					output = variables.bestack_2item_err
					return output
				else:
					a = bestack.pop()
					b = bestack.pop()
					if becode[i] == '+':
						bestack.append(a+b)
					elif becode[i] == '-':
						bestack.append(b-a)
					elif becode[i] == '*':
						bestack.append(a*b)
					elif becode[i] == '/':
						bestack.append(b/a)
					elif becode[i] == '%':
						bestack.append(b%a)
					else:
						output = variables.bestack_2item_err
						return output
			elif becode[i] == '!':
				if len(bestack) < 1:
					output = bestack_1item_err
					return output
				else:
					a = bestack.pop()
					if a == 0:
						bestack.append(1)
					else:
						bestack.append(0)
			elif becode[i] == '`':
				if len(bestack) < 2:
					output = variables.bestack_2item_err
					return output
				else:
					a = bestack.pop()
					b = bestack.pop()
					if(b > a):
						bestack.append(1)
					else:
						bestack.append(0)
			elif becode[i] == '<':
				pc_dir = variables.left
			elif becode[i] == '>':
				pc_dir = variables.right
			elif becode[i] == '?':
				pc_dir = randint(variables.left,variables.right)
			elif becode[i] == '_':
				if len(bestack) < 1:
					output = variables.bestack_1item_err
					return output
				else:
					a = bestack.pop()
					if a == 0:
						pc_dir = variables.right
					else:
						pc_dir = variables.left
			elif becode[i] == '|':
				if len(bestack) < 1:
					output = variables.bestack_1item_err
					return output
				else:
					a = bestack.pop()
					if a == 0:
						pc_dir = variables.down
					else:
						pc_dir = variables.up
			elif becode[i] == '"':
				j = i+1
				mark_found = False
				while j < len(becode):
					if becode[j] == '"':
						mark_found = True
						break
					else:			
						try:	
							bestack.append(ord(becode[j]))
						except (TypeError):
							bestack.append(ord(' '))
					j += 1
				if mark_found == False:
					output = variables.be_string_err
					return output
				i = j
			elif becode[i] == ':':
				if len(bestack) < 1:
					output = variables.bestack_1item_err
					return output
				else:
					a = bestack.pop()
					bestack.append(a)
					bestack.append(a)
			elif becode[i] == '\\':
				if len(bestack) < 2:
					output = variables.bestack_2item_err
					return output
				else:
					a = bestack.pop()
					b = bestack.pop()
					bestack.append(a)
					bestack.append(b)
			elif becode[i] == '.':
				if len(bestack) < 1:
					output = variables.bestack_1item_err
					return output
				else:
					a = bestack.pop()
					output = output + str(a)
			elif becode[i] == ',':
				if len(bestack) < 1:
					output = variables.bestack_1item_err
					return output
				else:
					a = bestack.pop()
					if (a) > 0 and (a) < 255:
						output = output + chr((a))
					else:
						output = output + "[NON-ASCII CHAR: " + str(a) + "]"
			elif becode[i] == '#':
				if pc_dir == variables.right:
					i += 1
				elif pc_dir == variables.left:
					i -= 1
				else: 
					output = variables.be_internal_err
					return output
			elif becode[i] == '$':
				if len(becode) < 1:
					output = "Stack underflow error!"
					return output
				else:
					bestack.pop()
			elif becode[i] == 'g':
				if len(bestack) < 2:
					output = variables.bestack_2item_err
					return output
				y_pos = bestack.pop()
				x_pos = bestack.pop()
				array_pos = x_pos
				if array_pos < 0 or array_pos > len(becode):
					bestack.append(0)
				else:
					bestack.append(ord(becode[array_pos]))
			elif becode[i] == '0' or becode[i] == '1' or becode[i] == '2' or becode[i] == '3' or becode[i] == '4' or becode[i] == '5' or becode[i] == '6' or becode[i] == '7' or becode[i] == '8' or becode[i] == '9':
				bestack.append(int(becode[i]))
			if pc_dir == variables.right:
				i += 1
			elif pc_dir == variables.left:
				i -= 1
			else:
				output = variables.be_internal_err
				return output
			if i < 0 or i >= len(becode):
				output = variables.be_oerflow_err
				return output
		signal.alarm(0)
		output = irc.process_output(output)
		return output