Beispiel #1
0
        static void Main(string[] args)
        {
            var e = new Addition(new Multiplication(
                                     new LiteralExpression(3), new LiteralExpression(4)),
                                 new LiteralExpression(2));

            var sb      = new StringBuilder();
            var printer = new ExpressionVisitor(sb);

            e.Accept(printer);

            Console.WriteLine(sb);
        }
Beispiel #2
0
        private void visitorPatternBtn_Click(object sender, RoutedEventArgs e)
        {
            // emulate 1+2+3
            var expr = new Addition(
                new Addition(
                    new Literal(1),
                    new Literal(2)
                    ),
                new Literal(3)
                );

            var expr1 = new Subtraction(
                new Subtraction(
                    new Literal(1),
                    new Literal(2)
                    ),
                new Literal(3)
                );

            var sb = new StringBuilder();
            var expressionPrinter = new ExpressionPrinter(sb);

            expr.Accept(expressionPrinter);
            expr1.Accept(expressionPrinter);
            Console.WriteLine(sb);

            // dynamic visitior
            //TODO why it breaks on this code ???
            //emulate 1 + 2 + 3
            //var expr2 = new DynamicAddition(
            //  new DynamicAddition(
            //    new DynamicLiteral(1),
            //    new DynamicLiteral(2)
            //  ),
            //  new DynamicLiteral(3)
            //);

            //var sb1 = new StringBuilder();
            //DynamicExpressionPrinter.Print((dynamic)expr2, sb);
            //Console.WriteLine(sb);
        }