Написание калькулятора с разбором выражений, страница 6

    char* Calculate (long double *NUM)

    {

      int prt = 0xFF;

      bool LastPrior = false;

      int PriorityLevel = 0, LFP = 0;

      while (FTC_Position < FTC_Length)

      {

        if (isprior (FTC[FTC_Position]))

        {

          if (IsSign () && LastPrior == true)

          { /* PUSHING NUMBER */

            PUSH_Number ();

            LastPrior = false;

          }

          PriorityLevel = GetLastPriority ();

          PriorityLevel -= PriorityLevel % 100;

          LFP = SetPriority (FTC[FTC_Position]);

          LFP -= LFP % 100 - RisePriority;

          if (LFP <= PriorityLevel)

            do/* DO BEGIN CALCULATIONS HERE */

            {

              PriorityLevel = GetLastPriority ();

              PriorityLevel -= PriorityLevel % 100;

              LFP = LookForPriority ();

              LFP -= LFP % 100;

              prt = POP_Priority ();

              CalcBuf (prt);

            }while (PriorityLevel == LFP &&

                    GetLastPriority () % 100 == LookForPriority () % 100);

          else

          {  

            if (IsSign ()) // THIS IS NOT USABLE FOR INTERNAL FUNCTIONS IN THIS FILE

              LastPrior = true;

            PUSH_Priority ();

          }

        }

        else

        { /* PUSHING NUMBER */

          PUSH_Number ();

          LastPrior = false;

        }

      }

      while (PriorityBuf.TOP () > 0)

      { /* ALL THE OTHER CALCULATIONS */

        prt = POP_Priority ();

        CalcBuf (prt);

      }

      POP_Number (NUM);

      return NULL;

    }

    /* END OF 'Calculate' FUNCTION */

  /* END OF AVAILABLE FUNCTIONS DEFINITION */

/********************************************************************

                  END OF PUBLIC MEMBERS DEFINITIONS

********************************************************************/

};

/* END OF 'ICalc' CLASS DEFINITION */

#endif

/********************************************************************

*  Copyright (C) 2004 - 2005

*  Hizov Software

*  Falling Anvil GRP Support Group

********************************************************************/

/********************************************************************

* FILE NAME           : STACK.H

* PURPOSE             : STACK DEFINITION

* PROGRAMMER          : MIHAIL A. HIZOV

* LAST UPDATE         : 13.10.2005 23:38

* VERSION             : 2.2

* FILE SIZE           : 3938 Bytes

* TOTAL PROGECT SIZE  :    -

* NOTE                : NO MODULE PREFIX DEFINED

*                       MAIN CLASS IS 'STACK'

*

* No part of this file may be changed without agreement of

* Mihail A. Hizov Personally

********************************************************************/

#ifndef _stack_h_

#define _stack_h_

#include <stdlib.h>

/* DEFINITION OF 'STACK' CLASS

   AVAILABLE METHODS ARE:

   1 - PUSH ELEMENT METHOD (void PUSH (TYPE)

   2 - POP ELEMENT METHOD (TYPE POP (void)

   3 - PREVIOUS ELEMENT (TYPE PrevElem (void))*/

template <typename TYPE>

class STACK

{

  private:

    int ElemetsQuantity;                        /* QUANTITY OF ALLOCATED ELEMENTHS */

    /* STACK LIST STRUCTURE DEFINITION */

    struct __stack_list__

    {

      TYPE Var;                                 /* VARIABLE */

      struct __stack_list__ *PointerToNext;     /* POINTER TO NEXT ELEMENT */