private bool TryString(char c)
        {
            if (!char.IsLetter(c))
            {
                return(false);
            }

            _buffer.Length = 0;
            _buffer.Append(c);

            char p = (char)_expressionReader.Peek();

            while (char.IsLetter(p))
            {
                _buffer.Append((char)_expressionReader.Read());
                p = (char)_expressionReader.Peek();
            }

            if (_variables.ContainsKey(_buffer.ToString()))
            {
                double           value      = _variables[_buffer.ToString()];
                NumberExpression expression = new NumberExpression(value);
                _expressionQueue.Enqueue(expression);

                return(true);
            }

            if (IsFunction(_buffer.ToString()))
            {
                _symbolStack.Push(_buffer.ToString());
                return(true);
            }

            throw new ParseException(Resources.InvalidVariableEncountered + _buffer);
        }
Exemple #2
0
        private bool TryNumber(char lastChar)
        {
            bool isNumber = NumberExpression.IsNumber(_currentChar);
            // only negative when last char is group start or symbol
            bool isNegative = NumberExpression.IsNegativeSign(_currentChar) &&
                              (lastChar == '\0' || lastChar == '(' || OperatorExpression.IsSymbol(lastChar));

            if (!isNumber && !isNegative)
            {
                return(false);
            }

            _buffer.Length = 0;
            _buffer.Append(_currentChar);

            char p = (char)_expressionReader.Peek();

            while (NumberExpression.IsNumber(p))
            {
                _currentChar = (char)_expressionReader.Read();
                _buffer.Append(_currentChar);
                p = (char)_expressionReader.Peek();
            }

            double value;

            if (!(double.TryParse(_buffer.ToString(), out value)))
            {
                throw new ParseException(Resources.InvalidNumberFormat + _buffer);
            }

            NumberExpression expression = new NumberExpression(value);

            _expressionQueue.Enqueue(expression);

            return(true);
        }
Exemple #3
0
        private bool TryString(char c)
        {
            if (!char.IsLetter(c))
                return false;

            _buffer.Length = 0;
            _buffer.Append(c);

            char p = (char)_expressionReader.Peek();
            while (char.IsLetter(p))
            {
                _buffer.Append((char)_expressionReader.Read());
                p = (char)_expressionReader.Peek();
            }

            if (_variables.ContainsKey(_buffer.ToString()))
            {
                double value = _variables[_buffer.ToString()];
                NumberExpression expression = new NumberExpression(value);
                _expressionQueue.Enqueue(expression);

                return true;
            }

            if (IsFunction(_buffer.ToString()))
            {
                _symbolStack.Push(_buffer.ToString());
                return true;
            }

            throw new ParseException(Resources.InvalidVariableEncountered + _buffer);
        }
Exemple #4
0
        private bool TryNumber(char c)
        {
            bool isNumber = NumberExpression.IsNumber(c);
            bool isNegative = _expressionQueue.Count == 0 && NumberExpression.IsNegativeSign(c);

            if (!isNumber && !isNegative)
                return false;

            _buffer.Length = 0;
            _buffer.Append(c);

            char p = (char)_expressionReader.Peek();
            while (NumberExpression.IsNumber(p))
            {
                _buffer.Append((char)_expressionReader.Read());
                p = (char)_expressionReader.Peek();
            }

            double value;
            if (!(double.TryParse(_buffer.ToString(), out value)))
                throw new ParseException(Resources.InvalidNumberFormat + _buffer);

            NumberExpression expression = new NumberExpression(value);
            _expressionQueue.Enqueue(expression);

            return true;
        }
        private bool TryNumber(char c, char l)
        {
            bool isNumber = NumberExpression.IsNumber(c);
            // only negative when last char is group start or symbol
            bool isNegative = NumberExpression.IsNegativeSign(c) &&
                (l == '\0' || l == '(' || OperatorExpression.IsSymbol(l));

            if (!isNumber && !isNegative)
                return false;

            _buffer.Length = 0;
            _buffer.Append(c);

            char p = (char)_expressionReader.Peek();
            while (NumberExpression.IsNumber(p))
            {
                _buffer.Append((char)_expressionReader.Read());
                p = (char)_expressionReader.Peek();
            }

            double value;
            if (!(double.TryParse(_buffer.ToString(), out value)))
                throw new ParseException(Resources.InvalidNumberFormat + _buffer);

            NumberExpression expression = new NumberExpression(value);
            _expressionQueue.Enqueue(expression);

            return true;
        }