ivprogParser.js 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837
  1. // Generated from grammar/ivprog.g4 by ANTLR 4.7.1
  2. // jshint ignore: start
  3. var antlr4 = require('antlr4/index');
  4. var ivprogListener = require('./ivprogListener').ivprogListener;
  5. import {ASA, NoGlobal} from '../js/asa';
  6. var grammarFileName = "ivprog.g4";
  7. var serializedATN = ["\u0003\u608b\ua72a\u8133\ub9ed\u417c\u3be7\u7786\u5964",
  8. "\u0003&S\u0004\u0002\t\u0002\u0004\u0003\t\u0003\u0004\u0004\t\u0004",
  9. "\u0004\u0005\t\u0005\u0004\u0006\t\u0006\u0004\u0007\t\u0007\u0004\b",
  10. "\t\b\u0003\u0002\u0003\u0002\u0003\u0002\u0003\u0002\u0003\u0003\u0003",
  11. "\u0003\u0003\u0003\u0003\u0003\u0007\u0003\u0019\n\u0003\f\u0003\u000e",
  12. "\u0003\u001c\u000b\u0003\u0003\u0003\u0003\u0003\u0003\u0004\u0003\u0004",
  13. "\u0003\u0004\u0003\u0005\u0005\u0005$\n\u0005\u0003\u0005\u0003\u0005",
  14. "\u0003\u0005\u0003\u0005\u0003\u0005\u0003\u0005\u0003\u0005\u0003\u0005",
  15. "\u0007\u0005.\n\u0005\f\u0005\u000e\u00051\u000b\u0005\u0003\u0006\u0003",
  16. "\u0006\u0003\u0006\u0005\u00066\n\u0006\u0003\u0006\u0003\u0006\u0003",
  17. "\u0006\u0005\u0006;\n\u0006\u0003\u0006\u0005\u0006>\n\u0006\u0005\u0006",
  18. "@\n\u0006\u0003\u0006\u0003\u0006\u0005\u0006D\n\u0006\u0003\u0006\u0003",
  19. "\u0006\u0003\u0007\u0003\u0007\u0003\u0007\u0003\u0007\u0003\u0007\u0005",
  20. "\u0007M\n\u0007\u0003\u0007\u0003\u0007\u0003\b\u0003\b\u0003\b\u0002",
  21. "\u0002\t\u0002\u0004\u0006\b\n\f\u000e\u0002\u0003\u0004\u0002!!##\u0002",
  22. "W\u0002\u0010\u0003\u0002\u0002\u0002\u0004\u0014\u0003\u0002\u0002",
  23. "\u0002\u0006\u001f\u0003\u0002\u0002\u0002\b#\u0003\u0002\u0002\u0002",
  24. "\n2\u0003\u0002\u0002\u0002\fL\u0003\u0002\u0002\u0002\u000eP\u0003",
  25. "\u0002\u0002\u0002\u0010\u0011\u0005\u0004\u0003\u0002\u0011\u0012\u0007",
  26. "\u0002\u0002\u0003\u0012\u0013\b\u0002\u0001\u0002\u0013\u0003\u0003",
  27. "\u0002\u0002\u0002\u0014\u0015\u0007\t\u0002\u0002\u0015\u0016\u0007",
  28. "\u0003\u0002\u0002\u0016\u001a\b\u0003\u0001\u0002\u0017\u0019\u0005",
  29. "\u0006\u0004\u0002\u0018\u0017\u0003\u0002\u0002\u0002\u0019\u001c\u0003",
  30. "\u0002\u0002\u0002\u001a\u0018\u0003\u0002\u0002\u0002\u001a\u001b\u0003",
  31. "\u0002\u0002\u0002\u001b\u001d\u0003\u0002\u0002\u0002\u001c\u001a\u0003",
  32. "\u0002\u0002\u0002\u001d\u001e\u0007\u0004\u0002\u0002\u001e\u0005\u0003",
  33. "\u0002\u0002\u0002\u001f \u0005\b\u0005\u0002 !\b\u0004\u0001\u0002",
  34. "!\u0007\u0003\u0002\u0002\u0002\"$\u0007\u0013\u0002\u0002#\"\u0003",
  35. "\u0002\u0002\u0002#$\u0003\u0002\u0002\u0002$%\u0003\u0002\u0002\u0002",
  36. "%&\u0005\f\u0007\u0002&\'\u0005\n\u0006\u0002\'(\b\u0005\u0001\u0002",
  37. "(/\u0003\u0002\u0002\u0002)*\u0007\u0005\u0002\u0002*+\u0005\n\u0006",
  38. "\u0002+,\b\u0005\u0001\u0002,.\u0003\u0002\u0002\u0002-)\u0003\u0002",
  39. "\u0002\u0002.1\u0003\u0002\u0002\u0002/-\u0003\u0002\u0002\u0002/0\u0003",
  40. "\u0002\u0002\u00020\t\u0003\u0002\u0002\u00021/\u0003\u0002\u0002\u0002",
  41. "2?\u0007\u001f\u0002\u000235\u0007\u0006\u0002\u000246\u0005\u000e\b",
  42. "\u000254\u0003\u0002\u0002\u000256\u0003\u0002\u0002\u000267\u0003\u0002",
  43. "\u0002\u00027=\u0007\u0007\u0002\u00028:\u0007\u0006\u0002\u00029;\u0005",
  44. "\u000e\b\u0002:9\u0003\u0002\u0002\u0002:;\u0003\u0002\u0002\u0002;",
  45. "<\u0003\u0002\u0002\u0002<>\u0007\u0007\u0002\u0002=8\u0003\u0002\u0002",
  46. "\u0002=>\u0003\u0002\u0002\u0002>@\u0003\u0002\u0002\u0002?3\u0003\u0002",
  47. "\u0002\u0002?@\u0003\u0002\u0002\u0002@C\u0003\u0002\u0002\u0002AB\u0007",
  48. "\b\u0002\u0002BD\u0005\u000e\b\u0002CA\u0003\u0002\u0002\u0002CD\u0003",
  49. "\u0002\u0002\u0002DE\u0003\u0002\u0002\u0002EF\b\u0006\u0001\u0002F",
  50. "\u000b\u0003\u0002\u0002\u0002GM\u0007\u000e\u0002\u0002HM\u0007\n\u0002",
  51. "\u0002IM\u0007\u000f\u0002\u0002JM\u0007\r\u0002\u0002KM\u0007\f\u0002",
  52. "\u0002LG\u0003\u0002\u0002\u0002LH\u0003\u0002\u0002\u0002LI\u0003\u0002",
  53. "\u0002\u0002LJ\u0003\u0002\u0002\u0002LK\u0003\u0002\u0002\u0002MN\u0003",
  54. "\u0002\u0002\u0002NO\b\u0007\u0001\u0002O\r\u0003\u0002\u0002\u0002",
  55. "PQ\t\u0002\u0002\u0002Q\u000f\u0003\u0002\u0002\u0002\u000b\u001a#/",
  56. "5:=?CL"].join("");
  57. var atn = new antlr4.atn.ATNDeserializer().deserialize(serializedATN);
  58. var decisionsToDFA = atn.decisionToState.map( function(ds, index) { return new antlr4.dfa.DFA(ds, index); });
  59. var sharedContextCache = new antlr4.PredictionContextCache();
  60. var literalNames = [ null, "'{'", "'}'", "','", "'['", "']'", "'='", "'programa'",
  61. "'real'", "'vazio'", "'logico'", "'cadeia'", "'inteiro'",
  62. "'caracter'", "'escolha'", "'caso'", "'contrario'",
  63. "'const'", "'funcao'", "'retorne'", "'para'", "'pare'",
  64. "'faca'", "'enquanto'", "'se'", "'senao'", null, "'nao'" ];
  65. var symbolicNames = [ null, null, null, null, null, null, null, "PR_PROGRAMA",
  66. "PR_REAL", "PR_VAZIO", "PR_LOGICO", "PR_CADEIA", "PR_INTEIRO",
  67. "PR_CARACTER", "PR_ESCOLHA", "PR_CASO", "PR_CONTRARIO",
  68. "PR_CONST", "PR_FUNCAO", "PR_RETORNE", "PR_PARA",
  69. "PR_PARE", "PR_FACA", "PR_ENQUANTO", "PR_SE", "PR_SENAO",
  70. "GAMBIARRA", "OPERADOR_NAO", "LOGICO", "ID", "ID_BIBLIOTECA",
  71. "INTEIRO", "REAL", "CADEIA", "CARACTER", "ESPACO",
  72. "COMENTARIO" ];
  73. var ruleNames = [ "parse", "programa", "declaracoesGlobais", "listaDeclaracoes",
  74. "declaracao", "declaracaoTipoDado", "expressao" ];
  75. function ivprogParser (input) {
  76. antlr4.Parser.call(this, input);
  77. this._interp = new antlr4.atn.ParserATNSimulator(this, atn, decisionsToDFA, sharedContextCache);
  78. this.ruleNames = ruleNames;
  79. this.literalNames = literalNames;
  80. this.symbolicNames = symbolicNames;
  81. this.criarTrechoCodigoFonte = function(tokenAntlr)
  82. {
  83. if (tokenAntlr != null)
  84. {
  85. const linha = tokenAntlr.getLine();
  86. const coluna = tokenAntlr.getCharPositionInLine();
  87. const tamanhoTexto = tokenAntlr.getText().length();
  88. return {linha: linha, coluna: coluna, tamanhoTexto: tamanhoTexto};
  89. }
  90. return null;
  91. }
  92. return this;
  93. }
  94. ivprogParser.prototype = Object.create(antlr4.Parser.prototype);
  95. ivprogParser.prototype.constructor = ivprogParser;
  96. Object.defineProperty(ivprogParser.prototype, "atn", {
  97. get : function() {
  98. return atn;
  99. }
  100. });
  101. ivprogParser.EOF = antlr4.Token.EOF;
  102. ivprogParser.T__0 = 1;
  103. ivprogParser.T__1 = 2;
  104. ivprogParser.T__2 = 3;
  105. ivprogParser.T__3 = 4;
  106. ivprogParser.T__4 = 5;
  107. ivprogParser.T__5 = 6;
  108. ivprogParser.PR_PROGRAMA = 7;
  109. ivprogParser.PR_REAL = 8;
  110. ivprogParser.PR_VAZIO = 9;
  111. ivprogParser.PR_LOGICO = 10;
  112. ivprogParser.PR_CADEIA = 11;
  113. ivprogParser.PR_INTEIRO = 12;
  114. ivprogParser.PR_CARACTER = 13;
  115. ivprogParser.PR_ESCOLHA = 14;
  116. ivprogParser.PR_CASO = 15;
  117. ivprogParser.PR_CONTRARIO = 16;
  118. ivprogParser.PR_CONST = 17;
  119. ivprogParser.PR_FUNCAO = 18;
  120. ivprogParser.PR_RETORNE = 19;
  121. ivprogParser.PR_PARA = 20;
  122. ivprogParser.PR_PARE = 21;
  123. ivprogParser.PR_FACA = 22;
  124. ivprogParser.PR_ENQUANTO = 23;
  125. ivprogParser.PR_SE = 24;
  126. ivprogParser.PR_SENAO = 25;
  127. ivprogParser.GAMBIARRA = 26;
  128. ivprogParser.OPERADOR_NAO = 27;
  129. ivprogParser.LOGICO = 28;
  130. ivprogParser.ID = 29;
  131. ivprogParser.ID_BIBLIOTECA = 30;
  132. ivprogParser.INTEIRO = 31;
  133. ivprogParser.REAL = 32;
  134. ivprogParser.CADEIA = 33;
  135. ivprogParser.CARACTER = 34;
  136. ivprogParser.ESPACO = 35;
  137. ivprogParser.COMENTARIO = 36;
  138. ivprogParser.RULE_parse = 0;
  139. ivprogParser.RULE_programa = 1;
  140. ivprogParser.RULE_declaracoesGlobais = 2;
  141. ivprogParser.RULE_listaDeclaracoes = 3;
  142. ivprogParser.RULE_declaracao = 4;
  143. ivprogParser.RULE_declaracaoTipoDado = 5;
  144. ivprogParser.RULE_expressao = 6;
  145. function ParseContext(parser, parent, invokingState) {
  146. if(parent===undefined) {
  147. parent = null;
  148. }
  149. if(invokingState===undefined || invokingState===null) {
  150. invokingState = -1;
  151. }
  152. antlr4.ParserRuleContext.call(this, parent, invokingState);
  153. this.parser = parser;
  154. this.ruleIndex = ivprogParser.RULE_parse;
  155. this.asa = null
  156. this.prog = null; // ProgramaContext
  157. return this;
  158. }
  159. ParseContext.prototype = Object.create(antlr4.ParserRuleContext.prototype);
  160. ParseContext.prototype.constructor = ParseContext;
  161. ParseContext.prototype.EOF = function() {
  162. return this.getToken(ivprogParser.EOF, 0);
  163. };
  164. ParseContext.prototype.programa = function() {
  165. return this.getTypedRuleContext(ProgramaContext,0);
  166. };
  167. ParseContext.prototype.enterRule = function(listener) {
  168. if(listener instanceof ivprogListener ) {
  169. listener.enterParse(this);
  170. }
  171. };
  172. ParseContext.prototype.exitRule = function(listener) {
  173. if(listener instanceof ivprogListener ) {
  174. listener.exitParse(this);
  175. }
  176. };
  177. ivprogParser.ParseContext = ParseContext;
  178. ivprogParser.prototype.parse = function() {
  179. var localctx = new ParseContext(this, this._ctx, this.state);
  180. this.enterRule(localctx, 0, ivprogParser.RULE_parse);
  181. try {
  182. this.enterOuterAlt(localctx, 1);
  183. this.state = 14;
  184. localctx.prog = this.programa();
  185. this.state = 15;
  186. this.match(ivprogParser.EOF);
  187. localctx.asa = localctx.prog.asa
  188. } catch (re) {
  189. if(re instanceof antlr4.error.RecognitionException) {
  190. localctx.exception = re;
  191. this._errHandler.reportError(this, re);
  192. this._errHandler.recover(this, re);
  193. } else {
  194. throw re;
  195. }
  196. } finally {
  197. this.exitRule();
  198. }
  199. return localctx;
  200. };
  201. function ProgramaContext(parser, parent, invokingState) {
  202. if(parent===undefined) {
  203. parent = null;
  204. }
  205. if(invokingState===undefined || invokingState===null) {
  206. invokingState = -1;
  207. }
  208. antlr4.ParserRuleContext.call(this, parent, invokingState);
  209. this.parser = parser;
  210. this.ruleIndex = ivprogParser.RULE_programa;
  211. this.asa = null
  212. return this;
  213. }
  214. ProgramaContext.prototype = Object.create(antlr4.ParserRuleContext.prototype);
  215. ProgramaContext.prototype.constructor = ProgramaContext;
  216. ProgramaContext.prototype.PR_PROGRAMA = function() {
  217. return this.getToken(ivprogParser.PR_PROGRAMA, 0);
  218. };
  219. ProgramaContext.prototype.declaracoesGlobais = function(i) {
  220. if(i===undefined) {
  221. i = null;
  222. }
  223. if(i===null) {
  224. return this.getTypedRuleContexts(DeclaracoesGlobaisContext);
  225. } else {
  226. return this.getTypedRuleContext(DeclaracoesGlobaisContext,i);
  227. }
  228. };
  229. ProgramaContext.prototype.enterRule = function(listener) {
  230. if(listener instanceof ivprogListener ) {
  231. listener.enterPrograma(this);
  232. }
  233. };
  234. ProgramaContext.prototype.exitRule = function(listener) {
  235. if(listener instanceof ivprogListener ) {
  236. listener.exitPrograma(this);
  237. }
  238. };
  239. ivprogParser.ProgramaContext = ProgramaContext;
  240. ivprogParser.prototype.programa = function() {
  241. var localctx = new ProgramaContext(this, this._ctx, this.state);
  242. this.enterRule(localctx, 2, ivprogParser.RULE_programa);
  243. var _la = 0; // Token type
  244. try {
  245. this.enterOuterAlt(localctx, 1);
  246. this.state = 18;
  247. this.match(ivprogParser.PR_PROGRAMA);
  248. this.state = 19;
  249. this.match(ivprogParser.T__0);
  250. localctx.asa = new ASA()
  251. this.state = 24;
  252. this._errHandler.sync(this);
  253. _la = this._input.LA(1);
  254. while((((_la) & ~0x1f) == 0 && ((1 << _la) & ((1 << ivprogParser.PR_REAL) | (1 << ivprogParser.PR_LOGICO) | (1 << ivprogParser.PR_CADEIA) | (1 << ivprogParser.PR_INTEIRO) | (1 << ivprogParser.PR_CARACTER) | (1 << ivprogParser.PR_CONST))) !== 0)) {
  255. this.state = 21;
  256. this.declaracoesGlobais(localctx.asa);
  257. this.state = 26;
  258. this._errHandler.sync(this);
  259. _la = this._input.LA(1);
  260. }
  261. this.state = 27;
  262. this.match(ivprogParser.T__1);
  263. } catch (re) {
  264. if(re instanceof antlr4.error.RecognitionException) {
  265. localctx.exception = re;
  266. this._errHandler.reportError(this, re);
  267. this._errHandler.recover(this, re);
  268. } else {
  269. throw re;
  270. }
  271. } finally {
  272. this.exitRule();
  273. }
  274. return localctx;
  275. };
  276. function DeclaracoesGlobaisContext(parser, parent, invokingState, asa) {
  277. if(parent===undefined) {
  278. parent = null;
  279. }
  280. if(invokingState===undefined || invokingState===null) {
  281. invokingState = -1;
  282. }
  283. antlr4.ParserRuleContext.call(this, parent, invokingState);
  284. this.parser = parser;
  285. this.ruleIndex = ivprogParser.RULE_declaracoesGlobais;
  286. this.asa = null
  287. this.vList = null; // ListaDeclaracoesContext
  288. this.asa = asa || null;
  289. return this;
  290. }
  291. DeclaracoesGlobaisContext.prototype = Object.create(antlr4.ParserRuleContext.prototype);
  292. DeclaracoesGlobaisContext.prototype.constructor = DeclaracoesGlobaisContext;
  293. DeclaracoesGlobaisContext.prototype.listaDeclaracoes = function() {
  294. return this.getTypedRuleContext(ListaDeclaracoesContext,0);
  295. };
  296. DeclaracoesGlobaisContext.prototype.enterRule = function(listener) {
  297. if(listener instanceof ivprogListener ) {
  298. listener.enterDeclaracoesGlobais(this);
  299. }
  300. };
  301. DeclaracoesGlobaisContext.prototype.exitRule = function(listener) {
  302. if(listener instanceof ivprogListener ) {
  303. listener.exitDeclaracoesGlobais(this);
  304. }
  305. };
  306. ivprogParser.DeclaracoesGlobaisContext = DeclaracoesGlobaisContext;
  307. ivprogParser.prototype.declaracoesGlobais = function(asa) {
  308. var localctx = new DeclaracoesGlobaisContext(this, this._ctx, this.state, asa);
  309. this.enterRule(localctx, 4, ivprogParser.RULE_declaracoesGlobais);
  310. try {
  311. this.enterOuterAlt(localctx, 1);
  312. this.state = 29;
  313. localctx.vList = this.listaDeclaracoes();
  314. if (localctx.asa != null) {
  315. this.globais = new NoGlobal();
  316. localctx.vList.lista.forEach( v => this.globais.addDeclaracao(v));
  317. localctx.asa.nos.push(localctx.vList.lista);
  318. }
  319. } catch (re) {
  320. if(re instanceof antlr4.error.RecognitionException) {
  321. localctx.exception = re;
  322. this._errHandler.reportError(this, re);
  323. this._errHandler.recover(this, re);
  324. } else {
  325. throw re;
  326. }
  327. } finally {
  328. this.exitRule();
  329. }
  330. return localctx;
  331. };
  332. function ListaDeclaracoesContext(parser, parent, invokingState) {
  333. if(parent===undefined) {
  334. parent = null;
  335. }
  336. if(invokingState===undefined || invokingState===null) {
  337. invokingState = -1;
  338. }
  339. antlr4.ParserRuleContext.call(this, parent, invokingState);
  340. this.parser = parser;
  341. this.ruleIndex = ivprogParser.RULE_listaDeclaracoes;
  342. this.lista = null
  343. this.tokenConst = null; // Token
  344. this.informacaoTipoDado = null; // DeclaracaoTipoDadoContext
  345. this.vDeclaracao = null; // DeclaracaoContext
  346. return this;
  347. }
  348. ListaDeclaracoesContext.prototype = Object.create(antlr4.ParserRuleContext.prototype);
  349. ListaDeclaracoesContext.prototype.constructor = ListaDeclaracoesContext;
  350. ListaDeclaracoesContext.prototype.declaracaoTipoDado = function() {
  351. return this.getTypedRuleContext(DeclaracaoTipoDadoContext,0);
  352. };
  353. ListaDeclaracoesContext.prototype.declaracao = function(i) {
  354. if(i===undefined) {
  355. i = null;
  356. }
  357. if(i===null) {
  358. return this.getTypedRuleContexts(DeclaracaoContext);
  359. } else {
  360. return this.getTypedRuleContext(DeclaracaoContext,i);
  361. }
  362. };
  363. ListaDeclaracoesContext.prototype.PR_CONST = function() {
  364. return this.getToken(ivprogParser.PR_CONST, 0);
  365. };
  366. ListaDeclaracoesContext.prototype.enterRule = function(listener) {
  367. if(listener instanceof ivprogListener ) {
  368. listener.enterListaDeclaracoes(this);
  369. }
  370. };
  371. ListaDeclaracoesContext.prototype.exitRule = function(listener) {
  372. if(listener instanceof ivprogListener ) {
  373. listener.exitListaDeclaracoes(this);
  374. }
  375. };
  376. ivprogParser.ListaDeclaracoesContext = ListaDeclaracoesContext;
  377. ivprogParser.prototype.listaDeclaracoes = function() {
  378. var localctx = new ListaDeclaracoesContext(this, this._ctx, this.state);
  379. this.enterRule(localctx, 6, ivprogParser.RULE_listaDeclaracoes);
  380. localctx.lista = []
  381. var _la = 0; // Token type
  382. try {
  383. this.enterOuterAlt(localctx, 1);
  384. this.state = 33;
  385. this._errHandler.sync(this);
  386. _la = this._input.LA(1);
  387. if(_la===ivprogParser.PR_CONST) {
  388. this.state = 32;
  389. localctx.tokenConst = this.match(ivprogParser.PR_CONST);
  390. }
  391. this.state = 35;
  392. localctx.informacaoTipoDado = this.declaracaoTipoDado();
  393. this.state = 36;
  394. localctx.vDeclaracao = this.declaracao(localctx.tokenConst, localctx.informacaoTipoDado.informacaoTipoDado);
  395. if(localctx.vDeclaracao) {
  396. localctx.lista.push(localctx.vDeclaracao.rDeclaracao);
  397. }
  398. localctx.vDeclaracao = null;
  399. this.state = 45;
  400. this._errHandler.sync(this);
  401. _la = this._input.LA(1);
  402. while(_la===ivprogParser.T__2) {
  403. this.state = 39;
  404. this.match(ivprogParser.T__2);
  405. this.state = 40;
  406. localctx.vDeclaracao = this.declaracao(localctx.tokenConst, localctx.informacaoTipoDado.informacaoTipoDado);
  407. if(localctx.vDeclaracao) {
  408. localctx.lista.push(localctx.vDeclaracao.rDeclaracao);
  409. }
  410. localctx.vDeclaracao = null;
  411. this.state = 47;
  412. this._errHandler.sync(this);
  413. _la = this._input.LA(1);
  414. }
  415. } catch (re) {
  416. if(re instanceof antlr4.error.RecognitionException) {
  417. localctx.exception = re;
  418. this._errHandler.reportError(this, re);
  419. this._errHandler.recover(this, re);
  420. } else {
  421. throw re;
  422. }
  423. } finally {
  424. this.exitRule();
  425. }
  426. return localctx;
  427. };
  428. function DeclaracaoContext(parser, parent, invokingState, tokenConst, informacaoTipoDado) {
  429. if(parent===undefined) {
  430. parent = null;
  431. }
  432. if(invokingState===undefined || invokingState===null) {
  433. invokingState = -1;
  434. }
  435. antlr4.ParserRuleContext.call(this, parent, invokingState);
  436. this.parser = parser;
  437. this.ruleIndex = ivprogParser.RULE_declaracao;
  438. this.tokenConst = null
  439. this.informacaoTipoDado = null
  440. this.rDeclaracao = null
  441. this._ID = null; // Token
  442. this.tk1 = null; // Token
  443. this.ind1 = null; // ExpressaoContext
  444. this.tk2 = null; // Token
  445. this.ind2 = null; // ExpressaoContext
  446. this.inicializacao = null; // ExpressaoContext
  447. this.tokenConst = tokenConst || null;
  448. this.informacaoTipoDado = informacaoTipoDado || null;
  449. return this;
  450. }
  451. DeclaracaoContext.prototype = Object.create(antlr4.ParserRuleContext.prototype);
  452. DeclaracaoContext.prototype.constructor = DeclaracaoContext;
  453. DeclaracaoContext.prototype.ID = function() {
  454. return this.getToken(ivprogParser.ID, 0);
  455. };
  456. DeclaracaoContext.prototype.expressao = function(i) {
  457. if(i===undefined) {
  458. i = null;
  459. }
  460. if(i===null) {
  461. return this.getTypedRuleContexts(ExpressaoContext);
  462. } else {
  463. return this.getTypedRuleContext(ExpressaoContext,i);
  464. }
  465. };
  466. DeclaracaoContext.prototype.enterRule = function(listener) {
  467. if(listener instanceof ivprogListener ) {
  468. listener.enterDeclaracao(this);
  469. }
  470. };
  471. DeclaracaoContext.prototype.exitRule = function(listener) {
  472. if(listener instanceof ivprogListener ) {
  473. listener.exitDeclaracao(this);
  474. }
  475. };
  476. ivprogParser.DeclaracaoContext = DeclaracaoContext;
  477. ivprogParser.prototype.declaracao = function(tokenConst, informacaoTipoDado) {
  478. var localctx = new DeclaracaoContext(this, this._ctx, this.state, tokenConst, informacaoTipoDado);
  479. this.enterRule(localctx, 8, ivprogParser.RULE_declaracao);
  480. var _la = 0; // Token type
  481. try {
  482. this.enterOuterAlt(localctx, 1);
  483. this.state = 48;
  484. localctx._ID = this.match(ivprogParser.ID);
  485. this.state = 61;
  486. this._errHandler.sync(this);
  487. _la = this._input.LA(1);
  488. if(_la===ivprogParser.T__3) {
  489. this.state = 49;
  490. localctx.tk1 = this.match(ivprogParser.T__3);
  491. this.state = 51;
  492. this._errHandler.sync(this);
  493. _la = this._input.LA(1);
  494. if(_la===ivprogParser.INTEIRO || _la===ivprogParser.CADEIA) {
  495. this.state = 50;
  496. localctx.ind1 = this.expressao();
  497. }
  498. this.state = 53;
  499. this.match(ivprogParser.T__4);
  500. this.state = 59;
  501. this._errHandler.sync(this);
  502. _la = this._input.LA(1);
  503. if(_la===ivprogParser.T__3) {
  504. this.state = 54;
  505. localctx.tk2 = this.match(ivprogParser.T__3);
  506. this.state = 56;
  507. this._errHandler.sync(this);
  508. _la = this._input.LA(1);
  509. if(_la===ivprogParser.INTEIRO || _la===ivprogParser.CADEIA) {
  510. this.state = 55;
  511. localctx.ind2 = this.expressao();
  512. }
  513. this.state = 58;
  514. this.match(ivprogParser.T__4);
  515. }
  516. }
  517. this.state = 65;
  518. this._errHandler.sync(this);
  519. _la = this._input.LA(1);
  520. if(_la===ivprogParser.T__5) {
  521. this.state = 63;
  522. this.match(ivprogParser.T__5);
  523. this.state = 64;
  524. localctx.inicializacao = this.expressao();
  525. }
  526. const constante = (localctx.tokenConst != null);
  527. const tipoDado = (localctx.informacaoTipoDado != null)? localctx.informacaoTipoDado.tipoDado : null;
  528. const nome = (localctx._ID != null)? (localctx._ID===null ? null : localctx._ID.text) : null;
  529. if ((localctx.tk1 == null) && (localctx.tk2 == null))
  530. localctx.rDeclaracao = new NoDeclaracaoVariavel(nome, tipoDado, constante)
  531. else
  532. if ((localctx.tk1 != null) && (localctx.tk2 == null))
  533. localctx.rDeclaracao = new NoDeclaracaoVetor(nome, tipoDado, (localctx.ind1===null ? null : this._input.getText(new antlr4.Interval(localctx.ind1.start,localctx.ind1.stop))), constante)
  534. else
  535. if ((localctx.tk1 != null) && (localctx.tk2 != null))
  536. localctx.rDeclaracao = new NoDeclaracaoMatriz(nome, tipoDado, (localctx.ind1===null ? null : this._input.getText(new antlr4.Interval(localctx.ind1.start,localctx.ind1.stop))), (localctx.ind2===null ? null : this._input.getText(new antlr4.Interval(localctx.ind2.start,localctx.ind2.stop))), constante)
  537. localctx.rDeclaracao.setInicializacao(inicializacao);
  538. localctx.rDeclaracao.setTrechoCodigoFonteNome(criarTrechoCodigoFonte(localctx._ID));
  539. localctx.rDeclaracao.setTrechoCodigoFonteTipoDado((localctx.informacaoTipoDado != null)? localctx.informacaoTipoDado.getTrechoCodigoFonte(): null);
  540. } catch (re) {
  541. if(re instanceof antlr4.error.RecognitionException) {
  542. localctx.exception = re;
  543. this._errHandler.reportError(this, re);
  544. this._errHandler.recover(this, re);
  545. } else {
  546. throw re;
  547. }
  548. } finally {
  549. this.exitRule();
  550. }
  551. return localctx;
  552. };
  553. function DeclaracaoTipoDadoContext(parser, parent, invokingState) {
  554. if(parent===undefined) {
  555. parent = null;
  556. }
  557. if(invokingState===undefined || invokingState===null) {
  558. invokingState = -1;
  559. }
  560. antlr4.ParserRuleContext.call(this, parent, invokingState);
  561. this.parser = parser;
  562. this.ruleIndex = ivprogParser.RULE_declaracaoTipoDado;
  563. this.informacaoTipoDado = null
  564. this.tokenTipoDado = null; // Token
  565. return this;
  566. }
  567. DeclaracaoTipoDadoContext.prototype = Object.create(antlr4.ParserRuleContext.prototype);
  568. DeclaracaoTipoDadoContext.prototype.constructor = DeclaracaoTipoDadoContext;
  569. DeclaracaoTipoDadoContext.prototype.PR_INTEIRO = function() {
  570. return this.getToken(ivprogParser.PR_INTEIRO, 0);
  571. };
  572. DeclaracaoTipoDadoContext.prototype.PR_REAL = function() {
  573. return this.getToken(ivprogParser.PR_REAL, 0);
  574. };
  575. DeclaracaoTipoDadoContext.prototype.PR_CARACTER = function() {
  576. return this.getToken(ivprogParser.PR_CARACTER, 0);
  577. };
  578. DeclaracaoTipoDadoContext.prototype.PR_CADEIA = function() {
  579. return this.getToken(ivprogParser.PR_CADEIA, 0);
  580. };
  581. DeclaracaoTipoDadoContext.prototype.PR_LOGICO = function() {
  582. return this.getToken(ivprogParser.PR_LOGICO, 0);
  583. };
  584. DeclaracaoTipoDadoContext.prototype.enterRule = function(listener) {
  585. if(listener instanceof ivprogListener ) {
  586. listener.enterDeclaracaoTipoDado(this);
  587. }
  588. };
  589. DeclaracaoTipoDadoContext.prototype.exitRule = function(listener) {
  590. if(listener instanceof ivprogListener ) {
  591. listener.exitDeclaracaoTipoDado(this);
  592. }
  593. };
  594. ivprogParser.DeclaracaoTipoDadoContext = DeclaracaoTipoDadoContext;
  595. ivprogParser.prototype.declaracaoTipoDado = function() {
  596. var localctx = new DeclaracaoTipoDadoContext(this, this._ctx, this.state);
  597. this.enterRule(localctx, 10, ivprogParser.RULE_declaracaoTipoDado);
  598. try {
  599. this.enterOuterAlt(localctx, 1);
  600. this.state = 74;
  601. this._errHandler.sync(this);
  602. switch(this._input.LA(1)) {
  603. case ivprogParser.PR_INTEIRO:
  604. this.state = 69;
  605. localctx.tokenTipoDado = this.match(ivprogParser.PR_INTEIRO);
  606. break;
  607. case ivprogParser.PR_REAL:
  608. this.state = 70;
  609. localctx.tokenTipoDado = this.match(ivprogParser.PR_REAL);
  610. break;
  611. case ivprogParser.PR_CARACTER:
  612. this.state = 71;
  613. localctx.tokenTipoDado = this.match(ivprogParser.PR_CARACTER);
  614. break;
  615. case ivprogParser.PR_CADEIA:
  616. this.state = 72;
  617. localctx.tokenTipoDado = this.match(ivprogParser.PR_CADEIA);
  618. break;
  619. case ivprogParser.PR_LOGICO:
  620. this.state = 73;
  621. localctx.tokenTipoDado = this.match(ivprogParser.PR_LOGICO);
  622. break;
  623. default:
  624. throw new antlr4.error.NoViableAltException(this);
  625. }
  626. localctx.informacaoTipoDado = new InformacaoTipoDado()
  627. localctx.informacaoTipoDado.setTipoDado(localctx.tokenTipoDado);
  628. localctx.informacaoTipoDado.setTrechoCodigoFonte(criarTrechoCodigoFonte(localctx.tokenTipoDado));
  629. } catch (re) {
  630. if(re instanceof antlr4.error.RecognitionException) {
  631. localctx.exception = re;
  632. this._errHandler.reportError(this, re);
  633. this._errHandler.recover(this, re);
  634. } else {
  635. throw re;
  636. }
  637. } finally {
  638. this.exitRule();
  639. }
  640. return localctx;
  641. };
  642. function ExpressaoContext(parser, parent, invokingState) {
  643. if(parent===undefined) {
  644. parent = null;
  645. }
  646. if(invokingState===undefined || invokingState===null) {
  647. invokingState = -1;
  648. }
  649. antlr4.ParserRuleContext.call(this, parent, invokingState);
  650. this.parser = parser;
  651. this.ruleIndex = ivprogParser.RULE_expressao;
  652. return this;
  653. }
  654. ExpressaoContext.prototype = Object.create(antlr4.ParserRuleContext.prototype);
  655. ExpressaoContext.prototype.constructor = ExpressaoContext;
  656. ExpressaoContext.prototype.INTEIRO = function() {
  657. return this.getToken(ivprogParser.INTEIRO, 0);
  658. };
  659. ExpressaoContext.prototype.CADEIA = function() {
  660. return this.getToken(ivprogParser.CADEIA, 0);
  661. };
  662. ExpressaoContext.prototype.enterRule = function(listener) {
  663. if(listener instanceof ivprogListener ) {
  664. listener.enterExpressao(this);
  665. }
  666. };
  667. ExpressaoContext.prototype.exitRule = function(listener) {
  668. if(listener instanceof ivprogListener ) {
  669. listener.exitExpressao(this);
  670. }
  671. };
  672. ivprogParser.ExpressaoContext = ExpressaoContext;
  673. ivprogParser.prototype.expressao = function() {
  674. var localctx = new ExpressaoContext(this, this._ctx, this.state);
  675. this.enterRule(localctx, 12, ivprogParser.RULE_expressao);
  676. var _la = 0; // Token type
  677. try {
  678. this.enterOuterAlt(localctx, 1);
  679. this.state = 78;
  680. _la = this._input.LA(1);
  681. if(!(_la===ivprogParser.INTEIRO || _la===ivprogParser.CADEIA)) {
  682. this._errHandler.recoverInline(this);
  683. }
  684. else {
  685. this._errHandler.reportMatch(this);
  686. this.consume();
  687. }
  688. } catch (re) {
  689. if(re instanceof antlr4.error.RecognitionException) {
  690. localctx.exception = re;
  691. this._errHandler.reportError(this, re);
  692. this._errHandler.recover(this, re);
  693. } else {
  694. throw re;
  695. }
  696. } finally {
  697. this.exitRule();
  698. }
  699. return localctx;
  700. };
  701. exports.ivprogParser = ivprogParser;