@designliquido/delegua 0.9.2 → 0.9.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (244) hide show
  1. package/bin/delegua +1 -1
  2. package/bin/delegua.cmd +1 -1
  3. package/bin/package.json +3 -3
  4. package/coverage/lcov-report/sorter.js +4 -4
  5. package/coverage/lcov-report/sorter.js.map +1 -1
  6. package/execucao.d.ts +1 -0
  7. package/execucao.js +29 -0
  8. package/execucao.js.map +1 -0
  9. package/fontes/avaliador-sintatico/avaliador-sintatico-base.d.ts +1 -1
  10. package/fontes/avaliador-sintatico/avaliador-sintatico-base.js +108 -105
  11. package/fontes/avaliador-sintatico/avaliador-sintatico-base.js.map +1 -1
  12. package/fontes/avaliador-sintatico/avaliador-sintatico.d.ts +1 -1
  13. package/fontes/avaliador-sintatico/avaliador-sintatico.js +244 -256
  14. package/fontes/avaliador-sintatico/avaliador-sintatico.js.map +1 -1
  15. package/fontes/avaliador-sintatico/dialetos/avaliador-sintatico-birl.d.ts +20 -0
  16. package/fontes/avaliador-sintatico/dialetos/avaliador-sintatico-birl.js +68 -0
  17. package/fontes/avaliador-sintatico/dialetos/avaliador-sintatico-birl.js.map +1 -0
  18. package/fontes/avaliador-sintatico/dialetos/avaliador-sintatico-egua-classico.d.ts +1 -1
  19. package/fontes/avaliador-sintatico/dialetos/avaliador-sintatico-egua-classico.js +227 -236
  20. package/fontes/avaliador-sintatico/dialetos/avaliador-sintatico-egua-classico.js.map +1 -1
  21. package/fontes/avaliador-sintatico/dialetos/avaliador-sintatico-eguap.d.ts +1 -1
  22. package/fontes/avaliador-sintatico/dialetos/avaliador-sintatico-eguap.js +247 -257
  23. package/fontes/avaliador-sintatico/dialetos/avaliador-sintatico-eguap.js.map +1 -1
  24. package/fontes/avaliador-sintatico/dialetos/avaliador-sintatico-visualg.d.ts +3 -0
  25. package/fontes/avaliador-sintatico/dialetos/avaliador-sintatico-visualg.js +192 -131
  26. package/fontes/avaliador-sintatico/dialetos/avaliador-sintatico-visualg.js.map +1 -1
  27. package/fontes/avaliador-sintatico/erro-avaliador-sintatico.js +6 -24
  28. package/fontes/avaliador-sintatico/erro-avaliador-sintatico.js.map +1 -1
  29. package/fontes/bibliotecas/biblioteca-global.js +206 -367
  30. package/fontes/bibliotecas/biblioteca-global.js.map +1 -1
  31. package/fontes/bibliotecas/importar-biblioteca.js +28 -29
  32. package/fontes/bibliotecas/importar-biblioteca.js.map +1 -1
  33. package/fontes/bibliotecas/primitivas-texto.js +9 -22
  34. package/fontes/bibliotecas/primitivas-texto.js.map +1 -1
  35. package/fontes/bibliotecas/primitivas-vetor.js +12 -14
  36. package/fontes/bibliotecas/primitivas-vetor.js.map +1 -1
  37. package/fontes/construtos/acesso-indice-variavel.js +6 -50
  38. package/fontes/construtos/acesso-indice-variavel.js.map +1 -1
  39. package/fontes/construtos/acesso-metodo.js +6 -50
  40. package/fontes/construtos/acesso-metodo.js.map +1 -1
  41. package/fontes/construtos/agrupamento.js +6 -50
  42. package/fontes/construtos/agrupamento.js.map +1 -1
  43. package/fontes/construtos/atribuicao-sobrescrita.js +6 -50
  44. package/fontes/construtos/atribuicao-sobrescrita.js.map +1 -1
  45. package/fontes/construtos/atribuir.js +6 -50
  46. package/fontes/construtos/atribuir.js.map +1 -1
  47. package/fontes/construtos/binario.js +6 -50
  48. package/fontes/construtos/binario.js.map +1 -1
  49. package/fontes/construtos/chamada.js +6 -50
  50. package/fontes/construtos/chamada.js.map +1 -1
  51. package/fontes/construtos/definir-valor.js +6 -50
  52. package/fontes/construtos/definir-valor.js.map +1 -1
  53. package/fontes/construtos/dicionario.js +6 -50
  54. package/fontes/construtos/dicionario.js.map +1 -1
  55. package/fontes/construtos/funcao.d.ts +2 -2
  56. package/fontes/construtos/funcao.js +6 -47
  57. package/fontes/construtos/funcao.js.map +1 -1
  58. package/fontes/construtos/isto.js +6 -47
  59. package/fontes/construtos/isto.js.map +1 -1
  60. package/fontes/construtos/literal.js +6 -47
  61. package/fontes/construtos/literal.js.map +1 -1
  62. package/fontes/construtos/logico.js +6 -50
  63. package/fontes/construtos/logico.js.map +1 -1
  64. package/fontes/construtos/super.js +6 -47
  65. package/fontes/construtos/super.js.map +1 -1
  66. package/fontes/construtos/unario.js +6 -50
  67. package/fontes/construtos/unario.js.map +1 -1
  68. package/fontes/construtos/variavel.js +6 -47
  69. package/fontes/construtos/variavel.js.map +1 -1
  70. package/fontes/construtos/vetor.js +6 -50
  71. package/fontes/construtos/vetor.js.map +1 -1
  72. package/fontes/declaracoes/bloco.js +9 -70
  73. package/fontes/declaracoes/bloco.js.map +1 -1
  74. package/fontes/declaracoes/classe.js +11 -72
  75. package/fontes/declaracoes/classe.js.map +1 -1
  76. package/fontes/declaracoes/continua.js +8 -65
  77. package/fontes/declaracoes/continua.js.map +1 -1
  78. package/fontes/declaracoes/declaracao.js +6 -47
  79. package/fontes/declaracoes/declaracao.js.map +1 -1
  80. package/fontes/declaracoes/enquanto.js +10 -71
  81. package/fontes/declaracoes/enquanto.js.map +1 -1
  82. package/fontes/declaracoes/escolha.js +11 -72
  83. package/fontes/declaracoes/escolha.js.map +1 -1
  84. package/fontes/declaracoes/escreva.js +9 -70
  85. package/fontes/declaracoes/escreva.js.map +1 -1
  86. package/fontes/declaracoes/expressao.js +9 -70
  87. package/fontes/declaracoes/expressao.js.map +1 -1
  88. package/fontes/declaracoes/fazer.js +10 -71
  89. package/fontes/declaracoes/fazer.js.map +1 -1
  90. package/fontes/declaracoes/funcao.js +10 -68
  91. package/fontes/declaracoes/funcao.js.map +1 -1
  92. package/fontes/declaracoes/importar.js +10 -71
  93. package/fontes/declaracoes/importar.js.map +1 -1
  94. package/fontes/declaracoes/leia.js +9 -70
  95. package/fontes/declaracoes/leia.js.map +1 -1
  96. package/fontes/declaracoes/para.js +12 -73
  97. package/fontes/declaracoes/para.js.map +1 -1
  98. package/fontes/declaracoes/retorna.js +10 -71
  99. package/fontes/declaracoes/retorna.js.map +1 -1
  100. package/fontes/declaracoes/se.js +12 -73
  101. package/fontes/declaracoes/se.js.map +1 -1
  102. package/fontes/declaracoes/sustar.js +8 -65
  103. package/fontes/declaracoes/sustar.js.map +1 -1
  104. package/fontes/declaracoes/tente.js +12 -73
  105. package/fontes/declaracoes/tente.js.map +1 -1
  106. package/fontes/declaracoes/var.js +10 -71
  107. package/fontes/declaracoes/var.js.map +1 -1
  108. package/fontes/delegua.js +125 -206
  109. package/fontes/delegua.js.map +1 -1
  110. package/fontes/depuracao/cyrb53.js +3 -4
  111. package/fontes/depuracao/cyrb53.js.map +1 -1
  112. package/fontes/depuracao/servidor-depuracao.js +125 -209
  113. package/fontes/depuracao/servidor-depuracao.js.map +1 -1
  114. package/fontes/espaco-variaveis.js +3 -4
  115. package/fontes/espaco-variaveis.js.map +1 -1
  116. package/fontes/estruturas/chamavel.js +6 -9
  117. package/fontes/estruturas/chamavel.js.map +1 -1
  118. package/fontes/estruturas/classe-padrao.js +17 -35
  119. package/fontes/estruturas/classe-padrao.js.map +1 -1
  120. package/fontes/estruturas/delegua-classe.d.ts +2 -2
  121. package/fontes/estruturas/delegua-classe.js +21 -39
  122. package/fontes/estruturas/delegua-classe.js.map +1 -1
  123. package/fontes/estruturas/delegua-funcao.js +48 -114
  124. package/fontes/estruturas/delegua-funcao.js.map +1 -1
  125. package/fontes/estruturas/funcao-padrao.js +13 -75
  126. package/fontes/estruturas/funcao-padrao.js.map +1 -1
  127. package/fontes/estruturas/metodo-primitiva.js +11 -39
  128. package/fontes/estruturas/metodo-primitiva.js.map +1 -1
  129. package/fontes/estruturas/modulo.js +6 -7
  130. package/fontes/estruturas/modulo.js.map +1 -1
  131. package/fontes/estruturas/objeto-delegua-classe.d.ts +3 -3
  132. package/fontes/estruturas/objeto-delegua-classe.js +12 -13
  133. package/fontes/estruturas/objeto-delegua-classe.js.map +1 -1
  134. package/fontes/estruturas/objeto-padrao.js +9 -11
  135. package/fontes/estruturas/objeto-padrao.js.map +1 -1
  136. package/fontes/excecoes/erro-em-tempo-de-execucao.js +8 -26
  137. package/fontes/excecoes/erro-em-tempo-de-execucao.js.map +1 -1
  138. package/fontes/importador/importador.js +21 -22
  139. package/fontes/importador/importador.js.map +1 -1
  140. package/fontes/interfaces/avaliador-sintatico-interface.d.ts +1 -1
  141. package/fontes/interfaces/parametro-interface.d.ts +1 -1
  142. package/fontes/interpretador/dialetos/egua-classico.js +592 -1019
  143. package/fontes/interpretador/dialetos/egua-classico.js.map +1 -1
  144. package/fontes/interpretador/inferenciador.js +1 -1
  145. package/fontes/interpretador/inferenciador.js.map +1 -1
  146. package/fontes/interpretador/interpretador-com-depuracao.js +186 -336
  147. package/fontes/interpretador/interpretador-com-depuracao.js.map +1 -1
  148. package/fontes/interpretador/interpretador.js +706 -1175
  149. package/fontes/interpretador/interpretador.js.map +1 -1
  150. package/fontes/interpretador/pilha-escopos-execucao.js +52 -57
  151. package/fontes/interpretador/pilha-escopos-execucao.js.map +1 -1
  152. package/fontes/lexador/dialetos/lexador-birl.d.ts +6 -19
  153. package/fontes/lexador/dialetos/lexador-birl.js +157 -49
  154. package/fontes/lexador/dialetos/lexador-birl.js.map +1 -1
  155. package/fontes/lexador/dialetos/lexador-egua-classico.js +43 -46
  156. package/fontes/lexador/dialetos/lexador-egua-classico.js.map +1 -1
  157. package/fontes/lexador/dialetos/lexador-eguap.js +59 -63
  158. package/fontes/lexador/dialetos/lexador-eguap.js.map +1 -1
  159. package/fontes/lexador/dialetos/lexador-visualg.js +45 -54
  160. package/fontes/lexador/dialetos/lexador-visualg.js.map +1 -1
  161. package/fontes/lexador/dialetos/palavras-reservadas/birl.d.ts +14 -1
  162. package/fontes/lexador/dialetos/palavras-reservadas/birl.js +18 -1
  163. package/fontes/lexador/dialetos/palavras-reservadas/birl.js.map +1 -1
  164. package/fontes/lexador/dialetos/palavras-reservadas/egua-classico.js +1 -1
  165. package/fontes/lexador/dialetos/palavras-reservadas/egua-classico.js.map +1 -1
  166. package/fontes/lexador/dialetos/palavras-reservadas/visualg.d.ts +24 -0
  167. package/fontes/lexador/dialetos/palavras-reservadas/visualg.js +25 -1
  168. package/fontes/lexador/dialetos/palavras-reservadas/visualg.js.map +1 -1
  169. package/fontes/lexador/lexador-base-linha-unica.d.ts +1 -1
  170. package/fontes/lexador/lexador-base-linha-unica.js +28 -29
  171. package/fontes/lexador/lexador-base-linha-unica.js.map +1 -1
  172. package/fontes/lexador/lexador.js +53 -57
  173. package/fontes/lexador/lexador.js.map +1 -1
  174. package/fontes/lexador/palavras-reservadas.js +1 -1
  175. package/fontes/lexador/palavras-reservadas.js.map +1 -1
  176. package/fontes/lexador/simbolo.js +5 -6
  177. package/fontes/lexador/simbolo.js.map +1 -1
  178. package/fontes/quebras/index.js +11 -42
  179. package/fontes/quebras/index.js.map +1 -1
  180. package/fontes/resolvedor/dialetos/egua-classico.js +143 -144
  181. package/fontes/resolvedor/dialetos/egua-classico.js.map +1 -1
  182. package/fontes/resolvedor/erro-resolvedor.js +6 -24
  183. package/fontes/resolvedor/erro-resolvedor.js.map +1 -1
  184. package/fontes/resolvedor/pilha-escopos.js +11 -12
  185. package/fontes/resolvedor/pilha-escopos.js.map +1 -1
  186. package/fontes/tipos-de-simbolos/birl.d.ts +7 -0
  187. package/fontes/tipos-de-simbolos/birl.js +20 -12
  188. package/fontes/tipos-de-simbolos/birl.js.map +1 -1
  189. package/fontes/tipos-de-simbolos/comum.d.ts +2 -0
  190. package/fontes/tipos-de-simbolos/comum.js +2 -0
  191. package/fontes/tipos-de-simbolos/comum.js.map +1 -1
  192. package/fontes/tipos-de-simbolos/visualg.d.ts +9 -0
  193. package/fontes/tipos-de-simbolos/visualg.js +9 -0
  194. package/fontes/tipos-de-simbolos/visualg.js.map +1 -1
  195. package/index.d.ts +5 -1
  196. package/index.js +18 -25
  197. package/index.js.map +1 -1
  198. package/jest.config.js +9 -47
  199. package/jest.config.js.map +1 -1
  200. package/package.json +3 -3
  201. package/testes/__mocks__/estatistica.js +1 -1
  202. package/testes/__mocks__/estatistica.js.map +1 -1
  203. package/testes/__mocks__/fisica.js +1 -1
  204. package/testes/__mocks__/fisica.js.map +1 -1
  205. package/testes/__mocks__/matematica.js +1 -1
  206. package/testes/__mocks__/matematica.js.map +1 -1
  207. package/testes/avaliador-sintatico.test.js +27 -27
  208. package/testes/avaliador-sintatico.test.js.map +1 -1
  209. package/testes/biblioteca-global.test.js +197 -440
  210. package/testes/biblioteca-global.test.js.map +1 -1
  211. package/testes/birl/avaliador-sintatico.test.d.ts +1 -0
  212. package/testes/birl/avaliador-sintatico.test.js +18 -0
  213. package/testes/birl/avaliador-sintatico.test.js.map +1 -0
  214. package/testes/birl/lexador.test.d.ts +1 -0
  215. package/testes/birl/lexador.test.js +31 -0
  216. package/testes/birl/lexador.test.js.map +1 -0
  217. package/testes/delegua.test.js +7 -7
  218. package/testes/delegua.test.js.map +1 -1
  219. package/testes/egua-classico/avaliador-sintatico.test.js +14 -14
  220. package/testes/egua-classico/avaliador-sintatico.test.js.map +1 -1
  221. package/testes/egua-classico/delegua.test.js +5 -5
  222. package/testes/egua-classico/delegua.test.js.map +1 -1
  223. package/testes/egua-classico/interpretador.test.js +180 -396
  224. package/testes/egua-classico/interpretador.test.js.map +1 -1
  225. package/testes/egua-classico/lexador.test.js +23 -23
  226. package/testes/egua-classico/lexador.test.js.map +1 -1
  227. package/testes/egua-classico/resolvedor.test.js +12 -12
  228. package/testes/egua-classico/resolvedor.test.js.map +1 -1
  229. package/testes/eguap/avaliador-sintatico.test.js +11 -11
  230. package/testes/eguap/avaliador-sintatico.test.js.map +1 -1
  231. package/testes/eguap/interpretador.test.js +189 -405
  232. package/testes/eguap/interpretador.test.js.map +1 -1
  233. package/testes/eguap/lexador.test.js +18 -18
  234. package/testes/eguap/lexador.test.js.map +1 -1
  235. package/testes/interpretador.test.js +431 -908
  236. package/testes/interpretador.test.js.map +1 -1
  237. package/testes/lexador.test.js +42 -42
  238. package/testes/lexador.test.js.map +1 -1
  239. package/testes/visualg/avaliador-sintatico.test.js +23 -23
  240. package/testes/visualg/avaliador-sintatico.test.js.map +1 -1
  241. package/testes/visualg/interpretador.test.js +16 -61
  242. package/testes/visualg/interpretador.test.js.map +1 -1
  243. package/testes/visualg/lexador.test.js +15 -15
  244. package/testes/visualg/lexador.test.js.map +1 -1
