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

Defined functions

charname defined in line 32; used 15 times
tokname defined in line 48; used 27 times
Last modified: 1981-07-10
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 1756
Valid CSS Valid XHTML 1.0 Strict