コード例 #1
0
        public void Visit(AdditionExpression ae)
        {
            ae.Left.Accept(this);
            var left = _result;

            ae.Right.Accept(this);
            _result += left;
        }
コード例 #2
0
 public void Visit(AdditionExpression ae)
 {
     _sb.Append("(");
     ae.Left.Accept(this);
     _sb.Append("+");
     ae.Right.Accept(this);
     _sb.Append(")");
 }
コード例 #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(")");
 }
コード例 #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());
        }
コード例 #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()}");
        }
コード例 #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}");
        }
コード例 #7
0
 public static double Calculate(this AdditionExpression ae)
 {
     return(Calculate((dynamic)ae.Left) + Calculate((dynamic)ae.Right));
 }