KumiScript/parser/AtomToken.cs

38 lines
926 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 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;
}
}
}