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