Expressions - Amazon Lex

Expressions

You can add expressions strings to perform functions in Amazon Lex V2. This table shows the syntax and examples that can be used in SRGS expressions.

Expression type Syntax Example Supported?
Regular expression literal String literal containing valid regex special characters
"^\d\.$"
No
Function function functionName(parameters) { functionBody}
var x = function calc() { return 10; }
No
Delete delete expression
delete obj.property;
No
Void void expression
void (2 == '2');
No
Typeof typeof expression
typeof 42;
No
Member index expression [ expressions ]
var fruits = ["apple"]; fruits[0];
Yes
Member dot expression . identifier
out.value
yes
Arguments expression (arguments)
new Date('1994-10-11')
Yes
Post increment expression++
var x=10; x++;
Yes
Post decrement expression--
var x=10; x--;
Yes
Pre increment ++expression
var x=10; ++x;
Yes
Pre decrement --expression
var x=10; --x;
Yes
Unary plusĀ / Unary minus +expression / -expression
+x / -x;
Yes
Bit not ~ expression
const a = 5; console.log( ~a );
Yes
Logical not ! expression
!(a > 0 || b > 0)
Yes
Multiplicative expression ('*' | '/' | '%') expression
(x + y) * (a / b)
Yes
Additive expression ('+' | '-') expression
(a + b) - (a - (a + b))
Yes
Bit shift expression ('<<' | '>>' | '>>>') expression
(a >> b) >>> c
Yes
Relative expression ('<' | '>' | '<=' | '>=') expression
if (a > b) { ... }
Yes
In expression in expression
fruits[0] in otherFruits;
Yes
Equality expression ('==' | '!=' | '===' | '!===') expression
if (a == b) { ... }
Yes
Bit and / xor / or expression ('&' | '^' | '|') expression
a & b / a ^ b / a | b
Yes
Logical and / or expression ('&&' | '||') expression
if (a && (b ||c)) { ...}
Yes
Ternary expression ? expression : expression
a > b ? obj.prop : 0
Yes
Assignment expression = expression
out.value = "string";
Yes
Assignment operator expression ('*=' | '/=' | '+=' | '-=' | '%=') expression
a *= 10;
Yes
Assignment bitwise operator expression ('<<=' | '>>=' | '>>>=' | '&=' | '^=' | '|=') expression
a <<= 10;
Yes
Identifier identifierSequence where identifierSequence is a sequence of valid characters
fruits=[10, 20, 30];
Yes
Null literal null
x = null;
Yes
Boolean literal true | false
x = true;
Yes
String literal 'string' / "string"
a = 'hello', b = "world";
Yes
Decimal literal integer [.] digits [exponent]
111.11 e+12
Yes
Hex literal 0 (x | X)[0-9a-fA-F]
0x123ABC
Yes
Octal literal O [0-7]
"O51"
Yes
Array literal [ expression, ... ]
v = [a, b, c];
Yes
Object literal {property: value, ...}
out = {value: 1, flag: false};
Yes
Parenthesized ( expressions )
x + (x + y)
Yes