Esempio n. 1
0
 private TokenType GetOneCharToken(char c)
 {
     return
         (oneCharTokenMap.ContainsKey(c) ? oneCharTokenMap[c] :
          CharPredicates.IsDecimalPoint(c) ? TokenType.POINT :
          CharPredicates.IsDigit(c) ? TokenType.NUMBER :
          CharPredicates.IsWhitespace(c) ? TokenType.WHITESPACE :
          CharPredicates.IsLetter(c) ? TokenType.INDETIFIER :
          c == '\0' ? TokenType.EOE :
          TokenType.ILLEGAL);
 }
Esempio n. 2
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);
        }