1 /* YACC grammar for Modula-2 expressions, for GDB.
2 Copyright (C) 1986, 1989, 1990, 1991 Free Software Foundation, Inc.
3 Generated from expread.y (now c-exp.y) and contributed by the Department
4 of Computer Science at the State University of New York at Buffalo, 1991.
6 This file is part of GDB.
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
22 /* Parse a Modula-2 expression from text in a string,
23 and return the result as a struct expression pointer.
24 That structure contains arithmetic operations in reverse polish,
25 with constants represented by operations that are followed by special data.
26 See expression.h for the details of the format.
27 What is important here is that it can be built up sequentially
28 during the process of parsing; the lower levels of the tree always
29 come first in the result. */
38 #include "expression.h"
41 #include "parser-defs.h"
43 /* These MUST be included in any grammar file!!!!
44 Please choose unique names! */
45 #define yyparse m2_parse
47 #define yyerror m2_error
48 #define yylval m2_lval
49 #define yychar m2_char
50 #define yydebug m2_debug
51 #define yypact m2_pact
58 #define yyexca m2_exca
59 #define yyerrflag m2_errflag
60 #define yynerrs m2_nerrs
64 #define yystate m2_state
68 #define yylloc m2_lloc
75 /* The sign of the number being parsed. */
78 /* The block that the module specified by the qualifer on an identifer is
80 struct block *modblock=0;
82 char *make_qualname();
84 /* #define YYDEBUG 1 */
88 /* Although the yacc "value" of an expression is not used,
89 since the result is stored in the structure being created,
90 other node types do have values. */
95 unsigned LONGEST ulval;
102 enum exp_opcode opcode;
103 struct internalvar *ivar;
109 %type <voidval> exp type_exp start set
110 %type <voidval> variable
115 %token <lval> INT HEX ERROR
116 %token <ulval> UINT TRUE FALSE CHAR
119 /* Both NAME and TYPENAME tokens represent symbols in the input,
120 and both convey their data as strings.
121 But a TYPENAME is a string that happens to be defined as a typedef
122 or builtin type name (such as int or char)
123 and a NAME is any other symbol.
125 Contexts where this distinction is not important can use the
126 nonterminal "name", which matches either NAME or TYPENAME. */
129 %token <sval> NAME BLOCKNAME IDENT CONST VARNAME
130 %token <sval> TYPENAME
132 %token SIZE CAP ORD HIGH ABS MIN MAX FLOAT_FUNC VAL CHR ODD TRUNC
133 %token INC DEC INCL EXCL
135 /* The GDB scope operator */
138 %token <lval> LAST REGNAME
140 %token <ivar> INTERNAL_VAR
146 %left '<' '>' LEQ GEQ '=' NOTEQUAL '#' IN
151 %left '*' '/' DIV MOD
153 %right '^' DOT '[' '('
156 /* This is not an actual token ; it is used for precedence.
166 { write_exp_elt_opcode(OP_TYPE);
167 write_exp_elt_type($1);
168 write_exp_elt_opcode(OP_TYPE);
174 exp : exp '^' %prec UNARY
175 { write_exp_elt_opcode (UNOP_IND); }
178 { number_sign = -1; }
181 write_exp_elt_opcode (UNOP_NEG); }
184 exp : '+' exp %prec UNARY
185 { write_exp_elt_opcode(UNOP_PLUS); }
188 exp : not_exp exp %prec UNARY
189 { write_exp_elt_opcode (UNOP_ZEROP); }
196 exp : CAP '(' exp ')'
197 { write_exp_elt_opcode (UNOP_CAP); }
200 exp : ORD '(' exp ')'
201 { write_exp_elt_opcode (UNOP_ORD); }
204 exp : ABS '(' exp ')'
205 { write_exp_elt_opcode (UNOP_ABS); }
208 exp : HIGH '(' exp ')'
209 { write_exp_elt_opcode (UNOP_HIGH); }
212 exp : MIN '(' type ')'
213 { write_exp_elt_opcode (UNOP_MIN);
214 write_exp_elt_type ($3);
215 write_exp_elt_opcode (UNOP_MIN); }
218 exp : MAX '(' type ')'
219 { write_exp_elt_opcode (UNOP_MAX);
220 write_exp_elt_type ($3);
221 write_exp_elt_opcode (UNOP_MIN); }
224 exp : FLOAT_FUNC '(' exp ')'
225 { write_exp_elt_opcode (UNOP_FLOAT); }
228 exp : VAL '(' type ',' exp ')'
229 { write_exp_elt_opcode (BINOP_VAL);
230 write_exp_elt_type ($3);
231 write_exp_elt_opcode (BINOP_VAL); }
234 exp : CHR '(' exp ')'
235 { write_exp_elt_opcode (UNOP_CHR); }
238 exp : ODD '(' exp ')'
239 { write_exp_elt_opcode (UNOP_ODD); }
242 exp : TRUNC '(' exp ')'
243 { write_exp_elt_opcode (UNOP_TRUNC); }
246 exp : SIZE exp %prec UNARY
247 { write_exp_elt_opcode (UNOP_SIZEOF); }
251 exp : INC '(' exp ')'
252 { write_exp_elt_opcode(UNOP_PREINCREMENT); }
255 exp : INC '(' exp ',' exp ')'
256 { write_exp_elt_opcode(BINOP_ASSIGN_MODIFY);
257 write_exp_elt_opcode(BINOP_ADD);
258 write_exp_elt_opcode(BINOP_ASSIGN_MODIFY); }
261 exp : DEC '(' exp ')'
262 { write_exp_elt_opcode(UNOP_PREDECREMENT);}
265 exp : DEC '(' exp ',' exp ')'
266 { write_exp_elt_opcode(BINOP_ASSIGN_MODIFY);
267 write_exp_elt_opcode(BINOP_SUB);
268 write_exp_elt_opcode(BINOP_ASSIGN_MODIFY); }
272 { write_exp_elt_opcode (STRUCTOP_STRUCT);
273 write_exp_string ($3);
274 write_exp_elt_opcode (STRUCTOP_STRUCT); }
281 { error("Sets are not implemented.");}
284 exp : INCL '(' exp ',' exp ')'
285 { error("Sets are not implemented.");}
288 exp : EXCL '(' exp ',' exp ')'
289 { error("Sets are not implemented.");}
291 set : '{' arglist '}'
292 { error("Sets are not implemented.");}
293 | type '{' arglist '}'
294 { error("Sets are not implemented.");}
298 /* Modula-2 array subscript notation [a,b,c...] */
300 /* This function just saves the number of arguments
301 that follow in the list. It is *not* specific to
304 non_empty_arglist ']' %prec DOT
305 { write_exp_elt_opcode (BINOP_MULTI_SUBSCRIPT);
306 write_exp_elt_longcst ((LONGEST) end_arglist());
307 write_exp_elt_opcode (BINOP_MULTI_SUBSCRIPT); }
311 /* This is to save the value of arglist_len
312 being accumulated by an outer function call. */
313 { start_arglist (); }
314 arglist ')' %prec DOT
315 { write_exp_elt_opcode (OP_FUNCALL);
316 write_exp_elt_longcst ((LONGEST) end_arglist ());
317 write_exp_elt_opcode (OP_FUNCALL); }
327 arglist : arglist ',' exp %prec ABOVE_COMMA
337 : non_empty_arglist ',' exp %prec ABOVE_COMMA
342 exp : '{' type '}' exp %prec UNARY
343 { write_exp_elt_opcode (UNOP_MEMVAL);
344 write_exp_elt_type ($2);
345 write_exp_elt_opcode (UNOP_MEMVAL); }
348 exp : type '(' exp ')' %prec UNARY
349 { write_exp_elt_opcode (UNOP_CAST);
350 write_exp_elt_type ($1);
351 write_exp_elt_opcode (UNOP_CAST); }
358 /* Binary operators in order of decreasing precedence. Note that some
359 of these operators are overloaded! (ie. sets) */
363 { write_exp_elt_opcode (BINOP_REPEAT); }
367 { write_exp_elt_opcode (BINOP_MUL); }
371 { write_exp_elt_opcode (BINOP_DIV); }
375 { write_exp_elt_opcode (BINOP_INTDIV); }
379 { write_exp_elt_opcode (BINOP_REM); }
383 { write_exp_elt_opcode (BINOP_ADD); }
387 { write_exp_elt_opcode (BINOP_SUB); }
391 { write_exp_elt_opcode (BINOP_EQUAL); }
394 exp : exp NOTEQUAL exp
395 { write_exp_elt_opcode (BINOP_NOTEQUAL); }
397 { write_exp_elt_opcode (BINOP_NOTEQUAL); }
401 { write_exp_elt_opcode (BINOP_LEQ); }
405 { write_exp_elt_opcode (BINOP_GEQ); }
409 { write_exp_elt_opcode (BINOP_LESS); }
413 { write_exp_elt_opcode (BINOP_GTR); }
417 { write_exp_elt_opcode (BINOP_AND); }
421 { write_exp_elt_opcode (BINOP_AND); }
425 { write_exp_elt_opcode (BINOP_OR); }
429 { write_exp_elt_opcode (BINOP_ASSIGN); }
436 { write_exp_elt_opcode (OP_BOOL);
437 write_exp_elt_longcst ((LONGEST) $1);
438 write_exp_elt_opcode (OP_BOOL); }
442 { write_exp_elt_opcode (OP_BOOL);
443 write_exp_elt_longcst ((LONGEST) $1);
444 write_exp_elt_opcode (OP_BOOL); }
448 { write_exp_elt_opcode (OP_LONG);
449 write_exp_elt_type (builtin_type_m2_int);
450 write_exp_elt_longcst ((LONGEST) $1);
451 write_exp_elt_opcode (OP_LONG); }
456 write_exp_elt_opcode (OP_LONG);
457 write_exp_elt_type (builtin_type_m2_card);
458 write_exp_elt_longcst ((LONGEST) $1);
459 write_exp_elt_opcode (OP_LONG);
464 { write_exp_elt_opcode (OP_LONG);
465 write_exp_elt_type (builtin_type_m2_char);
466 write_exp_elt_longcst ((LONGEST) $1);
467 write_exp_elt_opcode (OP_LONG); }
472 { write_exp_elt_opcode (OP_DOUBLE);
473 write_exp_elt_type (builtin_type_m2_real);
474 write_exp_elt_dblcst ($1);
475 write_exp_elt_opcode (OP_DOUBLE); }
481 /* The GDB internal variable $$, et al. */
483 { write_exp_elt_opcode (OP_LAST);
484 write_exp_elt_longcst ((LONGEST) $1);
485 write_exp_elt_opcode (OP_LAST); }
489 { write_exp_elt_opcode (OP_REGISTER);
490 write_exp_elt_longcst ((LONGEST) $1);
491 write_exp_elt_opcode (OP_REGISTER); }
494 exp : SIZE '(' type ')' %prec UNARY
495 { write_exp_elt_opcode (OP_LONG);
496 write_exp_elt_type (builtin_type_int);
497 write_exp_elt_longcst ((LONGEST) TYPE_LENGTH ($3));
498 write_exp_elt_opcode (OP_LONG); }
502 { write_exp_elt_opcode (OP_M2_STRING);
503 write_exp_string ($1);
504 write_exp_elt_opcode (OP_M2_STRING); }
507 /* This will be used for extensions later. Like adding modules. */
509 { $$ = SYMBOL_BLOCK_VALUE($1); }
514 = lookup_symbol (copy_name ($1), expression_context_block,
515 VAR_NAMESPACE, 0, NULL);
520 /* GDB scope operator */
521 fblock : block COLONCOLON BLOCKNAME
523 = lookup_symbol (copy_name ($3), $1,
524 VAR_NAMESPACE, 0, NULL);
525 if (!tem || SYMBOL_CLASS (tem) != LOC_BLOCK)
526 error ("No function \"%s\" in specified context.",
532 /* Useful for assigning to PROCEDURE variables */
534 { write_exp_elt_opcode(OP_VAR_VALUE);
535 write_exp_elt_sym ($1);
536 write_exp_elt_opcode (OP_VAR_VALUE); }
539 /* GDB internal ($foo) variable */
540 variable: INTERNAL_VAR
541 { write_exp_elt_opcode (OP_INTERNALVAR);
542 write_exp_elt_intern ($1);
543 write_exp_elt_opcode (OP_INTERNALVAR); }
546 /* GDB scope operator */
547 variable: block COLONCOLON NAME
548 { struct symbol *sym;
549 sym = lookup_symbol (copy_name ($3), $1,
550 VAR_NAMESPACE, 0, NULL);
552 error ("No symbol \"%s\" in specified context.",
555 write_exp_elt_opcode (OP_VAR_VALUE);
556 write_exp_elt_sym (sym);
557 write_exp_elt_opcode (OP_VAR_VALUE); }
560 /* Base case for variables. */
562 { struct symbol *sym;
563 int is_a_field_of_this;
565 sym = lookup_symbol (copy_name ($1),
566 expression_context_block,
577 if (innermost_block == 0 ||
578 contained_in (block_found,
580 innermost_block = block_found;
582 write_exp_elt_opcode (OP_VAR_VALUE);
583 write_exp_elt_sym (sym);
584 write_exp_elt_opcode (OP_VAR_VALUE);
589 register char *arg = copy_name ($1);
591 for (i = 0; i < misc_function_count; i++)
592 if (!strcmp (misc_function_vector[i].name, arg))
595 if (i < misc_function_count)
597 enum misc_function_type mft =
598 (enum misc_function_type)
599 misc_function_vector[i].type;
601 write_exp_elt_opcode (OP_LONG);
602 write_exp_elt_type (builtin_type_int);
603 write_exp_elt_longcst ((LONGEST) misc_function_vector[i].address);
604 write_exp_elt_opcode (OP_LONG);
605 write_exp_elt_opcode (UNOP_MEMVAL);
606 if (mft == mf_data || mft == mf_bss)
607 write_exp_elt_type (builtin_type_int);
608 else if (mft == mf_text)
609 write_exp_elt_type (lookup_function_type (builtin_type_int));
611 write_exp_elt_type (builtin_type_char);
612 write_exp_elt_opcode (UNOP_MEMVAL);
614 else if (symtab_list == 0
615 && partial_symtab_list == 0)
616 error ("No symbol table is loaded. Use the \"symbol-file\" command.");
618 error ("No symbol \"%s\" in current context.",
626 { $$ = lookup_typename (copy_name ($1),
627 expression_context_block, 0); }
638 return (MAX_OF_TYPE(builtin_type_m2_int) - b) < a;
645 return (MAX_OF_TYPE(builtin_type_m2_card) - b) < a;
649 /* Take care of parsing a number (anything that starts with a digit).
650 Set yylval and return the token type; update lexptr.
651 LEN is the number of characters in it. */
653 /*** Needs some error checking for the float case ***/
659 register char *p = lexptr;
660 register LONGEST n = 0;
661 register LONGEST prevn = 0;
662 register int c,i,ischar=0;
663 register int base = input_radix;
664 register int len = olen;
665 int unsigned_p = number_sign == 1 ? 1 : 0;
667 extern double atof ();
674 else if(p[len-1] == 'C' || p[len-1] == 'B')
677 ischar = p[len-1] == 'C';
681 /* Scan the number */
682 for (c = 0; c < len; c++)
684 if (p[c] == '.' && base == 10)
686 /* It's a float since it contains a point. */
687 yylval.dval = atof (p);
691 if (p[c] == '.' && base != 10)
692 error("Floating point numbers must be base 10.");
693 if (base == 10 && (p[c] < '0' || p[c] > '9'))
694 error("Invalid digit \'%c\' in number.",p[c]);
701 if( base == 8 && (c == '8' || c == '9'))
702 error("Invalid digit \'%c\' in octal number.",c);
703 if (c >= '0' && c <= '9')
707 if (base == 16 && c >= 'A' && c <= 'F')
715 if(!unsigned_p && number_sign == 1 && (prevn >= n))
716 unsigned_p=1; /* Try something unsigned */
717 /* Don't do the range check if n==i and i==0, since that special
718 case will give an overflow error. */
719 if(RANGE_CHECK && n!=i && i)
721 if((unsigned_p && (unsigned)prevn >= (unsigned)n) ||
722 ((!unsigned_p && number_sign==-1) && -prevn <= -n))
723 range_error("Overflow on numeric constant.");
729 if(*p == 'B' || *p == 'C' || *p == 'H')
730 lexptr++; /* Advance past B,C or H */
737 else if ( unsigned_p && number_sign == 1)
742 else if((unsigned_p && (n<0))) {
743 range_error("Overflow on numeric constant -- number too large.");
744 /* But, this can return if range_check == range_warn. */
767 /* Some specific keywords */
774 static struct keyword keytab[] =
777 {"IN", IN },/* Note space after IN */
796 {"FLOAT", FLOAT_FUNC },
801 /* Read one token, getting characters through lexptr. */
803 /* This is where we will check to make sure that the language and the operators used are
810 register int namelen;
812 register char *tokstart;
820 /* See if it is a special token of length 2 */
821 for( i = 0 ; i < sizeof tokentab2 / sizeof tokentab2[0] ; i++)
822 if(!strncmp(tokentab2[i].name, tokstart, 2))
825 return tokentab2[i].token;
828 switch (c = *tokstart)
845 if (paren_depth == 0)
852 if (comma_terminates && paren_depth == 0)
858 /* Might be a floating point number. */
859 if (lexptr[1] >= '0' && lexptr[1] <= '9')
860 break; /* Falls into number code. */
867 /* These are character tokens that appear as-is in the YACC grammar */
890 for (namelen = 1; (c = tokstart[namelen]) != quote && c != '\0'; namelen++)
893 c = tokstart[++namelen];
894 if (c >= '0' && c <= '9')
896 c = tokstart[++namelen];
897 if (c >= '0' && c <= '9')
898 c = tokstart[++namelen];
902 error("Unterminated string or character constant.");
903 yylval.sval.ptr = tokstart + 1;
904 yylval.sval.length = namelen - 1;
905 lexptr += namelen + 1;
907 if(namelen == 2) /* Single character */
909 yylval.ulval = tokstart[1];
916 /* Is it a number? */
917 /* Note: We have already dealt with the case of the token '.'.
918 See case '.' above. */
919 if ((c >= '0' && c <= '9'))
922 int got_dot = 0, got_e = 0;
923 register char *p = tokstart;
928 if (!got_e && (*p == 'e' || *p == 'E'))
930 else if (!got_dot && *p == '.')
932 else if (got_e && (p[-1] == 'e' || p[-1] == 'E')
933 && (*p == '-' || *p == '+'))
934 /* This is the sign of the exponent, not the end of the
937 else if ((*p < '0' || *p > '9') &&
938 (*p < 'A' || *p > 'F') &&
939 (*p != 'H')) /* Modula-2 hexadecimal number */
942 toktype = parse_number (p - tokstart);
943 if (toktype == ERROR)
945 char *err_copy = (char *) alloca (p - tokstart + 1);
947 bcopy (tokstart, err_copy, p - tokstart);
948 err_copy[p - tokstart] = 0;
949 error ("Invalid number \"%s\".", err_copy);
955 if (!(c == '_' || c == '$'
956 || (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z')))
957 /* We must have come across a bad character (e.g. ';'). */
958 error ("Invalid character '%c' in expression.", c);
960 /* It's a name. See how long it is. */
962 for (c = tokstart[namelen];
963 (c == '_' || c == '$' || (c >= '0' && c <= '9')
964 || (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z'));
965 c = tokstart[++namelen])
968 /* The token "if" terminates the expression and is NOT
969 removed from the input stream. */
970 if (namelen == 2 && tokstart[0] == 'i' && tokstart[1] == 'f')
977 /* Handle the tokens $digits; also $ (short for $0) and $$ (short for $$1)
978 and $$digits (equivalent to $<-digits> if you could type that).
979 Make token type LAST, and put the number (the digits) in yylval. */
981 if (*tokstart == '$')
983 register int negate = 0;
985 /* Double dollar means negate the number and add -1 as well.
986 Thus $$ alone means -1. */
987 if (namelen >= 2 && tokstart[1] == '$')
994 /* Just dollars (one or two) */
995 yylval.lval = - negate;
998 /* Is the rest of the token digits? */
999 for (; c < namelen; c++)
1000 if (!(tokstart[c] >= '0' && tokstart[c] <= '9'))
1004 yylval.lval = atoi (tokstart + 1 + negate);
1006 yylval.lval = - yylval.lval;
1011 /* Handle tokens that refer to machine registers:
1012 $ followed by a register name. */
1014 if (*tokstart == '$') {
1015 for (c = 0; c < NUM_REGS; c++)
1016 if (namelen - 1 == strlen (reg_names[c])
1017 && !strncmp (tokstart + 1, reg_names[c], namelen - 1))
1022 for (c = 0; c < num_std_regs; c++)
1023 if (namelen - 1 == strlen (std_regs[c].name)
1024 && !strncmp (tokstart + 1, std_regs[c].name, namelen - 1))
1026 yylval.lval = std_regs[c].regnum;
1032 /* Lookup special keywords */
1033 for(i = 0 ; i < sizeof(keytab) / sizeof(keytab[0]) ; i++)
1034 if(namelen == strlen(keytab[i].keyw) && !strncmp(tokstart,keytab[i].keyw,namelen))
1035 return keytab[i].token;
1037 yylval.sval.ptr = tokstart;
1038 yylval.sval.length = namelen;
1040 /* Any other names starting in $ are debugger internal variables. */
1042 if (*tokstart == '$')
1044 yylval.ivar = (struct internalvar *) lookup_internalvar (copy_name (yylval.sval) + 1);
1045 return INTERNAL_VAR;
1049 /* Use token-type BLOCKNAME for symbols that happen to be defined as
1050 functions. If this is not so, then ...
1051 Use token-type TYPENAME for symbols that happen to be defined
1052 currently as names of types; NAME for other symbols.
1053 The caller is not constrained to care about the distinction. */
1057 char *tmp = copy_name (yylval.sval);
1060 if (lookup_partial_symtab (tmp))
1062 sym = lookup_symbol (tmp, expression_context_block,
1063 VAR_NAMESPACE, 0, NULL);
1064 if (sym && SYMBOL_CLASS (sym) == LOC_BLOCK)
1066 if (lookup_typename (copy_name (yylval.sval), expression_context_block, 1))
1081 case LOC_CONST_BYTES:
1091 error("internal: Undefined class in m2lex()");
1094 error("internal: Unforseen case in m2lex()");
1099 /* Built-in BOOLEAN type. This is sort of a hack. */
1100 if(!strncmp(tokstart,"TRUE",4))
1105 else if(!strncmp(tokstart,"FALSE",5))
1112 /* Must be another type of name... */
1118 make_qualname(mod,ident)
1121 char *new = xmalloc(strlen(mod)+strlen(ident)+2);
1133 printf("Parsing: %s\n",lexptr);
1135 error("Invalid syntax in expression near character '%c'.",yychar);
1137 error("Invalid syntax in expression");
1140 /* Table of operators and their precedences for printing expressions. */
1142 const static struct op_print m2_op_print_tab[] = {
1143 {"+", BINOP_ADD, PREC_ADD, 0},
1144 {"+", UNOP_PLUS, PREC_PREFIX, 0},
1145 {"-", BINOP_SUB, PREC_ADD, 0},
1146 {"-", UNOP_NEG, PREC_PREFIX, 0},
1147 {"*", BINOP_MUL, PREC_MUL, 0},
1148 {"/", BINOP_DIV, PREC_MUL, 0},
1149 {"DIV", BINOP_INTDIV, PREC_MUL, 0},
1150 {"MOD", BINOP_REM, PREC_MUL, 0},
1151 {":=", BINOP_ASSIGN, PREC_ASSIGN, 1},
1152 {"OR", BINOP_OR, PREC_OR, 0},
1153 {"AND", BINOP_AND, PREC_AND, 0},
1154 {"NOT", UNOP_ZEROP, PREC_PREFIX, 0},
1155 {"=", BINOP_EQUAL, PREC_EQUAL, 0},
1156 {"<>", BINOP_NOTEQUAL, PREC_EQUAL, 0},
1157 {"<=", BINOP_LEQ, PREC_ORDER, 0},
1158 {">=", BINOP_GEQ, PREC_ORDER, 0},
1159 {">", BINOP_GTR, PREC_ORDER, 0},
1160 {"<", BINOP_LESS, PREC_ORDER, 0},
1161 {"^", UNOP_IND, PREC_PREFIX, 0},
1162 {"@", BINOP_REPEAT, PREC_REPEAT, 0},
1165 /* The built-in types of Modula-2. */
1167 struct type *builtin_type_m2_char;
1168 struct type *builtin_type_m2_int;
1169 struct type *builtin_type_m2_card;
1170 struct type *builtin_type_m2_real;
1171 struct type *builtin_type_m2_bool;
1173 struct type ** const (m2_builtin_types[]) =
1175 &builtin_type_m2_char,
1176 &builtin_type_m2_int,
1177 &builtin_type_m2_card,
1178 &builtin_type_m2_real,
1179 &builtin_type_m2_bool,
1183 const struct language_defn m2_language_defn = {
1189 m2_parse, /* parser */
1190 m2_error, /* parser error function */
1191 &builtin_type_m2_int, /* longest signed integral type */
1192 &builtin_type_m2_card, /* longest unsigned integral type */
1193 &builtin_type_m2_real, /* longest floating point type */
1194 "0%XH", "0%", "XH", /* Hex format string, prefix, suffix */
1195 "%oB", "%", "oB", /* Octal format string, prefix, suffix */
1196 m2_op_print_tab, /* expression operators for printing */
1200 /* Initialization for Modula-2 */
1203 _initialize_m2_exp ()
1205 /* FIXME: The code below assumes that the sizes of the basic data
1206 types are the same on the host and target machines!!! */
1208 /* Modula-2 "pervasive" types. NOTE: these can be redefined!!! */
1209 builtin_type_m2_int = init_type (TYPE_CODE_INT, sizeof(int), 0, "INTEGER");
1210 builtin_type_m2_card = init_type (TYPE_CODE_INT, sizeof(int), 1, "CARDINAL");
1211 builtin_type_m2_real = init_type (TYPE_CODE_FLT, sizeof(float), 0, "REAL");
1212 builtin_type_m2_char = init_type (TYPE_CODE_CHAR, sizeof(char), 1, "CHAR");
1214 builtin_type_m2_bool = init_type (TYPE_CODE_BOOL, sizeof(int), 1, "BOOLEAN");
1215 TYPE_NFIELDS(builtin_type_m2_bool) = 2;
1216 TYPE_FIELDS(builtin_type_m2_bool) =
1217 (struct field *) malloc (sizeof (struct field) * 2);
1218 TYPE_FIELD_BITPOS(builtin_type_m2_bool,0) = 0;
1219 TYPE_FIELD_NAME(builtin_type_m2_bool,0) = (char *)malloc(6);
1220 strcpy(TYPE_FIELD_NAME(builtin_type_m2_bool,0),"FALSE");
1221 TYPE_FIELD_BITPOS(builtin_type_m2_bool,1) = 1;
1222 TYPE_FIELD_NAME(builtin_type_m2_bool,1) = (char *)malloc(5);
1223 strcpy(TYPE_FIELD_NAME(builtin_type_m2_bool,1),"TRUE");
1225 add_language (&m2_language_defn);