Esempio n. 1
0
 private void SkipWhitespace()
 {
     while (CharPredicates.IsWhitespace(_scanner.Peek()))
     {
         _scanner.Advance();
     }
 }
Esempio n. 2
0
 private void ReadIdentifier()
 {
     while (CharPredicates.IsLetterOrDigit(_scanner.Peek()))
     {
         // TODO string builder
         next.Value += _scanner.Advance();
     }
 }
Esempio n. 3
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. 4
0
        private bool ReadDigits()
        {
            bool read = false;

            while (CharPredicates.IsDigit(_scanner.Peek()))
            {
                read        = true;
                next.Value += _scanner.Advance();
            }

            return(read);
        }
Esempio n. 5
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);
        }