Основы объектно-ориентированного программирования на языке C# book | Page 189

8.5 Комплексна вправа до роздiлу 7 public NumberExpression(long value) { this.value = value; } public override long Eval() { return value; } internal static bool TryRead(IInput input, out IToken result) { if (input.IsEmpty() || !char.IsDigit(input.Current)) { result = null; return false; } string s = ""; while (!input.IsEmpty()) { if (!char.IsDigit(input.Current)) { result = new NumberExpression(long.Parse(s)); return true; } else { s += input.Current; input.MoveNext(); } } result = new NumberExpression(long.Parse(s)); return true; } } public sealed class EmptyExpression : Expression { public override long Eval() { throw new InvalidOperationException("Empty expression cannot be evaluated"); } } public static class OperationsRegistry { private static Dictionary Ops1 = new Dictionary(); private static Dictionary Ops2 = new Dictionary(); public static void Register(IEnumerable ops) { foreach (Operation op in ops) Register(op); } 189