home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 22 gnu / 22-gnu.zip / BYACC.ZIP / ERROR.C < prev    next >
C/C++ Source or Header  |  1992-03-18  |  6KB  |  275 lines

  1. /* routines for printing error messages  */
  2. #include <stdlib.h>
  3.  
  4. #include "byacc.h"
  5.  
  6. void fatal(char *msg)
  7. {
  8.     fprintf(stderr, "%s: f - %s\n", myname, msg);
  9.     done(2);
  10. }
  11.  
  12.  
  13. void no_space(void)
  14. {
  15.     fprintf(stderr, "%s: f - out of space\n", myname);
  16.     abort();
  17.     done(2);
  18. }
  19.  
  20.  
  21. void open_error(char *filename)
  22. {
  23.     fprintf(stderr, "%s: f - cannot open \"%s\"\n", myname, filename);
  24.     done(2);
  25. }
  26.  
  27.  
  28. void unexpected_EOF(void)
  29. {
  30.     fprintf(stderr, "%s: e - line %d of \"%s\", unexpected end-of-file\n",
  31.         myname, lineno, input_file_name);
  32.     done(1);
  33. }
  34.  
  35.  
  36. void print_pos(char *st_line, char *st_cptr)
  37. {
  38.     register char *s;
  39.  
  40.     if (st_line == 0) return;
  41.     for (s = st_line; *s != '\n'; ++s)
  42.     {
  43.     if (isprint(*s) || *s == '\t')
  44.         putc(*s, stderr);
  45.     else
  46.         putc('?', stderr);
  47.     }
  48.     putc('\n', stderr);
  49.     for (s = st_line; s < st_cptr; ++s)
  50.     {
  51.     if (*s == '\t')
  52.         putc('\t', stderr);
  53.     else
  54.         putc(' ', stderr);
  55.     }
  56.     putc('^', stderr);
  57.     putc('\n', stderr);
  58. }
  59.  
  60.  
  61. void syntax_error(int st_lineno, char *st_line, char *st_cptr)
  62. {
  63.     fprintf(stderr, "%s: e - line %d of \"%s\", syntax error\n",
  64.         myname, st_lineno, input_file_name);
  65.     print_pos(st_line, st_cptr);
  66.     exit(1);
  67. }
  68.  
  69.  
  70. void unterminated_comment(int c_lineno, char * c_line, char * c_cptr)
  71. {
  72.     fprintf(stderr, "%s: e - line %d of \"%s\", unmatched /*\n",
  73.         myname, c_lineno, input_file_name);
  74.     print_pos(c_line, c_cptr);
  75.     done(1);
  76. }
  77.  
  78.  
  79. void unterminated_string(int s_lineno, char * s_line, char * s_cptr)
  80. {
  81.     fprintf(stderr, "%s: e - line %d of \"%s\", unterminated string\n",
  82.         myname, s_lineno, input_file_name);
  83.     print_pos(s_line, s_cptr);
  84.     done(1);
  85. }
  86.  
  87.  
  88. void unterminated_text(int t_lineno, char * t_line, char * t_cptr)
  89. {
  90.     fprintf(stderr, "%s: e - line %d of \"%s\", unmatched %%{\n",
  91.         myname, t_lineno, input_file_name);
  92.     print_pos(t_line, t_cptr);
  93.     done(1);
  94. }
  95.  
  96.  
  97. void unterminated_union(int u_lineno, char * u_line, char * u_cptr)
  98. {
  99.     fprintf(stderr, "%s: e - line %d of \"%s\", unterminated %%union \
  100. declaration\n", myname, u_lineno, input_file_name);
  101.     print_pos(u_line, u_cptr);
  102.     done(1);
  103. }
  104.  
  105.  
  106. void over_unionized(char * u_cptr)
  107. {
  108.     fprintf(stderr, "%s: e - line %d of \"%s\", too many %%union \
  109. declarations\n", myname, lineno, input_file_name);
  110.     print_pos(line, u_cptr);
  111.     done(1);
  112. }
  113.  
  114.  
  115. void illegal_tag(int t_lineno, char * t_line, char * t_cptr)
  116. {
  117.     fprintf(stderr, "%s: e - line %d of \"%s\", illegal tag\n",
  118.         myname, t_lineno, input_file_name);
  119.     print_pos(t_line, t_cptr);
  120.     done(1);
  121. }
  122.  
  123.  
  124. void illegal_character(char * c_cptr)
  125. {
  126.     fprintf(stderr, "%s: e - line %d of \"%s\", illegal character\n",
  127.         myname, lineno, input_file_name);
  128.     print_pos(line, c_cptr);
  129.     done(1);
  130. }
  131.  
  132.  
  133. void used_reserved(char * s)
  134. {
  135.     fprintf(stderr, "%s: e - line %d of \"%s\", illegal use of reserved symbol \
  136. %s\n", myname, lineno, input_file_name, s);
  137.     done(1);
  138. }
  139.  
  140.  
  141. void tokenized_start(char * s)
  142. {
  143.      fprintf(stderr, "%s: e - line %d of \"%s\", the start symbol %s cannot be \
  144. declared to be a token\n", myname, lineno, input_file_name, s);
  145.      done(1);
  146. }
  147.  
  148.  
  149. void retyped_warning(char * s)
  150. {
  151.     fprintf(stderr, "%s: w - line %d of \"%s\", the type of %s has been \
  152. redeclared\n", myname, lineno, input_file_name, s);
  153. }
  154.  
  155.  
  156. void reprec_warning(char * s)
  157. {
  158.     fprintf(stderr, "%s: w - line %d of \"%s\", the precedence of %s has been \
  159. redeclared\n", myname, lineno, input_file_name, s);
  160. }
  161.  
  162.  
  163. void revalued_warning(char *s)
  164. {
  165.     fprintf(stderr, "%s: w - line %d of \"%s\", the value of %s has been \
  166. redeclared\n", myname, lineno, input_file_name, s);
  167. }
  168.  
  169.  
  170. void terminal_start(char *s)
  171. {
  172.     fprintf(stderr, "%s: e - line %d of \"%s\", the start symbol %s is a \
  173. token\n", myname, lineno, input_file_name, s);
  174.     done(1);
  175. }
  176.  
  177.  
  178. void restarted_warning(void)
  179. {
  180.     fprintf(stderr, "%s: w - line %d of \"%s\", the start symbol has been \
  181. redeclared\n", myname, lineno, input_file_name);
  182. }
  183.  
  184.  
  185. void no_grammar(void)
  186. {
  187.     fprintf(stderr, "%s: e - line %d of \"%s\", no grammar has been \
  188. specified\n", myname, lineno, input_file_name);
  189.     done(1);
  190. }
  191.  
  192.  
  193. void terminal_lhs(int s_lineno)
  194. {
  195.     fprintf(stderr, "%s: e - line %d of \"%s\", a token appears on the lhs \
  196. of a production\n", myname, s_lineno, input_file_name);
  197.     done(1);
  198. }
  199.  
  200.  
  201. void prec_redeclared(void )
  202. {
  203.     fprintf(stderr, "%s: w - line %d of  \"%s\", conflicting %%prec \
  204. specifiers\n", myname, lineno, input_file_name);
  205. }
  206.  
  207.  
  208. void unterminated_action(int a_lineno, char * a_line, char * a_cptr)
  209. {
  210.     fprintf(stderr, "%s: e - line %d of \"%s\", unterminated action\n",
  211.         myname, a_lineno, input_file_name);
  212.     print_pos(a_line, a_cptr);
  213.     done(1);
  214. }
  215.  
  216.  
  217. void dollar_warning(int a_lineno, int i)
  218. {
  219.     fprintf(stderr, "%s: w - line %d of \"%s\", $%d references beyond the \
  220. end of the current rule\n", myname, a_lineno, input_file_name, i);
  221. }
  222.  
  223.  
  224. void dollar_error(int a_lineno, char * a_line, char * a_cptr)
  225. {
  226.     fprintf(stderr, "%s: e - line %d of \"%s\", illegal $-name\n",
  227.         myname, a_lineno, input_file_name);
  228.     print_pos(a_line, a_cptr);
  229.     done(1);
  230. }
  231.  
  232.  
  233. void untyped_lhs(void)
  234. {
  235.     fprintf(stderr, "%s: e - line %d of \"%s\", $$ is untyped\n",
  236.         myname, lineno, input_file_name);
  237.     done(1);
  238. }
  239.  
  240.  
  241. void untyped_rhs(int i, char *s)
  242. {
  243.     fprintf(stderr, "%s: e - line %d of \"%s\", $%d (%s) is untyped\n",
  244.         myname, lineno, input_file_name, i, s);
  245.     done(1);
  246. }
  247.  
  248.  
  249. void unknown_rhs(int i)
  250. {
  251.     fprintf(stderr, "%s: e - line %d of \"%s\", $%d is untyped\n",
  252.         myname, lineno, input_file_name, i);
  253.     done(1);
  254. }
  255.  
  256.  
  257. void default_action_warning(void)
  258. {
  259.     fprintf(stderr, "%s: w - line %d of \"%s\", the default action assigns an \
  260. undefined value to $$\n", myname, lineno, input_file_name);
  261. }
  262.  
  263.  
  264. void undefined_goal(char *s)
  265. {
  266.     fprintf(stderr, "%s: e - the start symbol %s is undefined\n", myname, s);
  267.     done(1);
  268. }
  269.  
  270.  
  271. void undefined_symbol_warning(char * s)
  272. {
  273.     fprintf(stderr, "%s: w - the symbol %s is undefined\n", myname, s);
  274. }
  275.