Annotation of 40BSD/cmd/pi/yyprint.c, revision 1.1.1.1

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

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.