// Reads a decimal number with optional exponentiation private Token ReadToComma(char ch) { StringBuilder sb = new StringBuilder(); sb.Append(ch); while (!reader.EndOfInput()) { char cPeek = reader.Peek(); if (cPeek == ',') { break; } cPeek = reader.GetNext(); sb.Append(cPeek); } return(new Token(sb.ToString(), TokenTypes.QUOTE)); }
private Token GetNextToken() { while (!reader.EndOfInput()) { char ch = reader.GetNext(); // skipping whitespaces if (Char.IsWhiteSpace(ch)) { continue; } switch (ch) { case '=': return(new Token(ch.ToString(), reader.Line, reader.Column, reader.Line, reader.Column, TokenTypes.EQUAL)); case '+': return(new Token(ch.ToString(), reader.Line, reader.Column, reader.Line, reader.Column, TokenTypes.PLUS)); case '-': return(new Token(ch.ToString(), reader.Line, reader.Column, reader.Line, reader.Column, TokenTypes.MINUS)); case '(': return(new Token(ch.ToString(), reader.Line, reader.Column, reader.Line, reader.Column, TokenTypes.LPAREN)); case ')': return(new Token(ch.ToString(), reader.Line, reader.Column, reader.Line, reader.Column, TokenTypes.RPAREN)); case ',': return(new Token(ch.ToString(), reader.Line, reader.Column, reader.Line, reader.Column, TokenTypes.COMMA)); case '^': return(new Token(ch.ToString(), reader.Line, reader.Column, reader.Line, reader.Column, TokenTypes.EXP)); case '%': return(new Token(ch.ToString(), reader.Line, reader.Column, reader.Line, reader.Column, TokenTypes.MODULUS)); case '!': if (reader.Peek() == '=') { reader.GetNext(); // go past the equal return(new Token(ch.ToString(), reader.Line, reader.Column, reader.Line, reader.Column, TokenTypes.NOTEQUAL)); } else { return(new Token(ch.ToString(), reader.Line, reader.Column, reader.Line, reader.Column, TokenTypes.NOT)); } case '&': return(new Token(ch.ToString(), reader.Line, reader.Column, reader.Line, reader.Column, TokenTypes.PLUSSTRING)); case '|': if (reader.Peek() == '|') { reader.GetNext(); // go past the '|' return(new Token(ch.ToString(), reader.Line, reader.Column, reader.Line, reader.Column, TokenTypes.OR)); } break; case '>': if (reader.Peek() == '=') { reader.GetNext(); // go past the equal return(new Token(ch.ToString(), reader.Line, reader.Column, reader.Line, reader.Column, TokenTypes.GREATERTHANOREQUAL)); } else { return(new Token(ch.ToString(), reader.Line, reader.Column, reader.Line, reader.Column, TokenTypes.GREATERTHAN)); } case '/': if (reader.Peek() == '*') { // beginning of a comment of form /* a comment */ reader.GetNext(); // go past the '*' ReadComment(); continue; } else { return(new Token(ch.ToString(), reader.Line, reader.Column, reader.Line, reader.Column, TokenTypes.FORWARDSLASH)); } case '<': if (reader.Peek() == '=') { reader.GetNext(); // go past the equal return(new Token(ch.ToString(), reader.Line, reader.Column, reader.Line, reader.Column, TokenTypes.LESSTHANOREQUAL)); } else if (reader.Peek() == '>') { reader.GetNext(); // go past the > return(new Token(ch.ToString(), reader.Line, reader.Column, reader.Line, reader.Column, TokenTypes.NOTEQUAL)); } else { return(new Token(ch.ToString(), reader.Line, reader.Column, reader.Line, reader.Column, TokenTypes.LESSTHAN)); } case '*': return(new Token(ch.ToString(), reader.Line, reader.Column, reader.Line, reader.Column, TokenTypes.STAR)); case '"': case '\'': return(ReadQuoted(ch)); case '{': return(ReadIdentifier(ch, 4)); default: break; } // end of swith if (Char.IsDigit(ch)) { return(ReadNumber(ch)); } else if (ch == '.') { char tc = reader.Peek(); if (Char.IsDigit(tc)) { return(ReadNumber(ch)); } return(new Token(ch.ToString(), reader.Line, reader.Column, reader.Line, reader.Column, TokenTypes.DOT)); } else if (Char.IsLetter(ch) || ch == '_') { return(ReadIdentifier(ch)); } else { return(new Token(ch.ToString(), reader.Line, reader.Column, reader.Line, reader.Column, TokenTypes.OTHER)); } } return(null); }