148116Sbostic /*-
2*62223Sbostic * Copyright (c) 1980, 1993
3*62223Sbostic * The Regents of the University of California. All rights reserved.
448116Sbostic *
548116Sbostic * %sccs.include.redist.c%
622204Sdist */
7784Speter
814747Sthien #ifndef lint
9*62223Sbostic static char sccsid[] = "@(#)yyerror.c 8.1 (Berkeley) 06/06/93";
1048116Sbostic #endif /* not lint */
11784Speter
12784Speter #include "whoami.h"
13784Speter #include "0.h"
1414747Sthien #include "tree_ty.h" /* must be included for yy.h */
15784Speter #include "yy.h"
16784Speter
17784Speter /*
18784Speter * Yerror prints an error
19784Speter * message and then returns
20784Speter * NIL for the tree if needed.
21784Speter * The error is flagged on the
22784Speter * current line which is printed
23784Speter * if the listing is turned off.
24784Speter #ifdef PXP
25784Speter *
26784Speter * As is obvious from the fooling around
27784Speter * with fout below, the Pascal system should
28784Speter * be changed to use the new library "lS".
29784Speter #endif
30784Speter */
3114747Sthien /*VARARGS*/
yerror(s,a1,a2,a3,a4,a5)32784Speter yerror(s, a1, a2, a3, a4, a5)
33784Speter char *s;
3414747Sthien char *a1, *a2, *a3, *a4, *a5;
35784Speter {
36784Speter #ifdef PI
37784Speter char buf[256];
38784Speter #endif
3914747Sthien register int i;
40784Speter static yySerrs;
41784Speter #ifdef PXP
42784Speter int ofout;
43784Speter #endif
44784Speter
45784Speter if (errpfx == 'w' && opt('w') != 0) {
46784Speter errpfx = 'E';
47784Speter return;
48784Speter }
4927739Smckusick /* no continuations allowed here */
5027739Smckusick if (errpfx == ' ')
5127739Smckusick errpfx = 'E';
52784Speter #ifdef PXP
53784Speter flush();
54784Speter ofout = fout[0];
55784Speter fout[0] = errout;
56784Speter #endif
57784Speter yyResume = 0;
58784Speter #ifdef PI
5914747Sthien geterr((int) s, buf);
60784Speter s = buf;
61784Speter #endif
62784Speter yysync();
63784Speter pchr(errpfx);
64784Speter pchr(' ');
65784Speter for (i = 3; i < yyecol; i++)
66784Speter pchr('-');
67784Speter printf("^--- ");
68784Speter /*
69784Speter if (yyecol > 60)
70784Speter printf("\n\t");
71784Speter */
72784Speter printf(s, a1, a2, a3, a4, a5);
73784Speter pchr('\n');
74784Speter if (errpfx == 'E')
75784Speter #ifdef PI
763085Smckusic eflg = TRUE, codeoff();
77784Speter #endif
78784Speter #ifdef PXP
793085Smckusic eflg = TRUE;
80784Speter #endif
81784Speter errpfx = 'E';
82784Speter yySerrs++;
83784Speter if (yySerrs >= MAXSYNERR) {
84784Speter yySerrs = 0;
85784Speter yerror("Too many syntax errors - QUIT");
86784Speter pexit(ERRS);
87784Speter }
88784Speter #ifdef PXP
89784Speter flush();
90784Speter fout[0] = ofout;
91784Speter return (0);
92784Speter #endif
93784Speter }
94784Speter
95784Speter /*
96784Speter * A bracketing error message
97784Speter */
brerror(where,what)98784Speter brerror(where, what)
99784Speter int where;
100784Speter char *what;
101784Speter {
102784Speter
103784Speter if (where == 0) {
104784Speter line = yyeline;
105784Speter setpfx(' ');
10614747Sthien error("End matched %s on line %d", what, (char *) where);
107784Speter return;
108784Speter }
109784Speter if (where < 0)
110784Speter where = -where;
11114747Sthien yerror("Inserted keyword end matching %s on line %d", what, (char *) where);
112784Speter }
113