home *** CD-ROM | disk | FTP | other *** search
/ The C Users' Group Library 1994 August / wc-cdrom-cusersgrouplibrary-1994-08.iso / vol_100 / 172_01 / outb.c < prev    next >
Text File  |  1979-12-31  |  4KB  |  121 lines

  1. /*
  2.   HEADER:              CUG  nnn.nn;
  3.   TITLE:               LEX - A Lexical Analyser Generator
  4.   VERSION:             1.1 for IBM-PC
  5.   DATE:                Jan 30, 1985
  6.   DESCRIPTION:         A Lexical Analyser Generator. From UNIX
  7.   KEYWORDS:            Lexical Analyser Generator YACC C PREP
  8.   SYSTEM:              IBM-PC and Compatiables
  9.   FILENAME:            OUTB.C
  10.   WARNINGS:            This program is not for the casual user. It will
  11.                        be useful primarily to expert developers.
  12.   CRC:                 N/A
  13.   SEE-ALSO:            YACC and PREP
  14.   AUTHORS:             Charles H. Forsyth
  15.                        Scott Guthery 11100 leafwood lane Austin, TX 78750
  16.                        Andrew M. Ward, Jr.  Houston, Texas (Modifications)
  17.   COMPILERS:           LATTICE C
  18.   REFERENCES:          UNIX Systems Manuals -- Lex Manual on distribution disks
  19. */
  20. /*
  21.  * Copyright (c) 1978 Charles H. Forsyth
  22.  */
  23.  
  24. #include <stdio.h>
  25. #include "lexlex.h"
  26.  
  27. extern int yyline;
  28. extern FILE *llout;
  29. extern void newcase(int);
  30. extern void llactr(void);
  31. extern void cclprint(char *);
  32. extern void setline(void);
  33.  
  34. void nfaprint(np, base)
  35. struct nfa *np;
  36. struct nfa *base;
  37. {
  38.         int i;
  39.  
  40.         if (np->n_flag&NPRT)
  41.                 return;
  42.         np->n_flag |= NPRT;
  43.         fprintf(stdout, "state %d\n", np-base);
  44.         switch (np->n_char) {
  45.         case EPSILON:
  46.                 for (i = 0; i < 2; i++)
  47.                         if (np->n_succ[i])
  48.                                 fprintf(stdout, "\tepsilon  %d\n", np->n_succ[i] );
  49.                 break;
  50.         case FIN:
  51.                 fprintf(stdout, "\tfinal state\n");
  52.                 break;
  53.         case CCL:
  54.                 fprintf(stdout, "\t[");
  55.                 cclprint(np->n_ccl);
  56.                 fprintf(stdout, "]  %d\n", np->n_succ[0]-base);
  57.  
  58.                 break;
  59.         default:
  60.                 putc('\t', stdout);
  61.                 chprint(np->n_char);
  62.                 fprintf(stdout, "  %d\n", np->n_succ[0]-base);
  63.                 break;
  64.         }
  65.         putc('\n', stdout);
  66.         if (np->n_succ[0])
  67.                 nfaprint(np->n_succ[0], base);
  68.         if (np->n_succ[1])
  69.                 nfaprint(np->n_succ[1], base);
  70. }
  71.  
  72. void cclprint(cp)
  73. char *cp;
  74. {
  75.         int i;
  76.         int nc;
  77.  
  78.         nc = 0;
  79.         for (i = 0; i < NCHARS; i++)
  80.                 {
  81.                 if (cp[i / NBPC] & (1 << (i % NBPC)))
  82.                         nc += chprint(i);
  83.                 if(nc >= 64)
  84.                         {
  85.                         nc = 0;
  86.                         fprintf(stdout, "\n\t ");
  87.                         }
  88.                 }
  89. }
  90.  
  91.  
  92. void llactr()
  93. {
  94.         /*
  95.          * Prior to generating the action routine, create
  96.          * the llstin() routine, which initializes yylex(),
  97.          * per the setting of the "-s" switch.  All hardwired
  98.          * variables have now been removed from yylex(). This
  99.          * allows analyzers to be independent of the standard
  100.          * I/O library and the table name.
  101.          */
  102.         fprintf(llout, "int _A%s(__na__)\t\t/* Action routine */\n\tint __na__;\n{\n", tabname);
  103. }
  104.  
  105.  
  106. void newcase(i)
  107. int i;
  108. {
  109.         static int putsw;
  110.  
  111.         if (!putsw++)
  112.                 fprintf(llout, "   switch (__na__)\n      {\n");
  113.         fprintf(llout, "\n      case %d:\n", i);
  114.         setline();
  115. }
  116.  
  117. void setline()
  118. {
  119.         fprintf(llout, "\n#line %d\n", yyline);
  120. }
  121.