# Server-Side Rendering Expression Syntax

# Support

Supports the following basic arithmetic operations, functions, and procedures:

  • (00) Types: Scalar, Vector, String

  • (01) Basic operators: +, -, *, /, %, ^

  • (02) Assignment: :=, +=, -=, *=, /=, %=

  • (03) Equality and inequality: =, ==, <>, !=, <, <=, >, >=

  • (04) Logical operators: and, mand, mor, nand, nor, not, or, shl, shr, xnor, xor, true, false

  • (05) Functions: 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) Trigonometric functions: acos, acosh, asin, asinh, atan, atanh, atan2, cos, cosh, cot, csc, sec, sin, sinc, sinh, tan, tanh, hypot, rad2deg, deg2grad, deg2rad, grad2deg

  • (07) Control structures: if-then-else, ternary conditional, switch-case, return-statement

  • (08) Loop statements: while, for, repeat-until, break, continue

  • (09) String handling: in, like, ilike, concatenation

  • (10) Optimization: constant-folding, simple strength reduction and dead code elimination

  • (11) Calculus: numerical integration and differentiation

# Example Expressions

  • (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 }-

# Built-in Operations and Functions

# Arithmetic and Assignment Operators

Operator Description
+ Addition between x and y. (e.g.: x + y)
- Subtraction between x and y. (e.g.: x - y)
* Multiplication between x and y. (e.g.: x * y)
/ Division between x and y. (e.g.: x / y)
% Modulus of x relative to y. (e.g.: x % y)
^ x to the power of y. (e.g.: x ^ y)
:= Assign the value of x to y. Where y is a variable or vector type. (e.g.: y := x)
+= Increment x by the value of the right-hand expression. Where x is a variable or vector type. (e.g.: x += abs(y - z))
-= Decrement x by the value of the right-hand expression. Where x is a variable or vector type. (e.g.: x[i] -= abs(y + z))
*= Assign x multiplied by the right-hand expression to x. Where x is a variable or vector type. (e.g.: x *= abs(y / z))
/= Assign x divided by the right-hand expression to x. Where x is a variable or vector type. (e.g.: x[i + j] /= abs(y * z))
%= Assign the modulus of x by the right-hand expression to x. Where x is a variable or vector type. (e.g.: x[2] %= y ^ 2)

# Equality and Inequality

Operator Description
== or = True only when x is strictly equal to y. (e.g.: x == y)
<> or != True only when x is not equal to y. (e.g.: x <> y or x != y)
< True only when x is less than y. (e.g.: x < y)
<= True only when x is less than or equal to y. (e.g.: x <= y)
> True only when x is greater than y. (e.g.: x > y)
>= True only when x is greater than or equal to y. (e.g.: x >= y)

# Boolean Operations

Operator Description
true True state or any value except zero (typically 1).
false False state, value exactly zero.
and Logical AND, true only when both x and y are true. (e.g.: x and y)
mand Multi-input logical AND, true only when all inputs are true. Expression short-circuits left to right. (e.g.: mand(x > y, z < w, u or v, w and x))
mor Multi-input logical OR, true if at least one input is true. Short-circuits left to right. (e.g.: mor(x > y, z < w, u or v, w and x))
nand Logical NAND, true only when x or y is false. (e.g.: x nand y)
nor Logical NOR, true only when the result of x or y is false. (e.g.: x nor y)
not Logical NOT, negates the logical meaning of input. (e.g.: not(x and y) == x nand y)
or Logical OR, true if x or y is true. (e.g.: x or y)
xor Logical XOR, true only when x and y have different logical states. (e.g.: x xor y)
xnor Logical XNOR, when the biconditional of x and y is satisfied. (e.g.: x xnor y)
Similar to AND (e.g.: (x & y) == (y and x))
| Similar to OR. (e.g.: (x | y) == (y or x))

# General Functions

Function Example
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(xx + yy)
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))

# Trigonometric Functions

Function Description
acos
acosh
asin
asinh
atan
atan2
atanh
cos
cosh
cot
csc
sec
sin
sinc
sinh
tan
tanh
deg2rad
deg2grad
rad2deg
grad2deg

# String Handling Functions

Function Example
= , ==
!=, <>
<=, >=
< , > 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]
<=> Swap the values of x and y. Where x and y are variables. x <=> y
[] String size operator returns the size of the string. 'abc'[] == 3; (('abc' + 'xyz')[1:4])[] == 4

(6) Control Structures

Function Example
if If x is true, return y, otherwise return 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)))
[*] Evaluates any result targeted by its case statements. True return value will be zero or the result
[*]
{
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;
}
[] Vector size operator returns the size of the vector
1. v[]
2. max_size := max(v0[],v1[],v2[],v3[])