home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 11 Util / 11-Util.zip / OS2_LEX.ZIP / OUT2.C < prev    next >
C/C++ Source or Header  |  1989-10-07  |  4KB  |  126 lines

  1. /*
  2.  * out2.c  --     Some of Lex's output routines for overlaying, moved
  3.  *                here from the original out.c as part of size reduction
  4.  *                effort.
  5.  *      Bob Denny
  6.  *      03-Dec-80
  7.  * More...
  8.  *      Bob Denny
  9.  *      29-May-81       RSX overlaying
  10.  *      19-Mar-82 Bob Denny -- New compiler and library
  11.  *      28-Aug-82 Bob Denny -- Change output format for readability. I know
  12.  *                              you UNIX hackers are not going to like this
  13.  *                              one.  Add code to generate llstin() per
  14.  *                              setting of "-s" switch.  Fix cclprint() to
  15.  *                              put 16 "characters" on a line. Clean up
  16.  *                              nfaprint().
  17.  *      29-Aug-82 Bob Denny -- Move chprint to root. Add llstin() to
  18.  *                              default lexin to stdin for standard I/O
  19.  *                              and no-op for stand-alone I/O.  Allows
  20.  *                              sdtio-specific code to be removed from
  21.  *                              yylex().
  22.  *      31-Aug-82 Bob Denny -- Add lexswitch( ...) to llstin so table
  23.  *                              name selected by -t switch is automatically
  24.  *                              switched-to at yylex() startup time.  Removed
  25.  *                              hard reference to "lextab" from yylex();
  26.  *      30-Oct-82 Bob Denny -- Remove lexswitch() from llstin(). Made it
  27.  *                              impossible to do a real lexswitch()! (dumb.)
  28.  *                              Default the table by statically initializing
  29.  *                              it to NULL and doing the lexswitch only if
  30.  *                              _tabp is NULL.
  31.  *        20-Nov-83 Scott Guthery -- Adapt for IBM PC & DeSmet C
  32.  */
  33.  
  34. #include <stdio.h>
  35. #include "lexlex.h"
  36. #include "lextern.h"
  37.  
  38. extern int yyline;
  39.  
  40. void cclprint(char *);
  41.  
  42. #ifdef DEBUG
  43.  
  44. void nfaprint(struct nfa *np, struct nfa *base)
  45. {
  46.         register i;
  47.  
  48.         if (np->n_flag&NPRT)
  49.                 return;
  50.         np->n_flag |= NPRT;
  51.         fprintf(lexlog, "state %d\n", np-base);
  52.         switch (np->n_char) {
  53.         case EPSILON:
  54.                 for (i = 0; i < 2; i++)
  55.                         if (np->n_succ[i])
  56.                                 fprintf(lexlog, "\tepsilon  %d\n", np->n_succ[i]-base);
  57.                 break;
  58.         case FIN:
  59.                 fprintf(lexlog, "\tfinal state\n");
  60.                 break;
  61.         case CCL:
  62.                 fprintf(lexlog, "\t[");
  63.                 cclprint(np->n_ccl);
  64.                 fprintf(lexlog, "]  %d\n", np->n_succ[0]-base);
  65.                 break;
  66.         default:
  67.                 putc('\t', lexlog);
  68.                 chprint(np->n_char);
  69.                 fprintf(lexlog, "  %d\n", np->n_succ[0]-base);
  70.                 break;
  71.         }
  72.         putc('\n', lexlog);
  73.         if (np->n_succ[0])
  74.                 nfaprint(np->n_succ[0], base);
  75.         if (np->n_succ[1])
  76.                 nfaprint(np->n_succ[1], base);
  77. }
  78.  
  79. void cclprint(char *cp)
  80. {
  81.         register i;
  82.         register nc;
  83.  
  84.         nc = 0;
  85.         for (i = 0; i < NCHARS; i++)
  86.                 {
  87.                 if (cp[i / NBPC] & (1 << (i % NBPC)))
  88.                         nc += chprint(i);
  89.                 if(nc >= 64)
  90.                         {
  91.                         nc = 0;
  92.                         fprintf(lexlog, "\n\t ");
  93.                         }
  94.                 }
  95. }
  96.  
  97. #endif
  98.  
  99. void llactr(void)
  100. {
  101.         /*
  102.          * Prior to generating the action routine, create
  103.          * the llstin() routine, which initializes yylex(),
  104.          * per the setting of the "-s" switch.  All hardwired
  105.          * variables have now been removed from yylex(). This
  106.          * allows analyzers to be independent of the standard
  107.          * I/O library and the table name.
  108.          */
  109.         fprintf(llout, "_A%s(__na__)\t\t/* Action routine */\n   {\n", tabname);
  110. }
  111.  
  112. void newcase(int i)
  113. {
  114.         static int putsw;
  115.  
  116.         if (!putsw++)
  117.                 fprintf(llout, "   switch (__na__)\n      {\n");
  118.         fprintf(llout, "\n      case %d:\n", i);
  119.         setline();
  120. }
  121.  
  122. void setline(void)
  123. {
  124.         fprintf(llout, "\n#line %d\n", yyline);
  125. }
  126.