Pristine Ack-5.5
[Ack-5.5.git] / lang / m2 / comp / LLmessage.c
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
8 /* S Y N T A X   E R R O R   R E P O R T I N G */
9
10 /* $Id: LLmessage.c,v 1.18 1997/02/21 17:10:11 ceriel Exp $ */
11
12 /*      Defines the LLmessage routine. LLgen-generated parsers require the
13         existence of a routine of that name.
14         The routine must do syntax-error reporting and must be able to
15         insert tokens in the token stream.
16 */
17
18 #include        <alloc.h>
19 #include        <em_arith.h>
20 #include        <em_label.h>
21
22 #include        "idf.h"
23 #include        "LLlex.h"
24 #include        "Lpars.h"
25
26 extern char             *symbol2str();
27 extern t_idf            *gen_anon_idf();
28
29 LLmessage(tk)
30         register int tk;
31 {
32         if (tk > 0)     {
33                 /* if (tk > 0), it represents the token to be inserted.
34                 */
35                 register t_token *dotp = &dot;
36
37 #ifndef LLNONCORR
38                 error("%s missing before %s", symbol2str(tk), symbol2str(dotp->tk_symb));
39 #endif
40
41                 aside = *dotp;
42
43                 dotp->tk_symb = tk;
44
45                 switch (tk)     {
46                 /* The operands need some body */
47                 case IDENT:
48                         dotp->TOK_IDF = gen_anon_idf();
49                         break;
50                 case STRING:
51                         dotp->tk_data.tk_str = (struct string *)
52                                                 Malloc(sizeof (struct string));
53                         dotp->TOK_SLE = 1;
54                         dotp->TOK_STR = Salloc("", 1);
55                         break;
56                 case INTEGER:
57                         dotp->TOK_INT = 1;
58                         break;
59                 case REAL:
60                         dotp->tk_data.tk_real = new_real();
61                         dotp->TOK_RSTR = Salloc("0.0", 4);
62                         flt_str2flt(dotp->TOK_RSTR, &dotp->TOK_RVAL);
63                         break;
64                 }
65         }
66         else if (tk  < 0) {
67                 error("end of file expected");
68         }
69         else    {
70 #ifndef LLNONCORR
71                 error("%s deleted", symbol2str(dot.tk_symb));
72 #else
73                 error("%s not expected", symbol2str(dot.tk_symb));
74 #endif
75         }
76         tk_nmb_at_last_syn_err = token_nmb;
77 }
78