Contents    Page-10    Prev    Next    Page+10    Index   

Basic Routines


TOKEN opstack, opndstack;

    /*                +  -  *  /  ... */
int opprec[20] = { 0, 6, 6, 7, 7, ...};

void pushop (TOKEN tok)      /* push op onto stack */
  {  tok->link = opstack;
     opstack = tok;  }

TOKEN popop ()               /* pop op from stack */
  { TOKEN tok;
    tok = opstack;
    opstack = tok->link;
    return(tok);   }

int prec (TOKEN tok)        /* precedence of op tok */
  { if (tok == NULL)
       return(-1);          /* -1 for empty stack */
       else if (tok->tokentype == OPERATOR)
          return(opprec[tok->whichval]);
          else return(-1);  }  /* -1 for ( */