Skip to content

Commit

Permalink
Novos exemplos. Alterações em mensagens de erro do interpretador.
Browse files Browse the repository at this point in the history
  • Loading branch information
gabrielavmattos-zz committed Jul 6, 2016
1 parent 5939ecd commit bc0dfd4
Show file tree
Hide file tree
Showing 42 changed files with 1,246 additions and 47 deletions.
Binary file added FAZEDORES_SITE/FAZEDORES/FAZEDORES/__init__.pyc
Binary file not shown.
Binary file added FAZEDORES_SITE/FAZEDORES/FAZEDORES/settings.pyc
Binary file not shown.
Binary file added FAZEDORES_SITE/FAZEDORES/FAZEDORES/urls.pyc
Binary file not shown.
Binary file added FAZEDORES_SITE/FAZEDORES/FAZEDORES/wsgi.pyc
Binary file not shown.
66 changes: 19 additions & 47 deletions FAZEDORES_SITE/FAZEDORES/FazedoresInterpreter/Interpreter.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class Interpreter():

def __init__(self, dataInput):

#print(dataInput)

dataInput += '\r\n'
self.dataOutput = []
self.setDataOutput("import mraa")
Expand All @@ -42,7 +42,7 @@ def __init__(self, dataInput):
dataInput = dataInput.split('\n')
self.setDataInput(dataInput)
self.deleteLines()
print(self.dataInput)



def setDataInput(self, dataInput):
Expand All @@ -54,7 +54,6 @@ def setDataOutput(self, line):
def getDataOutput(self):
if (self.error):
# retorna para a view
print([False, self.msgError])
return [False, self.msgError]
else:

Expand All @@ -73,15 +72,15 @@ def getDataOutput(self):
return [True,saida]

def setMsgError(self, msgError):
self.error = 1
self.msgError = "Erro(linha %d): %s" % (self.i + 1,msgError)
print (self.msgError)
self.getDataOutput()
if (len(self.msgError) == 0):
self.error = 1
self.msgError = "Erro(linha %d): %s\nDica: evite deixar linhas em branco." % (self.i + 1,msgError)
print (self.msgError)
self.getDataOutput()

def replaceBT(self, dataInput):
aux = ""
for i in range(0, len(dataInput)-1):
print("'"+dataInput[i]+"'")
if (dataInput[i] == '\t' or dataInput[i] == '\r'):
aux += ' '
else:
Expand Down Expand Up @@ -147,9 +146,6 @@ def declarations(self):
"""

line = self.dataInput[self.i].split(' ')
print ("adbahbsda")
print (line)

j = 0
if (line[j] in self.tokensDeclaration):
if (line[j] == "declare"):
Expand All @@ -172,7 +168,7 @@ def declarations(self):
if (not self.cmdSetup()):
return False
else:
#self.setMsgError("O comando "+line[j]+" não é reconhecido.")
self.setMsgError("O comando "+line[j]+" não é reconhecido.")
return False


Expand All @@ -182,20 +178,15 @@ def cmdSetup(self):
comandoSetup : 'ativar' '(' dispositivo ',' pino ')'
;
"""
print("setup")
#try:
# if (self.dataInput[self.i].index(' ')):
dataInputWithoutSpaces = self.removeSpaces(self.dataInput[self.i])
line = dataInputWithoutSpaces.split('@')
print (line)

if (line[0] == "comando_setup"):
self.i += 1
j = 0
dataInputWithoutSpaces = self.removeSpaces(self.dataInput[self.i])
print("Esse "+ self.dataInput[self.i] +".")
line = dataInputWithoutSpaces.split('@')
while (line[j] in self.tokensCmdSetup and self.i < len(self.dataInput)):
print (line)
while (line[j] in self.tokensCmdSetup and self.i < len(self.dataInput)):
if (line[j] == "ativar"):
j = j+1
if(line[j] in self.tokensDeviceDigits):
Expand All @@ -206,7 +197,6 @@ def cmdSetup(self):
self.setMsgError("Pino "+line[j]+" inválido.\nDica: \n- 0 a 3 portas analogicas\n- 4 a 8 são portas digitais\n- 5 e 6 são portas PWM\n- 21 porta I2C (usada para o LCD)\n")
return False
elif (line[j] in self.tokensDeviceAnalogs):
#print (line[j])
j = j+1;
if(self.validatePinDevice(line,j,1)):
pass
Expand All @@ -215,7 +205,6 @@ def cmdSetup(self):
return False
elif (line[j] == 'lcd'):
if(self.validatePinDevice(line,j, 2)):
print(line[j])
pass
else:
self.setMsgError("Pino "+line[j]+" inválido.")
Expand All @@ -239,7 +228,6 @@ def cmdSetup(self):
self.i += 1
return True
else:
print("Aqui " + self.dataInput[self.i] +".")
self.setMsgError("Comando 'fim_comando_setup' não encontrado!")
return False
else:
Expand All @@ -258,24 +246,21 @@ def cmdLoop(self):
indentation = 1
dataInputWithoutSpaces = self.removeSpaces(self.dataInput[self.i])
line = dataInputWithoutSpaces.split('@')
line = self.dataInput[self.i].split(' ')
#print (line)
line = self.dataInput[self.i].split(' ')

if (line[0] == "comando_loop"):
self.i += 1
dataInputWithoutSpaces = self.removeSpaces(self.dataInput[self.i])
#print(dataInputWithoutSpaces)
line = dataInputWithoutSpaces.split('@')

print (line)

j = 0
self.setDataOutput("while True:")
while (line[j] in self.tokensCmdLoop or line[j] in self.symbolTable):
print ("Linha atual: " + line[j])
if (self.cmdOutput(line, j, indentation)):
pass

