Skip to content

Operators and Keywords

Coding Seb edited this page Jan 19, 2019 · 15 revisions

Standard Operators

ExpressionEvaluator manage a large set of C# operators (See C# Operators)

ExpressionEvaluator respect the C# precedence rules of operators

Here is a list of which operators are supported in ExpressionEvaluator or not

Type Operator Support
Primary x.y Supported
Primary x?.y Supported
Primary x?[y] Supported
Primary f(x) Supported
Primary a[x] Supported
Primary x++ Supported Warning change the state of the postfixed element
Primary x-- Supported Warning change the state of the postfixed element
Primary new Supported you can also use new() function
Primary typeof Supported
Primary checked Not Supported
Primary unchecked Not Supported
Primary default(T) Supported
Primary delegate Not Supported
Primary sizeof Not Supported
Primary -> Not Supported
Unary +x Supported
Unary -x Supported
Unary !x Supported
Unary ~x Not Supported
Unary ++x Not Supported
Unary --x Not Supported
Unary (T)x Supported
Unary await Not Supported
Unary &x Not Supported
Unary *x Not Supported
Multiplicative x * y Supported
Multiplicative x / y Supported
Multiplicative x % y Supported
Additive x + y Supported
Additive x - y Supported
Shift x << y Supported
Shift x >> y Supported
Relational x < y Supported
Relational x > y Supported
Relational x <= y Supported
Relational x >= y Supported
Type-testing is Supported
Type-testing as Not Supported
Equality x == y Supported
Equality x != y Supported
Logical AND x & y Supported
Logical XOR x ^ y Supported
Logical OR x | y Supported
Conditional AND x && y Supported
Conditional OR x || y Supported
Null-coalescing x ?? y Supported
Conditional t ? x : y Supported
Lambda => Supported

Assignation operators

Warning all of the following operators change the value of their left element.

Assignation operators (and also postfix operators (++ and --)) are usable on :

Elements What is changing Options
Custom variables The variable in the Variables dictionary is changed and if the variable doesn't exists, it automatically created with the = operator Can be disabled with evaluator.OptionVariableAssignationActive = false;
Properties or fields on objects If the property/field is not readonly it is changed Can be disabled with evaluator.OptionPropertyOrFieldSetActive = false;
Indexed object like arrays, list or dictionaries The value at the specified index is changed Can be disabled with evaluator.OptionIndexingAssignationActive = false;

Here is the list of available assignation operator

Operator Support
= Supported (Can be use to declare a new variable that will be injected in the Variables dictionary)
+= Supported
-= Supported
*= Supported
/= Supported
%= Supported
&= Supported
|= Supported
^= Supported
<<= Supported
>>= Supported

To declare a variable, types are not yet supported and are for now dynamically deduced.

// Not supported
int x = 2;
string text = "hello";

for(int i = 0; i < 10; i++)
...

// Write this instead :
x = 2;
text = "hello";

for(i = 0; i < 10; i++)
...

Scripts

Scripts keywords

In addition to simple expression evaluation you can also evaluate small scripts with the method :

//object ScriptEvaluate(string script)
evaluator.ScriptEvaluate(script);

Scripts are just a serie of expressions to evaluate separated with a ; character and leaded by severals additionals keywords.

Currently the following scripts keywords are supported

Type Operator Support
Selection if Supported
Selection else if Supported
Selection else Supported
Selection switch case Not yet supported
Iteration do ... while Supported
Iteration for Supported
Iteration foreach, in Supported
Iteration while Supported
Jump break Supported in do, for and while blocks
Jump continue Supported in do, for and while blocks
Jump goto Not supported (But if you looked after it -> Booo !!! Bad code)
Jump return Supported
Jump/Exception throw Supported
Exception Handling try-catch Supported
Exception Handling try-finally Supported
Exception Handling try-catch-finally Supported

Remark : The way ScriptEvaluate works is to evaluate expressions one by one. There is no syntax check before the evaluation. So be aware that syntax or naming bugs only appears in execution and some code can already be evaluated at this time. Futhermore a syntaxic/naming bug in an if-else block for example can simply be ignored until the corresponding condition is met to evaluate the specific line of code.

Table Of Content

Clone this wiki locally