Contents    Page-10    Prev    Next    Page+10    Index   

Operator Precedence Parser


TOKEN expr ()
{ int done;
  TOKEN tok;
  done = 0;
  opstack = NULL;
  opndstack = NULL;
  while (done == 0)
   { tok = gettoken();
     if (EOFFLG == 0)
        switch (tok->tokentype)
         { case IDENTIFIERTOK: case NUMBERTOK:
             pushopnd (tok);   break;
           case DELIMITER:
             if (tok->whichval == LPARENTHESIS)
               pushop(tok);
             else if (tok->whichval
                        == RPARENTHESIS)
               { while (opstack->tokentype !=
                          DELIMITER)
                   reduceop();
                 popop(); }
             else done = 1;
             break;