tlang-interperter-cs/tlanglib/GetVariableValue.cs

39 lines
929 B
C#

namespace tlang
{
internal class SetVariableNode : Node
{
public Node Value {get;set;}
public GetVariableValue Name {get;set;}
public SetVariableNode(GetVariableValue gvn,Node v)
{
Name=gvn;
Value=v;
}
public override TObject Execute(IScopeEnvironment nodeEnv)
{
var res=Value.Execute(nodeEnv);
Name.SetValue(nodeEnv,res);
return res;
}
}
public class GetVariableValue : Node
{
public string Name {get;set;}
public GetVariableValue(string text)
{
this.Name = text;
}
public override TObject Execute(IScopeEnvironment nodeEnv)
{
return nodeEnv[Name];
}
public virtual void SetValue(IScopeEnvironment nodeEnv,TObject value)
{
nodeEnv[Name] = value;
}
}
}