---
title: 服务端渲染表达式语法
source: https://vjmap.com/guide/expr.html
---

# 服务端渲染表达式语法

## 支持
支持以下基本算术运算、功能和过程：

- (00) 类型：Scalar, Vector, String

- (01) 基本运算符：+、-、*、/、%、^

- (02) 赋值：:=, +=, -=, *=, /=, %=

- (03) 等于与不等于：=、==、<>、!=、<、<=、>、>=

- (04) 逻辑运算符：and, mand, mor, nand, nor, not, or, shl, shr,
  xnor, xor, true, false

- (05) 函数：abs, avg, ceil, clamp, equal, erf, erfc,  exp,  expm1, floor, frac,  log, log10, log1p,  log2,  logn, max,  min, mul,  ncdf,  not_equal, root,  round, roundn, sgn, sqrt, sum, swap, trunc

- (06) 三角函数：acos, acosh, asin, asinh, atan, atanh,  atan2,  cos,  cosh, cot,  csc, sec,  sin, sinc,  sinh,  tan, tanh, hypot, rad2deg, deg2grad,  deg2rad,  grad2deg

- (07) 控制结构：if-then-else, ternary conditional, switch-case,  return-statement

- (08) 循环语句：while、for、repeat-until、break、continue

- (09) 字符串处理：in，like，ilike，concatenation

- (10)优化：constant-folding, simple strength reduction and  dead code elimination

- (11) 微积分：数值积分与微分

## 示例表达式
- (01) sqrt(1 - (3 / x^2))
- (02) clamp(-1, sin(2 * pi * x) + cos(y / 2 * pi), +1)
- (03) sin(2.34e-3 * x)
- (04) if(((x[2] + 2) == 3) and ((y + 5) <= 9),1 + w, 2 / z)
- (05) inrange(-2,m,+2) == if(({-2 <= m} and [m <= +2]),1,0)
- (06) ({1/1}*[1/2]+(1/3))-{1/4}^[1/5]+(1/6)-({1/7}+[1/8]*(1/9))
- (07) a * exp(2.2 / 3.3 * t) + c
- (08) z := x + sin(2.567 * pi / y)
- (09) u := 2.123 * {pi * z} / (w := x + cos(y / pi))
- (10) 2x + 3y + 4z + 5w == 2 * x + 3 * y + 4 * z + 5 * w
- (11) 3(x + y) / 2.9 + 1.234e+12 == 3 * (x + y) / 2.9 + 1.234e+12
- (12) (x + y)3.3 + 1 / 4.5 == [x + y] * 3.3 + 1 / 4.5
- (13) (x + y[i])z + 1.1 / 2.7 == (x + y[i]) * z + 1.1 / 2.7
- (14) (sin(x / pi) cos(2y) + 1) == (sin(x / pi) * cos(2 * y) + 1)
- (15) 75x^17 + 25.1x^5 - 35x^4 - 15.2x^3 + 40x^2 - 15.3x + 1
- (16) (avg(x,y) <= x + y ? x - y : x * y) + 2.345 * pi / x
- (17) while (x <= 100) { x -= 1; }
- (18) x <= 'abc123' and (y in 'AString') or ('1x2y3z' != z)
- (19) ((x + 'abc') like '*123*') or ('a123b' ilike y)
- (20) sgn(+1.2^3.4z / -5.6y) <= {-7.8^9 / -10.11x }- 

## 内置操作和功能

###  算术和赋值运算符

|操作符|说明|
|:---|:---|
| + | x 和 y 之间的加法。（例如：x + y） |
| - | x 和 y 之间的减法。（例如：x - y） |
| * | x 和 y 之间的乘法。（例如：x * y） |
| / | x 和 y 之间的除法。（例如：x / y） |
| % | x 相对于 y 的模量。(例如: x % y) |
| ^ | x 的 y 次方。（例如：x ^ y） |
| := | 将 x 的值分配给 y。其中 y 是一个变量或向量类型。(例如: y := x) |
| += | 将 x 增加右侧表达式的值。其中 x 是变量或向量类型。 (例如: x += abs(y - z)) |
| -= | 将 x 递减右侧表达式的值。其中 x 是变量或向量类型。(例如: x[i] -= abs(y + z)) |
| *= | 将 x 乘以的值赋值x 右侧的表达式。其中 x 是变量或向量类型。(例如: x *= abs(y / z)) |
| /= | 将 x 除以表达式的值赋值 在 x 的右侧。其中 x 是一个 变量或向量类型。(例如: x[i + j] /= abs(y * z)) |
| %= | 将右侧表达式的值赋给 x 模x 的手边。其中 x 是变量或向量类型。(例如: x[2] %= y ^ 2) |

### 等于与不等于

