Beispiel #1
0
 public LazyBinaryOp(OP _x, String _Op, OP _y)
 {
     x  = _x;
     Op = _Op;
     y  = _y;
     if (funcs == null)
     {
         funcs = new Dictionary <String, Func <OP, OP, Tuple <int, string> > >();
         funcs.Add("{", (x, y) =>
         {
             var count = x.eval();
             var acc   = 0;
             var msg   = count.Item2 + "{";
             for (int i = 0; i < count.Item1; i++)
             {
                 var res = y.eval();
                 acc    += res.Item1;
                 if (i > 0)
                 {
                     msg += " + " + res.Item2;
                 }
                 else
                 {
                     msg += res.Item2;
                 }
             }
             msg += "}";
             return(Tuple.Create(acc, msg));
         }
                   );
     }
 }
Beispiel #2
0
 public override Tuple <int, string> eval()
 {
     return(funcs[Op](x.eval()));
 }