private void ParseIdentifier() { string identifier = string.Empty; int positionStart = currentPosition; while (CurrentChar == '_' || char.IsLetterOrDigit(CurrentChar)) { identifier += CurrentChar; NextChar(); } switch (identifier) { case "AND": expressionTokens.Add(new OperatorToken(TokenType.AndOperator, positionStart)); NextToken(); break; case "OR": expressionTokens.Add(new OperatorToken(TokenType.OrOperator, positionStart)); NextToken(); break; case "NOT": expressionTokens.Add(new OperatorToken(TokenType.NotOperator, positionStart)); NextToken(); break; case "TRUE": case "FALSE": ValueToken booleanToken = new ValueToken { Type = TokenType.BooleanValue, StringValue = identifier, SystemValue = (identifier == "TRUE"), PositionStart = positionStart }; expressionTokens.Add(booleanToken); NextToken(); break; case "LOE": expressionTokens.Add(new OperatorToken(TokenType.LessOrEqualOperator, positionStart)); NextToken(); break; case "GOE": expressionTokens.Add(new OperatorToken(TokenType.GreaterOrEqualOperator, positionStart)); NextToken(); break; default: ExpressionToken identifierToken = new ExpressionToken(); identifierToken.StringValue = identifier; identifierToken.Type = TokenType.Identifier; identifierToken.PositionStart = positionStart; expressionTokens.Add(identifierToken); NextToken(); break; } }
private void ParseNumber() { string stringNumber = String.Empty; ValueToken currentToken = new ValueToken { PositionStart = currentPosition, Type = TokenType.IntegerValue }; while (char.IsDigit(CurrentChar)) { stringNumber += CurrentChar; NextChar(); } if (CurrentChar == '.') { currentToken.Type = TokenType.DecimalValue; stringNumber += CurrentChar; NextChar(); if (!char.IsDigit(CurrentChar)) { throw new ArgumentException($"Unexpected '{CurrentChar}' at position {currentPosition}.\nDigit was expected."); } while (char.IsDigit(CurrentChar)) { stringNumber += CurrentChar; NextChar(); } } currentToken.SystemValue = stringNumber; expressionTokens.Add(currentToken); NextToken(); }
public void ParseString() { ValueToken currentToken = new ValueToken { PositionStart = currentPosition, Type = TokenType.StringValue }; NextChar(); string stringValue = String.Empty; while (!(CurrentChar == '\'' || CurrentChar == '\0')) { stringValue += CurrentChar; NextChar(); } if (CurrentChar == '\0') { throw new ArgumentException("String value must be enclosed by ' character!"); } currentToken.SystemValue = stringValue; expressionTokens.Add(currentToken); NextChar(); NextToken(); }