added element wise comparison operators
This commit is contained in:
@@ -56,6 +56,19 @@ class FloatEvalVisitor(MathExprVisitor):
|
||||
def visitPowExp(self, ctx):
|
||||
return math.pow(self.visit(ctx.unaryExpr()), self.visit(ctx.powExpr()))
|
||||
|
||||
def visitNeExp(self, ctx):
|
||||
return float(self.visit(ctx.neqExpr()) != self.visit(ctx.eqExpr()))
|
||||
def visitEqExp(self, ctx):
|
||||
return float(self.visit(ctx.eqExpr()) == self.visit(ctx.gtExpr()))
|
||||
def visitGtExp(self, ctx):
|
||||
return float(self.visit(ctx.gtExpr()) > self.visit(ctx.ltExpr()))
|
||||
def visitLtExp(self, ctx):
|
||||
return float(self.visit(ctx.ltExpr()) < self.visit(ctx.lteExpr()))
|
||||
def visitGeExp(self, ctx):
|
||||
return float(self.visit(ctx.gteExpr()) >= self.visit(ctx.neqExpr()))
|
||||
def visitLeExp(self, ctx):
|
||||
return float(self.visit(ctx.lteExpr()) <= self.visit(ctx.neqExpr()))
|
||||
|
||||
def visitToUnary(self, ctx):
|
||||
return self.visit(ctx.unaryExpr())
|
||||
|
||||
@@ -68,20 +81,18 @@ class FloatEvalVisitor(MathExprVisitor):
|
||||
def visitToAdd(self, ctx):
|
||||
return self.visit(ctx.addExpr())
|
||||
|
||||
def visitToAnd(self, ctx):
|
||||
return self.visit(ctx.andExpr())
|
||||
|
||||
def visitToXor(self, ctx):
|
||||
return self.visit(ctx.xorExpr())
|
||||
|
||||
def visitOrExp(self, ctx):
|
||||
return self.visit(ctx.orExpr()).bool() | self.visit(ctx.xorExpr()).bool()
|
||||
|
||||
def visitXorExp(self, ctx):
|
||||
return self.visit(ctx.xorExpr()).bool() ^ self.visit(ctx.andExpr()).bool()
|
||||
|
||||
def visitAndExp(self, ctx):
|
||||
return self.visit(ctx.andExpr()).bool() & self.visit(ctx.addExpr()).bool()
|
||||
def visitToGt(self, ctx):
|
||||
return self.visit(ctx.gtExpr())
|
||||
def visitToLt(self, ctx):
|
||||
return self.visit(ctx.ltExpr())
|
||||
def visitToEq(self, ctx):
|
||||
return self.visit(ctx.eqExpr())
|
||||
def visitToNeq(self, ctx):
|
||||
return self.visit(ctx.neqExpr())
|
||||
def visitToGe(self, ctx):
|
||||
return self.visit(ctx.gteExpr())
|
||||
def visitToLe(self, ctx):
|
||||
return self.visit(ctx.lteExpr())
|
||||
|
||||
# Single-argument functions
|
||||
def visitSinFunc(self, ctx): return math.sin(self.visit(ctx.expr()))
|
||||
|
||||
@@ -5,6 +5,15 @@ expr
|
||||
: atom | addExpr
|
||||
;
|
||||
|
||||
compExpr
|
||||
: compExpr GT addExpr # GtExp
|
||||
| compExpr GE addExpr # GeExp
|
||||
| compExpr LT addExpr # LtExp
|
||||
| compExpr LE addExpr # LeExp
|
||||
| compExpr EQ addExpr # EqExp
|
||||
| compExpr NE addExpr # NeExp
|
||||
| addExpr # ToAdd
|
||||
;
|
||||
|
||||
addExpr
|
||||
: addExpr PLUS mulExpr # AddExp
|
||||
@@ -135,6 +144,13 @@ DIV : '/';
|
||||
MOD : '%';
|
||||
POW : '^';
|
||||
|
||||
GE : '>=';
|
||||
GT : '>';
|
||||
LE : '<=';
|
||||
LT : '<';
|
||||
EQ : '==';
|
||||
NE : '!=';
|
||||
|
||||
CONSTANT : ('pi'|'PI'|'e'|'E');
|
||||
NUMBER : [0-9]+ ('.' [0-9]+)?;
|
||||
VARIABLE : [a-zA-Z_] [a-zA-Z_0-9]*;
|
||||
|
||||
File diff suppressed because one or more lines are too long
@@ -41,10 +41,16 @@ MULT=40
|
||||
DIV=41
|
||||
MOD=42
|
||||
POW=43
|
||||
CONSTANT=44
|
||||
NUMBER=45
|
||||
VARIABLE=46
|
||||
WS=47
|
||||
GE=44
|
||||
GT=45
|
||||
LE=46
|
||||
LT=47
|
||||
EQ=48
|
||||
NE=49
|
||||
CONSTANT=50
|
||||
NUMBER=51
|
||||
VARIABLE=52
|
||||
WS=53
|
||||
'('=1
|
||||
')'=2
|
||||
','=3
|
||||
@@ -88,3 +94,9 @@ WS=47
|
||||
'/'=41
|
||||
'%'=42
|
||||
'^'=43
|
||||
'>='=44
|
||||
'>'=45
|
||||
'<='=46
|
||||
'<'=47
|
||||
'=='=48
|
||||
'!='=49
|
||||
|
||||
File diff suppressed because one or more lines are too long
@@ -10,117 +10,127 @@ else:
|
||||
|
||||
def serializedATN():
|
||||
return [
|
||||
4,0,47,318,6,-1,2,0,7,0,2,1,7,1,2,2,7,2,2,3,7,3,2,4,7,4,2,5,7,5,
|
||||
4,0,53,346,6,-1,2,0,7,0,2,1,7,1,2,2,7,2,2,3,7,3,2,4,7,4,2,5,7,5,
|
||||
2,6,7,6,2,7,7,7,2,8,7,8,2,9,7,9,2,10,7,10,2,11,7,11,2,12,7,12,2,
|
||||
13,7,13,2,14,7,14,2,15,7,15,2,16,7,16,2,17,7,17,2,18,7,18,2,19,7,
|
||||
19,2,20,7,20,2,21,7,21,2,22,7,22,2,23,7,23,2,24,7,24,2,25,7,25,2,
|
||||
26,7,26,2,27,7,27,2,28,7,28,2,29,7,29,2,30,7,30,2,31,7,31,2,32,7,
|
||||
32,2,33,7,33,2,34,7,34,2,35,7,35,2,36,7,36,2,37,7,37,2,38,7,38,2,
|
||||
39,7,39,2,40,7,40,2,41,7,41,2,42,7,42,2,43,7,43,2,44,7,44,2,45,7,
|
||||
45,2,46,7,46,1,0,1,0,1,1,1,1,1,2,1,2,1,3,1,3,1,3,1,3,1,4,1,4,1,4,
|
||||
1,4,1,5,1,5,1,5,1,5,1,6,1,6,1,6,1,6,1,6,1,7,1,7,1,7,1,7,1,7,1,8,
|
||||
1,8,1,8,1,8,1,8,1,9,1,9,1,9,1,9,1,9,1,9,1,10,1,10,1,10,1,10,1,10,
|
||||
1,11,1,11,1,11,1,11,1,11,1,12,1,12,1,12,1,12,1,12,1,13,1,13,1,13,
|
||||
1,13,1,13,1,13,1,14,1,14,1,14,1,14,1,14,1,14,1,15,1,15,1,15,1,15,
|
||||
1,15,1,15,1,16,1,16,1,16,1,16,1,17,1,17,1,17,1,17,1,17,1,18,1,18,
|
||||
1,18,1,19,1,19,1,19,1,19,1,20,1,20,1,20,1,20,1,21,1,21,1,21,1,21,
|
||||
1,21,1,22,1,22,1,22,1,22,1,22,1,23,1,23,1,23,1,23,1,23,1,24,1,24,
|
||||
1,24,1,24,1,24,1,25,1,25,1,25,1,25,1,25,1,25,1,26,1,26,1,26,1,26,
|
||||
1,26,1,26,1,27,1,27,1,27,1,27,1,27,1,27,1,28,1,28,1,28,1,28,1,28,
|
||||
1,29,1,29,1,29,1,29,1,29,1,29,1,30,1,30,1,30,1,30,1,30,1,30,1,31,
|
||||
1,31,1,31,1,31,1,32,1,32,1,32,1,32,1,32,1,33,1,33,1,33,1,33,1,33,
|
||||
1,33,1,34,1,34,1,34,1,34,1,35,1,35,1,35,1,35,1,35,1,36,1,36,1,36,
|
||||
1,36,1,36,1,36,1,37,1,37,1,38,1,38,1,39,1,39,1,40,1,40,1,41,1,41,
|
||||
1,42,1,42,1,43,1,43,1,43,1,43,1,43,3,43,290,8,43,1,44,4,44,293,8,
|
||||
44,11,44,12,44,294,1,44,1,44,4,44,299,8,44,11,44,12,44,300,3,44,
|
||||
303,8,44,1,45,1,45,5,45,307,8,45,10,45,12,45,310,9,45,1,46,4,46,
|
||||
313,8,46,11,46,12,46,314,1,46,1,46,0,0,47,1,1,3,2,5,3,7,4,9,5,11,
|
||||
6,13,7,15,8,17,9,19,10,21,11,23,12,25,13,27,14,29,15,31,16,33,17,
|
||||
35,18,37,19,39,20,41,21,43,22,45,23,47,24,49,25,51,26,53,27,55,28,
|
||||
57,29,59,30,61,31,63,32,65,33,67,34,69,35,71,36,73,37,75,38,77,39,
|
||||
79,40,81,41,83,42,85,43,87,44,89,45,91,46,93,47,1,0,5,2,0,69,69,
|
||||
101,101,1,0,48,57,3,0,65,90,95,95,97,122,4,0,48,57,65,90,95,95,97,
|
||||
122,3,0,9,10,13,13,32,32,324,0,1,1,0,0,0,0,3,1,0,0,0,0,5,1,0,0,0,
|
||||
0,7,1,0,0,0,0,9,1,0,0,0,0,11,1,0,0,0,0,13,1,0,0,0,0,15,1,0,0,0,0,
|
||||
17,1,0,0,0,0,19,1,0,0,0,0,21,1,0,0,0,0,23,1,0,0,0,0,25,1,0,0,0,0,
|
||||
27,1,0,0,0,0,29,1,0,0,0,0,31,1,0,0,0,0,33,1,0,0,0,0,35,1,0,0,0,0,
|
||||
37,1,0,0,0,0,39,1,0,0,0,0,41,1,0,0,0,0,43,1,0,0,0,0,45,1,0,0,0,0,
|
||||
47,1,0,0,0,0,49,1,0,0,0,0,51,1,0,0,0,0,53,1,0,0,0,0,55,1,0,0,0,0,
|
||||
57,1,0,0,0,0,59,1,0,0,0,0,61,1,0,0,0,0,63,1,0,0,0,0,65,1,0,0,0,0,
|
||||
67,1,0,0,0,0,69,1,0,0,0,0,71,1,0,0,0,0,73,1,0,0,0,0,75,1,0,0,0,0,
|
||||
77,1,0,0,0,0,79,1,0,0,0,0,81,1,0,0,0,0,83,1,0,0,0,0,85,1,0,0,0,0,
|
||||
87,1,0,0,0,0,89,1,0,0,0,0,91,1,0,0,0,0,93,1,0,0,0,1,95,1,0,0,0,3,
|
||||
97,1,0,0,0,5,99,1,0,0,0,7,101,1,0,0,0,9,105,1,0,0,0,11,109,1,0,0,
|
||||
0,13,113,1,0,0,0,15,118,1,0,0,0,17,123,1,0,0,0,19,128,1,0,0,0,21,
|
||||
134,1,0,0,0,23,139,1,0,0,0,25,144,1,0,0,0,27,149,1,0,0,0,29,155,
|
||||
1,0,0,0,31,161,1,0,0,0,33,167,1,0,0,0,35,171,1,0,0,0,37,176,1,0,
|
||||
0,0,39,179,1,0,0,0,41,183,1,0,0,0,43,187,1,0,0,0,45,192,1,0,0,0,
|
||||
47,197,1,0,0,0,49,202,1,0,0,0,51,207,1,0,0,0,53,213,1,0,0,0,55,219,
|
||||
1,0,0,0,57,225,1,0,0,0,59,230,1,0,0,0,61,236,1,0,0,0,63,242,1,0,
|
||||
0,0,65,246,1,0,0,0,67,251,1,0,0,0,69,257,1,0,0,0,71,261,1,0,0,0,
|
||||
73,266,1,0,0,0,75,272,1,0,0,0,77,274,1,0,0,0,79,276,1,0,0,0,81,278,
|
||||
1,0,0,0,83,280,1,0,0,0,85,282,1,0,0,0,87,289,1,0,0,0,89,292,1,0,
|
||||
0,0,91,304,1,0,0,0,93,312,1,0,0,0,95,96,5,40,0,0,96,2,1,0,0,0,97,
|
||||
98,5,41,0,0,98,4,1,0,0,0,99,100,5,44,0,0,100,6,1,0,0,0,101,102,5,
|
||||
115,0,0,102,103,5,105,0,0,103,104,5,110,0,0,104,8,1,0,0,0,105,106,
|
||||
5,99,0,0,106,107,5,111,0,0,107,108,5,115,0,0,108,10,1,0,0,0,109,
|
||||
110,5,116,0,0,110,111,5,97,0,0,111,112,5,110,0,0,112,12,1,0,0,0,
|
||||
113,114,5,97,0,0,114,115,5,115,0,0,115,116,5,105,0,0,116,117,5,110,
|
||||
0,0,117,14,1,0,0,0,118,119,5,97,0,0,119,120,5,99,0,0,120,121,5,111,
|
||||
0,0,121,122,5,115,0,0,122,16,1,0,0,0,123,124,5,97,0,0,124,125,5,
|
||||
116,0,0,125,126,5,97,0,0,126,127,5,110,0,0,127,18,1,0,0,0,128,129,
|
||||
5,97,0,0,129,130,5,116,0,0,130,131,5,97,0,0,131,132,5,110,0,0,132,
|
||||
133,5,50,0,0,133,20,1,0,0,0,134,135,5,115,0,0,135,136,5,105,0,0,
|
||||
136,137,5,110,0,0,137,138,5,104,0,0,138,22,1,0,0,0,139,140,5,99,
|
||||
0,0,140,141,5,111,0,0,141,142,5,115,0,0,142,143,5,104,0,0,143,24,
|
||||
1,0,0,0,144,145,5,116,0,0,145,146,5,97,0,0,146,147,5,110,0,0,147,
|
||||
148,5,104,0,0,148,26,1,0,0,0,149,150,5,97,0,0,150,151,5,115,0,0,
|
||||
151,152,5,105,0,0,152,153,5,110,0,0,153,154,5,104,0,0,154,28,1,0,
|
||||
0,0,155,156,5,97,0,0,156,157,5,99,0,0,157,158,5,111,0,0,158,159,
|
||||
5,115,0,0,159,160,5,104,0,0,160,30,1,0,0,0,161,162,5,97,0,0,162,
|
||||
163,5,116,0,0,163,164,5,97,0,0,164,165,5,110,0,0,165,166,5,104,0,
|
||||
0,166,32,1,0,0,0,167,168,5,97,0,0,168,169,5,98,0,0,169,170,5,115,
|
||||
0,0,170,34,1,0,0,0,171,172,5,115,0,0,172,173,5,113,0,0,173,174,5,
|
||||
114,0,0,174,175,5,116,0,0,175,36,1,0,0,0,176,177,5,108,0,0,177,178,
|
||||
5,110,0,0,178,38,1,0,0,0,179,180,5,108,0,0,180,181,5,111,0,0,181,
|
||||
182,5,103,0,0,182,40,1,0,0,0,183,184,5,101,0,0,184,185,5,120,0,0,
|
||||
185,186,5,112,0,0,186,42,1,0,0,0,187,188,5,115,0,0,188,189,5,109,
|
||||
0,0,189,190,5,105,0,0,190,191,5,110,0,0,191,44,1,0,0,0,192,193,5,
|
||||
115,0,0,193,194,5,109,0,0,194,195,5,97,0,0,195,196,5,120,0,0,196,
|
||||
46,1,0,0,0,197,198,5,116,0,0,198,199,5,109,0,0,199,200,5,105,0,0,
|
||||
200,201,5,110,0,0,201,48,1,0,0,0,202,203,5,116,0,0,203,204,5,109,
|
||||
0,0,204,205,5,97,0,0,205,206,5,120,0,0,206,50,1,0,0,0,207,208,5,
|
||||
116,0,0,208,209,5,110,0,0,209,210,5,111,0,0,210,211,5,114,0,0,211,
|
||||
212,5,109,0,0,212,52,1,0,0,0,213,214,5,115,0,0,214,215,5,110,0,0,
|
||||
215,216,5,111,0,0,216,217,5,114,0,0,217,218,5,109,0,0,218,54,1,0,
|
||||
0,0,219,220,5,102,0,0,220,221,5,108,0,0,221,222,5,111,0,0,222,223,
|
||||
5,111,0,0,223,224,5,114,0,0,224,56,1,0,0,0,225,226,5,99,0,0,226,
|
||||
227,5,101,0,0,227,228,5,105,0,0,228,229,5,108,0,0,229,58,1,0,0,0,
|
||||
230,231,5,114,0,0,231,232,5,111,0,0,232,233,5,117,0,0,233,234,5,
|
||||
110,0,0,234,235,5,100,0,0,235,60,1,0,0,0,236,237,5,103,0,0,237,238,
|
||||
5,97,0,0,238,239,5,109,0,0,239,240,5,109,0,0,240,241,5,97,0,0,241,
|
||||
62,1,0,0,0,242,243,5,112,0,0,243,244,5,111,0,0,244,245,5,119,0,0,
|
||||
245,64,1,0,0,0,246,247,5,115,0,0,247,248,5,105,0,0,248,249,5,103,
|
||||
0,0,249,250,5,109,0,0,250,66,1,0,0,0,251,252,5,99,0,0,252,253,5,
|
||||
108,0,0,253,254,5,97,0,0,254,255,5,109,0,0,255,256,5,112,0,0,256,
|
||||
68,1,0,0,0,257,258,5,102,0,0,258,259,5,102,0,0,259,260,5,116,0,0,
|
||||
260,70,1,0,0,0,261,262,5,105,0,0,262,263,5,102,0,0,263,264,5,102,
|
||||
0,0,264,265,5,116,0,0,265,72,1,0,0,0,266,267,5,97,0,0,267,268,5,
|
||||
110,0,0,268,269,5,103,0,0,269,270,5,108,0,0,270,271,5,101,0,0,271,
|
||||
74,1,0,0,0,272,273,5,43,0,0,273,76,1,0,0,0,274,275,5,45,0,0,275,
|
||||
78,1,0,0,0,276,277,5,42,0,0,277,80,1,0,0,0,278,279,5,47,0,0,279,
|
||||
82,1,0,0,0,280,281,5,37,0,0,281,84,1,0,0,0,282,283,5,94,0,0,283,
|
||||
86,1,0,0,0,284,285,5,112,0,0,285,290,5,105,0,0,286,287,5,80,0,0,
|
||||
287,290,5,73,0,0,288,290,7,0,0,0,289,284,1,0,0,0,289,286,1,0,0,0,
|
||||
289,288,1,0,0,0,290,88,1,0,0,0,291,293,7,1,0,0,292,291,1,0,0,0,293,
|
||||
294,1,0,0,0,294,292,1,0,0,0,294,295,1,0,0,0,295,302,1,0,0,0,296,
|
||||
298,5,46,0,0,297,299,7,1,0,0,298,297,1,0,0,0,299,300,1,0,0,0,300,
|
||||
298,1,0,0,0,300,301,1,0,0,0,301,303,1,0,0,0,302,296,1,0,0,0,302,
|
||||
303,1,0,0,0,303,90,1,0,0,0,304,308,7,2,0,0,305,307,7,3,0,0,306,305,
|
||||
1,0,0,0,307,310,1,0,0,0,308,306,1,0,0,0,308,309,1,0,0,0,309,92,1,
|
||||
0,0,0,310,308,1,0,0,0,311,313,7,4,0,0,312,311,1,0,0,0,313,314,1,
|
||||
0,0,0,314,312,1,0,0,0,314,315,1,0,0,0,315,316,1,0,0,0,316,317,6,
|
||||
46,0,0,317,94,1,0,0,0,7,0,289,294,300,302,308,314,1,6,0,0
|
||||
45,2,46,7,46,2,47,7,47,2,48,7,48,2,49,7,49,2,50,7,50,2,51,7,51,2,
|
||||
52,7,52,1,0,1,0,1,1,1,1,1,2,1,2,1,3,1,3,1,3,1,3,1,4,1,4,1,4,1,4,
|
||||
1,5,1,5,1,5,1,5,1,6,1,6,1,6,1,6,1,6,1,7,1,7,1,7,1,7,1,7,1,8,1,8,
|
||||
1,8,1,8,1,8,1,9,1,9,1,9,1,9,1,9,1,9,1,10,1,10,1,10,1,10,1,10,1,11,
|
||||
1,11,1,11,1,11,1,11,1,12,1,12,1,12,1,12,1,12,1,13,1,13,1,13,1,13,
|
||||
1,13,1,13,1,14,1,14,1,14,1,14,1,14,1,14,1,15,1,15,1,15,1,15,1,15,
|
||||
1,15,1,16,1,16,1,16,1,16,1,17,1,17,1,17,1,17,1,17,1,18,1,18,1,18,
|
||||
1,19,1,19,1,19,1,19,1,20,1,20,1,20,1,20,1,21,1,21,1,21,1,21,1,21,
|
||||
1,22,1,22,1,22,1,22,1,22,1,23,1,23,1,23,1,23,1,23,1,24,1,24,1,24,
|
||||
1,24,1,24,1,25,1,25,1,25,1,25,1,25,1,25,1,26,1,26,1,26,1,26,1,26,
|
||||
1,26,1,27,1,27,1,27,1,27,1,27,1,27,1,28,1,28,1,28,1,28,1,28,1,29,
|
||||
1,29,1,29,1,29,1,29,1,29,1,30,1,30,1,30,1,30,1,30,1,30,1,31,1,31,
|
||||
1,31,1,31,1,32,1,32,1,32,1,32,1,32,1,33,1,33,1,33,1,33,1,33,1,33,
|
||||
1,34,1,34,1,34,1,34,1,35,1,35,1,35,1,35,1,35,1,36,1,36,1,36,1,36,
|
||||
1,36,1,36,1,37,1,37,1,38,1,38,1,39,1,39,1,40,1,40,1,41,1,41,1,42,
|
||||
1,42,1,43,1,43,1,43,1,44,1,44,1,45,1,45,1,45,1,46,1,46,1,47,1,47,
|
||||
1,47,1,48,1,48,1,48,1,49,1,49,1,49,1,49,1,49,3,49,318,8,49,1,50,
|
||||
4,50,321,8,50,11,50,12,50,322,1,50,1,50,4,50,327,8,50,11,50,12,50,
|
||||
328,3,50,331,8,50,1,51,1,51,5,51,335,8,51,10,51,12,51,338,9,51,1,
|
||||
52,4,52,341,8,52,11,52,12,52,342,1,52,1,52,0,0,53,1,1,3,2,5,3,7,
|
||||
4,9,5,11,6,13,7,15,8,17,9,19,10,21,11,23,12,25,13,27,14,29,15,31,
|
||||
16,33,17,35,18,37,19,39,20,41,21,43,22,45,23,47,24,49,25,51,26,53,
|
||||
27,55,28,57,29,59,30,61,31,63,32,65,33,67,34,69,35,71,36,73,37,75,
|
||||
38,77,39,79,40,81,41,83,42,85,43,87,44,89,45,91,46,93,47,95,48,97,
|
||||
49,99,50,101,51,103,52,105,53,1,0,5,2,0,69,69,101,101,1,0,48,57,
|
||||
3,0,65,90,95,95,97,122,4,0,48,57,65,90,95,95,97,122,3,0,9,10,13,
|
||||
13,32,32,352,0,1,1,0,0,0,0,3,1,0,0,0,0,5,1,0,0,0,0,7,1,0,0,0,0,9,
|
||||
1,0,0,0,0,11,1,0,0,0,0,13,1,0,0,0,0,15,1,0,0,0,0,17,1,0,0,0,0,19,
|
||||
1,0,0,0,0,21,1,0,0,0,0,23,1,0,0,0,0,25,1,0,0,0,0,27,1,0,0,0,0,29,
|
||||
1,0,0,0,0,31,1,0,0,0,0,33,1,0,0,0,0,35,1,0,0,0,0,37,1,0,0,0,0,39,
|
||||
1,0,0,0,0,41,1,0,0,0,0,43,1,0,0,0,0,45,1,0,0,0,0,47,1,0,0,0,0,49,
|
||||
1,0,0,0,0,51,1,0,0,0,0,53,1,0,0,0,0,55,1,0,0,0,0,57,1,0,0,0,0,59,
|
||||
1,0,0,0,0,61,1,0,0,0,0,63,1,0,0,0,0,65,1,0,0,0,0,67,1,0,0,0,0,69,
|
||||
1,0,0,0,0,71,1,0,0,0,0,73,1,0,0,0,0,75,1,0,0,0,0,77,1,0,0,0,0,79,
|
||||
1,0,0,0,0,81,1,0,0,0,0,83,1,0,0,0,0,85,1,0,0,0,0,87,1,0,0,0,0,89,
|
||||
1,0,0,0,0,91,1,0,0,0,0,93,1,0,0,0,0,95,1,0,0,0,0,97,1,0,0,0,0,99,
|
||||
1,0,0,0,0,101,1,0,0,0,0,103,1,0,0,0,0,105,1,0,0,0,1,107,1,0,0,0,
|
||||
3,109,1,0,0,0,5,111,1,0,0,0,7,113,1,0,0,0,9,117,1,0,0,0,11,121,1,
|
||||
0,0,0,13,125,1,0,0,0,15,130,1,0,0,0,17,135,1,0,0,0,19,140,1,0,0,
|
||||
0,21,146,1,0,0,0,23,151,1,0,0,0,25,156,1,0,0,0,27,161,1,0,0,0,29,
|
||||
167,1,0,0,0,31,173,1,0,0,0,33,179,1,0,0,0,35,183,1,0,0,0,37,188,
|
||||
1,0,0,0,39,191,1,0,0,0,41,195,1,0,0,0,43,199,1,0,0,0,45,204,1,0,
|
||||
0,0,47,209,1,0,0,0,49,214,1,0,0,0,51,219,1,0,0,0,53,225,1,0,0,0,
|
||||
55,231,1,0,0,0,57,237,1,0,0,0,59,242,1,0,0,0,61,248,1,0,0,0,63,254,
|
||||
1,0,0,0,65,258,1,0,0,0,67,263,1,0,0,0,69,269,1,0,0,0,71,273,1,0,
|
||||
0,0,73,278,1,0,0,0,75,284,1,0,0,0,77,286,1,0,0,0,79,288,1,0,0,0,
|
||||
81,290,1,0,0,0,83,292,1,0,0,0,85,294,1,0,0,0,87,296,1,0,0,0,89,299,
|
||||
1,0,0,0,91,301,1,0,0,0,93,304,1,0,0,0,95,306,1,0,0,0,97,309,1,0,
|
||||
0,0,99,317,1,0,0,0,101,320,1,0,0,0,103,332,1,0,0,0,105,340,1,0,0,
|
||||
0,107,108,5,40,0,0,108,2,1,0,0,0,109,110,5,41,0,0,110,4,1,0,0,0,
|
||||
111,112,5,44,0,0,112,6,1,0,0,0,113,114,5,115,0,0,114,115,5,105,0,
|
||||
0,115,116,5,110,0,0,116,8,1,0,0,0,117,118,5,99,0,0,118,119,5,111,
|
||||
0,0,119,120,5,115,0,0,120,10,1,0,0,0,121,122,5,116,0,0,122,123,5,
|
||||
97,0,0,123,124,5,110,0,0,124,12,1,0,0,0,125,126,5,97,0,0,126,127,
|
||||
5,115,0,0,127,128,5,105,0,0,128,129,5,110,0,0,129,14,1,0,0,0,130,
|
||||
131,5,97,0,0,131,132,5,99,0,0,132,133,5,111,0,0,133,134,5,115,0,
|
||||
0,134,16,1,0,0,0,135,136,5,97,0,0,136,137,5,116,0,0,137,138,5,97,
|
||||
0,0,138,139,5,110,0,0,139,18,1,0,0,0,140,141,5,97,0,0,141,142,5,
|
||||
116,0,0,142,143,5,97,0,0,143,144,5,110,0,0,144,145,5,50,0,0,145,
|
||||
20,1,0,0,0,146,147,5,115,0,0,147,148,5,105,0,0,148,149,5,110,0,0,
|
||||
149,150,5,104,0,0,150,22,1,0,0,0,151,152,5,99,0,0,152,153,5,111,
|
||||
0,0,153,154,5,115,0,0,154,155,5,104,0,0,155,24,1,0,0,0,156,157,5,
|
||||
116,0,0,157,158,5,97,0,0,158,159,5,110,0,0,159,160,5,104,0,0,160,
|
||||
26,1,0,0,0,161,162,5,97,0,0,162,163,5,115,0,0,163,164,5,105,0,0,
|
||||
164,165,5,110,0,0,165,166,5,104,0,0,166,28,1,0,0,0,167,168,5,97,
|
||||
0,0,168,169,5,99,0,0,169,170,5,111,0,0,170,171,5,115,0,0,171,172,
|
||||
5,104,0,0,172,30,1,0,0,0,173,174,5,97,0,0,174,175,5,116,0,0,175,
|
||||
176,5,97,0,0,176,177,5,110,0,0,177,178,5,104,0,0,178,32,1,0,0,0,
|
||||
179,180,5,97,0,0,180,181,5,98,0,0,181,182,5,115,0,0,182,34,1,0,0,
|
||||
0,183,184,5,115,0,0,184,185,5,113,0,0,185,186,5,114,0,0,186,187,
|
||||
5,116,0,0,187,36,1,0,0,0,188,189,5,108,0,0,189,190,5,110,0,0,190,
|
||||
38,1,0,0,0,191,192,5,108,0,0,192,193,5,111,0,0,193,194,5,103,0,0,
|
||||
194,40,1,0,0,0,195,196,5,101,0,0,196,197,5,120,0,0,197,198,5,112,
|
||||
0,0,198,42,1,0,0,0,199,200,5,115,0,0,200,201,5,109,0,0,201,202,5,
|
||||
105,0,0,202,203,5,110,0,0,203,44,1,0,0,0,204,205,5,115,0,0,205,206,
|
||||
5,109,0,0,206,207,5,97,0,0,207,208,5,120,0,0,208,46,1,0,0,0,209,
|
||||
210,5,116,0,0,210,211,5,109,0,0,211,212,5,105,0,0,212,213,5,110,
|
||||
0,0,213,48,1,0,0,0,214,215,5,116,0,0,215,216,5,109,0,0,216,217,5,
|
||||
97,0,0,217,218,5,120,0,0,218,50,1,0,0,0,219,220,5,116,0,0,220,221,
|
||||
5,110,0,0,221,222,5,111,0,0,222,223,5,114,0,0,223,224,5,109,0,0,
|
||||
224,52,1,0,0,0,225,226,5,115,0,0,226,227,5,110,0,0,227,228,5,111,
|
||||
0,0,228,229,5,114,0,0,229,230,5,109,0,0,230,54,1,0,0,0,231,232,5,
|
||||
102,0,0,232,233,5,108,0,0,233,234,5,111,0,0,234,235,5,111,0,0,235,
|
||||
236,5,114,0,0,236,56,1,0,0,0,237,238,5,99,0,0,238,239,5,101,0,0,
|
||||
239,240,5,105,0,0,240,241,5,108,0,0,241,58,1,0,0,0,242,243,5,114,
|
||||
0,0,243,244,5,111,0,0,244,245,5,117,0,0,245,246,5,110,0,0,246,247,
|
||||
5,100,0,0,247,60,1,0,0,0,248,249,5,103,0,0,249,250,5,97,0,0,250,
|
||||
251,5,109,0,0,251,252,5,109,0,0,252,253,5,97,0,0,253,62,1,0,0,0,
|
||||
254,255,5,112,0,0,255,256,5,111,0,0,256,257,5,119,0,0,257,64,1,0,
|
||||
0,0,258,259,5,115,0,0,259,260,5,105,0,0,260,261,5,103,0,0,261,262,
|
||||
5,109,0,0,262,66,1,0,0,0,263,264,5,99,0,0,264,265,5,108,0,0,265,
|
||||
266,5,97,0,0,266,267,5,109,0,0,267,268,5,112,0,0,268,68,1,0,0,0,
|
||||
269,270,5,102,0,0,270,271,5,102,0,0,271,272,5,116,0,0,272,70,1,0,
|
||||
0,0,273,274,5,105,0,0,274,275,5,102,0,0,275,276,5,102,0,0,276,277,
|
||||
5,116,0,0,277,72,1,0,0,0,278,279,5,97,0,0,279,280,5,110,0,0,280,
|
||||
281,5,103,0,0,281,282,5,108,0,0,282,283,5,101,0,0,283,74,1,0,0,0,
|
||||
284,285,5,43,0,0,285,76,1,0,0,0,286,287,5,45,0,0,287,78,1,0,0,0,
|
||||
288,289,5,42,0,0,289,80,1,0,0,0,290,291,5,47,0,0,291,82,1,0,0,0,
|
||||
292,293,5,37,0,0,293,84,1,0,0,0,294,295,5,94,0,0,295,86,1,0,0,0,
|
||||
296,297,5,62,0,0,297,298,5,61,0,0,298,88,1,0,0,0,299,300,5,62,0,
|
||||
0,300,90,1,0,0,0,301,302,5,60,0,0,302,303,5,61,0,0,303,92,1,0,0,
|
||||
0,304,305,5,60,0,0,305,94,1,0,0,0,306,307,5,61,0,0,307,308,5,61,
|
||||
0,0,308,96,1,0,0,0,309,310,5,33,0,0,310,311,5,61,0,0,311,98,1,0,
|
||||
0,0,312,313,5,112,0,0,313,318,5,105,0,0,314,315,5,80,0,0,315,318,
|
||||
5,73,0,0,316,318,7,0,0,0,317,312,1,0,0,0,317,314,1,0,0,0,317,316,
|
||||
1,0,0,0,318,100,1,0,0,0,319,321,7,1,0,0,320,319,1,0,0,0,321,322,
|
||||
1,0,0,0,322,320,1,0,0,0,322,323,1,0,0,0,323,330,1,0,0,0,324,326,
|
||||
5,46,0,0,325,327,7,1,0,0,326,325,1,0,0,0,327,328,1,0,0,0,328,326,
|
||||
1,0,0,0,328,329,1,0,0,0,329,331,1,0,0,0,330,324,1,0,0,0,330,331,
|
||||
1,0,0,0,331,102,1,0,0,0,332,336,7,2,0,0,333,335,7,3,0,0,334,333,
|
||||
1,0,0,0,335,338,1,0,0,0,336,334,1,0,0,0,336,337,1,0,0,0,337,104,
|
||||
1,0,0,0,338,336,1,0,0,0,339,341,7,4,0,0,340,339,1,0,0,0,341,342,
|
||||
1,0,0,0,342,340,1,0,0,0,342,343,1,0,0,0,343,344,1,0,0,0,344,345,
|
||||
6,52,0,0,345,106,1,0,0,0,7,0,317,322,328,330,336,342,1,6,0,0
|
||||
]
|
||||
|
||||
class MathExprLexer(Lexer):
|
||||
@@ -172,10 +182,16 @@ class MathExprLexer(Lexer):
|
||||
DIV = 41
|
||||
MOD = 42
|
||||
POW = 43
|
||||
CONSTANT = 44
|
||||
NUMBER = 45
|
||||
VARIABLE = 46
|
||||
WS = 47
|
||||
GE = 44
|
||||
GT = 45
|
||||
LE = 46
|
||||
LT = 47
|
||||
EQ = 48
|
||||
NE = 49
|
||||
CONSTANT = 50
|
||||
NUMBER = 51
|
||||
VARIABLE = 52
|
||||
WS = 53
|
||||
|
||||
channelNames = [ u"DEFAULT_TOKEN_CHANNEL", u"HIDDEN" ]
|
||||
|
||||
@@ -188,7 +204,7 @@ class MathExprLexer(Lexer):
|
||||
"'smin'", "'smax'", "'tmin'", "'tmax'", "'tnorm'", "'snorm'",
|
||||
"'floor'", "'ceil'", "'round'", "'gamma'", "'pow'", "'sigm'",
|
||||
"'clamp'", "'fft'", "'ifft'", "'angle'", "'+'", "'-'", "'*'",
|
||||
"'/'", "'%'", "'^'" ]
|
||||
"'/'", "'%'", "'^'", "'>='", "'>'", "'<='", "'<'", "'=='", "'!='" ]
|
||||
|
||||
symbolicNames = [ "<INVALID>",
|
||||
"SIN", "COS", "TAN", "ASIN", "ACOS", "ATAN", "ATAN2", "SINH",
|
||||
@@ -196,15 +212,17 @@ class MathExprLexer(Lexer):
|
||||
"LOG", "EXP", "SMIN", "SMAX", "TMIN", "TMAX", "TNORM", "SNORM",
|
||||
"FLOOR", "CEIL", "ROUND", "GAMMA", "POWE", "SIGM", "CLAMP",
|
||||
"SFFT", "SIFFT", "ANGL", "PLUS", "MINUS", "MULT", "DIV", "MOD",
|
||||
"POW", "CONSTANT", "NUMBER", "VARIABLE", "WS" ]
|
||||
"POW", "GE", "GT", "LE", "LT", "EQ", "NE", "CONSTANT", "NUMBER",
|
||||
"VARIABLE", "WS" ]
|
||||
|
||||
ruleNames = [ "T__0", "T__1", "T__2", "SIN", "COS", "TAN", "ASIN", "ACOS",
|
||||
"ATAN", "ATAN2", "SINH", "COSH", "TANH", "ASINH", "ACOSH",
|
||||
"ATANH", "ABS", "SQRT", "LN", "LOG", "EXP", "SMIN", "SMAX",
|
||||
"TMIN", "TMAX", "TNORM", "SNORM", "FLOOR", "CEIL", "ROUND",
|
||||
"GAMMA", "POWE", "SIGM", "CLAMP", "SFFT", "SIFFT", "ANGL",
|
||||
"PLUS", "MINUS", "MULT", "DIV", "MOD", "POW", "CONSTANT",
|
||||
"NUMBER", "VARIABLE", "WS" ]
|
||||
"PLUS", "MINUS", "MULT", "DIV", "MOD", "POW", "GE", "GT",
|
||||
"LE", "LT", "EQ", "NE", "CONSTANT", "NUMBER", "VARIABLE",
|
||||
"WS" ]
|
||||
|
||||
grammarFileName = "MathExpr.g4"
|
||||
|
||||
|
||||
@@ -41,10 +41,16 @@ MULT=40
|
||||
DIV=41
|
||||
MOD=42
|
||||
POW=43
|
||||
CONSTANT=44
|
||||
NUMBER=45
|
||||
VARIABLE=46
|
||||
WS=47
|
||||
GE=44
|
||||
GT=45
|
||||
LE=46
|
||||
LT=47
|
||||
EQ=48
|
||||
NE=49
|
||||
CONSTANT=50
|
||||
NUMBER=51
|
||||
VARIABLE=52
|
||||
WS=53
|
||||
'('=1
|
||||
')'=2
|
||||
','=3
|
||||
@@ -88,3 +94,9 @@ WS=47
|
||||
'/'=41
|
||||
'%'=42
|
||||
'^'=43
|
||||
'>='=44
|
||||
'>'=45
|
||||
'<='=46
|
||||
'<'=47
|
||||
'=='=48
|
||||
'!='=49
|
||||
|
||||
@@ -17,6 +17,69 @@ class MathExprListener(ParseTreeListener):
|
||||
pass
|
||||
|
||||
|
||||
# Enter a parse tree produced by MathExprParser#LtExp.
|
||||
def enterLtExp(self, ctx:MathExprParser.LtExpContext):
|
||||
pass
|
||||
|
||||
# Exit a parse tree produced by MathExprParser#LtExp.
|
||||
def exitLtExp(self, ctx:MathExprParser.LtExpContext):
|
||||
pass
|
||||
|
||||
|
||||
# Enter a parse tree produced by MathExprParser#EqExp.
|
||||
def enterEqExp(self, ctx:MathExprParser.EqExpContext):
|
||||
pass
|
||||
|
||||
# Exit a parse tree produced by MathExprParser#EqExp.
|
||||
def exitEqExp(self, ctx:MathExprParser.EqExpContext):
|
||||
pass
|
||||
|
||||
|
||||
# Enter a parse tree produced by MathExprParser#ToAdd.
|
||||
def enterToAdd(self, ctx:MathExprParser.ToAddContext):
|
||||
pass
|
||||
|
||||
# Exit a parse tree produced by MathExprParser#ToAdd.
|
||||
def exitToAdd(self, ctx:MathExprParser.ToAddContext):
|
||||
pass
|
||||
|
||||
|
||||
# Enter a parse tree produced by MathExprParser#GeExp.
|
||||
def enterGeExp(self, ctx:MathExprParser.GeExpContext):
|
||||
pass
|
||||
|
||||
# Exit a parse tree produced by MathExprParser#GeExp.
|
||||
def exitGeExp(self, ctx:MathExprParser.GeExpContext):
|
||||
pass
|
||||
|
||||
|
||||
# Enter a parse tree produced by MathExprParser#LeExp.
|
||||
def enterLeExp(self, ctx:MathExprParser.LeExpContext):
|
||||
pass
|
||||
|
||||
# Exit a parse tree produced by MathExprParser#LeExp.
|
||||
def exitLeExp(self, ctx:MathExprParser.LeExpContext):
|
||||
pass
|
||||
|
||||
|
||||
# Enter a parse tree produced by MathExprParser#NeExp.
|
||||
def enterNeExp(self, ctx:MathExprParser.NeExpContext):
|
||||
pass
|
||||
|
||||
# Exit a parse tree produced by MathExprParser#NeExp.
|
||||
def exitNeExp(self, ctx:MathExprParser.NeExpContext):
|
||||
pass
|
||||
|
||||
|
||||
# Enter a parse tree produced by MathExprParser#GtExp.
|
||||
def enterGtExp(self, ctx:MathExprParser.GtExpContext):
|
||||
pass
|
||||
|
||||
# Exit a parse tree produced by MathExprParser#GtExp.
|
||||
def exitGtExp(self, ctx:MathExprParser.GtExpContext):
|
||||
pass
|
||||
|
||||
|
||||
# Enter a parse tree produced by MathExprParser#AddExp.
|
||||
def enterAddExp(self, ctx:MathExprParser.AddExpContext):
|
||||
pass
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -14,6 +14,41 @@ class MathExprVisitor(ParseTreeVisitor):
|
||||
return self.visitChildren(ctx)
|
||||
|
||||
|
||||
# Visit a parse tree produced by MathExprParser#LtExp.
|
||||
def visitLtExp(self, ctx:MathExprParser.LtExpContext):
|
||||
return self.visitChildren(ctx)
|
||||
|
||||
|
||||
# Visit a parse tree produced by MathExprParser#EqExp.
|
||||
def visitEqExp(self, ctx:MathExprParser.EqExpContext):
|
||||
return self.visitChildren(ctx)
|
||||
|
||||
|
||||
# Visit a parse tree produced by MathExprParser#ToAdd.
|
||||
def visitToAdd(self, ctx:MathExprParser.ToAddContext):
|
||||
return self.visitChildren(ctx)
|
||||
|
||||
|
||||
# Visit a parse tree produced by MathExprParser#GeExp.
|
||||
def visitGeExp(self, ctx:MathExprParser.GeExpContext):
|
||||
return self.visitChildren(ctx)
|
||||
|
||||
|
||||
# Visit a parse tree produced by MathExprParser#LeExp.
|
||||
def visitLeExp(self, ctx:MathExprParser.LeExpContext):
|
||||
return self.visitChildren(ctx)
|
||||
|
||||
|
||||
# Visit a parse tree produced by MathExprParser#NeExp.
|
||||
def visitNeExp(self, ctx:MathExprParser.NeExpContext):
|
||||
return self.visitChildren(ctx)
|
||||
|
||||
|
||||
# Visit a parse tree produced by MathExprParser#GtExp.
|
||||
def visitGtExp(self, ctx:MathExprParser.GtExpContext):
|
||||
return self.visitChildren(ctx)
|
||||
|
||||
|
||||
# Visit a parse tree produced by MathExprParser#AddExp.
|
||||
def visitAddExp(self, ctx:MathExprParser.AddExpContext):
|
||||
return self.visitChildren(ctx)
|
||||
|
||||
@@ -87,6 +87,19 @@ class TensorEvalVisitor(MathExprVisitor):
|
||||
def visitAndExp(self, ctx):
|
||||
return torch.logical_and(self.visit(ctx.andExpr()).bool(), self.visit(ctx.addExpr()).bool())
|
||||
|
||||
def visitNeExp(self, ctx):
|
||||
return torch.ne(self.visit(ctx.neqExpr()), self.visit(ctx.eqExpr())).float()
|
||||
def visitEqExp(self, ctx):
|
||||
return torch.eq(self.visit(ctx.eqExpr()), self.visit(ctx.gtExpr())).float()
|
||||
def visitGtExp(self, ctx):
|
||||
return torch.gt(self.visit(ctx.gtExpr()), self.visit(ctx.ltExpr())).float()
|
||||
def visitLtExp(self, ctx):
|
||||
return torch.lt(self.visit(ctx.ltExpr()), self.visit(ctx.lteExpr())).float()
|
||||
def visitGeExp(self, ctx):
|
||||
return torch.ge(self.visit(ctx.gteExpr()), self.visit(ctx.neqExpr())).float()
|
||||
def visitLeExp(self, ctx):
|
||||
return torch.le(self.visit(ctx.lteExpr()), self.visit(ctx.neqExpr())).float()
|
||||
|
||||
# Single-argument functions
|
||||
def visitSinFunc(self, ctx): return torch.sin(self.visit(ctx.expr()))
|
||||
def visitCosFunc(self, ctx): return torch.cos(self.visit(ctx.expr()))
|
||||
@@ -112,9 +125,8 @@ class TensorEvalVisitor(MathExprVisitor):
|
||||
def visitRoundFunc(self, ctx): return torch.round(self.visit(ctx.expr()))
|
||||
def visitGammaFunc(self, ctx): return torch.special.gamma(self.visit(ctx.expr())).exp()
|
||||
def visitSigmoidFunc(self, ctx): return torch.sigmoid(self.visit(ctx.expr()))
|
||||
def visitClampFunc(self, ctx): return torch.clamp(self.visit(ctx.expr(0)), self.visit(ctx.expr(1)), self.visit(ctx.expr(2)))
|
||||
def visitAnglFunc(self, ctx): return torch.angle(self.visit(ctx.expr()))
|
||||
|
||||
|
||||
def visitSfftFunc(self, ctx):
|
||||
s = self.shape
|
||||
|
||||
@@ -153,6 +165,7 @@ class TensorEvalVisitor(MathExprVisitor):
|
||||
def visitAtan2Func(self, ctx):
|
||||
return torch.atan2(self.visit(ctx.expr(0)), self.visit(ctx.expr(1)))
|
||||
|
||||
def visitClampFunc(self, ctx): return torch.clamp(self.visit(ctx.expr(0)), self.visit(ctx.expr(1)), self.visit(ctx.expr(2)))
|
||||
# N-argument functions
|
||||
def visitSMinFunc(self, ctx):
|
||||
args = [self.visit(e) for e in ctx.expr()]
|
||||
|
||||
Reference in New Issue
Block a user