public RSResult Evaluate(RSToken statement) { RSResult result = null; switch (statement) { case RSBlock p: foreach (var s in p.Tokens) { result = Evaluate(s); if (result.Returnable) { return(result); } } return(result); case RSConstant c: return(RSResult.FromValue(c.Value)); case RSBinary b: return(Binary(b)); case RSNumber n: return(RSResult.FromValue(n.Value)); case RSString s: return(RSResult.FromValue(s.Value)); case RSOutput o: result = Evaluate(o.Expression); Output(result.Value); return(result); } throw (new Exception($"I don't know how to evaluate {statement.GetType()} statements")); }
public RSBlock(RSToken head, IEnumerable <RSToken> tail) { this.Tokens = new List <RSToken>(); this.Tokens.Add(head); this.Tokens.AddRange(tail); }
public RSBlock(RSToken token) { this.Tokens = new List <RSToken> { token }; }