34 lines
765 B
C#
34 lines
765 B
C#
|
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);
|
||
|
}
|
||
|
}
|
||
|
}
|