KumiScript/parser/AtomToken.cs
2024-01-25 23:37:51 -06:00

38 lines
No EOL
926 B
C#

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 NumberFactory.NormalizeFloat(f);
if (_value == "null")
return NilExpression.GetInstance();
if (_value == "t")
return TrueExpression.GetInstance();
return new SymbolExpression(new Symbol(_value));
}
public override string GetValue()
{
return _value;
}
}
}