1 /* $Id: modula-2.c,v 1.13 1994/06/24 11:00:31 ceriel Exp $ */
3 /* Language dependant support; this one is for Modula-2 */
20 extern FILE *db_out, *db_in;
40 static struct langdep m2 = {
70 struct langdep *m2_dep = &m2;
77 fprintf(db_out, (c >= 040 && c < 0177) ? "'%c'" : "%oC", c);
81 print_string(f, s, len)
86 register char *str = s;
90 if (*str++ == '\'') delim = '"';
92 fprintf(f, "%c%.*s%c", delim, len, s, delim);
101 if (! (int_size % size)) return size;
102 if (! (size % int_size)) return size;
103 return ((size + int_size - 1) / int_size) * int_size;
156 /* The problem arising with the "parsing" of a number
157 is that we don't know the base in advance so we
158 have to read the number with the help of a rather
159 complex finite automaton.
161 enum statetp {Oct,Hex,Dec,OctEndOrHex,End,Real};
162 register enum statetp state;
164 register int base = 10;
165 register char *np = &buf[0];
168 state = is_oct(ch) ? Oct : Dec;
174 if (np < &buf[512]) *np++ = ch;
177 if (ch == 'B' || ch == 'C') {
185 if (np < &buf[512]) {
190 if (is_hex(ch)) state = Hex;
191 else if (ch == '.') state = Real;
194 if (ch == 'H') base = 16;
195 else ungetc(ch, db_in);
201 if (np < &buf[512]) *np++ = ch;
207 error("H expected after hex number");
213 if (np < &buf[512]) *np++ = ch;
231 if (np >= &buf[512]) {
233 error("constant too long");
237 while (*np == '0') np++;
246 c = *np++ - 'A' + 10;
254 if (state == Real) break;
257 /* a real real constant */
258 if (np < &buf[512]) *np++ = '.';
264 if (np < &buf[512]) *np++ = ch;
271 if (np < &buf[512]) *np++ = ch;
273 if (ch == '+' || ch == '-') {
274 /* Signed scalefactor
276 if (np < &buf[512]) *np++ = ch;
281 if (np < &buf[512]) *np++ = ch;
283 } while (is_dig(ch));
286 error("bad scale factor");
293 if (np >= &buf[512]) {
295 error("real constant too long");
297 else tok.fval = atof(buf);
306 register char *p = &buf[0];
307 register struct idf *id;
310 if (p - buf < 512) *p++ = c;
315 /* now recognize AND, DIV, IN, MOD, NOT, OR */
318 if (strcmp(buf, "AND") == 0) {
324 if (strcmp(buf, "DIV") == 0) {
330 if (strcmp(buf, "IN") == 0) {
336 if (strcmp(buf, "MOD") == 0) {
342 if (strcmp(buf, "NOT") == 0) {
348 if (strcmp(buf, "OR") == 0) {
354 id = str2idf(buf, 1);
356 tok.str = id->id_text;
357 return id->id_reserved ? id->id_reserved : NAME;
384 return PREF_OR_BIN_OP;
387 return PREF_OR_BIN_OP;
404 tok.ival = E_NOTEQUAL;
409 tok.ival = E_NOTEQUAL;
413 tok.ival = E_LTEQUAL;
422 tok.ival = E_GTEQUAL;
435 error((c >= 040 && c < 0177) ? "%s'%c'" : "%s'\\0%o'", "illegal character ", c);
446 register int len = 0;
448 while (ch = getc(db_in), ch != c) {
450 error("newline in string");
457 tok.str = Salloc(buf, (unsigned) len);
468 switch(p->t_whichoper) {
471 print_node(f, p->t_args[0], 0);
475 print_node(f, p->t_args[0], 0);
479 print_node(f, p->t_args[0], 0);
482 print_node(f, p->t_args[0], 0);
488 if (p->t_whichoper == E_ARRAY) {
489 print_node(f, p->t_args[0], 0);
491 print_node(f, p->t_args[1], 0);
495 if (p->t_whichoper == E_SELECT) {
496 print_node(f, p->t_args[0], 0);
498 print_node(f, p->t_args[1], 0);
502 print_node(f, p->t_args[0], 0);
503 switch(p->t_whichoper) {
547 print_node(f, p->t_args[1], 0);
556 /* No problems of this kind in Modula-2 */