コード例 #1
0
 //optional field, but good to have
 public PrgState(StackInterface<IStmt> stack, MapInterface<String, int> dictionary, HeapInterface<int> heap, ListInterface<int> list, IStmt prg)
 {
     id = generator++;
     exeStack = stack;
     symTable = dictionary;
     heapTable = heap;
     output = list;
     originalProgram = prg;
     exeStack.Push (originalProgram);
 }
コード例 #2
0
        //optional field, but good to have

        public PrgState(StackInterface <IStmt> stack, MapInterface <String, int> dictionary, HeapInterface <int> heap, ListInterface <int> list, IStmt prg)
        {
            id              = generator++;
            exeStack        = stack;
            symTable        = dictionary;
            heapTable       = heap;
            output          = list;
            originalProgram = prg;
            exeStack.Push(originalProgram);
        }
コード例 #3
0
ファイル: Calc.cs プロジェクト: Gosed/HomeWorks
 public Calc()
 {
     stack = new ListStack();  //I don't know what is wrong
     //stack = new ArrayStack();
 }
コード例 #4
0
ファイル: Program.cs プロジェクト: GalinaSazonova/2semester
        /// <summary>
        /// Calculating exression written in postfix
        /// </summary>
        /// <param name="stack"></param>
        /// <param name="line"></param>
        /// <returns></returns>
        public static int Calculator(StackInterface stack, string line)
        {
            int mainResult = 0;

            for (int i = 0; i != line.Length; i++)
            {
                char symbol = line[i];
                if (symbol != '-' && symbol != '*' && symbol != '/' && symbol != '+' && symbol != ' ')
                {
                    stack.Push(Convert.ToInt16(symbol) - 48);
                }
                else
                {
                    switch (symbol)
                    {
                    case '+':
                    {
                        int result = 0;
                        result += stack.Pop();
                        result += stack.Pop();
                        stack.Push(result);
                        break;
                    }

                    case '-':
                    {
                        int result = 0;
                        result -= stack.Pop();
                        result += stack.Pop();
                        stack.Push(result);
                        break;
                    }

                    case '*':
                    {
                        int result = 1;
                        result *= stack.Pop();
                        result *= stack.Pop();
                        stack.Push(result);
                        break;
                    }

                    case '/':
                    {
                        int tempor = stack.Pop();
                        if (tempor != 0)
                        {
                            int result = 0;
                            result = stack.Pop() / tempor;
                            stack.Push(result);
                            break;
                        }
                        else
                        {
                            throw new DivideByZeroException();
                        }
                    }

                    default:
                    {
                        continue;
                    }
                    }
                }
            }
            if (mainResult != -99999)
            {
                mainResult = stack.Pop();
                return(mainResult);
            }
            else
            {
                return(mainResult);
            }
        }
コード例 #5
0
ファイル: Program.cs プロジェクト: GalinaSazonova/2semester
 /// <summary>
 /// Calculating exression written in postfix
 /// </summary>
 /// <param name="stack"></param>
 /// <param name="line"></param>
 /// <returns></returns>
 public static int Calculator(StackInterface stack, string line)
 {
     int mainResult = 0;
     for (int i = 0; i != line.Length; i++)
     {
         char symbol = line[i];
         if (symbol != '-' && symbol != '*' && symbol != '/' && symbol != '+' && symbol != ' ')
         {
             stack.Push(Convert.ToInt16(symbol) - 48);
         }
         else switch (symbol)
             {
                 case '+':
                     {
                         int result = 0;
                         result += stack.Pop();
                         result += stack.Pop();
                         stack.Push(result);
                         break;
                     }
                 case '-':
                     {
                         int result = 0;
                         result -= stack.Pop();
                         result += stack.Pop();
                         stack.Push(result);
                         break;
                     }
                 case '*':
                     {
                         int result = 1;
                         result *= stack.Pop();
                         result *= stack.Pop();
                         stack.Push(result);
                         break;
                     }
                 case '/':
                     {
                         int tempor = stack.Pop();
                         if (tempor != 0)
                         {
                             int result = 0;
                             result = stack.Pop() / tempor;
                             stack.Push(result);
                             break;
                         }
                         else
                         {
                             throw new DivideByZeroException();
                         }
                     }
                 default:
                     {
                         continue;
                     }
             }
     }
     if (mainResult != -99999)
     {
         mainResult = stack.Pop();
         return mainResult;
     }
     else
     {
         return mainResult;
     }
 }