1: /*
   2:  * Routines for producing error messages.
   3:  */
   4: 
   5: #include "itran.h"
   6: #include "token.h"
   7: #include "tree.h"
   8: #include "lex.h"
   9: 
  10: struct errmsg {
  11:    int  e_state;        /* parser state number */
  12:    char *e_mesg;        /* message text */
  13:    } errtab[] = {
  14: #include "synerr.h"
  15:     -1,  "syntax error"
  16:    };
  17: 
  18: /*
  19:  * yyerror produces syntax error messages.  tok is the offending token
  20:  *  (yychar), lval is yylval, and state is the parser's state.
  21:  *
  22:  * errtab is searched for the state, if it is found, the associated
  23:  *  message is produced; if the state isn't found, "syntax error"
  24:  *  is produced.
  25:  */
  26: yyerror(tok, lval, state)
  27: int tok, state;
  28: nodeptr lval;
  29:    {
  30:    register struct errmsg *p;
  31:    char *mapterm();
  32: 
  33:    if (*filep)
  34:       fprintf(stderr, "%s, ", *filep);
  35:    if (tok == EOFX)   /* special case end of file */
  36:       fprintf(stderr, "unexpected end of file\n");
  37:    else {
  38:       fprintf(stderr, "line %d: ", LINE(lval));
  39:       if (COL(lval))
  40:          fprintf(stderr, "\"%s\": ", mapterm(tok,lval));
  41:       for (p = errtab; p->e_state != state && p->e_state >= 0; p++) ;
  42:       fprintf(stderr, "%s\n", p->e_mesg);
  43:       }
  44:    fatalerrs++;
  45:    nocode++;
  46:    }
  47: /*
  48:  * err produces the error messages s1 and s2 (if non-null).  The
  49:  *  current line number is found in tline.
  50:  */
  51: err(s1, s2)
  52: char *s1, *s2;
  53:    {
  54:    if (*filep)
  55:       fprintf(stderr, "%s, ", *filep);
  56:    fprintf(stderr, "line %d: ", tline);
  57:    if (s2)
  58:       fprintf(stderr, "\"%s\": ", s2);
  59:    fprintf(stderr, "%s\n", s1);
  60:    fatalerrs++;
  61:    nocode++;
  62:    }
  63: 
  64: /*
  65:  * lerr produces the error message s and associates it with line l.
  66:  */
  67: lerr(l, s)
  68: int l;
  69: char *s;
  70:    {
  71:    if (*filep)
  72:       fprintf(stderr, "%s, ", *filep);
  73:    fprintf(stderr, "line %d: ", l);
  74:    fprintf(stderr, "%s\n", s);
  75:    fatalerrs++;
  76:    nocode++;
  77:    }
  78: 
  79: /*
  80:  * warn produces s1 and s2 (if non-null) as warning messages.  The current
  81:  *  line is in tline.
  82:  */
  83: warn(s1, s2)
  84: char *s1, *s2;
  85:    {
  86:    if (*filep)
  87:       fprintf(stderr, "%s, ", *filep);
  88:    fprintf(stderr, "line %d: ", tline);
  89:    if (s2)
  90:       fprintf(stderr, "\"%s\": ", s2);
  91:    fprintf(stderr, "%s\n", s1);
  92:    warnings++;
  93:    }
  94: 
  95: /*
  96:  * syserr is called for fatal errors.  The message s is produced and the
  97:  *  translator exits.
  98:  */
  99: syserr(s)
 100: char *s;
 101:    {
 102:    if (*filep)
 103:       fprintf(stderr, "%s, ", *filep);
 104:    fprintf(stderr, "line %d: %s\n", inline, s);
 105:    exit(1);
 106:    }
 107: 
 108: /*
 109:  * mapterm finds a printable string for the given token type
 110:  *  and value.
 111:  */
 112: char *mapterm(typ,val)
 113: int typ;
 114: nodeptr val;
 115:    {
 116:    register struct toktab *t;
 117:    register i;
 118: 
 119:    i = typ;
 120:    if (i == IDENT || i == INTLIT || i == REALLIT || i == STRINGLIT || i == CSETLIT)
 121:       return (STR0(val));
 122:    for (t = toktab; t->t_type != i; t++)
 123:       if (t->t_type == 0)
 124:          return ("???");
 125:    return (t->t_word);
 126:    }

Defined functions

lerr defined in line 67; used 5 times
mapterm defined in line 112; used 2 times
warn defined in line 83; used 1 times
yyerror defined in line 26; used 1 times

Defined variables

errtab defined in line 13; used 1 times
  • in line 41

Defined struct's

errmsg defined in line 10; used 2 times
  • in line 30(2)
Last modified: 1984-11-18
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 1084
Valid CSS Valid XHTML 1.0 Strict