LLmessage.c 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. /* S Y N T A X E R R O R R E P O R T I N G */
  2. /* Defines the LLmessage routine. LLgen-generated parsers require the
  3. existence of a routine of that name.
  4. The routine must do syntax-error reporting and must be able to
  5. insert tokens in the token stream.
  6. */
  7. #include <alloc.h>
  8. #include <em_arith.h>
  9. #include <em_label.h>
  10. #include "LLlex.h"
  11. #include "Lpars.h"
  12. #include "idf.h"
  13. #include "type.h"
  14. extern char *symbol2str();
  15. extern char *Malloc(), *Salloc();
  16. extern struct idf *gen_anon_idf();
  17. extern int expect_label;
  18. LLmessage(tk)
  19. register int tk;
  20. {
  21. if( tk > 0 ) {
  22. /* if( tk > 0 ), it represents the token to be inserted.
  23. */
  24. register struct token *dotp = &dot;
  25. error("%s missing before %s", symbol2str(tk), symbol2str(dotp->tk_symb));
  26. aside = *dotp;
  27. asidetype = toktype;
  28. dotp->tk_symb = tk;
  29. switch( tk ) {
  30. /* The operands need some body */
  31. case IDENT:
  32. dotp->TOK_IDF = gen_anon_idf();
  33. break;
  34. case STRING:
  35. dotp->tk_data.tk_str = (struct string *)
  36. Malloc(sizeof (struct string));
  37. dotp->TOK_SLE = 1;
  38. dotp->TOK_STR = Salloc("", 1);
  39. toktype = standard_type(T_STRINGCONST, 1, (arith) 1);
  40. break;
  41. case INTEGER:
  42. toktype = int_type;
  43. if( !expect_label )
  44. dotp->TOK_INT = 1;
  45. else
  46. dotp->TOK_INT = -1;
  47. break;
  48. case REAL:
  49. dotp->tk_data.tk_real = (struct real *)
  50. Malloc(sizeof(struct real));
  51. /* inverse struct */
  52. dotp->TOK_RIV = (struct real *)
  53. Malloc(sizeof(struct real));
  54. dotp->TOK_RIV->r_inverse = dotp->tk_data.tk_real;
  55. dotp->TOK_REL = Salloc("0.0", 4);
  56. dotp->TOK_RIV->r_real = dotp->TOK_REL;
  57. toktype = real_type;
  58. break;
  59. }
  60. }
  61. else if( tk < 0 ) error("garbage at end of program");
  62. else error("%s deleted", symbol2str(dot.tk_symb));
  63. }