Exemplo n.º 1
0
        public void SelfReferenceSubstituteTest()
        {
            var ast1 = new ArithmExprNode(1,
                                          new IdNode(1, "x"),
                                          ArithmOpNode.FromSymbol(1, "+"),
                                          new ArithmExprNode(1,
                                                             new IdNode(1, "y"),
                                                             ArithmOpNode.FromSymbol(1, "+"),
                                                             new IdNode(1, "x")
                                                             )
                                          );

            var repl = new ArithmExprNode(1,
                                          new IdNode(1, "y"),
                                          new ArithmOpNode(1, "-", BinaryOperations.ArithmeticFromSymbol("-")),
                                          new IdNode(1, "x")
                                          );
            var ast2 = new ArithmExprNode(1,
                                          new IdNode(1, "x"),
                                          ArithmOpNode.FromSymbol(1, "+"),
                                          new ArithmExprNode(1,
                                                             repl,
                                                             ArithmOpNode.FromSymbol(1, "+"),
                                                             new IdNode(1, "x")
                                                             )
                                          );

            Assert.That(ast1.Substitute(new IdNode(2, "y"), repl), Is.EqualTo(ast2));
        }
Exemplo n.º 2
0
 public static ArithmOpNode FromSymbol(int line, string symbol)
 => new ArithmOpNode(line, symbol, BinaryOperations.ArithmeticFromSymbol(symbol));