Annotation of researchv9/cmd/sun/mip/yyerror.c, revision 1.1.1.1

1.1       root        1: #ifndef lint
                      2: static char sccsid[] = "@(#)yyerror.c 1.1 86/02/03 Copyr 1984 Sun Micro";
                      3: #endif
                      4: 
                      5: /*
                      6:  * Copyright (c) 1984 by Sun Microsystems, Inc.
                      7:  */
                      8: 
                      9: #include "cpass1.h"
                     10: #include <ctype.h>
                     11: 
                     12: /*
                     13:  * printnames for yacc tokens
                     14:  */
                     15: 
                     16: extern int tokebufptr;
                     17: extern char tokebufr[];
                     18: #define MAXTOKELENGTH 20 /* don't care past here */
                     19: 
                     20: struct pname {
                     21:     int           pval;
                     22:     char * name;
                     23:     enum { NOPRINT, VALPRINT, FVALPRINT, NAMEPRINT, STRINGPRINT,
                     24:           ASGPRINT,RELPRINT, EQLPRINT, DIVPRINT, INCRPRINT, UNIPRINT,
                     25:           STRPRINT,SHIFTPRINT, TYPEPRINT, CLASSPRINT, STRUCTPRINT,
                     26:           WORDPRINT, SYMPRINT } howprint;
                     27: } pname[] = {
                     28:     0,         "<nothing>",NOPRINT,
                     29:     ERROR,     "<nothing>",NOPRINT,
                     30:     NAME,      "<name>",       NAMEPRINT,
                     31:     STRING,    "<string>",     STRINGPRINT,
                     32:     ICON,      "<constant>",VALPRINT,
                     33:     FCON,      "<fconstant>", FVALPRINT,
                     34:     PLUS,      "+",    SYMPRINT,
                     35:     ASG PLUS,  "+=",   SYMPRINT,
                     36:     MINUS,     "-",    SYMPRINT,
                     37:     ASG MINUS, "-=",   SYMPRINT,
                     38:     UNARY MINUS,"-",   SYMPRINT,
                     39:     MUL,       "*",    SYMPRINT,
                     40:     ASG MUL,   "*=",   SYMPRINT,
                     41:     UNARY MUL, "*",    SYMPRINT,
                     42:     AND,       "&",    SYMPRINT,
                     43:     ASG AND,   "&=",   SYMPRINT,
                     44:     UNARY AND, "&",    SYMPRINT,
                     45:     OR,                "|",    SYMPRINT,
                     46:     ASG OR,    "|=",   SYMPRINT,
                     47:     ER,                "^",    SYMPRINT,
                     48:     ASG ER,    "^=",   SYMPRINT,
                     49:     QUEST,     "?",    SYMPRINT,
                     50:     COLON,     ":",    SYMPRINT,
                     51:     ANDAND,    "&&",   SYMPRINT,
                     52:     OROR,      "||",   SYMPRINT,
                     53:     25,                "=op",  ASGPRINT,
                     54:     26,                "relop",RELPRINT,
                     55:     27,                "==",   EQLPRINT,
                     56:     28,                "/",    DIVPRINT,
                     57:     29,                "<<",   SYMPRINT,
                     58:     30,                "++",   INCRPRINT,
                     59:     31,                "!",    UNIPRINT,
                     60:     32,                "->",   STRPRINT,
                     61:     TYPE,      "type", TYPEPRINT,
                     62:     CLASS,     "extern",CLASSPRINT,
                     63:     STRUCT,    "struct",STRUCTPRINT,
                     64:     RETURN,    "return",WORDPRINT,
                     65:     GOTO,      "goto", WORDPRINT,
                     66:     IF,                "if",   WORDPRINT,
                     67:     ELSE,      "else", WORDPRINT,
                     68:     SWITCH,    "switch",WORDPRINT,
                     69:     BREAK,     "break",WORDPRINT,
                     70:     CONTINUE,  "continue",WORDPRINT,
                     71:     WHILE,     "while",WORDPRINT,
                     72:     DO,                "do",   WORDPRINT,
                     73:     FOR,       "for",  WORDPRINT,
                     74:     DEFAULT,   "default",WORDPRINT,
                     75:     CASE,      "case", WORDPRINT,
                     76:     SIZEOF,    "sizeof",WORDPRINT,
                     77:     ENUM,      "enum", WORDPRINT,
                     78:     LP,                "(",    SYMPRINT,
                     79:     RP,                ")",    SYMPRINT,
                     80:     LC,                "{",    SYMPRINT,
                     81:     RC,                "}",    SYMPRINT,
                     82:     LB,                "[",    SYMPRINT,
                     83:     RB,                "]",    SYMPRINT,
                     84:     CM,                ",",    SYMPRINT,
                     85:     SM,                ";",    SYMPRINT,
                     86:     ASSIGN,    "=",    SYMPRINT,
                     87:     ASM,       "asm",  WORDPRINT,
                     88:     0,         0,      NOPRINT,
                     89: };
                     90: 
                     91: static struct pname *
                     92: plookup( n ) 
                     93:     register n;
                     94: {
                     95:     register struct pname *p;
                     96:     p = pname;
                     97:     while ( p->name != 0 ){
                     98:        if ( p->pval == n ) return p;
                     99:        p++;
                    100:     }
                    101:     return 0;
                    102: }
                    103: 
                    104: ccerror( s, c ) char *s; int c;
                    105: { /* error printing routine in parser */
                    106:     static char mungbuffer[300];
                    107:     static char word[] = "word", symbol[] = "symbol";
                    108:     char *printname;
                    109:     char *noun;
                    110:     char *q = "\"";
                    111:     struct pname *p;
                    112:     extern char yytext[];
                    113:     int i,mt;
                    114:     char token[MAXTOKELENGTH+10], *thischar;
                    115: 
                    116:     p = plookup( c );
                    117:     if (p == 0 || p->howprint==NOPRINT){
                    118:        uerror( s );
                    119:     } else {
                    120:        printname = p->name;
                    121:        switch(p->howprint){
                    122:        case WORDPRINT:
                    123:            noun = word;
                    124:            break;
                    125:        case TYPEPRINT:
                    126:            /* this is hard */
                    127:            noun = "type word";
                    128:            printname = yytext;
                    129:            break;
                    130:        case CLASSPRINT:
                    131:            noun = word;
                    132:            switch(yylval.intval){
                    133:            case AUTO:
                    134:                printname = "auto"; break;
                    135:            case EXTERN:
                    136:                printname = "extern"; break;
                    137:            case FORTRAN:
                    138:                printname = "fortran"; break;
                    139:            case REGISTER:
                    140:                printname = "register"; break;
                    141:            case STATIC:
                    142:                printname = "static"; break;
                    143:            case TYPEDEF:
                    144:                printname = "typedef"; break;
                    145:            }
                    146:            break;
                    147:        case STRUCTPRINT:
                    148:            noun = word;
                    149:            if (yylval.intval==INUNION)
                    150:                printname = "union";
                    151:            break;
                    152:        case SYMPRINT:
                    153:            noun = symbol;
                    154:            q = "";
                    155:            break;
                    156:        case RELPRINT:
                    157:            noun = symbol;
                    158:            q = "";
                    159:            switch ( yylval.intval ){
                    160:            case LS: printname = "<"; break;
                    161:            case LE: printname = "<="; break;
                    162:            case GT: printname = ">"; break;
                    163:            case GE: printname = ">="; break;
                    164:            }
                    165:            break;
                    166:        case EQLPRINT:
                    167:            noun = symbol;
                    168:            q = "";
                    169:            if ( yylval.intval == NE )
                    170:                printname = "!=";
                    171:            break;
                    172:        case DIVPRINT:
                    173:            noun = symbol;
                    174:            q = "";
                    175:            if ( yylval.intval == MOD )
                    176:                printname = "%";
                    177:            break;
                    178:        case SHIFTPRINT:
                    179:            noun = symbol;
                    180:            q = "";
                    181:            if ( yylval.intval == RS)
                    182:                printname = ">>" ;
                    183:            break;
                    184:        case INCRPRINT:
                    185:            noun = symbol;
                    186:            q = "";
                    187:            if ( yylval.intval == DECR )
                    188:                printname = "--";
                    189:            break;
                    190:        case UNIPRINT:
                    191:            noun = symbol;
                    192:            q = "";
                    193:            if ( yylval.intval == COMPL )
                    194:                printname = "~";
                    195:            break;
                    196:        case STRPRINT:
                    197:            noun = symbol;
                    198:            q = "";
                    199:            if ( yylval.intval == DOT )
                    200:                printname = ".";
                    201:            break;
                    202:        case ASGPRINT:
                    203:            noun = symbol;
                    204:            q = "";
                    205:            switch ( yylval.intval ){
                    206:            case ASG PLUS: printname = "+="; break;
                    207:            case ASG MINUS: printname = "-="; break;
                    208:            case ASG MUL: printname = "*="; break;
                    209:            case ASG DIV: printname = "/="; break;
                    210:            case ASG MOD: printname = "%="; break;
                    211:            case ASG AND: printname = "&="; break;
                    212:            case ASG OR: printname = "|="; break;
                    213:            case ASG ER: printname = "^="; break;
                    214:            case ASG LS: printname = "<<="; break;
                    215:            case ASG RS: printname = ">>="; break;
                    216:            }
                    217:            break;
                    218:        case NAMEPRINT:
                    219:            noun = "variable name";
                    220:            printname = yytext;
                    221:            break;
                    222:        case STRINGPRINT:
                    223:            noun = "string";
                    224:            goto gettoken;
                    225:        case VALPRINT:
                    226:        case FVALPRINT:
                    227:            noun = "constant";
                    228:        gettoken:
                    229:            thischar = tokebufr;
                    230:            q = "";
                    231:            if (tokebufptr >= MAXTOKELENGTH)
                    232:                mt = MAXTOKELENGTH;
                    233:            else
                    234:                mt = tokebufptr;
                    235:            for (i=0; i<=mt; i++){
                    236:                if (isascii(*thischar) && isprint(*thischar))
                    237:                    token[i] = *thischar;
                    238:                else
                    239:                    token[i] = '?';
                    240:                thischar ++;
                    241:            }
                    242:            token[i] = '\0';
                    243:            if (mt < tokebufptr)
                    244:                strcat( token, "...");
                    245:            printname = token;
                    246:            break;
                    247:        default:
                    248:            noun = "";
                    249:            break;
                    250:        }
                    251:        sprintf( mungbuffer, "%s at or near %s %s%s%s", s, noun, q, printname, q);
                    252:        uerror( "%s", mungbuffer );
                    253:     }
                    254: }

unix.superglobalmegacorp.com

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