1: /*
2: * Copyright (c) 1980 Regents of the University of California.
3: * All rights reserved. The Berkeley software License Agreement
4: * specifies the terms and conditions for redistribution.
5: */
6:
7: #ifndef lint
8: static char sccsid[] = "@(#)yyprint.c 5.1 (Berkeley) 6/5/85";
9: #endif not lint
10:
11: #include "whoami.h"
12: #include "0.h"
13: #include "tree_ty.h" /* must be included for yy.h */
14: #include "yy.h"
15:
16: char *tokname();
17:
18: STATIC short bounce;
19:
20: /*
21: * Printing representation of a
22: * "character" - a lexical token
23: * not in a yytok structure.
24: * 'which' indicates which char * you want
25: * should always be called as "charname(...,0),charname(...,1)"
26: */
27: char *
28: charname(ch , which )
29: int ch;
30: int which;
31: {
32: struct yytok Ych;
33:
34: Ych.Yychar = ch;
35: Ych.Yylval = nullsem(ch);
36: return (tokname(&Ych , which ));
37: }
38:
39: /*
40: * Printing representation of a token
41: * 'which' as above.
42: */
43: char *
44: tokname(tp , which )
45: register struct yytok *tp;
46: int which;
47: {
48: register char *cp;
49: register struct kwtab *kp;
50: char *cp2;
51:
52: cp2 = "";
53: switch (tp->Yychar) {
54: case YCASELAB:
55: cp = "case-label";
56: break;
57: case YEOF:
58: cp = "end-of-file";
59: break;
60: case YILLCH:
61: cp = "illegal character";
62: break;
63: case 256:
64: /* error token */
65: cp = "error";
66: break;
67: case YID:
68: cp = "identifier";
69: break;
70: case YNUMB:
71: cp = "real number";
72: break;
73: case YINT:
74: case YBINT:
75: cp = "number";
76: break;
77: case YSTRING:
78: cp = (char *) tp->Yylval;
79: cp = cp == NIL || cp[1] == 0 ? "character" : "string";
80: break;
81: case YDOTDOT:
82: cp = "'..'";
83: break;
84: default:
85: if (tp->Yychar < 256) {
86: cp = "'x'\0'x'\0'x'\0'x'";
87: /*
88: * for four times reentrant code!
89: * used to be:
90: * if (bounce = ((bounce + 1) & 1))
91: * cp += 4;
92: */
93: bounce = ( bounce + 1 ) % 4;
94: cp += (4 * bounce); /* 'x'\0 is 4 chars */
95: cp[1] = tp->Yychar;
96: break;
97: }
98: for (kp = yykey; kp->kw_str != NIL && kp->kw_val != tp->Yychar; kp++)
99: continue;
100: cp = "keyword ";
101: cp2 = kp->kw_str;
102: }
103: return ( which ? cp2 : cp );
104: }
Defined functions
tokname
defined in line
43; used 27 times
- in line 16,
36
- in /usr/src/ucb/PORT/pascal/src/yy.h line
147
- in /usr/src/ucb/PORT/pascal/src/yyrecover.c line
215-216(2),
240-241(2),
409-410(2),
424-427(4),
444-445(2),
457-458(2),
551-552(2),
563-564(2),
639-640(2),
654-657(4)
Defined variables
sccsid
defined in line
8;
never used