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); }
private bool ReadDigits() { bool read = false; while (CharPredicates.IsDigit(_scanner.Peek())) { read = true; next.Value += _scanner.Advance(); } return(read); }
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); }