home *** CD-ROM | disk | FTP | other *** search
/ minnie.tuhs.org / unixen.tar / unixen / PDP-11 / Distributions / ucb / spencer_2bsd.tar.gz / 2bsd.tar / src / pi0 / yyprint.c < prev    next >
C/C++ Source or Header  |  1980-02-17  |  2KB  |  98 lines

  1. /* Copyright (c) 1979 Regents of the University of California */
  2. #
  3. /*
  4.  * pi - Pascal interpreter code translator
  5.  *
  6.  * Charles Haley, Bill Joy UCB
  7.  * Version 1.2 January 1979
  8.  *
  9.  *
  10.  * pxp - Pascal execution profiler
  11.  *
  12.  * Bill Joy UCB
  13.  * Version 1.2 January 1979
  14.  */
  15.  
  16. #include "0.h"
  17. #include "yy.h"
  18.  
  19. long    tokname();
  20.  
  21. STATIC    char bounce;
  22.  
  23. /*
  24.  * Printing representation of a
  25.  * "character" - a lexical token
  26.  * not in a yytok structure.
  27.  */
  28. long
  29. charname(ch)
  30.     int ch;
  31. {
  32.     struct yytok Ych;
  33.  
  34.     Ych.Yychar = ch;
  35.     Ych.Yylval = nullsem(ch);
  36.     return (tokname(&Ych));
  37. }
  38.  
  39. /*
  40.  * Printing representation of a token
  41.  */
  42. long
  43. tokname(tp)
  44.     register struct yytok *tp;
  45. {
  46.     register char *cp;
  47.     register struct kwtab *kp;
  48.     long l;
  49.  
  50.     (&l)->pint2 = "";
  51.     switch (tp->Yychar) {
  52.         case YCASELAB:
  53.             cp = "case-label";
  54.             break;
  55.         case YEOF:
  56.             cp = "end-of-file";
  57.             break;
  58.         case YILLCH:
  59.             cp = "illegal character";
  60.             break;
  61.         case 256:
  62.             /* error token */
  63.             cp = "error";
  64.             break;
  65.         case YID:
  66.             cp = "identifier";
  67.             break;
  68.         case YNUMB:
  69.             cp = "real number";
  70.             break;
  71.         case YINT:
  72.         case YBINT:
  73.             cp = "number";
  74.             break;
  75.         case YSTRING:
  76.             cp = tp->Yylval;
  77.             cp = cp == NIL || cp[1] == 0 ? "character" : "string";
  78.             break;
  79.         case YDOTDOT:
  80.             cp = "'..'";
  81.             break;
  82.         default:
  83.             if (tp->Yychar < 256) {
  84.                 cp = "'x'\0'x'";
  85.                 if (bounce = ((bounce + 1) & 1))
  86.                     cp =+ 4;
  87.                 cp[1] = tp->Yychar;
  88.                 break;
  89.             }
  90.             for (kp = yykey; kp->kw_str != NIL && kp->kw_val != tp->Yychar; kp++)
  91.                 continue;
  92.             cp = "keyword ";
  93.             (&l)->pint2 = kp->kw_str;
  94.     }
  95.     (&l)->pint = cp;
  96.     return (l);
  97. }
  98.