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))
|
2024-07-12 00:17:00 +00:00
|
|
|
return new NumberExpression(f);
|
2024-01-26 05:37:51 +00:00
|
|
|
|
|
|
|
if (_value == "null")
|
|
|
|
return NilExpression.GetInstance();
|
|
|
|
|
|
|
|
if (_value == "t")
|
|
|
|
return TrueExpression.GetInstance();
|
|
|
|
|
2024-07-12 00:17:00 +00:00
|
|
|
return new SymbolExpression(SymbolTable.GetInstance().FromString(_value));
|
2024-01-26 05:37:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public override string GetValue()
|
|
|
|
{
|
|
|
|
return _value;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|