tlang-interperter-cs/IfNode.cs

34 lines
765 B
C#
Raw Normal View History

2023-03-09 19:40:14 +00:00
namespace tlang
{
internal class IfNode : Node
{
public Node Condition {get;set;}
public Node Yes {get;set;}
public Node No {get;set;}
public IfNode(Node condition, Node yes, Node no)
{
this.Condition = condition;
this.Yes = yes;
this.No = no;
}
public override TObject Execute(IScopeEnvironment nodeEnv)
{
var condition = Condition.Execute(nodeEnv);
var cInt = condition as TNumber;
bool condition_bool=false;
if(cInt != null)
{
condition_bool=cInt.Value != 0;
}
return condition_bool ? Yes.Execute(nodeEnv) : No.Execute(nodeEnv);
}
}
}