示例#1
0
        internal static ParseErrorExpression ParseError(PositionalTokenizer tokenizer, string message, ExpressionBase expression)
        {
            var error = ParseError(tokenizer, message);

            error.InnerError = expression as ParseErrorExpression;
            expression.CopyLocation(error);
            return(error);
        }
        /// <summary>
        /// Attempts to convert an expression to a <see cref="FloatConstantExpression"/>.
        /// </summary>
        /// <param name="expression">The expression to convert.</param>
        /// <returns>The converted expression, or a <see cref="ParseErrorExpression"/> if the expression could not be converted.</returns>
        public static ExpressionBase ConvertFrom(ExpressionBase expression)
        {
            FloatConstantExpression floatExpression;

            switch (expression.Type)
            {
            case ExpressionType.FloatConstant:
                return(expression);

            case ExpressionType.IntegerConstant:
                floatExpression = new FloatConstantExpression((float)((IntegerConstantExpression)expression).Value);
                break;

            default:
                return(new ParseErrorExpression("Cannot convert to float", expression));
            }

            expression.CopyLocation(floatExpression);
            return(floatExpression);
        }