KumiScript/reader/AtomToken.cs

38 lines
No EOL
944 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 new NumberExpression(f);
if (_value == "null")
return NilExpression.GetInstance();
if (_value == "t")
return TrueExpression.GetInstance();
return new SymbolExpression(SymbolTable.GetInstance().FromString(_value));
}
public override string GetValue()
{
return _value;
}
}
}