Beispiel #1
0
        public override void Open(string filename)
        {
            _realDirectory = filename;
            _context       = new RealContext(new DirectoryInfo(filename));

            BuildFS();
        }
        public void Interpret(RealContext context)
        {
            if (context.Input.Length == 0)
            {
                return;
            }

            if (context.Input.StartsWith(Nine()))
            {
                context.Output += (9 * Multiplier());
                context.Input   = context.Input.Substring(2);
            }
            else if (context.Input.StartsWith(Four()))
            {
                context.Output += (4 * Multiplier());
                context.Input   = context.Input.Substring(2);
            }
            else if (context.Input.StartsWith(Five()))
            {
                context.Output += (5 * Multiplier());
                context.Input   = context.Input.Substring(1);
            }

            while (context.Input.StartsWith(One()))
            {
                context.Output += (1 * Multiplier());
                context.Input   = context.Input.Substring(1);
            }
        }
        public static void InterpreterRealWorld()
        {
            string      roman   = "MCMXXVIII";
            RealContext context = new RealContext(roman);

            // Build the 'parse tree'
            List <RealExpression> tree = new List <RealExpression>();

            tree.Add(new ThousandExpression());
            tree.Add(new HundredExpression());
            tree.Add(new TenExpression());
            tree.Add(new OneExpression());

            // Interpret
            foreach (RealExpression exp in tree)
            {
                exp.Interpret(context);
            }

            Log.WriteLine("{0} = {1}", roman, context.Output);
        }
 public Wrapper(RealContext context)
 {
     this.context = context;
 }
Beispiel #5
0
 public TenantContext(int tenantId)
 {
     realContext   = new RealContext();
     this.tenantId = tenantId;
 }