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[] = "@(#)yyerror.c 5.1 (Berkeley) 06/05/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 /* 17 * Yerror prints an error 18 * message and then returns 19 * NIL for the tree if needed. 20 * The error is flagged on the 21 * current line which is printed 22 * if the listing is turned off. 23 #ifdef PXP 24 * 25 * As is obvious from the fooling around 26 * with fout below, the Pascal system should 27 * be changed to use the new library "lS". 28 #endif 29 */ 30 /*VARARGS*/ 31 yerror(s, a1, a2, a3, a4, a5) 32 char *s; 33 char *a1, *a2, *a3, *a4, *a5; 34 { 35 #ifdef PI 36 char buf[256]; 37 #endif 38 register int i; 39 static yySerrs; 40 #ifdef PXP 41 int ofout; 42 #endif 43 44 if (errpfx == 'w' && opt('w') != 0) { 45 errpfx = 'E'; 46 return; 47 } 48 #ifdef PXP 49 flush(); 50 ofout = fout[0]; 51 fout[0] = errout; 52 #endif 53 yyResume = 0; 54 #ifdef PI 55 geterr((int) s, buf); 56 s = buf; 57 #endif 58 yysync(); 59 pchr(errpfx); 60 pchr(' '); 61 for (i = 3; i < yyecol; i++) 62 pchr('-'); 63 printf("^--- "); 64 /* 65 if (yyecol > 60) 66 printf("\n\t"); 67 */ 68 printf(s, a1, a2, a3, a4, a5); 69 pchr('\n'); 70 if (errpfx == 'E') 71 #ifdef PI 72 eflg = TRUE, codeoff(); 73 #endif 74 #ifdef PXP 75 eflg = TRUE; 76 #endif 77 errpfx = 'E'; 78 yySerrs++; 79 if (yySerrs >= MAXSYNERR) { 80 yySerrs = 0; 81 yerror("Too many syntax errors - QUIT"); 82 pexit(ERRS); 83 } 84 #ifdef PXP 85 flush(); 86 fout[0] = ofout; 87 return (0); 88 #endif 89 } 90 91 /* 92 * A bracketing error message 93 */ 94 brerror(where, what) 95 int where; 96 char *what; 97 { 98 99 if (where == 0) { 100 line = yyeline; 101 setpfx(' '); 102 error("End matched %s on line %d", what, (char *) where); 103 return; 104 } 105 if (where < 0) 106 where = -where; 107 yerror("Inserted keyword end matching %s on line %d", what, (char *) where); 108 } 109