2023-06-08 18:14:35 +00:00
|
|
|
using System.IO;
|
|
|
|
|
2023-03-09 19:40:14 +00:00
|
|
|
namespace tlang
|
|
|
|
{
|
|
|
|
internal class AddNode : Node
|
|
|
|
{
|
2023-06-08 18:14:35 +00:00
|
|
|
|
2023-03-09 19:40:14 +00:00
|
|
|
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;
|
2023-03-09 23:57:16 +00:00
|
|
|
var dleft = l as TDictionary;
|
2023-03-09 19:40:14 +00:00
|
|
|
|
2023-03-09 23:57:16 +00:00
|
|
|
if(dleft != null)
|
|
|
|
{
|
|
|
|
if(dleft.MemberExists("add"))
|
|
|
|
{
|
|
|
|
var mbm = dleft["add"] as ICallable;
|
|
|
|
if(mbm != null)
|
|
|
|
{
|
|
|
|
return mbm.Call(r);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2023-03-09 19:40:14 +00:00
|
|
|
|
2023-03-09 23:57:16 +00:00
|
|
|
|
2023-03-09 19:40:14 +00:00
|
|
|
if(lNum != null && rNum != null)
|
2023-06-08 18:14:35 +00:00
|
|
|
return TObject.Number(lNum.Value + rNum.Value);
|
2023-03-09 19:40:14 +00:00
|
|
|
|
|
|
|
if(lStr != null && rStr != null)
|
2023-06-08 18:14:35 +00:00
|
|
|
return TObject.String(lStr.Value + rStr.Value);
|
2023-03-09 19:40:14 +00:00
|
|
|
if(lStr != null && rNum != null)
|
2023-06-08 18:14:35 +00:00
|
|
|
return TObject.String(lStr.Value + rNum.Value.ToString());
|
2023-03-09 19:40:14 +00:00
|
|
|
if(lNum != null && rStr != null)
|
2023-06-08 18:14:35 +00:00
|
|
|
return TObject.String(lNum.Value.ToString() + rStr.Value);
|
2023-03-09 19:40:14 +00:00
|
|
|
|
2023-03-09 23:57:16 +00:00
|
|
|
|
|
|
|
|
2023-06-08 18:14:35 +00:00
|
|
|
return TObject.Null;
|
2023-03-09 19:40:14 +00:00
|
|
|
}
|
2023-06-08 18:14:35 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
2023-03-09 19:40:14 +00:00
|
|
|
}
|
|
|
|
}
|