|操作符|说明|
|:---|:---|
| == 或 = | 仅当 x 严格等于 y 时才为真。（例如：x == y）|
| <> 或 != | 仅当 x 不等于 y 时才为真。（例如：x <> y 或 x != y）|
| < | 仅当 x 小于 y 时才为真。(例如: x < y) |
| <= | 仅当 x 小于或等于 y 时才为真。（例如：x <= y）|
| &#62; | 仅当 x 大于 y 时才为真。（例如：x > y） |
| >= | 仅当 x 大于或等于 y 时才为真。（例如：x >= y）|

### 布尔运算

|操作符|说明|
|:---|:---|
| true | 真实状态或除零以外的任何值（通常为 1）。|
| false | 错误状态，值恰好为零。|
| and| 逻辑与，仅当 x 和 y 都为真时才为真。（例如：x and| y） |
| mand | 多输入逻辑与，仅当所有输入都为 | 时为真的。表达式从左到右短路。 (例如: mand(x > y, z < w, u or v, w and x)) |
| mor | 多输入逻辑或，如果至少是 | 之一，则为真,输入是真的。从左到右短路 ;表达式。(例如: mor(x > y, z < w, u or v, w and x)) |
| nand | 逻辑 NAND，仅当 x 或 y 为假时才为真。（例如：x nand y） |
| nor| 逻辑 NOR，仅当 x 或 y 的结果为假时才为真（例如：x nor y） |
| not| 逻辑非，否定输入的逻辑意义。(例如: not(x and y) == x nand y) |
| or | 逻辑或，如果 x 或  or 为真，则为真。（例如：x or y） |
| xor| 逻辑异或，仅当 x 和 y 的逻辑状态为 True （例如：x xor y） |
| xnor | 逻辑 XNOR，当 x 和 y 的双条件满足。(例如: x xnor y) |
| ＆| 类似于 AND 但从左到右的表达式(例如: (x & y) == (y and x)) |
| &#124; | 与 OR 类似，(例如: (x &#124; y) == (y or x)) |

### 通用函数
|函数|示例|
|:---|:---|
| abs      |  abs(x)                 |
| avg      | avg(x,y,z,w,u,v) == (x + y + z + w + u + v) / 6)   |
| ceil     | ceil(x)   |
| clamp    |  clamp(r0,x,r1)     |
| equal    |  |
| erf      | erf(x)                     |
| erfc     |erfc(x)     |
| exp      | exp(x)   |
| expm1    | expm1(x)   |
| floor    | floor(x)                                         |
| frac     |frac(x)            |
| hypot    | hypot(x,y) = sqrt(x*x + y*y)|
| iclamp   | iclamp(r0,x,r1)                     |
| inrange  | inrange(r0,x,r1)           |
| log      | log(x)                 |
| log10    | log10(x)               |
| log1p    |  log1p(x)                                         |
| log2     | log2(x)                  |
| logn     | logn(x,8)                                        |
| max      | max(x,y,z,w,u,v) |
| min      |  min(x,y,z,w,u)  |
| mul      | mul(x,y,z,w,u,v,t) == (x * y * z * w * u * v * t) |
| ncdf     | ncdf(x) |
| not_equal| |
| pow      | pow(x,y) == x ^ y           |
| root     | root(x,3) == x^(1/3)                             |
| round    | round(x)         |
| roundn   | roundn(1.2345678,4) == 1.2346                   |
| sgn      | sgn(x)                                         |
| sqrt     |  sqrt(x)         |
| sum      | sum(x,y,z,w,u,v,t) == (x + y + z + w + u + v + t) |
| swap     | swap(x,y) or x <=> y)         |
| trunc   | trunc(x))                   |

### 三角函数
|函数|说明|
|:---|:---|
| acos     |                                      |
| acosh    |                                         |
| asin     |                                          |
| asinh    |                                      |
| atan     |                                          |
| atan2    |                                         |
| atanh    |                                          |
| cos      |                              |
| cosh     |   |
| cot      |   |
| csc      |   |
| sec      |   |
| sin      |   |
| sinc     |   |
| sinh     |   |
| tan      |   |
| tanh     |   |
| deg2rad  |   |
| deg2grad |   |
| rad2deg  |   |
| grad2deg |   |

