Esempio n. 1
0
        private TokenType ReadNumber()
        {
            // TODO returning bool instead of token type
            bool hasDigitsBeforePoint = false;
            // bool hasDecimalPoint = false;
            bool hasDigitsAfterPoint = false;

            // bool hasExponentialNotation = false;

            hasDigitsBeforePoint = ReadDigits();
            if (CharPredicates.IsDecimalPoint(_scanner.Peek()))
            {
                // hasDecimalPoint = true;
                next.Value += _scanner.Advance();

                hasDigitsAfterPoint = ReadDigits();
            }

            if (!hasDigitsBeforePoint && !hasDigitsAfterPoint)
            {
                return(TokenType.ILLEGAL);
            }

            if (CharPredicates.IsExponentialNotation(_scanner.Peek()))
            {
                // hasExponentialNotation = true;

                next.Value += _scanner.Advance();

                if (CharPredicates.IsSignOperator(_scanner.Peek()))
                {
                    next.Value += _scanner.Advance();
                }

                if (!CharPredicates.IsDigit(_scanner.Peek()))
                {
                    return(TokenType.ILLEGAL);
                }

                ReadDigits();
            }

            return(TokenType.NUMBER);
        }