37 lines
1.0 KiB
C#
37 lines
1.0 KiB
C#
|
namespace tlang
|
||
|
{
|
||
|
internal class AddNode : Node
|
||
|
{
|
||
|
public Node Left {get;set;}
|
||
|
public Node Right {get;set;}
|
||
|
|
||
|
public AddNode(Node left, Node right)
|
||
|
{
|
||
|
this.Left = left;
|
||
|
this.Right = right;
|
||
|
}
|
||
|
|
||
|
public override TObject Execute(IScopeEnvironment nodeEnv)
|
||
|
{
|
||
|
var l=Left.Execute(nodeEnv);
|
||
|
var r = Right.Execute(nodeEnv);
|
||
|
var lNum = l as TNumber;
|
||
|
var rNum = r as TNumber;
|
||
|
var lStr = l as TString;
|
||
|
var rStr = r as TString;
|
||
|
|
||
|
|
||
|
if(lNum != null && rNum != null)
|
||
|
return new TNumber(lNum.Value + rNum.Value);
|
||
|
|
||
|
if(lStr != null && rStr != null)
|
||
|
return new TString(lStr.Value + rStr.Value);
|
||
|
if(lStr != null && rNum != null)
|
||
|
return new TString(lStr.Value + rNum.Value.ToString());
|
||
|
if(lNum != null && rStr != null)
|
||
|
return new TString(lNum.Value.ToString() + rStr.Value);
|
||
|
|
||
|
return new TNull();
|
||
|
}
|
||
|
}
|
||
|
}
|