コード例 #1
0
        /// <summary>
        /// Performs a for loop
        /// </summary>
        /// <param name="tree">Tree to be executed</param>
        private void ForLoop(KermitAST tree)
        {
            KermitAST begin     = (KermitAST)tree.GetChild(0);
            KermitAST condition = (KermitAST)tree.GetChild(1);
            KermitAST action    = (KermitAST)tree.GetChild(2);
            KermitAST code      = (KermitAST)tree.GetChild(3);

            ScopeSpace  sp   = new ScopeSpace("while", _currentSpace);
            MemorySpace save = _currentSpace;

            try
            {
                _currentSpace = sp;
                for (Execute(begin); (KBool)Execute(condition); Execute(action))
                {
                    Execute(code);
                }
            }
            finally
            {
                _currentSpace = save;
            }
        }
コード例 #2
0
        /// <summary>
        /// Performs a while loop
        /// </summary>
        /// <param name="tree">Tree to be executed</param>
        private void WhileLoop(KermitAST tree)
        {
            KermitAST condition = (KermitAST)tree.GetChild(0);
            KermitAST code      = (KermitAST)tree.GetChild(1);

            ScopeSpace  sp   = new ScopeSpace("while", _currentSpace);
            MemorySpace save = _currentSpace;

            try
            {
                _currentSpace = sp;
                KBool cond = Execute(condition).Cast <KBool>();
                while (cond)
                {
                    Execute(code);
                    cond = Execute(condition).Cast <KBool>();
                }
            }
            finally
            {
                _currentSpace = save;
            }
        }