コード例 #1
0
ファイル: Eval.cs プロジェクト: vstrien/KOCus
        /// <summary>
        /// Parses and extracts a numeric value at the current position
        /// </summary>
        /// <param name="parser">TextParser object</param>
        /// <returns></returns>
        protected string ParseNumberToken(TextParser parser)
        {
            bool hasDecimal = false;
            int  start      = parser.Position;

            while (Char.IsDigit(parser.Peek()) || parser.Peek() == '.')
            {
                if (parser.Peek() == '.')
                {
                    if (hasDecimal)
                    {
                        throw new EvalException(ErrMultipleDecimalPoints, parser.Position);
                    }
                    hasDecimal = true;
                }
                parser.MoveAhead();
            }
            // Extract token
            string token = parser.Extract(start, parser.Position);

            if (token == ".")
            {
                throw new EvalException(ErrInvalidOperand, parser.Position - 1);
            }
            return(token);
        }
コード例 #2
0
ファイル: Eval.cs プロジェクト: vstrien/KOCus
        /// <summary>
        /// Parses and extracts a symbol at the current position
        /// </summary>
        /// <param name="parser">TextParser object</param>
        /// <returns></returns>
        protected string ParseSymbolToken(TextParser parser)
        {
            int start = parser.Position;

            while (Char.IsLetterOrDigit(parser.Peek()) || parser.Peek() == '_')
            {
                parser.MoveAhead();
            }
            return(parser.Extract(start, parser.Position));
        }
コード例 #3
0
ファイル: Eval.cs プロジェクト: vstrien/KOCus
 /// <summary>
 /// Extracts and evaluates a function parameter and returns its value. If an
 /// exception occurs, it is caught and the column is adjusted to reflect the
 /// position in original string, and the exception is rethrown.
 /// </summary>
 /// <param name="parser">TextParser object</param>
 /// <param name="paramStart">Column where this parameter started</param>
 /// <returns></returns>
 protected double EvaluateParameter(TextParser parser, int paramStart)
 {
     try
     {
         // Extract expression and evaluate it
         string expression = parser.Extract(paramStart, parser.Position);
         return(Execute(expression));
     }
     catch (EvalException ex)
     {
         // Adjust column and rethrow exception
         ex.Column += paramStart;
         throw ex;
     }
 }
コード例 #4
0
ファイル: Eval.cs プロジェクト: vstrien/KOCus
 /// <summary>
 /// Parses and extracts a symbol at the current position
 /// </summary>
 /// <param name="parser">TextParser object</param>
 /// <returns></returns>
 protected string ParseSymbolToken(TextParser parser)
 {
     int start = parser.Position;
     while (Char.IsLetterOrDigit(parser.Peek()) || parser.Peek() == '_')
         parser.MoveAhead();
     return parser.Extract(start, parser.Position);
 }
コード例 #5
0
ファイル: Eval.cs プロジェクト: vstrien/KOCus
 /// <summary>
 /// Parses and extracts a numeric value at the current position
 /// </summary>
 /// <param name="parser">TextParser object</param>
 /// <returns></returns>
 protected string ParseNumberToken(TextParser parser)
 {
     bool hasDecimal = false;
     int start = parser.Position;
     while (Char.IsDigit(parser.Peek()) || parser.Peek() == '.')
     {
         if (parser.Peek() == '.')
         {
             if (hasDecimal)
                 throw new EvalException(ErrMultipleDecimalPoints, parser.Position);
             hasDecimal = true;
         }
         parser.MoveAhead();
     }
     // Extract token
     string token = parser.Extract(start, parser.Position);
     if (token == ".")
         throw new EvalException(ErrInvalidOperand, parser.Position - 1);
     return token;
 }
コード例 #6
0
ファイル: Eval.cs プロジェクト: vstrien/KOCus
 /// <summary>
 /// Extracts and evaluates a function parameter and returns its value. If an
 /// exception occurs, it is caught and the column is adjusted to reflect the
 /// position in original string, and the exception is rethrown.
 /// </summary>
 /// <param name="parser">TextParser object</param>
 /// <param name="paramStart">Column where this parameter started</param>
 /// <returns></returns>
 protected double EvaluateParameter(TextParser parser, int paramStart)
 {
     try
     {
         // Extract expression and evaluate it
         string expression = parser.Extract(paramStart, parser.Position);
         return Execute(expression);
     }
     catch (EvalException ex)
     {
         // Adjust column and rethrow exception
         ex.Column += paramStart;
         throw ex;
     }
 }