home *** CD-ROM | disk | FTP | other *** search
/ Microsoft Programmer's Library 1.3 / Microsoft-Programers-Library-v1.3.iso / sampcode / alde_c / misc / util / lex / out2.c < prev    next >
Encoding:
C/C++ Source or Header  |  1980-01-01  |  4.1 KB  |  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.  
  37. extern int yyline;
  38.  
  39. #ifdef DEBUG
  40.  
  41. nfaprint(np, base)
  42. register struct nfa *np;
  43. struct nfa *base;
  44. {
  45.         register i;
  46.  
  47.         if (np->n_flag&NPRT)
  48.                 return;
  49.         np->n_flag |= NPRT;
  50.         fprintf(lexlog, "state %d\n", np-base);
  51.         switch (np->n_char) {
  52.         case EPSILON:
  53.                 for (i = 0; i < 2; i++)
  54.                         if (np->n_succ[i])
  55.                                 fprintf(lexlog, "\tepsilon  %d\n", np->n_succ[i]-base);
  56.                 break;
  57.         case FIN:
  58.                 fprintf(lexlog, "\tfinal state\n");
  59.                 break;
  60.         case CCL:
  61.                 fprintf(lexlog, "\t[");
  62.                 cclprint(np->n_ccl);
  63.                 fprintf(lexlog, "]  %d\n", np->n_succ[0]-base);
  64.  
  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. cclprint(cp)
  80. register char *cp;
  81. {
  82.         register i;
  83.         register nc;
  84.  
  85.         nc = 0;
  86.         for (i = 0; i < NCHARS; i++)
  87.                 {
  88.                 if (cp[i / NBPC] & (1 << (i % NBPC)))
  89.                         nc += chprint(i);
  90.                 if(nc >= 64)
  91.                         {
  92.                         nc = 0;
  93.                         fprintf(lexlog, "\n\t ");
  94.                         }
  95.                 }
  96. }
  97.  
  98. #endif
  99.  
  100. llactr()
  101. {
  102.         /*
  103.          * Prior to generating the action routine, create
  104.          * the llstin() routine, which initializes yylex(),
  105.          * per the setting of the "-s" switch.  All hardwired
  106.          * variables have now been removed from yylex(). This
  107.          * allows analyzers to be independent of the standard
  108.          * I/O library and the table name.
  109.          */
  110.         fprintf(llout, "_A%s(__na__)\t\t/* Action routine */\n   {\n", tabname);
  111. }
  112.  
  113.  
  114. newcase(i)
  115. {
  116.         static int putsw;
  117.  
  118.         if (!putsw++)
  119.                 fprintf(llout, "   switch (__na__)\n      {\n");
  120.         fprintf(llout, "\n      case %d:\n", i);
  121.         setline();
  122. }
  123.  
  124. setline()
  125. {
  126.         fprintf(llout, "\n#line %d\n", yyline);
  127. }
  128.