Beispiel #1
0
        private static IToken Acquire(IToken arg0, IToken arg1)
        {
            var key = Tuple.Create(arg0, arg1);

            if (Cache.TryGetValue(key, out var cached))
            {
                return(cached);
            }

            IToken x;

            if (arg1 == null)
            {
                x = new AddOperator(arg0);
            }
            else
            {
                var x0 = AlienMessageParser.Reduce(arg0);
                var x1 = AlienMessageParser.Reduce(arg1);
                x = ConstantOperator.Acquire(x0.AsValue() + x1.AsValue());
            }

            Cache[key] = x;
            return(x);
        }
Beispiel #2
0
        public IToken Apply(IToken arg)
        {
            if (x0 == null)
            {
                return(Acquire(arg));
            }

            x0 = AlienMessageParser.Reduce(x0);
            var x1 = AlienMessageParser.Reduce(arg);

            return(ConstantOperator.Acquire(x0.AsValue() * x1.AsValue()));
        }
Beispiel #3
0
        public IToken Apply(IToken arg)
        {
            if (x0 == null)
            {
                return(Acquire(arg));
            }

            x0 = AlienMessageParser.Reduce(x0);
            var x1 = AlienMessageParser.Reduce(arg);

            return(ConstantOperator.Acquire(decimal.Round(x0.AsValue() / x1.AsValue(), MidpointRounding.ToZero)));
        }
Beispiel #4
0
        public static ConstantOperator Acquire(decimal value)
        {
            if (Cache.TryGetValue(value, out var cached))
            {
                return(cached);
            }

            var x = new ConstantOperator(value);

            Cache[value] = x;

            return(x);
        }
Beispiel #5
0
        public IToken Apply(IToken arg)
        {
            var x0 = AlienMessageParser.Reduce(arg);

            return(ConstantOperator.Acquire(x0.AsValue() - 1));
        }
Beispiel #6
0
 public IToken Apply(IToken arg)
 {
     return(ConstantOperator.Acquire((decimal)Math.Pow(2, (double)arg.AsValue())));
 }