@@ -22,70 +22,34 @@ var __importStar = (this && this.__importStar) || function (mod) {
22
22
  __setModuleDefault(result, mod);
23
23
  return result;
24
24
  };
25
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
26
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
27
- return new (P || (P = Promise))(function (resolve, reject) {
28
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
29
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
30
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
31
- step((generator = generator.apply(thisArg, _arguments || [])).next());
32
- });
33
- };
34
- var __generator = (this && this.__generator) || function (thisArg, body) {
35
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
36
- return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
37
- function verb(n) { return function (v) { return step([n, v]); }; }
38
- function step(op) {
39
- if (f) throw new TypeError("Generator is already executing.");
40
- while (_) try {
41
- if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
42
- if (y = 0, t) op = [op[0] & 2, t.value];
43
- switch (op[0]) {
44
- case 0: case 1: t = op; break;
45
- case 4: _.label++; return { value: op[1], done: false };
46
- case 5: _.label++; y = op[1]; op = [0]; continue;
47
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
48
- default:
49
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
50
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
51
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
52
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
53
- if (t[2]) _.ops.pop();
54
- _.trys.pop(); continue;
55
- }
56
- op = body.call(thisArg, _);
57
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
58
- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
59
- }
60
- };
61
25
  var __importDefault = (this && this.__importDefault) || function (mod) {
62
26
  return (mod && mod.__esModule) ? mod : { "default": mod };
63
27
  };
64
28
  Object.defineProperty(exports, "__esModule", { value: true });
65
29
  exports.InterpretadorEguaClassico = void 0;
66
- var caminho = __importStar(require("path"));
67
- var fs = __importStar(require("fs"));
68
- var espaco_variaveis_1 = require("../../espaco-variaveis");
69
- var delegua_1 = require("../../delegua");
70
- var biblioteca_global_1 = __importDefault(require("../../bibliotecas/biblioteca-global"));
71
- var importar_biblioteca_1 = __importDefault(require("../../bibliotecas/importar-biblioteca"));
72
- var chamavel_1 = require("../../estruturas/chamavel");
73
- var funcao_padrao_1 = require("../../estruturas/funcao-padrao");
74
- var delegua_classe_1 = require("../../estruturas/delegua-classe");
75
- var delegua_funcao_1 = require("../../estruturas/delegua-funcao");
76
- var objeto_delegua_classe_1 = require("../../estruturas/objeto-delegua-classe");
77
- var modulo_1 = require("../../estruturas/modulo");
78
- var excecoes_1 = require("../../excecoes");
79
- var pilha_escopos_execucao_1 = require("../pilha-escopos-execucao");
80
- var quebras_1 = require("../../quebras");
81
- var inferenciador_1 = require("../inferenciador");
82
- var egua_classico_1 = __importDefault(require("../../tipos-de-simbolos/egua-classico"));
30
+ const caminho = __importStar(require("path"));
31
+ const fs = __importStar(require("fs"));
32
+ const espaco_variaveis_1 = require("../../espaco-variaveis");
33
+ const delegua_1 = require("../../delegua");
34
+ const biblioteca_global_1 = __importDefault(require("../../bibliotecas/biblioteca-global"));
35
+ const importar_biblioteca_1 = __importDefault(require("../../bibliotecas/importar-biblioteca"));
36
+ const chamavel_1 = require("../../estruturas/chamavel");
37
+ const funcao_padrao_1 = require("../../estruturas/funcao-padrao");
38
+ const delegua_classe_1 = require("../../estruturas/delegua-classe");
39
+ const delegua_funcao_1 = require("../../estruturas/delegua-funcao");
40
+ const objeto_delegua_classe_1 = require("../../estruturas/objeto-delegua-classe");
41
+ const modulo_1 = require("../../estruturas/modulo");
42
+ const excecoes_1 = require("../../excecoes");
43
+ const pilha_escopos_execucao_1 = require("../pilha-escopos-execucao");
44
+ const quebras_1 = require("../../quebras");
45
+ const inferenciador_1 = require("../inferenciador");
46
+ const egua_classico_1 = __importDefault(require("../../tipos-de-simbolos/egua-classico"));
83
47
  /**
84
48
  * O Interpretador visita todos os elementos complexos gerados pelo analisador sintático (Parser)
85
49
  * e de fato executa a lógica de programação descrita no código.
86
50
  */
87
- var InterpretadorEguaClassico = /** @class */ (function () {
88
- function InterpretadorEguaClassico(Delegua, resolvedor, diretorioBase) {
51
+ class InterpretadorEguaClassico {
52
+ constructor(Delegua, resolvedor, diretorioBase) {
89
53
  this.interfaceEntradaSaida = null;
90
54
  this.Delegua = Delegua;
91
55
  this.resolvedor = resolvedor;
@@ -94,7 +58,7 @@ var InterpretadorEguaClassico = /** @class */ (function () {
94
58
  this.locais = new Map();
95
59
  this.erros = [];
96
60
  this.pilhaEscoposExecucao = new pilha_escopos_execucao_1.PilhaEscoposExecucao();
97
- var escopoExecucao = {
61
+ const escopoExecucao = {
98
62
  declaracoes: [],
99
63
  declaracaoAtual: 0,
100
64
  ambiente: new espaco_variaveis_1.EspacoVariaveis(),
@@ -102,56 +66,47 @@ var InterpretadorEguaClassico = /** @class */ (function () {
102
66
  this.pilhaEscoposExecucao.empilhar(escopoExecucao);
103
67
  (0, biblioteca_global_1.default)(this, this.pilhaEscoposExecucao);
104
68
  }
105
- InterpretadorEguaClassico.prototype.visitarExpressaoLeia = function (expressao) {
69
+ visitarExpressaoLeia(expressao) {
106
70
  throw new Error('Método não implementado.');
107
- };
108
- InterpretadorEguaClassico.prototype.visitarExpressaoLiteral = function (expressao) {
71
+ }
72
+ visitarExpressaoLiteral(expressao) {
109
73
  return expressao.valor;
110
- };
111
- InterpretadorEguaClassico.prototype.avaliar = function (expressao) {
74
+ }
75
+ avaliar(expressao) {
112
76
  return expressao.aceitar(this);
113
- };
114
- InterpretadorEguaClassico.prototype.visitarExpressaoAgrupamento = function (expressao) {
77
+ }
78
+ visitarExpressaoAgrupamento(expressao) {
115
79
  return this.avaliar(expressao.expressao);
116
- };
117
- InterpretadorEguaClassico.prototype.eVerdadeiro = function (objeto) {
80
+ }
81
+ eVerdadeiro(objeto) {
118
82
  if (objeto === null)
119
83
  return false;
120
84
  if (typeof objeto === 'boolean')
121
85
  return Boolean(objeto);
122
86
  return true;
123
- };
124
- InterpretadorEguaClassico.prototype.verificarOperandoNumero = function (operador, operando) {
87
+ }
88
+ verificarOperandoNumero(operador, operando) {
125
89
  if (typeof operando === 'number' || operando.tipo === 'número')
126
90
  return;
127
91
  throw new excecoes_1.ErroEmTempoDeExecucao(operador, 'Operador precisa ser um número.', operador.linha);
128
- };
129
- InterpretadorEguaClassico.prototype.visitarExpressaoUnaria = function (expr) {
130
- return __awaiter(this, void 0, void 0, function () {
131
- var direita, valor;
132
- return __generator(this, function (_a) {
133
- switch (_a.label) {
134
- case 0: return [4 /*yield*/, this.avaliar(expr.direita)];
135
- case 1:
136
- direita = _a.sent();
137
- valor = direita.hasOwnProperty('valor') ?
138
- direita.valor :
139
- direita;
140
- switch (expr.operador.tipo) {
141
- case egua_classico_1.default.SUBTRACAO:
142
- this.verificarOperandoNumero(expr.operador, valor);
143
- return [2 /*return*/, -valor];
144
- case egua_classico_1.default.NEGACAO:
145
- return [2 /*return*/, !this.eVerdadeiro(valor)];
146
- case egua_classico_1.default.BIT_NOT:
147
- return [2 /*return*/, ~valor];
148
- }
149
- return [2 /*return*/, null];
150
- }
151
- });
152
- });
153
- };
154
- InterpretadorEguaClassico.prototype.eIgual = function (esquerda, direita) {
92
+ }
93
+ async visitarExpressaoUnaria(expr) {
94
+ const direita = await this.avaliar(expr.direita);
95
+ const valor = direita.hasOwnProperty('valor') ?
96
+ direita.valor :
97
+ direita;
98
+ switch (expr.operador.tipo) {
99
+ case egua_classico_1.default.SUBTRACAO:
100
+ this.verificarOperandoNumero(expr.operador, valor);
101
+ return -valor;
102
+ case egua_classico_1.default.NEGACAO:
103
+ return !this.eVerdadeiro(valor);
104
+ case egua_classico_1.default.BIT_NOT:
105
+ return ~valor;
106
+ }
107
+ return null;
108
+ }
109
+ eIgual(esquerda, direita) {
155
110
  if (esquerda.tipo) {
156
111
  if (esquerda.tipo === 'nulo' &&
157
112
  direita.tipo &&
@@ -166,14 +121,14 @@ var InterpretadorEguaClassico = /** @class */ (function () {
166
121
  if (esquerda === null)
167
122
  return false;
168
123
  return esquerda === direita;
169
- };
170
- InterpretadorEguaClassico.prototype.verificarOperandosNumeros = function (operador, direita, esquerda) {
171
- var tipoDireita = direita.tipo
124
+ }
125
+ verificarOperandosNumeros(operador, direita, esquerda) {
126
+ const tipoDireita = direita.tipo
172
127
  ? direita.tipo
173
128
  : typeof direita === 'number'
174
129
  ? 'número'
175
130
  : String(NaN);
176
- var tipoEsquerda = esquerda.tipo
131
+ const tipoEsquerda = esquerda.tipo
177
132
  ? esquerda.tipo
178
133
  : typeof esquerda === 'number'
179
134
  ? 'número'
@@ -181,537 +136,325 @@ var InterpretadorEguaClassico = /** @class */ (function () {
181
136
  if (tipoDireita === 'número' && tipoEsquerda === 'número')
182
137
  return;
183
138
  throw new excecoes_1.ErroEmTempoDeExecucao(operador, 'Operadores precisam ser números.', operador.linha);
184
- };
185
- InterpretadorEguaClassico.prototype.visitarExpressaoBinaria = function (expressao) {
186
- return __awaiter(this, void 0, void 0, function () {
187
- var esquerda, direita, valorEsquerdo, valorDireito, tipoEsquerdo, tipoDireito, erro_1;
188
- return __generator(this, function (_a) {
189
- switch (_a.label) {
190
- case 0:
191
- _a.trys.push([0, 3, , 4]);
192
- return [4 /*yield*/, this.avaliar(expressao.esquerda)];
193
- case 1:
194
- esquerda = _a.sent();
195
- return [4 /*yield*/, this.avaliar(expressao.direita)];
196
- case 2:
197
- direita = _a.sent();
198
- valorEsquerdo = esquerda.hasOwnProperty('valor')
199
- ? esquerda.valor
200
- : esquerda;
201
- valorDireito = direita.hasOwnProperty('valor')
202
- ? direita.valor
203
- : direita;
204
- tipoEsquerdo = esquerda.hasOwnProperty('tipo')
205
- ? esquerda.tipo
206
- : (0, inferenciador_1.inferirTipoVariavel)(esquerda);
207
- tipoDireito = direita.hasOwnProperty('tipo')
208
- ? direita.tipo
209
- : (0, inferenciador_1.inferirTipoVariavel)(direita);
210
- switch (expressao.operador.tipo) {
211
- case egua_classico_1.default.EXPONENCIACAO:
212
- this.verificarOperandosNumeros(expressao.operador, esquerda, direita);
213
- return [2 /*return*/, Math.pow(valorEsquerdo, valorDireito)];
214
- case egua_classico_1.default.MAIOR:
215
- this.verificarOperandosNumeros(expressao.operador, esquerda, direita);
216
- return [2 /*return*/, Number(valorEsquerdo) > Number(valorDireito)];
217
- case egua_classico_1.default.MAIOR_IGUAL:
218
- this.verificarOperandosNumeros(expressao.operador, esquerda, direita);
219
- return [2 /*return*/, Number(valorEsquerdo) >= Number(valorDireito)];
220
- case egua_classico_1.default.MENOR:
221
- this.verificarOperandosNumeros(expressao.operador, esquerda, direita);
222
- return [2 /*return*/, Number(valorEsquerdo) < Number(valorDireito)];
223
- case egua_classico_1.default.MENOR_IGUAL:
224
- this.verificarOperandosNumeros(expressao.operador, esquerda, direita);
225
- return [2 /*return*/, Number(valorEsquerdo) <= Number(valorDireito)];
226
- case egua_classico_1.default.SUBTRACAO:
227
- this.verificarOperandosNumeros(expressao.operador, esquerda, direita);
228
- return [2 /*return*/, Number(valorEsquerdo) - Number(valorDireito)];
229
- case egua_classico_1.default.ADICAO:
230
- if (tipoEsquerdo === 'número' && tipoDireito === 'número') {
231
- return [2 /*return*/, Number(esquerda) + Number(direita)];
232
- }
233
- else if (tipoEsquerdo === 'texto' &&
234
- tipoDireito === 'texto') {
235
- return [2 /*return*/, String(esquerda) + String(direita)];
236
- }
237
- throw new excecoes_1.ErroEmTempoDeExecucao(expressao.operador, 'Operadores precisam ser dois números ou duas strings.');
238
- case egua_classico_1.default.DIVISAO:
239
- this.verificarOperandosNumeros(expressao.operador, esquerda, direita);
240
- return [2 /*return*/, Number(valorEsquerdo) / Number(valorDireito)];
241
- case egua_classico_1.default.MULTIPLICACAO:
242
- this.verificarOperandosNumeros(expressao.operador, esquerda, direita);
243
- return [2 /*return*/, Number(valorEsquerdo) * Number(valorDireito)];
244
- case egua_classico_1.default.MODULO:
245
- this.verificarOperandosNumeros(expressao.operador, esquerda, direita);
246
- return [2 /*return*/, Number(valorEsquerdo) % Number(valorDireito)];
247
- case egua_classico_1.default.BIT_AND:
248
- this.verificarOperandosNumeros(expressao.operador, esquerda, direita);
249
- return [2 /*return*/, Number(valorEsquerdo) & Number(valorDireito)];
250
- case egua_classico_1.default.BIT_XOR:
251
- this.verificarOperandosNumeros(expressao.operador, esquerda, direita);
252
- return [2 /*return*/, Number(valorEsquerdo) ^ Number(valorDireito)];
253
- case egua_classico_1.default.BIT_OR:
254
- this.verificarOperandosNumeros(expressao.operador, esquerda, direita);
255
- return [2 /*return*/, Number(valorEsquerdo) | Number(valorDireito)];
256
- case egua_classico_1.default.MENOR_MENOR:
257
- this.verificarOperandosNumeros(expressao.operador, esquerda, direita);
258
- return [2 /*return*/, Number(valorEsquerdo) << Number(valorDireito)];
259
- case egua_classico_1.default.MAIOR_MAIOR:
260
- this.verificarOperandosNumeros(expressao.operador, esquerda, direita);
261
- return [2 /*return*/, Number(valorEsquerdo) >> Number(valorDireito)];
262
- case egua_classico_1.default.DIFERENTE:
263
- return [2 /*return*/, !this.eIgual(valorEsquerdo, valorDireito)];
264
- case egua_classico_1.default.IGUAL_IGUAL:
265
- return [2 /*return*/, this.eIgual(valorEsquerdo, valorDireito)];
266
- }
267
- return [2 /*return*/, null];
268
- case 3:
269
- erro_1 = _a.sent();
270
- return [2 /*return*/, Promise.reject(erro_1)];
271
- case 4: return [2 /*return*/];
272
- }
273
- });
274
- });
275
- };
276
- InterpretadorEguaClassico.prototype.visitarExpressaoDeChamada = function (expressao) {
277
- return __awaiter(this, void 0, void 0, function () {
278
- var variavelEntidadeChamada, entidadeChamada, argumentos, i, _a, _b, parametros, diferenca, i, novosArgumentos;
279
- return __generator(this, function (_c) {
280
- switch (_c.label) {
281
- case 0: return [4 /*yield*/, this.avaliar(expressao.entidadeChamada)];
282
- case 1:
283
- variavelEntidadeChamada = _c.sent();
284
- entidadeChamada = variavelEntidadeChamada.hasOwnProperty('valor')
285
- ? variavelEntidadeChamada.valor
286
- : variavelEntidadeChamada;
287
- argumentos = [];
288
- i = 0;
289
- _c.label = 2;
290
- case 2:
291
- if (!(i < expressao.argumentos.length)) return [3 /*break*/, 5];
292
- _b = (_a = argumentos).push;
293
- return [4 /*yield*/, this.avaliar(expressao.argumentos[i])];
294
- case 3:
295
- _b.apply(_a, [_c.sent()]);
296
- _c.label = 4;
297
- case 4:
298
- i++;
299
- return [3 /*break*/, 2];
300
- case 5:
301
- if (!(entidadeChamada instanceof chamavel_1.Chamavel)) {
302
- throw new excecoes_1.ErroEmTempoDeExecucao(expressao.parentese, 'Só pode chamar função ou classe.', expressao.linha);
303
- }
304
- if (entidadeChamada instanceof delegua_funcao_1.DeleguaFuncao) {
305
- parametros = entidadeChamada.declaracao.parametros;
306
- }
307
- else if (entidadeChamada instanceof delegua_classe_1.DeleguaClasse) {
308
- parametros = entidadeChamada.metodos.inicializacao
309
- ? entidadeChamada.metodos.inicializacao.declaracao.parametros
310
- : [];
311
- }
312
- else {
313
- parametros = [];
314
- }
315
- // Isso aqui completa os parâmetros não preenchidos com nulos.
316
- if (argumentos.length < entidadeChamada.aridade()) {
317
- diferenca = entidadeChamada.aridade() - argumentos.length;
318
- for (i = 0; i < diferenca; i++) {
319
- argumentos.push(null);
320
- }
321
- }
322
- else {
323
- if (parametros &&
324
- parametros.length > 0 &&
325
- parametros[parametros.length - 1]['tipo'] === 'estrela') {
326
- novosArgumentos = argumentos.slice(0, parametros.length - 1);
327
- novosArgumentos.push(argumentos.slice(parametros.length - 1, argumentos.length));
328
- argumentos = novosArgumentos;
329
- }
330
- }
331
- if (entidadeChamada instanceof funcao_padrao_1.FuncaoPadrao) {
332
- return [2 /*return*/, entidadeChamada.chamar(argumentos, expressao.entidadeChamada.nome)];
333
- }
334
- return [2 /*return*/, entidadeChamada.chamar(this, argumentos)];
335
- }
336
- });
337
- });
338
- };
339
- InterpretadorEguaClassico.prototype.visitarExpressaoDeAtribuicao = function (expressao) {
340
- return __awaiter(this, void 0, void 0, function () {
341
- var valor;
342
- return __generator(this, function (_a) {
343
- switch (_a.label) {
344
- case 0: return [4 /*yield*/, this.avaliar(expressao.valor)];
345
- case 1:
346
- valor = _a.sent();
347
- this.pilhaEscoposExecucao.atribuirVariavel(expressao.simbolo, valor);
348
- return [2 /*return*/, valor];
349
- }
350
- });
351
- });
352
- };
353
- InterpretadorEguaClassico.prototype.procurarVariavel = function (simbolo, expressao) {
139
+ }
140
+ async visitarExpressaoBinaria(expressao) {
141
+ try {
142
+ const esquerda = await this.avaliar(expressao.esquerda);
143
+ const direita = await this.avaliar(expressao.direita);
144
+ const valorEsquerdo = esquerda.hasOwnProperty('valor')
145
+ ? esquerda.valor
146
+ : esquerda;
147
+ const valorDireito = direita.hasOwnProperty('valor')
148
+ ? direita.valor
149
+ : direita;
150
+ const tipoEsquerdo = esquerda.hasOwnProperty('tipo')
151
+ ? esquerda.tipo
152
+ : (0, inferenciador_1.inferirTipoVariavel)(esquerda);
153
+ const tipoDireito = direita.hasOwnProperty('tipo')
154
+ ? direita.tipo
155
+ : (0, inferenciador_1.inferirTipoVariavel)(direita);
156
+ switch (expressao.operador.tipo) {
157
+ case egua_classico_1.default.EXPONENCIACAO:
158
+ this.verificarOperandosNumeros(expressao.operador, esquerda, direita);
159
+ return Math.pow(valorEsquerdo, valorDireito);
160
+ case egua_classico_1.default.MAIOR:
161
+ this.verificarOperandosNumeros(expressao.operador, esquerda, direita);
162
+ return Number(valorEsquerdo) > Number(valorDireito);
163
+ case egua_classico_1.default.MAIOR_IGUAL:
164
+ this.verificarOperandosNumeros(expressao.operador, esquerda, direita);
165
+ return Number(valorEsquerdo) >= Number(valorDireito);
166
+ case egua_classico_1.default.MENOR:
167
+ this.verificarOperandosNumeros(expressao.operador, esquerda, direita);
168
+ return Number(valorEsquerdo) < Number(valorDireito);
169
+ case egua_classico_1.default.MENOR_IGUAL:
170
+ this.verificarOperandosNumeros(expressao.operador, esquerda, direita);
171
+ return Number(valorEsquerdo) <= Number(valorDireito);
172
+ case egua_classico_1.default.SUBTRACAO:
173
+ this.verificarOperandosNumeros(expressao.operador, esquerda, direita);
174
+ return Number(valorEsquerdo) - Number(valorDireito);
175
+ case egua_classico_1.default.ADICAO:
176
+ if (tipoEsquerdo === 'número' && tipoDireito === 'número') {
177
+ return Number(esquerda) + Number(direita);
178
+ }
179
+ else if (tipoEsquerdo === 'texto' &&
180
+ tipoDireito === 'texto') {
181
+ return String(esquerda) + String(direita);
182
+ }
183
+ throw new excecoes_1.ErroEmTempoDeExecucao(expressao.operador, 'Operadores precisam ser dois números ou duas strings.');
184
+ case egua_classico_1.default.DIVISAO:
185
+ this.verificarOperandosNumeros(expressao.operador, esquerda, direita);
186
+ return Number(valorEsquerdo) / Number(valorDireito);
187
+ case egua_classico_1.default.MULTIPLICACAO:
188
+ this.verificarOperandosNumeros(expressao.operador, esquerda, direita);
189
+ return Number(valorEsquerdo) * Number(valorDireito);
190
+ case egua_classico_1.default.MODULO:
191
+ this.verificarOperandosNumeros(expressao.operador, esquerda, direita);
192
+ return Number(valorEsquerdo) % Number(valorDireito);
193
+ case egua_classico_1.default.BIT_AND:
194
+ this.verificarOperandosNumeros(expressao.operador, esquerda, direita);
195
+ return Number(valorEsquerdo) & Number(valorDireito);
196
+ case egua_classico_1.default.BIT_XOR:
197
+ this.verificarOperandosNumeros(expressao.operador, esquerda, direita);
198
+ return Number(valorEsquerdo) ^ Number(valorDireito);
199
+ case egua_classico_1.default.BIT_OR:
200
+ this.verificarOperandosNumeros(expressao.operador, esquerda, direita);
201
+ return Number(valorEsquerdo) | Number(valorDireito);
202
+ case egua_classico_1.default.MENOR_MENOR:
203
+ this.verificarOperandosNumeros(expressao.operador, esquerda, direita);
204
+ return Number(valorEsquerdo) << Number(valorDireito);
205
+ case egua_classico_1.default.MAIOR_MAIOR:
206
+ this.verificarOperandosNumeros(expressao.operador, esquerda, direita);
207
+ return Number(valorEsquerdo) >> Number(valorDireito);
208
+ case egua_classico_1.default.DIFERENTE:
209
+ return !this.eIgual(valorEsquerdo, valorDireito);
210
+ case egua_classico_1.default.IGUAL_IGUAL:
211
+ return this.eIgual(valorEsquerdo, valorDireito);
212
+ }
213
+ return null;
214
+ }
215
+ catch (erro) {
216
+ return Promise.reject(erro);
217
+ }
218
+ }
219
+ async visitarExpressaoDeChamada(expressao) {
220
+ const variavelEntidadeChamada = await this.avaliar(expressao.entidadeChamada);
221
+ const entidadeChamada = variavelEntidadeChamada.hasOwnProperty('valor')
222
+ ? variavelEntidadeChamada.valor
223
+ : variavelEntidadeChamada;
224
+ let argumentos = [];
225
+ for (let i = 0; i < expressao.argumentos.length; i++) {
226
+ argumentos.push(await this.avaliar(expressao.argumentos[i]));
227
+ }
228
+ if (!(entidadeChamada instanceof chamavel_1.Chamavel)) {
229
+ throw new excecoes_1.ErroEmTempoDeExecucao(expressao.parentese, 'Só pode chamar função ou classe.', expressao.linha);
230
+ }
231
+ let parametros;
232
+ if (entidadeChamada instanceof delegua_funcao_1.DeleguaFuncao) {
233
+ parametros = entidadeChamada.declaracao.parametros;
234
+ }
235
+ else if (entidadeChamada instanceof delegua_classe_1.DeleguaClasse) {
236
+ parametros = entidadeChamada.metodos.inicializacao
237
+ ? entidadeChamada.metodos.inicializacao.declaracao.parametros
238
+ : [];
239
+ }
240
+ else {
241
+ parametros = [];
242
+ }
243
+ // Isso aqui completa os parâmetros não preenchidos com nulos.
244
+ if (argumentos.length < entidadeChamada.aridade()) {
245
+ const diferenca = entidadeChamada.aridade() - argumentos.length;
246
+ for (let i = 0; i < diferenca; i++) {
247
+ argumentos.push(null);
248
+ }
249
+ }
250
+ else {
251
+ if (parametros &&
252
+ parametros.length > 0 &&
253
+ parametros[parametros.length - 1]['tipo'] === 'estrela') {
254
+ const novosArgumentos = argumentos.slice(0, parametros.length - 1);
255
+ novosArgumentos.push(argumentos.slice(parametros.length - 1, argumentos.length));
256
+ argumentos = novosArgumentos;
257
+ }
258
+ }
259
+ if (entidadeChamada instanceof funcao_padrao_1.FuncaoPadrao) {
260
+ return entidadeChamada.chamar(argumentos, expressao.entidadeChamada.nome);
261
+ }
262
+ return entidadeChamada.chamar(this, argumentos);
263
+ }
264
+ async visitarExpressaoDeAtribuicao(expressao) {
265
+ const valor = await this.avaliar(expressao.valor);
266
+ this.pilhaEscoposExecucao.atribuirVariavel(expressao.simbolo, valor);
267
+ return valor;
268
+ }
269
+ procurarVariavel(simbolo, expressao) {
354
270
  return this.pilhaEscoposExecucao.obterVariavel(simbolo);
355
- };
356
- InterpretadorEguaClassico.prototype.visitarExpressaoDeVariavel = function (expressao) {
271
+ }
272
+ visitarExpressaoDeVariavel(expressao) {
357
273
  return this.procurarVariavel(expressao.simbolo, expressao);
358
- };
359
- InterpretadorEguaClassico.prototype.visitarDeclaracaoDeExpressao = function (declaracao) {
360
- return __awaiter(this, void 0, void 0, function () {
361
- return __generator(this, function (_a) {
362
- switch (_a.label) {
363
- case 0: return [4 /*yield*/, this.avaliar(declaracao.expressao)];
364
- case 1: return [2 /*return*/, _a.sent()];
365
- }
366
- });
367
- });
368
- };
369
- InterpretadorEguaClassico.prototype.visitarExpressaoLogica = function (expressao) {
370
- return __awaiter(this, void 0, void 0, function () {
371
- var esquerda, direita;
372
- return __generator(this, function (_a) {
373
- switch (_a.label) {
374
- case 0: return [4 /*yield*/, this.avaliar(expressao.esquerda)];
375
- case 1:
376
- esquerda = _a.sent();
377
- if (!(expressao.operador.tipo === egua_classico_1.default.EM)) return [3 /*break*/, 3];
378
- return [4 /*yield*/, this.avaliar(expressao.direita)];
379
- case 2:
380
- direita = _a.sent();
381
- if (Array.isArray(direita) || typeof direita === 'string') {
382
- return [2 /*return*/, direita.includes(esquerda)];
383
- }
384
- else if (direita.constructor === Object) {
385
- return [2 /*return*/, esquerda in direita];
386
- }
387
- else {
388
- throw new excecoes_1.ErroEmTempoDeExecucao(esquerda, "Tipo de chamada inválida com 'em'.", expressao.linha);
389
- }
390
- _a.label = 3;
391
- case 3:
392
- // se um estado for verdadeiro, retorna verdadeiro
393
- if (expressao.operador.tipo === egua_classico_1.default.OU) {
394
- if (this.eVerdadeiro(esquerda))
395
- return [2 /*return*/, esquerda];
396
- }
397
- // se um estado for falso, retorna falso
398
- if (expressao.operador.tipo === egua_classico_1.default.E) {
399
- if (!this.eVerdadeiro(esquerda))
400
- return [2 /*return*/, esquerda];
401
- }
402
- return [4 /*yield*/, this.avaliar(expressao.direita)];
403
- case 4: return [2 /*return*/, _a.sent()];
404
- }
405
- });
406
- });
407
- };
408
- InterpretadorEguaClassico.prototype.visitarExpressaoSe = function (declaracao) {
409
- return __awaiter(this, void 0, void 0, function () {
410
- var _a, i, atual, _b;
411
- return __generator(this, function (_c) {
412
- switch (_c.label) {
413
- case 0:
414
- _a = this.eVerdadeiro;
415
- return [4 /*yield*/, this.avaliar(declaracao.condicao)];
416
- case 1:
417
- if (!_a.apply(this, [_c.sent()])) return [3 /*break*/, 3];
418
- return [4 /*yield*/, this.executar(declaracao.caminhoEntao)];
419
- case 2: return [2 /*return*/, _c.sent()];
420
- case 3:
421
- i = 0;
422
- _c.label = 4;
423
- case 4:
424
- if (!(i < declaracao.caminhosSeSenao.length)) return [3 /*break*/, 8];
425
- atual = declaracao.caminhosSeSenao[i];
426
- _b = this.eVerdadeiro;
427
- return [4 /*yield*/, this.avaliar(atual.condicao)];
428
- case 5:
429
- if (!_b.apply(this, [_c.sent()])) return [3 /*break*/, 7];
430
- return [4 /*yield*/, this.executar(atual.caminho)];
431
- case 6: return [2 /*return*/, _c.sent()];
432
- case 7:
433
- i++;
434
- return [3 /*break*/, 4];
435
- case 8:
436
- if (!(declaracao.caminhoSenao !== null)) return [3 /*break*/, 10];
437
- return [4 /*yield*/, this.executar(declaracao.caminhoSenao)];
438
- case 9: return [2 /*return*/, _c.sent()];
439
- case 10: return [2 /*return*/, null];
440
- }
441
- });
442
- });
443
- };
444
- InterpretadorEguaClassico.prototype.visitarExpressaoPara = function (declaracao) {
445
- return __awaiter(this, void 0, void 0, function () {
446
- var _a, erro_2;
447
- return __generator(this, function (_b) {
448
- switch (_b.label) {
449
- case 0:
450
- if (!(declaracao.inicializador !== null)) return [3 /*break*/, 2];
451
- return [4 /*yield*/, this.avaliar(declaracao.inicializador)];
452
- case 1:
453
- _b.sent();
454
- _b.label = 2;
455
- case 2:
456
- if (!true) return [3 /*break*/, 10];
457
- if (!(declaracao.condicao !== null)) return [3 /*break*/, 4];
458
- _a = this.eVerdadeiro;
459
- return [4 /*yield*/, this.avaliar(declaracao.condicao)];
460
- case 3:
461
- if (!_a.apply(this, [_b.sent()])) {
462
- return [3 /*break*/, 10];
463
- }
464
- _b.label = 4;
465
- case 4:
466
- _b.trys.push([4, 6, , 7]);
467
- return [4 /*yield*/, this.executar(declaracao.corpo)];
468
- case 5:
469
- _b.sent();
470
- return [3 /*break*/, 7];
471
- case 6:
472
- erro_2 = _b.sent();
473
- throw erro_2;
474
- case 7:
475
- if (!(declaracao.incrementar !== null)) return [3 /*break*/, 9];
476
- return [4 /*yield*/, this.avaliar(declaracao.incrementar)];
477
- case 8:
478
- _b.sent();
479
- _b.label = 9;
480
- case 9: return [3 /*break*/, 2];
481
- case 10: return [2 /*return*/, null];
482
- }
483
- });
484
- });
485
- };
486
- InterpretadorEguaClassico.prototype.visitarExpressaoFazer = function (declaracao) {
487
- return __awaiter(this, void 0, void 0, function () {
488
- var erro_3, _a;
489
- return __generator(this, function (_b) {
490
- switch (_b.label) {
491
- case 0:
492
- _b.trys.push([0, 2, , 3]);
493
- return [4 /*yield*/, this.executar(declaracao.caminhoFazer)];
494
- case 1:
495
- _b.sent();
496
- return [3 /*break*/, 3];
497
- case 2:
498
- erro_3 = _b.sent();
499
- throw erro_3;
500
- case 3:
501
- _a = this.eVerdadeiro;
502
- return [4 /*yield*/, this.avaliar(declaracao.condicaoEnquanto)];
503
- case 4:
504
- if (_a.apply(this, [_b.sent()])) return [3 /*break*/, 0];
505
- _b.label = 5;
506
- case 5: return [2 /*return*/];
274
+ }
275
+ async visitarDeclaracaoDeExpressao(declaracao) {
276
+ return await this.avaliar(declaracao.expressao);
277
+ }
278
+ async visitarExpressaoLogica(expressao) {
279
+ const esquerda = await this.avaliar(expressao.esquerda);
280
+ if (expressao.operador.tipo === egua_classico_1.default.EM) {
281
+ const direita = await this.avaliar(expressao.direita);
282
+ if (Array.isArray(direita) || typeof direita === 'string') {
283
+ return direita.includes(esquerda);
284
+ }
285
+ else if (direita.constructor === Object) {
286
+ return esquerda in direita;
287
+ }
288
+ else {
289
+ throw new excecoes_1.ErroEmTempoDeExecucao(esquerda, "Tipo de chamada inválida com 'em'.", expressao.linha);
290
+ }
291
+ }
292
+ // se um estado for verdadeiro, retorna verdadeiro
293
+ if (expressao.operador.tipo === egua_classico_1.default.OU) {
294
+ if (this.eVerdadeiro(esquerda))
295
+ return esquerda;
296
+ }
297
+ // se um estado for falso, retorna falso
298
+ if (expressao.operador.tipo === egua_classico_1.default.E) {
299
+ if (!this.eVerdadeiro(esquerda))
300
+ return esquerda;
301
+ }
302
+ return await this.avaliar(expressao.direita);
303
+ }
304
+ async visitarExpressaoSe(declaracao) {
305
+ if (this.eVerdadeiro(await this.avaliar(declaracao.condicao))) {
306
+ return await this.executar(declaracao.caminhoEntao);
307
+ }
308
+ for (let i = 0; i < declaracao.caminhosSeSenao.length; i++) {
309
+ const atual = declaracao.caminhosSeSenao[i];
310
+ if (this.eVerdadeiro(await this.avaliar(atual.condicao))) {
311
+ return await this.executar(atual.caminho);
312
+ }
313
+ }
314
+ if (declaracao.caminhoSenao !== null) {
315
+ return await this.executar(declaracao.caminhoSenao);
316
+ }
317
+ return null;
318
+ }
319
+ async visitarExpressaoPara(declaracao) {
320
+ if (declaracao.inicializador !== null) {
321
+ await this.avaliar(declaracao.inicializador);
322
+ }
323
+ while (true) {
324
+ if (declaracao.condicao !== null) {
325
+ if (!this.eVerdadeiro(await this.avaliar(declaracao.condicao))) {
326
+ break;
507
327
  }
508
- });
509
- });
510
- };
511
- InterpretadorEguaClassico.prototype.visitarExpressaoEscolha = function (declaracao) {
512
- return __awaiter(this, void 0, void 0, function () {
513
- var condicaoEscolha, caminhos, caminhoPadrao, encontrado, i, caminho_1, j, k, erro_4, i, erro_5;
514
- return __generator(this, function (_a) {
515
- switch (_a.label) {
516
- case 0: return [4 /*yield*/, this.avaliar(declaracao.identificadorOuLiteral)];
517
- case 1:
518
- condicaoEscolha = _a.sent();
519
- caminhos = declaracao.caminhos;
520
- caminhoPadrao = declaracao.caminhoPadrao;
521
- encontrado = false;
522
- _a.label = 2;
523
- case 2:
524
- _a.trys.push([2, 19, , 20]);
525
- i = 0;
526
- _a.label = 3;
527
- case 3:
528
- if (!(i < caminhos.length)) return [3 /*break*/, 14];
529
- caminho_1 = caminhos[i];
530
- j = 0;
531
- _a.label = 4;
532
- case 4:
533
- if (!(j < caminho_1.condicoes.length)) return [3 /*break*/, 13];
534
- return [4 /*yield*/, this.avaliar(caminho_1.condicoes[j])];
535
- case 5:
536
- if (!((_a.sent()) === condicaoEscolha)) return [3 /*break*/, 12];
328
+ }
329
+ try {
330
+ await this.executar(declaracao.corpo);
331
+ }
332
+ catch (erro) {
333
+ throw erro;
334
+ }
335
+ if (declaracao.incrementar !== null) {
336
+ await this.avaliar(declaracao.incrementar);
337
+ }
338
+ }
339
+ return null;
340
+ }
341
+ async visitarExpressaoFazer(declaracao) {
342
+ do {
343
+ try {
344
+ await this.executar(declaracao.caminhoFazer);
345
+ }
346
+ catch (erro) {
347
+ throw erro;
348
+ }
349
+ } while (this.eVerdadeiro(await this.avaliar(declaracao.condicaoEnquanto)));
350
+ }
351
+ async visitarExpressaoEscolha(declaracao) {
352
+ const condicaoEscolha = await this.avaliar(declaracao.identificadorOuLiteral);
353
+ const caminhos = declaracao.caminhos;
354
+ const caminhoPadrao = declaracao.caminhoPadrao;
355
+ let encontrado = false;
356
+ try {
357
+ for (let i = 0; i < caminhos.length; i++) {
358
+ const caminho = caminhos[i];
359
+ for (let j = 0; j < caminho.condicoes.length; j++) {
360
+ if (await this.avaliar(caminho.condicoes[j]) === condicaoEscolha) {
537
361
  encontrado = true;
538
- _a.label = 6;
539
- case 6:
540
- _a.trys.push([6, 11, , 12]);
541
- k = 0;
542
- _a.label = 7;
543
- case 7:
544
- if (!(k < caminho_1.declaracoes.length)) return [3 /*break*/, 10];
545
- return [4 /*yield*/, this.executar(caminho_1.declaracoes[k])];
546
- case 8:
547
- _a.sent();
548
- _a.label = 9;
549
- case 9:
550
- k++;
551
- return [3 /*break*/, 7];
552
- case 10: return [3 /*break*/, 12];
553
- case 11:
554
- erro_4 = _a.sent();
555
- throw erro_4;
556
- case 12:
557
- j++;
558
- return [3 /*break*/, 4];
559
- case 13:
560
- i++;
561
- return [3 /*break*/, 3];
562
- case 14:
563
- if (!(caminhoPadrao !== null && encontrado === false)) return [3 /*break*/, 18];
564
- i = 0;
565
- _a.label = 15;
566
- case 15:
567
- if (!(i < caminhoPadrao.declaracoes.length)) return [3 /*break*/, 18];
568
- return [4 /*yield*/, this.executar(caminhoPadrao['declaracoes'][i])];
569
- case 16:
570
- _a.sent();
571
- _a.label = 17;
572
- case 17:
573
- i++;
574
- return [3 /*break*/, 15];
575
- case 18: return [3 /*break*/, 20];
576
- case 19:
577
- erro_5 = _a.sent();
578
- throw erro_5;
579
- case 20: return [2 /*return*/];
580
- }
581
- });
582
- });
583
- };
584
- InterpretadorEguaClassico.prototype.visitarExpressaoTente = function (declaracao) {
585
- return __awaiter(this, void 0, void 0, function () {
586
- var sucesso, erro_6;
587
- return __generator(this, function (_a) {
588
- switch (_a.label) {
589
- case 0:
590
- _a.trys.push([0, , 10, 13]);
591
- sucesso = true;
592
- _a.label = 1;
593
- case 1:
594
- _a.trys.push([1, 3, , 7]);
595
- return [4 /*yield*/, this.executarBloco(declaracao.caminhoTente)];
596
- case 2:
597
- _a.sent();
598
- return [3 /*break*/, 7];
599
- case 3:
600
- erro_6 = _a.sent();
601
- sucesso = false;
602
- if (!(declaracao.caminhoPegue !== null)) return [3 /*break*/, 5];
603
- return [4 /*yield*/, this.executarBloco(declaracao.caminhoPegue)];
604
- case 4:
605
- _a.sent();
606
- return [3 /*break*/, 6];
607
- case 5:
608
- this.erros.push(erro_6);
609
- _a.label = 6;
610
- case 6: return [3 /*break*/, 7];
611
- case 7:
612
- if (!(sucesso && declaracao.caminhoSenao !== null)) return [3 /*break*/, 9];
613
- return [4 /*yield*/, this.executarBloco(declaracao.caminhoSenao)];
614
- case 8:
615
- _a.sent();
616
- _a.label = 9;
617
- case 9: return [3 /*break*/, 13];
618
- case 10:
619
- if (!(declaracao.caminhoFinalmente !== null)) return [3 /*break*/, 12];
620
- return [4 /*yield*/, this.executarBloco(declaracao.caminhoFinalmente)];
621
- case 11:
622
- _a.sent();
623
- _a.label = 12;
624
- case 12: return [7 /*endfinally*/];
625
- case 13: return [2 /*return*/];
626
- }
627
- });
628
- });
629
- };
630
- InterpretadorEguaClassico.prototype.visitarExpressaoEnquanto = function (declaracao) {
631
- return __awaiter(this, void 0, void 0, function () {
632
- var _a, erro_7;
633
- return __generator(this, function (_b) {
634
- switch (_b.label) {
635
- case 0:
636
- _a = this.eVerdadeiro;
637
- return [4 /*yield*/, this.avaliar(declaracao.condicao)];
638
- case 1:
639
- if (!_a.apply(this, [_b.sent()])) return [3 /*break*/, 6];
640
- _b.label = 2;
641
- case 2:
642
- _b.trys.push([2, 4, , 5]);
643
- return [4 /*yield*/, this.executar(declaracao.corpo)];
644
- case 3:
645
- _b.sent();
646
- return [3 /*break*/, 5];
647
- case 4:
648
- erro_7 = _b.sent();
649
- throw erro_7;
650
- case 5: return [3 /*break*/, 0];
651
- case 6: return [2 /*return*/, null];
652
- }
653
- });
654
- });
655
- };
656
- InterpretadorEguaClassico.prototype.visitarExpressaoImportar = function (declaracao) {
657
- return __awaiter(this, void 0, void 0, function () {
658
- var caminhoRelativo, caminhoTotal, dados, delegua, exportar, eDicionario, novoModulo, chaves, i;
659
- return __generator(this, function (_a) {
660
- switch (_a.label) {
661
- case 0: return [4 /*yield*/, this.avaliar(declaracao.caminho)];
662
- case 1:
663
- caminhoRelativo = _a.sent();
664
- caminhoTotal = caminho.join(this.diretorioBase, caminhoRelativo);
665
- dados = (0, importar_biblioteca_1.default)(caminhoRelativo);
666
- if (dados)
667
- return [2 /*return*/, dados];
668
362
  try {
669
- if (!fs.existsSync(caminhoTotal)) {
670
- throw new excecoes_1.ErroEmTempoDeExecucao(declaracao.simboloFechamento, 'Não foi possível encontrar arquivo importado.', declaracao.linha);
363
+ for (let k = 0; k < caminho.declaracoes.length; k++) {
364
+ await this.executar(caminho.declaracoes[k]);
671
365
  }
672
366
  }
673
367
  catch (erro) {
674
- throw new excecoes_1.ErroEmTempoDeExecucao(declaracao.simboloFechamento, 'Não foi possível ler o arquivo.', declaracao.linha);
675
- }
676
- dados = fs.readFileSync(caminhoTotal).toString();
677
- delegua = new delegua_1.Delegua(this.Delegua.dialeto, false);
678
- delegua.executar(dados);
679
- exportar = this.pilhaEscoposExecucao.obterTodasDeleguaFuncao();
680
- eDicionario = function (objeto) { return objeto.constructor === Object; };
681
- if (eDicionario(exportar)) {
682
- novoModulo = new modulo_1.DeleguaModulo();
683
- chaves = Object.keys(exportar);
684
- for (i = 0; i < chaves.length; i++) {
685
- novoModulo[chaves[i]] = exportar[chaves[i]];
686
- }
687
- return [2 /*return*/, novoModulo];
368
+ throw erro;
688
369
  }
689
- return [2 /*return*/, exportar];
370
+ }
690
371
  }
691
- });
692
- });
693
- };
694
- InterpretadorEguaClassico.prototype.visitarExpressaoEscreva = function (declaracao) {
695
- return __awaiter(this, void 0, void 0, function () {
696
- var valor, erro_8;
697
- return __generator(this, function (_a) {
698
- switch (_a.label) {
699
- case 0:
700
- _a.trys.push([0, 2, , 3]);
701
- return [4 /*yield*/, this.avaliar(declaracao.argumentos[0])];
702
- case 1:
703
- valor = _a.sent();
704
- console.log(this.paraTexto(valor));
705
- return [2 /*return*/, null];
706
- case 2:
707
- erro_8 = _a.sent();
708
- this.erros.push(erro_8);
709
- return [3 /*break*/, 3];
710
- case 3: return [2 /*return*/];
372
+ }
373
+ if (caminhoPadrao !== null && encontrado === false) {
374
+ for (let i = 0; i < caminhoPadrao.declaracoes.length; i++) {
375
+ await this.executar(caminhoPadrao['declaracoes'][i]);
711
376
  }
712
- });
713
- });
714
- };
377
+ }
378
+ }
379
+ catch (erro) {
380
+ throw erro;
381
+ }
382
+ }
383
+ async visitarExpressaoTente(declaracao) {
384
+ try {
385
+ let sucesso = true;
386
+ try {
387
+ await this.executarBloco(declaracao.caminhoTente);
388
+ }
389
+ catch (erro) {
390
+ sucesso = false;
391
+ if (declaracao.caminhoPegue !== null) {
392
+ await this.executarBloco(declaracao.caminhoPegue);
393
+ }
394
+ else {
395
+ this.erros.push(erro);
396
+ }
397
+ }
398
+ if (sucesso && declaracao.caminhoSenao !== null) {
399
+ await this.executarBloco(declaracao.caminhoSenao);
400
+ }
401
+ }
402
+ finally {
403
+ if (declaracao.caminhoFinalmente !== null)
404
+ await this.executarBloco(declaracao.caminhoFinalmente);
405
+ }
406
+ }
407
+ async visitarExpressaoEnquanto(declaracao) {
408
+ while (this.eVerdadeiro(await this.avaliar(declaracao.condicao))) {
409
+ try {
410
+ await this.executar(declaracao.corpo);
411
+ }
412
+ catch (erro) {
413
+ throw erro;
414
+ }
415
+ }
416
+ return null;
417
+ }
418
+ async visitarExpressaoImportar(declaracao) {
419
+ const caminhoRelativo = await this.avaliar(declaracao.caminho);
420
+ const caminhoTotal = caminho.join(this.diretorioBase, caminhoRelativo);
421
+ // const nomeArquivo = caminho.basename(caminhoTotal);
422
+ let dados = (0, importar_biblioteca_1.default)(caminhoRelativo);
423
+ if (dados)
424
+ return dados;
425
+ try {
426
+ if (!fs.existsSync(caminhoTotal)) {
427
+ throw new excecoes_1.ErroEmTempoDeExecucao(declaracao.simboloFechamento, 'Não foi possível encontrar arquivo importado.', declaracao.linha);
428
+ }
429
+ }
430
+ catch (erro) {
431
+ throw new excecoes_1.ErroEmTempoDeExecucao(declaracao.simboloFechamento, 'Não foi possível ler o arquivo.', declaracao.linha);
432
+ }
433
+ dados = fs.readFileSync(caminhoTotal).toString();
434
+ const delegua = new delegua_1.Delegua(this.Delegua.dialeto, false);
435
+ delegua.executar(dados);
436
+ const exportar = this.pilhaEscoposExecucao.obterTodasDeleguaFuncao();
437
+ const eDicionario = (objeto) => objeto.constructor === Object;
438
+ if (eDicionario(exportar)) {
439
+ const novoModulo = new modulo_1.DeleguaModulo();
440
+ const chaves = Object.keys(exportar);
441
+ for (let i = 0; i < chaves.length; i++) {
442
+ novoModulo[chaves[i]] = exportar[chaves[i]];
443
+ }
444
+ return novoModulo;
445
+ }
446
+ return exportar;
447
+ }
448
+ async visitarExpressaoEscreva(declaracao) {
449
+ try {
450
+ const valor = await this.avaliar(declaracao.argumentos[0]);
451
+ console.log(this.paraTexto(valor));
452
+ return null;
453
+ }
454
+ catch (erro) {
455
+ this.erros.push(erro);
456
+ }
457
+ }
715
458
  /**
716
459
  * Empilha declarações na pilha de escopos de execução, cria um novo ambiente e
717
460
  * executa as declarações empilhadas.
@@ -722,355 +465,221 @@ var InterpretadorEguaClassico = /** @class */ (function () {
722
465
  * @param declaracoes Um vetor de declaracoes a ser executado.
723
466
  * @param ambiente O ambiente de execução quando houver, como parâmetros, argumentos, etc.
724
467
  */
725
- InterpretadorEguaClassico.prototype.executarBloco = function (declaracoes, ambiente) {
726
- return __awaiter(this, void 0, void 0, function () {
727
- var escopoExecucao, retornoUltimoEscopo;
728
- return __generator(this, function (_a) {
729
- switch (_a.label) {
730
- case 0:
731
- escopoExecucao = {
732
- declaracoes: declaracoes,
733
- declaracaoAtual: 0,
734
- ambiente: ambiente || new espaco_variaveis_1.EspacoVariaveis(),
735
- };
736
- this.pilhaEscoposExecucao.empilhar(escopoExecucao);
737
- return [4 /*yield*/, this.executarUltimoEscopo()];
738
- case 1:
739
- retornoUltimoEscopo = _a.sent();
740
- if (retornoUltimoEscopo instanceof excecoes_1.ErroEmTempoDeExecucao) {
741
- throw retornoUltimoEscopo;
742
- }
743
- return [2 /*return*/, retornoUltimoEscopo];
744
- }
745
- });
746
- });
747
- };
748
- InterpretadorEguaClassico.prototype.visitarExpressaoBloco = function (declaracao) {
749
- return __awaiter(this, void 0, void 0, function () {
750
- return __generator(this, function (_a) {
751
- switch (_a.label) {
752
- case 0: return [4 /*yield*/, this.executarBloco(declaracao.declaracoes)];
753
- case 1: return [2 /*return*/, _a.sent()];
754
- }
755
- });
756
- });
757
- };
468
+ async executarBloco(declaracoes, ambiente) {
469
+ const escopoExecucao = {
470
+ declaracoes: declaracoes,
471
+ declaracaoAtual: 0,
472
+ ambiente: ambiente || new espaco_variaveis_1.EspacoVariaveis(),
473
+ };
474
+ this.pilhaEscoposExecucao.empilhar(escopoExecucao);
475
+ const retornoUltimoEscopo = await this.executarUltimoEscopo();
476
+ if (retornoUltimoEscopo instanceof excecoes_1.ErroEmTempoDeExecucao) {
477
+ throw retornoUltimoEscopo;
478
+ }
479
+ return retornoUltimoEscopo;
480
+ }
481
+ async visitarExpressaoBloco(declaracao) {
482
+ return await this.executarBloco(declaracao.declaracoes);
483
+ }
758
484
  /**
759
485
  * Executa expressão de definição de variável.
760
486
  * @param declaracao A declaração Var
761
487
  * @returns Sempre retorna nulo.
762
488
  */
763
- InterpretadorEguaClassico.prototype.visitarExpressaoVar = function (declaracao) {
764
- return __awaiter(this, void 0, void 0, function () {
765
- var valorOuOutraVariavel;
766
- return __generator(this, function (_a) {
767
- switch (_a.label) {
768
- case 0:
769
- valorOuOutraVariavel = null;
770
- if (!(declaracao.inicializador !== null)) return [3 /*break*/, 2];
771
- return [4 /*yield*/, this.avaliar(declaracao.inicializador)];
772
- case 1:
773
- valorOuOutraVariavel = _a.sent();
774
- _a.label = 2;
775
- case 2:
776
- this.pilhaEscoposExecucao.definirVariavel(declaracao.simbolo.lexema, valorOuOutraVariavel.hasOwnProperty('valor')
777
- ? valorOuOutraVariavel.valor
778
- : valorOuOutraVariavel);
779
- return [2 /*return*/, null];
780
- }
781
- });
782
- });
783
- };
784
- InterpretadorEguaClassico.prototype.visitarExpressaoContinua = function (declaracao) {
489
+ async visitarExpressaoVar(declaracao) {
490
+ let valorOuOutraVariavel = null;
491
+ if (declaracao.inicializador !== null) {
492
+ valorOuOutraVariavel = await this.avaliar(declaracao.inicializador);
493
+ }
494
+ this.pilhaEscoposExecucao.definirVariavel(declaracao.simbolo.lexema, valorOuOutraVariavel.hasOwnProperty('valor')
495
+ ? valorOuOutraVariavel.valor
496
+ : valorOuOutraVariavel);
497
+ return null;
498
+ }
499
+ visitarExpressaoContinua(declaracao) {
785
500
  return new quebras_1.ContinuarQuebra();
786
- };
787
- InterpretadorEguaClassico.prototype.visitarExpressaoSustar = function (declaracao) {
501
+ }
502
+ visitarExpressaoSustar(declaracao) {
788
503
  return new quebras_1.SustarQuebra();
789
- };
790
- InterpretadorEguaClassico.prototype.visitarExpressaoRetornar = function (declaracao) {
791
- return __awaiter(this, void 0, void 0, function () {
792
- var valor;
793
- return __generator(this, function (_a) {
794
- switch (_a.label) {
795
- case 0:
796
- valor = null;
797
- if (!(declaracao.valor != null)) return [3 /*break*/, 2];
798
- return [4 /*yield*/, this.avaliar(declaracao.valor)];
799
- case 1:
800
- valor = _a.sent();
801
- _a.label = 2;
802
- case 2: return [2 /*return*/, new quebras_1.RetornoQuebra(valor)];
803
- }
804
- });
805
- });
806
- };
807
- InterpretadorEguaClassico.prototype.visitarExpressaoDeleguaFuncao = function (expressao) {
504
+ }
505
+ async visitarExpressaoRetornar(declaracao) {
506
+ let valor = null;
507
+ if (declaracao.valor != null)
508
+ valor = await this.avaliar(declaracao.valor);
509
+ return new quebras_1.RetornoQuebra(valor);
510
+ }
511
+ visitarExpressaoDeleguaFuncao(expressao) {
808
512
  return new delegua_funcao_1.DeleguaFuncao(null, expressao);
809
- };
810
- InterpretadorEguaClassico.prototype.visitarExpressaoAtribuicaoSobrescrita = function (expressao) {
811
- return __awaiter(this, void 0, void 0, function () {
812
- var objeto, indice, valor;
813
- return __generator(this, function (_a) {
814
- switch (_a.label) {
815
- case 0: return [4 /*yield*/, this.avaliar(expressao.objeto)];
816
- case 1:
817
- objeto = _a.sent();
818
- return [4 /*yield*/, this.avaliar(expressao.indice)];
819
- case 2:
820
- indice = _a.sent();
821
- return [4 /*yield*/, this.avaliar(expressao.valor)];
822
- case 3:
823
- valor = _a.sent();
824
- if (Array.isArray(objeto)) {
825
- if (indice < 0 && objeto.length !== 0) {
826
- while (indice < 0) {
827
- indice += objeto.length;
828
- }
829
- }
830
- while (objeto.length < indice) {
831
- objeto.push(null);
832
- }
833
- objeto[indice] = valor;
834
- }
835
- else if (objeto.constructor === Object ||
836
- objeto instanceof objeto_delegua_classe_1.ObjetoDeleguaClasse ||
837
- objeto instanceof delegua_funcao_1.DeleguaFuncao ||
838
- objeto instanceof delegua_classe_1.DeleguaClasse ||
839
- objeto instanceof modulo_1.DeleguaModulo) {
840
- objeto[indice] = valor;
841
- }
842
- else {
843
- throw new excecoes_1.ErroEmTempoDeExecucao(expressao.objeto.nome, 'Somente listas, dicionários, classes e objetos podem ser mudados por sobrescrita.', expressao.linha);
844
- }
845
- return [2 /*return*/];
513
+ }
514
+ async visitarExpressaoAtribuicaoSobrescrita(expressao) {
515
+ const objeto = await this.avaliar(expressao.objeto);
516
+ let indice = await this.avaliar(expressao.indice);
517
+ const valor = await this.avaliar(expressao.valor);
518
+ if (Array.isArray(objeto)) {
519
+ if (indice < 0 && objeto.length !== 0) {
520
+ while (indice < 0) {
521
+ indice += objeto.length;
846
522
  }
847
- });
848
- });
849
- };
850
- InterpretadorEguaClassico.prototype.visitarExpressaoAcessoIndiceVariavel = function (expressao) {
851
- return __awaiter(this, void 0, void 0, function () {
852
- var variavelObjeto, objeto, indice, valorIndice;
853
- return __generator(this, function (_a) {
854
- switch (_a.label) {
855
- case 0: return [4 /*yield*/, this.avaliar(expressao.entidadeChamada)];
856
- case 1:
857
- variavelObjeto = _a.sent();
858
- objeto = variavelObjeto.hasOwnProperty('valor')
859
- ? variavelObjeto.valor
860
- : variavelObjeto;
861
- return [4 /*yield*/, this.avaliar(expressao.indice)];
862
- case 2:
863
- indice = _a.sent();
864
- valorIndice = indice.hasOwnProperty('valor') ? indice.valor : indice;
865
- if (Array.isArray(objeto)) {
866
- if (!Number.isInteger(valorIndice)) {
867
- throw new excecoes_1.ErroEmTempoDeExecucao(expressao.simboloFechamento, 'Somente inteiros podem ser usados para indexar um vetor.', expressao.linha);
868
- }
869
- if (indice < 0 && objeto.length !== 0) {
870
- while (indice < 0) {
871
- indice += objeto.length;
872
- }
873
- }
874
- if (indice >= objeto.length) {
875
- throw new excecoes_1.ErroEmTempoDeExecucao(expressao.simboloFechamento, 'Índice do vetor fora do intervalo.', expressao.linha);
876
- }
877
- return [2 /*return*/, objeto[indice]];
878
- }
879
- else if (objeto.constructor === Object ||
880
- objeto instanceof objeto_delegua_classe_1.ObjetoDeleguaClasse ||
881
- objeto instanceof delegua_funcao_1.DeleguaFuncao ||
882
- objeto instanceof delegua_classe_1.DeleguaClasse ||
883
- objeto instanceof modulo_1.DeleguaModulo) {
884
- return [2 /*return*/, objeto[indice] || null];
885
- }
886
- else if (typeof objeto === 'string') {
887
- if (!Number.isInteger(indice)) {
888
- throw new excecoes_1.ErroEmTempoDeExecucao(expressao.simboloFechamento, 'Somente inteiros podem ser usados para indexar um vetor.', expressao.linha);
889
- }
890
- if (indice < 0 && objeto.length !== 0) {
891
- while (indice < 0) {
892
- indice += objeto.length;
893
- }
894
- }
895
- if (indice >= objeto.length) {
896
- throw new excecoes_1.ErroEmTempoDeExecucao(expressao.simboloFechamento, 'Índice fora do tamanho.', expressao.linha);
897
- }
898
- return [2 /*return*/, objeto.charAt(indice)];
899
- }
900
- else {
901
- throw new excecoes_1.ErroEmTempoDeExecucao(expressao.entidadeChamada.nome, 'Somente listas, dicionários, classes e objetos podem ser mudados por sobrescrita.', expressao.linha);
902
- }
903
- return [2 /*return*/];
523
+ }
524
+ while (objeto.length < indice) {
525
+ objeto.push(null);
526
+ }
527
+ objeto[indice] = valor;
528
+ }
529
+ else if (objeto.constructor === Object ||
530
+ objeto instanceof objeto_delegua_classe_1.ObjetoDeleguaClasse ||
531
+ objeto instanceof delegua_funcao_1.DeleguaFuncao ||
532
+ objeto instanceof delegua_classe_1.DeleguaClasse ||
533
+ objeto instanceof modulo_1.DeleguaModulo) {
534
+ objeto[indice] = valor;
535
+ }
536
+ else {
537
+ throw new excecoes_1.ErroEmTempoDeExecucao(expressao.objeto.nome, 'Somente listas, dicionários, classes e objetos podem ser mudados por sobrescrita.', expressao.linha);
538
+ }
539
+ }
540
+ async visitarExpressaoAcessoIndiceVariavel(expressao) {
541
+ const variavelObjeto = await this.avaliar(expressao.entidadeChamada);
542
+ const objeto = variavelObjeto.hasOwnProperty('valor')
543
+ ? variavelObjeto.valor
544
+ : variavelObjeto;
545
+ let indice = await this.avaliar(expressao.indice);
546
+ const valorIndice = indice.hasOwnProperty('valor') ? indice.valor : indice;
547
+ if (Array.isArray(objeto)) {
548
+ if (!Number.isInteger(valorIndice)) {
549
+ throw new excecoes_1.ErroEmTempoDeExecucao(expressao.simboloFechamento, 'Somente inteiros podem ser usados para indexar um vetor.', expressao.linha);
550
+ }
551
+ if (indice < 0 && objeto.length !== 0) {
552
+ while (indice < 0) {
553
+ indice += objeto.length;
904
554
  }
905
- });
906
- });
907
- };
908
- InterpretadorEguaClassico.prototype.visitarExpressaoDefinirValor = function (expressao) {
909
- return __awaiter(this, void 0, void 0, function () {
910
- var objeto, valor;
911
- return __generator(this, function (_a) {
912
- switch (_a.label) {
913
- case 0: return [4 /*yield*/, this.avaliar(expressao.objeto)];
914
- case 1:
915
- objeto = _a.sent();
916
- if (!(objeto instanceof objeto_delegua_classe_1.ObjetoDeleguaClasse) &&
917
- objeto.constructor !== Object) {
918
- throw new excecoes_1.ErroEmTempoDeExecucao(expressao.objeto.nome, 'Somente instâncias e dicionários podem possuir campos.', expressao.linha);
919
- }
920
- return [4 /*yield*/, this.avaliar(expressao.valor)];
921
- case 2:
922
- valor = _a.sent();
923
- if (objeto instanceof objeto_delegua_classe_1.ObjetoDeleguaClasse) {
924
- objeto.set(expressao.nome, valor);
925
- return [2 /*return*/, valor];
926
- }
927
- else if (objeto.constructor === Object) {
928
- objeto[expressao.simbolo.lexema] = valor;
929
- }
930
- return [2 /*return*/];
555
+ }
556
+ if (indice >= objeto.length) {
557
+ throw new excecoes_1.ErroEmTempoDeExecucao(expressao.simboloFechamento, 'Índice do vetor fora do intervalo.', expressao.linha);
558
+ }
559
+ return objeto[indice];
560
+ }
561
+ else if (objeto.constructor === Object ||
562
+ objeto instanceof objeto_delegua_classe_1.ObjetoDeleguaClasse ||
563
+ objeto instanceof delegua_funcao_1.DeleguaFuncao ||
564
+ objeto instanceof delegua_classe_1.DeleguaClasse ||
565
+ objeto instanceof modulo_1.DeleguaModulo) {
566
+ return objeto[indice] || null;
567
+ }
568
+ else if (typeof objeto === 'string') {
569
+ if (!Number.isInteger(indice)) {
570
+ throw new excecoes_1.ErroEmTempoDeExecucao(expressao.simboloFechamento, 'Somente inteiros podem ser usados para indexar um vetor.', expressao.linha);
571
+ }
572
+ if (indice < 0 && objeto.length !== 0) {
573
+ while (indice < 0) {
574
+ indice += objeto.length;
931
575
  }
932
- });
933
- });
934
- };
935
- InterpretadorEguaClassico.prototype.visitarExpressaoFuncao = function (declaracao) {
936
- var funcao = new delegua_funcao_1.DeleguaFuncao(declaracao.simbolo.lexema, declaracao.funcao);
576
+ }
577
+ if (indice >= objeto.length) {
578
+ throw new excecoes_1.ErroEmTempoDeExecucao(expressao.simboloFechamento, 'Índice fora do tamanho.', expressao.linha);
579
+ }
580
+ return objeto.charAt(indice);
581
+ }
582
+ else {
583
+ throw new excecoes_1.ErroEmTempoDeExecucao(expressao.entidadeChamada.nome, 'Somente listas, dicionários, classes e objetos podem ser mudados por sobrescrita.', expressao.linha);
584
+ }
585
+ }
586
+ async visitarExpressaoDefinirValor(expressao) {
587
+ const objeto = await this.avaliar(expressao.objeto);
588
+ if (!(objeto instanceof objeto_delegua_classe_1.ObjetoDeleguaClasse) &&
589
+ objeto.constructor !== Object) {
590
+ throw new excecoes_1.ErroEmTempoDeExecucao(expressao.objeto.nome, 'Somente instâncias e dicionários podem possuir campos.', expressao.linha);
591
+ }
592
+ const valor = await this.avaliar(expressao.valor);
593
+ if (objeto instanceof objeto_delegua_classe_1.ObjetoDeleguaClasse) {
594
+ objeto.definir(expressao.nome, valor);
595
+ return valor;
596
+ }
597
+ else if (objeto.constructor === Object) {
598
+ objeto[expressao.simbolo.lexema] = valor;
599
+ }
600
+ }
601
+ visitarExpressaoFuncao(declaracao) {
602
+ const funcao = new delegua_funcao_1.DeleguaFuncao(declaracao.simbolo.lexema, declaracao.funcao);
937
603
  this.pilhaEscoposExecucao.definirVariavel(declaracao.simbolo.lexema, funcao);
938
- };
939
- InterpretadorEguaClassico.prototype.visitarExpressaoClasse = function (declaracao) {
940
- return __awaiter(this, void 0, void 0, function () {
941
- var superClasse, variavelSuperClasse, metodos, definirMetodos, i, metodoAtual, eInicializador, funcao, deleguaClasse;
942
- return __generator(this, function (_a) {
943
- switch (_a.label) {
944
- case 0:
945
- superClasse = null;
946
- if (!(declaracao.superClasse !== null)) return [3 /*break*/, 2];
947
- return [4 /*yield*/, this.avaliar(declaracao.superClasse)];
948
- case 1:
949
- variavelSuperClasse = _a.sent();
950
- superClasse = variavelSuperClasse.valor;
951
- if (!(superClasse instanceof delegua_classe_1.DeleguaClasse)) {
952
- throw new excecoes_1.ErroEmTempoDeExecucao(declaracao.superClasse.nome, 'SuperClasse precisa ser uma classe.', declaracao.linha);
953
- }
954
- _a.label = 2;
955
- case 2:
956
- this.pilhaEscoposExecucao.definirVariavel(declaracao.simbolo.lexema, null);
957
- if (declaracao.superClasse !== null) {
958
- this.pilhaEscoposExecucao.definirVariavel('super', superClasse);
959
- }
960
- metodos = {};
961
- definirMetodos = declaracao.metodos;
962
- for (i = 0; i < declaracao.metodos.length; i++) {
963
- metodoAtual = definirMetodos[i];
964
- eInicializador = metodoAtual.simbolo.lexema === 'construtor';
965
- funcao = new delegua_funcao_1.DeleguaFuncao(metodoAtual.simbolo.lexema, metodoAtual.funcao, undefined, eInicializador);
966
- metodos[metodoAtual.simbolo.lexema] = funcao;
967
- }
968
- deleguaClasse = new delegua_classe_1.DeleguaClasse(declaracao.simbolo.lexema, superClasse, metodos);
969
- // TODO: Recolocar isso se for necessário.
970
- /* if (superClasse !== null) {
971
- this.ambiente = this.ambiente.enclosing;
972
- } */
973
- this.pilhaEscoposExecucao.atribuirVariavel(declaracao.simbolo, deleguaClasse);
974
- return [2 /*return*/, null];
975
- }
976
- });
977
- });
978
- };
979
- InterpretadorEguaClassico.prototype.visitarExpressaoAcessoMetodo = function (expressao) {
980
- return __awaiter(this, void 0, void 0, function () {
981
- var variavelObjeto, objeto;
982
- return __generator(this, function (_a) {
983
- switch (_a.label) {
984
- case 0: return [4 /*yield*/, this.avaliar(expressao.objeto)];
985
- case 1:
986
- variavelObjeto = _a.sent();
987
- objeto = variavelObjeto === null || variavelObjeto === void 0 ? void 0 : variavelObjeto.valor;
988
- if (objeto instanceof objeto_delegua_classe_1.ObjetoDeleguaClasse) {
989
- return [2 /*return*/, objeto.get(expressao.simbolo) || null];
990
- }
991
- else if (objeto.constructor === Object) {
992
- return [2 /*return*/, objeto[expressao.simbolo.lexema] || null];
993
- }
994
- else if (objeto instanceof modulo_1.DeleguaModulo) {
995
- return [2 /*return*/, objeto[expressao.simbolo.lexema] || null];
996
- }
997
- throw new excecoes_1.ErroEmTempoDeExecucao(expressao.nome, 'Você só pode acessar métodos do objeto e dicionários.', expressao.linha);
998
- }
999
- });
1000
- });
1001
- };
1002
- InterpretadorEguaClassico.prototype.visitarExpressaoIsto = function (expressao) {
604
+ }
605
+ async visitarExpressaoClasse(declaracao) {
606
+ let superClasse = null;
607
+ if (declaracao.superClasse !== null) {
608
+ const variavelSuperClasse = await this.avaliar(declaracao.superClasse);
609
+ superClasse = variavelSuperClasse.valor;
610
+ if (!(superClasse instanceof delegua_classe_1.DeleguaClasse)) {
611
+ throw new excecoes_1.ErroEmTempoDeExecucao(declaracao.superClasse.nome, 'SuperClasse precisa ser uma classe.', declaracao.linha);
612
+ }
613
+ }
614
+ this.pilhaEscoposExecucao.definirVariavel(declaracao.simbolo.lexema, null);
615
+ if (declaracao.superClasse !== null) {
616
+ this.pilhaEscoposExecucao.definirVariavel('super', superClasse);
617
+ }
618
+ const metodos = {};
619
+ const definirMetodos = declaracao.metodos;
620
+ for (let i = 0; i < declaracao.metodos.length; i++) {
621
+ const metodoAtual = definirMetodos[i];
622
+ const eInicializador = metodoAtual.simbolo.lexema === 'construtor';
623
+ const funcao = new delegua_funcao_1.DeleguaFuncao(metodoAtual.simbolo.lexema, metodoAtual.funcao, undefined, eInicializador);
624
+ metodos[metodoAtual.simbolo.lexema] = funcao;
625
+ }
626
+ const deleguaClasse = new delegua_classe_1.DeleguaClasse(declaracao.simbolo.lexema, superClasse, metodos);
627
+ // TODO: Recolocar isso se for necessário.
628
+ /* if (superClasse !== null) {
629
+ this.ambiente = this.ambiente.enclosing;
630
+ } */
631
+ this.pilhaEscoposExecucao.atribuirVariavel(declaracao.simbolo, deleguaClasse);
632
+ return null;
633
+ }
634
+ async visitarExpressaoAcessoMetodo(expressao) {
635
+ const variavelObjeto = await this.avaliar(expressao.objeto);
636
+ const objeto = variavelObjeto === null || variavelObjeto === void 0 ? void 0 : variavelObjeto.valor;
637
+ if (objeto instanceof objeto_delegua_classe_1.ObjetoDeleguaClasse) {
638
+ return objeto.obter(expressao.simbolo) || null;
639
+ }
640
+ else if (objeto.constructor === Object) {
641
+ return objeto[expressao.simbolo.lexema] || null;
642
+ }
643
+ else if (objeto instanceof modulo_1.DeleguaModulo) {
644
+ return objeto[expressao.simbolo.lexema] || null;
645
+ }
646
+ throw new excecoes_1.ErroEmTempoDeExecucao(expressao.nome, 'Você pode acessar métodos do objeto e dicionários.', expressao.linha);
647
+ }
648
+ visitarExpressaoIsto(expressao) {
1003
649
  return this.procurarVariavel(expressao.palavraChave, expressao);
1004
- };
1005
- InterpretadorEguaClassico.prototype.visitarExpressaoDicionario = function (expressao) {
1006
- return __awaiter(this, void 0, void 0, function () {
1007
- var dicionario, i, _a, _b;
1008
- return __generator(this, function (_c) {
1009
- switch (_c.label) {
1010
- case 0:
1011
- dicionario = {};
1012
- i = 0;
1013
- _c.label = 1;
1014
- case 1:
1015
- if (!(i < expressao.chaves.length)) return [3 /*break*/, 5];
1016
- _a = dicionario;
1017
- return [4 /*yield*/, this.avaliar(expressao.chaves[i])];
1018
- case 2:
1019
- _b = _c.sent();
1020
- return [4 /*yield*/, this.avaliar(expressao.valores[i])];
1021
- case 3:
1022
- _a[_b] = _c.sent();
1023
- _c.label = 4;
1024
- case 4:
1025
- i++;
1026
- return [3 /*break*/, 1];
1027
- case 5: return [2 /*return*/, dicionario];
1028
- }
1029
- });
1030
- });
1031
- };
1032
- InterpretadorEguaClassico.prototype.visitarExpressaoVetor = function (expressao) {
1033
- return __awaiter(this, void 0, void 0, function () {
1034
- var valores, i, _a, _b;
1035
- return __generator(this, function (_c) {
1036
- switch (_c.label) {
1037
- case 0:
1038
- valores = [];
1039
- i = 0;
1040
- _c.label = 1;
1041
- case 1:
1042
- if (!(i < expressao.valores.length)) return [3 /*break*/, 4];
1043
- _b = (_a = valores).push;
1044
- return [4 /*yield*/, this.avaliar(expressao.valores[i])];
1045
- case 2:
1046
- _b.apply(_a, [_c.sent()]);
1047
- _c.label = 3;
1048
- case 3:
1049
- i++;
1050
- return [3 /*break*/, 1];
1051
- case 4: return [2 /*return*/, valores];
1052
- }
1053
- });
1054
- });
1055
- };
1056
- InterpretadorEguaClassico.prototype.visitarExpressaoSuper = function (expressao) {
1057
- var distancia = this.locais.get(expressao);
1058
- var superClasse = this.pilhaEscoposExecucao.obterVariavelEm(distancia, 'super');
1059
- var objeto = this.pilhaEscoposExecucao.obterVariavelEm(distancia - 1, 'isto');
1060
- var metodo = superClasse.valor.encontrarMetodo(expressao.metodo.lexema);
650
+ }
651
+ async visitarExpressaoDicionario(expressao) {
652
+ const dicionario = {};
653
+ for (let i = 0; i < expressao.chaves.length; i++) {
654
+ dicionario[await this.avaliar(expressao.chaves[i])] = await this.avaliar(expressao.valores[i]);
655
+ }
656
+ return dicionario;
657
+ }
658
+ async visitarExpressaoVetor(expressao) {
659
+ const valores = [];
660
+ for (let i = 0; i < expressao.valores.length; i++) {
661
+ valores.push(await this.avaliar(expressao.valores[i]));
662
+ }
663
+ return valores;
664
+ }
665
+ visitarExpressaoSuper(expressao) {
666
+ const distancia = this.locais.get(expressao);
667
+ const superClasse = this.pilhaEscoposExecucao.obterVariavelEm(distancia, 'super');
668
+ const objeto = this.pilhaEscoposExecucao.obterVariavelEm(distancia - 1, 'isto');
669
+ const metodo = superClasse.valor.encontrarMetodo(expressao.metodo.lexema);
1061
670
  if (metodo === undefined) {
1062
671
  throw new excecoes_1.ErroEmTempoDeExecucao(expressao.metodo, 'Método chamado indefinido.', expressao.linha);
1063
672
  }
1064
673
  return metodo.definirInstancia(objeto.valor);
1065
- };
1066
- InterpretadorEguaClassico.prototype.paraTexto = function (objeto) {
674
+ }
675
+ paraTexto(objeto) {
1067
676
  if (objeto === null)
1068
677
  return 'nulo';
1069
678
  if (typeof objeto === 'boolean') {
1070
679
  return objeto ? 'verdadeiro' : 'falso';
1071
680
  }
1072
681
  if (objeto instanceof Date) {
1073
- var formato = Intl.DateTimeFormat('pt', {
682
+ const formato = Intl.DateTimeFormat('pt', {
1074
683
  dateStyle: 'full',
1075
684
  timeStyle: 'full',
1076
685
  });
@@ -1084,18 +693,10 @@ var InterpretadorEguaClassico = /** @class */ (function () {
1084
693
  return 'nulo';
1085
694
  }
1086
695
  return objeto.toString();
1087
- };
1088
- InterpretadorEguaClassico.prototype.executar = function (declaracao, mostrarResultado) {
1089
- if (mostrarResultado === void 0) { mostrarResultado = false; }
1090
- return __awaiter(this, void 0, void 0, function () {
1091
- return __generator(this, function (_a) {
1092
- switch (_a.label) {
1093
- case 0: return [4 /*yield*/, declaracao.aceitar(this)];
1094
- case 1: return [2 /*return*/, _a.sent()];
1095
- }
1096
- });
1097
- });
1098
- };
696
+ }
697
+ async executar(declaracao, mostrarResultado = false) {
698
+ return await declaracao.aceitar(this);
699
+ }
1099
700
  /**
1100
701
  * Executa o último escopo empilhado no topo na pilha de escopos do Interpretador.
1101
702
  * Originalmente, Égua não trabalha com uma pilha de escopos.
@@ -1109,69 +710,41 @@ var InterpretadorEguaClassico = /** @class */ (function () {
1109
710
  * Interpretador Égua: https://github.com/eguatech/egua/blob/master/src/interpreter.js
1110
711
  * @returns O resultado da execução do escopo, se houver.
1111
712
  */
1112
- InterpretadorEguaClassico.prototype.executarUltimoEscopo = function () {
1113
- return __awaiter(this, void 0, void 0, function () {
1114
- var ultimoEscopo, retornoExecucao, erro_9;
1115
- return __generator(this, function (_a) {
1116
- switch (_a.label) {
1117
- case 0:
1118
- ultimoEscopo = this.pilhaEscoposExecucao.topoDaPilha();
1119
- _a.label = 1;
1120
- case 1:
1121
- _a.trys.push([1, 6, 7, 8]);
1122
- retornoExecucao = void 0;
1123
- _a.label = 2;
1124
- case 2:
1125
- if (!(!(retornoExecucao instanceof quebras_1.Quebra) &&
1126
- ultimoEscopo.declaracaoAtual < ultimoEscopo.declaracoes.length)) return [3 /*break*/, 5];
1127
- return [4 /*yield*/, this.executar(ultimoEscopo.declaracoes[ultimoEscopo.declaracaoAtual])];
1128
- case 3:
1129
- retornoExecucao = _a.sent();
1130
- _a.label = 4;
1131
- case 4:
1132
- ultimoEscopo.declaracaoAtual++;
1133
- return [3 /*break*/, 2];
1134
- case 5: return [2 /*return*/, retornoExecucao];
1135
- case 6:
1136
- erro_9 = _a.sent();
1137
- return [2 /*return*/, erro_9];
1138
- case 7:
1139
- this.pilhaEscoposExecucao.removerUltimo();
1140
- return [7 /*endfinally*/];
1141
- case 8: return [2 /*return*/];
1142
- }
1143
- });
1144
- });
1145
- };
1146
- InterpretadorEguaClassico.prototype.interpretar = function (declaracoes) {
1147
- return __awaiter(this, void 0, void 0, function () {
1148
- var retornoResolvedor, escopoExecucao;
1149
- return __generator(this, function (_a) {
1150
- switch (_a.label) {
1151
- case 0:
1152
- this.erros = [];
1153
- retornoResolvedor = this.resolvedor.resolver(declaracoes);
1154
- this.locais = retornoResolvedor.locais;
1155
- escopoExecucao = {
1156
- declaracoes: declaracoes,
1157
- declaracaoAtual: 0,
1158
- ambiente: new espaco_variaveis_1.EspacoVariaveis(),
1159
- };
1160
- this.pilhaEscoposExecucao.empilhar(escopoExecucao);
1161
- return [4 /*yield*/, this.executarUltimoEscopo()];
1162
- case 1:
1163
- _a.sent();
1164
- return [2 /*return*/, {
1165
- erros: this.erros,
1166
- }];
1167
- }
1168
- });
1169
- });
1170
- };
1171
- InterpretadorEguaClassico.prototype.finalizacao = function () {
713
+ async executarUltimoEscopo() {
714
+ const ultimoEscopo = this.pilhaEscoposExecucao.topoDaPilha();
715
+ try {
716
+ let retornoExecucao;
717
+ for (; !(retornoExecucao instanceof quebras_1.Quebra) &&
718
+ ultimoEscopo.declaracaoAtual < ultimoEscopo.declaracoes.length; ultimoEscopo.declaracaoAtual++) {
719
+ retornoExecucao = await this.executar(ultimoEscopo.declaracoes[ultimoEscopo.declaracaoAtual]);
720
+ }
721
+ return retornoExecucao;
722
+ }
723
+ catch (erro) {
724
+ return erro;
725
+ }
726
+ finally {
727
+ this.pilhaEscoposExecucao.removerUltimo();
728
+ }
729
+ }
730
+ async interpretar(declaracoes) {
731
+ this.erros = [];
732
+ const retornoResolvedor = this.resolvedor.resolver(declaracoes);
733
+ this.locais = retornoResolvedor.locais;
734
+ const escopoExecucao = {
735
+ declaracoes: declaracoes,
736
+ declaracaoAtual: 0,
737
+ ambiente: new espaco_variaveis_1.EspacoVariaveis(),
738
+ };
739
+ this.pilhaEscoposExecucao.empilhar(escopoExecucao);
740
+ await this.executarUltimoEscopo();
741
+ return {
742
+ erros: this.erros,
743
+ };
744
+ }
745
+ finalizacao() {
1172
746
  this.funcaoDeRetorno();
1173
- };
1174
- return InterpretadorEguaClassico;
1175
- }());
747
+ }
748
+ }
1176
749
  exports.InterpretadorEguaClassico = InterpretadorEguaClassico;
1177
750
  //# sourceMappingURL=egua-classico.js.map