ANFParser.py (44951B)
1 # Generated from /home/erik/PycharmProjects/pythonProject/grammar/ANF.g4 by ANTLR 4.13.1 2 # encoding: utf-8 3 from antlr4 import * 4 from io import StringIO 5 import sys 6 if sys.version_info[1] > 5: 7 from typing import TextIO 8 else: 9 from typing.io import TextIO 10 11 def serializedATN(): 12 return [ 13 4,1,29,157,2,0,7,0,2,1,7,1,2,2,7,2,2,3,7,3,2,4,7,4,1,0,4,0,12,8, 14 0,11,0,12,0,13,1,1,1,1,1,1,1,1,1,1,1,1,5,1,22,8,1,10,1,12,1,25,9, 15 1,3,1,27,8,1,1,1,1,1,1,1,1,1,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2, 16 1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2, 17 1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2, 18 1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2, 19 1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2, 20 1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,5,2,114,8,2,10,2,12,2,117,9,2,1, 21 2,1,2,1,2,1,2,3,2,123,8,2,1,3,1,3,1,3,1,3,1,3,5,3,130,8,3,10,3,12, 22 3,133,9,3,1,3,1,3,1,3,3,3,138,8,3,1,4,1,4,1,4,1,4,1,4,1,4,1,4,1, 23 4,1,4,1,4,1,4,1,4,1,4,1,4,1,4,3,4,155,8,4,1,4,0,0,5,0,2,4,6,8,0, 24 0,176,0,11,1,0,0,0,2,15,1,0,0,0,4,122,1,0,0,0,6,137,1,0,0,0,8,154, 25 1,0,0,0,10,12,3,2,1,0,11,10,1,0,0,0,12,13,1,0,0,0,13,11,1,0,0,0, 26 13,14,1,0,0,0,14,1,1,0,0,0,15,16,5,1,0,0,16,17,5,26,0,0,17,26,5, 27 2,0,0,18,23,5,26,0,0,19,20,5,3,0,0,20,22,5,26,0,0,21,19,1,0,0,0, 28 22,25,1,0,0,0,23,21,1,0,0,0,23,24,1,0,0,0,24,27,1,0,0,0,25,23,1, 29 0,0,0,26,18,1,0,0,0,26,27,1,0,0,0,27,28,1,0,0,0,28,29,5,4,0,0,29, 30 30,5,5,0,0,30,31,3,8,4,0,31,3,1,0,0,0,32,123,5,6,0,0,33,123,5,7, 31 0,0,34,123,5,26,0,0,35,123,5,27,0,0,36,123,5,28,0,0,37,38,5,2,0, 32 0,38,39,3,4,2,0,39,40,5,8,0,0,40,41,3,4,2,0,41,42,5,4,0,0,42,123, 33 1,0,0,0,43,44,5,2,0,0,44,45,3,4,2,0,45,46,5,9,0,0,46,47,3,4,2,0, 34 47,48,5,4,0,0,48,123,1,0,0,0,49,50,5,2,0,0,50,51,3,4,2,0,51,52,5, 35 10,0,0,52,53,3,4,2,0,53,54,5,4,0,0,54,123,1,0,0,0,55,56,5,2,0,0, 36 56,57,3,4,2,0,57,58,5,11,0,0,58,59,3,4,2,0,59,60,5,4,0,0,60,123, 37 1,0,0,0,61,62,5,2,0,0,62,63,3,4,2,0,63,64,5,12,0,0,64,65,3,4,2,0, 38 65,66,5,4,0,0,66,123,1,0,0,0,67,68,5,2,0,0,68,69,3,4,2,0,69,70,5, 39 13,0,0,70,71,3,4,2,0,71,72,5,4,0,0,72,123,1,0,0,0,73,74,5,2,0,0, 40 74,75,3,4,2,0,75,76,5,14,0,0,76,77,3,4,2,0,77,78,5,4,0,0,78,123, 41 1,0,0,0,79,80,5,2,0,0,80,81,3,4,2,0,81,82,5,15,0,0,82,83,3,4,2,0, 42 83,84,5,4,0,0,84,123,1,0,0,0,85,86,5,2,0,0,86,87,3,4,2,0,87,88,5, 43 16,0,0,88,89,3,4,2,0,89,90,5,4,0,0,90,123,1,0,0,0,91,92,5,2,0,0, 44 92,93,3,4,2,0,93,94,5,17,0,0,94,95,3,4,2,0,95,96,5,4,0,0,96,123, 45 1,0,0,0,97,98,5,2,0,0,98,99,3,4,2,0,99,100,5,18,0,0,100,101,3,4, 46 2,0,101,102,5,4,0,0,102,123,1,0,0,0,103,104,5,2,0,0,104,105,3,4, 47 2,0,105,106,5,19,0,0,106,107,3,4,2,0,107,108,5,4,0,0,108,123,1,0, 48 0,0,109,110,5,2,0,0,110,115,5,26,0,0,111,112,5,3,0,0,112,114,5,26, 49 0,0,113,111,1,0,0,0,114,117,1,0,0,0,115,113,1,0,0,0,115,116,1,0, 50 0,0,116,118,1,0,0,0,117,115,1,0,0,0,118,119,5,5,0,0,119,120,3,8, 51 4,0,120,121,5,4,0,0,121,123,1,0,0,0,122,32,1,0,0,0,122,33,1,0,0, 52 0,122,34,1,0,0,0,122,35,1,0,0,0,122,36,1,0,0,0,122,37,1,0,0,0,122, 53 43,1,0,0,0,122,49,1,0,0,0,122,55,1,0,0,0,122,61,1,0,0,0,122,67,1, 54 0,0,0,122,73,1,0,0,0,122,79,1,0,0,0,122,85,1,0,0,0,122,91,1,0,0, 55 0,122,97,1,0,0,0,122,103,1,0,0,0,122,109,1,0,0,0,123,5,1,0,0,0,124, 56 125,5,26,0,0,125,126,5,2,0,0,126,131,3,4,2,0,127,128,5,3,0,0,128, 57 130,3,4,2,0,129,127,1,0,0,0,130,133,1,0,0,0,131,129,1,0,0,0,131, 58 132,1,0,0,0,132,134,1,0,0,0,133,131,1,0,0,0,134,135,5,4,0,0,135, 59 138,1,0,0,0,136,138,3,4,2,0,137,124,1,0,0,0,137,136,1,0,0,0,138, 60 7,1,0,0,0,139,140,5,20,0,0,140,141,5,26,0,0,141,142,5,21,0,0,142, 61 143,3,6,3,0,143,144,5,22,0,0,144,145,3,8,4,0,145,155,1,0,0,0,146, 62 147,5,23,0,0,147,148,3,4,2,0,148,149,5,24,0,0,149,150,3,8,4,0,150, 63 151,5,25,0,0,151,152,3,8,4,0,152,155,1,0,0,0,153,155,3,6,3,0,154, 64 139,1,0,0,0,154,146,1,0,0,0,154,153,1,0,0,0,155,9,1,0,0,0,8,13,23, 65 26,115,122,131,137,154 66 ] 67 68 class ANFParser ( Parser ): 69 70 grammarFileName = "ANF.g4" 71 72 atn = ATNDeserializer().deserialize(serializedATN()) 73 74 decisionsToDFA = [ DFA(ds, i) for i, ds in enumerate(atn.decisionToState) ] 75 76 sharedContextCache = PredictionContextCache() 77 78 literalNames = [ "<INVALID>", "'def'", "'('", "','", "')'", "':'", "'true'", 79 "'false'", "'+'", "'-'", "'*'", "'/'", "'>'", "'<'", 80 "'=='", "'<<'", "'>>'", "'&&'", "'||'", "'^^'", "'let'", 81 "'='", "'in'", "'if'", "'then'", "'else'" ] 82 83 symbolicNames = [ "<INVALID>", "<INVALID>", "<INVALID>", "<INVALID>", 84 "<INVALID>", "<INVALID>", "<INVALID>", "<INVALID>", 85 "<INVALID>", "<INVALID>", "<INVALID>", "<INVALID>", 86 "<INVALID>", "<INVALID>", "<INVALID>", "<INVALID>", 87 "<INVALID>", "<INVALID>", "<INVALID>", "<INVALID>", 88 "<INVALID>", "<INVALID>", "<INVALID>", "<INVALID>", 89 "<INVALID>", "<INVALID>", "IDENT", "NUMBER", "STRING", 90 "WS" ] 91 92 RULE_prog = 0 93 RULE_def = 1 94 RULE_aexp = 2 95 RULE_funcall = 3 96 RULE_cexp = 4 97 98 ruleNames = [ "prog", "def", "aexp", "funcall", "cexp" ] 99 100 EOF = Token.EOF 101 T__0=1 102 T__1=2 103 T__2=3 104 T__3=4 105 T__4=5 106 T__5=6 107 T__6=7 108 T__7=8 109 T__8=9 110 T__9=10 111 T__10=11 112 T__11=12 113 T__12=13 114 T__13=14 115 T__14=15 116 T__15=16 117 T__16=17 118 T__17=18 119 T__18=19 120 T__19=20 121 T__20=21 122 T__21=22 123 T__22=23 124 T__23=24 125 T__24=25 126 IDENT=26 127 NUMBER=27 128 STRING=28 129 WS=29 130 131 def __init__(self, input:TokenStream, output:TextIO = sys.stdout): 132 super().__init__(input, output) 133 self.checkVersion("4.13.1") 134 self._interp = ParserATNSimulator(self, self.atn, self.decisionsToDFA, self.sharedContextCache) 135 self._predicates = None 136 137 138 139 140 class ProgContext(ParserRuleContext): 141 __slots__ = 'parser' 142 143 def __init__(self, parser, parent:ParserRuleContext=None, invokingState:int=-1): 144 super().__init__(parent, invokingState) 145 self.parser = parser 146 147 def def_(self, i:int=None): 148 if i is None: 149 return self.getTypedRuleContexts(ANFParser.DefContext) 150 else: 151 return self.getTypedRuleContext(ANFParser.DefContext,i) 152 153 154 def getRuleIndex(self): 155 return ANFParser.RULE_prog 156 157 def enterRule(self, listener:ParseTreeListener): 158 if hasattr( listener, "enterProg" ): 159 listener.enterProg(self) 160 161 def exitRule(self, listener:ParseTreeListener): 162 if hasattr( listener, "exitProg" ): 163 listener.exitProg(self) 164 165 def accept(self, visitor:ParseTreeVisitor): 166 if hasattr( visitor, "visitProg" ): 167 return visitor.visitProg(self) 168 else: 169 return visitor.visitChildren(self) 170 171 172 173 174 def prog(self): 175 176 localctx = ANFParser.ProgContext(self, self._ctx, self.state) 177 self.enterRule(localctx, 0, self.RULE_prog) 178 self._la = 0 # Token type 179 try: 180 self.enterOuterAlt(localctx, 1) 181 self.state = 11 182 self._errHandler.sync(self) 183 _la = self._input.LA(1) 184 while True: 185 self.state = 10 186 self.def_() 187 self.state = 13 188 self._errHandler.sync(self) 189 _la = self._input.LA(1) 190 if not (_la==1): 191 break 192 193 except RecognitionException as re: 194 localctx.exception = re 195 self._errHandler.reportError(self, re) 196 self._errHandler.recover(self, re) 197 finally: 198 self.exitRule() 199 return localctx 200 201 202 class DefContext(ParserRuleContext): 203 __slots__ = 'parser' 204 205 def __init__(self, parser, parent:ParserRuleContext=None, invokingState:int=-1): 206 super().__init__(parent, invokingState) 207 self.parser = parser 208 209 def IDENT(self, i:int=None): 210 if i is None: 211 return self.getTokens(ANFParser.IDENT) 212 else: 213 return self.getToken(ANFParser.IDENT, i) 214 215 def cexp(self): 216 return self.getTypedRuleContext(ANFParser.CexpContext,0) 217 218 219 def getRuleIndex(self): 220 return ANFParser.RULE_def 221 222 def enterRule(self, listener:ParseTreeListener): 223 if hasattr( listener, "enterDef" ): 224 listener.enterDef(self) 225 226 def exitRule(self, listener:ParseTreeListener): 227 if hasattr( listener, "exitDef" ): 228 listener.exitDef(self) 229 230 def accept(self, visitor:ParseTreeVisitor): 231 if hasattr( visitor, "visitDef" ): 232 return visitor.visitDef(self) 233 else: 234 return visitor.visitChildren(self) 235 236 237 238 239 def def_(self): 240 241 localctx = ANFParser.DefContext(self, self._ctx, self.state) 242 self.enterRule(localctx, 2, self.RULE_def) 243 self._la = 0 # Token type 244 try: 245 self.enterOuterAlt(localctx, 1) 246 self.state = 15 247 self.match(ANFParser.T__0) 248 self.state = 16 249 self.match(ANFParser.IDENT) 250 self.state = 17 251 self.match(ANFParser.T__1) 252 self.state = 26 253 self._errHandler.sync(self) 254 _la = self._input.LA(1) 255 if _la==26: 256 self.state = 18 257 self.match(ANFParser.IDENT) 258 self.state = 23 259 self._errHandler.sync(self) 260 _la = self._input.LA(1) 261 while _la==3: 262 self.state = 19 263 self.match(ANFParser.T__2) 264 self.state = 20 265 self.match(ANFParser.IDENT) 266 self.state = 25 267 self._errHandler.sync(self) 268 _la = self._input.LA(1) 269 270 271 272 self.state = 28 273 self.match(ANFParser.T__3) 274 self.state = 29 275 self.match(ANFParser.T__4) 276 self.state = 30 277 self.cexp() 278 except RecognitionException as re: 279 localctx.exception = re 280 self._errHandler.reportError(self, re) 281 self._errHandler.recover(self, re) 282 finally: 283 self.exitRule() 284 return localctx 285 286 287 class AexpContext(ParserRuleContext): 288 __slots__ = 'parser' 289 290 def __init__(self, parser, parent:ParserRuleContext=None, invokingState:int=-1): 291 super().__init__(parent, invokingState) 292 self.parser = parser 293 294 295 def getRuleIndex(self): 296 return ANFParser.RULE_aexp 297 298 299 def copyFrom(self, ctx:ParserRuleContext): 300 super().copyFrom(ctx) 301 302 303 304 class AddContext(AexpContext): 305 306 def __init__(self, parser, ctx:ParserRuleContext): # actually a ANFParser.AexpContext 307 super().__init__(parser) 308 self.copyFrom(ctx) 309 310 def aexp(self, i:int=None): 311 if i is None: 312 return self.getTypedRuleContexts(ANFParser.AexpContext) 313 else: 314 return self.getTypedRuleContext(ANFParser.AexpContext,i) 315 316 317 def enterRule(self, listener:ParseTreeListener): 318 if hasattr( listener, "enterAdd" ): 319 listener.enterAdd(self) 320 321 def exitRule(self, listener:ParseTreeListener): 322 if hasattr( listener, "exitAdd" ): 323 listener.exitAdd(self) 324 325 def accept(self, visitor:ParseTreeVisitor): 326 if hasattr( visitor, "visitAdd" ): 327 return visitor.visitAdd(self) 328 else: 329 return visitor.visitChildren(self) 330 331 332 class BsrContext(AexpContext): 333 334 def __init__(self, parser, ctx:ParserRuleContext): # actually a ANFParser.AexpContext 335 super().__init__(parser) 336 self.copyFrom(ctx) 337 338 def aexp(self, i:int=None): 339 if i is None: 340 return self.getTypedRuleContexts(ANFParser.AexpContext) 341 else: 342 return self.getTypedRuleContext(ANFParser.AexpContext,i) 343 344 345 def enterRule(self, listener:ParseTreeListener): 346 if hasattr( listener, "enterBsr" ): 347 listener.enterBsr(self) 348 349 def exitRule(self, listener:ParseTreeListener): 350 if hasattr( listener, "exitBsr" ): 351 listener.exitBsr(self) 352 353 def accept(self, visitor:ParseTreeVisitor): 354 if hasattr( visitor, "visitBsr" ): 355 return visitor.visitBsr(self) 356 else: 357 return visitor.visitChildren(self) 358 359 360 class SubContext(AexpContext): 361 362 def __init__(self, parser, ctx:ParserRuleContext): # actually a ANFParser.AexpContext 363 super().__init__(parser) 364 self.copyFrom(ctx) 365 366 def aexp(self, i:int=None): 367 if i is None: 368 return self.getTypedRuleContexts(ANFParser.AexpContext) 369 else: 370 return self.getTypedRuleContext(ANFParser.AexpContext,i) 371 372 373 def enterRule(self, listener:ParseTreeListener): 374 if hasattr( listener, "enterSub" ): 375 listener.enterSub(self) 376 377 def exitRule(self, listener:ParseTreeListener): 378 if hasattr( listener, "exitSub" ): 379 listener.exitSub(self) 380 381 def accept(self, visitor:ParseTreeVisitor): 382 if hasattr( visitor, "visitSub" ): 383 return visitor.visitSub(self) 384 else: 385 return visitor.visitChildren(self) 386 387 388 class OrContext(AexpContext): 389 390 def __init__(self, parser, ctx:ParserRuleContext): # actually a ANFParser.AexpContext 391 super().__init__(parser) 392 self.copyFrom(ctx) 393 394 def aexp(self, i:int=None): 395 if i is None: 396 return self.getTypedRuleContexts(ANFParser.AexpContext) 397 else: 398 return self.getTypedRuleContext(ANFParser.AexpContext,i) 399 400 401 def enterRule(self, listener:ParseTreeListener): 402 if hasattr( listener, "enterOr" ): 403 listener.enterOr(self) 404 405 def exitRule(self, listener:ParseTreeListener): 406 if hasattr( listener, "exitOr" ): 407 listener.exitOr(self) 408 409 def accept(self, visitor:ParseTreeVisitor): 410 if hasattr( visitor, "visitOr" ): 411 return visitor.visitOr(self) 412 else: 413 return visitor.visitChildren(self) 414 415 416 class MulContext(AexpContext): 417 418 def __init__(self, parser, ctx:ParserRuleContext): # actually a ANFParser.AexpContext 419 super().__init__(parser) 420 self.copyFrom(ctx) 421 422 def aexp(self, i:int=None): 423 if i is None: 424 return self.getTypedRuleContexts(ANFParser.AexpContext) 425 else: 426 return self.getTypedRuleContext(ANFParser.AexpContext,i) 427 428 429 def enterRule(self, listener:ParseTreeListener): 430 if hasattr( listener, "enterMul" ): 431 listener.enterMul(self) 432 433 def exitRule(self, listener:ParseTreeListener): 434 if hasattr( listener, "exitMul" ): 435 listener.exitMul(self) 436 437 def accept(self, visitor:ParseTreeVisitor): 438 if hasattr( visitor, "visitMul" ): 439 return visitor.visitMul(self) 440 else: 441 return visitor.visitChildren(self) 442 443 444 class VarContext(AexpContext): 445 446 def __init__(self, parser, ctx:ParserRuleContext): # actually a ANFParser.AexpContext 447 super().__init__(parser) 448 self.copyFrom(ctx) 449 450 def IDENT(self): 451 return self.getToken(ANFParser.IDENT, 0) 452 453 def enterRule(self, listener:ParseTreeListener): 454 if hasattr( listener, "enterVar" ): 455 listener.enterVar(self) 456 457 def exitRule(self, listener:ParseTreeListener): 458 if hasattr( listener, "exitVar" ): 459 listener.exitVar(self) 460 461 def accept(self, visitor:ParseTreeVisitor): 462 if hasattr( visitor, "visitVar" ): 463 return visitor.visitVar(self) 464 else: 465 return visitor.visitChildren(self) 466 467 468 class NumContext(AexpContext): 469 470 def __init__(self, parser, ctx:ParserRuleContext): # actually a ANFParser.AexpContext 471 super().__init__(parser) 472 self.copyFrom(ctx) 473 474 def NUMBER(self): 475 return self.getToken(ANFParser.NUMBER, 0) 476 477 def enterRule(self, listener:ParseTreeListener): 478 if hasattr( listener, "enterNum" ): 479 listener.enterNum(self) 480 481 def exitRule(self, listener:ParseTreeListener): 482 if hasattr( listener, "exitNum" ): 483 listener.exitNum(self) 484 485 def accept(self, visitor:ParseTreeVisitor): 486 if hasattr( visitor, "visitNum" ): 487 return visitor.visitNum(self) 488 else: 489 return visitor.visitChildren(self) 490 491 492 class FalseContext(AexpContext): 493 494 def __init__(self, parser, ctx:ParserRuleContext): # actually a ANFParser.AexpContext 495 super().__init__(parser) 496 self.copyFrom(ctx) 497 498 499 def enterRule(self, listener:ParseTreeListener): 500 if hasattr( listener, "enterFalse" ): 501 listener.enterFalse(self) 502 503 def exitRule(self, listener:ParseTreeListener): 504 if hasattr( listener, "exitFalse" ): 505 listener.exitFalse(self) 506 507 def accept(self, visitor:ParseTreeVisitor): 508 if hasattr( visitor, "visitFalse" ): 509 return visitor.visitFalse(self) 510 else: 511 return visitor.visitChildren(self) 512 513 514 class LtContext(AexpContext): 515 516 def __init__(self, parser, ctx:ParserRuleContext): # actually a ANFParser.AexpContext 517 super().__init__(parser) 518 self.copyFrom(ctx) 519 520 def aexp(self, i:int=None): 521 if i is None: 522 return self.getTypedRuleContexts(ANFParser.AexpContext) 523 else: 524 return self.getTypedRuleContext(ANFParser.AexpContext,i) 525 526 527 def enterRule(self, listener:ParseTreeListener): 528 if hasattr( listener, "enterLt" ): 529 listener.enterLt(self) 530 531 def exitRule(self, listener:ParseTreeListener): 532 if hasattr( listener, "exitLt" ): 533 listener.exitLt(self) 534 535 def accept(self, visitor:ParseTreeVisitor): 536 if hasattr( visitor, "visitLt" ): 537 return visitor.visitLt(self) 538 else: 539 return visitor.visitChildren(self) 540 541 542 class EqContext(AexpContext): 543 544 def __init__(self, parser, ctx:ParserRuleContext): # actually a ANFParser.AexpContext 545 super().__init__(parser) 546 self.copyFrom(ctx) 547 548 def aexp(self, i:int=None): 549 if i is None: 550 return self.getTypedRuleContexts(ANFParser.AexpContext) 551 else: 552 return self.getTypedRuleContext(ANFParser.AexpContext,i) 553 554 555 def enterRule(self, listener:ParseTreeListener): 556 if hasattr( listener, "enterEq" ): 557 listener.enterEq(self) 558 559 def exitRule(self, listener:ParseTreeListener): 560 if hasattr( listener, "exitEq" ): 561 listener.exitEq(self) 562 563 def accept(self, visitor:ParseTreeVisitor): 564 if hasattr( visitor, "visitEq" ): 565 return visitor.visitEq(self) 566 else: 567 return visitor.visitChildren(self) 568 569 570 class GtContext(AexpContext): 571 572 def __init__(self, parser, ctx:ParserRuleContext): # actually a ANFParser.AexpContext 573 super().__init__(parser) 574 self.copyFrom(ctx) 575 576 def aexp(self, i:int=None): 577 if i is None: 578 return self.getTypedRuleContexts(ANFParser.AexpContext) 579 else: 580 return self.getTypedRuleContext(ANFParser.AexpContext,i) 581 582 583 def enterRule(self, listener:ParseTreeListener): 584 if hasattr( listener, "enterGt" ): 585 listener.enterGt(self) 586 587 def exitRule(self, listener:ParseTreeListener): 588 if hasattr( listener, "exitGt" ): 589 listener.exitGt(self) 590 591 def accept(self, visitor:ParseTreeVisitor): 592 if hasattr( visitor, "visitGt" ): 593 return visitor.visitGt(self) 594 else: 595 return visitor.visitChildren(self) 596 597 598 class StrContext(AexpContext): 599 600 def __init__(self, parser, ctx:ParserRuleContext): # actually a ANFParser.AexpContext 601 super().__init__(parser) 602 self.copyFrom(ctx) 603 604 def STRING(self): 605 return self.getToken(ANFParser.STRING, 0) 606 607 def enterRule(self, listener:ParseTreeListener): 608 if hasattr( listener, "enterStr" ): 609 listener.enterStr(self) 610 611 def exitRule(self, listener:ParseTreeListener): 612 if hasattr( listener, "exitStr" ): 613 listener.exitStr(self) 614 615 def accept(self, visitor:ParseTreeVisitor): 616 if hasattr( visitor, "visitStr" ): 617 return visitor.visitStr(self) 618 else: 619 return visitor.visitChildren(self) 620 621 622 class DivContext(AexpContext): 623 624 def __init__(self, parser, ctx:ParserRuleContext): # actually a ANFParser.AexpContext 625 super().__init__(parser) 626 self.copyFrom(ctx) 627 628 def aexp(self, i:int=None): 629 if i is None: 630 return self.getTypedRuleContexts(ANFParser.AexpContext) 631 else: 632 return self.getTypedRuleContext(ANFParser.AexpContext,i) 633 634 635 def enterRule(self, listener:ParseTreeListener): 636 if hasattr( listener, "enterDiv" ): 637 listener.enterDiv(self) 638 639 def exitRule(self, listener:ParseTreeListener): 640 if hasattr( listener, "exitDiv" ): 641 listener.exitDiv(self) 642 643 def accept(self, visitor:ParseTreeVisitor): 644 if hasattr( visitor, "visitDiv" ): 645 return visitor.visitDiv(self) 646 else: 647 return visitor.visitChildren(self) 648 649 650 class AndContext(AexpContext): 651 652 def __init__(self, parser, ctx:ParserRuleContext): # actually a ANFParser.AexpContext 653 super().__init__(parser) 654 self.copyFrom(ctx) 655 656 def aexp(self, i:int=None): 657 if i is None: 658 return self.getTypedRuleContexts(ANFParser.AexpContext) 659 else: 660 return self.getTypedRuleContext(ANFParser.AexpContext,i) 661 662 663 def enterRule(self, listener:ParseTreeListener): 664 if hasattr( listener, "enterAnd" ): 665 listener.enterAnd(self) 666 667 def exitRule(self, listener:ParseTreeListener): 668 if hasattr( listener, "exitAnd" ): 669 listener.exitAnd(self) 670 671 def accept(self, visitor:ParseTreeVisitor): 672 if hasattr( visitor, "visitAnd" ): 673 return visitor.visitAnd(self) 674 else: 675 return visitor.visitChildren(self) 676 677 678 class TrueContext(AexpContext): 679 680 def __init__(self, parser, ctx:ParserRuleContext): # actually a ANFParser.AexpContext 681 super().__init__(parser) 682 self.copyFrom(ctx) 683 684 685 def enterRule(self, listener:ParseTreeListener): 686 if hasattr( listener, "enterTrue" ): 687 listener.enterTrue(self) 688 689 def exitRule(self, listener:ParseTreeListener): 690 if hasattr( listener, "exitTrue" ): 691 listener.exitTrue(self) 692 693 def accept(self, visitor:ParseTreeVisitor): 694 if hasattr( visitor, "visitTrue" ): 695 return visitor.visitTrue(self) 696 else: 697 return visitor.visitChildren(self) 698 699 700 class LamContext(AexpContext): 701 702 def __init__(self, parser, ctx:ParserRuleContext): # actually a ANFParser.AexpContext 703 super().__init__(parser) 704 self.copyFrom(ctx) 705 706 def IDENT(self, i:int=None): 707 if i is None: 708 return self.getTokens(ANFParser.IDENT) 709 else: 710 return self.getToken(ANFParser.IDENT, i) 711 def cexp(self): 712 return self.getTypedRuleContext(ANFParser.CexpContext,0) 713 714 715 def enterRule(self, listener:ParseTreeListener): 716 if hasattr( listener, "enterLam" ): 717 listener.enterLam(self) 718 719 def exitRule(self, listener:ParseTreeListener): 720 if hasattr( listener, "exitLam" ): 721 listener.exitLam(self) 722 723 def accept(self, visitor:ParseTreeVisitor): 724 if hasattr( visitor, "visitLam" ): 725 return visitor.visitLam(self) 726 else: 727 return visitor.visitChildren(self) 728 729 730 class BslContext(AexpContext): 731 732 def __init__(self, parser, ctx:ParserRuleContext): # actually a ANFParser.AexpContext 733 super().__init__(parser) 734 self.copyFrom(ctx) 735 736 def aexp(self, i:int=None): 737 if i is None: 738 return self.getTypedRuleContexts(ANFParser.AexpContext) 739 else: 740 return self.getTypedRuleContext(ANFParser.AexpContext,i) 741 742 743 def enterRule(self, listener:ParseTreeListener): 744 if hasattr( listener, "enterBsl" ): 745 listener.enterBsl(self) 746 747 def exitRule(self, listener:ParseTreeListener): 748 if hasattr( listener, "exitBsl" ): 749 listener.exitBsl(self) 750 751 def accept(self, visitor:ParseTreeVisitor): 752 if hasattr( visitor, "visitBsl" ): 753 return visitor.visitBsl(self) 754 else: 755 return visitor.visitChildren(self) 756 757 758 class XorContext(AexpContext): 759 760 def __init__(self, parser, ctx:ParserRuleContext): # actually a ANFParser.AexpContext 761 super().__init__(parser) 762 self.copyFrom(ctx) 763 764 def aexp(self, i:int=None): 765 if i is None: 766 return self.getTypedRuleContexts(ANFParser.AexpContext) 767 else: 768 return self.getTypedRuleContext(ANFParser.AexpContext,i) 769 770 771 def enterRule(self, listener:ParseTreeListener): 772 if hasattr( listener, "enterXor" ): 773 listener.enterXor(self) 774 775 def exitRule(self, listener:ParseTreeListener): 776 if hasattr( listener, "exitXor" ): 777 listener.exitXor(self) 778 779 def accept(self, visitor:ParseTreeVisitor): 780 if hasattr( visitor, "visitXor" ): 781 return visitor.visitXor(self) 782 else: 783 return visitor.visitChildren(self) 784 785 786 787 def aexp(self): 788 789 localctx = ANFParser.AexpContext(self, self._ctx, self.state) 790 self.enterRule(localctx, 4, self.RULE_aexp) 791 self._la = 0 # Token type 792 try: 793 self.state = 122 794 self._errHandler.sync(self) 795 la_ = self._interp.adaptivePredict(self._input,4,self._ctx) 796 if la_ == 1: 797 localctx = ANFParser.TrueContext(self, localctx) 798 self.enterOuterAlt(localctx, 1) 799 self.state = 32 800 self.match(ANFParser.T__5) 801 pass 802 803 elif la_ == 2: 804 localctx = ANFParser.FalseContext(self, localctx) 805 self.enterOuterAlt(localctx, 2) 806 self.state = 33 807 self.match(ANFParser.T__6) 808 pass 809 810 elif la_ == 3: 811 localctx = ANFParser.VarContext(self, localctx) 812 self.enterOuterAlt(localctx, 3) 813 self.state = 34 814 self.match(ANFParser.IDENT) 815 pass 816 817 elif la_ == 4: 818 localctx = ANFParser.NumContext(self, localctx) 819 self.enterOuterAlt(localctx, 4) 820 self.state = 35 821 self.match(ANFParser.NUMBER) 822 pass 823 824 elif la_ == 5: 825 localctx = ANFParser.StrContext(self, localctx) 826 self.enterOuterAlt(localctx, 5) 827 self.state = 36 828 self.match(ANFParser.STRING) 829 pass 830 831 elif la_ == 6: 832 localctx = ANFParser.AddContext(self, localctx) 833 self.enterOuterAlt(localctx, 6) 834 self.state = 37 835 self.match(ANFParser.T__1) 836 self.state = 38 837 self.aexp() 838 self.state = 39 839 self.match(ANFParser.T__7) 840 self.state = 40 841 self.aexp() 842 self.state = 41 843 self.match(ANFParser.T__3) 844 pass 845 846 elif la_ == 7: 847 localctx = ANFParser.SubContext(self, localctx) 848 self.enterOuterAlt(localctx, 7) 849 self.state = 43 850 self.match(ANFParser.T__1) 851 self.state = 44 852 self.aexp() 853 self.state = 45 854 self.match(ANFParser.T__8) 855 self.state = 46 856 self.aexp() 857 self.state = 47 858 self.match(ANFParser.T__3) 859 pass 860 861 elif la_ == 8: 862 localctx = ANFParser.MulContext(self, localctx) 863 self.enterOuterAlt(localctx, 8) 864 self.state = 49 865 self.match(ANFParser.T__1) 866 self.state = 50 867 self.aexp() 868 self.state = 51 869 self.match(ANFParser.T__9) 870 self.state = 52 871 self.aexp() 872 self.state = 53 873 self.match(ANFParser.T__3) 874 pass 875 876 elif la_ == 9: 877 localctx = ANFParser.DivContext(self, localctx) 878 self.enterOuterAlt(localctx, 9) 879 self.state = 55 880 self.match(ANFParser.T__1) 881 self.state = 56 882 self.aexp() 883 self.state = 57 884 self.match(ANFParser.T__10) 885 self.state = 58 886 self.aexp() 887 self.state = 59 888 self.match(ANFParser.T__3) 889 pass 890 891 elif la_ == 10: 892 localctx = ANFParser.GtContext(self, localctx) 893 self.enterOuterAlt(localctx, 10) 894 self.state = 61 895 self.match(ANFParser.T__1) 896 self.state = 62 897 self.aexp() 898 self.state = 63 899 self.match(ANFParser.T__11) 900 self.state = 64 901 self.aexp() 902 self.state = 65 903 self.match(ANFParser.T__3) 904 pass 905 906 elif la_ == 11: 907 localctx = ANFParser.LtContext(self, localctx) 908 self.enterOuterAlt(localctx, 11) 909 self.state = 67 910 self.match(ANFParser.T__1) 911 self.state = 68 912 self.aexp() 913 self.state = 69 914 self.match(ANFParser.T__12) 915 self.state = 70 916 self.aexp() 917 self.state = 71 918 self.match(ANFParser.T__3) 919 pass 920 921 elif la_ == 12: 922 localctx = ANFParser.EqContext(self, localctx) 923 self.enterOuterAlt(localctx, 12) 924 self.state = 73 925 self.match(ANFParser.T__1) 926 self.state = 74 927 self.aexp() 928 self.state = 75 929 self.match(ANFParser.T__13) 930 self.state = 76 931 self.aexp() 932 self.state = 77 933 self.match(ANFParser.T__3) 934 pass 935 936 elif la_ == 13: 937 localctx = ANFParser.BslContext(self, localctx) 938 self.enterOuterAlt(localctx, 13) 939 self.state = 79 940 self.match(ANFParser.T__1) 941 self.state = 80 942 self.aexp() 943 self.state = 81 944 self.match(ANFParser.T__14) 945 self.state = 82 946 self.aexp() 947 self.state = 83 948 self.match(ANFParser.T__3) 949 pass 950 951 elif la_ == 14: 952 localctx = ANFParser.BsrContext(self, localctx) 953 self.enterOuterAlt(localctx, 14) 954 self.state = 85 955 self.match(ANFParser.T__1) 956 self.state = 86 957 self.aexp() 958 self.state = 87 959 self.match(ANFParser.T__15) 960 self.state = 88 961 self.aexp() 962 self.state = 89 963 self.match(ANFParser.T__3) 964 pass 965 966 elif la_ == 15: 967 localctx = ANFParser.AndContext(self, localctx) 968 self.enterOuterAlt(localctx, 15) 969 self.state = 91 970 self.match(ANFParser.T__1) 971 self.state = 92 972 self.aexp() 973 self.state = 93 974 self.match(ANFParser.T__16) 975 self.state = 94 976 self.aexp() 977 self.state = 95 978 self.match(ANFParser.T__3) 979 pass 980 981 elif la_ == 16: 982 localctx = ANFParser.OrContext(self, localctx) 983 self.enterOuterAlt(localctx, 16) 984 self.state = 97 985 self.match(ANFParser.T__1) 986 self.state = 98 987 self.aexp() 988 self.state = 99 989 self.match(ANFParser.T__17) 990 self.state = 100 991 self.aexp() 992 self.state = 101 993 self.match(ANFParser.T__3) 994 pass 995 996 elif la_ == 17: 997 localctx = ANFParser.XorContext(self, localctx) 998 self.enterOuterAlt(localctx, 17) 999 self.state = 103 1000 self.match(ANFParser.T__1) 1001 self.state = 104 1002 self.aexp() 1003 self.state = 105 1004 self.match(ANFParser.T__18) 1005 self.state = 106 1006 self.aexp() 1007 self.state = 107 1008 self.match(ANFParser.T__3) 1009 pass 1010 1011 elif la_ == 18: 1012 localctx = ANFParser.LamContext(self, localctx) 1013 self.enterOuterAlt(localctx, 18) 1014 self.state = 109 1015 self.match(ANFParser.T__1) 1016 self.state = 110 1017 self.match(ANFParser.IDENT) 1018 self.state = 115 1019 self._errHandler.sync(self) 1020 _la = self._input.LA(1) 1021 while _la==3: 1022 self.state = 111 1023 self.match(ANFParser.T__2) 1024 self.state = 112 1025 self.match(ANFParser.IDENT) 1026 self.state = 117 1027 self._errHandler.sync(self) 1028 _la = self._input.LA(1) 1029 1030 self.state = 118 1031 self.match(ANFParser.T__4) 1032 self.state = 119 1033 self.cexp() 1034 self.state = 120 1035 self.match(ANFParser.T__3) 1036 pass 1037 1038 1039 except RecognitionException as re: 1040 localctx.exception = re 1041 self._errHandler.reportError(self, re) 1042 self._errHandler.recover(self, re) 1043 finally: 1044 self.exitRule() 1045 return localctx 1046 1047 1048 class FuncallContext(ParserRuleContext): 1049 __slots__ = 'parser' 1050 1051 def __init__(self, parser, parent:ParserRuleContext=None, invokingState:int=-1): 1052 super().__init__(parent, invokingState) 1053 self.parser = parser 1054 1055 1056 def getRuleIndex(self): 1057 return ANFParser.RULE_funcall 1058 1059 1060 def copyFrom(self, ctx:ParserRuleContext): 1061 super().copyFrom(ctx) 1062 1063 1064 1065 class CallContext(FuncallContext): 1066 1067 def __init__(self, parser, ctx:ParserRuleContext): # actually a ANFParser.FuncallContext 1068 super().__init__(parser) 1069 self.copyFrom(ctx) 1070 1071 def IDENT(self): 1072 return self.getToken(ANFParser.IDENT, 0) 1073 def aexp(self, i:int=None): 1074 if i is None: 1075 return self.getTypedRuleContexts(ANFParser.AexpContext) 1076 else: 1077 return self.getTypedRuleContext(ANFParser.AexpContext,i) 1078 1079 1080 def enterRule(self, listener:ParseTreeListener): 1081 if hasattr( listener, "enterCall" ): 1082 listener.enterCall(self) 1083 1084 def exitRule(self, listener:ParseTreeListener): 1085 if hasattr( listener, "exitCall" ): 1086 listener.exitCall(self) 1087 1088 def accept(self, visitor:ParseTreeVisitor): 1089 if hasattr( visitor, "visitCall" ): 1090 return visitor.visitCall(self) 1091 else: 1092 return visitor.visitChildren(self) 1093 1094 1095 class AtomContext(FuncallContext): 1096 1097 def __init__(self, parser, ctx:ParserRuleContext): # actually a ANFParser.FuncallContext 1098 super().__init__(parser) 1099 self.copyFrom(ctx) 1100 1101 def aexp(self): 1102 return self.getTypedRuleContext(ANFParser.AexpContext,0) 1103 1104 1105 def enterRule(self, listener:ParseTreeListener): 1106 if hasattr( listener, "enterAtom" ): 1107 listener.enterAtom(self) 1108 1109 def exitRule(self, listener:ParseTreeListener): 1110 if hasattr( listener, "exitAtom" ): 1111 listener.exitAtom(self) 1112 1113 def accept(self, visitor:ParseTreeVisitor): 1114 if hasattr( visitor, "visitAtom" ): 1115 return visitor.visitAtom(self) 1116 else: 1117 return visitor.visitChildren(self) 1118 1119 1120 1121 def funcall(self): 1122 1123 localctx = ANFParser.FuncallContext(self, self._ctx, self.state) 1124 self.enterRule(localctx, 6, self.RULE_funcall) 1125 self._la = 0 # Token type 1126 try: 1127 self.state = 137 1128 self._errHandler.sync(self) 1129 la_ = self._interp.adaptivePredict(self._input,6,self._ctx) 1130 if la_ == 1: 1131 localctx = ANFParser.CallContext(self, localctx) 1132 self.enterOuterAlt(localctx, 1) 1133 self.state = 124 1134 self.match(ANFParser.IDENT) 1135 self.state = 125 1136 self.match(ANFParser.T__1) 1137 self.state = 126 1138 self.aexp() 1139 self.state = 131 1140 self._errHandler.sync(self) 1141 _la = self._input.LA(1) 1142 while _la==3: 1143 self.state = 127 1144 self.match(ANFParser.T__2) 1145 self.state = 128 1146 self.aexp() 1147 self.state = 133 1148 self._errHandler.sync(self) 1149 _la = self._input.LA(1) 1150 1151 self.state = 134 1152 self.match(ANFParser.T__3) 1153 pass 1154 1155 elif la_ == 2: 1156 localctx = ANFParser.AtomContext(self, localctx) 1157 self.enterOuterAlt(localctx, 2) 1158 self.state = 136 1159 self.aexp() 1160 pass 1161 1162 1163 except RecognitionException as re: 1164 localctx.exception = re 1165 self._errHandler.reportError(self, re) 1166 self._errHandler.recover(self, re) 1167 finally: 1168 self.exitRule() 1169 return localctx 1170 1171 1172 class CexpContext(ParserRuleContext): 1173 __slots__ = 'parser' 1174 1175 def __init__(self, parser, parent:ParserRuleContext=None, invokingState:int=-1): 1176 super().__init__(parent, invokingState) 1177 self.parser = parser 1178 1179 1180 def getRuleIndex(self): 1181 return ANFParser.RULE_cexp 1182 1183 1184 def copyFrom(self, ctx:ParserRuleContext): 1185 super().copyFrom(ctx) 1186 1187 1188 1189 class LetContext(CexpContext): 1190 1191 def __init__(self, parser, ctx:ParserRuleContext): # actually a ANFParser.CexpContext 1192 super().__init__(parser) 1193 self.copyFrom(ctx) 1194 1195 def IDENT(self): 1196 return self.getToken(ANFParser.IDENT, 0) 1197 def funcall(self): 1198 return self.getTypedRuleContext(ANFParser.FuncallContext,0) 1199 1200 def cexp(self): 1201 return self.getTypedRuleContext(ANFParser.CexpContext,0) 1202 1203 1204 def enterRule(self, listener:ParseTreeListener): 1205 if hasattr( listener, "enterLet" ): 1206 listener.enterLet(self) 1207 1208 def exitRule(self, listener:ParseTreeListener): 1209 if hasattr( listener, "exitLet" ): 1210 listener.exitLet(self) 1211 1212 def accept(self, visitor:ParseTreeVisitor): 1213 if hasattr( visitor, "visitLet" ): 1214 return visitor.visitLet(self) 1215 else: 1216 return visitor.visitChildren(self) 1217 1218 1219 class IfContext(CexpContext): 1220 1221 def __init__(self, parser, ctx:ParserRuleContext): # actually a ANFParser.CexpContext 1222 super().__init__(parser) 1223 self.copyFrom(ctx) 1224 1225 def aexp(self): 1226 return self.getTypedRuleContext(ANFParser.AexpContext,0) 1227 1228 def cexp(self, i:int=None): 1229 if i is None: 1230 return self.getTypedRuleContexts(ANFParser.CexpContext) 1231 else: 1232 return self.getTypedRuleContext(ANFParser.CexpContext,i) 1233 1234 1235 def enterRule(self, listener:ParseTreeListener): 1236 if hasattr( listener, "enterIf" ): 1237 listener.enterIf(self) 1238 1239 def exitRule(self, listener:ParseTreeListener): 1240 if hasattr( listener, "exitIf" ): 1241 listener.exitIf(self) 1242 1243 def accept(self, visitor:ParseTreeVisitor): 1244 if hasattr( visitor, "visitIf" ): 1245 return visitor.visitIf(self) 1246 else: 1247 return visitor.visitChildren(self) 1248 1249 1250 class FcContext(CexpContext): 1251 1252 def __init__(self, parser, ctx:ParserRuleContext): # actually a ANFParser.CexpContext 1253 super().__init__(parser) 1254 self.copyFrom(ctx) 1255 1256 def funcall(self): 1257 return self.getTypedRuleContext(ANFParser.FuncallContext,0) 1258 1259 1260 def enterRule(self, listener:ParseTreeListener): 1261 if hasattr( listener, "enterFc" ): 1262 listener.enterFc(self) 1263 1264 def exitRule(self, listener:ParseTreeListener): 1265 if hasattr( listener, "exitFc" ): 1266 listener.exitFc(self) 1267 1268 def accept(self, visitor:ParseTreeVisitor): 1269 if hasattr( visitor, "visitFc" ): 1270 return visitor.visitFc(self) 1271 else: 1272 return visitor.visitChildren(self) 1273 1274 1275 1276 def cexp(self): 1277 1278 localctx = ANFParser.CexpContext(self, self._ctx, self.state) 1279 self.enterRule(localctx, 8, self.RULE_cexp) 1280 try: 1281 self.state = 154 1282 self._errHandler.sync(self) 1283 token = self._input.LA(1) 1284 if token in [20]: 1285 localctx = ANFParser.LetContext(self, localctx) 1286 self.enterOuterAlt(localctx, 1) 1287 self.state = 139 1288 self.match(ANFParser.T__19) 1289 self.state = 140 1290 self.match(ANFParser.IDENT) 1291 self.state = 141 1292 self.match(ANFParser.T__20) 1293 self.state = 142 1294 self.funcall() 1295 self.state = 143 1296 self.match(ANFParser.T__21) 1297 self.state = 144 1298 self.cexp() 1299 pass 1300 elif token in [23]: 1301 localctx = ANFParser.IfContext(self, localctx) 1302 self.enterOuterAlt(localctx, 2) 1303 self.state = 146 1304 self.match(ANFParser.T__22) 1305 self.state = 147 1306 self.aexp() 1307 self.state = 148 1308 self.match(ANFParser.T__23) 1309 self.state = 149 1310 self.cexp() 1311 self.state = 150 1312 self.match(ANFParser.T__24) 1313 self.state = 151 1314 self.cexp() 1315 pass 1316 elif token in [2, 6, 7, 26, 27, 28]: 1317 localctx = ANFParser.FcContext(self, localctx) 1318 self.enterOuterAlt(localctx, 3) 1319 self.state = 153 1320 self.funcall() 1321 pass 1322 else: 1323 raise NoViableAltException(self) 1324 1325 except RecognitionException as re: 1326 localctx.exception = re 1327 self._errHandler.reportError(self, re) 1328 self._errHandler.recover(self, re) 1329 finally: 1330 self.exitRule() 1331 return localctx 1332 1333 1334 1335 1336