Ejemplo n.º 1
0
 private void PushCommand(Command comm)
 {
     CommandStack.Push(comm);
 }
Ejemplo n.º 2
0
        /// <summary>
        /// Push new Command for evaluation in stack.
        /// </summary>
        /// <param name="inOperation">Operation to evaluate.</param>
        /// <param name="inLeftOperand">Left operand.</param>
        /// <param name="requiredCellMemory">Memory Cell in StackMemory, that stores needed value.</param>
        public void PushCommand(String inOperation, int requiredCellMemory, int inLeftOperand)
        {
            freeMemory(requiredCellMemory);

            int currEmptyCellMemory = GetUnusedMemoryCell();

            Command currCommand = new Command(inOperation, requiredCellMemory, inLeftOperand, currEmptyCellMemory);
            commandStack.Push(currCommand);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Push new Command for evaluation in stack
        /// </summary>
        /// <param name="inOperation">Operation to evaluate.</param>
        /// <param name="inLeftOperand">Left operand.</param>
        /// <param name="inRightOperand">Right operand.</param>
        public void PushCommand(String inOperation, String inLeftOperand, String inRightOperand)
        {
            int currEmptyCellMemory = GetUnusedMemoryCell();

            Command currCommand = new Command(inOperation, inLeftOperand, inRightOperand, currEmptyCellMemory);
            commandStack.Push(currCommand);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Function converts stack with two-address instruction commands into pbStack with one-address instruction commands.
        /// </summary>
        /// <returns>Stack with one-address instruction commands.</returns>
        public Stack<Command> populateStack()
        {
            Stack<Command> returnVal = new Stack<Command>();
            Stack<Command> tempStack ;
            Command loadCommand;
            Command OperationCommand;
            Command SaveCommand;
            foreach (Command currCommand in CommandStack)
            {
                if (currCommand.leftOperand == null)
                {
                    if (currCommand.rightOperand == null)
                    {
                        // if Right points direct to value and Left operand stores in MemoryCell

                        // Save result to Memory Cell
                        // KOP  |MEM  |M{#}|
                        SaveCommand = new Command(CommandBase.commVals.Mem, currCommand.MemoryCellUsed);
                        returnVal.Push(SaveCommand);

                        // Load Right operand and Evaluate Operation
                        // KOP  |OP   |RO|
                        OperationCommand = new Command((CommandBase.commVals)currCommand.Code, currCommand.MemoryCellNeededExtra, true);
                        returnVal.Push(OperationCommand);

                        // Load left operand
                        // KOP  |LOAD |M{#}|
                        loadCommand = new Command(CommandBase.commVals.Load, currCommand.MemoryCellNeeded);
                        returnVal.Push(loadCommand);
                    }
                    else
                    {
                        // if Right points direct to value and Left operand stores in MemoryCell

                        // Save result to Memory Cell
                        // KOP  |MEM  |M{#}|
                        SaveCommand = new Command(CommandBase.commVals.Mem, currCommand.MemoryCellUsed);
                        returnVal.Push(SaveCommand);

                        // Load Right operand and Evaluate Operation
                        // KOP  |OP   |RO|
                        OperationCommand = new Command((CommandBase.commVals)currCommand.Code, currCommand.MemoryCellNeeded);
                        returnVal.Push(OperationCommand);

                        // Load left operand
                        // KOP  |LOAD |M{#}|
                        loadCommand = new Command(CommandBase.commVals.Load, currCommand.MemoryCellNeeded);
                        returnVal.Push(loadCommand);
                    }
                }
                else
                    if (currCommand.rightOperand == null)
                    {
                        // if Left points direct to value and Right operand stores in MemoryCell

                        // Save result to Memory Cell
                        // KOP  |MEM  |M{#}|
                        SaveCommand = new Command(CommandBase.commVals.Mem, currCommand.MemoryCellUsed);
                        returnVal.Push(SaveCommand);

                        // Load Right operand and Evaluate Operation
                        // KOP  |OP   |M{#}|
                        OperationCommand = new Command((CommandBase.commVals)currCommand.Code, currCommand.MemoryCellNeeded);
                        returnVal.Push(OperationCommand);

                        // Load left operand
                        // KOP  |LOAD |LO|
                        loadCommand = new Command(CommandBase.commVals.Load, currCommand.leftOperand);
                        returnVal.Push(loadCommand);
                    }
                    else
                    {
                        // if Left and Right Operands are points direct to their values.

                        // Save result to Memory Cell
                        // KOP  |MEM  |M{#}|
                        SaveCommand = new Command(CommandBase.commVals.Mem, currCommand.MemoryCellUsed);
                        returnVal.Push(SaveCommand);

                        // Load Right operand and Evaluate Operation
                        // KOP  |OP   |RO|
                        OperationCommand = new Command((CommandBase.commVals)currCommand.Code, currCommand.rightOperand);
                        returnVal.Push(OperationCommand);

                        // Load left operand
                        // KOP  |LOAD |LO|
                        loadCommand = new Command(CommandBase.commVals.Load, currCommand.leftOperand);
                        returnVal.Push(loadCommand);
                    }

            }// foreach
            //tempStack = new Stack<Command>(returnVal);
            //return tempStack;
            return returnVal;
        }