|
|
1.1 root 1: /*
2: * Routines for producing error messages.
3: */
4:
5: #include "itran.h"
6: #include "token.h"
7: #include "tree.h"
8: #include "lex.h"
9:
10: struct errmsg {
11: int e_state; /* parser state number */
12: char *e_mesg; /* message text */
13: } errtab[] = {
14: /*
15: * Initialization of table that maps error states to messages.
16: */
17:
18: 1, "end of file expected",
19: 2, "global, record, or procedure declaration expected",
20: 9, "link list expected",
21: 11, "missing semicolon",
22: 14, "global, record, or procedure declaration expected",
23: 19, "missing record name",
24: 22, "invalid global declaration",
25: 23, "missing procedure name",
26: 24, "missing procedure name", /* ? */
27: 25, "missing link file name",
28: 26, "missing field list in record declaration",
29: 28, "missing end",
30: 29, "missing semicolon or operator",
31: 44, "invalid operand for unary operator",
32: 45, "invalid operand for unary operator",
33: 46, "invalid operand for unary operator",
34: 47, "invalid operand for unary operator",
35: 48, "invalid operand for unary operator",
36: 49, "invalid operand for unary operator",
37: 59, "invalid create expression",
38: 66, "invalid keyword construction",
39: 93, "invalid if control expression",
40: 94, "invalid case control expression",
41: 95, "invalid while control expression",
42: 96, "invalid until control expression",
43: 97, "invalid every control expression",
44: 98, "invalid repeat expression",
45: 101, "missing parameter list in procedure declaration",
46: 105, "invalid local declaration",
47: 106, "invalid initial expression",
48: 112, "invalid operand",
49: 113, "invalid operand",
50: 114, "invalid operand in assignment",
51: 115, "invalid operand in augmented assignment",
52: 116, "invalid operand in augmented assignment",
53: 117, "invalid operand in augmented assignment",
54: 118, "invalid operand in augmented assignment",
55: 119, "invalid to clause",
56: 149, "invalid operand in alternation",
57: 150, "invalid operand",
58: 165, "invalid operand",
59: 168, "invalid operand",
60: 173, "invalid operand",
61: 178, "invalid operand",
62: 179, "invalid operand",
63: 180, "invalid operand",
64: 183, "invalid reference or subscript", /* ? */
65: 184, "invalid field name",
66: 193, "missing right parenthesis", /* ? */
67: 194, "missing right brace",
68: 200, "missing right bracket", /* ? */
69: 201, "missing then",
70: 202, "missing of",
71: 207, "missing identifier",
72: 209, "missing right parenthesis",
73: 211, "missing end",
74: 212, "invalid declaration",
75: 213, "missing semicolon or operator",
76: 231, "missing right bracket",
77: 241, "missing right parenthesis", /* ? */
78: 242, "invalid then clause",
79: 243, "missing left brace",
80: 244, "invalid do clause",
81: 245, "invalid do clause",
82: 246, "invalid do clause",
83: 248, "invalid argument list",
84: 253, "invalid by clause",
85: 255, "invalid section",
86: 261, "missing right parenthesis",
87: 264, "missing right bracket",
88: 266, "invalid case clause",
89: 272, "missing right bracket or ampersand",
90: 273, "missing right brace",
91: 274, "missing right parenthesis",
92: 278, "invalid else clause",
93: 279, "missing right brace or semicolon",
94: 281, "missing colon",
95: 282, "missing colon or ampersand",
96: 288, "invalid case clause",
97: 289, "invalid default clause",
98: 290, "invalid case clause",
99: -1, "syntax error"
100: };
101:
102: /*
103: * yyerror produces syntax error messages. tok is the offending token
104: * (yychar), lval is yylval, and state is the parser's state.
105: *
106: * errtab is searched for the state, if it is found, the associated
107: * message is produced; if the state isn't found, "syntax error"
108: * is produced.
109: */
110: yyerror(tok, lval, state)
111: int tok, state;
112: nodeptr lval;
113: {
114: register struct errmsg *p;
115: char *mapterm();
116:
117: if (*filep)
118: fprintf(stderr, "%s, ", *filep);
119: if (tok == EOFX) /* special case end of file */
120: fprintf(stderr, "unexpected end of file\n");
121: else {
122: fprintf(stderr, "line %d: ", Line(lval));
123: if (Col(lval))
124: fprintf(stderr, "\"%s\": ", mapterm(tok,lval));
125: for (p = errtab; p->e_state != state && p->e_state >= 0; p++) ;
126: fprintf(stderr, "%s\n", p->e_mesg);
127: }
128: fatalerrs++;
129: nocode++;
130: }
131: /*
132: * err produces the error messages s1 and s2 (if nonnull). The
133: * current line number is found in tline.
134: */
135: err(s1, s2)
136: char *s1, *s2;
137: {
138: if (*filep)
139: fprintf(stderr, "%s, ", *filep);
140: fprintf(stderr, "line %d: ", tline);
141: if (s2)
142: fprintf(stderr, "\"%s\": ", s2);
143: fprintf(stderr, "%s\n", s1);
144: fatalerrs++;
145: nocode++;
146: }
147:
148: /*
149: * lerr produces the error message s and associates it with line l.
150: */
151: lerr(l, s)
152: int l;
153: char *s;
154: {
155: if (*filep)
156: fprintf(stderr, "%s, ", *filep);
157: fprintf(stderr, "line %d: ", l);
158: fprintf(stderr, "%s\n", s);
159: fatalerrs++;
160: nocode++;
161: }
162:
163: /*
164: * warn produces s1 and s2 (if nonnull) as warning messages. The current
165: * line is in tline.
166: */
167: warn(s1, s2)
168: char *s1, *s2;
169: {
170: if (*filep)
171: fprintf(stderr, "%s, ", *filep);
172: fprintf(stderr, "line %d: ", tline);
173: if (s2)
174: fprintf(stderr, "\"%s\": ", s2);
175: fprintf(stderr, "%s\n", s1);
176: warnings++;
177: }
178:
179: /*
180: * syserr is called for fatal errors. The message s is produced and the
181: * translator exits.
182: */
183: syserr(s)
184: char *s;
185: {
186: if (*filep)
187: fprintf(stderr, "%s, ", *filep);
188: fprintf(stderr, "line %d: %s\n", inline, s);
189: exit(ErrorExit);
190: }
191:
192: /*
193: * mapterm finds a printable string for the given token type
194: * and value.
195: */
196: char *mapterm(typ,val)
197: int typ;
198: nodeptr val;
199: {
200: register struct toktab *t;
201: register i;
202:
203: i = typ;
204: if (i == IDENT || i == INTLIT || i == REALLIT || i == STRINGLIT || i == CSETLIT)
205: return Str0(val);
206: for (t = toktab; t->t_type != i; t++)
207: if (t->t_type == 0)
208: return "???";
209: return (t->t_word);
210: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.