Code Separators and Code Blocks

  • If the value of property char ExpressionSeparatorCharacter { get; } in UniversalExpressionParser.IExpressionLanguageProvider is not equal to character ‘0’, multiple expressions can be used in a single expression.

For example if the value of property ExpressionSeparatorCharacter is ‘;’ the expression “var x=f1(y);println(x)” will be parsed to a list of two expression items for “x=f1(y)” and “println(x)”. Otherwise, the parser will report an error for this expression (see section on Error Reporting for more details on errors).

  • If both values of properties char CodeBlockStartMarker { get; } and string CodeBlockEndMarker { get; } in UniversalExpressionParser.IExpressionLanguageProvider are not equal to character ‘0’, code block expressions can be used to combine multiple expressions into code block expression items of type UniversalExpressionParser.ExpressionItems.ICodeBlockExpressionItem.

  • For example if the values of properties CodeBlockStartMarker and CodeBlockEndMarker are ‘{’ and ‘}’, the expression below will be parsed to two code block expressions of type UniversalExpressionParser.ExpressionItems.ICodeBlockExpressionItem. Otherwise, the parser will report errors.

1{
2    var x = y^2;
3    println(x);
4}
5
6{
7    fl(x1, x2);
8    println(x) // No need for ';' after the last expression
9}

Click here to see the visualized instance of UniversalExpressionParser.IParseExpressionResult

More complex examples of code blocks and code separators

 1var y = x1 + 2.5 * x2;
 2
 3f1()
 4{
 5    // Code block used as function body (see examples in Postfixes folder)
 6}
 7
 8var z = e ^ 2.3;
 9{
10    var x = 5 * y;
11    println("x=" + x);
12
13    {
14        var y1 = 10 * x;
15        println(getExp(y1));
16    }
17
18    {
19        var y2 = 20 * x;
20        println(getExp(y2));
21    }
22
23    getExp(x) : double
24    {
25        // another code block used as function body (see examples in Postfixes folder)
26        return e^x;
27    }
28}
29
30f2()
31{
32    // Another code block used as function body (see examples in Postfixes folder)
33}
34
35{
36    // Another code block
37}
38
39public class Dog
40{
41    public Bark()
42    {
43        // Note, code separator ';' is not necessary, if the expression is followed by code block end marker '}'.
44        println("bark")
45    }
46}

Click here to see the visualized instance of UniversalExpressionParser.IParseExpressionResult