本文整理汇总了C#中IToken.Simplify方法的典型用法代码示例。如果您正苦于以下问题:C# IToken.Simplify方法的具体用法?C# IToken.Simplify怎么用?C# IToken.Simplify使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IToken
的用法示例。
在下文中一共展示了IToken.Simplify方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Simplify
public override TokenList Simplify(IToken first, IToken last)
{
if (first == null)
throw new Exception($"Operation {Text} can not be unary.");
TokenList lastList = last.Simplify();
if (lastList == null || lastList.Count != 1)
throw new Exception($"Second element of Operation {Text} is not unique.");
IntToken intToken = lastList[0] as IntToken;
if (intToken == null)
throw new Exception($"Operation {Text} must have integer second element.");
return new TokenList(first.Simplify()[intToken.Value]);
}
示例2: Simplify
public virtual TokenList Simplify(IToken first, IToken last)
{
if (first == null)
{
if (CanBeUnary)
{
ITypeToken secondType = last?.Simplify()[0] as ITypeToken;
return secondType != null ? Evaluate(secondType) : new TokenList(new ExpressionToken(null, this, last));
}
throw new Exception($"Operation {Text} can not be unary.");
}
if (CanBeBinary)
{
ITypeToken firstType = first.Simplify()[0] as ITypeToken;
ITypeToken secondType = last?.Simplify()[0] as ITypeToken;
return firstType != null && secondType != null ? Evaluate(firstType, secondType) : new TokenList(new ExpressionToken(first, this, last));
}
throw new Exception($"Operation {Text} can not be binary.");
}