PageRenderTime 34ms CodeModel.GetById 12ms RepoModel.GetById 0ms app.codeStats 0ms

/src/mosmlyac/error.c

https://github.com/bluegnu/mosml
C | 286 lines | 218 code | 67 blank | 1 comment | 10 complexity | 227710b08730106ddde36ddec93a8237 MD5 | raw file
Possible License(s): GPL-2.0
  1. /* routines for printing error messages */
  2. #include "defs.h"
  3. void fatal(char *msg)
  4. {
  5. fprintf(stderr, "%s: fatal - %s\n", myname, msg);
  6. done(2);
  7. }
  8. void no_space(void)
  9. {
  10. fprintf(stderr, "%s: fatal - out of space\n", myname);
  11. done(2);
  12. }
  13. void open_error(char *filename)
  14. {
  15. fprintf(stderr, "%s: fatal - cannot open \"%s\"\n", myname, filename);
  16. done(2);
  17. }
  18. void unexpected_EOF(void)
  19. {
  20. fprintf(stderr, "%s: error - line %d of \"%s\", unexpected end-of-file\n",
  21. myname, lineno, input_file_name);
  22. done(1);
  23. }
  24. void print_pos(char *st_line, char *st_cptr)
  25. {
  26. register char *s;
  27. if (st_line == 0) return;
  28. for (s = st_line; *s != '\n'; ++s)
  29. {
  30. if (isprint(*s) || *s == '\t')
  31. putc(*s, stderr);
  32. else
  33. putc('?', stderr);
  34. }
  35. putc('\n', stderr);
  36. for (s = st_line; s < st_cptr; ++s)
  37. {
  38. if (*s == '\t')
  39. putc('\t', stderr);
  40. else
  41. putc(' ', stderr);
  42. }
  43. putc('^', stderr);
  44. putc('\n', stderr);
  45. }
  46. void syntax_error(int st_lineno, char *st_line, char *st_cptr)
  47. {
  48. fprintf(stderr, "%s: error - line %d of \"%s\", syntax error\n",
  49. myname, st_lineno, input_file_name);
  50. print_pos(st_line, st_cptr);
  51. done(1);
  52. }
  53. void unterminated_comment(int c_lineno, char *c_line, char *c_cptr)
  54. {
  55. fprintf(stderr, "%s: error - line %d of \"%s\", unmatched (*\n",
  56. myname, c_lineno, input_file_name);
  57. print_pos(c_line, c_cptr);
  58. done(1);
  59. }
  60. void unterminated_string(int s_lineno, char *s_line, char *s_cptr)
  61. {
  62. fprintf(stderr, "%s: error - line %d of \"%s\", unterminated string\n",
  63. myname, s_lineno, input_file_name);
  64. print_pos(s_line, s_cptr);
  65. done(1);
  66. }
  67. void unterminated_text(int t_lineno, char *t_line, char *t_cptr)
  68. {
  69. fprintf(stderr, "%s: error - line %d of \"%s\", unmatched %%{\n",
  70. myname, t_lineno, input_file_name);
  71. print_pos(t_line, t_cptr);
  72. done(1);
  73. }
  74. void unterminated_union(int u_lineno, char *u_line, char *u_cptr)
  75. {
  76. fprintf(stderr, "%s: error - line %d of \"%s\", unterminated %%union \
  77. declaration\n", myname, u_lineno, input_file_name);
  78. print_pos(u_line, u_cptr);
  79. done(1);
  80. }
  81. void over_unionized(char *u_cptr)
  82. {
  83. fprintf(stderr, "%s: error - line %d of \"%s\", too many %%union \
  84. declarations\n", myname, lineno, input_file_name);
  85. print_pos(line, u_cptr);
  86. done(1);
  87. }
  88. void illegal_tag(int t_lineno, char *t_line, char *t_cptr)
  89. {
  90. fprintf(stderr, "%s: error - line %d of \"%s\", illegal tag\n",
  91. myname, t_lineno, input_file_name);
  92. print_pos(t_line, t_cptr);
  93. done(1);
  94. }
  95. void illegal_character(char *c_cptr)
  96. {
  97. fprintf(stderr, "%s: error - line %d of \"%s\", illegal character\n",
  98. myname, lineno, input_file_name);
  99. print_pos(line, c_cptr);
  100. done(1);
  101. }
  102. void used_reserved(char *s)
  103. {
  104. fprintf(stderr, "%s: error - line %d of \"%s\", illegal use of reserved symbol \
  105. %s\n", myname, lineno, input_file_name, s);
  106. done(1);
  107. }
  108. void tokenized_start(char *s)
  109. {
  110. fprintf(stderr, "%s: error - line %d of \"%s\", the start symbol %s cannot be \
  111. declared to be a token\n", myname, lineno, input_file_name, s);
  112. done(1);
  113. }
  114. void retyped_warning(char *s)
  115. {
  116. fprintf(stderr, "%s: warning - line %d of \"%s\", the type of %s has been \
  117. redeclared\n", myname, lineno, input_file_name, s);
  118. }
  119. void reprec_warning(char *s)
  120. {
  121. fprintf(stderr, "%s: warning - line %d of \"%s\", the precedence of %s has been \
  122. redeclared\n", myname, lineno, input_file_name, s);
  123. }
  124. void revalued_warning(char *s)
  125. {
  126. fprintf(stderr, "%s: warning - line %d of \"%s\", the value of %s has been \
  127. redeclared\n", myname, lineno, input_file_name, s);
  128. }
  129. void terminal_start(char *s)
  130. {
  131. fprintf(stderr, "%s: error - line %d of \"%s\", the entry point %s is a \
  132. token\n", myname, lineno, input_file_name, s);
  133. done(1);
  134. }
  135. void too_many_entries(void)
  136. {
  137. fprintf(stderr, "%s: error - line %d of \"%s\", more than 256 entry points\n",
  138. myname, lineno, input_file_name);
  139. done(1);
  140. }
  141. void no_grammar(void)
  142. {
  143. fprintf(stderr, "%s: error - line %d of \"%s\", no grammar has been \
  144. specified\n", myname, lineno, input_file_name);
  145. done(1);
  146. }
  147. void terminal_lhs(int s_lineno)
  148. {
  149. fprintf(stderr, "%s: error - line %d of \"%s\", a token appears on the lhs \
  150. of a production\n", myname, s_lineno, input_file_name);
  151. done(1);
  152. }
  153. void prec_redeclared(void)
  154. {
  155. fprintf(stderr, "%s: warning - line %d of \"%s\", conflicting %%prec \
  156. specifiers\n", myname, lineno, input_file_name);
  157. }
  158. void unterminated_action(int a_lineno, char *a_line, char *a_cptr)
  159. {
  160. fprintf(stderr, "%s: error - line %d of \"%s\", unterminated action\n",
  161. myname, a_lineno, input_file_name);
  162. print_pos(a_line, a_cptr);
  163. done(1);
  164. }
  165. void dollar_warning(int a_lineno, int i)
  166. {
  167. fprintf(stderr, "%s: warning - line %d of \"%s\", $%d references beyond the \
  168. end of the current rule\n", myname, a_lineno, input_file_name, i);
  169. }
  170. void dollar_error(int a_lineno, char *a_line, char *a_cptr)
  171. {
  172. fprintf(stderr, "%s: error - line %d of \"%s\", illegal $-name\n",
  173. myname, a_lineno, input_file_name);
  174. print_pos(a_line, a_cptr);
  175. done(1);
  176. }
  177. void untyped_lhs(void)
  178. {
  179. fprintf(stderr, "%s: error - line %d of \"%s\", $$ is untyped\n",
  180. myname, lineno, input_file_name);
  181. done(1);
  182. }
  183. void untyped_rhs(int i, char *s)
  184. {
  185. fprintf(stderr, "%s: error - line %d of \"%s\", $%d (%s) is untyped\n",
  186. myname, lineno, input_file_name, i, s);
  187. done(1);
  188. }
  189. void unknown_rhs(int i)
  190. {
  191. fprintf(stderr, "%s: error - line %d of \"%s\", $%d is unbound\n",
  192. myname, lineno, input_file_name, i);
  193. done(1);
  194. }
  195. void illegal_token_ref(int i, char *name)
  196. {
  197. fprintf(stderr, "%s: error - line %d of \"%s\", $%d refers to terminal `%s', which has no argument\n",
  198. myname, lineno, input_file_name, i, name);
  199. done(1);
  200. }
  201. void default_action_warning(void)
  202. {
  203. fprintf(stderr, "%s: warning - line %d of \"%s\", the default action assigns an \
  204. undefined value to $$\n", myname, lineno, input_file_name);
  205. }
  206. void undefined_goal(char *s)
  207. {
  208. fprintf(stderr, "%s: error - the start symbol %s is undefined\n", myname, s);
  209. done(1);
  210. }
  211. void undefined_symbol_warning(char *s)
  212. {
  213. fprintf(stderr, "%s: warning - the symbol %s is undefined\n", myname, s);
  214. }
  215. void missing_type(char *s)
  216. {
  217. fprintf(stderr, "%s: error - the symbol '%s' has no %%type declaration\n", myname, s);
  218. done(1);
  219. }