@designliquido/delegua 0.8.0 → 0.9.0-0

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 (287) hide show
  1. package/bin/package.json +10 -2
  2. package/fontes/avaliador-sintatico/avaliador-sintatico-base.d.ts +2 -1
  3. package/fontes/avaliador-sintatico/avaliador-sintatico-base.js +3 -0
  4. package/fontes/avaliador-sintatico/avaliador-sintatico-base.js.map +1 -1
  5. package/fontes/avaliador-sintatico/avaliador-sintatico.d.ts +7 -5
  6. package/fontes/avaliador-sintatico/avaliador-sintatico.js +16 -1
  7. package/fontes/avaliador-sintatico/avaliador-sintatico.js.map +1 -1
  8. package/fontes/avaliador-sintatico/dialetos/avaliador-sintatico-egua-classico.d.ts +5 -4
  9. package/fontes/avaliador-sintatico/dialetos/avaliador-sintatico-egua-classico.js +3 -0
  10. package/fontes/avaliador-sintatico/dialetos/avaliador-sintatico-egua-classico.js.map +1 -1
  11. package/fontes/avaliador-sintatico/dialetos/avaliador-sintatico-eguap.d.ts +10 -9
  12. package/fontes/avaliador-sintatico/dialetos/avaliador-sintatico-eguap.js +12 -0
  13. package/fontes/avaliador-sintatico/dialetos/avaliador-sintatico-eguap.js.map +1 -1
  14. package/fontes/avaliador-sintatico/dialetos/avaliador-sintatico-visualg.d.ts +2 -2
  15. package/fontes/avaliador-sintatico/dialetos/avaliador-sintatico-visualg.js +17 -11
  16. package/fontes/avaliador-sintatico/dialetos/avaliador-sintatico-visualg.js.map +1 -1
  17. package/fontes/avaliador-sintatico/erro-avaliador-sintatico.d.ts +1 -1
  18. package/fontes/avaliador-sintatico/retornos/index.d.ts +3 -0
  19. package/fontes/avaliador-sintatico/retornos/index.js +20 -0
  20. package/fontes/avaliador-sintatico/retornos/index.js.map +1 -0
  21. package/fontes/avaliador-sintatico/retornos/retorno-declaracao.d.ts +3 -0
  22. package/fontes/avaliador-sintatico/retornos/retorno-declaracao.js +3 -0
  23. package/fontes/avaliador-sintatico/retornos/retorno-declaracao.js.map +1 -0
  24. package/fontes/avaliador-sintatico/retornos/retorno-primario.d.ts +3 -0
  25. package/fontes/avaliador-sintatico/retornos/retorno-primario.js +3 -0
  26. package/fontes/avaliador-sintatico/retornos/retorno-primario.js.map +1 -0
  27. package/fontes/avaliador-sintatico/retornos/retorno-resolver-declaracao.d.ts +2 -0
  28. package/fontes/avaliador-sintatico/retornos/retorno-resolver-declaracao.js +3 -0
  29. package/fontes/avaliador-sintatico/retornos/retorno-resolver-declaracao.js.map +1 -0
  30. package/fontes/bibliotecas/biblioteca-global.d.ts +2 -2
  31. package/fontes/bibliotecas/biblioteca-global.js +363 -134
  32. package/fontes/bibliotecas/biblioteca-global.js.map +1 -1
  33. package/fontes/bibliotecas/importar-biblioteca.d.ts +1 -1
  34. package/fontes/bibliotecas/importar-biblioteca.js +13 -14
  35. package/fontes/bibliotecas/importar-biblioteca.js.map +1 -1
  36. package/fontes/bibliotecas/primitivas-texto.js +13 -7
  37. package/fontes/bibliotecas/primitivas-texto.js.map +1 -1
  38. package/fontes/bibliotecas/primitivas-vetor.js +25 -11
  39. package/fontes/bibliotecas/primitivas-vetor.js.map +1 -1
  40. package/fontes/construtos/acesso-indice-variavel.d.ts +3 -3
  41. package/fontes/construtos/acesso-indice-variavel.js +41 -1
  42. package/fontes/construtos/acesso-indice-variavel.js.map +1 -1
  43. package/fontes/construtos/acesso-metodo.d.ts +3 -3
  44. package/fontes/construtos/acesso-metodo.js +41 -1
  45. package/fontes/construtos/acesso-metodo.js.map +1 -1
  46. package/fontes/construtos/agrupamento.d.ts +3 -3
  47. package/fontes/construtos/agrupamento.js +41 -1
  48. package/fontes/construtos/agrupamento.js.map +1 -1
  49. package/fontes/construtos/atribuicao-sobrescrita.d.ts +3 -2
  50. package/fontes/construtos/atribuicao-sobrescrita.js +41 -1
  51. package/fontes/construtos/atribuicao-sobrescrita.js.map +1 -1
  52. package/fontes/construtos/atribuir.d.ts +3 -3
  53. package/fontes/construtos/atribuir.js +41 -1
  54. package/fontes/construtos/atribuir.js.map +1 -1
  55. package/fontes/construtos/binario.d.ts +3 -3
  56. package/fontes/construtos/binario.js +41 -1
  57. package/fontes/construtos/binario.js.map +1 -1
  58. package/fontes/construtos/chamada.d.ts +3 -3
  59. package/fontes/construtos/chamada.js +41 -1
  60. package/fontes/construtos/chamada.js.map +1 -1
  61. package/fontes/construtos/conjunto.d.ts +3 -2
  62. package/fontes/construtos/conjunto.js +41 -1
  63. package/fontes/construtos/conjunto.js.map +1 -1
  64. package/fontes/construtos/construto.d.ts +1 -1
  65. package/fontes/construtos/dicionario.d.ts +3 -2
  66. package/fontes/construtos/dicionario.js +41 -1
  67. package/fontes/construtos/dicionario.js.map +1 -1
  68. package/fontes/construtos/funcao.d.ts +3 -3
  69. package/fontes/construtos/funcao.js +41 -1
  70. package/fontes/construtos/funcao.js.map +1 -1
  71. package/fontes/construtos/index.d.ts +18 -18
  72. package/fontes/construtos/isto.d.ts +3 -2
  73. package/fontes/construtos/isto.js +41 -1
  74. package/fontes/construtos/isto.js.map +1 -1
  75. package/fontes/construtos/literal.d.ts +4 -3
  76. package/fontes/construtos/literal.js +41 -1
  77. package/fontes/construtos/literal.js.map +1 -1
  78. package/fontes/construtos/logico.d.ts +3 -2
  79. package/fontes/construtos/logico.js +41 -1
  80. package/fontes/construtos/logico.js.map +1 -1
  81. package/fontes/construtos/super.d.ts +2 -2
  82. package/fontes/construtos/super.js +41 -1
  83. package/fontes/construtos/super.js.map +1 -1
  84. package/fontes/construtos/unario.d.ts +3 -2
  85. package/fontes/construtos/unario.js +41 -1
  86. package/fontes/construtos/unario.js.map +1 -1
  87. package/fontes/construtos/variavel.d.ts +3 -3
  88. package/fontes/construtos/variavel.js +41 -1
  89. package/fontes/construtos/variavel.js.map +1 -1
  90. package/fontes/construtos/vetor.d.ts +2 -1
  91. package/fontes/construtos/vetor.js +41 -1
  92. package/fontes/construtos/vetor.js.map +1 -1
  93. package/fontes/declaracoes/bloco.d.ts +3 -3
  94. package/fontes/declaracoes/bloco.js +41 -1
  95. package/fontes/declaracoes/bloco.js.map +1 -1
  96. package/fontes/declaracoes/classe.d.ts +3 -3
  97. package/fontes/declaracoes/classe.js +41 -1
  98. package/fontes/declaracoes/classe.js.map +1 -1
  99. package/fontes/declaracoes/continua.d.ts +3 -3
  100. package/fontes/declaracoes/continua.js +41 -1
  101. package/fontes/declaracoes/continua.js.map +1 -1
  102. package/fontes/declaracoes/declaracao.d.ts +2 -1
  103. package/fontes/declaracoes/declaracao.js +43 -3
  104. package/fontes/declaracoes/declaracao.js.map +1 -1
  105. package/fontes/declaracoes/enquanto.d.ts +4 -3
  106. package/fontes/declaracoes/enquanto.js +41 -1
  107. package/fontes/declaracoes/enquanto.js.map +1 -1
  108. package/fontes/declaracoes/escolha.d.ts +4 -3
  109. package/fontes/declaracoes/escolha.js +41 -1
  110. package/fontes/declaracoes/escolha.js.map +1 -1
  111. package/fontes/declaracoes/escreva.d.ts +1 -1
  112. package/fontes/declaracoes/escreva.js +41 -1
  113. package/fontes/declaracoes/escreva.js.map +1 -1
  114. package/fontes/declaracoes/expressao.d.ts +4 -4
  115. package/fontes/declaracoes/expressao.js +41 -1
  116. package/fontes/declaracoes/expressao.js.map +1 -1
  117. package/fontes/declaracoes/fazer.d.ts +3 -2
  118. package/fontes/declaracoes/fazer.js +41 -1
  119. package/fontes/declaracoes/fazer.js.map +1 -1
  120. package/fontes/declaracoes/funcao.d.ts +3 -3
  121. package/fontes/declaracoes/funcao.js +41 -1
  122. package/fontes/declaracoes/funcao.js.map +1 -1
  123. package/fontes/declaracoes/importar.d.ts +4 -3
  124. package/fontes/declaracoes/importar.js +41 -1
  125. package/fontes/declaracoes/importar.js.map +1 -1
  126. package/fontes/declaracoes/leia.d.ts +4 -4
  127. package/fontes/declaracoes/leia.js +44 -1
  128. package/fontes/declaracoes/leia.js.map +1 -1
  129. package/fontes/declaracoes/para.d.ts +3 -2
  130. package/fontes/declaracoes/para.js +41 -1
  131. package/fontes/declaracoes/para.js.map +1 -1
  132. package/fontes/declaracoes/retorna.d.ts +3 -3
  133. package/fontes/declaracoes/retorna.js +41 -1
  134. package/fontes/declaracoes/retorna.js.map +1 -1
  135. package/fontes/declaracoes/se.d.ts +3 -3
  136. package/fontes/declaracoes/se.js +41 -1
  137. package/fontes/declaracoes/se.js.map +1 -1
  138. package/fontes/declaracoes/sustar.d.ts +3 -3
  139. package/fontes/declaracoes/sustar.js +41 -1
  140. package/fontes/declaracoes/sustar.js.map +1 -1
  141. package/fontes/declaracoes/tente.d.ts +3 -3
  142. package/fontes/declaracoes/tente.js +41 -1
  143. package/fontes/declaracoes/tente.js.map +1 -1
  144. package/fontes/declaracoes/var.d.ts +4 -4
  145. package/fontes/declaracoes/var.js +41 -1
  146. package/fontes/declaracoes/var.js.map +1 -1
  147. package/fontes/delegua.d.ts +4 -4
  148. package/fontes/delegua.js +138 -63
  149. package/fontes/delegua.js.map +1 -1
  150. package/fontes/depuracao/cyrb53.js +6 -3
  151. package/fontes/depuracao/cyrb53.js.map +1 -1
  152. package/fontes/depuracao/servidor-depuracao.d.ts +4 -4
  153. package/fontes/depuracao/servidor-depuracao.js +199 -87
  154. package/fontes/depuracao/servidor-depuracao.js.map +1 -1
  155. package/fontes/espaco-variaveis.d.ts +1 -1
  156. package/fontes/espaco-variaveis.js +0 -1
  157. package/fontes/espaco-variaveis.js.map +1 -1
  158. package/fontes/estruturas/chamavel.js +1 -1
  159. package/fontes/estruturas/classe-padrao.d.ts +1 -1
  160. package/fontes/estruturas/classe-padrao.js.map +1 -1
  161. package/fontes/estruturas/delegua-classe.d.ts +4 -4
  162. package/fontes/estruturas/delegua-classe.js +5 -3
  163. package/fontes/estruturas/delegua-classe.js.map +1 -1
  164. package/fontes/estruturas/funcao-padrao.d.ts +2 -2
  165. package/fontes/estruturas/funcao-padrao.js +47 -3
  166. package/fontes/estruturas/funcao-padrao.js.map +1 -1
  167. package/fontes/estruturas/funcao.d.ts +5 -5
  168. package/fontes/estruturas/funcao.js +75 -24
  169. package/fontes/estruturas/funcao.js.map +1 -1
  170. package/fontes/estruturas/index.d.ts +9 -9
  171. package/fontes/estruturas/metodo-primitiva.d.ts +1 -1
  172. package/fontes/estruturas/modulo.d.ts +1 -1
  173. package/fontes/estruturas/modulo.js +1 -1
  174. package/fontes/estruturas/objeto-delegua-classe.d.ts +2 -2
  175. package/fontes/estruturas/objeto-delegua-classe.js +2 -2
  176. package/fontes/estruturas/objeto-delegua-classe.js.map +1 -1
  177. package/fontes/estruturas/objeto-padrao.js.map +1 -1
  178. package/fontes/excecoes/erro-em-tempo-de-execucao.d.ts +1 -1
  179. package/fontes/excecoes/erro-em-tempo-de-execucao.js.map +1 -1
  180. package/fontes/excecoes/index.d.ts +1 -1
  181. package/fontes/importador/importador.d.ts +1 -1
  182. package/fontes/importador/importador.js +3 -2
  183. package/fontes/importador/importador.js.map +1 -1
  184. package/fontes/importador/retorno-importador.d.ts +2 -2
  185. package/fontes/interfaces/avaliador-sintatico-interface.d.ts +5 -4
  186. package/fontes/interfaces/delegua-interface.d.ts +4 -4
  187. package/fontes/interfaces/escopo-execucao.d.ts +2 -2
  188. package/fontes/interfaces/importador-interface.d.ts +1 -1
  189. package/fontes/interfaces/interpretador-com-depuracao-interface.d.ts +6 -7
  190. package/fontes/interfaces/interpretador-interface.d.ts +6 -5
  191. package/fontes/interfaces/lexador-interface.d.ts +2 -2
  192. package/fontes/interfaces/parametro-interface.d.ts +1 -1
  193. package/fontes/interfaces/pilha-escopos-execucao-interface.d.ts +5 -5
  194. package/fontes/interfaces/resolvedor-interface.d.ts +5 -5
  195. package/fontes/interfaces/retornos/retorno-avaliador-sintatico.d.ts +2 -2
  196. package/fontes/interfaces/retornos/retorno-execucao-interface.d.ts +1 -1
  197. package/fontes/interfaces/retornos/retorno-interpretador.d.ts +1 -1
  198. package/fontes/interfaces/retornos/retorno-lexador.d.ts +3 -3
  199. package/fontes/interfaces/variavel-interface.d.ts +1 -1
  200. package/fontes/interpretador/dialetos/egua-classico.d.ts +31 -30
  201. package/fontes/interpretador/dialetos/egua-classico.js +922 -461
  202. package/fontes/interpretador/dialetos/egua-classico.js.map +1 -1
  203. package/fontes/interpretador/dialetos/index.js.map +1 -1
  204. package/fontes/interpretador/erro-interpretador.d.ts +1 -1
  205. package/fontes/interpretador/inferenciador.js.map +1 -1
  206. package/fontes/interpretador/interpretador-com-depuracao.d.ts +6 -6
  207. package/fontes/interpretador/interpretador-com-depuracao.js +280 -153
  208. package/fontes/interpretador/interpretador-com-depuracao.js.map +1 -1
  209. package/fontes/interpretador/interpretador.d.ts +44 -35
  210. package/fontes/interpretador/interpretador.js +1047 -535
  211. package/fontes/interpretador/interpretador.js.map +1 -1
  212. package/fontes/interpretador/pilha-escopos-execucao.js +16 -5
  213. package/fontes/interpretador/pilha-escopos-execucao.js.map +1 -1
  214. package/fontes/lexador/dialetos/index.js.map +1 -1
  215. package/fontes/lexador/dialetos/lexador-birl.d.ts +25 -0
  216. package/fontes/lexador/dialetos/lexador-birl.js +75 -0
  217. package/fontes/lexador/dialetos/lexador-birl.js.map +1 -0
  218. package/fontes/lexador/dialetos/lexador-egua-classico.js +3 -3
  219. package/fontes/lexador/dialetos/lexador-egua-classico.js.map +1 -1
  220. package/fontes/lexador/dialetos/lexador-eguap.d.ts +4 -4
  221. package/fontes/lexador/dialetos/lexador-eguap.js +15 -9
  222. package/fontes/lexador/dialetos/lexador-eguap.js.map +1 -1
  223. package/fontes/lexador/dialetos/lexador-visualg.d.ts +2 -2
  224. package/fontes/lexador/dialetos/lexador-visualg.js +6 -4
  225. package/fontes/lexador/dialetos/lexador-visualg.js.map +1 -1
  226. package/fontes/lexador/dialetos/palavras-reservadas/birl.d.ts +2 -0
  227. package/fontes/lexador/dialetos/palavras-reservadas/birl.js +4 -0
  228. package/fontes/lexador/dialetos/palavras-reservadas/birl.js.map +1 -0
  229. package/fontes/lexador/dialetos/palavras-reservadas/visualg.js +1 -1
  230. package/fontes/lexador/dialetos/palavras-reservadas/visualg.js.map +1 -1
  231. package/fontes/lexador/lexador-base-linha-unica.d.ts +3 -3
  232. package/fontes/lexador/lexador-base-linha-unica.js.map +1 -1
  233. package/fontes/lexador/lexador.js +2 -2
  234. package/fontes/lexador/lexador.js.map +1 -1
  235. package/fontes/lexador/palavras-reservadas.d.ts +22 -21
  236. package/fontes/lexador/palavras-reservadas.js +22 -21
  237. package/fontes/lexador/palavras-reservadas.js.map +1 -1
  238. package/fontes/lexador/simbolo.d.ts +1 -1
  239. package/fontes/lexador/simbolo.js +1 -1
  240. package/fontes/lexador/simbolo.js.map +1 -1
  241. package/fontes/quebras/index.js.map +1 -1
  242. package/fontes/resolvedor/dialetos/egua-classico.d.ts +25 -3
  243. package/fontes/resolvedor/dialetos/egua-classico.js +41 -1
  244. package/fontes/resolvedor/dialetos/egua-classico.js.map +1 -1
  245. package/fontes/resolvedor/dialetos/index.js.map +1 -1
  246. package/fontes/resolvedor/erro-resolvedor.d.ts +1 -1
  247. package/fontes/resolvedor/pilha-escopos.d.ts +1 -1
  248. package/fontes/resolvedor/pilha-escopos.js +2 -2
  249. package/fontes/resolvedor/pilha-escopos.js.map +1 -1
  250. package/fontes/resolvedor/retorno-resolvedor.d.ts +2 -2
  251. package/fontes/tipos-de-simbolos/birl.d.ts +18 -0
  252. package/fontes/tipos-de-simbolos/birl.js +21 -0
  253. package/fontes/tipos-de-simbolos/birl.js.map +1 -0
  254. package/fontes/tipos-de-simbolos/comum.js +15 -15
  255. package/fontes/tipos-de-simbolos/comum.js.map +1 -1
  256. package/fontes/tipos-de-simbolos/delegua.d.ts +2 -1
  257. package/fontes/tipos-de-simbolos/delegua.js +74 -73
  258. package/fontes/tipos-de-simbolos/delegua.js.map +1 -1
  259. package/fontes/tipos-de-simbolos/eguap.d.ts +1 -0
  260. package/fontes/tipos-de-simbolos/eguap.js +70 -69
  261. package/fontes/tipos-de-simbolos/eguap.js.map +1 -1
  262. package/fontes/tipos-de-simbolos/visualg.js +44 -44
  263. package/fontes/tipos-de-simbolos/visualg.js.map +1 -1
  264. package/index.js +1 -1
  265. package/index.js.map +1 -1
  266. package/jest.config.js +2 -2
  267. package/jest.config.js.map +1 -1
  268. package/package.json +10 -2
  269. package/testes/avaliador-sintatico.test.js +5 -5
  270. package/testes/avaliador-sintatico.test.js.map +1 -1
  271. package/testes/biblioteca-global.test.js +424 -181
  272. package/testes/biblioteca-global.test.js.map +1 -1
  273. package/testes/egua-classico/delegua.test.js.map +1 -1
  274. package/testes/egua-classico/interpretador.test.js +379 -163
  275. package/testes/egua-classico/interpretador.test.js.map +1 -1
  276. package/testes/egua-classico/resolvedor.test.js.map +1 -1
  277. package/testes/eguap/avaliador-sintatico.test.js +1 -5
  278. package/testes/eguap/avaliador-sintatico.test.js.map +1 -1
  279. package/testes/eguap/interpretador.test.js +388 -172
  280. package/testes/eguap/interpretador.test.js.map +1 -1
  281. package/testes/eguap/lexador.test.js +1 -1
  282. package/testes/eguap/lexador.test.js.map +1 -1
  283. package/testes/interpretador.test.js +876 -351
  284. package/testes/interpretador.test.js.map +1 -1
  285. package/fontes/tipos/avaliador-sintatico-egua-e-eguap-classico-returno-tipo.d.ts +0 -5
  286. package/fontes/tipos/avaliador-sintatico-egua-e-eguap-classico-returno-tipo.js +0 -3
  287. package/fontes/tipos/avaliador-sintatico-egua-e-eguap-classico-returno-tipo.js.map +0 -1
