Exemplo n.º 1
0
        public void Visit(AdditionExpression ae)
        {
            ae.Left.Accept(this);
            var left = _result;

            ae.Right.Accept(this);
            _result += left;
        }
Exemplo n.º 2
0
 public void Visit(AdditionExpression ae)
 {
     _sb.Append("(");
     ae.Left.Accept(this);
     _sb.Append("+");
     ae.Right.Accept(this);
     _sb.Append(")");
 }
Exemplo n.º 3
0
 //  !!! Dangerous approach. Compiler type checking is omitted. !!!
 public static void Print(this AdditionExpression ae, StringBuilder sb)
 {
     sb.Append("(");
     Print((dynamic)ae.Left, sb);
     sb.Append("+");
     Print((dynamic)ae.Right, sb);
     sb.Append(")");
 }
Exemplo n.º 4
0
        static void Main(string[] args)
        {
            var exp = new AdditionExpression(new DoubleExpression(1),
                                             new AdditionExpression(new DoubleExpression(2), new DoubleExpression(3)));
            var sb = new StringBuilder();

            exp.Print(sb);
            WriteLine(sb.ToString());
        }
Exemplo n.º 5
0
        static void Main(string[] args)
        {
            var exp = new AdditionExpression(new DoubleExpression(1),
                                             new AdditionExpression(new DoubleExpression(2), new DoubleExpression(3)));
            var sb = new StringBuilder();

            exp.Print(sb);
            WriteLine($"{sb} = {exp.Calculate()}");
        }
Exemplo n.º 6
0
        static void Main(string[] args)
        {
            var exp = new AdditionExpression(new DoubleExpression(1),
                                             new AdditionExpression(new DoubleExpression(2), new DoubleExpression(3)));
            var ev = new ExpressionPrinter();

            exp.Accept(ev);
            var calc = new ExpressionCalculator();

            exp.Accept(calc);
            WriteLine($"{ev.ToString()} = {calc.Result}");
        }
Exemplo n.º 7
0
 public static double Calculate(this AdditionExpression ae)
 {
     return(Calculate((dynamic)ae.Left) + Calculate((dynamic)ae.Right));
 }