Пример #1
0
        /// <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
        /// <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
 /// <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
 /// <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;
   }
 }
Пример #5
0
 /// <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);
 }
Пример #6
0
 /// <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;
 }