home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 11 Util / 11-Util.zip / OS2_LEX.ZIP / LEXSWI.C < prev    next >
C/C++ Source or Header  |  1989-10-25  |  913b  |  55 lines

  1. /*
  2.  * lexswitch -- switch lex tables
  3.  */
  4.  
  5. /*
  6.  * Bob Denny     28-Aug-82  Remove reference to stdio.h
  7.  * Scott Guthery 20-Nov-83    Adapt for IBM PC & DeSmet C
  8.  */
  9.  
  10. #include <lex.h>
  11. #include <stdlib.h>
  12.  
  13. extern struct lextab *_tabp;
  14.  
  15. typedef struct stack {
  16.     struct stack  *next;
  17.     struct lextab *table;
  18.     } STACK;
  19.  
  20. static STACK *lextop = NULL;
  21.  
  22. struct lextab *lexswitch(struct lextab *lp)
  23. {
  24.         register struct lextab *olp;
  25.  
  26.         olp = _tabp;
  27.         _tabp = lp;
  28.         return(olp);
  29. }
  30.  
  31. void lexpush(struct lextab *lp)
  32. {
  33.         STACK *sp;
  34.  
  35.         sp = (STACK *) malloc(sizeof(STACK));
  36.         sp->next = lextop;
  37.         sp->table = lexswitch(lp);
  38.         lextop = sp;
  39. }
  40.  
  41. void lexpop(void)
  42. {
  43.     STACK *sp;
  44.  
  45.     if (lextop != NULL)
  46.         {
  47.         sp = lextop;
  48.         lextop = sp->next;
  49.         lexswitch(sp->table);
  50.         free(sp);
  51.         }
  52.  
  53. }
  54.  
  55.