AST pretty much complete

This commit is contained in:
Mike Nolan 2023-03-10 04:12:51 -06:00
parent c91f9b9781
commit c1a3acee07
13 changed files with 502 additions and 0 deletions

View File

@ -0,0 +1,40 @@
namespace tlang
{
internal class BitwiseAndNode : Node
{
public Node Left {get;set;}
public Node Right {get;set;}
public BitwiseAndNode(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 dleft = l as TDictionary;
if(dleft != null)
{
if(dleft.MemberExists("band"))
{
var mbm = dleft["band"] as ICallable;
if(mbm != null)
{
return mbm.Call(r);
}
}
}
if(lnum != null && rnum != null)
return new TNumber((long)lnum.Value & (long)rnum.Value);
return new TNull();
}
}
}

40
tlanglib/BitwiseOrNode.cs Normal file
View File

@ -0,0 +1,40 @@
namespace tlang
{
internal class BitwiseOrNode : Node
{
public Node Left {get;set;}
public Node Right {get;set;}
public BitwiseOrNode(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 dleft = l as TDictionary;
if(dleft != null)
{
if(dleft.MemberExists("bor"))
{
var mbm = dleft["bor"] as ICallable;
if(mbm != null)
{
return mbm.Call(r);
}
}
}
if(lnum != null && rnum != null)
return new TNumber((long)lnum.Value | (long)rnum.Value);
return new TNull();
}
}
}

40
tlanglib/EqualsNode.cs Normal file
View File

@ -0,0 +1,40 @@
namespace tlang
{
internal class EqualsNode : Node
{
public Node Left {get;set;}
public Node Right {get;set;}
public EqualsNode(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 dleft = l as TDictionary;
if(dleft != null)
{
if(dleft.MemberExists("eq"))
{
var mbm = dleft["eq"] as ICallable;
if(mbm != null)
{
return mbm.Call(r);
}
}
}
if(lnum != null && rnum != null)
return new TNumber(lnum.Value == rnum.Value ? 1 : 0);
return new TNull();
}
}
}

View File

@ -0,0 +1,40 @@
namespace tlang
{
internal class GreaterThanEqualsNode : Node
{
public Node Left {get;set;}
public Node Right {get;set;}
public GreaterThanEqualsNode(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 dleft = l as TDictionary;
if(dleft != null)
{
if(dleft.MemberExists("gte"))
{
var mbm = dleft["gte"] as ICallable;
if(mbm != null)
{
return mbm.Call(r);
}
}
}
if(lnum != null && rnum != null)
return new TNumber(lnum.Value >= rnum.Value ? 1 : 0);
return new TNull();
}
}
}

View File

@ -0,0 +1,40 @@
namespace tlang
{
internal class GreaterThanNode : Node
{
public Node Left {get;set;}
public Node Right {get;set;}
public GreaterThanNode(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 dleft = l as TDictionary;
if(dleft != null)
{
if(dleft.MemberExists("gt"))
{
var mbm = dleft["gt"] as ICallable;
if(mbm != null)
{
return mbm.Call(r);
}
}
}
if(lnum != null && rnum != null)
return new TNumber(lnum.Value > rnum.Value ? 1 : 0);
return new TNull();
}
}
}

40
tlanglib/LeftShift.cs Normal file
View File

@ -0,0 +1,40 @@
namespace tlang
{
internal class LeftShiftNode : Node
{
public Node Left {get;set;}
public Node Right {get;set;}
public LeftShiftNode(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 dleft = l as TDictionary;
if(dleft != null)
{
if(dleft.MemberExists("ls"))
{
var mbm = dleft["ls"] as ICallable;
if(mbm != null)
{
return mbm.Call(r);
}
}
}
if(lnum != null && rnum != null)
return new TNumber((long)lnum.Value << (int)rnum.Value);
return new TNull();
}
}
}

View File

@ -0,0 +1,40 @@
namespace tlang
{
internal class LessThanEqualsNode : Node
{
public Node Left {get;set;}
public Node Right {get;set;}
public LessThanEqualsNode(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 dleft = l as TDictionary;
if(dleft != null)
{
if(dleft.MemberExists("lte"))
{
var mbm = dleft["lte"] as ICallable;
if(mbm != null)
{
return mbm.Call(r);
}
}
}
if(lnum != null && rnum != null)
return new TNumber(lnum.Value <= rnum.Value ? 1 : 0);
return new TNull();
}
}
}

