LLmessage.c 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. /*
  2. * (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
  3. * See the copyright notice in the ACK home directory, in the file "Copyright".
  4. *
  5. * Author: Ceriel J.H. Jacobs
  6. */
  7. /* S Y N T A X E R R O R R E P O R T I N G */
  8. /* $Id$ */
  9. /* Defines the LLmessage routine. LLgen-generated parsers require the
  10. existence of a routine of that name.
  11. The routine must do syntax-error reporting and must be able to
  12. insert tokens in the token stream.
  13. */
  14. #include <alloc.h>
  15. #include <em_arith.h>
  16. #include <em_label.h>
  17. #include "idf.h"
  18. #include "LLlex.h"
  19. #include "Lpars.h"
  20. extern char *symbol2str();
  21. extern t_idf *gen_anon_idf();
  22. LLmessage(tk)
  23. register int tk;
  24. {
  25. if (tk > 0) {
  26. /* if (tk > 0), it represents the token to be inserted.
  27. */
  28. register t_token *dotp = &dot;
  29. #ifndef LLNONCORR
  30. error("%s missing before %s", symbol2str(tk), symbol2str(dotp->tk_symb));
  31. #endif
  32. aside = *dotp;
  33. dotp->tk_symb = tk;
  34. switch (tk) {
  35. /* The operands need some body */
  36. case IDENT:
  37. dotp->TOK_IDF = gen_anon_idf();
  38. break;
  39. case STRING:
  40. dotp->tk_data.tk_str = (struct string *)
  41. Malloc(sizeof (struct string));
  42. dotp->TOK_SLE = 1;
  43. dotp->TOK_STR = Salloc("", 1);
  44. break;
  45. case INTEGER:
  46. dotp->TOK_INT = 1;
  47. break;
  48. case REAL:
  49. dotp->tk_data.tk_real = new_real();
  50. dotp->TOK_RSTR = Salloc("0.0", 4);
  51. flt_str2flt(dotp->TOK_RSTR, &dotp->TOK_RVAL);
  52. break;
  53. }
  54. }
  55. else if (tk < 0) {
  56. error("end of file expected");
  57. }
  58. else {
  59. #ifndef LLNONCORR
  60. error("%s deleted", symbol2str(dot.tk_symb));
  61. #else
  62. error("%s not expected", symbol2str(dot.tk_symb));
  63. #endif
  64. }
  65. tk_nmb_at_last_syn_err = token_nmb;
  66. }