/// <summary>
 /// 若出错则返回null,否则返回result
 /// </summary>
 /// <param name="exprType"></param>
 /// <param name="left"></param>
 /// <param name="right"></param>
 /// <param name="loc"></param>
 /// <returns></returns>
 private BinaryLogicExpr processBinaryLogicExpr(BinaryLogicExpr result, Expression left, Expression right, Location loc)
 {
     result.DataType = DataType.Bool;
     if (result.DataType == DataType.Error)
         return null;
     result.FirstOp = left;
     result.SecondOp = right;
     result.Location = loc;
     return result;
 }
        private BinaryCmpExpr processBinaryCmpExpr(BinaryCmpExpr result, Expression left, Expression right, Location loc)
        {
            if (left.DataType == DataType.Bool || left.DataType == DataType.String
                || right.DataType == DataType.Bool || right.DataType == DataType.String)
            {
                kernel.IssueError(ErrorType.OprandTypeError, loc);
                return null;
            }
            else
            {
                result.DataType = DataType.Bool;
            }

            result.FirstOp = left;
            result.SecondOp = right;
            result.Location = loc;
            return result;
        }
        private BinaryAlgoExpr processBinaryAlgoExpr(BinaryAlgoExpr result, Expression left, Expression right, Location loc)
        {
            if ((left.DataType == DataType.String || right.DataType == DataType.String) && result is AddExpr)
            {
                result.DataType = DataType.String;
            }
            else if (left.DataType == DataType.Bool || left.DataType == DataType.String
                || right.DataType == DataType.Bool || right.DataType == DataType.String)
            {
                kernel.IssueError(ErrorType.OprandTypeError, loc);
                return null;
            }
            else if (left.DataType == DataType.Float || right.DataType == DataType.Float)
            {
                result.DataType = DataType.Float;
            }
            else if (left.DataType == DataType.Int && right.DataType == DataType.Int)
            {
                result.DataType = DataType.Int;
            }
            else
            {
                result.DataType = DataType.Unknown;
            }

            result.FirstOp = left;
            result.SecondOp = right;
            result.Location = loc;
            return result;
        }
        private RightValue readRightValue(Expression expression)
        {
            if (expression is LeftValueExpr)
            {
                return readRightValue((expression as LeftValueExpr).LeftValue, expression.Location);
            }
            else if (expression is RightValueExpr)
            {
                return (expression as RightValueExpr).RightValue;
            }

            //只有上面两种情况
            throw new Exception();
        }
 public string EvalStr(Expression expr)
 {
     return Eval(expr).ToString();
 }
 public RightValue Eval(Expression expr)
 {
     expr.Accept(this);
     RightValue result = readRightValue(expr);
     return result;
 }