1# Generated from gn.g4 by ANTLR 4.7.1 2# encoding: utf-8 3from __future__ import print_function 4from antlr4 import * 5from io import StringIO 6import sys 7 8def serializedATN(): 9 with StringIO() as buf: 10 buf.write(u"\3\u608b\ua72a\u8133\ub9ed\u417c\u3be7\u7786\u5964\3") 11 buf.write(u"\24\u008e\4\2\t\2\4\3\t\3\4\4\t\4\4\5\t\5\4\6\t\6\4\7") 12 buf.write(u"\t\7\4\b\t\b\4\t\t\t\4\n\t\n\4\13\t\13\4\f\t\f\4\r\t") 13 buf.write(u"\r\4\16\t\16\4\17\t\17\4\20\t\20\4\21\t\21\3\2\3\2\3") 14 buf.write(u"\2\3\3\3\3\3\3\5\3)\n\3\3\4\3\4\3\4\5\4.\n\4\3\5\3\5") 15 buf.write(u"\3\5\3\5\3\6\3\6\3\6\5\6\67\n\6\3\6\3\6\5\6;\n\6\3\7") 16 buf.write(u"\3\7\3\7\3\7\3\7\3\7\3\7\3\7\5\7E\n\7\5\7G\n\7\3\b\3") 17 buf.write(u"\b\3\b\3\b\3\t\3\t\7\tO\n\t\f\t\16\tR\13\t\3\n\3\n\3") 18 buf.write(u"\n\3\n\3\n\3\13\3\13\3\13\3\13\3\f\3\f\3\f\3\f\3\f\3") 19 buf.write(u"\f\7\fc\n\f\f\f\16\ff\13\f\3\r\3\r\3\r\5\rk\n\r\3\16") 20 buf.write(u"\3\16\3\16\3\16\3\16\3\16\3\16\3\16\3\16\3\16\3\16\3") 21 buf.write(u"\16\3\16\3\16\5\16{\n\16\5\16}\n\16\3\16\5\16\u0080\n") 22 buf.write(u"\16\3\17\3\17\3\17\7\17\u0085\n\17\f\17\16\17\u0088\13") 23 buf.write(u"\17\3\20\3\20\3\21\3\21\3\21\2\3\26\22\2\4\6\b\n\f\16") 24 buf.write(u"\20\22\24\26\30\32\34\36 \2\2\2\u0094\2\"\3\2\2\2\4(") 25 buf.write(u"\3\2\2\2\6-\3\2\2\2\b/\3\2\2\2\n\63\3\2\2\2\f<\3\2\2") 26 buf.write(u"\2\16H\3\2\2\2\20P\3\2\2\2\22S\3\2\2\2\24X\3\2\2\2\26") 27 buf.write(u"\\\3\2\2\2\30j\3\2\2\2\32\177\3\2\2\2\34\u0081\3\2\2") 28 buf.write(u"\2\36\u0089\3\2\2\2 \u008b\3\2\2\2\"#\5\20\t\2#$\7\2") 29 buf.write(u"\2\3$\3\3\2\2\2%)\5\b\5\2&)\5\n\6\2\')\5\f\7\2(%\3\2") 30 buf.write(u"\2\2(&\3\2\2\2(\'\3\2\2\2)\5\3\2\2\2*.\7\20\2\2+.\5\22") 31 buf.write(u"\n\2,.\5\24\13\2-*\3\2\2\2-+\3\2\2\2-,\3\2\2\2.\7\3\2") 32 buf.write(u"\2\2/\60\5\6\4\2\60\61\7\r\2\2\61\62\5\26\f\2\62\t\3") 33 buf.write(u"\2\2\2\63\64\7\20\2\2\64\66\7\3\2\2\65\67\5\34\17\2\66") 34 buf.write(u"\65\3\2\2\2\66\67\3\2\2\2\678\3\2\2\28:\7\4\2\29;\5\16") 35 buf.write(u"\b\2:9\3\2\2\2:;\3\2\2\2;\13\3\2\2\2<=\7\5\2\2=>\7\3") 36 buf.write(u"\2\2>?\5\26\f\2?@\7\4\2\2@F\5\16\b\2AD\5\36\20\2BE\5") 37 buf.write(u"\f\7\2CE\5\16\b\2DB\3\2\2\2DC\3\2\2\2EG\3\2\2\2FA\3\2") 38 buf.write(u"\2\2FG\3\2\2\2G\r\3\2\2\2HI\7\6\2\2IJ\5\20\t\2JK\7\7") 39 buf.write(u"\2\2K\17\3\2\2\2LO\5\4\3\2MO\5 \21\2NL\3\2\2\2NM\3\2") 40 buf.write(u"\2\2OR\3\2\2\2PN\3\2\2\2PQ\3\2\2\2Q\21\3\2\2\2RP\3\2") 41 buf.write(u"\2\2ST\7\20\2\2TU\7\b\2\2UV\5\26\f\2VW\7\t\2\2W\23\3") 42 buf.write(u"\2\2\2XY\7\20\2\2YZ\7\n\2\2Z[\7\20\2\2[\25\3\2\2\2\\") 43 buf.write(u"]\b\f\1\2]^\5\30\r\2^d\3\2\2\2_`\f\3\2\2`a\7\17\2\2a") 44 buf.write(u"c\5\26\f\4b_\3\2\2\2cf\3\2\2\2db\3\2\2\2de\3\2\2\2e\27") 45 buf.write(u"\3\2\2\2fd\3\2\2\2gk\5\32\16\2hi\7\16\2\2ik\5\30\r\2") 46 buf.write(u"jg\3\2\2\2jh\3\2\2\2k\31\3\2\2\2l\u0080\7\20\2\2m\u0080") 47 buf.write(u"\7\21\2\2n\u0080\7\22\2\2o\u0080\5\n\6\2p\u0080\5\22") 48 buf.write(u"\n\2q\u0080\5\24\13\2r\u0080\5\16\b\2st\7\3\2\2tu\5\26") 49 buf.write(u"\f\2uv\7\4\2\2v\u0080\3\2\2\2w|\7\b\2\2xz\5\34\17\2y") 50 buf.write(u"{\7\13\2\2zy\3\2\2\2z{\3\2\2\2{}\3\2\2\2|x\3\2\2\2|}") 51 buf.write(u"\3\2\2\2}~\3\2\2\2~\u0080\7\t\2\2\177l\3\2\2\2\177m\3") 52 buf.write(u"\2\2\2\177n\3\2\2\2\177o\3\2\2\2\177p\3\2\2\2\177q\3") 53 buf.write(u"\2\2\2\177r\3\2\2\2\177s\3\2\2\2\177w\3\2\2\2\u0080\33") 54 buf.write(u"\3\2\2\2\u0081\u0086\5\26\f\2\u0082\u0083\7\13\2\2\u0083") 55 buf.write(u"\u0085\5\26\f\2\u0084\u0082\3\2\2\2\u0085\u0088\3\2\2") 56 buf.write(u"\2\u0086\u0084\3\2\2\2\u0086\u0087\3\2\2\2\u0087\35\3") 57 buf.write(u"\2\2\2\u0088\u0086\3\2\2\2\u0089\u008a\7\f\2\2\u008a") 58 buf.write(u"\37\3\2\2\2\u008b\u008c\7\23\2\2\u008c!\3\2\2\2\20(-") 59 buf.write(u"\66:DFNPdjz|\177\u0086") 60 return buf.getvalue() 61 62 63class gnParser ( Parser ): 64 65 grammarFileName = "gn.g4" 66 67 atn = ATNDeserializer().deserialize(serializedATN()) 68 69 decisionsToDFA = [ DFA(ds, i) for i, ds in enumerate(atn.decisionToState) ] 70 71 sharedContextCache = PredictionContextCache() 72 73 literalNames = [ u"<INVALID>", u"'('", u"')'", u"'if'", u"'{'", u"'}'", 74 u"'['", u"']'", u"'.'", u"','", u"'else'", u"<INVALID>", 75 u"'!'" ] 76 77 symbolicNames = [ u"<INVALID>", u"<INVALID>", u"<INVALID>", u"<INVALID>", 78 u"<INVALID>", u"<INVALID>", u"<INVALID>", u"<INVALID>", 79 u"<INVALID>", u"<INVALID>", u"<INVALID>", u"AssignOp", 80 u"UnaryOp", u"BinaryOp", u"Identifier", u"Integer", 81 u"String", u"COMMENT", u"WS" ] 82 83 RULE_r = 0 84 RULE_statement = 1 85 RULE_lvalue = 2 86 RULE_assignment = 3 87 RULE_call = 4 88 RULE_condition = 5 89 RULE_block = 6 90 RULE_statementlist = 7 91 RULE_arrayaccess = 8 92 RULE_scopeaccess = 9 93 RULE_expr = 10 94 RULE_unaryexpr = 11 95 RULE_primaryexpr = 12 96 RULE_exprlist = 13 97 RULE_elsec = 14 98 RULE_comment = 15 99 100 ruleNames = [ u"r", u"statement", u"lvalue", u"assignment", u"call", 101 u"condition", u"block", u"statementlist", u"arrayaccess", 102 u"scopeaccess", u"expr", u"unaryexpr", u"primaryexpr", 103 u"exprlist", u"elsec", u"comment" ] 104 105 EOF = Token.EOF 106 T__0=1 107 T__1=2 108 T__2=3 109 T__3=4 110 T__4=5 111 T__5=6 112 T__6=7 113 T__7=8 114 T__8=9 115 T__9=10 116 AssignOp=11 117 UnaryOp=12 118 BinaryOp=13 119 Identifier=14 120 Integer=15 121 String=16 122 COMMENT=17 123 WS=18 124 125 def __init__(self, input, output=sys.stdout): 126 super(gnParser, self).__init__(input, output=output) 127 self.checkVersion("4.7.1") 128 self._interp = ParserATNSimulator(self, self.atn, self.decisionsToDFA, self.sharedContextCache) 129 self._predicates = None 130 131 132 133 class RContext(ParserRuleContext): 134 135 def __init__(self, parser, parent=None, invokingState=-1): 136 super(gnParser.RContext, self).__init__(parent, invokingState) 137 self.parser = parser 138 139 def statementlist(self): 140 return self.getTypedRuleContext(gnParser.StatementlistContext,0) 141 142 143 def EOF(self): 144 return self.getToken(gnParser.EOF, 0) 145 146 def getRuleIndex(self): 147 return gnParser.RULE_r 148 149 def enterRule(self, listener): 150 if hasattr(listener, "enterR"): 151 listener.enterR(self) 152 153 def exitRule(self, listener): 154 if hasattr(listener, "exitR"): 155 listener.exitR(self) 156 157 158 159 160 def r(self): 161 162 localctx = gnParser.RContext(self, self._ctx, self.state) 163 self.enterRule(localctx, 0, self.RULE_r) 164 try: 165 self.enterOuterAlt(localctx, 1) 166 self.state = 32 167 self.statementlist() 168 self.state = 33 169 self.match(gnParser.EOF) 170 except RecognitionException as re: 171 localctx.exception = re 172 self._errHandler.reportError(self, re) 173 self._errHandler.recover(self, re) 174 finally: 175 self.exitRule() 176 return localctx 177 178 class StatementContext(ParserRuleContext): 179 180 def __init__(self, parser, parent=None, invokingState=-1): 181 super(gnParser.StatementContext, self).__init__(parent, invokingState) 182 self.parser = parser 183 184 def assignment(self): 185 return self.getTypedRuleContext(gnParser.AssignmentContext,0) 186 187 188 def call(self): 189 return self.getTypedRuleContext(gnParser.CallContext,0) 190 191 192 def condition(self): 193 return self.getTypedRuleContext(gnParser.ConditionContext,0) 194 195 196 def getRuleIndex(self): 197 return gnParser.RULE_statement 198 199 def enterRule(self, listener): 200 if hasattr(listener, "enterStatement"): 201 listener.enterStatement(self) 202 203 def exitRule(self, listener): 204 if hasattr(listener, "exitStatement"): 205 listener.exitStatement(self) 206 207 208 209 210 def statement(self): 211 212 localctx = gnParser.StatementContext(self, self._ctx, self.state) 213 self.enterRule(localctx, 2, self.RULE_statement) 214 try: 215 self.state = 38 216 self._errHandler.sync(self) 217 la_ = self._interp.adaptivePredict(self._input,0,self._ctx) 218 if la_ == 1: 219 self.enterOuterAlt(localctx, 1) 220 self.state = 35 221 self.assignment() 222 pass 223 224 elif la_ == 2: 225 self.enterOuterAlt(localctx, 2) 226 self.state = 36 227 self.call() 228 pass 229 230 elif la_ == 3: 231 self.enterOuterAlt(localctx, 3) 232 self.state = 37 233 self.condition() 234 pass 235 236 237 except RecognitionException as re: 238 localctx.exception = re 239 self._errHandler.reportError(self, re) 240 self._errHandler.recover(self, re) 241 finally: 242 self.exitRule() 243 return localctx 244 245 class LvalueContext(ParserRuleContext): 246 247 def __init__(self, parser, parent=None, invokingState=-1): 248 super(gnParser.LvalueContext, self).__init__(parent, invokingState) 249 self.parser = parser 250 251 def Identifier(self): 252 return self.getToken(gnParser.Identifier, 0) 253 254 def arrayaccess(self): 255 return self.getTypedRuleContext(gnParser.ArrayaccessContext,0) 256 257 258 def scopeaccess(self): 259 return self.getTypedRuleContext(gnParser.ScopeaccessContext,0) 260 261 262 def getRuleIndex(self): 263 return gnParser.RULE_lvalue 264 265 def enterRule(self, listener): 266 if hasattr(listener, "enterLvalue"): 267 listener.enterLvalue(self) 268 269 def exitRule(self, listener): 270 if hasattr(listener, "exitLvalue"): 271 listener.exitLvalue(self) 272 273 274 275 276 def lvalue(self): 277 278 localctx = gnParser.LvalueContext(self, self._ctx, self.state) 279 self.enterRule(localctx, 4, self.RULE_lvalue) 280 try: 281 self.state = 43 282 self._errHandler.sync(self) 283 la_ = self._interp.adaptivePredict(self._input,1,self._ctx) 284 if la_ == 1: 285 self.enterOuterAlt(localctx, 1) 286 self.state = 40 287 self.match(gnParser.Identifier) 288 pass 289 290 elif la_ == 2: 291 self.enterOuterAlt(localctx, 2) 292 self.state = 41 293 self.arrayaccess() 294 pass 295 296 elif la_ == 3: 297 self.enterOuterAlt(localctx, 3) 298 self.state = 42 299 self.scopeaccess() 300 pass 301 302 303 except RecognitionException as re: 304 localctx.exception = re 305 self._errHandler.reportError(self, re) 306 self._errHandler.recover(self, re) 307 finally: 308 self.exitRule() 309 return localctx 310 311 class AssignmentContext(ParserRuleContext): 312 313 def __init__(self, parser, parent=None, invokingState=-1): 314 super(gnParser.AssignmentContext, self).__init__(parent, invokingState) 315 self.parser = parser 316 317 def lvalue(self): 318 return self.getTypedRuleContext(gnParser.LvalueContext,0) 319 320 321 def AssignOp(self): 322 return self.getToken(gnParser.AssignOp, 0) 323 324 def expr(self): 325 return self.getTypedRuleContext(gnParser.ExprContext,0) 326 327 328 def getRuleIndex(self): 329 return gnParser.RULE_assignment 330 331 def enterRule(self, listener): 332 if hasattr(listener, "enterAssignment"): 333 listener.enterAssignment(self) 334 335 def exitRule(self, listener): 336 if hasattr(listener, "exitAssignment"): 337 listener.exitAssignment(self) 338 339 340 341 342 def assignment(self): 343 344 localctx = gnParser.AssignmentContext(self, self._ctx, self.state) 345 self.enterRule(localctx, 6, self.RULE_assignment) 346 try: 347 self.enterOuterAlt(localctx, 1) 348 self.state = 45 349 self.lvalue() 350 self.state = 46 351 self.match(gnParser.AssignOp) 352 self.state = 47 353 self.expr(0) 354 except RecognitionException as re: 355 localctx.exception = re 356 self._errHandler.reportError(self, re) 357 self._errHandler.recover(self, re) 358 finally: 359 self.exitRule() 360 return localctx 361 362 class CallContext(ParserRuleContext): 363 364 def __init__(self, parser, parent=None, invokingState=-1): 365 super(gnParser.CallContext, self).__init__(parent, invokingState) 366 self.parser = parser 367 368 def Identifier(self): 369 return self.getToken(gnParser.Identifier, 0) 370 371 def exprlist(self): 372 return self.getTypedRuleContext(gnParser.ExprlistContext,0) 373 374 375 def block(self): 376 return self.getTypedRuleContext(gnParser.BlockContext,0) 377 378 379 def getRuleIndex(self): 380 return gnParser.RULE_call 381 382 def enterRule(self, listener): 383 if hasattr(listener, "enterCall"): 384 listener.enterCall(self) 385 386 def exitRule(self, listener): 387 if hasattr(listener, "exitCall"): 388 listener.exitCall(self) 389 390 391 392 393 def call(self): 394 395 localctx = gnParser.CallContext(self, self._ctx, self.state) 396 self.enterRule(localctx, 8, self.RULE_call) 397 self._la = 0 # Token type 398 try: 399 self.enterOuterAlt(localctx, 1) 400 self.state = 49 401 self.match(gnParser.Identifier) 402 self.state = 50 403 self.match(gnParser.T__0) 404 self.state = 52 405 self._errHandler.sync(self) 406 _la = self._input.LA(1) 407 if (((_la) & ~0x3f) == 0 and ((1 << _la) & ((1 << gnParser.T__0) | (1 << gnParser.T__3) | (1 << gnParser.T__5) | (1 << gnParser.UnaryOp) | (1 << gnParser.Identifier) | (1 << gnParser.Integer) | (1 << gnParser.String))) != 0): 408 self.state = 51 409 self.exprlist() 410 411 412 self.state = 54 413 self.match(gnParser.T__1) 414 self.state = 56 415 self._errHandler.sync(self) 416 la_ = self._interp.adaptivePredict(self._input,3,self._ctx) 417 if la_ == 1: 418 self.state = 55 419 self.block() 420 421 422 except RecognitionException as re: 423 localctx.exception = re 424 self._errHandler.reportError(self, re) 425 self._errHandler.recover(self, re) 426 finally: 427 self.exitRule() 428 return localctx 429 430 class ConditionContext(ParserRuleContext): 431 432 def __init__(self, parser, parent=None, invokingState=-1): 433 super(gnParser.ConditionContext, self).__init__(parent, invokingState) 434 self.parser = parser 435 436 def expr(self): 437 return self.getTypedRuleContext(gnParser.ExprContext,0) 438 439 440 def block(self, i=None): 441 if i is None: 442 return self.getTypedRuleContexts(gnParser.BlockContext) 443 else: 444 return self.getTypedRuleContext(gnParser.BlockContext,i) 445 446 447 def elsec(self): 448 return self.getTypedRuleContext(gnParser.ElsecContext,0) 449 450 451 def condition(self): 452 return self.getTypedRuleContext(gnParser.ConditionContext,0) 453 454 455 def getRuleIndex(self): 456 return gnParser.RULE_condition 457 458 def enterRule(self, listener): 459 if hasattr(listener, "enterCondition"): 460 listener.enterCondition(self) 461 462 def exitRule(self, listener): 463 if hasattr(listener, "exitCondition"): 464 listener.exitCondition(self) 465 466 467 468 469 def condition(self): 470 471 localctx = gnParser.ConditionContext(self, self._ctx, self.state) 472 self.enterRule(localctx, 10, self.RULE_condition) 473 self._la = 0 # Token type 474 try: 475 self.enterOuterAlt(localctx, 1) 476 self.state = 58 477 self.match(gnParser.T__2) 478 self.state = 59 479 self.match(gnParser.T__0) 480 self.state = 60 481 self.expr(0) 482 self.state = 61 483 self.match(gnParser.T__1) 484 self.state = 62 485 self.block() 486 self.state = 68 487 self._errHandler.sync(self) 488 _la = self._input.LA(1) 489 if _la==gnParser.T__9: 490 self.state = 63 491 self.elsec() 492 self.state = 66 493 self._errHandler.sync(self) 494 token = self._input.LA(1) 495 if token in [gnParser.T__2]: 496 self.state = 64 497 self.condition() 498 pass 499 elif token in [gnParser.T__3]: 500 self.state = 65 501 self.block() 502 pass 503 else: 504 raise NoViableAltException(self) 505 506 507 508 except RecognitionException as re: 509 localctx.exception = re 510 self._errHandler.reportError(self, re) 511 self._errHandler.recover(self, re) 512 finally: 513 self.exitRule() 514 return localctx 515 516 class BlockContext(ParserRuleContext): 517 518 def __init__(self, parser, parent=None, invokingState=-1): 519 super(gnParser.BlockContext, self).__init__(parent, invokingState) 520 self.parser = parser 521 522 def statementlist(self): 523 return self.getTypedRuleContext(gnParser.StatementlistContext,0) 524 525 526 def getRuleIndex(self): 527 return gnParser.RULE_block 528 529 def enterRule(self, listener): 530 if hasattr(listener, "enterBlock"): 531 listener.enterBlock(self) 532 533 def exitRule(self, listener): 534 if hasattr(listener, "exitBlock"): 535 listener.exitBlock(self) 536 537 538 539 540 def block(self): 541 542 localctx = gnParser.BlockContext(self, self._ctx, self.state) 543 self.enterRule(localctx, 12, self.RULE_block) 544 try: 545 self.enterOuterAlt(localctx, 1) 546 self.state = 70 547 self.match(gnParser.T__3) 548 self.state = 71 549 self.statementlist() 550 self.state = 72 551 self.match(gnParser.T__4) 552 except RecognitionException as re: 553 localctx.exception = re 554 self._errHandler.reportError(self, re) 555 self._errHandler.recover(self, re) 556 finally: 557 self.exitRule() 558 return localctx 559 560 class StatementlistContext(ParserRuleContext): 561 562 def __init__(self, parser, parent=None, invokingState=-1): 563 super(gnParser.StatementlistContext, self).__init__(parent, invokingState) 564 self.parser = parser 565 566 def statement(self, i=None): 567 if i is None: 568 return self.getTypedRuleContexts(gnParser.StatementContext) 569 else: 570 return self.getTypedRuleContext(gnParser.StatementContext,i) 571 572 573 def comment(self, i=None): 574 if i is None: 575 return self.getTypedRuleContexts(gnParser.CommentContext) 576 else: 577 return self.getTypedRuleContext(gnParser.CommentContext,i) 578 579 580 def getRuleIndex(self): 581 return gnParser.RULE_statementlist 582 583 def enterRule(self, listener): 584 if hasattr(listener, "enterStatementlist"): 585 listener.enterStatementlist(self) 586 587 def exitRule(self, listener): 588 if hasattr(listener, "exitStatementlist"): 589 listener.exitStatementlist(self) 590 591 592 593 594 def statementlist(self): 595 596 localctx = gnParser.StatementlistContext(self, self._ctx, self.state) 597 self.enterRule(localctx, 14, self.RULE_statementlist) 598 self._la = 0 # Token type 599 try: 600 self.enterOuterAlt(localctx, 1) 601 self.state = 78 602 self._errHandler.sync(self) 603 _la = self._input.LA(1) 604 while (((_la) & ~0x3f) == 0 and ((1 << _la) & ((1 << gnParser.T__2) | (1 << gnParser.Identifier) | (1 << gnParser.COMMENT))) != 0): 605 self.state = 76 606 self._errHandler.sync(self) 607 token = self._input.LA(1) 608 if token in [gnParser.T__2, gnParser.Identifier]: 609 self.state = 74 610 self.statement() 611 pass 612 elif token in [gnParser.COMMENT]: 613 self.state = 75 614 self.comment() 615 pass 616 else: 617 raise NoViableAltException(self) 618 619 self.state = 80 620 self._errHandler.sync(self) 621 _la = self._input.LA(1) 622 623 except RecognitionException as re: 624 localctx.exception = re 625 self._errHandler.reportError(self, re) 626 self._errHandler.recover(self, re) 627 finally: 628 self.exitRule() 629 return localctx 630 631 class ArrayaccessContext(ParserRuleContext): 632 633 def __init__(self, parser, parent=None, invokingState=-1): 634 super(gnParser.ArrayaccessContext, self).__init__(parent, invokingState) 635 self.parser = parser 636 637 def Identifier(self): 638 return self.getToken(gnParser.Identifier, 0) 639 640 def expr(self): 641 return self.getTypedRuleContext(gnParser.ExprContext,0) 642 643 644 def getRuleIndex(self): 645 return gnParser.RULE_arrayaccess 646 647 def enterRule(self, listener): 648 if hasattr(listener, "enterArrayaccess"): 649 listener.enterArrayaccess(self) 650 651 def exitRule(self, listener): 652 if hasattr(listener, "exitArrayaccess"): 653 listener.exitArrayaccess(self) 654 655 656 657 658 def arrayaccess(self): 659 660 localctx = gnParser.ArrayaccessContext(self, self._ctx, self.state) 661 self.enterRule(localctx, 16, self.RULE_arrayaccess) 662 try: 663 self.enterOuterAlt(localctx, 1) 664 self.state = 81 665 self.match(gnParser.Identifier) 666 self.state = 82 667 self.match(gnParser.T__5) 668 self.state = 83 669 self.expr(0) 670 self.state = 84 671 self.match(gnParser.T__6) 672 except RecognitionException as re: 673 localctx.exception = re 674 self._errHandler.reportError(self, re) 675 self._errHandler.recover(self, re) 676 finally: 677 self.exitRule() 678 return localctx 679 680 class ScopeaccessContext(ParserRuleContext): 681 682 def __init__(self, parser, parent=None, invokingState=-1): 683 super(gnParser.ScopeaccessContext, self).__init__(parent, invokingState) 684 self.parser = parser 685 686 def Identifier(self, i=None): 687 if i is None: 688 return self.getTokens(gnParser.Identifier) 689 else: 690 return self.getToken(gnParser.Identifier, i) 691 692 def getRuleIndex(self): 693 return gnParser.RULE_scopeaccess 694 695 def enterRule(self, listener): 696 if hasattr(listener, "enterScopeaccess"): 697 listener.enterScopeaccess(self) 698 699 def exitRule(self, listener): 700 if hasattr(listener, "exitScopeaccess"): 701 listener.exitScopeaccess(self) 702 703 704 705 706 def scopeaccess(self): 707 708 localctx = gnParser.ScopeaccessContext(self, self._ctx, self.state) 709 self.enterRule(localctx, 18, self.RULE_scopeaccess) 710 try: 711 self.enterOuterAlt(localctx, 1) 712 self.state = 86 713 self.match(gnParser.Identifier) 714 self.state = 87 715 self.match(gnParser.T__7) 716 self.state = 88 717 self.match(gnParser.Identifier) 718 except RecognitionException as re: 719 localctx.exception = re 720 self._errHandler.reportError(self, re) 721 self._errHandler.recover(self, re) 722 finally: 723 self.exitRule() 724 return localctx 725 726 class ExprContext(ParserRuleContext): 727 728 def __init__(self, parser, parent=None, invokingState=-1): 729 super(gnParser.ExprContext, self).__init__(parent, invokingState) 730 self.parser = parser 731 732 def unaryexpr(self): 733 return self.getTypedRuleContext(gnParser.UnaryexprContext,0) 734 735 736 def expr(self, i=None): 737 if i is None: 738 return self.getTypedRuleContexts(gnParser.ExprContext) 739 else: 740 return self.getTypedRuleContext(gnParser.ExprContext,i) 741 742 743 def BinaryOp(self): 744 return self.getToken(gnParser.BinaryOp, 0) 745 746 def getRuleIndex(self): 747 return gnParser.RULE_expr 748 749 def enterRule(self, listener): 750 if hasattr(listener, "enterExpr"): 751 listener.enterExpr(self) 752 753 def exitRule(self, listener): 754 if hasattr(listener, "exitExpr"): 755 listener.exitExpr(self) 756 757 758 759 def expr(self, _p=0): 760 _parentctx = self._ctx 761 _parentState = self.state 762 localctx = gnParser.ExprContext(self, self._ctx, _parentState) 763 _prevctx = localctx 764 _startState = 20 765 self.enterRecursionRule(localctx, 20, self.RULE_expr, _p) 766 try: 767 self.enterOuterAlt(localctx, 1) 768 self.state = 91 769 self.unaryexpr() 770 self._ctx.stop = self._input.LT(-1) 771 self.state = 98 772 self._errHandler.sync(self) 773 _alt = self._interp.adaptivePredict(self._input,8,self._ctx) 774 while _alt!=2 and _alt!=ATN.INVALID_ALT_NUMBER: 775 if _alt==1: 776 if self._parseListeners is not None: 777 self.triggerExitRuleEvent() 778 _prevctx = localctx 779 localctx = gnParser.ExprContext(self, _parentctx, _parentState) 780 self.pushNewRecursionContext(localctx, _startState, self.RULE_expr) 781 self.state = 93 782 if not self.precpred(self._ctx, 1): 783 from antlr4.error.Errors import FailedPredicateException 784 raise FailedPredicateException(self, "self.precpred(self._ctx, 1)") 785 self.state = 94 786 self.match(gnParser.BinaryOp) 787 self.state = 95 788 self.expr(2) 789 self.state = 100 790 self._errHandler.sync(self) 791 _alt = self._interp.adaptivePredict(self._input,8,self._ctx) 792 793 except RecognitionException as re: 794 localctx.exception = re 795 self._errHandler.reportError(self, re) 796 self._errHandler.recover(self, re) 797 finally: 798 self.unrollRecursionContexts(_parentctx) 799 return localctx 800 801 class UnaryexprContext(ParserRuleContext): 802 803 def __init__(self, parser, parent=None, invokingState=-1): 804 super(gnParser.UnaryexprContext, self).__init__(parent, invokingState) 805 self.parser = parser 806 807 def primaryexpr(self): 808 return self.getTypedRuleContext(gnParser.PrimaryexprContext,0) 809 810 811 def UnaryOp(self): 812 return self.getToken(gnParser.UnaryOp, 0) 813 814 def unaryexpr(self): 815 return self.getTypedRuleContext(gnParser.UnaryexprContext,0) 816 817 818 def getRuleIndex(self): 819 return gnParser.RULE_unaryexpr 820 821 def enterRule(self, listener): 822 if hasattr(listener, "enterUnaryexpr"): 823 listener.enterUnaryexpr(self) 824 825 def exitRule(self, listener): 826 if hasattr(listener, "exitUnaryexpr"): 827 listener.exitUnaryexpr(self) 828 829 830 831 832 def unaryexpr(self): 833 834 localctx = gnParser.UnaryexprContext(self, self._ctx, self.state) 835 self.enterRule(localctx, 22, self.RULE_unaryexpr) 836 try: 837 self.state = 104 838 self._errHandler.sync(self) 839 token = self._input.LA(1) 840 if token in [gnParser.T__0, gnParser.T__3, gnParser.T__5, gnParser.Identifier, gnParser.Integer, gnParser.String]: 841 self.enterOuterAlt(localctx, 1) 842 self.state = 101 843 self.primaryexpr() 844 pass 845 elif token in [gnParser.UnaryOp]: 846 self.enterOuterAlt(localctx, 2) 847 self.state = 102 848 self.match(gnParser.UnaryOp) 849 self.state = 103 850 self.unaryexpr() 851 pass 852 else: 853 raise NoViableAltException(self) 854 855 except RecognitionException as re: 856 localctx.exception = re 857 self._errHandler.reportError(self, re) 858 self._errHandler.recover(self, re) 859 finally: 860 self.exitRule() 861 return localctx 862 863 class PrimaryexprContext(ParserRuleContext): 864 865 def __init__(self, parser, parent=None, invokingState=-1): 866 super(gnParser.PrimaryexprContext, self).__init__(parent, invokingState) 867 self.parser = parser 868 869 def Identifier(self): 870 return self.getToken(gnParser.Identifier, 0) 871 872 def Integer(self): 873 return self.getToken(gnParser.Integer, 0) 874 875 def String(self): 876 return self.getToken(gnParser.String, 0) 877 878 def call(self): 879 return self.getTypedRuleContext(gnParser.CallContext,0) 880 881 882 def arrayaccess(self): 883 return self.getTypedRuleContext(gnParser.ArrayaccessContext,0) 884 885 886 def scopeaccess(self): 887 return self.getTypedRuleContext(gnParser.ScopeaccessContext,0) 888 889 890 def block(self): 891 return self.getTypedRuleContext(gnParser.BlockContext,0) 892 893 894 def expr(self): 895 return self.getTypedRuleContext(gnParser.ExprContext,0) 896 897 898 def exprlist(self): 899 return self.getTypedRuleContext(gnParser.ExprlistContext,0) 900 901 902 def getRuleIndex(self): 903 return gnParser.RULE_primaryexpr 904 905 def enterRule(self, listener): 906 if hasattr(listener, "enterPrimaryexpr"): 907 listener.enterPrimaryexpr(self) 908 909 def exitRule(self, listener): 910 if hasattr(listener, "exitPrimaryexpr"): 911 listener.exitPrimaryexpr(self) 912 913 914 915 916 def primaryexpr(self): 917 918 localctx = gnParser.PrimaryexprContext(self, self._ctx, self.state) 919 self.enterRule(localctx, 24, self.RULE_primaryexpr) 920 self._la = 0 # Token type 921 try: 922 self.state = 125 923 self._errHandler.sync(self) 924 la_ = self._interp.adaptivePredict(self._input,12,self._ctx) 925 if la_ == 1: 926 self.enterOuterAlt(localctx, 1) 927 self.state = 106 928 self.match(gnParser.Identifier) 929 pass 930 931 elif la_ == 2: 932 self.enterOuterAlt(localctx, 2) 933 self.state = 107 934 self.match(gnParser.Integer) 935 pass 936 937 elif la_ == 3: 938 self.enterOuterAlt(localctx, 3) 939 self.state = 108 940 self.match(gnParser.String) 941 pass 942 943 elif la_ == 4: 944 self.enterOuterAlt(localctx, 4) 945 self.state = 109 946 self.call() 947 pass 948 949 elif la_ == 5: 950 self.enterOuterAlt(localctx, 5) 951 self.state = 110 952 self.arrayaccess() 953 pass 954 955 elif la_ == 6: 956 self.enterOuterAlt(localctx, 6) 957 self.state = 111 958 self.scopeaccess() 959 pass 960 961 elif la_ == 7: 962 self.enterOuterAlt(localctx, 7) 963 self.state = 112 964 self.block() 965 pass 966 967 elif la_ == 8: 968 self.enterOuterAlt(localctx, 8) 969 self.state = 113 970 self.match(gnParser.T__0) 971 self.state = 114 972 self.expr(0) 973 self.state = 115 974 self.match(gnParser.T__1) 975 pass 976 977 elif la_ == 9: 978 self.enterOuterAlt(localctx, 9) 979 self.state = 117 980 self.match(gnParser.T__5) 981 self.state = 122 982 self._errHandler.sync(self) 983 _la = self._input.LA(1) 984 if (((_la) & ~0x3f) == 0 and ((1 << _la) & ((1 << gnParser.T__0) | (1 << gnParser.T__3) | (1 << gnParser.T__5) | (1 << gnParser.UnaryOp) | (1 << gnParser.Identifier) | (1 << gnParser.Integer) | (1 << gnParser.String))) != 0): 985 self.state = 118 986 self.exprlist() 987 self.state = 120 988 self._errHandler.sync(self) 989 _la = self._input.LA(1) 990 if _la==gnParser.T__8: 991 self.state = 119 992 self.match(gnParser.T__8) 993 994 995 996 997 self.state = 124 998 self.match(gnParser.T__6) 999 pass 1000 1001 1002 except RecognitionException as re: 1003 localctx.exception = re 1004 self._errHandler.reportError(self, re) 1005 self._errHandler.recover(self, re) 1006 finally: 1007 self.exitRule() 1008 return localctx 1009 1010 class ExprlistContext(ParserRuleContext): 1011 1012 def __init__(self, parser, parent=None, invokingState=-1): 1013 super(gnParser.ExprlistContext, self).__init__(parent, invokingState) 1014 self.parser = parser 1015 1016 def expr(self, i=None): 1017 if i is None: 1018 return self.getTypedRuleContexts(gnParser.ExprContext) 1019 else: 1020 return self.getTypedRuleContext(gnParser.ExprContext,i) 1021 1022 1023 def getRuleIndex(self): 1024 return gnParser.RULE_exprlist 1025 1026 def enterRule(self, listener): 1027 if hasattr(listener, "enterExprlist"): 1028 listener.enterExprlist(self) 1029 1030 def exitRule(self, listener): 1031 if hasattr(listener, "exitExprlist"): 1032 listener.exitExprlist(self) 1033 1034 1035 1036 1037 def exprlist(self): 1038 1039 localctx = gnParser.ExprlistContext(self, self._ctx, self.state) 1040 self.enterRule(localctx, 26, self.RULE_exprlist) 1041 try: 1042 self.enterOuterAlt(localctx, 1) 1043 self.state = 127 1044 self.expr(0) 1045 self.state = 132 1046 self._errHandler.sync(self) 1047 _alt = self._interp.adaptivePredict(self._input,13,self._ctx) 1048 while _alt!=2 and _alt!=ATN.INVALID_ALT_NUMBER: 1049 if _alt==1: 1050 self.state = 128 1051 self.match(gnParser.T__8) 1052 self.state = 129 1053 self.expr(0) 1054 self.state = 134 1055 self._errHandler.sync(self) 1056 _alt = self._interp.adaptivePredict(self._input,13,self._ctx) 1057 1058 except RecognitionException as re: 1059 localctx.exception = re 1060 self._errHandler.reportError(self, re) 1061 self._errHandler.recover(self, re) 1062 finally: 1063 self.exitRule() 1064 return localctx 1065 1066 class ElsecContext(ParserRuleContext): 1067 1068 def __init__(self, parser, parent=None, invokingState=-1): 1069 super(gnParser.ElsecContext, self).__init__(parent, invokingState) 1070 self.parser = parser 1071 1072 1073 def getRuleIndex(self): 1074 return gnParser.RULE_elsec 1075 1076 def enterRule(self, listener): 1077 if hasattr(listener, "enterElsec"): 1078 listener.enterElsec(self) 1079 1080 def exitRule(self, listener): 1081 if hasattr(listener, "exitElsec"): 1082 listener.exitElsec(self) 1083 1084 1085 1086 1087 def elsec(self): 1088 1089 localctx = gnParser.ElsecContext(self, self._ctx, self.state) 1090 self.enterRule(localctx, 28, self.RULE_elsec) 1091 try: 1092 self.enterOuterAlt(localctx, 1) 1093 self.state = 135 1094 self.match(gnParser.T__9) 1095 except RecognitionException as re: 1096 localctx.exception = re 1097 self._errHandler.reportError(self, re) 1098 self._errHandler.recover(self, re) 1099 finally: 1100 self.exitRule() 1101 return localctx 1102 1103 class CommentContext(ParserRuleContext): 1104 1105 def __init__(self, parser, parent=None, invokingState=-1): 1106 super(gnParser.CommentContext, self).__init__(parent, invokingState) 1107 self.parser = parser 1108 1109 def COMMENT(self): 1110 return self.getToken(gnParser.COMMENT, 0) 1111 1112 def getRuleIndex(self): 1113 return gnParser.RULE_comment 1114 1115 def enterRule(self, listener): 1116 if hasattr(listener, "enterComment"): 1117 listener.enterComment(self) 1118 1119 def exitRule(self, listener): 1120 if hasattr(listener, "exitComment"): 1121 listener.exitComment(self) 1122 1123 1124 1125 1126 def comment(self): 1127 1128 localctx = gnParser.CommentContext(self, self._ctx, self.state) 1129 self.enterRule(localctx, 30, self.RULE_comment) 1130 try: 1131 self.enterOuterAlt(localctx, 1) 1132 self.state = 137 1133 self.match(gnParser.COMMENT) 1134 except RecognitionException as re: 1135 localctx.exception = re 1136 self._errHandler.reportError(self, re) 1137 self._errHandler.recover(self, re) 1138 finally: 1139 self.exitRule() 1140 return localctx 1141 1142 1143 1144 def sempred(self, localctx, ruleIndex, predIndex): 1145 if self._predicates == None: 1146 self._predicates = dict() 1147 self._predicates[10] = self.expr_sempred 1148 pred = self._predicates.get(ruleIndex, None) 1149 if pred is None: 1150 raise Exception("No predicate with index:" + str(ruleIndex)) 1151 else: 1152 return pred(localctx, predIndex) 1153 1154 def expr_sempred(self, localctx, predIndex): 1155 if predIndex == 0: 1156 return self.precpred(self._ctx, 1) 1157 1158 1159 1160 1161 1162