in tools/SeeDot/seedot/compiler/antlr/seedotParser.py [0:0]
def expr(self, _p:int=0):
_parentctx = self._ctx
_parentState = self.state
localctx = seedotParser.ExprContext(self, self._ctx, _parentState)
_prevctx = localctx
_startState = 0
self.enterRecursionRule(localctx, 0, self.RULE_expr, _p)
self._la = 0 # Token type
try:
self.enterOuterAlt(localctx, 1)
self.state = 202
self._errHandler.sync(self)
la_ = self._interp.adaptivePredict(self._input,1,self._ctx)
if la_ == 1:
localctx = seedotParser.IntContext(self, localctx)
self._ctx = localctx
_prevctx = localctx
self.state = 13
self.match(seedotParser.IntConst)
pass
elif la_ == 2:
localctx = seedotParser.FloatContext(self, localctx)
self._ctx = localctx
_prevctx = localctx
self.state = 14
self.match(seedotParser.FloatConst)
pass
elif la_ == 3:
localctx = seedotParser.IdContext(self, localctx)
self._ctx = localctx
_prevctx = localctx
self.state = 15
self.match(seedotParser.Id)
pass
elif la_ == 4:
localctx = seedotParser.DeclContext(self, localctx)
self._ctx = localctx
_prevctx = localctx
self.state = 16
self.match(seedotParser.T__0)
self.state = 17
self.intConstList()
self.state = 18
self.match(seedotParser.T__1)
self.state = 19
self.match(seedotParser.In)
self.state = 20
self.match(seedotParser.T__2)
self.state = 21
self.match(seedotParser.FloatConst)
self.state = 22
self.match(seedotParser.T__3)
self.state = 23
self.match(seedotParser.FloatConst)
self.state = 24
self.match(seedotParser.T__4)
pass
elif la_ == 5:
localctx = seedotParser.InitContext(self, localctx)
self._ctx = localctx
_prevctx = localctx
self.state = 26
self.match(seedotParser.T__5)
self.state = 27
self.match(seedotParser.T__0)
self.state = 28
self.match(seedotParser.T__2)
self.state = 29
self.intConstList()
self.state = 30
self.match(seedotParser.T__4)
self.state = 31
self.match(seedotParser.T__3)
self.state = 32
self.match(seedotParser.FloatConst)
self.state = 33
self.match(seedotParser.T__1)
pass
elif la_ == 6:
localctx = seedotParser.ReshapeContext(self, localctx)
self._ctx = localctx
_prevctx = localctx
self.state = 35
self.match(seedotParser.Reshape)
self.state = 36
self.match(seedotParser.T__0)
self.state = 37
self.expr(0)
self.state = 38
self.match(seedotParser.T__3)
self.state = 39
self.match(seedotParser.T__0)
self.state = 40
self.intConstList()
self.state = 41
self.match(seedotParser.T__1)
self.state = 42
self.match(seedotParser.T__3)
self.state = 43
self.match(seedotParser.T__0)
self.state = 44
self.intConstList()
self.state = 45
self.match(seedotParser.T__1)
self.state = 46
self.match(seedotParser.T__1)
pass
elif la_ == 7:
localctx = seedotParser.MaxpoolContext(self, localctx)
self._ctx = localctx
_prevctx = localctx
self.state = 48
self.match(seedotParser.Maxpool)
self.state = 49
self.match(seedotParser.T__0)
self.state = 50
self.expr(0)
self.state = 51
self.match(seedotParser.T__3)
self.state = 52
self.match(seedotParser.T__8)
self.state = 53
self.match(seedotParser.IntConst)
self.state = 54
self.match(seedotParser.IntConst)
self.state = 55
self.match(seedotParser.T__9)
self.state = 56
self.match(seedotParser.T__3)
self.state = 57
self.match(seedotParser.T__10)
self.state = 58
self.match(seedotParser.IntConst)
self.state = 59
self.match(seedotParser.IntConst)
self.state = 60
self.match(seedotParser.IntConst)
self.state = 61
self.match(seedotParser.IntConst)
self.state = 62
self.match(seedotParser.T__9)
self.state = 63
self.match(seedotParser.T__3)
self.state = 64
self.match(seedotParser.T__11)
self.state = 65
self.match(seedotParser.IntConst)
self.state = 66
self.match(seedotParser.IntConst)
self.state = 67
self.match(seedotParser.T__9)
self.state = 68
self.match(seedotParser.T__1)
pass
elif la_ == 8:
localctx = seedotParser.ReverseContext(self, localctx)
self._ctx = localctx
_prevctx = localctx
self.state = 70
self.match(seedotParser.Reverse)
self.state = 71
self.match(seedotParser.T__0)
self.state = 72
self.expr(0)
self.state = 73
self.match(seedotParser.T__3)
self.state = 74
self.match(seedotParser.IntConst)
self.state = 75
self.match(seedotParser.T__1)
pass
elif la_ == 9:
localctx = seedotParser.FuncCallContext(self, localctx)
self._ctx = localctx
_prevctx = localctx
self.state = 77
self.match(seedotParser.Id)
self.state = 78
self.match(seedotParser.T__0)
self.state = 79
self.expr(0)
self.state = 84
self._errHandler.sync(self)
_la = self._input.LA(1)
while _la==seedotParser.T__3:
self.state = 80
self.match(seedotParser.T__3)
self.state = 81
self.expr(0)
self.state = 86
self._errHandler.sync(self)
_la = self._input.LA(1)
self.state = 87
self.match(seedotParser.T__1)
pass
elif la_ == 10:
localctx = seedotParser.UopContext(self, localctx)
self._ctx = localctx
_prevctx = localctx
self.state = 89
self.addOp()
self.state = 90
self.expr(11)
pass
elif la_ == 11:
localctx = seedotParser.ConvolutionContext(self, localctx)
self._ctx = localctx
_prevctx = localctx
self.state = 92
self.match(seedotParser.Conv2d)
self.state = 93
self.match(seedotParser.T__0)
self.state = 94
self.expr(0)
self.state = 95
self.match(seedotParser.T__3)
self.state = 96
self.expr(0)
self.state = 97
self.match(seedotParser.T__3)
self.state = 98
self.match(seedotParser.T__11)
self.state = 99
self.match(seedotParser.IntConst)
self.state = 100
self.match(seedotParser.IntConst)
self.state = 101
self.match(seedotParser.T__9)
self.state = 102
self.match(seedotParser.T__3)
self.state = 103
self.match(seedotParser.T__10)
self.state = 104
self.match(seedotParser.IntConst)
self.state = 105
self.match(seedotParser.IntConst)
self.state = 106
self.match(seedotParser.IntConst)
self.state = 107
self.match(seedotParser.IntConst)
self.state = 108
self.match(seedotParser.T__9)
self.state = 109
self.match(seedotParser.T__3)
self.state = 110
self.match(seedotParser.T__12)
self.state = 111
self.match(seedotParser.IntConst)
self.state = 112
self.match(seedotParser.IntConst)
self.state = 113
self.match(seedotParser.T__9)
self.state = 114
self.match(seedotParser.T__3)
self.state = 115
self.match(seedotParser.T__13)
self.state = 116
self.match(seedotParser.IntConst)
self.state = 117
self.match(seedotParser.T__9)
self.state = 118
self.match(seedotParser.T__1)
pass
elif la_ == 12:
localctx = seedotParser.MbconvContext(self, localctx)
self._ctx = localctx
_prevctx = localctx
self.state = 120
self.match(seedotParser.MbConv)
self.state = 121
self.match(seedotParser.T__0)
self.state = 122
self.expr(0)
self.state = 123
self.match(seedotParser.T__3)
self.state = 124
self.match(seedotParser.T__2)
self.state = 125
self.expr(0)
self.state = 126
self.match(seedotParser.T__3)
self.state = 127
self.expr(0)
self.state = 128
self.match(seedotParser.T__3)
self.state = 129
self.expr(0)
self.state = 130
self.match(seedotParser.T__4)
self.state = 131
self.match(seedotParser.T__3)
self.state = 132
self.match(seedotParser.T__2)
self.state = 133
self.expr(0)
self.state = 134
self.match(seedotParser.T__3)
self.state = 135
self.expr(0)
self.state = 136
self.match(seedotParser.T__3)
self.state = 137
self.expr(0)
self.state = 138
self.match(seedotParser.T__4)
self.state = 139
self.match(seedotParser.T__3)
self.state = 140
self.match(seedotParser.T__2)
self.state = 141
self.expr(0)
self.state = 142
self.match(seedotParser.T__3)
self.state = 143
self.expr(0)
self.state = 144
self.match(seedotParser.T__3)
self.state = 145
self.expr(0)
self.state = 146
self.match(seedotParser.T__4)
self.state = 147
self.match(seedotParser.T__3)
self.state = 148
self.match(seedotParser.T__11)
self.state = 149
self.match(seedotParser.IntConst)
self.state = 150
self.match(seedotParser.IntConst)
self.state = 151
self.match(seedotParser.T__9)
self.state = 152
self.match(seedotParser.T__3)
self.state = 153
self.match(seedotParser.T__10)
self.state = 154
self.match(seedotParser.IntConst)
self.state = 155
self.match(seedotParser.IntConst)
self.state = 156
self.match(seedotParser.IntConst)
self.state = 157
self.match(seedotParser.IntConst)
self.state = 158
self.match(seedotParser.T__9)
self.state = 159
self.match(seedotParser.T__1)
pass
elif la_ == 13:
localctx = seedotParser.FuncContext(self, localctx)
self._ctx = localctx
_prevctx = localctx
self.state = 161
self.specialFunc()
self.state = 162
self.match(seedotParser.T__0)
self.state = 163
self.expr(0)
self.state = 164
self.match(seedotParser.T__1)
pass
elif la_ == 14:
localctx = seedotParser.SumContext(self, localctx)
self._ctx = localctx
_prevctx = localctx
self.state = 166
self.match(seedotParser.Sum)
self.state = 167
self.match(seedotParser.T__0)
self.state = 168
self.match(seedotParser.Id)
self.state = 169
self.match(seedotParser.T__14)
self.state = 170
self.match(seedotParser.T__2)
self.state = 171
self.match(seedotParser.IntConst)
self.state = 172
self.match(seedotParser.T__15)
self.state = 173
self.match(seedotParser.IntConst)
self.state = 174
self.match(seedotParser.T__4)
self.state = 175
self.match(seedotParser.T__1)
self.state = 176
self.expr(5)
pass
elif la_ == 15:
localctx = seedotParser.LoopContext(self, localctx)
self._ctx = localctx
_prevctx = localctx
self.state = 177
self.match(seedotParser.Loop)
self.state = 178
self.match(seedotParser.T__0)
self.state = 179
self.match(seedotParser.Id)
self.state = 180
self.match(seedotParser.T__14)
self.state = 181
self.match(seedotParser.T__2)
self.state = 182
self.match(seedotParser.IntConst)
self.state = 183
self.match(seedotParser.T__15)
self.state = 184
self.match(seedotParser.IntConst)
self.state = 185
self.match(seedotParser.T__4)
self.state = 186
self.match(seedotParser.T__3)
self.state = 187
self.expr(0)
self.state = 188
self.match(seedotParser.T__1)
self.state = 189
self.expr(4)
pass
elif la_ == 16:
localctx = seedotParser.LetContext(self, localctx)
self._ctx = localctx
_prevctx = localctx
self.state = 191
self.match(seedotParser.Let)
self.state = 192
self.lhs()
self.state = 193
self.match(seedotParser.T__14)
self.state = 194
self.expr(0)
self.state = 195
self.match(seedotParser.In)
self.state = 196
self.expr(2)
pass
elif la_ == 17:
localctx = seedotParser.ParenContext(self, localctx)
self._ctx = localctx
_prevctx = localctx
self.state = 198
self.match(seedotParser.T__0)
self.state = 199
self.expr(0)
self.state = 200
self.match(seedotParser.T__1)
pass
self._ctx.stop = self._input.LT(-1)
self.state = 246
self._errHandler.sync(self)
_alt = self._interp.adaptivePredict(self._input,4,self._ctx)
while _alt!=2 and _alt!=ATN.INVALID_ALT_NUMBER:
if _alt==1:
if self._parseListeners is not None:
self.triggerExitRuleEvent()
_prevctx = localctx
self.state = 244
self._errHandler.sync(self)
la_ = self._interp.adaptivePredict(self._input,3,self._ctx)
if la_ == 1:
localctx = seedotParser.Bop1Context(self, seedotParser.ExprContext(self, _parentctx, _parentState))
self.pushNewRecursionContext(localctx, _startState, self.RULE_expr)
self.state = 204
if not self.precpred(self._ctx, 10):
from antlr4.error.Errors import FailedPredicateException
raise FailedPredicateException(self, "self.precpred(self._ctx, 10)")
self.state = 205
self.binOp()
self.state = 206
self.expr(11)
pass
elif la_ == 2:
localctx = seedotParser.Bop2Context(self, seedotParser.ExprContext(self, _parentctx, _parentState))
self.pushNewRecursionContext(localctx, _startState, self.RULE_expr)
self.state = 208
if not self.precpred(self._ctx, 9):
from antlr4.error.Errors import FailedPredicateException
raise FailedPredicateException(self, "self.precpred(self._ctx, 9)")
self.state = 209
self.addOp()
self.state = 210
self.expr(10)
pass
elif la_ == 3:
localctx = seedotParser.CondContext(self, seedotParser.ExprContext(self, _parentctx, _parentState))
self.pushNewRecursionContext(localctx, _startState, self.RULE_expr)
self.state = 212
if not self.precpred(self._ctx, 3):
from antlr4.error.Errors import FailedPredicateException
raise FailedPredicateException(self, "self.precpred(self._ctx, 3)")
self.state = 213
self.match(seedotParser.T__16)
self.state = 214
self.match(seedotParser.IntConst)
self.state = 215
self.match(seedotParser.T__17)
self.state = 216
self.expr(0)
self.state = 217
self.match(seedotParser.T__15)
self.state = 218
self.expr(4)
pass
elif la_ == 4:
localctx = seedotParser.TranspContext(self, seedotParser.ExprContext(self, _parentctx, _parentState))
self.pushNewRecursionContext(localctx, _startState, self.RULE_expr)
self.state = 220
if not self.precpred(self._ctx, 18):
from antlr4.error.Errors import FailedPredicateException
raise FailedPredicateException(self, "self.precpred(self._ctx, 18)")
self.state = 221
self.match(seedotParser.T__6)
pass
elif la_ == 5:
localctx = seedotParser.SpliceContext(self, seedotParser.ExprContext(self, _parentctx, _parentState))
self.pushNewRecursionContext(localctx, _startState, self.RULE_expr)
self.state = 222
if not self.precpred(self._ctx, 16):
from antlr4.error.Errors import FailedPredicateException
raise FailedPredicateException(self, "self.precpred(self._ctx, 16)")
self.state = 223
self.match(seedotParser.T__2)
self.state = 224
self.expr(0)
self.state = 225
self.match(seedotParser.T__7)
self.state = 226
self.match(seedotParser.IntConst)
self.state = 227
self.match(seedotParser.T__4)
self.state = 236
self._errHandler.sync(self)
_alt = self._interp.adaptivePredict(self._input,2,self._ctx)
while _alt!=2 and _alt!=ATN.INVALID_ALT_NUMBER:
if _alt==1:
self.state = 228
self.match(seedotParser.T__2)
self.state = 229
self.expr(0)
self.state = 230
self.match(seedotParser.T__7)
self.state = 231
self.match(seedotParser.IntConst)
self.state = 232
self.match(seedotParser.T__4)
self.state = 238
self._errHandler.sync(self)
_alt = self._interp.adaptivePredict(self._input,2,self._ctx)
pass
elif la_ == 6:
localctx = seedotParser.IndexContext(self, seedotParser.ExprContext(self, _parentctx, _parentState))
self.pushNewRecursionContext(localctx, _startState, self.RULE_expr)
self.state = 239
if not self.precpred(self._ctx, 13):
from antlr4.error.Errors import FailedPredicateException
raise FailedPredicateException(self, "self.precpred(self._ctx, 13)")
self.state = 240
self.match(seedotParser.T__2)
self.state = 241
self.expr(0)
self.state = 242
self.match(seedotParser.T__4)
pass
self.state = 248
self._errHandler.sync(self)
_alt = self._interp.adaptivePredict(self._input,4,self._ctx)
except RecognitionException as re:
localctx.exception = re
self._errHandler.reportError(self, re)
self._errHandler.recover(self, re)
finally:
self.unrollRecursionContexts(_parentctx)
return localctx