KumiScript/reader/AtomToken.cs

38 lines
944 B
C#
Raw Normal View History

2024-01-26 05:37:51 +00:00
using KumiScript.Interpreter;
namespace KumiScript.Reader
{
public class AtomToken : Token
{
readonly string _value;
public AtomToken(string value)
{
_value = value;
}
public override Expression Accept(ITokenVisitor tokenVisitor)
{
return tokenVisitor.VisitAtom(this);
}
public virtual Expression ToExpression()
{
decimal f;
if (decimal.TryParse(_value, out f))
return new NumberExpression(f);
2024-01-26 05:37:51 +00:00
if (_value == "null")
return NilExpression.GetInstance();
if (_value == "t")
return TrueExpression.GetInstance();
return new SymbolExpression(SymbolTable.GetInstance().FromString(_value));
2024-01-26 05:37:51 +00:00
}
public override string GetValue()
{
return _value;
}
}
}