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