public void Conditiona_test_op_ordering_2() { var compiler = new DotNetXzaarScriptCompiler(); compiler.RegisterVariable <bool>("a"); compiler.RegisterVariable <bool>("b"); compiler.RegisterVariable <bool>("c"); compiler.RegisterVariable <bool>("e"); var expression = compiler.Compile( new XzaarScriptTransformer().Transform( new XzaarScriptParser().Parse( new XzaarScriptLexer().Tokenize("a && b || c && e")))) as LambdaXzaarCompiledScript; Assert.AreEqual("(a, b, c, e) => ((a And b) Or (c And e))", expression.GetLambdaExpression().ToString()); }
public void Conditiona_test_op_ordering_1() { var lexer = new XzaarScriptLexer(); var parser = new XzaarScriptParser(); var transformer = new XzaarScriptTransformer(); var compiler = new DotNetXzaarScriptCompiler(); var tokens = lexer.Tokenize("a && b || c"); var ast0 = parser.Parse(tokens); var ast1 = transformer.Transform(ast0); compiler.RegisterVariable <bool>("a"); compiler.RegisterVariable <bool>("b"); compiler.RegisterVariable <bool>("c"); var expression = compiler.Compile(ast1) as LambdaXzaarCompiledScript; Assert.AreEqual("(a, b, c) => ((a And b) Or c)", expression.GetLambdaExpression().ToString()); }
public void TransformTest_if_else_then_with_bodies_semicolon_separated_2() { var lexer = new XzaarScriptLexer(); var parser = new XzaarScriptParser(); var transformer = new XzaarScriptTransformer(); var compiler = new DotNetXzaarScriptCompiler(); var tokens = lexer.Tokenize("if (a == 0) { a = 3; b = 8; } else { a = 4; }"); var ast = parser.Parse(tokens); ast = transformer.Transform(ast); compiler.RegisterVariable <int>("a"); compiler.RegisterVariable <int>("b"); var expression = compiler.Compile(ast) as LambdaXzaarCompiledScript; var expr = expression.GetLambdaExpression(); var str = expr.ToString(); Assert.AreEqual("(a, b) => IIF((a == 0), { ... }, (a = 4))", str); }
public void Interpreter_full_chain_complex_3() { var lexer = new XzaarScriptLexer(); var parser = new XzaarScriptParser(); var transformer = new XzaarScriptTransformer(); var compiler = new DotNetXzaarScriptCompiler(); var tokens = lexer.Tokenize("apa == 8 && over == 9000 || apa == 24"); var ast0 = parser.Parse(tokens); var ast1 = transformer.Transform(ast0); compiler.RegisterVariable <int>("apa"); compiler.RegisterVariable <int>("over"); var expression = compiler.Compile(ast1) as LambdaXzaarCompiledScript; Assert.AreEqual("(apa, over) => (((apa == 8) And (over == 9000)) Or (apa == 24))", expression.GetLambdaExpression().ToString()); Assert.IsTrue(expression.Invoke <bool>(8, 9000)); Assert.IsFalse(expression.Invoke <bool>(8, 0)); Assert.IsTrue(expression.Invoke <bool>(24, 0)); Assert.IsFalse(expression.Invoke <bool>(0, 0)); }
public void Compile_value_mul_10() { var lexer = new XzaarScriptLexer(); var parser = new XzaarScriptParser(); var transformer = new XzaarScriptTransformer(); var compiler = new DotNetXzaarScriptCompiler(); var tokens = lexer.Tokenize("apa * 10"); var ast0 = parser.Parse(tokens); var ast1 = transformer.Transform(ast0); compiler.RegisterVariable <int>("apa"); var expression = compiler.Compile(ast1) as LambdaXzaarCompiledScript; var result = expression.Invoke <int>(10); Assert.AreEqual(10 * 10, result); }
public void Compile_value_lt_1_mul_2() { var lexer = new XzaarScriptLexer(); var parser = new XzaarScriptParser(); var transformer = new XzaarScriptTransformer(); var compiler = new DotNetXzaarScriptCompiler(); var tokens = lexer.Tokenize("(apa == 8) || (apa < (1 * 2))"); var ast0 = parser.Parse(tokens); var ast1 = transformer.Transform(ast0); compiler.RegisterVariable <int>("apa"); var expression = compiler.Compile(ast1) as LambdaXzaarCompiledScript; Assert.IsTrue(expression.Invoke <bool>(0)); Assert.IsTrue(expression.Invoke <bool>(8)); Assert.IsFalse(expression.Invoke <bool>(10)); }
public void TransformTest_if_else_then_without_bodies() { var lexer = new XzaarScriptLexer(); var parser = new XzaarScriptParser(); var transformer = new XzaarScriptTransformer(); var compiler = new DotNetXzaarScriptCompiler(); var tokens = lexer.Tokenize("if (a == 0) a = 3 else a = 4"); var ast = parser.Parse(tokens); ast = transformer.Transform(ast); compiler.RegisterVariable <int>("a"); var expression = compiler.Compile(ast) as LambdaXzaarCompiledScript; var str = expression.GetLambdaExpression().ToString(); Assert.AreEqual("a => IIF((a == 0), (a = 3), (a = 4))", str); }