PaleyExpressions Samples

CSharp · Console

/Program.cs

using System;
using System.Collections.Generic;
using PaleyExpressions;
using PaleyExpressions.Runners;

var samples = """
              sqr(10*(1+2.9))
              lower(s + " " + "World!")
              iif(x > 10, upper("x is greater than 10"), upper("x is less than or equal to 10"))
              1 > 2 and 3 < 4
              true and !false
              """;

var variables = new Dictionary<string, object?>
{
    {"x", 8.567d},
    {"s", "Hello"}
};

foreach (var expression in samples.Split(Environment.NewLine))
{
    var ast = new AstRunner(expression, typeof(Functions))
        .Interpret(variables);
    var exp = new ExpressionRunner(expression, typeof(Functions))
        .Interpret(variables);

    Console.WriteLine("AST: " + ast);
    Console.WriteLine("EXP: " + exp);
}

public static class Functions
{
    [Function("sqr")]
    public static double Square(double d) => d * d;
}
;