SyntaxAnalyse/TokenRecord/Method/TokenIf.cs
(完整代码) 1KB//xxxxxxxxxxx
using System;
using System.Collections.Generic;
using System.Text;
namespace ConExpress.Calculator
{
/// <summary>
/// If记号类,对应关键字if,不区分大小写
/// </summary>
/// <example>用法:if(Condition, TrueValue, FalseValue),如果Condition为true,则返回TrueValue,否则返回FalseValue</example>
public class TokenIf : TokenMethod
{
public TokenIf(int Index, int Length)
: base(Index, Length)
{
}
protected override void SetChildCount()
{
this.m_ChildCount = 3;
}
public override void Execute()
{
this.CheckChildCount("if语句运算元素数量不合法");
TokenRecord TokenCondition = this.ChildList[0];
TokenRecord TokenTrue = this.ChildList[1];
TokenRecord TokenFalse = this.ChildList[2];
//execute child token
TokenCondition.Execute();
//TODO:优化,根据条件判断执行
TokenTrue.Execute();
TokenFalse.Execute();
//if TokenTrue's type is not equal TokenFalse's type, convert them to string
if (TokenTrue.TokenValueType != TokenFalse.TokenValueType)
{
//Error or set token type as string
TokenTrue.ChangeTokenToString();
TokenFalse.ChangeTokenToString();
}
this.TokenValueType = TokenTrue.TokenValueType;
this.TokenValue = TokenCondition.ChangeTokenToBoolean() ? TokenTrue.TokenValue : TokenFalse.TokenValue;
}
}
}
24 小时内免费解锁 3 个项目,之后 1 算力/个。 规则说明
AI 解读 AI
登录后可用,每次 10 算力,解读结果公开显示在下面。
还没有人解读过这个文件。