aded break and continue
This commit is contained in:
@@ -14,6 +14,8 @@ stmt:
|
||||
ifStmt # IfStatement
|
||||
| whileStmt # WhileStatement
|
||||
| block # BlockStatement
|
||||
| breakStmt # BreakStatement
|
||||
| continueStmt # ContinueStatement
|
||||
| returnStmt # ReturnStatement
|
||||
| varDef # VarDefStmt
|
||||
| expr SEMICOLON # ExprStatement;
|
||||
@@ -21,6 +23,8 @@ stmt:
|
||||
ifStmt: IF LPAREN expr RPAREN stmt (ELSE stmt)?;
|
||||
whileStmt: WHILE LPAREN expr RPAREN stmt;
|
||||
block: LBRACE stmt* RBRACE;
|
||||
breakStmt: BREAK SEMICOLON;
|
||||
continueStmt: CONTINUE SEMICOLON;
|
||||
returnStmt: RETURN expr? SEMICOLON;
|
||||
|
||||
expr: ternaryExpr | atom | compExpr;
|
||||
@@ -299,6 +303,8 @@ SORT: 'sort';
|
||||
APPEND: 'append';
|
||||
|
||||
TIMESTAMP: 'timestamp' | 'now';
|
||||
BREAK: break;
|
||||
CONTINUE: continue;
|
||||
|
||||
PLUS: '+';
|
||||
MINUS: '-';
|
||||
|
||||
+132
-237
@@ -1,237 +1,132 @@
|
||||
SIN=1
|
||||
COS=2
|
||||
TAN=3
|
||||
ASIN=4
|
||||
ACOS=5
|
||||
ATAN=6
|
||||
ATAN2=7
|
||||
SINH=8
|
||||
COSH=9
|
||||
TANH=10
|
||||
ASINH=11
|
||||
ACOSH=12
|
||||
ATANH=13
|
||||
ABS=14
|
||||
SQRT=15
|
||||
LN=16
|
||||
LOG=17
|
||||
EXP=18
|
||||
SMIN=19
|
||||
SMAX=20
|
||||
TMIN=21
|
||||
TMAX=22
|
||||
TNORM=23
|
||||
SNORM=24
|
||||
FLOOR=25
|
||||
CEIL=26
|
||||
ROUND=27
|
||||
GAMMA=28
|
||||
POWE=29
|
||||
SIGM=30
|
||||
CLAMP=31
|
||||
SFFT=32
|
||||
SIFFT=33
|
||||
ANGL=34
|
||||
PRNT=35
|
||||
PRINT_SHAPE=36
|
||||
NVL=37
|
||||
LERP=38
|
||||
STEP=39
|
||||
SMOOTHSTEP=40
|
||||
FRACT=41
|
||||
RELU=42
|
||||
SOFTPLUS=43
|
||||
GELU=44
|
||||
SIGN=45
|
||||
MAP=46
|
||||
EZCONV=47
|
||||
CONV=48
|
||||
SWAP=49
|
||||
PERM=50
|
||||
RESHAPE=51
|
||||
RANGE=52
|
||||
TOPK=53
|
||||
BOTK=54
|
||||
PINV=55
|
||||
SUM=56
|
||||
MEAN=57
|
||||
STD=58
|
||||
VAR=59
|
||||
QUARTILE=60
|
||||
PERCENTILE=61
|
||||
QUANTILE=62
|
||||
DOT=63
|
||||
MOMENT=64
|
||||
ANY=65
|
||||
ALL=66
|
||||
EDGE=67
|
||||
GAUSSIAN=68
|
||||
MEDIAN=69
|
||||
MODE=70
|
||||
CUMSUM=71
|
||||
CUMPROD=72
|
||||
TOPK_IND=73
|
||||
BOTK_IND=74
|
||||
CUBIC_EASE=75
|
||||
ELASTIC_EASE=76
|
||||
SINE_EASE=77
|
||||
SMOOTHERSTEP=78
|
||||
DIST=79
|
||||
REMAP=80
|
||||
IF=81
|
||||
ELSE=82
|
||||
WHILE=83
|
||||
RETURN=84
|
||||
PUSH=85
|
||||
POP=86
|
||||
CLEAR=87
|
||||
HAS=88
|
||||
GET=89
|
||||
NOISE=90
|
||||
RAND=91
|
||||
CAUCHY=92
|
||||
EXPONENTIAL=93
|
||||
LOGNORMAL=94
|
||||
BERNOULLI=95
|
||||
POISSON=96
|
||||
COSSIM=97
|
||||
FLIP=98
|
||||
COV=99
|
||||
SORT=100
|
||||
APPEND=101
|
||||
TIMESTAMP=102
|
||||
PLUS=103
|
||||
MINUS=104
|
||||
MULT=105
|
||||
DIV=106
|
||||
MOD=107
|
||||
POW=108
|
||||
GE=109
|
||||
GT=110
|
||||
LE=111
|
||||
LT=112
|
||||
EQ=113
|
||||
EQUEALS=114
|
||||
NE=115
|
||||
PIPE=116
|
||||
LPAREN=117
|
||||
RPAREN=118
|
||||
COMMA=119
|
||||
SEMICOLON=120
|
||||
ARROW=121
|
||||
LBRACKET=122
|
||||
RBRACKET=123
|
||||
QUESTION=124
|
||||
COLON=125
|
||||
LBRACE=126
|
||||
RBRACE=127
|
||||
CONSTANT=128
|
||||
NUMBER=129
|
||||
VARIABLE=130
|
||||
SL_COMMENT=131
|
||||
ML_COMMENT=132
|
||||
WS=133
|
||||
'sin'=1
|
||||
'cos'=2
|
||||
'tan'=3
|
||||
'asin'=4
|
||||
'acos'=5
|
||||
'atan'=6
|
||||
'atan2'=7
|
||||
'sinh'=8
|
||||
'cosh'=9
|
||||
'tanh'=10
|
||||
'asinh'=11
|
||||
'acosh'=12
|
||||
'atanh'=13
|
||||
'abs'=14
|
||||
'sqrt'=15
|
||||
'ln'=16
|
||||
'log'=17
|
||||
'exp'=18
|
||||
'smin'=19
|
||||
'smax'=20
|
||||
'tmin'=21
|
||||
'tmax'=22
|
||||
'tnorm'=23
|
||||
'snorm'=24
|
||||
'floor'=25
|
||||
'ceil'=26
|
||||
'round'=27
|
||||
'gamma'=28
|
||||
'pow'=29
|
||||
'sigm'=30
|
||||
'clamp'=31
|
||||
'fft'=32
|
||||
'ifft'=33
|
||||
'angle'=34
|
||||
'print'=35
|
||||
'lerp'=38
|
||||
'step'=39
|
||||
'smoothstep'=40
|
||||
'fract'=41
|
||||
'relu'=42
|
||||
'softplus'=43
|
||||
'gelu'=44
|
||||
'sign'=45
|
||||
'map'=46
|
||||
'swap'=49
|
||||
'range'=52
|
||||
'topk'=53
|
||||
'botk'=54
|
||||
'pinv'=55
|
||||
'sum'=56
|
||||
'mean'=57
|
||||
'std'=58
|
||||
'var'=59
|
||||
'quantile'=62
|
||||
'dot'=63
|
||||
'moment'=64
|
||||
'any'=65
|
||||
'all'=66
|
||||
'edge'=67
|
||||
'median'=69
|
||||
'mode'=70
|
||||
'cumsum'=71
|
||||
'cumprod'=72
|
||||
'smootherstep'=78
|
||||
'remap'=80
|
||||
'if'=81
|
||||
'else'=82
|
||||
'while'=83
|
||||
'return'=84
|
||||
'push'=85
|
||||
'pop'=86
|
||||
'clear'=87
|
||||
'has'=88
|
||||
'get'=89
|
||||
'cossim'=97
|
||||
'flip'=98
|
||||
'cov'=99
|
||||
'sort'=100
|
||||
'append'=101
|
||||
'+'=103
|
||||
'-'=104
|
||||
'*'=105
|
||||
'/'=106
|
||||
'%'=107
|
||||
'^'=108
|
||||
'>='=109
|
||||
'>'=110
|
||||
'<='=111
|
||||
'<'=112
|
||||
'=='=113
|
||||
'='=114
|
||||
'!='=115
|
||||
'|'=116
|
||||
'('=117
|
||||
')'=118
|
||||
','=119
|
||||
';'=120
|
||||
'->'=121
|
||||
'['=122
|
||||
']'=123
|
||||
'?'=124
|
||||
':'=125
|
||||
'{'=126
|
||||
'}'=127
|
||||
VARIABLE=1
|
||||
LPAREN=2
|
||||
RPAREN=3
|
||||
ARROW=4
|
||||
SEMICOLON=5
|
||||
EQUEALS=6
|
||||
COMMA=7
|
||||
IF=8
|
||||
ELSE=9
|
||||
WHILE=10
|
||||
LBRACE=11
|
||||
RBRACE=12
|
||||
BREAK=13
|
||||
CONTINUE=14
|
||||
RETURN=15
|
||||
QUESTION=16
|
||||
COLON=17
|
||||
GT=18
|
||||
GE=19
|
||||
LT=20
|
||||
LE=21
|
||||
EQ=22
|
||||
NE=23
|
||||
PLUS=24
|
||||
MINUS=25
|
||||
MULT=26
|
||||
DIV=27
|
||||
MOD=28
|
||||
POW=29
|
||||
LBRACKET=30
|
||||
RBRACKET=31
|
||||
NUMBER=32
|
||||
CONSTANT=33
|
||||
PIPE=34
|
||||
TIMESTAMP=35
|
||||
SIN=36
|
||||
COS=37
|
||||
TAN=38
|
||||
ASIN=39
|
||||
ACOS=40
|
||||
ATAN=41
|
||||
SINH=42
|
||||
COSH=43
|
||||
TANH=44
|
||||
ASINH=45
|
||||
ACOSH=46
|
||||
ATANH=47
|
||||
ABS=48
|
||||
SQRT=49
|
||||
LN=50
|
||||
LOG=51
|
||||
EXP=52
|
||||
TNORM=53
|
||||
SNORM=54
|
||||
FLOOR=55
|
||||
CEIL=56
|
||||
ROUND=57
|
||||
GAMMA=58
|
||||
SIGM=59
|
||||
SFFT=60
|
||||
SIFFT=61
|
||||
ANGL=62
|
||||
PRNT=63
|
||||
FRACT=64
|
||||
RELU=65
|
||||
SOFTPLUS=66
|
||||
GELU=67
|
||||
SIGN=68
|
||||
PRINT_SHAPE=69
|
||||
PINV=70
|
||||
SUM=71
|
||||
MEAN=72
|
||||
STD=73
|
||||
VAR=74
|
||||
SORT=75
|
||||
NOISE=76
|
||||
RAND=77
|
||||
ANY=78
|
||||
ALL=79
|
||||
EDGE=80
|
||||
MEDIAN=81
|
||||
MODE=82
|
||||
CUMSUM=83
|
||||
CUMPROD=84
|
||||
POP=85
|
||||
CLEAR=86
|
||||
HAS=87
|
||||
GET=88
|
||||
POWE=89
|
||||
ATAN2=90
|
||||
TMIN=91
|
||||
TMAX=92
|
||||
STEP=93
|
||||
TOPK=94
|
||||
BOTK=95
|
||||
QUARTILE=96
|
||||
PERCENTILE=97
|
||||
QUANTILE=98
|
||||
DOT=99
|
||||
COSSIM=100
|
||||
FLIP=101
|
||||
COV=102
|
||||
APPEND=103
|
||||
EXPONENTIAL=104
|
||||
BERNOULLI=105
|
||||
POISSON=106
|
||||
GAUSSIAN=107
|
||||
TOPK_IND=108
|
||||
BOTK_IND=109
|
||||
PUSH=110
|
||||
CLAMP=111
|
||||
LERP=112
|
||||
SMOOTHSTEP=113
|
||||
RANGE=114
|
||||
MOMENT=115
|
||||
CAUCHY=116
|
||||
LOGNORMAL=117
|
||||
CUBIC_EASE=118
|
||||
ELASTIC_EASE=119
|
||||
SINE_EASE=120
|
||||
SMOOTHERSTEP=121
|
||||
SWAP=122
|
||||
NVL=123
|
||||
DIST=124
|
||||
REMAP=125
|
||||
SMIN=126
|
||||
SMAX=127
|
||||
MAP=128
|
||||
EZCONV=129
|
||||
CONV=130
|
||||
PERM=131
|
||||
RESHAPE=132
|
||||
|
||||
+1872
-1761
File diff suppressed because it is too large
Load Diff
@@ -44,6 +44,16 @@ class MathExprVisitor(ParseTreeVisitor):
|
||||
return self.visitChildren(ctx)
|
||||
|
||||
|
||||
# Visit a parse tree produced by MathExprParser#BreakStatement.
|
||||
def visitBreakStatement(self, ctx:MathExprParser.BreakStatementContext):
|
||||
return self.visitChildren(ctx)
|
||||
|
||||
|
||||
# Visit a parse tree produced by MathExprParser#ContinueStatement.
|
||||
def visitContinueStatement(self, ctx:MathExprParser.ContinueStatementContext):
|
||||
return self.visitChildren(ctx)
|
||||
|
||||
|
||||
# Visit a parse tree produced by MathExprParser#ReturnStatement.
|
||||
def visitReturnStatement(self, ctx:MathExprParser.ReturnStatementContext):
|
||||
return self.visitChildren(ctx)
|
||||
@@ -74,6 +84,16 @@ class MathExprVisitor(ParseTreeVisitor):
|
||||
return self.visitChildren(ctx)
|
||||
|
||||
|
||||
# Visit a parse tree produced by MathExprParser#breakStmt.
|
||||
def visitBreakStmt(self, ctx:MathExprParser.BreakStmtContext):
|
||||
return self.visitChildren(ctx)
|
||||
|
||||
|
||||
# Visit a parse tree produced by MathExprParser#continueStmt.
|
||||
def visitContinueStmt(self, ctx:MathExprParser.ContinueStmtContext):
|
||||
return self.visitChildren(ctx)
|
||||
|
||||
|
||||
# Visit a parse tree produced by MathExprParser#returnStmt.
|
||||
def visitReturnStmt(self, ctx:MathExprParser.ReturnStmtContext):
|
||||
return self.visitChildren(ctx)
|
||||
|
||||
@@ -12,6 +12,11 @@ class ReturnSignal:
|
||||
def __init__(self, value):
|
||||
self.value = value
|
||||
|
||||
class BreakSignal:
|
||||
pass
|
||||
|
||||
class ContinueSignal:
|
||||
pass
|
||||
|
||||
class UnifiedMathVisitor(MathExprVisitor):
|
||||
def __init__(self, variables, shape=None, device=None, functions=None, depth=0, state_storage=None):
|
||||
@@ -1288,6 +1293,8 @@ class UnifiedMathVisitor(MathExprVisitor):
|
||||
|
||||
if isinstance(res, ReturnSignal):
|
||||
return res.value
|
||||
if isinstance(res, (BreakSignal, ContinueSignal)):
|
||||
raise RuntimeError("break/continue outside of loop")
|
||||
|
||||
final_expr_node = ctx.getChild(count - 2)
|
||||
if final_expr_node:
|
||||
@@ -1363,7 +1370,16 @@ class UnifiedMathVisitor(MathExprVisitor):
|
||||
|
||||
if isinstance(res, ReturnSignal):
|
||||
return res
|
||||
if isinstance(res, BreakSignal):
|
||||
break
|
||||
if isinstance(res, ContinueSignal):
|
||||
continue
|
||||
return None
|
||||
def visitBreakStmt(self, ctx):
|
||||
return BreakSignal()
|
||||
|
||||
def visitContinueStmt(self, ctx):
|
||||
return ContinueSignal()
|
||||
|
||||
def visitReturnStatement(self, ctx):
|
||||
res = yield ctx.returnStmt()
|
||||
|
||||
Reference in New Issue
Block a user