def jumpifneqs_i(interpret: i.Interpret, instruction): label_name = list(instruction)[0].text if label_name not in interpret.label_dict.keys(): exit(52) symb2_type, symb2_value = interpret.data_stack.pop() if len(interpret.data_stack) == 0: exit(56) symb1_type, symb1_value = interpret.data_stack.pop() if symb1_value is None or symb2_value is None: exit(56) if symb1_type == 'nil' or symb2_type == 'nil': if symb1_type != symb2_type: interpret.inst_index = interpret.label_dict[label_name] elif symb1_type != symb2_type: exit(53) elif symb1_type == 'bool': if str(symb1_value) != str(symb2_value): interpret.inst_index = interpret.label_dict[label_name] elif symb1_type == 'string': symb1_value = replace_escape_sequences(symb1_value) symb2_value = replace_escape_sequences(symb2_value) if symb1_value != symb2_value: interpret.inst_index = interpret.label_dict[label_name] elif symb1_type == 'int': if symb1_value != symb2_value: interpret.inst_index = interpret.label_dict[label_name] else: exit(53)
def eq_i(interpret: i.Interpret, instruction): var_frame, var_name = var_prepare(instruction, interpret) symb1_type, symb1_value = interpret.get_type_and_value_of_symb( list(instruction)[1]) symb2_type, symb2_value = interpret.get_type_and_value_of_symb( list(instruction)[2]) if symb1_value is None or symb2_value is None: exit(56) if symb1_type == 'nil' or symb2_type == 'nil': if symb1_type == symb2_type: var_frame[var_name] = tuple(['bool', True]) else: var_frame[var_name] = tuple(['bool', False]) elif symb1_type != symb2_type: exit(53) elif symb1_type == 'bool': var_frame[var_name] = tuple( ['bool', str(symb1_value) == str(symb2_value)]) elif symb1_type == 'string': symb1_value = replace_escape_sequences(symb1_value) symb2_value = replace_escape_sequences(symb2_value) var_frame[var_name] = tuple(['bool', symb1_value == symb2_value]) elif symb1_type == 'int': var_frame[var_name] = tuple(['bool', symb1_value == symb2_value]) else: exit(53)
def popframe_i(interpret: i.Interpret, instruction): if len(interpret.frame_stack) == 0: exit(55) interpret.tmp_frame = interpret.frame_stack.pop() if len(interpret.frame_stack) != 0: interpret.local_frame = interpret.frame_stack[-1] else: interpret.local_frame = None
def concat_i(interpret: i.Interpret, instruction): var_frame, var_name = var_prepare(instruction, interpret) symb1_type, symb1_value = interpret.get_type_and_value_of_symb( list(instruction)[1]) symb2_type, symb2_value = interpret.get_type_and_value_of_symb( list(instruction)[2]) if symb1_value is None or symb2_value is None: exit(56) if symb1_type != 'string' or symb2_type != 'string': exit(53) var_frame[var_name] = tuple([symb1_type, symb1_value + symb2_value])
def mul_i(interpret: i.Interpret, instruction): var_frame, var_name = var_prepare(instruction, interpret) symb1_type, symb1_val = interpret.get_type_and_value_of_symb( list(instruction)[1]) symb2_type, symb2_val = interpret.get_type_and_value_of_symb( list(instruction)[2]) if symb1_val is None or symb2_val is None: exit(56) if symb1_type != 'int' or symb2_type != 'int': exit(53) result = symb1_val * symb2_val var_frame[var_name] = tuple([symb1_type, result])
def setup(self): #os.chdir(r"C:\Program Files (x86)\Google\Chrome\Application") os.chdir(config.chrome_install_path) cmd = "chrome.exe --remote-debugging-port=9222" os.popen(cmd) time.sleep(1) self.chrome = PyChromeDevTools.ChromeInterface() self.options = webdriver.ChromeOptions() self.options._debugger_address = "localhost:9222" self.driver = webdriver.Chrome(chrome_options=self.options) Interpret.replace_driver(self.actions, self.driver) Interpret.replace_chrome(self.actions, self.chrome) self.chrome.Profiler.enable() self.chrome.Profiler.startPreciseCoverage()
def getchar_i(interpret: i.Interpret, instruction): var_frame, var_name = var_prepare(instruction, interpret) symb1_type, symb1_value = interpret.get_type_and_value_of_symb( list(instruction)[1]) symb2_type, symb2_value = interpret.get_type_and_value_of_symb( list(instruction)[2]) if symb1_value is None or symb2_value is None: exit(56) if symb1_type != 'string' or symb2_type != 'int': exit(53) if 0 > symb2_value or symb2_value > len(symb1_value) - 1: exit(58) var_frame[var_name] = tuple([symb1_type, symb1_value[symb2_value]])
def __init__(self): self.driver = webdriver self.interpret = Interpret() self.casename = '' self.actions = [] self.testcases = [] self.case_factroy()
def move_i(interpret: i.Interpret, instruction): var_frame, var_name = var_prepare(instruction, interpret) symb1_type, symb1_value = interpret.get_type_and_value_of_symb( list(instruction)[1]) if symb1_value is None: exit(56) var_frame[var_name] = tuple([symb1_type, symb1_value])
def stri2int_i(interpret: i.Interpret, instruction): var_frame, var_name = var_prepare(instruction, interpret) symb1_type, symb1_value = interpret.get_type_and_value_of_symb( list(instruction)[1]) symb2_type, symb2_value = interpret.get_type_and_value_of_symb( list(instruction)[2]) if symb1_value is None or symb2_value is None: exit(56) if symb1_type != 'string' or symb2_type != 'int': exit(53) if 0 > symb2_value or symb2_value > len(symb1_value) - 1: exit(58) try: var_frame[var_name] = tuple(['int', ord(symb1_value[symb2_value])]) except: exit(58) # mozna jiny kod, neni specifikovano jak se ma ukoncit
def strlen_i(interpret: i.Interpret, instruction): var_frame, var_name = var_prepare(instruction, interpret) symb1_type, symb1_val = interpret.get_type_and_value_of_symb( list(instruction)[1]) if symb1_val is None: exit(56) if symb1_type != 'string': exit(53) var_frame[var_name] = tuple(['int', len(symb1_val)])
def setchar_i(interpret: i.Interpret, instruction): var_frame, var_name = var_prepare(instruction, interpret) var_type, var_value = interpret.get_type_and_value_of_var( list(instruction)[0]) symb1_type, symb1_value = interpret.get_type_and_value_of_symb( list(instruction)[1]) symb2_type, symb2_value = interpret.get_type_and_value_of_symb( list(instruction)[2]) if symb1_value is None or symb2_value is None or var_value is None: exit(56) if symb1_type != 'int' or symb2_type != 'string' or var_type != 'string': exit(53) if 0 > symb1_value or symb1_value > len(var_value) - 1 or len( symb2_value) == 0: exit(58) symb2_value = replace_escape_sequences(symb2_value) result = var_value[:symb1_value] + symb2_value[0] + var_value[symb1_value + 1:] var_frame[var_name] = tuple([symb2_type, result])
def exit_i(interpret: i.Interpret, instruction): symb1_type, symb1_value = interpret.get_type_and_value_of_symb( list(instruction)[0]) if symb1_value is None: exit(56) if symb1_type != 'int': exit(53) if 0 <= symb1_value <= 49: exit(symb1_value) else: exit(57)
def jumpifeq_i(interpret: i.Interpret, instruction): label_name = list(instruction)[0].text if label_name not in interpret.label_dict.keys(): exit(52) symb1_type, symb1_value = interpret.get_type_and_value_of_symb( list(instruction)[1]) symb2_type, symb2_value = interpret.get_type_and_value_of_symb( list(instruction)[2]) if symb1_value is None or symb2_value is None: exit(56) if symb1_type == 'nil' or symb2_type == 'nil': if symb1_type == symb2_type: interpret.inst_index = interpret.label_dict[label_name] elif symb1_type != symb2_type: exit(53) elif symb1_type == 'bool': if str(symb1_value) == str(symb2_value): interpret.inst_index = interpret.label_dict[label_name] elif symb1_type == 'string': symb1_value = replace_escape_sequences(symb1_value) symb2_value = replace_escape_sequences(symb2_value) if symb1_value == symb2_value: interpret.inst_index = interpret.label_dict[label_name] elif symb1_type == 'int': if symb1_value == symb2_value: interpret.inst_index = interpret.label_dict[label_name] else: exit(53)
def int2char_i(interpret: i.Interpret, instruction): var_frame, var_name = var_prepare(instruction, interpret) symb1_type, symb1_value = interpret.get_type_and_value_of_symb( list(instruction)[1]) if symb1_value is None: exit(56) if symb1_type != 'int': exit(53) try: symb1_value = chr(symb1_value) except: exit(58) var_frame[var_name] = tuple(['string', symb1_value])
def type_i(interpret: i.Interpret, instruction): var_frame, var_name = var_prepare(instruction, interpret) symb1_type, symb1_val = interpret.get_type_and_value_of_symb( list(instruction)[1]) if symb1_type in ['int', 'nil', 'bool']: symb1_val = symb1_type elif symb1_val is None: symb1_val = '' else: symb1_val = 'string' var_frame[var_name] = tuple(['string', symb1_val])
def dprint_i(interpret: i.Interpret, instruction): symb_type, symb_value = interpret.get_type_and_value_of_symb( list(instruction)[0]) if symb_value is None: exit(56) if symb_type == 'nil': print('', file=sys.stderr, end='') elif symb_type == 'bool': print(str(symb_value).lower(), file=sys.stderr, end='') elif symb_type == 'string': symb_value = replace_escape_sequences(symb_value) print(symb_value, file=sys.stderr, end='') else: print(symb_value, file=sys.stderr, end='')
def read_i(interpret: i.Interpret, instruction): var_frame, var_name = var_prepare(instruction, interpret) symb1_type, symb1_value = interpret.get_type_and_value_of_symb( list(instruction)[1]) if symb1_value is None: exit(56) if symb1_type != 'type' or symb1_value not in ['int', 'bool', 'string']: exit(53) if interpret.input_data is not None: try: read_input = interpret.input_data.pop(0) read_input = read_input.rstrip('\n\r') except: symb1_value = 'nil' read_input = 'nil' else: try: read_input = input() except: symb1_value = 'nil' read_input = 'nil' try: if symb1_value == 'int': try: read_input = int(read_input) except: read_input = 'nil' symb1_value = 'nil' elif symb1_value == 'string': try: read_input = str(read_input) except: read_input = 'nil' symb1_value = 'nil' elif symb1_value == 'bool': read_input = read_input.lower() if read_input == 'true': read_input = True else: read_input = False except: symb1_value = 'nil' read_input = 'nil' var_frame[var_name] = tuple([symb1_value, read_input])
def defvar_i(interpret: i.Interpret, instruction): regex = re.match(r'^([GLT]F)@([\-$&%*!?a-zA-Z_][\-$&%*!?\w]*$)+', list(instruction)[0].text) if regex is None or regex.lastindex != 2: exit(32) frame = regex.group(1) variable = regex.group(2) if frame == 'GF': if interpret.get_frame_of_var(variable, 'GF') is not None: exit(52) interpret.global_frame[variable] = tuple([None, None]) elif frame == 'LF': if interpret.get_frame_of_var(variable, 'LF') is not None: exit(52) interpret.local_frame[variable] = tuple([None, None]) elif frame == 'TF': if interpret.get_frame_of_var(variable, 'TF') is not None: exit(52) interpret.tmp_frame[variable] = tuple([None, None])
def stateA(): ser.write("?A\r\n") a=ser.readline() print a def stateB(): ser.write("?B\r\n") a=ser.readline() print a if __name__=="__main__": # Incialitzem el port serie. ser=serial.Serial('/dev/ttyACM0',9600) # Cridem la classe interpet. I= Interpret() # Afegim les ordres. I.afegeix_ordre("ajuda",ajuda) I.afegeix_ordre("start",start) I.afegeix_ordre("stop",stop) I.afegeix_ordre("estat_A",stateA) I.afegeix_ordre("estat_B",stateB) I.afegeix_ordre("force_A",forceA) I.afegeix_ordre("force_B",forceB) I._prompt="***" print "Inicializant el Interpret... \n" time.sleep(1.5) I.run() ser.close()
""" print "Gracies per utilitzar el PARKING 'CARLE'" def begining(): print "\n\t\t\t PARKING 'CARLE'" info() def info(): """ Et mostra el conjunt de comandes que pots utilitzar en l'interpret. """ print "Les comanandes són:\n -info\n -exit\n -reset\n -consulta 'NOM'\n -esborra 'NOM'\n -insereix 'NOM' 'DNI' 'DATA'" print "*Aquells noms entre cometes simples '' indiquen el nom de la variable" if __name__=="__main__": I= Interpret() I._prompt="=> " I.set_end(ending) I.set_begin(begining) I.afegeix_ordre("info",info) I.afegeix_ordre("reset",buidar) I.afegeix_ordre("consulta",cerca) I.afegeix_ordre("llistat_buides",llistat) #I.afegeix_ordre("consulta",consulta) I.afegeix_ordre("esborra",sortir) #I.afegeix_ordre("ocupar_primera",ocupar_first) I.afegeix_ordre("insereix",ocupa) I.run() #buidar()
""" print "Gracies per utilitzar el PARKING 'CARLE'" def begining(): print "\n\t\t\t PARKING 'CARLE'" info() def info(): """ Et mostra el conjunt de comandes que pots utilitzar en l'interpret. """ print "Les comanandes són:\n -info\n -exit\n -reset\n -cerca 'DNI'\n -llistat_buides\n -sortir 'DNI'\n -ocupar 'DNI' 'NOM' 'DATA'" print "*Aquells noms entre cometes simples '' indiquen el nom de la variable" if __name__=="__main__": I= Interpret() I._prompt="=> " I.set_end(ending) I.set_begin(begining) I.afegeix_ordre("info",info) I.afegeix_ordre("reset",buidar) I.afegeix_ordre("cerca",cerca) I.afegeix_ordre("llistat_buides",llistat) #I.afegeix_ordre("consulta",consulta) I.afegeix_ordre("sortir",sortir) #I.afegeix_ordre("ocupar_primera",ocupar_first) I.afegeix_ordre("ocupar",ocupa) I.run() #buidar()
""" print "Gracies per utilitzar la xarxa social 'CARLE'" def begining(): print "\n\t\t\t Xarxa Social CARLE" info() def info(): """ Et mostra el conjunt de comandes que pots utilitzar en l'interpret. """ print "Les comanandes són:\n -info\n -exit\n -crear_db \n -Create_Account 'email' 'nom' 'cognom' 'poblacio' 'data de neixement' 'imatge de perfil'(opcional) \n -mostrar_usuaris \n -mostrar_amistats \n -info_usuari 'nom' 'cognom' \n -mostrar_amics 'nom' 'cognom' \n -Friend_request 'email1' 'email2' \n -Check_requests 'email' \n -Block_friend 'email1' 'email2' \n -Unblock_friend 'email1' 'email2' \n Funcions de debug \n -debug_pass 'nom' 'cognom' \n -debug_accounts 'path'" print "*Aquells noms entre cometes simples '' indiquen el nom de la variable" if __name__=="__main__": I= Interpret() I._prompt="=> " I.set_end(ending) I.set_begin(begining) I.afegeix_ordre("crear_db",nova_base_de_dades) I.afegeix_ordre("Create_Account",Create_Account) I.afegeix_ordre("mostrar_usuaris",mostrar_usuaris) I.afegeix_ordre("mostrar_amistats",mostrar_amistats) I.afegeix_ordre("info_usuari",info_usuari) I.afegeix_ordre("mostrar_amics",mostrar_amics) I.afegeix_ordre("Friend_request",enviar_peticio_amistat) I.afegeix_ordre("Check_requests",comprovar_peticions_amistat) I.afegeix_ordre("Block_friend",bloquejar_amistat) I.afegeix_ordre("Unblock_friend",desbloquejar_amistat) I.afegeix_ordre("debug_pass",debug_show_pass) I.afegeix_ordre("debug_accounts",debug_insert_accounts_file)
""" print "Gracies per utilitzar el PARKING 'CARLE'" def begining(): print "\n\t\t\t PARKING 'CARLE'" info() def info(): """ Et mostra el conjunt de comandes que pots utilitzar en l'interpret. """ print "Les comanandes són:\n -info\n -exit\n -cerca 'matricula'\n -llistat_buides\n -consulta 'plaça'\n -sortir 'matricula'\n -ocupar_primera 'matricula'\n -ocupar 'plaça' 'matricula'" print "*Aquells noms entre cometes simples '' indiquen el nom de la variable" if __name__ == "__main__": I = Interpret() I._prompt = "=> " I.set_end(ending) I.set_begin(begining) I.afegeix_ordre("info", info) I.afegeix_ordre("cerca", cerca) I.afegeix_ordre("llistat_buides", llistat) I.afegeix_ordre("consulta", consulta) I.afegeix_ordre("sortir", sortir) I.afegeix_ordre("ocupar_primera", ocupar_first) I.afegeix_ordre("ocupar", ocupa) I.run()
def clears_i(interpret: i.Interpret, instruction): interpret.data_stack = []
""" Funcio que s'executa quan sortim del programa. """ print "Gracies per utilitzar els serveis de 'CARLE'" def begining(): print "\n\t\t\t TAULA 'CARLE'" info() def info(): """ Et mostra el conjunt de comandes que pots utilitzar en l'interpret. """ print "Les comanandes són:\n -info\n -exit\n -reset\n -consulta 'NOM'\n -esborra 'NOM' 'DNI'\n -insereix 'NOM' 'DNI' 'DATA'" print "*Aquells noms entre cometes simples '' indiquen el nom de la variable" if __name__ == "__main__": I = Interpret() I._prompt = "=> " I.set_end(ending) I.set_begin(begining) I.afegeix_ordre("info", info) I.afegeix_ordre("reset", buidar) I.afegeix_ordre("consulta", cerca) I.afegeix_ordre("esborra", sortir) I.afegeix_ordre("insereix", ocupa) I.run()
def createframe_i(interpret: i.Interpret, instruction): interpret.tmp_frame = {}
""" ========== Mòdul Main ========== El mòdul main no conté cap doctest, de totes formes, es pot solicitar l'acces al Github del projecte a la seguent direccio: github.com/Ateles84/TECPRO_PT2 """ from interpret import Interpret from xarxaSocial import iTicApp if __name__ == '__main__': xxss = iTicApp() i = Interpret() i.setPrompt("~: ") i.setBegin(xxss.obre) i.setEnd(xxss.desa) i.afegeixOrdre("usuari", xxss.afegeixUsuari) i.afegeixOrdre("hashtag", xxss.afegeixHashtag) i.afegeixOrdre("publicar", xxss.publicarPost) i.afegeixOrdre("print", "cyka blyat") i.afegeixOrdre("ajuda", "rush b fast") i.afegeixOrdre("users", xxss.users) i.afegeixOrdre("posts", xxss.posts) i.afegeixOrdre("posts-user", xxss.llistarPostsUser) i.afegeixOrdre("hashtags", xxss.hashtags) i.afegeixOrdre("desa", xxss.desa) i.run()
print('---------------\nNOM: '+str(c)+'\nDNI: '+str(b)+'\nDATA: '+str(h)+'\n----------------') def ending(): """ Funcio que s'executa quan sortim del programa. """ print "Gracies per utilitzar els serveis de 'CARLE'" def begining(): print "\n\t\t\t TAULA 'CARLE'" info() def info(): """ Et mostra el conjunt de comandes que pots utilitzar en l'interpret. """ print "Les comanandes són:\n -info\n -exit\n -reset\n -consulta 'NOM'\n -esborra 'NOM' 'DNI'\n -insereix 'NOM' 'DNI' 'DATA'" print "*Aquells noms entre cometes simples '' indiquen el nom de la variable" if __name__=="__main__": I= Interpret() I._prompt="=> " I.set_end(ending) I.set_begin(begining) I.afegeix_ordre("info",info) I.afegeix_ordre("reset",buidar) I.afegeix_ordre("consulta",cerca) I.afegeix_ordre("esborra",sortir) I.afegeix_ordre("insereix",ocupa) I.run()
def pushs_i(interpret: i.Interpret, instruction): symb_type, symb_value = interpret.get_type_and_value_of_symb( list(instruction)[0]) if symb_value is None: exit(56) interpret.data_stack.append(tuple([symb_type, symb_value]))
def return_i(interpret: i.Interpret, instruction): if len(interpret.call_stack) == 0: exit(56) interpret.inst_index = interpret.call_stack.pop()
Funcio que s'executa quan sortim del programa. """ print "Gracies per utilitzar el PARKING 'CARLE'" def begining(): print "\n\t\t\t PARKING 'CARLE'" info() def info(): """ Et mostra el conjunt de comandes que pots utilitzar en l'interpret. """ print "Les comanandes són:\n -info\n -exit\n -cerca 'matricula'\n -llistat_buides\n -consulta 'plaça'\n -sortir 'matricula'\n -ocupar_primera 'matricula' 'color' 'marca'\n -ocupar 'plaça' 'matricula' 'color' 'marca'" print "*Aquells noms entre cometes simples '' indiquen el nom de la variable" if __name__=="__main__": I= Interpret() I._prompt="=> " I.set_end(ending) I.set_begin(begining) I.afegeix_ordre("info",info) I.afegeix_ordre("cerca",cerca) I.afegeix_ordre("llistat_buides",llistat) I.afegeix_ordre("consulta",consulta) I.afegeix_ordre("sortir",sortir) I.afegeix_ordre("ocupar_primera",ocupar_first) I.afegeix_ordre("ocupar",ocupa) I.run()
def pushframe_i(interpret: i.Interpret, instruction): if interpret.tmp_frame is None: exit(55) interpret.frame_stack.append(interpret.tmp_frame) interpret.local_frame = interpret.frame_stack[-1] interpret.tmp_frame = None
def setup(self): self.driver = webdriver.Chrome() self.driver.maximize_window() Interpret.replace_driver(self.actions, self.driver)
def jump_i(interpret: i.Interpret, instruction): if list(instruction)[0].text not in interpret.label_dict.keys(): exit(52) interpret.inst_index = interpret.label_dict[list(instruction)[0].text]
def call_i(interpret: i.Interpret, instruction): if list(instruction)[0].text not in interpret.label_dict.keys(): exit(52) interpret.call_stack.append(interpret.inst_index) interpret.inst_index = interpret.label_dict[list(instruction)[0].text]
def stop(): ser.write('S') b=ser.readline() if b == "SHUTDOWN\n": print "SHUTDOWN" else: print "Error : La comanda stop només es pot utilitzar si el semafor està ences" def ajuda(): print " Les comanandes són : start , stop , emergency" def emergency(): ser.write('E') a=ser.readline() if a== "EMERGENCY\n": print "EMERGENCY" else: print "Error : La comanda emergency no es pot utilitzar com inicialitzador ni com a restart després d'un stop " if __name__=="__main__": # Incialitzem el port serie. ser=serial.Serial('/dev/ttyACM0',9600) # Cridem la classe interpet. I= Interpret() # Afegim les ordres. I.afegeix_ordre("ajuda",ajuda) I.afegeix_ordre("start",start) I.afegeix_ordre("stop",stop) I.afegeix_ordre("emergency",emergency) I._prompt="***" I.run() ser.close()