Bora vê
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

semantico.py 1.7KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. def semantico(token, args):
  2. Avariaveis(token, args)
  3. def divisao(token, args, lista):
  4. linha = []
  5. if args.lse:
  6. print("Verificando Divisão por Zero.")
  7. def verificando(lista):
  8. for exp in lista.values():
  9. if 'î' not in exp:
  10. try:
  11. eval(''.join(exp))
  12. except ZeroDivisionError:
  13. from colorama import Style
  14. Color()
  15. print (f' Divisão por Zero {exp} '+ Style.RESET_ALL)
  16. def trocandoValores(lista,a,key):
  17. import re
  18. for exp in lista.keys():
  19. if exp in a:
  20. a=re.sub(r''+exp, (''.join(lista[exp])),''.join(a))
  21. lista[key] = ''.join(a)
  22. def Avariaveis(token, args):
  23. variaveis = {}
  24. if args.lse:
  25. print ('#' * 80)
  26. print('Carregando Tabela de Variveis.')
  27. print("Verificando Variaveis Duplicadas.")
  28. for var in token:
  29. if 'id' in var and var[2] == 2:
  30. if var[1] not in variaveis:
  31. variaveis[var[1]] = 'î'
  32. else:
  33. Color()
  34. print(f'\'{var[1]}\' declaração duplicada: ' + reset(var))
  35. if args.lse:
  36. print("Variaveis declaradas: ")
  37. for var in variaveis.items():
  38. print(var[0])
  39. print("Verificando Variaveis não declaradas.")
  40. for code in token:
  41. if 'id' in code:
  42. if not (code[1] in variaveis):
  43. Color();
  44. print(f'Variavel \'{code[1]}\' não declarado: ' + reset(code))
  45. divisao(token, args, variaveis)
  46. def Color():
  47. from colorama import Fore, Back
  48. print(Fore.CYAN + 'Erro semantico:')
  49. def reset(linha):
  50. from colorama import Style
  51. return f'linha{linha[2]} : coluna{linha[3]}' + Style.RESET_ALL