def esCADENA(linea: str, pos: int) -> str: q0 = 0 F = [2] #Q=0..3 # #sigma=(C,O); delta = [None] * 4 for i in range(4): delta[i] = [None] * 2 delta[0][0] = 1 delta[0][1] = 3 delta[1][0] = 2 delta[1][1] = 1 delta[2][0] = 3 delta[2][1] = 3 delta[3][0] = 3 delta[3][1] = 3 auxControl = pos estado = q0 lexema = '' T = arc.leerCaracter(linea, auxControl) while estado != 3 and auxControl < len(linea) and T != "\n" and (estado not in F): estado = delta[estado][simbCAD(T)] if estado != 3: lexema = lexema + T auxControl = auxControl + 1 T = arc.leerCaracter(linea, auxControl) if estado in F: pos = auxControl return lexema else: return ""
def esID(linea: str, posicion: int) -> str: q0 = 0 F = {0, 1} # Q = (0,1,2) # sigma=[(letra, digito, guionBajo, otro)] #letra = 0ra columna, digito = 1da columna, guionBajo = 2ra columna, otro= 3ta columna) delta = [None] * 3 for i in range(3): delta[i] = [None] * 4 delta[0][0] = 1 delta[0][1] = 2 delta[0][2] = 2 delta[0][3] = 2 delta[1][0] = 1 delta[1][1] = 1 delta[1][2] = 1 delta[1][3] = 2 delta[2][0] = 2 delta[2][1] = 2 delta[2][2] = 2 delta[2][3] = 2 lexema = "" auxControl = posicion T = arc.leerCaracter(linea, auxControl) estado = q0 while (estado != 2) and auxControl < len(linea) and (T != " ") and ( T != "\n") and not simbolo(linea, auxControl): estado = delta[estado][simboloID(T)] lexema = lexema + T auxControl = auxControl + 1 T = arc.leerCaracter(linea, auxControl) if estado in F: return lexema else: return ""
def esLEER(linea: str, posicion: str) -> str: q0 = 0 F = {4} #Q=0..5 #sigma=(L, E, R, O) delta = [None] * 6 for i in range(6): delta[i] = [None] * 4 delta[0][0] = 1 delta[0][1] = 5 delta[0][2] = 5 delta[0][3] = 5 delta[1][0] = 5 delta[1][1] = 2 delta[1][2] = 5 delta[1][3] = 5 delta[2][0] = 5 delta[2][1] = 3 delta[2][2] = 5 delta[2][3] = 5 delta[3][0] = 5 delta[3][1] = 5 delta[3][2] = 4 delta[3][3] = 5 delta[4][0] = 5 delta[4][1] = 5 delta[4][2] = 5 delta[4][3] = 5 auxControl = posicion estado = q0 lexema = "" T = arc.leerCaracter(linea, auxControl) while estado != 5 and auxControl < len( linea) and T != " " and T != "\n" and not simbolo( linea, auxControl): estado = delta[estado][simbLEER(T)] if estado != 5: lexema = lexema + T auxControl = auxControl + 1 T = arc.leerCaracter(linea, auxControl) if estado in F: return lexema else: return ""
def esESCRIBIR(linea: str, pos: int) -> int: q0 = 0 F = {8} #Q=0..9; # #sigma=(E, S, C, R, I, B ,O) 0 para E, 1 para S, 2 para C... #delta = np.empty((10, 7)) delta = [None] * 10 for i in range(10): delta[i] = [None] * 7 delta[0][0] = 1 delta[0][1] = 9 delta[0][2] = 9 delta[0][3] = 9 delta[0][4] = 9 delta[0][5] = 9 delta[0][6] = 9 delta[1][0] = 9 delta[1][1] = 2 delta[1][2] = 9 delta[1][3] = 9 delta[1][4] = 9 delta[1][5] = 9 delta[1][6] = 9 delta[2][0] = 9 delta[2][1] = 9 delta[2][2] = 3 delta[2][3] = 9 delta[2][4] = 9 delta[2][5] = 9 delta[2][6] = 9 delta[3][0] = 9 delta[3][1] = 9 delta[3][2] = 9 delta[3][3] = 4 delta[3][4] = 9 delta[3][5] = 9 delta[3][6] = 9 delta[4][0] = 9 delta[4][1] = 9 delta[4][2] = 9 delta[4][3] = 9 delta[4][4] = 5 delta[4][5] = 9 delta[4][6] = 9 delta[5][0] = 9 delta[5][1] = 9 delta[5][2] = 9 delta[5][3] = 9 delta[5][4] = 9 delta[5][5] = 6 delta[5][6] = 9 delta[6][0] = 9 delta[6][1] = 9 delta[6][2] = 9 delta[6][3] = 9 delta[6][4] = 7 delta[6][5] = 9 delta[6][6] = 9 delta[7][0] = 9 delta[7][1] = 9 delta[7][2] = 9 delta[7][3] = 8 delta[7][4] = 9 delta[7][5] = 9 delta[7][6] = 9 delta[8][0] = 9 delta[8][1] = 9 delta[8][2] = 9 delta[8][3] = 9 delta[8][4] = 9 delta[8][5] = 9 delta[8][6] = 9 delta[9][0] = 9 delta[9][1] = 9 delta[9][2] = 9 delta[9][3] = 9 delta[9][4] = 9 delta[9][5] = 9 delta[9][6] = 9 auxControl = pos estado = q0 lexema = "" T = arc.leerCaracter(linea, pos) while estado != 9 and auxControl < len( linea) and T != " " and T != "\n" and not simbolo( linea, auxControl): estado = delta[estado][simbESCRI(T)] if estado != 9: lexema = lexema + T auxControl = auxControl + 1 T = arc.leerCaracter(linea, auxControl) if estado in F: posicion = auxControl return lexema else: return ""
def esConstReal(linea: str, pos: int) -> str: q0 = 0 F = {4, 2, 7} #Q=range(1,9) #sigma=(D, menos, punto, E, O) delta = [None] * 9 for i in range(9): delta[i] = [None] * 5 estado = q0 auxControl = pos delta[0][0] = 2 delta[0][1] = 1 delta[0][2] = 8 # 8=muerto delta[0][3] = 8 delta[0][4] = 8 delta[1][0] = 2 delta[1][1] = 8 delta[1][2] = 8 delta[1][3] = 8 delta[1][4] = 8 delta[2][0] = 2 delta[2][1] = 8 delta[2][2] = 3 delta[2][3] = 5 delta[2][4] = 8 delta[3][0] = 4 delta[3][1] = 8 delta[3][2] = 8 delta[3][3] = 8 delta[3][4] = 8 delta[4][0] = 4 delta[4][1] = 8 delta[4][2] = 8 delta[4][3] = 5 delta[4][4] = 8 delta[5][0] = 7 delta[5][1] = 6 delta[5][2] = 8 delta[5][3] = 8 delta[5][4] = 8 delta[6][0] = 7 delta[6][1] = 8 delta[6][2] = 8 delta[6][3] = 8 delta[6][4] = 8 delta[7][0] = 7 delta[7][1] = 8 delta[7][2] = 8 delta[7][3] = 8 delta[7][4] = 8 delta[8][0] = 8 delta[8][1] = 8 delta[8][2] = 8 delta[8][3] = 8 delta[8][4] = 8 lexema = "" T = arc.leerCaracter(linea, auxControl) while estado != 8 and auxControl < len( linea) and T != " " and T != "\n" and (not simbolo1( linea, auxControl)): estado = delta[estado][simbCONS(T)] if estado != 8: lexema = lexema + T auxControl = auxControl + 1 T = arc.leerCaracter(linea, auxControl) if estado in F: return lexema else: return ""
def simbolo1(linea: str, posicion: int) -> bool: simb = False aux = arc.leerCaracter(linea, posicion) if aux in {'=', '+', '*', '/', ';', ',', '(', ')'}: simb = True return simb