示例#1
0
        public string Visit(MultiplyOpNode visited)
        {
            var sb = new StringBuilder();

            // parentheses might be needed around children with lower priorities
            int thisPriority = visited.Accept(priorityGetter);
            int sonPriority  = visited.LeftSon.Accept(priorityGetter);

            if (sonPriority < thisPriority)
            {
                sb.Append("(");
            }
            sb.Append(visited.LeftSon.Accept(this));
            if (sonPriority < thisPriority)
            {
                sb.Append(")");
            }

            sb.Append("*");
            sonPriority = visited.RightSon.Accept(priorityGetter);

            // * is associative - no need for parentheses when RightSon has same priority
            if (sonPriority < thisPriority)
            {
                sb.Append("(");
            }
            sb.Append(visited.RightSon.Accept(this));
            if (sonPriority < thisPriority)
            {
                sb.Append(")");
            }

            return(sb.ToString());
        }
示例#2
0
        public double Visit(MultiplyOpNode caller)
        {
            double left  = caller.LeftSon.Accept(this);
            double right = caller.RightSon.Accept(this);

            return(left * right);
        }
示例#3
0
        public int Visit(MultiplyOpNode caller)
        {
            int left  = caller.LeftSon.Accept(this);
            int right = caller.RightSon.Accept(this);

            return(checked (left * right));
        }
示例#4
0
        public string Visit(MultiplyOpNode visited)
        {
            var sb = new StringBuilder();

            sb.Append("(");
            sb.Append(visited.LeftSon.Accept(this));
            sb.Append("*");
            sb.Append(visited.RightSon.Accept(this));
            sb.Append(")");
            return(sb.ToString());
        }
示例#5
0
 public int Visit(MultiplyOpNode visited)
 {
     return(5);
 }