error.c 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335
  1. /*
  2. * Copyright (c) 1989 The Regents of the University of California.
  3. * All rights reserved.
  4. *
  5. * This code is derived from software contributed to Berkeley by
  6. * Robert Paul Corbett.
  7. *
  8. * Redistribution and use in source and binary forms, with or without
  9. * modification, are permitted provided that the following conditions
  10. * are met:
  11. * 1. Redistributions of source code must retain the above copyright
  12. * notice, this list of conditions and the following disclaimer.
  13. * 2. Redistributions in binary form must reproduce the above copyright
  14. * notice, this list of conditions and the following disclaimer in the
  15. * documentation and/or other materials provided with the distribution.
  16. * 3. All advertising materials mentioning features or use of this software
  17. * must display the following acknowledgement:
  18. * This product includes software developed by the University of
  19. * California, Berkeley and its contributors.
  20. * 4. Neither the name of the University nor the names of its contributors
  21. * may be used to endorse or promote products derived from this software
  22. * without specific prior written permission.
  23. *
  24. * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
  25. * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  26. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  27. * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
  28. * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  29. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  30. * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  31. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  32. * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  33. * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  34. * SUCH DAMAGE.
  35. */
  36. #ifndef lint
  37. static char sccsid[] = "@(#)error.c 5.3 (Berkeley) 6/1/90";
  38. #endif /* not lint */
  39. /* routines for printing error messages */
  40. #include "defs.h"
  41. fatal(msg)
  42. char *msg;
  43. {
  44. fprintf(stderr, "%s: f - %s\n", myname, msg);
  45. done(2);
  46. }
  47. no_space()
  48. {
  49. fprintf(stderr, "%s: f - out of space\n", myname);
  50. done(2);
  51. }
  52. open_error(filename)
  53. char *filename;
  54. {
  55. fprintf(stderr, "%s: f - cannot open \"%s\"\n", myname, filename);
  56. done(2);
  57. }
  58. unexpected_EOF()
  59. {
  60. fprintf(stderr, "%s: e - line %d of \"%s\", unexpected end-of-file\n",
  61. myname, lineno, input_file_name);
  62. done(1);
  63. }
  64. print_pos(st_line, st_cptr)
  65. char *st_line;
  66. char *st_cptr;
  67. {
  68. register char *s;
  69. if (st_line == 0) return;
  70. for (s = st_line; *s != '\n'; ++s)
  71. {
  72. if (isprint(*s) || *s == '\t')
  73. putc(*s, stderr);
  74. else
  75. putc('?', stderr);
  76. }
  77. putc('\n', stderr);
  78. for (s = st_line; s < st_cptr; ++s)
  79. {
  80. if (*s == '\t')
  81. putc('\t', stderr);
  82. else
  83. putc(' ', stderr);
  84. }
  85. putc('^', stderr);
  86. putc('\n', stderr);
  87. }
  88. syntax_error(st_lineno, st_line, st_cptr)
  89. int st_lineno;
  90. char *st_line;
  91. char *st_cptr;
  92. {
  93. fprintf(stderr, "%s: e - line %d of \"%s\", syntax error\n",
  94. myname, st_lineno, input_file_name);
  95. print_pos(st_line, st_cptr);
  96. done(1);
  97. }
  98. unterminated_comment(c_lineno, c_line, c_cptr)
  99. int c_lineno;
  100. char *c_line;
  101. char *c_cptr;
  102. {
  103. fprintf(stderr, "%s: e - line %d of \"%s\", unmatched /*\n",
  104. myname, c_lineno, input_file_name);
  105. print_pos(c_line, c_cptr);
  106. done(1);
  107. }
  108. unterminated_string(s_lineno, s_line, s_cptr)
  109. int s_lineno;
  110. char *s_line;
  111. char *s_cptr;
  112. {
  113. fprintf(stderr, "%s: e - line %d of \"%s\", unterminated string\n",
  114. myname, s_lineno, input_file_name);
  115. print_pos(s_line, s_cptr);
  116. done(1);
  117. }
  118. unterminated_text(t_lineno, t_line, t_cptr)
  119. int t_lineno;
  120. char *t_line;
  121. char *t_cptr;
  122. {
  123. fprintf(stderr, "%s: e - line %d of \"%s\", unmatched %%{\n",
  124. myname, t_lineno, input_file_name);
  125. print_pos(t_line, t_cptr);
  126. done(1);
  127. }
  128. illegal_tag(t_lineno, t_line, t_cptr)
  129. int t_lineno;
  130. char *t_line;
  131. char *t_cptr;
  132. {
  133. fprintf(stderr, "%s: e - line %d of \"%s\", illegal tag\n",
  134. myname, t_lineno, input_file_name);
  135. print_pos(t_line, t_cptr);
  136. done(1);
  137. }
  138. illegal_character(c_cptr)
  139. char *c_cptr;
  140. {
  141. fprintf(stderr, "%s: e - line %d of \"%s\", illegal character\n",
  142. myname, lineno, input_file_name);
  143. print_pos(line, c_cptr);
  144. done(1);
  145. }
  146. used_reserved(s)
  147. char *s;
  148. {
  149. fprintf(stderr, "%s: e - line %d of \"%s\", illegal use of reserved symbol \
  150. %s\n", myname, lineno, input_file_name, s);
  151. done(1);
  152. }
  153. tokenized_start(s)
  154. char *s;
  155. {
  156. fprintf(stderr, "%s: e - line %d of \"%s\", the start symbol %s cannot be \
  157. declared to be a token\n", myname, lineno, input_file_name, s);
  158. done(1);
  159. }
  160. retyped_warning(s)
  161. char *s;
  162. {
  163. fprintf(stderr, "%s: w - line %d of \"%s\", the type of %s has been \
  164. redeclared\n", myname, lineno, input_file_name, s);
  165. }
  166. reprec_warning(s)
  167. char *s;
  168. {
  169. fprintf(stderr, "%s: w - line %d of \"%s\", the precedence of %s has been \
  170. redeclared\n", myname, lineno, input_file_name, s);
  171. }
  172. revalued_warning(s)
  173. char *s;
  174. {
  175. fprintf(stderr, "%s: w - line %d of \"%s\", the value of %s has been \
  176. redeclared\n", myname, lineno, input_file_name, s);
  177. }
  178. terminal_start(s)
  179. char *s;
  180. {
  181. fprintf(stderr, "%s: e - line %d of \"%s\", the start symbol %s is a \
  182. token\n", myname, lineno, input_file_name, s);
  183. done(1);
  184. }
  185. restarted_warning()
  186. {
  187. fprintf(stderr, "%s: w - line %d of \"%s\", the start symbol has been \
  188. redeclared\n", myname, lineno, input_file_name);
  189. }
  190. no_grammar()
  191. {
  192. fprintf(stderr, "%s: e - line %d of \"%s\", no grammar has been \
  193. specified\n", myname, lineno, input_file_name);
  194. done(1);
  195. }
  196. terminal_lhs(s_lineno)
  197. int s_lineno;
  198. {
  199. fprintf(stderr, "%s: e - line %d of \"%s\", a token appears on the lhs \
  200. of a production\n", myname, s_lineno, input_file_name);
  201. done(1);
  202. }
  203. prec_redeclared()
  204. {
  205. fprintf(stderr, "%s: w - line %d of \"%s\", conflicting %%prec \
  206. specifiers\n", myname, lineno, input_file_name);
  207. }
  208. unterminated_action(a_lineno, a_line, a_cptr)
  209. int a_lineno;
  210. char *a_line;
  211. char *a_cptr;
  212. {
  213. fprintf(stderr, "%s: e - line %d of \"%s\", unterminated action\n",
  214. myname, a_lineno, input_file_name);
  215. print_pos(a_line, a_cptr);
  216. done(1);
  217. }
  218. dollar_warning(a_lineno, i)
  219. int a_lineno;
  220. int i;
  221. {
  222. fprintf(stderr, "%s: w - line %d of \"%s\", $%d references beyond the \
  223. end of the current rule\n", myname, a_lineno, input_file_name, i);
  224. }
  225. dollar_error(a_lineno, a_line, a_cptr)
  226. int a_lineno;
  227. char *a_line;
  228. char *a_cptr;
  229. {
  230. fprintf(stderr, "%s: e - line %d of \"%s\", illegal $-name\n",
  231. myname, a_lineno, input_file_name);
  232. print_pos(a_line, a_cptr);
  233. done(1);
  234. }
  235. untyped_lhs()
  236. {
  237. fprintf(stderr, "%s: w - line %d of \"%s\", $$ is untyped\n",
  238. myname, lineno, input_file_name);
  239. /** done(1); */
  240. }
  241. untyped_rhs(i, s)
  242. int i;
  243. char *s;
  244. {
  245. fprintf(stderr, "%s: w - line %d of \"%s\", $%d (%s) is untyped\n",
  246. myname, lineno, input_file_name, i, s);
  247. /** done(1); */
  248. }
  249. unknown_rhs(i)
  250. int i;
  251. {
  252. fprintf(stderr, "%s: e - line %d of \"%s\", $%d is untyped\n",
  253. myname, lineno, input_file_name, i);
  254. done(1);
  255. }
  256. default_action_warning()
  257. {
  258. fprintf(stderr, "%s: w - line %d of \"%s\", the default action assigns an \
  259. undefined value to $$\n", myname, lineno, input_file_name);
  260. }
  261. undefined_goal(s)
  262. char *s;
  263. {
  264. fprintf(stderr, "%s: e - the start symbol %s is undefined\n", myname, s);
  265. done(1);
  266. }
  267. undefined_symbol_warning(s)
  268. char *s;
  269. {
  270. fprintf(stderr, "%s: w - the symbol %s is undefined\n", myname, s);
  271. }