示例#1
0
        public static TreeNode Compare(EvaluatorBase evaluator, TreeNode a, TreeNode b)
        {
            TreeNode arg_a = evaluator.Evaluate(a);
            TreeNode arg_b = evaluator.Evaluate(b);

            if (arg_a.GetType() != arg_b.GetType())
            {
                throw new ArgumentException("arguments must be of the same type to compare");
            }

            int result = 0;

            if (arg_a is IntLiteral)
            {
                result = (arg_a as IntLiteral).Value.CompareTo(
                    (arg_b as IntLiteral).Value);
            }
            else if (arg_a is DoubleLiteral)
            {
                result = (arg_a as DoubleLiteral).Value.CompareTo(
                    (arg_b as DoubleLiteral).Value);
            }
            else if (arg_a is StringLiteral)
            {
                result = (arg_a as StringLiteral).Value.CompareTo(
                    (arg_b as StringLiteral).Value);
            }
            else if (arg_a is BooleanLiteral)
            {
                result = (arg_a as BooleanLiteral).Value.CompareTo(
                    (arg_b as BooleanLiteral).Value);
            }
            else
            {
                throw new ArgumentException("invalid type for comparison");
            }

            return(new IntLiteral(result));
        }
示例#2
0
 public EvaluationException(TreeNode node, string token, Exception inner) : base(string.Format(
                                                                                     "Evaluation exception at token `{0} ({1})' [{2},{3}]",
                                                                                     node.GetType(), token, node.Line, node.Column), inner)
 {
 }
示例#3
0
 public EvaluationException(TreeNode node, string token, Exception inner) : base(String.Format(
     "Evaluation exception at token `{0} ({1})' [{2},{3}]",
     node.GetType(), token, node.Line, node.Column), inner)
 {
 }