40
tlanglib/LessThanNode.cs Normal file
View File

@ -0,0 +1,40 @@
namespace tlang
{
internal class LessThanNode : Node
{
public Node Left {get;set;}
public Node Right {get;set;}
public LessThanNode(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 dleft = l as TDictionary;
if(dleft != null)
{
if(dleft.MemberExists("lt"))
{
var mbm = dleft["lt"] as ICallable;
if(mbm != null)
{
return mbm.Call(r);
}
}
}
if(lnum != null && rnum != null)
return new TNumber(lnum.Value < rnum.Value ? 1 : 0);
return new TNull();
}
}
}

View File

@ -0,0 +1,31 @@
namespace tlang
{
internal class LogicalAndNode : Node
{
public Node Left {get;set;}
public Node Right {get;set;}
public LogicalAndNode(Node left, Node right)
{
Left = left;
Right = right;
}
public override TObject Execute(IScopeEnvironment nodeEnv)
{
var l = Left.Execute(nodeEnv);
var r = Right.Execute(nodeEnv);
var ldict = l as TDictionary;
if(ldict != null)
{
var lor=ldict["land"] as ICallable;
if(lor != null)
{
return lor.Call(r);
}
}
return new TNumber(l.AsBoolean && r.AsBoolean ? 1 : 0);
}
}
}

31
tlanglib/LogicalOrNode.cs Normal file
View File

@ -0,0 +1,31 @@
namespace tlang
{
internal class LogicalOrNode : Node
{
public Node Left {get;set;}
public Node Right {get;set;}
public LogicalOrNode(Node left, Node right)
{
Left = left;
Right = right;
}
public override TObject Execute(IScopeEnvironment nodeEnv)
{
var l = Left.Execute(nodeEnv);
var r = Right.Execute(nodeEnv);
var ldict = l as TDictionary;
if(ldict != null)
{
var lor=ldict["lor"] as ICallable;
if(lor != null)
{
return lor.Call(r);
}
}
return new TNumber(l.AsBoolean || r.AsBoolean ? 1 : 0);
}
}
}

40
tlanglib/NotEqualsNode.cs Normal file
View File

@ -0,0 +1,40 @@
namespace tlang
{
internal class NotEqualsNode : Node
{
public Node Left {get;set;}
public Node Right {get;set;}
public NotEqualsNode(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 dleft = l as TDictionary;
if(dleft != null)
{
if(dleft.MemberExists("neq"))
{
var mbm = dleft["neq"] as ICallable;
if(mbm != null)
{
return mbm.Call(r);
}
}
}
if(lnum != null && rnum != null)
return new TNumber(lnum.Value != rnum.Value ? 1 : 0);
return new TNull();
}
}
}

40
tlanglib/RightShift.cs Normal file
View File

@ -0,0 +1,40 @@
namespace tlang
{
internal class RightShiftNode : Node
{
public Node Left {get;set;}
public Node Right {get;set;}
public RightShiftNode(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 dleft = l as TDictionary;
if(dleft != null)
{
if(dleft.MemberExists("rs"))
{
var mbm = dleft["rs"] as ICallable;
if(mbm != null)
{
return mbm.Call(r);
}
}
}
if(lnum != null && rnum != null)
return new TNumber((long)lnum.Value >> (int)rnum.Value);
return new TNull();
}
}
}

40
tlanglib/XOrNode.cs Normal file
View File

@ -0,0 +1,40 @@
namespace tlang
{
internal class XOrNode : Node
{
public Node Left {get;set;}
public Node Right {get;set;}
public XOrNode(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 dleft = l as TDictionary;
if(dleft != null)
{
if(dleft.MemberExists("xor"))
{
var mbm = dleft["xor"] as ICallable;
if(mbm != null)
{
return mbm.Call(r);
}
}
}
if(lnum != null && rnum != null)
return new TNumber((long)lnum.Value ^ (long)rnum.Value);
return new TNull();
}
}
}