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