예제 #1
0
        public void CompileDefine()
        {
            Compiler compiler = new Compiler("define foo { 1 2 dup }");

            Expression expression = compiler.CompileExpression();

            Assert.IsNotNull(expression);
            Assert.IsInstanceOfType(expression, typeof(DefineExpression));

            DefineExpression define = (DefineExpression)expression;

            Assert.AreEqual("foo", define.Name);
            Assert.IsNotNull(define.Expressions);
            Assert.AreEqual(3, define.Expressions.Count);
            Assert.IsInstanceOfType(define.Expressions[0], typeof(IntegerExpression));
            Assert.IsInstanceOfType(define.Expressions[1], typeof(IntegerExpression));
            Assert.IsInstanceOfType(define.Expressions[2], typeof(DupExpression));

            Assert.AreEqual("define foo { 1 2 dup }", define.ToString());
        }
예제 #2
0
        public void CreateAndEvaluateDefineExpression()
        {
            Machine           machine = new Machine();
            List <Expression> list    = new List <Expression>();

            list.Add(new IntegerExpression(1));
            list.Add(new IntegerExpression(2));
            list.Add(new IntegerExpression(3));

            DefineExpression expression = new DefineExpression("foo", list);

            Assert.IsNotNull(expression);
            Assert.AreEqual("foo", expression.Name);
            Assert.IsNotNull(expression.Expressions);
            Assert.AreEqual(3, expression.Expressions.Count);

            Assert.AreEqual(0, machine.StackCount);
            expression.Evaluate(machine);
            Assert.AreEqual(0, machine.StackCount);
        }