### 字符处理函数
|函数|示例|
|:---|:---|
|  = , ==  ||
|  !=, <>  |   |
|  <=, >=  | |
|  < , >   |  not((x <= 'AbC') and ('1x2y3z' <> y)) or (z == x)  |
| in       |  x in y or 'abc' in 'abcdefgh'                    |
| like     | T x like y or 'abcdefgh' like 'a?d*h'               |
| ilike    | x ilike y or 'a1B2c3D4e5F6g7H' ilike 'a?d*h'     |
| [r0:r1]  |  x[1:4] == 'bcde' ;  x[ :5] == x[:10 / 2] == 'abcdef' ; x[2 + 1: ] == x[3:] =='defgh'  ;        x[ : ] == x[:] == 'abcdefgh' ;       5. x[4/2:3+2] == x[2:5] == 'cdef'    
|  :=      |   y := x ; y := 'abc' ;y := x[:i + j] ; y := '0123456789'[2:7] ;y := '0123456789'[2i + 1:7]  ;y := (x := '0123456789'[2:7]);y[i:j] := x ; y[i:j] := (x + 'abcdefg'[8 / 4:5])[m:n]  
|  +       | x + y;   (x + 'a1B2c3D4' + y)[i:2j]    
| <=>      | 交换 x 和 y 的值。其中 x 和 y 是可变的 x <=> y |
| []       |  字符串大小运算符返回字符串的大小 'abc'[] == 3; (('abc' + 'xyz')[1:4])[] == 4                        |

(6) 控制结构

|函数|示例|
|:---|:---|
| if       | 如果 x 为真，则返回 y，否则返回 z。 if (x, y, z) ; if ((x + 1) > 2y, z + 1, w / v); if (x > y) z; if (x <= 2*y) { z + w }; |
| if-else  | 1. if (x > y) z; else w;                                |
|          | 2. if (x > y) z; else if (w != u) v;                    |
|          | 3. if (x < y) { z; w + 1; } else u;                     |
|          | 4. if ((x != y) and (z > w))                            |
|          |    {                                                    |
|          |      y := sin(x) / u;                                   |
|          |      z := w + 1;                                        |
|          |    }                                                    |
|          |    else if (x > (z + 1))                                |
|          |    {                                                    |
|          |      w := abs (x - y) + z;                              |
|          |      u := (x + 1) > 2y ? 2u : 3u;                       |
|          |    }                                                    |
| switch   | switch                                                  |
|          | {                                                       |
|          |   case x > (y + z) : 2 * x / abs(y - z);                |
|          |   case x < 3       : sin(x + y);                        |
|          |   default          : 1 + x;                             |
|          | }                                                       |
| while    | while ((x -= 1) > 0)                                    |
|          | {                                                       |
|          |   y := x + z;                                           |
|          |   w := u + y;                                           |
|          | }                                                       |
| repeat  | repeat                                                  |
|          |   y := x + z;                                           |
|          |   w := u + y;                                           |
|          | until ((x += 1) > 100)                                  |
| for      | for (var x := 0; (x < n) and (x != y); x += 1)          |
|          | {                                                       |
|          |   y := y + x / 2 - z;                                   |
|          |   w := u + y;                                           |
|          | }                                                       |
| break    | while ((i += 1) < 10)                                   |
|          | {                                                       |
|          |   if (i < 5)                                            |
|          |     j -= i + 2;                                         |
|          |   else if (i % 2 == 0)                                  |
|          |     break;                                              |
|          |   else                                                  |
|          |     break[2i + 3];                                      |
|          | }                                                       |
| continue | for (var i := 0; i < 10; i += 1)                        |
|          | {                                                       |
|          |   if (i < 5)                                            |
|          |     continue;                                           |
|          |   j -= i + 2;                                           |
|          | }                                                       |
| return   |  1. return [1];                                          |
|          | 2. return [x, 'abx'];                                   |
|          | 3. return [x, x + y,'abx'];                             |
|          | 4. return [];                                           |
|          | 5. if (x < y)                                           |
|          |     return [x, x - y, 'result-set1', 123.456];          |
|          |    else                                                 |
|          |     return [y, x + y, 'result-set2'];                   |
| ?:       | 1. x ? y : z                                            |
|          | 2. x + 1 > 2y ? z + 1 : (w / v)                         |
|          | 3. min(x,y) > z ? (x < y + 1) ? x : y : (w * v)         |
| ~        |  eg:                                                     |
|          | ~(i := x + 1, j := y / z, k := sin(w/u)) == (sin(w/u))) |
|          | ~{i := x + 1; j := y / z; k := sin(w/u)} == (sin(w/u))) |
| [*]      | 评估其 case 语句所针对的任何结果. 真的返回值将为零或结果                                            |
|          | [*]                                                     |
|          | {                                                       |
|          |   case (x + 1) > (y - 2)    : x := z / 2 + sin(y / pi); |
|          |   case (x + 2) < abs(y + 3) : w / 4 + min(5y,9);        |
|          |   case (x + 3) == (y * 4)   : y := abs(z / 6) + 7y;     |
|          | }                                                       |
| []       | 向量大小运算符返回向量的大小                                                    |
|          | 1. v[]                                                  |
|          | 2. max_size := max(v0[],v1[],v2[],v3[])                 |
