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