elif (line[j] in self.symbolTable):
print("here")
self.cmdInput(line, j, indentation)

elif (self.cmdSleep(line, j, indentation)):
Expand All @@ -293,15 +278,14 @@ def cmdLoop(self):
line = dataInputWithoutSpaces.split('@')
j = 0
else:
print("Aqui" + line[j])
if ("fim_comando_loop" in self.dataInput[self.i]):
return True
else:
#self.setMsgError("Comando '"+line[j]+"' não reconhecido.")
self.setMsgError("Comando '"+line[j]+"' não reconhecido.")
return False

else:
#self.setMsgError("Comando "+line[0]+" não reconhecido.")
self.setMsgError("Comando "+line[0]+" não reconhecido.")
return False

def cmdOutput(self, line, j, indentation):
Expand All @@ -320,13 +304,11 @@ def cmdOutput(self, line, j, indentation):
else:
self.setMsgError("Comando 'ligar' utilizado em dispositivo errado.")
return False
print(idDevice)

if (idDevice in self.devicesTable):
if (self.devicesTable[idDevice][0] == 'pwm'):
if(len(line) > 4):
if (line[3].isdigit()):
#print ("Tá aqui")
self.setDataOutput("\t"*indentation + idDevice + ".write("+line[3]+"/255.0)")
self.devicesTable[idDevice][2] = 'ativo'
elif(line[3] in self.symbolTable):
Expand All @@ -340,7 +322,6 @@ def cmdOutput(self, line, j, indentation):
self.setMsgError("Comando 'ligar' em pwm deve passar um valor inteiro.")
return False
elif (self.devicesTable[idDevice][2] == 'desativo'):
#print ("aui " +line[2])
self.setDataOutput("\t"*indentation + idDevice + ".write(1)")
self.devicesTable[idDevice][2] = 'ativo'

Expand All @@ -364,7 +345,6 @@ def cmdOutput(self, line, j, indentation):
self.setMsgError("Comando 'ligar' em pwm deve passar um valor inteiro.")
return False
elif (self.devicesTable[idDevice][2] == 'desativo'):
#print ("aui " +line[2])
self.setDataOutput("\t"*indentation + idDevice + ".write(1)")
self.devicesTable[idDevice][2] = 'ativo'
else:
Expand All @@ -375,7 +355,6 @@ def cmdOutput(self, line, j, indentation):
return False

elif (line[j] == "desligar"):
#print (line)
j = j + 1
if(line[j+1].isdigit()):
idDevice = line[j]+line[j+1]
Expand All @@ -387,7 +366,7 @@ def cmdOutput(self, line, j, indentation):
else:
self.setMsgError("Comando 'desligar' utilizado em dispositivo errado.")
return False
#print(idDevice)

if (idDevice in self.devicesTable):
if (self.devicesTable[idDevice][0] in ('pwm', 'digitsOUT')):
if (self.devicesTable[idDevice][2] == 'ativo'):
Expand Down Expand Up @@ -427,7 +406,7 @@ def cmdInput(self, line, j, indentation):
else:
self.setMsgError("Comando 'ler' utilizado em dispositivo errado.")
return False
print(self.devicesTable)

if (idDevice in self.devicesTable):
if (self.devicesTable[idDevice][0] == 'digitsIN'):
self.setDataOutput("\t"*indentation + output + idDevice + ".read()")
Expand Down Expand Up @@ -560,7 +539,7 @@ def cmdLCD(self, line, j, indentation):
return False
elif (line[j] == 'escrever'):
j += 1
if (line[j] == 'lcd'):
if (line[j] == 'lcd' or line[j] == 'tela' or line[j] == 'LCD'):
if(line[j+1].isdigit()):
idDevice = line[j]+line[j+1]
elif(line[j+1] in self.symbolTable):
Expand Down Expand Up @@ -720,9 +699,7 @@ def validatePinDevice(self, line, j, typeP):
return False

else:
#print (symbolTable)
return False
#print ("output")

return True

Expand All @@ -741,7 +718,6 @@ def validateVar(self, line, j):
if (line[j] in self.types and isValue):
self.symbolTable[symbol] = ["var", line[j], value]
self.setDataOutput(symbol +" = "+ str(value))
print(self.symbolTable)
return True
else:
self.setMsgError("Verifique a variavel "+line[j-1]+" e seu tipo "+line[j]+".")
Expand All @@ -766,8 +742,7 @@ def validateConst(self, line, j):
j += 1

isValue, value = self.validateValue(line[j], line[j+2])
if (line[j] in self.types and line[j+1] == '=' and isValue):
print(line[j])
if (line[j] in self.types and line[j+1] == '=' and isValue):
self.symbolTable[symbol] = ["const", line[j], value]
self.setDataOutput(symbol +" = "+ str(value))
return True
Expand All @@ -785,7 +760,6 @@ def validateIdent(self, line):
// Definindo o identificador:
IDENT : ('a'..'z' | 'A'..'Z' | '_') ('a'..'z' | 'A'..'Z' | '0'..'9' | '_')*;
"""
print(line)
if (line[0].isalpha() or line[0] == '_'):
if(line[len(line)-1:len(line)] == ':'):
symbol = line.split(':')[0]
Expand Down Expand Up @@ -833,8 +807,6 @@ def validateValue(self, typeS, value):
return [False, ""]

def __del__(self):
print("etejabsdadba")

self.symbolTable.clear()
self.devicesTable.clear()
del self.portsAnalog
Expand Down
Binary file not shown.
Loading

0 comments on commit bc0dfd4

Please sign in to comment.