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