@@ -22,12 +22,49 @@ 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
+ };
25
61
  var __importDefault = (this && this.__importDefault) || function (mod) {
26
62
  return (mod && mod.__esModule) ? mod : { "default": mod };
27
63
  };
28
64
  Object.defineProperty(exports, "__esModule", { value: true });
29
65
  exports.Interpretador = void 0;
30
66
  var caminho = __importStar(require("path"));
67
+ var readline = __importStar(require("readline"));
31
68
  var browser_process_hrtime_1 = __importDefault(require("browser-process-hrtime"));
32
69
  var delegua_1 = __importDefault(require("../tipos-de-simbolos/delegua"));
33
70
  var espaco_variaveis_1 = require("../espaco-variaveis");
@@ -48,13 +85,20 @@ var primitivas_vetor_1 = __importDefault(require("../bibliotecas/primitivas-veto
48
85
  var Interpretador = /** @class */ (function () {
49
86
  function Interpretador(importador, diretorioBase, performance, funcaoDeRetorno) {
50
87
  if (performance === void 0) { performance = false; }
88
+ if (funcaoDeRetorno === void 0) { funcaoDeRetorno = null; }
51
89
  this.funcaoDeRetorno = null;
90
+ this.interfaceDeEntrada = null;
52
91
  this.resultadoInterpretador = [];
53
- this.regexInterpolacao = /\$\{([a-z_][\w]*)\}/ig;
92
+ this.regexInterpolacao = /\$\{([a-z_][\w]*)\}/gi;
54
93
  this.importador = importador;
55
94
  this.diretorioBase = diretorioBase;
56
95
  this.performance = performance;
57
96
  this.funcaoDeRetorno = funcaoDeRetorno || console.log;
97
+ this.interfaceDeEntrada = readline.createInterface({
98
+ input: process.stdin,
99
+ output: process.stdout,
100
+ prompt: '\n> ',
101
+ });
58
102
  this.erros = [];
59
103
  this.declaracoes = [];
60
104
  this.pilhaEscoposExecucao = new pilha_escopos_execucao_1.PilhaEscoposExecucao();
@@ -69,10 +113,22 @@ var Interpretador = /** @class */ (function () {
69
113
  /**
70
114
  * Execução da leitura de valores da entrada configurada no
71
115
  * início da aplicação.
72
- * @param expressao
116
+ * @param expressao Expressão do tipo Leia
117
+ * @returns Promise com o resultado da leitura.
73
118
  */
74
119
  Interpretador.prototype.visitarExpressaoLeia = function (expressao) {
75
- throw new Error('Método não implementado.');
120
+ return __awaiter(this, void 0, void 0, function () {
121
+ var mensagem;
122
+ var _this = this;
123
+ return __generator(this, function (_a) {
124
+ mensagem = expressao.argumentos && expressao.argumentos[0] ? expressao.argumentos[0].valor : '';
125
+ return [2 /*return*/, new Promise(function (resolucao) {
126
+ return _this.interfaceDeEntrada.question(mensagem, function (resposta) {
127
+ resolucao(resposta);
128
+ });
129
+ })];
130
+ });
131
+ });
76
132
  };
77
133
  /**
78
134
  * Retira a interpolação de um texto.
@@ -107,7 +163,7 @@ var Interpretador = /** @class */ (function () {
107
163
  var nomeVariavel = s.replace(/[\$\{\}]*/g, '');
108
164
  return {
109
165
  variavel: nomeVariavel,
110
- valor: _this.pilhaEscoposExecucao.obterVariavelPorNome(nomeVariavel)
166
+ valor: _this.pilhaEscoposExecucao.obterVariavelPorNome(nomeVariavel),
111
167
  };
112
168
  });
113
169
  };
@@ -119,10 +175,24 @@ var Interpretador = /** @class */ (function () {
119
175
  return expressao.valor;
120
176
  };
121
177
  Interpretador.prototype.avaliar = function (expressao) {
122
- return expressao.aceitar(this);
178
+ return __awaiter(this, void 0, void 0, function () {
179
+ return __generator(this, function (_a) {
180
+ switch (_a.label) {
181
+ case 0: return [4 /*yield*/, expressao.aceitar(this)];
182
+ case 1: return [2 /*return*/, _a.sent()];
183
+ }
184
+ });
185
+ });
123
186
  };
124
187
  Interpretador.prototype.visitarExpressaoAgrupamento = function (expressao) {
125
- return this.avaliar(expressao.expressao);
188
+ return __awaiter(this, void 0, void 0, function () {
189
+ return __generator(this, function (_a) {
190
+ switch (_a.label) {
191
+ case 0: return [4 /*yield*/, this.avaliar(expressao.expressao)];
192
+ case 1: return [2 /*return*/, _a.sent()];
193
+ }
194
+ });
195
+ });
126
196
  };
127
197
  Interpretador.prototype.eVerdadeiro = function (objeto) {
128
198
  if (objeto === null)
@@ -132,22 +202,34 @@ var Interpretador = /** @class */ (function () {
132
202
  return true;
133
203
  };
134
204
  Interpretador.prototype.verificarOperandoNumero = function (operador, operando) {
135
- if (typeof operando === 'number')
205
+ if (typeof operando === 'number' || operando.tipo === 'número')
136
206
  return;
137
- throw new excecoes_1.ErroEmTempoDeExecucao(operador, 'Operando precisa ser um número.', operador.linha);
207
+ throw new excecoes_1.ErroEmTempoDeExecucao(operador, 'Operando precisa ser um número.', Number(operador.linha));
138
208
  };
139
209
  Interpretador.prototype.visitarExpressaoUnaria = function (expressao) {
140
- var direita = this.avaliar(expressao.direita);
141
- switch (expressao.operador.tipo) {
142
- case delegua_1.default.SUBTRACAO:
143
- this.verificarOperandoNumero(expressao.operador, direita);
144
- return -direita;
145
- case delegua_1.default.NEGACAO:
146
- return !this.eVerdadeiro(direita);
147
- case delegua_1.default.BIT_NOT:
148
- return ~direita;
149
- }
150
- return null;
210
+ return __awaiter(this, void 0, void 0, function () {
211
+ var direita, valor;
212
+ return __generator(this, function (_a) {
213
+ switch (_a.label) {
214
+ case 0: return [4 /*yield*/, this.avaliar(expressao.direita)];
215
+ case 1:
216
+ direita = _a.sent();
217
+ valor = direita.hasOwnProperty('valor') ?
218
+ direita.valor :
219
+ direita;
220
+ switch (expressao.operador.tipo) {
221
+ case delegua_1.default.SUBTRACAO:
222
+ this.verificarOperandoNumero(expressao.operador, valor);
223
+ return [2 /*return*/, -valor];
224
+ case delegua_1.default.NEGACAO:
225
+ return [2 /*return*/, !this.eVerdadeiro(valor)];
226
+ case delegua_1.default.BIT_NOT:
227
+ return [2 /*return*/, ~valor];
228
+ }
229
+ return [2 /*return*/, null];
230
+ }
231
+ });
232
+ });
151
233
  };
152
234
  Interpretador.prototype.eIgual = function (esquerda, direita) {
153
235
  if (esquerda === null && direita === null)
@@ -189,81 +271,98 @@ var Interpretador = /** @class */ (function () {
189
271
  throw new excecoes_1.ErroEmTempoDeExecucao(operador, 'Operadores precisam ser números.', operador.linha);
190
272
  };
191
273
  Interpretador.prototype.visitarExpressaoBinaria = function (expressao) {
192
- var esquerda = this.avaliar(expressao.esquerda);
193
- var direita = this.avaliar(expressao.direita);
194
- var valorEsquerdo = (esquerda === null || esquerda === void 0 ? void 0 : esquerda.hasOwnProperty('valor'))
195
- ? esquerda.valor
196
- : esquerda;
197
- var valorDireito = (direita === null || direita === void 0 ? void 0 : direita.hasOwnProperty('valor'))
198
- ? direita.valor
199
- : direita;
200
- var tipoEsquerdo = (esquerda === null || esquerda === void 0 ? void 0 : esquerda.hasOwnProperty('tipo'))
201
- ? esquerda.tipo
202
- : (0, inferenciador_1.inferirTipoVariavel)(esquerda);
203
- var tipoDireito = (direita === null || direita === void 0 ? void 0 : direita.hasOwnProperty('tipo'))
204
- ? direita.tipo
205
- : (0, inferenciador_1.inferirTipoVariavel)(direita);
206
- switch (expressao.operador.tipo) {
207
- case delegua_1.default.EXPONENCIACAO:
208
- this.verificarOperandosNumeros(expressao.operador, esquerda, direita);
209
- return Math.pow(valorEsquerdo, valorDireito);
210
- case delegua_1.default.MAIOR:
211
- this.verificarOperandosNumeros(expressao.operador, esquerda, direita);
212
- return Number(valorEsquerdo) > Number(valorDireito);
213
- case delegua_1.default.MAIOR_IGUAL:
214
- this.verificarOperandosNumeros(expressao.operador, esquerda, direita);
215
- return Number(valorEsquerdo) >= Number(valorDireito);
216
- case delegua_1.default.MENOR:
217
- this.verificarOperandosNumeros(expressao.operador, esquerda, direita);
218
- return Number(valorEsquerdo) < Number(valorDireito);
219
- case delegua_1.default.MENOR_IGUAL:
220
- this.verificarOperandosNumeros(expressao.operador, esquerda, direita);
221
- return Number(valorEsquerdo) <= Number(valorDireito);
222
- case delegua_1.default.SUBTRACAO:
223
- case delegua_1.default.MENOS_IGUAL:
224
- this.verificarOperandosNumeros(expressao.operador, esquerda, direita);
225
- return Number(valorEsquerdo) - Number(valorDireito);
226
- case delegua_1.default.ADICAO:
227
- case delegua_1.default.MAIS_IGUAL:
228
- if (tipoEsquerdo === 'número' && tipoDireito === 'número') {
229
- return Number(valorEsquerdo) + Number(valorDireito);
230
- }
231
- else {
232
- return String(valorEsquerdo) + String(valorDireito);
274
+ return __awaiter(this, void 0, void 0, function () {
275
+ var esquerda, direita, valorEsquerdo, valorDireito, tipoEsquerdo, tipoDireito, erro_1;
276
+ return __generator(this, function (_a) {
277
+ switch (_a.label) {
278
+ case 0:
279
+ _a.trys.push([0, 3, , 4]);
280
+ return [4 /*yield*/, this.avaliar(expressao.esquerda)];
281
+ case 1:
282
+ esquerda = _a.sent();
283
+ return [4 /*yield*/, this.avaliar(expressao.direita)];
284
+ case 2:
285
+ direita = _a.sent();
286
+ valorEsquerdo = (esquerda === null || esquerda === void 0 ? void 0 : esquerda.hasOwnProperty('valor'))
287
+ ? esquerda.valor
288
+ : esquerda;
289
+ valorDireito = (direita === null || direita === void 0 ? void 0 : direita.hasOwnProperty('valor'))
290
+ ? direita.valor
291
+ : direita;
292
+ tipoEsquerdo = (esquerda === null || esquerda === void 0 ? void 0 : esquerda.hasOwnProperty('tipo'))
293
+ ? esquerda.tipo
294
+ : (0, inferenciador_1.inferirTipoVariavel)(esquerda);
295
+ tipoDireito = (direita === null || direita === void 0 ? void 0 : direita.hasOwnProperty('tipo'))
296
+ ? direita.tipo
297
+ : (0, inferenciador_1.inferirTipoVariavel)(direita);
298
+ switch (expressao.operador.tipo) {
299
+ case delegua_1.default.EXPONENCIACAO:
300
+ this.verificarOperandosNumeros(expressao.operador, esquerda, direita);
301
+ return [2 /*return*/, Math.pow(valorEsquerdo, valorDireito)];
302
+ case delegua_1.default.MAIOR:
303
+ this.verificarOperandosNumeros(expressao.operador, esquerda, direita);
304
+ return [2 /*return*/, Number(valorEsquerdo) > Number(valorDireito)];
305
+ case delegua_1.default.MAIOR_IGUAL:
306
+ this.verificarOperandosNumeros(expressao.operador, esquerda, direita);
307
+ return [2 /*return*/, Number(valorEsquerdo) >= Number(valorDireito)];
308
+ case delegua_1.default.MENOR:
309
+ this.verificarOperandosNumeros(expressao.operador, esquerda, direita);
310
+ return [2 /*return*/, Number(valorEsquerdo) < Number(valorDireito)];
311
+ case delegua_1.default.MENOR_IGUAL:
312
+ this.verificarOperandosNumeros(expressao.operador, esquerda, direita);
313
+ return [2 /*return*/, Number(valorEsquerdo) <= Number(valorDireito)];
314
+ case delegua_1.default.SUBTRACAO:
315
+ case delegua_1.default.MENOS_IGUAL:
316
+ this.verificarOperandosNumeros(expressao.operador, esquerda, direita);
317
+ return [2 /*return*/, Number(valorEsquerdo) - Number(valorDireito)];
318
+ case delegua_1.default.ADICAO:
319
+ case delegua_1.default.MAIS_IGUAL:
320
+ if (tipoEsquerdo === 'número' && tipoDireito === 'número') {
321
+ return [2 /*return*/, Number(valorEsquerdo) + Number(valorDireito)];
322
+ }
323
+ else {
324
+ return [2 /*return*/, String(valorEsquerdo) + String(valorDireito)];
325
+ }
326
+ case delegua_1.default.DIVISAO:
327
+ case delegua_1.default.DIVISAO_IGUAL:
328
+ this.verificarOperandosNumeros(expressao.operador, esquerda, direita);
329
+ return [2 /*return*/, Number(valorEsquerdo) / Number(valorDireito)];
330
+ case delegua_1.default.MULTIPLICACAO:
331
+ case delegua_1.default.MULTIPLICACAO_IGUAL:
332
+ this.verificarOperandosNumeros(expressao.operador, esquerda, direita);
333
+ return [2 /*return*/, Number(valorEsquerdo) * Number(valorDireito)];
334
+ case delegua_1.default.MODULO:
335
+ case delegua_1.default.MODULO_IGUAL:
336
+ this.verificarOperandosNumeros(expressao.operador, esquerda, direita);
337
+ return [2 /*return*/, Number(valorEsquerdo) % Number(valorDireito)];
338
+ case delegua_1.default.BIT_AND:
339
+ this.verificarOperandosNumeros(expressao.operador, esquerda, direita);
340
+ return [2 /*return*/, Number(valorEsquerdo) & Number(valorDireito)];
341
+ case delegua_1.default.BIT_XOR:
342
+ this.verificarOperandosNumeros(expressao.operador, esquerda, direita);
343
+ return [2 /*return*/, Number(valorEsquerdo) ^ Number(valorDireito)];
344
+ case delegua_1.default.BIT_OR:
345
+ this.verificarOperandosNumeros(expressao.operador, esquerda, direita);
346
+ return [2 /*return*/, Number(valorEsquerdo) | Number(valorDireito)];
347
+ case delegua_1.default.MENOR_MENOR:
348
+ this.verificarOperandosNumeros(expressao.operador, esquerda, direita);
349
+ return [2 /*return*/, Number(valorEsquerdo) << Number(valorDireito)];
350
+ case delegua_1.default.MAIOR_MAIOR:
351
+ this.verificarOperandosNumeros(expressao.operador, esquerda, direita);
352
+ return [2 /*return*/, Number(valorEsquerdo) >> Number(valorDireito)];
353
+ case delegua_1.default.DIFERENTE:
354
+ return [2 /*return*/, !this.eIgual(valorEsquerdo, valorDireito)];
355
+ case delegua_1.default.IGUAL_IGUAL:
356
+ return [2 /*return*/, this.eIgual(valorEsquerdo, valorDireito)];
357
+ }
358
+ return [3 /*break*/, 4];
359
+ case 3:
360
+ erro_1 = _a.sent();
361
+ return [2 /*return*/, Promise.reject(erro_1)];
362
+ case 4: return [2 /*return*/];
233
363
  }
234
- case delegua_1.default.DIVISAO:
235
- case delegua_1.default.DIVISAO_IGUAL:
236
- this.verificarOperandosNumeros(expressao.operador, esquerda, direita);
237
- return Number(valorEsquerdo) / Number(valorDireito);
238
- case delegua_1.default.MULTIPLICACAO:
239
- case delegua_1.default.MULTIPLICACAO_IGUAL:
240
- this.verificarOperandosNumeros(expressao.operador, esquerda, direita);
241
- return Number(valorEsquerdo) * Number(valorDireito);
242
- case delegua_1.default.MODULO:
243
- case delegua_1.default.MODULO_IGUAL:
244
- this.verificarOperandosNumeros(expressao.operador, esquerda, direita);
245
- return Number(valorEsquerdo) % Number(valorDireito);
246
- case delegua_1.default.BIT_AND:
247
- this.verificarOperandosNumeros(expressao.operador, esquerda, direita);
248
- return Number(valorEsquerdo) & Number(valorDireito);
249
- case delegua_1.default.BIT_XOR:
250
- this.verificarOperandosNumeros(expressao.operador, esquerda, direita);
251
- return Number(valorEsquerdo) ^ Number(valorDireito);
252
- case delegua_1.default.BIT_OR:
253
- this.verificarOperandosNumeros(expressao.operador, esquerda, direita);
254
- return Number(valorEsquerdo) | Number(valorDireito);
255
- case delegua_1.default.MENOR_MENOR:
256
- this.verificarOperandosNumeros(expressao.operador, esquerda, direita);
257
- return Number(valorEsquerdo) << Number(valorDireito);
258
- case delegua_1.default.MAIOR_MAIOR:
259
- this.verificarOperandosNumeros(expressao.operador, esquerda, direita);
260
- return Number(valorEsquerdo) >> Number(valorDireito);
261
- case delegua_1.default.DIFERENTE:
262
- return !this.eIgual(valorEsquerdo, valorDireito);
263
- case delegua_1.default.IGUAL_IGUAL:
264
- return this.eIgual(valorEsquerdo, valorDireito);
265
- }
266
- return null;
364
+ });
365
+ });
267
366
  };
268
367
  /**
269
368
  * Executa uma chamada de função, método ou classe.
@@ -271,65 +370,99 @@ var Interpretador = /** @class */ (function () {
271
370
  * @returns O resultado da chamada.
272
371
  */
273
372
  Interpretador.prototype.visitarExpressaoDeChamada = function (expressao) {
274
- var variavelEntidadeChamada = this.avaliar(expressao.entidadeChamada);
275
- var entidadeChamada = variavelEntidadeChamada.hasOwnProperty('valor')
276
- ? variavelEntidadeChamada.valor
277
- : variavelEntidadeChamada;
278
- var argumentos = [];
279
- for (var i = 0; i < expressao.argumentos.length; i++) {
280
- argumentos.push(this.avaliar(expressao.argumentos[i]));
281
- }
282
- if (!(entidadeChamada instanceof estruturas_1.Chamavel)) {
283
- throw new excecoes_1.ErroEmTempoDeExecucao(expressao.parentese, 'Só pode chamar função ou classe.', expressao.linha);
284
- }
285
- if (entidadeChamada instanceof metodo_primitiva_1.MetodoPrimitiva) {
286
- var argumentosResolvidos = [];
287
- for (var _i = 0, _a = expressao.argumentos; _i < _a.length; _i++) {
288
- var argumento = _a[_i];
289
- var valorResolvido = this.avaliar(argumento);
290
- argumentosResolvidos.push(valorResolvido.hasOwnProperty('valor')
291
- ? valorResolvido.valor
292
- : valorResolvido);
293
- }
294
- return entidadeChamada.chamar(argumentosResolvidos);
295
- }
296
- var parametros;
297
- if (entidadeChamada instanceof estruturas_1.DeleguaFuncao) {
298
- parametros = entidadeChamada.declaracao.parametros;
299
- }
300
- else if (entidadeChamada instanceof estruturas_1.DeleguaClasse) {
301
- parametros = entidadeChamada.metodos.inicializacao
302
- ? entidadeChamada.metodos.inicializacao.declaracao.parametros
303
- : [];
304
- }
305
- else {
306
- parametros = [];
307
- }
308
- // Completar os parâmetros não preenchidos com nulos.
309
- if (argumentos.length < entidadeChamada.aridade()) {
310
- var diferenca = entidadeChamada.aridade() - argumentos.length;
311
- for (var i = 0; i < diferenca; i++) {
312
- argumentos.push(null);
313
- }
314
- }
315
- else {
316
- if (parametros &&
317
- parametros.length > 0 &&
318
- parametros[parametros.length - 1].tipo === 'estrela') {
319
- var novosArgumentos = argumentos.slice(0, parametros.length - 1);
320
- novosArgumentos.push(argumentos.slice(parametros.length - 1, argumentos.length));
321
- argumentos = novosArgumentos;
322
- }
323
- }
324
- if (entidadeChamada instanceof estruturas_1.FuncaoPadrao) {
325
- try {
326
- return entidadeChamada.chamar(argumentos, expressao.entidadeChamada.nome);
327
- }
328
- catch (erro) {
329
- this.erros.push(erro);
330
- }
331
- }
332
- return entidadeChamada.chamar(this, argumentos);
373
+ return __awaiter(this, void 0, void 0, function () {
374
+ var variavelEntidadeChamada, entidadeChamada, argumentos, i, _a, _b, argumentosResolvidos, _i, _c, argumento, valorResolvido, parametros, diferenca, i, novosArgumentos, erro_2;
375
+ return __generator(this, function (_d) {
376
+ switch (_d.label) {
377
+ case 0:
378
+ _d.trys.push([0, 11, , 12]);
379
+ return [4 /*yield*/, this.avaliar(expressao.entidadeChamada)];
380
+ case 1:
381
+ variavelEntidadeChamada = _d.sent();
382
+ entidadeChamada = variavelEntidadeChamada.hasOwnProperty('valor')
383
+ ? variavelEntidadeChamada.valor
384
+ : variavelEntidadeChamada;
385
+ argumentos = [];
386
+ i = 0;
387
+ _d.label = 2;
388
+ case 2:
389
+ if (!(i < expressao.argumentos.length)) return [3 /*break*/, 5];
390
+ _b = (_a = argumentos).push;
391
+ return [4 /*yield*/, this.avaliar(expressao.argumentos[i])];
392
+ case 3:
393
+ _b.apply(_a, [_d.sent()]);
394
+ _d.label = 4;
395
+ case 4:
396
+ i++;
397
+ return [3 /*break*/, 2];
398
+ case 5:
399
+ if (!(entidadeChamada instanceof estruturas_1.Chamavel)) {
400
+ throw new excecoes_1.ErroEmTempoDeExecucao(expressao.parentese, 'Só pode chamar função ou classe.', expressao.linha);
401
+ }
402
+ if (!(entidadeChamada instanceof metodo_primitiva_1.MetodoPrimitiva)) return [3 /*break*/, 10];
403
+ argumentosResolvidos = [];
404
+ _i = 0, _c = expressao.argumentos;
405
+ _d.label = 6;
406
+ case 6:
407
+ if (!(_i < _c.length)) return [3 /*break*/, 9];
408
+ argumento = _c[_i];
409
+ return [4 /*yield*/, this.avaliar(argumento)];
410
+ case 7:
411
+ valorResolvido = _d.sent();
412
+ argumentosResolvidos.push(valorResolvido.hasOwnProperty('valor')
413
+ ? valorResolvido.valor
414
+ : valorResolvido);
415
+ _d.label = 8;
416
+ case 8:
417
+ _i++;
418
+ return [3 /*break*/, 6];
419
+ case 9: return [2 /*return*/, entidadeChamada.chamar(argumentosResolvidos)];
420
+ case 10:
421
+ parametros = void 0;
422
+ if (entidadeChamada instanceof estruturas_1.DeleguaFuncao) {
423
+ parametros = entidadeChamada.declaracao.parametros;
424
+ }
425
+ else if (entidadeChamada instanceof estruturas_1.DeleguaClasse) {
426
+ parametros = entidadeChamada.metodos.inicializacao
427
+ ? entidadeChamada.metodos.inicializacao.declaracao.parametros
428
+ : [];
429
+ }
430
+ else {
431
+ parametros = [];
432
+ }
433
+ // Completar os parâmetros não preenchidos com nulos.
434
+ if (argumentos.length < entidadeChamada.aridade()) {
435
+ diferenca = entidadeChamada.aridade() - argumentos.length;
436
+ for (i = 0; i < diferenca; i++) {
437
+ argumentos.push(null);
438
+ }
439
+ }
440
+ else {
441
+ if (parametros &&
442
+ parametros.length > 0 &&
443
+ parametros[parametros.length - 1].tipo === 'estrela') {
444
+ novosArgumentos = argumentos.slice(0, parametros.length - 1);
445
+ novosArgumentos.push(argumentos.slice(parametros.length - 1, argumentos.length));
446
+ argumentos = novosArgumentos;
447
+ }
448
+ }
449
+ if (entidadeChamada instanceof estruturas_1.FuncaoPadrao) {
450
+ try {
451
+ return [2 /*return*/, entidadeChamada.chamar(argumentos, expressao.entidadeChamada.nome)];
452
+ }
453
+ catch (erro) {
454
+ this.erros.push(erro);
455
+ }
456
+ }
457
+ return [2 /*return*/, entidadeChamada.chamar(this, argumentos)];
458
+ case 11:
459
+ erro_2 = _d.sent();
460
+ console.log(erro_2);
461
+ return [3 /*break*/, 12];
462
+ case 12: return [2 /*return*/];
463
+ }
464
+ });
465
+ });
333
466
  };
334
467
  /**
335
468
  * Execução de uma expressão de atribuição.
@@ -337,9 +470,18 @@ var Interpretador = /** @class */ (function () {
337
470
  * @returns O valor atribuído.
338
471
  */
339
472
  Interpretador.prototype.visitarExpressaoDeAtribuicao = function (expressao) {
340
- var valor = this.avaliar(expressao.valor);
341
- this.pilhaEscoposExecucao.atribuirVariavel(expressao.simbolo, valor);
342
- return valor;
473
+ return __awaiter(this, void 0, void 0, function () {
474
+ var valor;
475
+ return __generator(this, function (_a) {
476
+ switch (_a.label) {
477
+ case 0: return [4 /*yield*/, this.avaliar(expressao.valor)];
478
+ case 1:
479
+ valor = _a.sent();
480
+ this.pilhaEscoposExecucao.atribuirVariavel(expressao.simbolo, valor);
481
+ return [2 /*return*/, valor];
482
+ }
483
+ });
484
+ });
343
485
  };
344
486
  Interpretador.prototype.procurarVariavel = function (simbolo) {
345
487
  return this.pilhaEscoposExecucao.obterVariavel(simbolo);
@@ -348,33 +490,53 @@ var Interpretador = /** @class */ (function () {
348
490
  return this.procurarVariavel(expressao.simbolo);
349
491
  };
350
492
  Interpretador.prototype.visitarDeclaracaoDeExpressao = function (declaracao) {
351
- return this.avaliar(declaracao.expressao);
493
+ return __awaiter(this, void 0, void 0, function () {
494
+ return __generator(this, function (_a) {
495
+ switch (_a.label) {
496
+ case 0: return [4 /*yield*/, this.avaliar(declaracao.expressao)];
497
+ case 1: return [2 /*return*/, _a.sent()];
498
+ }
499
+ });
500
+ });
352
501
  };
353
502
  Interpretador.prototype.visitarExpressaoLogica = function (expressao) {
354
- var esquerda = this.avaliar(expressao.esquerda);
355
- if (expressao.operador.tipo === delegua_1.default.EM) {
356
- var direita = this.avaliar(expressao.direita);
357
- if (Array.isArray(direita) || typeof direita === 'string') {
358
- return direita.includes(esquerda);
359
- }
360
- else if (direita.constructor === Object) {
361
- return esquerda in direita;
362
- }
363
- else {
364
- throw new excecoes_1.ErroEmTempoDeExecucao(esquerda, "Tipo de chamada inválida com 'em'.", expressao.linha);
365
- }
366
- }
367
- // se um estado for verdadeiro, retorna verdadeiro
368
- if (expressao.operador.tipo === delegua_1.default.OU) {
369
- if (this.eVerdadeiro(esquerda))
370
- return esquerda;
371
- }
372
- // se um estado for falso, retorna falso
373
- if (expressao.operador.tipo === delegua_1.default.E) {
374
- if (!this.eVerdadeiro(esquerda))
375
- return esquerda;
376
- }
377
- return this.avaliar(expressao.direita);
503
+ return __awaiter(this, void 0, void 0, function () {
504
+ var esquerda, direita;
505
+ return __generator(this, function (_a) {
506
+ switch (_a.label) {
507
+ case 0: return [4 /*yield*/, this.avaliar(expressao.esquerda)];
508
+ case 1:
509
+ esquerda = _a.sent();
510
+ if (!(expressao.operador.tipo === delegua_1.default.EM)) return [3 /*break*/, 3];
511
+ return [4 /*yield*/, this.avaliar(expressao.direita)];
512
+ case 2:
513
+ direita = _a.sent();
514
+ if (Array.isArray(direita) || typeof direita === 'string') {
515
+ return [2 /*return*/, direita.includes(esquerda)];
516
+ }
517
+ else if (direita.constructor === Object) {
518
+ return [2 /*return*/, esquerda in direita];
519
+ }
520
+ else {
521
+ throw new excecoes_1.ErroEmTempoDeExecucao(esquerda, "Tipo de chamada inválida com 'em'.", expressao.linha);
522
+ }
523
+ _a.label = 3;
524
+ case 3:
525
+ // se um estado for verdadeiro, retorna verdadeiro
526
+ if (expressao.operador.tipo === delegua_1.default.OU) {
527
+ if (this.eVerdadeiro(esquerda))
528
+ return [2 /*return*/, esquerda];
529
+ }
530
+ // se um estado for falso, retorna falso
531
+ if (expressao.operador.tipo === delegua_1.default.E) {
532
+ if (!this.eVerdadeiro(esquerda))
533
+ return [2 /*return*/, esquerda];
534
+ }
535
+ return [4 /*yield*/, this.avaliar(expressao.direita)];
536
+ case 4: return [2 /*return*/, _a.sent()];
537
+ }
538
+ });
539
+ });
378
540
  };
379
541
  /**
380
542
  * Executa uma expressão Se, que tem uma condição, pode ter um bloco
@@ -383,146 +545,288 @@ var Interpretador = /** @class */ (function () {
383
545
  * @returns O resultado da avaliação do bloco cuja condição é verdadeira.
384
546
  */
385
547
  Interpretador.prototype.visitarExpressaoSe = function (declaracao) {
386
- if (this.eVerdadeiro(this.avaliar(declaracao.condicao))) {
387
- return this.executar(declaracao.caminhoEntao);
388
- }
389
- for (var i = 0; i < declaracao.caminhosSeSenao.length; i++) {
390
- var atual = declaracao.caminhosSeSenao[i];
391
- if (this.eVerdadeiro(this.avaliar(atual.condicao))) {
392
- return this.executar(atual.caminho);
393
- }
394
- }
395
- if (declaracao.caminhoSenao !== null) {
396
- return this.executar(declaracao.caminhoSenao);
397
- }
398
- return null;
548
+ return __awaiter(this, void 0, void 0, function () {
549
+ var _a, i, atual, _b;
550
+ return __generator(this, function (_c) {
551
+ switch (_c.label) {
552
+ case 0:
553
+ _a = this.eVerdadeiro;
554
+ return [4 /*yield*/, this.avaliar(declaracao.condicao)];
555
+ case 1:
556
+ if (!_a.apply(this, [_c.sent()])) return [3 /*break*/, 3];
557
+ return [4 /*yield*/, this.executar(declaracao.caminhoEntao)];
558
+ case 2: return [2 /*return*/, _c.sent()];
559
+ case 3:
560
+ i = 0;
561
+ _c.label = 4;
562
+ case 4:
563
+ if (!(i < declaracao.caminhosSeSenao.length)) return [3 /*break*/, 8];
564
+ atual = declaracao.caminhosSeSenao[i];
565
+ _b = this.eVerdadeiro;
566
+ return [4 /*yield*/, this.avaliar(atual.condicao)];
567
+ case 5:
568
+ if (!_b.apply(this, [_c.sent()])) return [3 /*break*/, 7];
569
+ return [4 /*yield*/, this.executar(atual.caminho)];
570
+ case 6: return [2 /*return*/, _c.sent()];
571
+ case 7:
572
+ i++;
573
+ return [3 /*break*/, 4];
574
+ case 8:
575
+ if (!(declaracao.caminhoSenao !== null)) return [3 /*break*/, 10];
576
+ return [4 /*yield*/, this.executar(declaracao.caminhoSenao)];
577
+ case 9: return [2 /*return*/, _c.sent()];
578
+ case 10: return [2 /*return*/, null];
579
+ }
580
+ });
581
+ });
399
582
  };
400
583
  Interpretador.prototype.visitarExpressaoPara = function (declaracao) {
401
- if (declaracao.inicializador !== null) {
402
- this.avaliar(declaracao.inicializador);
403
- }
404
- var retornoExecucao;
405
- while (!(retornoExecucao instanceof quebras_1.Quebra)) {
406
- if (declaracao.condicao !== null &&
407
- !this.eVerdadeiro(this.avaliar(declaracao.condicao))) {
408
- break;
409
- }
410
- try {
411
- retornoExecucao = this.executar(declaracao.corpo);
412
- }
413
- catch (erro) {
414
- throw erro;
415
- }
416
- if (declaracao.incrementar !== null) {
417
- this.avaliar(declaracao.incrementar);
418
- }
419
- }
420
- return null;
584
+ return __awaiter(this, void 0, void 0, function () {
585
+ var retornoExecucao, _a, _b, erro_3;
586
+ return __generator(this, function (_c) {
587
+ switch (_c.label) {
588
+ case 0:
589
+ if (!(declaracao.inicializador !== null)) return [3 /*break*/, 2];
590
+ return [4 /*yield*/, this.avaliar(declaracao.inicializador)];
591
+ case 1:
592
+ _c.sent();
593
+ _c.label = 2;
594
+ case 2:
595
+ if (!!(retornoExecucao instanceof quebras_1.Quebra)) return [3 /*break*/, 11];
596
+ _a = declaracao.condicao !== null;
597
+ if (!_a) return [3 /*break*/, 4];
598
+ _b = this.eVerdadeiro;
599
+ return [4 /*yield*/, this.avaliar(declaracao.condicao)];
600
+ case 3:
601
+ _a = !_b.apply(this, [_c.sent()]);
602
+ _c.label = 4;
603
+ case 4:
604
+ if (_a) {
605
+ return [3 /*break*/, 11];
606
+ }
607
+ _c.label = 5;
608
+ case 5:
609
+ _c.trys.push([5, 7, , 8]);
610
+ return [4 /*yield*/, this.executar(declaracao.corpo)];
611
+ case 6:
612
+ retornoExecucao = _c.sent();
613
+ return [3 /*break*/, 8];
614
+ case 7:
615
+ erro_3 = _c.sent();
616
+ throw erro_3;
617
+ case 8:
618
+ if (!(declaracao.incrementar !== null)) return [3 /*break*/, 10];
619
+ return [4 /*yield*/, this.avaliar(declaracao.incrementar)];
620
+ case 9:
621
+ _c.sent();
622
+ _c.label = 10;
623
+ case 10: return [3 /*break*/, 2];
624
+ case 11: return [2 /*return*/, null];
625
+ }
626
+ });
627
+ });
421
628
  };
422
629
  Interpretador.prototype.visitarExpressaoFazer = function (declaracao) {
423
- var retornoExecucao;
424
- do {
425
- try {
426
- retornoExecucao = this.executar(declaracao.caminhoFazer);
427
- }
428
- catch (erro) {
429
- throw erro;
430
- }
431
- } while (!(retornoExecucao instanceof quebras_1.Quebra) &&
432
- this.eVerdadeiro(this.avaliar(declaracao.condicaoEnquanto)));
630
+ return __awaiter(this, void 0, void 0, function () {
631
+ var retornoExecucao, erro_4, _a, _b;
632
+ return __generator(this, function (_c) {
633
+ switch (_c.label) {
634
+ case 0:
635
+ _c.trys.push([0, 2, , 3]);
636
+ return [4 /*yield*/, this.executar(declaracao.caminhoFazer)];
637
+ case 1:
638
+ retornoExecucao = _c.sent();
639
+ return [3 /*break*/, 3];
640
+ case 2:
641
+ erro_4 = _c.sent();
642
+ throw erro_4;
643
+ case 3:
644
+ _a = !(retornoExecucao instanceof quebras_1.Quebra);
645
+ if (!_a) return [3 /*break*/, 5];
646
+ _b = this.eVerdadeiro;
647
+ return [4 /*yield*/, this.avaliar(declaracao.condicaoEnquanto)];
648
+ case 4:
649
+ _a = _b.apply(this, [_c.sent()]);
650
+ _c.label = 5;
651
+ case 5:
652
+ if (_a) return [3 /*break*/, 0];
653
+ _c.label = 6;
654
+ case 6: return [2 /*return*/];
655
+ }
656
+ });
657
+ });
433
658
  };
434
659
  Interpretador.prototype.visitarExpressaoEscolha = function (declaracao) {
435
- var condicaoEscolha = this.avaliar(declaracao.identificadorOuLiteral);
436
- var caminhos = declaracao.caminhos;
437
- var caminhoPadrao = declaracao.caminhoPadrao;
438
- var encontrado = false;
439
- try {
440
- for (var i = 0; i < caminhos.length; i++) {
441
- var caminho_1 = caminhos[i];
442
- for (var j = 0; j < caminho_1.condicoes.length; j++) {
443
- if (this.avaliar(caminho_1.condicoes[j]) === condicaoEscolha) {
660
+ return __awaiter(this, void 0, void 0, function () {
661
+ var condicaoEscolha, caminhos, caminhoPadrao, encontrado, i, caminho_1, j, erro_5, erro_6;
662
+ return __generator(this, function (_a) {
663
+ switch (_a.label) {
664
+ case 0: return [4 /*yield*/, this.avaliar(declaracao.identificadorOuLiteral)];
665
+ case 1:
666
+ condicaoEscolha = _a.sent();
667
+ caminhos = declaracao.caminhos;
668
+ caminhoPadrao = declaracao.caminhoPadrao;
669
+ encontrado = false;
670
+ _a.label = 2;
671
+ case 2:
672
+ _a.trys.push([2, 14, , 15]);
673
+ i = 0;
674
+ _a.label = 3;
675
+ case 3:
676
+ if (!(i < caminhos.length)) return [3 /*break*/, 11];
677
+ caminho_1 = caminhos[i];
678
+ j = 0;
679
+ _a.label = 4;
680
+ case 4:
681
+ if (!(j < caminho_1.condicoes.length)) return [3 /*break*/, 10];
682
+ return [4 /*yield*/, this.avaliar(caminho_1.condicoes[j])];
683
+ case 5:
684
+ if (!((_a.sent()) === condicaoEscolha)) return [3 /*break*/, 9];
444
685
  encontrado = true;
445
- try {
446
- this.executarBloco(caminho_1.declaracoes);
447
- }
448
- catch (erro) {
449
- throw erro;
450
- }
451
- }
686
+ _a.label = 6;
687
+ case 6:
688
+ _a.trys.push([6, 8, , 9]);
689
+ return [4 /*yield*/, this.executarBloco(caminho_1.declaracoes)];
690
+ case 7:
691
+ _a.sent();
692
+ return [3 /*break*/, 9];
693
+ case 8:
694
+ erro_5 = _a.sent();
695
+ throw erro_5;
696
+ case 9:
697
+ j++;
698
+ return [3 /*break*/, 4];
699
+ case 10:
700
+ i++;
701
+ return [3 /*break*/, 3];
702
+ case 11:
703
+ if (!(caminhoPadrao !== null && encontrado === false)) return [3 /*break*/, 13];
704
+ return [4 /*yield*/, this.executarBloco(caminhoPadrao.declaracoes)];
705
+ case 12:
706
+ _a.sent();
707
+ _a.label = 13;
708
+ case 13: return [3 /*break*/, 15];
709
+ case 14:
710
+ erro_6 = _a.sent();
711
+ throw erro_6;
712
+ case 15: return [2 /*return*/];
452
713
  }
453
- }
454
- if (caminhoPadrao !== null && encontrado === false) {
455
- this.executarBloco(caminhoPadrao.declaracoes);
456
- }
457
- }
458
- catch (erro) {
459
- throw erro;
460
- }
714
+ });
715
+ });
461
716
  };
462
717
  Interpretador.prototype.visitarExpressaoTente = function (declaracao) {
463
- try {
464
- var sucesso = true;
465
- try {
466
- this.executarBloco(declaracao.caminhoTente);
467
- }
468
- catch (erro) {
469
- sucesso = false;
470
- if (declaracao.caminhoPegue !== null) {
471
- this.executarBloco(declaracao.caminhoPegue);
472
- }
473
- else {
474
- this.erros.push(erro);
718
+ return __awaiter(this, void 0, void 0, function () {
719
+ var sucesso, erro_7;
720
+ return __generator(this, function (_a) {
721
+ switch (_a.label) {
722
+ case 0:
723
+ _a.trys.push([0, , 10, 13]);
724
+ sucesso = true;
725
+ _a.label = 1;
726
+ case 1:
727
+ _a.trys.push([1, 3, , 7]);
728
+ return [4 /*yield*/, this.executarBloco(declaracao.caminhoTente)];
729
+ case 2:
730
+ _a.sent();
731
+ return [3 /*break*/, 7];
732
+ case 3:
733
+ erro_7 = _a.sent();
734
+ sucesso = false;
735
+ if (!(declaracao.caminhoPegue !== null)) return [3 /*break*/, 5];
736
+ return [4 /*yield*/, this.executarBloco(declaracao.caminhoPegue)];
737
+ case 4:
738
+ _a.sent();
739
+ return [3 /*break*/, 6];
740
+ case 5:
741
+ this.erros.push(erro_7);
742
+ _a.label = 6;
743
+ case 6: return [3 /*break*/, 7];
744
+ case 7:
745
+ if (!(sucesso && declaracao.caminhoSenao !== null)) return [3 /*break*/, 9];
746
+ return [4 /*yield*/, this.executarBloco(declaracao.caminhoSenao)];
747
+ case 8:
748
+ _a.sent();
749
+ _a.label = 9;
750
+ case 9: return [3 /*break*/, 13];
751
+ case 10:
752
+ if (!(declaracao.caminhoFinalmente !== null)) return [3 /*break*/, 12];
753
+ return [4 /*yield*/, this.executarBloco(declaracao.caminhoFinalmente)];
754
+ case 11:
755
+ _a.sent();
756
+ _a.label = 12;
757
+ case 12: return [7 /*endfinally*/];
758
+ case 13: return [2 /*return*/];
475
759
  }
476
- }
477
- if (sucesso && declaracao.caminhoSenao !== null) {
478
- this.executarBloco(declaracao.caminhoSenao);
479
- }
480
- }
481
- finally {
482
- if (declaracao.caminhoFinalmente !== null)
483
- this.executarBloco(declaracao.caminhoFinalmente);
484
- }
760
+ });
761
+ });
485
762
  };
486
763
  Interpretador.prototype.visitarExpressaoEnquanto = function (declaracao) {
487
- var retornoExecucao;
488
- while (!(retornoExecucao instanceof quebras_1.Quebra) &&
489
- this.eVerdadeiro(this.avaliar(declaracao.condicao))) {
490
- try {
491
- retornoExecucao = this.executar(declaracao.corpo);
492
- }
493
- catch (erro) {
494
- throw erro;
495
- }
496
- }
497
- return null;
764
+ return __awaiter(this, void 0, void 0, function () {
765
+ var retornoExecucao, _a, _b, erro_8;
766
+ return __generator(this, function (_c) {
767
+ switch (_c.label) {
768
+ case 0:
769
+ _a = !(retornoExecucao instanceof quebras_1.Quebra);
770
+ if (!_a) return [3 /*break*/, 2];
771
+ _b = this.eVerdadeiro;
772
+ return [4 /*yield*/, this.avaliar(declaracao.condicao)];
773
+ case 1:
774
+ _a = _b.apply(this, [_c.sent()]);
775
+ _c.label = 2;
776
+ case 2:
777
+ if (!_a) return [3 /*break*/, 7];
778
+ _c.label = 3;
779
+ case 3:
780
+ _c.trys.push([3, 5, , 6]);
781
+ return [4 /*yield*/, this.executar(declaracao.corpo)];
782
+ case 4:
783
+ retornoExecucao = _c.sent();
784
+ return [3 /*break*/, 6];
785
+ case 5:
786
+ erro_8 = _c.sent();
787
+ throw erro_8;
788
+ case 6: return [3 /*break*/, 0];
789
+ case 7: return [2 /*return*/, null];
790
+ }
791
+ });
792
+ });
498
793
  };
499
794
  Interpretador.prototype.visitarExpressaoImportar = function (declaracao) {
500
- var caminhoRelativo = this.avaliar(declaracao.caminho);
501
- var caminhoTotal = caminho.join(this.diretorioBase, caminhoRelativo);
502
- var nomeArquivo = caminho.basename(caminhoTotal);
503
- if (!caminhoTotal.endsWith('.egua') &&
504
- !caminhoTotal.endsWith('.delegua')) {
505
- try {
506
- return (0, importar_biblioteca_1.default)(caminhoRelativo);
507
- }
508
- catch (erro) {
509
- this.erros.push(erro);
510
- return null;
511
- }
512
- }
513
- var conteudoImportacao = this.importador.importar(caminhoRelativo);
514
- var retornoInterpretador = this.interpretar(conteudoImportacao.retornoAvaliadorSintatico.declaracoes, true);
515
- var funcoesChamaveis = this.pilhaEscoposExecucao.obterTodasDeleguaFuncao();
516
- var eDicionario = function (objeto) { return objeto.constructor === Object; };
517
- if (eDicionario(funcoesChamaveis)) {
518
- var novoModulo = new estruturas_1.DeleguaModulo();
519
- var chaves = Object.keys(funcoesChamaveis);
520
- for (var i = 0; i < chaves.length; i++) {
521
- novoModulo.componentes[chaves[i]] = funcoesChamaveis[chaves[i]];
522
- }
523
- return novoModulo;
524
- }
525
- return funcoesChamaveis;
795
+ return __awaiter(this, void 0, void 0, function () {
796
+ var caminhoRelativo, caminhoTotal, nomeArquivo, conteudoImportacao, retornoInterpretador, funcoesChamaveis, eDicionario, novoModulo, chaves, i;
797
+ return __generator(this, function (_a) {
798
+ switch (_a.label) {
799
+ case 0: return [4 /*yield*/, this.avaliar(declaracao.caminho)];
800
+ case 1:
801
+ caminhoRelativo = _a.sent();
802
+ caminhoTotal = caminho.join(this.diretorioBase, caminhoRelativo);
803
+ nomeArquivo = caminho.basename(caminhoTotal);
804
+ if (!caminhoTotal.endsWith('.egua') &&
805
+ !caminhoTotal.endsWith('.delegua')) {
806
+ try {
807
+ return [2 /*return*/, (0, importar_biblioteca_1.default)(caminhoRelativo)];
808
+ }
809
+ catch (erro) {
810
+ this.erros.push(erro);
811
+ return [2 /*return*/, null];
812
+ }
813
+ }
814
+ conteudoImportacao = this.importador.importar(caminhoRelativo);
815
+ retornoInterpretador = this.interpretar(conteudoImportacao.retornoAvaliadorSintatico.declaracoes, true);
816
+ funcoesChamaveis = this.pilhaEscoposExecucao.obterTodasDeleguaFuncao();
817
+ eDicionario = function (objeto) { return objeto.constructor === Object; };
818
+ if (eDicionario(funcoesChamaveis)) {
819
+ novoModulo = new estruturas_1.DeleguaModulo();
820
+ chaves = Object.keys(funcoesChamaveis);
821
+ for (i = 0; i < chaves.length; i++) {
822
+ novoModulo.componentes[chaves[i]] = funcoesChamaveis[chaves[i]];
823
+ }
824
+ return [2 /*return*/, novoModulo];
825
+ }
826
+ return [2 /*return*/, funcoesChamaveis];
827
+ }
828
+ });
829
+ });
526
830
  };
527
831
  /**
528
832
  * Execução de uma escrita na saída configurada, que pode ser `console` (padrão) ou
@@ -531,24 +835,42 @@ var Interpretador = /** @class */ (function () {
531
835
  * @returns Sempre nulo, por convenção de visita.
532
836
  */
533
837
  Interpretador.prototype.visitarExpressaoEscreva = function (declaracao) {
534
- try {
535
- var valor = void 0;
536
- for (var _i = 0, _a = declaracao.argumentos; _i < _a.length; _i++) {
537
- var argumento = _a[_i];
538
- var resultadoAvaliacao = this.avaliar(argumento);
539
- valor = (resultadoAvaliacao === null || resultadoAvaliacao === void 0 ? void 0 : resultadoAvaliacao.hasOwnProperty('valor'))
540
- ? resultadoAvaliacao.valor
541
- : resultadoAvaliacao;
542
- }
543
- var formatoTexto = this.paraTexto(valor);
544
- // Por enquanto `escreva` não devolve resultado no interpretador.
545
- // this.resultadoInterpretador.push(formatoTexto);
546
- this.funcaoDeRetorno(formatoTexto);
547
- return null;
548
- }
549
- catch (erro) {
550
- this.erros.push(erro);
551
- }
838
+ return __awaiter(this, void 0, void 0, function () {
839
+ var valor, _i, _a, argumento, resultadoAvaliacao, formatoTexto, erro_9;
840
+ return __generator(this, function (_b) {
841
+ switch (_b.label) {
842
+ case 0:
843
+ _b.trys.push([0, 5, , 6]);
844
+ valor = void 0;
845
+ _i = 0, _a = declaracao.argumentos;
846
+ _b.label = 1;
847
+ case 1:
848
+ if (!(_i < _a.length)) return [3 /*break*/, 4];
849
+ argumento = _a[_i];
850
+ return [4 /*yield*/, this.avaliar(argumento)];
851
+ case 2:
852
+ resultadoAvaliacao = _b.sent();
853
+ valor = (resultadoAvaliacao === null || resultadoAvaliacao === void 0 ? void 0 : resultadoAvaliacao.hasOwnProperty('valor'))
854
+ ? resultadoAvaliacao.valor
855
+ : resultadoAvaliacao;
856
+ _b.label = 3;
857
+ case 3:
858
+ _i++;
859
+ return [3 /*break*/, 1];
860
+ case 4:
861
+ formatoTexto = this.paraTexto(valor);
862
+ // Por enquanto `escreva` não devolve resultado no interpretador.
863
+ // this.resultadoInterpretador.push(formatoTexto);
864
+ this.funcaoDeRetorno(formatoTexto);
865
+ return [2 /*return*/, null];
866
+ case 5:
867
+ erro_9 = _b.sent();
868
+ this.erros.push(erro_9);
869
+ return [3 /*break*/, 6];
870
+ case 6: return [2 /*return*/];
871
+ }
872
+ });
873
+ });
552
874
  };
553
875
  /**
554
876
  * Empilha declarações na pilha de escopos de execução, cria um novo ambiente e
@@ -560,20 +882,37 @@ var Interpretador = /** @class */ (function () {
560
882
  * @param ambiente O ambiente de execução quando houver, como parâmetros, argumentos, etc.
561
883
  */
562
884
  Interpretador.prototype.executarBloco = function (declaracoes, ambiente) {
563
- var escopoExecucao = {
564
- declaracoes: declaracoes,
565
- declaracaoAtual: 0,
566
- ambiente: ambiente || new espaco_variaveis_1.EspacoVariaveis(),
567
- };
568
- this.pilhaEscoposExecucao.empilhar(escopoExecucao);
569
- var retornoUltimoEscopo = this.executarUltimoEscopo();
570
- if (retornoUltimoEscopo instanceof excecoes_1.ErroEmTempoDeExecucao) {
571
- throw retornoUltimoEscopo;
572
- }
573
- return retornoUltimoEscopo;
885
+ return __awaiter(this, void 0, void 0, function () {
886
+ var escopoExecucao, retornoUltimoEscopo;
887
+ return __generator(this, function (_a) {
888
+ switch (_a.label) {
889
+ case 0:
890
+ escopoExecucao = {
891
+ declaracoes: declaracoes,
892
+ declaracaoAtual: 0,
893
+ ambiente: ambiente || new espaco_variaveis_1.EspacoVariaveis(),
894
+ };
895
+ this.pilhaEscoposExecucao.empilhar(escopoExecucao);
896
+ return [4 /*yield*/, this.executarUltimoEscopo()];
897
+ case 1:
898
+ retornoUltimoEscopo = _a.sent();
899
+ if (retornoUltimoEscopo instanceof excecoes_1.ErroEmTempoDeExecucao) {
900
+ throw retornoUltimoEscopo;
901
+ }
902
+ return [2 /*return*/, retornoUltimoEscopo];
903
+ }
904
+ });
905
+ });
574
906
  };
575
907
  Interpretador.prototype.visitarExpressaoBloco = function (declaracao) {
576
- return this.executarBloco(declaracao.declaracoes);
908
+ return __awaiter(this, void 0, void 0, function () {
909
+ return __generator(this, function (_a) {
910
+ switch (_a.label) {
911
+ case 0: return [4 /*yield*/, this.executarBloco(declaracao.declaracoes)];
912
+ case 1: return [2 /*return*/, _a.sent()];
913
+ }
914
+ });
915
+ });
577
916
  };
578
917
  /**
579
918
  * Executa expressão de definição de variável.
@@ -581,12 +920,25 @@ var Interpretador = /** @class */ (function () {
581
920
  * @returns Sempre retorna nulo.
582
921
  */
583
922
  Interpretador.prototype.visitarExpressaoVar = function (declaracao) {
584
- var valorOuOutraVariavel = null;
585
- if (declaracao.inicializador !== null) {
586
- valorOuOutraVariavel = this.avaliar(declaracao.inicializador);
587
- }
588
- this.pilhaEscoposExecucao.definirVariavel(declaracao.simbolo.lexema, valorOuOutraVariavel.hasOwnProperty('valor') ? valorOuOutraVariavel.valor : valorOuOutraVariavel);
589
- return null;
923
+ return __awaiter(this, void 0, void 0, function () {
924
+ var valorOuOutraVariavel;
925
+ return __generator(this, function (_a) {
926
+ switch (_a.label) {
927
+ case 0:
928
+ valorOuOutraVariavel = null;
929
+ if (!(declaracao.inicializador !== null)) return [3 /*break*/, 2];
930
+ return [4 /*yield*/, this.avaliar(declaracao.inicializador)];
931
+ case 1:
932
+ valorOuOutraVariavel = _a.sent();
933
+ _a.label = 2;
934
+ case 2:
935
+ this.pilhaEscoposExecucao.definirVariavel(declaracao.simbolo.lexema, valorOuOutraVariavel.hasOwnProperty('valor')
936
+ ? valorOuOutraVariavel.valor
937
+ : valorOuOutraVariavel);
938
+ return [2 /*return*/, null];
939
+ }
940
+ });
941
+ });
590
942
  };
591
943
  Interpretador.prototype.visitarExpressaoContinua = function (declaracao) {
592
944
  return new quebras_1.ContinuarQuebra();
@@ -595,99 +947,150 @@ var Interpretador = /** @class */ (function () {
595
947
  return new quebras_1.SustarQuebra();
596
948
  };
597
949
  Interpretador.prototype.visitarExpressaoRetornar = function (declaracao) {
598
- var valor = null;
599
- if (declaracao.valor != null)
600
- valor = this.avaliar(declaracao.valor);
601
- return new quebras_1.RetornoQuebra(valor);
950
+ return __awaiter(this, void 0, void 0, function () {
951
+ var valor;
952
+ return __generator(this, function (_a) {
953
+ switch (_a.label) {
954
+ case 0:
955
+ valor = null;
956
+ if (!(declaracao.valor != null)) return [3 /*break*/, 2];
957
+ return [4 /*yield*/, this.avaliar(declaracao.valor)];
958
+ case 1:
959
+ valor = _a.sent();
960
+ _a.label = 2;
961
+ case 2: return [2 /*return*/, new quebras_1.RetornoQuebra(valor)];
962
+ }
963
+ });
964
+ });
602
965
  };
603
966
  Interpretador.prototype.visitarExpressaoDeleguaFuncao = function (expressao) {
604
967
  return new estruturas_1.DeleguaFuncao(null, expressao);
605
968
  };
606
969
  Interpretador.prototype.visitarExpressaoAtribuicaoSobrescrita = function (expressao) {
607
- var objeto = this.avaliar(expressao.objeto);
608
- var indice = this.avaliar(expressao.indice);
609
- var valor = this.avaliar(expressao.valor);
610
- if (Array.isArray(objeto)) {
611
- if (indice < 0 && objeto.length !== 0) {
612
- while (indice < 0) {
613
- indice += objeto.length;
970
+ return __awaiter(this, void 0, void 0, function () {
971
+ var promises, objeto, indice, valor;
972
+ return __generator(this, function (_a) {
973
+ switch (_a.label) {
974
+ case 0: return [4 /*yield*/, Promise.all([
975
+ this.avaliar(expressao.objeto),
976
+ this.avaliar(expressao.indice),
977
+ this.avaliar(expressao.valor)
978
+ ])];
979
+ case 1:
980
+ promises = _a.sent();
981
+ objeto = promises[0];
982
+ indice = promises[1];
983
+ valor = promises[2];
984
+ if (Array.isArray(objeto)) {
985
+ if (indice < 0 && objeto.length !== 0) {
986
+ while (indice < 0) {
987
+ indice += objeto.length;
988
+ }
989
+ }
990
+ while (objeto.length < indice) {
991
+ objeto.push(null);
992
+ }
993
+ objeto[indice] = valor;
994
+ }
995
+ else if (objeto.constructor === Object ||
996
+ objeto instanceof estruturas_1.ObjetoDeleguaClasse ||
997
+ objeto instanceof estruturas_1.DeleguaFuncao ||
998
+ objeto instanceof estruturas_1.DeleguaClasse ||
999
+ objeto instanceof estruturas_1.DeleguaModulo) {
1000
+ objeto[indice] = valor;
1001
+ }
1002
+ else {
1003
+ throw new excecoes_1.ErroEmTempoDeExecucao(expressao.objeto.nome, 'Somente listas, dicionários, classes e objetos podem ser mudados por sobrescrita.', expressao.linha);
1004
+ }
1005
+ return [2 /*return*/];
614
1006
  }
615
- }
616
- while (objeto.length < indice) {
617
- objeto.push(null);
618
- }
619
- objeto[indice] = valor;
620
- }
621
- else if (objeto.constructor === Object ||
622
- objeto instanceof estruturas_1.ObjetoDeleguaClasse ||
623
- objeto instanceof estruturas_1.DeleguaFuncao ||
624
- objeto instanceof estruturas_1.DeleguaClasse ||
625
- objeto instanceof estruturas_1.DeleguaModulo) {
626
- objeto[indice] = valor;
627
- }
628
- else {
629
- throw new excecoes_1.ErroEmTempoDeExecucao(expressao.objeto.nome, 'Somente listas, dicionários, classes e objetos podem ser mudados por sobrescrita.', expressao.linha);
630
- }
1007
+ });
1008
+ });
631
1009
  };
632
1010
  Interpretador.prototype.visitarExpressaoAcessoIndiceVariavel = function (expressao) {
633
- var variavelObjeto = this.avaliar(expressao.entidadeChamada);
634
- var objeto = variavelObjeto.hasOwnProperty('valor')
635
- ? variavelObjeto.valor
636
- : variavelObjeto;
637
- var indice = this.avaliar(expressao.indice);
638
- if (Array.isArray(objeto)) {
639
- if (!Number.isInteger(indice)) {
640
- throw new excecoes_1.ErroEmTempoDeExecucao(expressao.simboloFechamento, 'Somente inteiros podem ser usados para indexar um vetor.', expressao.linha);
641
- }
642
- if (indice < 0 && objeto.length !== 0) {
643
- while (indice < 0) {
644
- indice += objeto.length;
645
- }
646
- }
647
- if (indice >= objeto.length) {
648
- throw new excecoes_1.ErroEmTempoDeExecucao(expressao.simboloFechamento, 'Índice do vetor fora do intervalo.', expressao.linha);
649
- }
650
- return objeto[indice];
651
- }
652
- else if (objeto.constructor === Object ||
653
- objeto instanceof estruturas_1.ObjetoDeleguaClasse ||
654
- objeto instanceof estruturas_1.DeleguaFuncao ||
655
- objeto instanceof estruturas_1.DeleguaClasse ||
656
- objeto instanceof estruturas_1.DeleguaModulo) {
657
- return objeto[indice] || null;
658
- }
659
- else if (typeof objeto === 'string') {
660
- if (!Number.isInteger(indice)) {
661
- throw new excecoes_1.ErroEmTempoDeExecucao(expressao.simboloFechamento, 'Somente inteiros podem ser usados para indexar um vetor.', expressao.linha);
662
- }
663
- if (indice < 0 && objeto.length !== 0) {
664
- while (indice < 0) {
665
- indice += objeto.length;
1011
+ return __awaiter(this, void 0, void 0, function () {
1012
+ var variavelObjeto, objeto, indice, valorIndice;
1013
+ return __generator(this, function (_a) {
1014
+ switch (_a.label) {
1015
+ case 0: return [4 /*yield*/, this.avaliar(expressao.entidadeChamada)];
1016
+ case 1:
1017
+ variavelObjeto = _a.sent();
1018
+ objeto = variavelObjeto.hasOwnProperty('valor')
1019
+ ? variavelObjeto.valor
1020
+ : variavelObjeto;
1021
+ return [4 /*yield*/, this.avaliar(expressao.indice)];
1022
+ case 2:
1023
+ indice = _a.sent();
1024
+ valorIndice = indice.hasOwnProperty('valor') ? indice.valor : indice;
1025
+ if (Array.isArray(objeto)) {
1026
+ if (!Number.isInteger(valorIndice)) {
1027
+ throw new excecoes_1.ErroEmTempoDeExecucao(expressao.simboloFechamento, 'Somente inteiros podem ser usados para indexar um vetor.', expressao.linha);
1028
+ }
1029
+ if (valorIndice < 0 && objeto.length !== 0) {
1030
+ while (valorIndice < 0) {
1031
+ valorIndice += objeto.length;
1032
+ }
1033
+ }
1034
+ if (valorIndice >= objeto.length) {
1035
+ throw new excecoes_1.ErroEmTempoDeExecucao(expressao.simboloFechamento, 'Índice do vetor fora do intervalo.', expressao.linha);
1036
+ }
1037
+ return [2 /*return*/, objeto[valorIndice]];
1038
+ }
1039
+ else if (objeto.constructor === Object ||
1040
+ objeto instanceof estruturas_1.ObjetoDeleguaClasse ||
1041
+ objeto instanceof estruturas_1.DeleguaFuncao ||
1042
+ objeto instanceof estruturas_1.DeleguaClasse ||
1043
+ objeto instanceof estruturas_1.DeleguaModulo) {
1044
+ return [2 /*return*/, objeto[valorIndice] || null];
1045
+ }
1046
+ else if (typeof objeto === 'string') {
1047
+ if (!Number.isInteger(valorIndice)) {
1048
+ throw new excecoes_1.ErroEmTempoDeExecucao(expressao.simboloFechamento, 'Somente inteiros podem ser usados para indexar um vetor.', expressao.linha);
1049
+ }
1050
+ if (valorIndice < 0 && objeto.length !== 0) {
1051
+ while (valorIndice < 0) {
1052
+ valorIndice += objeto.length;
1053
+ }
1054
+ }
1055
+ if (valorIndice >= objeto.length) {
1056
+ throw new excecoes_1.ErroEmTempoDeExecucao(expressao.simboloFechamento, 'Índice fora do tamanho.', expressao.linha);
1057
+ }
1058
+ return [2 /*return*/, objeto.charAt(valorIndice)];
1059
+ }
1060
+ else {
1061
+ throw new excecoes_1.ErroEmTempoDeExecucao(expressao.entidadeChamada.nome, 'Somente listas, dicionários, classes e objetos podem ser mudados por sobrescrita.', expressao.linha);
1062
+ }
1063
+ return [2 /*return*/];
666
1064
  }
667
- }
668
- if (indice >= objeto.length) {
669
- throw new excecoes_1.ErroEmTempoDeExecucao(expressao.simboloFechamento, 'Índice fora do tamanho.', expressao.linha);
670
- }
671
- return objeto.charAt(indice);
672
- }
673
- else {
674
- throw new excecoes_1.ErroEmTempoDeExecucao(expressao.entidadeChamada.nome, 'Somente listas, dicionários, classes e objetos podem ser mudados por sobrescrita.', expressao.linha);
675
- }
1065
+ });
1066
+ });
676
1067
  };
677
1068
  Interpretador.prototype.visitarExpressaoDefinir = function (expressao) {
678
- var objeto = this.avaliar(expressao.objeto);
679
- if (!(objeto instanceof estruturas_1.ObjetoDeleguaClasse) &&
680
- objeto.constructor !== Object) {
681
- throw new excecoes_1.ErroEmTempoDeExecucao(expressao.objeto.nome, 'Somente instâncias e dicionários podem possuir campos.', expressao.linha);
682
- }
683
- var valor = this.avaliar(expressao.valor);
684
- if (objeto instanceof estruturas_1.ObjetoDeleguaClasse) {
685
- objeto.set(expressao.nome, valor);
686
- return valor;
687
- }
688
- else if (objeto.constructor === Object) {
689
- objeto[expressao.simbolo.lexema] = valor;
690
- }
1069
+ return __awaiter(this, void 0, void 0, function () {
1070
+ var objeto, valor;
1071
+ return __generator(this, function (_a) {
1072
+ switch (_a.label) {
1073
+ case 0: return [4 /*yield*/, this.avaliar(expressao.objeto)];
1074
+ case 1:
1075
+ objeto = _a.sent();
1076
+ if (!(objeto instanceof estruturas_1.ObjetoDeleguaClasse) &&
1077
+ objeto.constructor !== Object) {
1078
+ throw new excecoes_1.ErroEmTempoDeExecucao(expressao.objeto.nome, 'Somente instâncias e dicionários podem possuir campos.', expressao.linha);
1079
+ }
1080
+ return [4 /*yield*/, this.avaliar(expressao.valor)];
1081
+ case 2:
1082
+ valor = _a.sent();
1083
+ if (objeto instanceof estruturas_1.ObjetoDeleguaClasse) {
1084
+ objeto.set(expressao.nome, valor);
1085
+ return [2 /*return*/, valor];
1086
+ }
1087
+ else if (objeto.constructor === Object) {
1088
+ objeto[expressao.simbolo.lexema] = valor;
1089
+ }
1090
+ return [2 /*return*/];
1091
+ }
1092
+ });
1093
+ });
691
1094
  };
692
1095
  Interpretador.prototype.visitarExpressaoFuncao = function (declaracao) {
693
1096
  var funcao = new estruturas_1.DeleguaFuncao(declaracao.simbolo.lexema, declaracao.funcao);
@@ -699,33 +1102,44 @@ var Interpretador = /** @class */ (function () {
699
1102
  * @returns Sempre retorna nulo, por ser requerido pelo contrato de visita.
700
1103
  */
701
1104
  Interpretador.prototype.visitarExpressaoClasse = function (declaracao) {
702
- var superClasse = null;
703
- if (declaracao.superClasse !== null) {
704
- var variavelSuperClasse = this.avaliar(declaracao.superClasse);
705
- superClasse = variavelSuperClasse.valor;
706
- if (!(superClasse instanceof estruturas_1.DeleguaClasse)) {
707
- throw new excecoes_1.ErroEmTempoDeExecucao(declaracao.superClasse.nome, 'SuperClasse precisa ser uma classe.', declaracao.linha);
708
- }
709
- }
710
- this.pilhaEscoposExecucao.definirVariavel(declaracao.simbolo.lexema, null);
711
- if (declaracao.superClasse !== null) {
712
- this.pilhaEscoposExecucao.definirVariavel('super', superClasse);
713
- }
714
- var metodos = {};
715
- var definirMetodos = declaracao.metodos;
716
- for (var i = 0; i < declaracao.metodos.length; i++) {
717
- var metodoAtual = definirMetodos[i];
718
- var eInicializador = metodoAtual.simbolo.lexema === 'construtor';
719
- var funcao = new estruturas_1.DeleguaFuncao(metodoAtual.simbolo.lexema, metodoAtual.funcao, undefined, eInicializador);
720
- metodos[metodoAtual.simbolo.lexema] = funcao;
721
- }
722
- var deleguaClasse = new estruturas_1.DeleguaClasse(declaracao.simbolo.lexema, superClasse, metodos);
723
- // TODO: Recolocar isso se for necessário.
724
- /* if (superClasse !== null) {
725
- this.ambiente = this.ambiente.enclosing;
726
- } */
727
- this.pilhaEscoposExecucao.atribuirVariavel(declaracao.simbolo, deleguaClasse);
728
- return null;
1105
+ return __awaiter(this, void 0, void 0, function () {
1106
+ var superClasse, variavelSuperClasse, metodos, definirMetodos, i, metodoAtual, eInicializador, funcao, deleguaClasse;
1107
+ return __generator(this, function (_a) {
1108
+ switch (_a.label) {
1109
+ case 0:
1110
+ superClasse = null;
1111
+ if (!(declaracao.superClasse !== null)) return [3 /*break*/, 2];
1112
+ return [4 /*yield*/, this.avaliar(declaracao.superClasse)];
1113
+ case 1:
1114
+ variavelSuperClasse = _a.sent();
1115
+ superClasse = variavelSuperClasse.valor;
1116
+ if (!(superClasse instanceof estruturas_1.DeleguaClasse)) {
1117
+ throw new excecoes_1.ErroEmTempoDeExecucao(declaracao.superClasse.nome, 'SuperClasse precisa ser uma classe.', declaracao.linha);
1118
+ }
1119
+ _a.label = 2;
1120
+ case 2:
1121
+ this.pilhaEscoposExecucao.definirVariavel(declaracao.simbolo.lexema, null);
1122
+ if (declaracao.superClasse !== null) {
1123
+ this.pilhaEscoposExecucao.definirVariavel('super', superClasse);
1124
+ }
1125
+ metodos = {};
1126
+ definirMetodos = declaracao.metodos;
1127
+ for (i = 0; i < declaracao.metodos.length; i++) {
1128
+ metodoAtual = definirMetodos[i];
1129
+ eInicializador = metodoAtual.simbolo.lexema === 'construtor';
1130
+ funcao = new estruturas_1.DeleguaFuncao(metodoAtual.simbolo.lexema, metodoAtual.funcao, undefined, eInicializador);
1131
+ metodos[metodoAtual.simbolo.lexema] = funcao;
1132
+ }
1133
+ deleguaClasse = new estruturas_1.DeleguaClasse(declaracao.simbolo.lexema, superClasse, metodos);
1134
+ // TODO: Recolocar isso se for necessário.
1135
+ /* if (superClasse !== null) {
1136
+ this.ambiente = this.ambiente.enclosing;
1137
+ } */
1138
+ this.pilhaEscoposExecucao.atribuirVariavel(declaracao.simbolo, deleguaClasse);
1139
+ return [2 /*return*/, null];
1140
+ }
1141
+ });
1142
+ });
729
1143
  };
730
1144
  /**
731
1145
  * Executa um acesso a método, normalmente de um objeto de classe.
@@ -733,49 +1147,95 @@ var Interpretador = /** @class */ (function () {
733
1147
  * @returns O resultado da execução.
734
1148
  */
735
1149
  Interpretador.prototype.visitarExpressaoAcessoMetodo = function (expressao) {
736
- var variavelObjeto = this.avaliar(expressao.objeto);
737
- var objeto = variavelObjeto === null || variavelObjeto === void 0 ? void 0 : variavelObjeto.valor;
738
- if (objeto instanceof estruturas_1.ObjetoDeleguaClasse) {
739
- return objeto.get(expressao.simbolo) || null;
740
- }
741
- if (objeto.constructor === Object) {
742
- return objeto[expressao.simbolo.lexema] || null;
743
- }
744
- if (objeto instanceof estruturas_1.DeleguaModulo) {
745
- return objeto.componentes[expressao.simbolo.lexema] || null;
746
- }
747
- switch (variavelObjeto.tipo) {
748
- case 'texto':
749
- var metodoDePrimitivaTexto = primitivas_texto_1.default[expressao.simbolo.lexema];
750
- if (metodoDePrimitivaTexto) {
751
- return new metodo_primitiva_1.MetodoPrimitiva(objeto, metodoDePrimitivaTexto);
752
- }
753
- break;
754
- case 'vetor':
755
- var metodoDePrimitivaVetor = primitivas_vetor_1.default[expressao.simbolo.lexema];
756
- if (metodoDePrimitivaVetor) {
757
- return new metodo_primitiva_1.MetodoPrimitiva(objeto, metodoDePrimitivaVetor);
1150
+ return __awaiter(this, void 0, void 0, function () {
1151
+ var variavelObjeto, objeto, metodoDePrimitivaTexto, metodoDePrimitivaVetor;
1152
+ return __generator(this, function (_a) {
1153
+ switch (_a.label) {
1154
+ case 0: return [4 /*yield*/, this.avaliar(expressao.objeto)];
1155
+ case 1:
1156
+ variavelObjeto = _a.sent();
1157
+ objeto = variavelObjeto === null || variavelObjeto === void 0 ? void 0 : variavelObjeto.valor;
1158
+ if (objeto instanceof estruturas_1.ObjetoDeleguaClasse) {
1159
+ return [2 /*return*/, objeto.get(expressao.simbolo) || null];
1160
+ }
1161
+ if (objeto.constructor === Object) {
1162
+ return [2 /*return*/, objeto[expressao.simbolo.lexema] || null];
1163
+ }
1164
+ if (objeto instanceof estruturas_1.DeleguaModulo) {
1165
+ return [2 /*return*/, objeto.componentes[expressao.simbolo.lexema] || null];
1166
+ }
1167
+ switch (variavelObjeto.tipo) {
1168
+ case 'texto':
1169
+ metodoDePrimitivaTexto = primitivas_texto_1.default[expressao.simbolo.lexema];
1170
+ if (metodoDePrimitivaTexto) {
1171
+ return [2 /*return*/, new metodo_primitiva_1.MetodoPrimitiva(objeto, metodoDePrimitivaTexto)];
1172
+ }
1173
+ break;
1174
+ case 'vetor':
1175
+ metodoDePrimitivaVetor = primitivas_vetor_1.default[expressao.simbolo.lexema];
1176
+ if (metodoDePrimitivaVetor) {
1177
+ return [2 /*return*/, new metodo_primitiva_1.MetodoPrimitiva(objeto, metodoDePrimitivaVetor)];
1178
+ }
1179
+ break;
1180
+ }
1181
+ throw new excecoes_1.ErroEmTempoDeExecucao(expressao.nome, 'Você só pode acessar métodos do objeto e dicionários.', expressao.linha);
758
1182
  }
759
- break;
760
- }
761
- throw new excecoes_1.ErroEmTempoDeExecucao(expressao.nome, 'Você só pode acessar métodos do objeto e dicionários.', expressao.linha);
1183
+ });
1184
+ });
762
1185
  };
763
1186
  Interpretador.prototype.visitarExpressaoIsto = function (expressao) {
764
1187
  return this.procurarVariavel(expressao.palavraChave);
765
1188
  };
766
1189
  Interpretador.prototype.visitarExpressaoDicionario = function (expressao) {
767
- var dicionario = {};
768
- for (var i = 0; i < expressao.chaves.length; i++) {
769
- dicionario[this.avaliar(expressao.chaves[i])] = this.avaliar(expressao.valores[i]);
770
- }
771
- return dicionario;
1190
+ return __awaiter(this, void 0, void 0, function () {
1191
+ var dicionario, i, promises;
1192
+ return __generator(this, function (_a) {
1193
+ switch (_a.label) {
1194
+ case 0:
1195
+ dicionario = {};
1196
+ i = 0;
1197
+ _a.label = 1;
1198
+ case 1:
1199
+ if (!(i < expressao.chaves.length)) return [3 /*break*/, 4];
1200
+ return [4 /*yield*/, Promise.all([
1201
+ this.avaliar(expressao.chaves[i]),
1202
+ this.avaliar(expressao.valores[i])
1203
+ ])];
1204
+ case 2:
1205
+ promises = _a.sent();
1206
+ dicionario[promises[0]] = promises[1];
1207
+ _a.label = 3;
1208
+ case 3:
1209
+ i++;
1210
+ return [3 /*break*/, 1];
1211
+ case 4: return [2 /*return*/, dicionario];
1212
+ }
1213
+ });
1214
+ });
772
1215
  };
773
1216
  Interpretador.prototype.visitarExpressaoVetor = function (expressao) {
774
- var valores = [];
775
- for (var i = 0; i < expressao.valores.length; i++) {
776
- valores.push(this.avaliar(expressao.valores[i]));
777
- }
778
- return valores;
1217
+ return __awaiter(this, void 0, void 0, function () {
1218
+ var valores, i, _a, _b;
1219
+ return __generator(this, function (_c) {
1220
+ switch (_c.label) {
1221
+ case 0:
1222
+ valores = [];
1223
+ i = 0;
1224
+ _c.label = 1;
1225
+ case 1:
1226
+ if (!(i < expressao.valores.length)) return [3 /*break*/, 4];
1227
+ _b = (_a = valores).push;
1228
+ return [4 /*yield*/, this.avaliar(expressao.valores[i])];
1229
+ case 2:
1230
+ _b.apply(_a, [_c.sent()]);
1231
+ _c.label = 3;
1232
+ case 3:
1233
+ i++;
1234
+ return [3 /*break*/, 1];
1235
+ case 4: return [2 /*return*/, valores];
1236
+ }
1237
+ });
1238
+ });
779
1239
  };
780
1240
  // TODO: Após remoção do Resolvedor, simular casos que usem 'super' e 'isto'.
781
1241
  Interpretador.prototype.visitarExpressaoSuper = function (expressao) {
@@ -816,14 +1276,23 @@ var Interpretador = /** @class */ (function () {
816
1276
  */
817
1277
  Interpretador.prototype.executar = function (declaracao, mostrarResultado) {
818
1278
  if (mostrarResultado === void 0) { mostrarResultado = false; }
819
- var resultado = declaracao.aceitar(this);
820
- if (mostrarResultado) {
821
- this.funcaoDeRetorno(this.paraTexto(resultado));
822
- }
823
- if (resultado || typeof resultado === 'boolean') {
824
- this.resultadoInterpretador.push(this.paraTexto(resultado));
825
- }
826
- return resultado;
1279
+ return __awaiter(this, void 0, void 0, function () {
1280
+ var resultado;
1281
+ return __generator(this, function (_a) {
1282
+ switch (_a.label) {
1283
+ case 0: return [4 /*yield*/, declaracao.aceitar(this)];
1284
+ case 1:
1285
+ resultado = _a.sent();
1286
+ if (mostrarResultado) {
1287
+ this.funcaoDeRetorno(this.paraTexto(resultado));
1288
+ }
1289
+ if (resultado || typeof resultado === 'boolean') {
1290
+ this.resultadoInterpretador.push(this.paraTexto(resultado));
1291
+ }
1292
+ return [2 /*return*/, resultado];
1293
+ }
1294
+ });
1295
+ });
827
1296
  };
828
1297
  /**
829
1298
  * Executa o último escopo empilhado no topo na pilha de escopos do interpretador.
@@ -837,25 +1306,42 @@ var Interpretador = /** @class */ (function () {
837
1306
  */
838
1307
  Interpretador.prototype.executarUltimoEscopo = function (manterAmbiente) {
839
1308
  if (manterAmbiente === void 0) { manterAmbiente = false; }
840
- var ultimoEscopo = this.pilhaEscoposExecucao.topoDaPilha();
841
- try {
842
- var retornoExecucao = void 0;
843
- for (; !(retornoExecucao instanceof quebras_1.Quebra) &&
844
- ultimoEscopo.declaracaoAtual < ultimoEscopo.declaracoes.length; ultimoEscopo.declaracaoAtual++) {
845
- retornoExecucao = this.executar(ultimoEscopo.declaracoes[ultimoEscopo.declaracaoAtual]);
846
- }
847
- return retornoExecucao;
848
- }
849
- catch (erro) {
850
- return erro;
851
- }
852
- finally {
853
- this.pilhaEscoposExecucao.removerUltimo();
854
- if (manterAmbiente) {
855
- var escopoAnterior = this.pilhaEscoposExecucao.topoDaPilha();
856
- escopoAnterior.ambiente.valores = Object.assign(escopoAnterior.ambiente.valores, ultimoEscopo.ambiente.valores);
857
- }
858
- }
1309
+ return __awaiter(this, void 0, void 0, function () {
1310
+ var ultimoEscopo, retornoExecucao, erro_10, escopoAnterior;
1311
+ return __generator(this, function (_a) {
1312
+ switch (_a.label) {
1313
+ case 0:
1314
+ ultimoEscopo = this.pilhaEscoposExecucao.topoDaPilha();
1315
+ _a.label = 1;
1316
+ case 1:
1317
+ _a.trys.push([1, 6, 7, 8]);
1318
+ retornoExecucao = void 0;
1319
+ _a.label = 2;
1320
+ case 2:
1321
+ if (!(!(retornoExecucao instanceof quebras_1.Quebra) &&
1322
+ ultimoEscopo.declaracaoAtual < ultimoEscopo.declaracoes.length)) return [3 /*break*/, 5];
1323
+ return [4 /*yield*/, this.executar(ultimoEscopo.declaracoes[ultimoEscopo.declaracaoAtual])];
1324
+ case 3:
1325
+ retornoExecucao = _a.sent();
1326
+ _a.label = 4;
1327
+ case 4:
1328
+ ultimoEscopo.declaracaoAtual++;
1329
+ return [3 /*break*/, 2];
1330
+ case 5: return [2 /*return*/, retornoExecucao];
1331
+ case 6:
1332
+ erro_10 = _a.sent();
1333
+ return [2 /*return*/, Promise.reject(erro_10)];
1334
+ case 7:
1335
+ this.pilhaEscoposExecucao.removerUltimo();
1336
+ if (manterAmbiente) {
1337
+ escopoAnterior = this.pilhaEscoposExecucao.topoDaPilha();
1338
+ escopoAnterior.ambiente.valores = Object.assign(escopoAnterior.ambiente.valores, ultimoEscopo.ambiente.valores);
1339
+ }
1340
+ return [7 /*endfinally*/];
1341
+ case 8: return [2 /*return*/];
1342
+ }
1343
+ });
1344
+ });
859
1345
  };
860
1346
  /**
861
1347
  * Interpretação sem depurador, com medição de performance.
@@ -867,29 +1353,55 @@ var Interpretador = /** @class */ (function () {
867
1353
  */
868
1354
  Interpretador.prototype.interpretar = function (declaracoes, manterAmbiente) {
869
1355
  if (manterAmbiente === void 0) { manterAmbiente = false; }
870
- this.erros = [];
871
- var escopoExecucao = {
872
- declaracoes: declaracoes,
873
- declaracaoAtual: 0,
874
- ambiente: new espaco_variaveis_1.EspacoVariaveis(),
875
- };
876
- this.pilhaEscoposExecucao.empilhar(escopoExecucao);
877
- var inicioInterpretacao = (0, browser_process_hrtime_1.default)();
878
- try {
879
- this.executarUltimoEscopo(manterAmbiente);
880
- }
881
- finally {
882
- if (this.performance) {
883
- var deltaInterpretacao = (0, browser_process_hrtime_1.default)(inicioInterpretacao);
884
- console.log("[Interpretador] Tempo para interpreta\u00E7ao: ".concat(deltaInterpretacao[0] * 1e9 + deltaInterpretacao[1], "ns"));
885
- }
886
- var retorno = {
887
- erros: this.erros,
888
- resultado: this.resultadoInterpretador,
889
- };
890
- this.resultadoInterpretador = [];
891
- return retorno;
892
- }
1356
+ return __awaiter(this, void 0, void 0, function () {
1357
+ var escopoExecucao, inicioInterpretacao, retornoOuErro, erro_11, deltaInterpretacao, retorno;
1358
+ return __generator(this, function (_a) {
1359
+ switch (_a.label) {
1360
+ case 0:
1361
+ this.erros = [];
1362
+ escopoExecucao = {
1363
+ declaracoes: declaracoes,
1364
+ declaracaoAtual: 0,
1365
+ ambiente: new espaco_variaveis_1.EspacoVariaveis(),
1366
+ };
1367
+ this.pilhaEscoposExecucao.empilhar(escopoExecucao);
1368
+ inicioInterpretacao = (0, browser_process_hrtime_1.default)();
1369
+ _a.label = 1;
1370
+ case 1:
1371
+ _a.trys.push([1, 3, 4, 5]);
1372
+ return [4 /*yield*/, this.executarUltimoEscopo(manterAmbiente)];
1373
+ case 2:
1374
+ retornoOuErro = _a.sent();
1375
+ if (retornoOuErro instanceof excecoes_1.ErroEmTempoDeExecucao) {
1376
+ this.erros.push(retornoOuErro);
1377
+ }
1378
+ return [3 /*break*/, 5];
1379
+ case 3:
1380
+ erro_11 = _a.sent();
1381
+ this.erros.push(erro_11);
1382
+ return [3 /*break*/, 5];
1383
+ case 4:
1384
+ if (this.performance) {
1385
+ deltaInterpretacao = (0, browser_process_hrtime_1.default)(inicioInterpretacao);
1386
+ console.log("[Interpretador] Tempo para interpreta\u00E7ao: ".concat(deltaInterpretacao[0] * 1e9 + deltaInterpretacao[1], "ns"));
1387
+ }
1388
+ retorno = {
1389
+ erros: this.erros,
1390
+ resultado: this.resultadoInterpretador,
1391
+ };
1392
+ this.resultadoInterpretador = [];
1393
+ return [2 /*return*/, retorno];
1394
+ case 5: return [2 /*return*/];
1395
+ }
1396
+ });
1397
+ });
1398
+ };
1399
+ /**
1400
+ * Procedimento de finalização de execução, normalmente solicitado pelo
1401
+ * núcleo da linguagem.
1402
+ */
1403
+ Interpretador.prototype.finalizacao = function () {
1404
+ this.interfaceDeEntrada.close();
893
1405
  };
894
1406
  return Interpretador;
895
1407
  }());