private AST operand()
{
#if WRITE_DEBUG_INFO
Console.WriteLine("operand");
#endif
AST operandTree = null;
if (lookAheadType(1) == Token.TokenType.NAME &&
lookAheadType(2) == Token.TokenType.PARANTHESIS_LEFT)
{
operandTree = functionCall();
}
else if ( lookAheadType(1) == Token.TokenType.NAME &&
lookAheadType(2) == Token.TokenType.BRACKET_LEFT )
{
operandTree = arrayLookup();
}
else if ( lookAheadType(1) == Token.TokenType.FROM )
{
operandTree = fromMinToMaxArrayCreation();
}
else if (lookAheadType(1) == Token.TokenType.NAME)
{
Token operandToken = match(Token.TokenType.NAME);
operandTree = new AST(operandToken);
}
else if (lookAheadType(1) == Token.TokenType.NUMBER)
{
Token operandToken = match(Token.TokenType.NUMBER);
float number = (float)Convert.ToDouble(operandToken.getTokenString(),
CultureInfo.InvariantCulture
);
operandTree = new AST(new TokenWithValue(operandToken.getTokenType(),
operandToken.getTokenString(),
number));
}
else if (lookAheadType(1) == Token.TokenType.QUOTED_STRING)
{
Token operandToken = match(Token.TokenType.QUOTED_STRING);
operandTree = new AST(new TokenWithValue(operandToken.getTokenType(),
operandToken.getTokenString(),
operandToken.getTokenString()));
}
else if (lookAheadType(1) == Token.TokenType.BOOLEAN_VALUE)
{
Token operandToken = match(Token.TokenType.BOOLEAN_VALUE);
bool boolean = operandToken.getTokenString().ToLower() == "true" ? true : false;
operandTree = new AST(new TokenWithValue(operandToken.getTokenType(),
operandToken.getTokenString(),
boolean));
}
else if (lookAheadType(1) == Token.TokenType.OPERATOR &&
lookAhead(1).getTokenString() == "-")
{
operandTree = negativeExpression();
}
else if (lookAheadType(1) == Token.TokenType.OPERATOR &&
lookAhead(1).getTokenString() == "+")
{
match(Token.TokenType.OPERATOR); // discard
operandTree = operand();
}
else if (lookAheadType(1) == Token.TokenType.BRACKET_LEFT)
{
operandTree = arrayCreation();
}
return operandTree;
}