|
|
1.1 root 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.1 February 1978
8: *
9: *
10: * pxp - Pascal execution profiler
11: *
12: * Bill Joy UCB
13: * Version 1.1 February 1978
14: */
15:
16: #include "0.h"
17: #include "yy.h"
18:
19: char *tokname();
20:
21: int bounce;
22:
23: /*
24: * Printing representation of a
25: * "character" - a lexical token
26: * not in a yytok structure.
27: * 'which' indicates which char * you want
28: * should always be called as "charname(...,0),charname(...,1)"
29: */
30: char *
31: charname(ch , which )
32: int ch;
33: int which;
34: {
35: struct yytok Ych;
36:
37: Ych.Yychar = ch;
38: Ych.Yylval = nullsem(ch);
39: return (tokname(&Ych , which ));
40: }
41:
42: /*
43: * Printing representation of a token
44: * 'which' as above.
45: */
46: char *
47: tokname(tp , which )
48: register struct yytok *tp;
49: int which;
50: {
51: register char *cp;
52: register struct kwtab *kp;
53: char *cp2;
54:
55: cp2 = "";
56: switch (tp->Yychar) {
57: case YCASELAB:
58: cp = "case-label";
59: break;
60: case YEOF:
61: cp = "end-of-file";
62: break;
63: case YILLCH:
64: cp = "illegal character";
65: break;
66: case 256:
67: /* error token */
68: cp = "error";
69: break;
70: case YID:
71: cp = "identifier";
72: break;
73: case YNUMB:
74: cp = "real number";
75: break;
76: case YINT:
77: case YBINT:
78: cp = "number";
79: break;
80: case YSTRING:
81: cp = tp->Yylval;
82: cp = cp == NIL || cp[1] == 0 ? "character" : "string";
83: break;
84: case YDOTDOT:
85: cp = "'..'";
86: break;
87: default:
88: if (tp->Yychar < 256) {
89: cp = "'x'\0'x'";
90: /*
91: * for twice reentrant code!
92: * used to be:
93: * if (bounce = ((bounce + 1) & 1))
94: * cp += 4;
95: * now: don't bounce unless 0th call
96: */
97: if ( which == 0 )
98: bounce = ((bounce + 1) & 1);
99: if (bounce)
100: cp =+ 4;
101: cp[1] = tp->Yychar;
102: break;
103: }
104: for (kp = yykey; kp->kw_str != NIL && kp->kw_val != tp->Yychar; kp++)
105: continue;
106: cp = "keyword ";
107: cp2 = kp->kw_str;
108: }
109: return ( which ? cp2 : cp );
110: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.