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