本文整理汇总了C#中Token.SubTokens方法的典型用法代码示例。如果您正苦于以下问题:C# Token.SubTokens方法的具体用法?C# Token.SubTokens怎么用?C# Token.SubTokens使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Token
的用法示例。
在下文中一共展示了Token.SubTokens方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: FormTheExpression
/// <summary>
/// The primary function that make the expression that will be compiled then evaluated.
/// </summary>
/// <param name="tokens"></param>
/// <returns></returns>
public Expression FormTheExpression(Token tokens)
{
Expression quantityExpression = null;
ExprOp eop = null;
ExprOp FirstEop = null;
int ix = 0; //this is the index in the discovered tokens
while (ix < tokens.Count)
{
string q = tokens[ix].TokenValue;
string op = ix + 1 < tokens.Count ? tokens[ix + 1].TokenValue : string.Empty;
if (q == "+" || q == "-")
{
// unary prefix operator.
//consume another token for number
if (q == "+")
{
//q = tokens[ix].TokenValue;
quantityExpression = Expression.Constant(1.0);
}
else
{
quantityExpression = Expression.Constant(-1.0);
}
op = "_h*";
ix--;
goto ExpressionCompleted;
}
if (tokens[ix].TokenClassType == typeof(IfWordToken))
{
// this is an If Word so we need to take all the tokens after it until we find THEN token
// and form expression.
int ifClosingIndex;
Token IfBodyToken = tokens.SubTokens(ix + 1, typeof(ThenWordToken), out ifClosingIndex);
int thenClosingIndex;
Token ThenBodyToken = null;
int elseClosingIndex;
Token ElseBodyToken = null;
ix = ifClosingIndex;
if (ix < tokens.Count)
{
if (tokens[ifClosingIndex].TokenClassType == typeof(ThenWordToken))
{
// True part evaluation
ThenBodyToken = tokens.SubTokens(ix + 1, typeof(ElseWordToken), out thenClosingIndex);
ix = thenClosingIndex;
if (ix < tokens.Count)
{
if (tokens[thenClosingIndex].TokenClassType == typeof(ElseWordToken))
{
// True part evaluation
ElseBodyToken = tokens.SubTokens(ix + 1, typeof(ElseWordToken), out elseClosingIndex);
ix = elseClosingIndex;
}
}
}
}
Expression TestPart = FormTheExpression(IfBodyToken);
Expression TruePart;
Expression FalsePart;
if (ThenBodyToken != null)
TruePart = Expression.Convert(FormTheExpression(ThenBodyToken), typeof(object));
else
TruePart = Expression.Constant(true, typeof(object));
if (ElseBodyToken != null)
FalsePart = Expression.Convert(FormTheExpression(ElseBodyToken), typeof(object));
else
FalsePart = Expression.Constant(false, typeof(object));
quantityExpression = Expression.Condition(TestPart, TruePart, FalsePart);
}
else if (tokens[ix].TokenClassType == typeof(ParenthesisCallToken))
{
quantityExpression = FunctionCallExpression(tokens[ix]);
}
else if (tokens[ix].TokenClassType == typeof(ParenthesisGroupToken))
{
//.........这里部分代码省略.........