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