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"
46 /* These MUST be included in any grammar file!!!! Please choose unique names!
47 Note that this are a combined list of variables that can be produced
48 by any one of bison, byacc, or yacc. */
49 #define yymaxdepth m2_maxdepth
50 #define yyparse m2_parse
52 #define yyerror m2_error
53 #define yylval m2_lval
54 #define yychar m2_char
55 #define yydebug m2_debug
56 #define yypact m2_pact
63 #define yyexca m2_exca
64 #define yyerrflag m2_errflag
65 #define yynerrs m2_nerrs
70 #define yystate m2_state
75 #define yylloc m2_lloc
76 #define yyss m2_yyss /* byacc */
77 #define yyssp m2_yysp /* byacc */
78 #define yyvs m2_yyvs /* byacc */
79 #define yyvsp m2_yyvsp /* byacc */
83 make_qualname PARAMS ((char *, char *));
87 parse_number PARAMS ((int));
90 yylex PARAMS ((void));
93 yyerror PARAMS ((char *));
96 yyparse PARAMS ((void));
98 /* The sign of the number being parsed. */
101 /* The block that the module specified by the qualifer on an identifer is
103 struct block *modblock=0;
105 /* #define YYDEBUG 1 */
108 /* Although the yacc "value" of an expression is not used,
109 since the result is stored in the structure being created,
110 other node types do have values. */
115 unsigned LONGEST ulval;
122 enum exp_opcode opcode;
123 struct internalvar *ivar;
129 %type <voidval> exp type_exp start set
130 %type <voidval> variable
135 %token <lval> INT HEX ERROR
136 %token <ulval> UINT M2_TRUE M2_FALSE CHAR
139 /* Both NAME and TYPENAME tokens represent symbols in the input,
140 and both convey their data as strings.
141 But a TYPENAME is a string that happens to be defined as a typedef
142 or builtin type name (such as int or char)
143 and a NAME is any other symbol.
145 Contexts where this distinction is not important can use the
146 nonterminal "name", which matches either NAME or TYPENAME. */
149 %token <sval> NAME BLOCKNAME IDENT VARNAME
150 %token <sval> TYPENAME
152 %token SIZE CAP ORD HIGH ABS MIN_FUNC MAX_FUNC FLOAT_FUNC VAL CHR ODD TRUNC
153 %token INC DEC INCL EXCL
155 /* The GDB scope operator */
158 %token <lval> LAST REGNAME
160 %token <ivar> INTERNAL_VAR
166 %left '<' '>' LEQ GEQ '=' NOTEQUAL '#' IN
171 %left '*' '/' DIV MOD
173 %right '^' DOT '[' '('
176 /* This is not an actual token ; it is used for precedence.
181 /* Ensure that if the generated parser contains any calls to malloc/realloc,
182 that they get mapped to xmalloc/xrealloc. We have to do this here
183 rather than earlier in the file because this is the first point after
184 the place where the SVR4 yacc includes <malloc.h>, and if we do it
185 before that, then the remapped declarations in <malloc.h> will collide
186 with the ones in "defs.h". */
188 #define malloc xmalloc
189 #define realloc xrealloc
199 { write_exp_elt_opcode(OP_TYPE);
200 write_exp_elt_type($1);
201 write_exp_elt_opcode(OP_TYPE);
207 exp : exp '^' %prec UNARY
208 { write_exp_elt_opcode (UNOP_IND); }
211 { number_sign = -1; }
214 write_exp_elt_opcode (UNOP_NEG); }
217 exp : '+' exp %prec UNARY
218 { write_exp_elt_opcode(UNOP_PLUS); }
221 exp : not_exp exp %prec UNARY
222 { write_exp_elt_opcode (UNOP_ZEROP); }
229 exp : CAP '(' exp ')'
230 { write_exp_elt_opcode (UNOP_CAP); }
233 exp : ORD '(' exp ')'
234 { write_exp_elt_opcode (UNOP_ORD); }
237 exp : ABS '(' exp ')'
238 { write_exp_elt_opcode (UNOP_ABS); }
241 exp : HIGH '(' exp ')'
242 { write_exp_elt_opcode (UNOP_HIGH); }
245 exp : MIN_FUNC '(' type ')'
246 { write_exp_elt_opcode (UNOP_MIN);
247 write_exp_elt_type ($3);
248 write_exp_elt_opcode (UNOP_MIN); }
251 exp : MAX_FUNC '(' type ')'
252 { write_exp_elt_opcode (UNOP_MAX);
253 write_exp_elt_type ($3);
254 write_exp_elt_opcode (UNOP_MIN); }
257 exp : FLOAT_FUNC '(' exp ')'
258 { write_exp_elt_opcode (UNOP_FLOAT); }
261 exp : VAL '(' type ',' exp ')'
262 { write_exp_elt_opcode (BINOP_VAL);
263 write_exp_elt_type ($3);
264 write_exp_elt_opcode (BINOP_VAL); }
267 exp : CHR '(' exp ')'
268 { write_exp_elt_opcode (UNOP_CHR); }
271 exp : ODD '(' exp ')'
272 { write_exp_elt_opcode (UNOP_ODD); }
275 exp : TRUNC '(' exp ')'
276 { write_exp_elt_opcode (UNOP_TRUNC); }
279 exp : SIZE exp %prec UNARY
280 { write_exp_elt_opcode (UNOP_SIZEOF); }
284 exp : INC '(' exp ')'
285 { write_exp_elt_opcode(UNOP_PREINCREMENT); }
288 exp : INC '(' exp ',' exp ')'
289 { write_exp_elt_opcode(BINOP_ASSIGN_MODIFY);
290 write_exp_elt_opcode(BINOP_ADD);
291 write_exp_elt_opcode(BINOP_ASSIGN_MODIFY); }
294 exp : DEC '(' exp ')'
295 { write_exp_elt_opcode(UNOP_PREDECREMENT);}
298 exp : DEC '(' exp ',' exp ')'
299 { write_exp_elt_opcode(BINOP_ASSIGN_MODIFY);
300 write_exp_elt_opcode(BINOP_SUB);
301 write_exp_elt_opcode(BINOP_ASSIGN_MODIFY); }
305 { write_exp_elt_opcode (STRUCTOP_STRUCT);
306 write_exp_string ($3);
307 write_exp_elt_opcode (STRUCTOP_STRUCT); }
314 { error("Sets are not implemented.");}
317 exp : INCL '(' exp ',' exp ')'
318 { error("Sets are not implemented.");}
321 exp : EXCL '(' exp ',' exp ')'
322 { error("Sets are not implemented.");}
324 set : '{' arglist '}'
325 { error("Sets are not implemented.");}
326 | type '{' arglist '}'
327 { error("Sets are not implemented.");}
331 /* Modula-2 array subscript notation [a,b,c...] */
333 /* This function just saves the number of arguments
334 that follow in the list. It is *not* specific to
337 non_empty_arglist ']' %prec DOT
338 { write_exp_elt_opcode (BINOP_MULTI_SUBSCRIPT);
339 write_exp_elt_longcst ((LONGEST) end_arglist());
340 write_exp_elt_opcode (BINOP_MULTI_SUBSCRIPT); }
344 /* This is to save the value of arglist_len
345 being accumulated by an outer function call. */
346 { start_arglist (); }
347 arglist ')' %prec DOT
348 { write_exp_elt_opcode (OP_FUNCALL);
349 write_exp_elt_longcst ((LONGEST) end_arglist ());
350 write_exp_elt_opcode (OP_FUNCALL); }
360 arglist : arglist ',' exp %prec ABOVE_COMMA
370 : non_empty_arglist ',' exp %prec ABOVE_COMMA
375 exp : '{' type '}' exp %prec UNARY
376 { write_exp_elt_opcode (UNOP_MEMVAL);
377 write_exp_elt_type ($2);
378 write_exp_elt_opcode (UNOP_MEMVAL); }
381 exp : type '(' exp ')' %prec UNARY
382 { write_exp_elt_opcode (UNOP_CAST);
383 write_exp_elt_type ($1);
384 write_exp_elt_opcode (UNOP_CAST); }
391 /* Binary operators in order of decreasing precedence. Note that some
392 of these operators are overloaded! (ie. sets) */
396 { write_exp_elt_opcode (BINOP_REPEAT); }
400 { write_exp_elt_opcode (BINOP_MUL); }
404 { write_exp_elt_opcode (BINOP_DIV); }
408 { write_exp_elt_opcode (BINOP_INTDIV); }
412 { write_exp_elt_opcode (BINOP_REM); }
416 { write_exp_elt_opcode (BINOP_ADD); }
420 { write_exp_elt_opcode (BINOP_SUB); }
424 { write_exp_elt_opcode (BINOP_EQUAL); }
427 exp : exp NOTEQUAL exp
428 { write_exp_elt_opcode (BINOP_NOTEQUAL); }
430 { write_exp_elt_opcode (BINOP_NOTEQUAL); }
434 { write_exp_elt_opcode (BINOP_LEQ); }
438 { write_exp_elt_opcode (BINOP_GEQ); }
442 { write_exp_elt_opcode (BINOP_LESS); }
446 { write_exp_elt_opcode (BINOP_GTR); }
450 { write_exp_elt_opcode (BINOP_AND); }
454 { write_exp_elt_opcode (BINOP_AND); }
458 { write_exp_elt_opcode (BINOP_OR); }
462 { write_exp_elt_opcode (BINOP_ASSIGN); }
469 { write_exp_elt_opcode (OP_BOOL);
470 write_exp_elt_longcst ((LONGEST) $1);
471 write_exp_elt_opcode (OP_BOOL); }
475 { write_exp_elt_opcode (OP_BOOL);
476 write_exp_elt_longcst ((LONGEST) $1);
477 write_exp_elt_opcode (OP_BOOL); }
481 { write_exp_elt_opcode (OP_LONG);
482 write_exp_elt_type (builtin_type_m2_int);
483 write_exp_elt_longcst ((LONGEST) $1);
484 write_exp_elt_opcode (OP_LONG); }
489 write_exp_elt_opcode (OP_LONG);
490 write_exp_elt_type (builtin_type_m2_card);
491 write_exp_elt_longcst ((LONGEST) $1);
492 write_exp_elt_opcode (OP_LONG);
497 { write_exp_elt_opcode (OP_LONG);
498 write_exp_elt_type (builtin_type_m2_char);
499 write_exp_elt_longcst ((LONGEST) $1);
500 write_exp_elt_opcode (OP_LONG); }
505 { write_exp_elt_opcode (OP_DOUBLE);
506 write_exp_elt_type (builtin_type_m2_real);
507 write_exp_elt_dblcst ($1);
508 write_exp_elt_opcode (OP_DOUBLE); }
514 /* The GDB internal variable $$, et al. */
516 { write_exp_elt_opcode (OP_LAST);
517 write_exp_elt_longcst ((LONGEST) $1);
518 write_exp_elt_opcode (OP_LAST); }
522 { write_exp_elt_opcode (OP_REGISTER);
523 write_exp_elt_longcst ((LONGEST) $1);
524 write_exp_elt_opcode (OP_REGISTER); }
527 exp : SIZE '(' type ')' %prec UNARY
528 { write_exp_elt_opcode (OP_LONG);
529 write_exp_elt_type (builtin_type_int);
530 write_exp_elt_longcst ((LONGEST) TYPE_LENGTH ($3));
531 write_exp_elt_opcode (OP_LONG); }
535 { write_exp_elt_opcode (OP_M2_STRING);
536 write_exp_string ($1);
537 write_exp_elt_opcode (OP_M2_STRING); }
540 /* This will be used for extensions later. Like adding modules. */
542 { $$ = SYMBOL_BLOCK_VALUE($1); }
547 = lookup_symbol (copy_name ($1), expression_context_block,
548 VAR_NAMESPACE, 0, NULL);
553 /* GDB scope operator */
554 fblock : block COLONCOLON BLOCKNAME
556 = lookup_symbol (copy_name ($3), $1,
557 VAR_NAMESPACE, 0, NULL);
558 if (!tem || SYMBOL_CLASS (tem) != LOC_BLOCK)
559 error ("No function \"%s\" in specified context.",
565 /* Useful for assigning to PROCEDURE variables */
567 { write_exp_elt_opcode(OP_VAR_VALUE);
568 write_exp_elt_sym ($1);
569 write_exp_elt_opcode (OP_VAR_VALUE); }
572 /* GDB internal ($foo) variable */
573 variable: INTERNAL_VAR
574 { write_exp_elt_opcode (OP_INTERNALVAR);
575 write_exp_elt_intern ($1);
576 write_exp_elt_opcode (OP_INTERNALVAR); }
579 /* GDB scope operator */
580 variable: block COLONCOLON NAME
581 { struct symbol *sym;
582 sym = lookup_symbol (copy_name ($3), $1,
583 VAR_NAMESPACE, 0, NULL);
585 error ("No symbol \"%s\" in specified context.",
588 write_exp_elt_opcode (OP_VAR_VALUE);
589 write_exp_elt_sym (sym);
590 write_exp_elt_opcode (OP_VAR_VALUE); }
593 /* Base case for variables. */
595 { struct symbol *sym;
596 int is_a_field_of_this;
598 sym = lookup_symbol (copy_name ($1),
599 expression_context_block,
613 if (innermost_block == 0 ||
614 contained_in (block_found,
616 innermost_block = block_found;
623 case LOC_LABEL: /* maybe should go above? */
625 case LOC_CONST_BYTES:
626 /* These are listed so gcc -Wall will reveal
630 write_exp_elt_opcode (OP_VAR_VALUE);
631 write_exp_elt_sym (sym);
632 write_exp_elt_opcode (OP_VAR_VALUE);
636 struct minimal_symbol *msymbol;
637 register char *arg = copy_name ($1);
639 msymbol = lookup_minimal_symbol (arg,
640 (struct objfile *) NULL);
643 write_exp_elt_opcode (OP_LONG);
644 write_exp_elt_type (builtin_type_int);
645 write_exp_elt_longcst ((LONGEST) msymbol -> address);
646 write_exp_elt_opcode (OP_LONG);
647 write_exp_elt_opcode (UNOP_MEMVAL);
648 if (msymbol -> type == mst_data ||
649 msymbol -> type == mst_bss)
650 write_exp_elt_type (builtin_type_int);
651 else if (msymbol -> type == mst_text)
652 write_exp_elt_type (lookup_function_type (builtin_type_int));
654 write_exp_elt_type (builtin_type_char);
655 write_exp_elt_opcode (UNOP_MEMVAL);
657 else if (!have_full_symbols () && !have_partial_symbols ())
658 error ("No symbol table is loaded. Use the \"symbol-file\" command.");
660 error ("No symbol \"%s\" in current context.",
668 { $$ = lookup_typename (copy_name ($1),
669 expression_context_block, 0); }
680 return (MAX_OF_TYPE(builtin_type_m2_int) - b) < a;
687 return (MAX_OF_TYPE(builtin_type_m2_card) - b) < a;
691 /* Take care of parsing a number (anything that starts with a digit).
692 Set yylval and return the token type; update lexptr.
693 LEN is the number of characters in it. */
695 /*** Needs some error checking for the float case ***/
701 register char *p = lexptr;
702 register LONGEST n = 0;
703 register LONGEST prevn = 0;
704 register int c,i,ischar=0;
705 register int base = input_radix;
706 register int len = olen;
707 int unsigned_p = number_sign == 1 ? 1 : 0;
714 else if(p[len-1] == 'C' || p[len-1] == 'B')
717 ischar = p[len-1] == 'C';
721 /* Scan the number */
722 for (c = 0; c < len; c++)
724 if (p[c] == '.' && base == 10)
726 /* It's a float since it contains a point. */
727 yylval.dval = atof (p);
731 if (p[c] == '.' && base != 10)
732 error("Floating point numbers must be base 10.");
733 if (base == 10 && (p[c] < '0' || p[c] > '9'))
734 error("Invalid digit \'%c\' in number.",p[c]);
741 if( base == 8 && (c == '8' || c == '9'))
742 error("Invalid digit \'%c\' in octal number.",c);
743 if (c >= '0' && c <= '9')
747 if (base == 16 && c >= 'A' && c <= 'F')
755 if(!unsigned_p && number_sign == 1 && (prevn >= n))
756 unsigned_p=1; /* Try something unsigned */
757 /* Don't do the range check if n==i and i==0, since that special
758 case will give an overflow error. */
759 if(RANGE_CHECK && n!=i && i)
761 if((unsigned_p && (unsigned)prevn >= (unsigned)n) ||
762 ((!unsigned_p && number_sign==-1) && -prevn <= -n))
763 range_error("Overflow on numeric constant.");
769 if(*p == 'B' || *p == 'C' || *p == 'H')
770 lexptr++; /* Advance past B,C or H */
777 else if ( unsigned_p && number_sign == 1)
782 else if((unsigned_p && (n<0))) {
783 range_error("Overflow on numeric constant -- number too large.");
784 /* But, this can return if range_check == range_warn. */
799 { {'<', '>'}, NOTEQUAL },
800 { {':', '='}, ASSIGN },
803 { {':', ':'}, COLONCOLON },
807 /* Some specific keywords */
814 static struct keyword keytab[] =
817 {"IN", IN },/* Note space after IN */
836 {"FLOAT", FLOAT_FUNC },
841 /* Read one token, getting characters through lexptr. */
843 /* This is where we will check to make sure that the language and the operators used are
850 register int namelen;
852 register char *tokstart;
860 /* See if it is a special token of length 2 */
861 for( i = 0 ; i < sizeof tokentab2 / sizeof tokentab2[0] ; i++)
862 if(!strncmp(tokentab2[i].name, tokstart, 2))
865 return tokentab2[i].token;
868 switch (c = *tokstart)
885 if (paren_depth == 0)
892 if (comma_terminates && paren_depth == 0)
898 /* Might be a floating point number. */
899 if (lexptr[1] >= '0' && lexptr[1] <= '9')
900 break; /* Falls into number code. */
907 /* These are character tokens that appear as-is in the YACC grammar */
930 for (namelen = 1; (c = tokstart[namelen]) != quote && c != '\0'; namelen++)
933 c = tokstart[++namelen];
934 if (c >= '0' && c <= '9')
936 c = tokstart[++namelen];
937 if (c >= '0' && c <= '9')
938 c = tokstart[++namelen];
942 error("Unterminated string or character constant.");
943 yylval.sval.ptr = tokstart + 1;
944 yylval.sval.length = namelen - 1;
945 lexptr += namelen + 1;
947 if(namelen == 2) /* Single character */
949 yylval.ulval = tokstart[1];
956 /* Is it a number? */
957 /* Note: We have already dealt with the case of the token '.'.
958 See case '.' above. */
959 if ((c >= '0' && c <= '9'))
962 int got_dot = 0, got_e = 0;
963 register char *p = tokstart;
968 if (!got_e && (*p == 'e' || *p == 'E'))
970 else if (!got_dot && *p == '.')
972 else if (got_e && (p[-1] == 'e' || p[-1] == 'E')
973 && (*p == '-' || *p == '+'))
974 /* This is the sign of the exponent, not the end of the
977 else if ((*p < '0' || *p > '9') &&
978 (*p < 'A' || *p > 'F') &&
979 (*p != 'H')) /* Modula-2 hexadecimal number */
982 toktype = parse_number (p - tokstart);
983 if (toktype == ERROR)
985 char *err_copy = (char *) alloca (p - tokstart + 1);
987 memcpy (err_copy, tokstart, p - tokstart);
988 err_copy[p - tokstart] = 0;
989 error ("Invalid number \"%s\".", err_copy);
995 if (!(c == '_' || c == '$'
996 || (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z')))
997 /* We must have come across a bad character (e.g. ';'). */
998 error ("Invalid character '%c' in expression.", c);
1000 /* It's a name. See how long it is. */
1002 for (c = tokstart[namelen];
1003 (c == '_' || c == '$' || (c >= '0' && c <= '9')
1004 || (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z'));
1005 c = tokstart[++namelen])
1008 /* The token "if" terminates the expression and is NOT
1009 removed from the input stream. */
1010 if (namelen == 2 && tokstart[0] == 'i' && tokstart[1] == 'f')
1017 /* Handle the tokens $digits; also $ (short for $0) and $$ (short for $$1)
1018 and $$digits (equivalent to $<-digits> if you could type that).
1019 Make token type LAST, and put the number (the digits) in yylval. */
1021 if (*tokstart == '$')
1023 register int negate = 0;
1025 /* Double dollar means negate the number and add -1 as well.
1026 Thus $$ alone means -1. */
1027 if (namelen >= 2 && tokstart[1] == '$')
1034 /* Just dollars (one or two) */
1035 yylval.lval = - negate;
1038 /* Is the rest of the token digits? */
1039 for (; c < namelen; c++)
1040 if (!(tokstart[c] >= '0' && tokstart[c] <= '9'))
1044 yylval.lval = atoi (tokstart + 1 + negate);
1046 yylval.lval = - yylval.lval;
1051 /* Handle tokens that refer to machine registers:
1052 $ followed by a register name. */
1054 if (*tokstart == '$') {
1055 for (c = 0; c < NUM_REGS; c++)
1056 if (namelen - 1 == strlen (reg_names[c])
1057 && !strncmp (tokstart + 1, reg_names[c], namelen - 1))
1062 for (c = 0; c < num_std_regs; c++)
1063 if (namelen - 1 == strlen (std_regs[c].name)
1064 && !strncmp (tokstart + 1, std_regs[c].name, namelen - 1))
1066 yylval.lval = std_regs[c].regnum;
1072 /* Lookup special keywords */
1073 for(i = 0 ; i < sizeof(keytab) / sizeof(keytab[0]) ; i++)
1074 if(namelen == strlen(keytab[i].keyw) && !strncmp(tokstart,keytab[i].keyw,namelen))
1075 return keytab[i].token;
1077 yylval.sval.ptr = tokstart;
1078 yylval.sval.length = namelen;
1080 /* Any other names starting in $ are debugger internal variables. */
1082 if (*tokstart == '$')
1084 yylval.ivar = (struct internalvar *) lookup_internalvar (copy_name (yylval.sval) + 1);
1085 return INTERNAL_VAR;
1089 /* Use token-type BLOCKNAME for symbols that happen to be defined as
1090 functions. If this is not so, then ...
1091 Use token-type TYPENAME for symbols that happen to be defined
1092 currently as names of types; NAME for other symbols.
1093 The caller is not constrained to care about the distinction. */
1097 char *tmp = copy_name (yylval.sval);
1100 if (lookup_partial_symtab (tmp))
1102 sym = lookup_symbol (tmp, expression_context_block,
1103 VAR_NAMESPACE, 0, NULL);
1104 if (sym && SYMBOL_CLASS (sym) == LOC_BLOCK)
1106 if (lookup_typename (copy_name (yylval.sval), expression_context_block, 1))
1121 case LOC_CONST_BYTES:
1131 error("internal: Undefined class in m2lex()");
1134 error("internal: Unforseen case in m2lex()");
1139 /* Built-in BOOLEAN type. This is sort of a hack. */
1140 if(!strncmp(tokstart,"TRUE",4))
1145 else if(!strncmp(tokstart,"FALSE",5))
1152 /* Must be another type of name... */
1159 make_qualname(mod,ident)
1162 char *new = xmalloc(strlen(mod)+strlen(ident)+2);
1173 char *msg; /* unused */
1175 printf("Parsing: %s\n",lexptr);
1177 error("Invalid syntax in expression near character '%c'.",yychar);
1179 error("Invalid syntax in expression");
1182 /* Table of operators and their precedences for printing expressions. */
1184 const static struct op_print m2_op_print_tab[] = {
1185 {"+", BINOP_ADD, PREC_ADD, 0},
1186 {"+", UNOP_PLUS, PREC_PREFIX, 0},
1187 {"-", BINOP_SUB, PREC_ADD, 0},
1188 {"-", UNOP_NEG, PREC_PREFIX, 0},
1189 {"*", BINOP_MUL, PREC_MUL, 0},
1190 {"/", BINOP_DIV, PREC_MUL, 0},
1191 {"DIV", BINOP_INTDIV, PREC_MUL, 0},
1192 {"MOD", BINOP_REM, PREC_MUL, 0},
1193 {":=", BINOP_ASSIGN, PREC_ASSIGN, 1},
1194 {"OR", BINOP_OR, PREC_OR, 0},
1195 {"AND", BINOP_AND, PREC_AND, 0},
1196 {"NOT", UNOP_ZEROP, PREC_PREFIX, 0},
1197 {"=", BINOP_EQUAL, PREC_EQUAL, 0},
1198 {"<>", BINOP_NOTEQUAL, PREC_EQUAL, 0},
1199 {"<=", BINOP_LEQ, PREC_ORDER, 0},
1200 {">=", BINOP_GEQ, PREC_ORDER, 0},
1201 {">", BINOP_GTR, PREC_ORDER, 0},
1202 {"<", BINOP_LESS, PREC_ORDER, 0},
1203 {"^", UNOP_IND, PREC_PREFIX, 0},
1204 {"@", BINOP_REPEAT, PREC_REPEAT, 0},
1207 /* The built-in types of Modula-2. */
1209 struct type *builtin_type_m2_char;
1210 struct type *builtin_type_m2_int;
1211 struct type *builtin_type_m2_card;
1212 struct type *builtin_type_m2_real;
1213 struct type *builtin_type_m2_bool;
1215 struct type ** const (m2_builtin_types[]) =
1217 &builtin_type_m2_char,
1218 &builtin_type_m2_int,
1219 &builtin_type_m2_card,
1220 &builtin_type_m2_real,
1221 &builtin_type_m2_bool,
1225 const struct language_defn m2_language_defn = {
1231 m2_parse, /* parser */
1232 m2_error, /* parser error function */
1233 &builtin_type_m2_int, /* longest signed integral type */
1234 &builtin_type_m2_card, /* longest unsigned integral type */
1235 &builtin_type_m2_real, /* longest floating point type */
1236 "0%XH", "0%", "XH", /* Hex format string, prefix, suffix */
1237 "%oB", "%", "oB", /* Octal format string, prefix, suffix */
1238 m2_op_print_tab, /* expression operators for printing */
1242 /* Initialization for Modula-2 */
1245 _initialize_m2_exp ()
1247 /* Modula-2 "pervasive" types. NOTE: these can be redefined!!! */
1248 builtin_type_m2_int =
1249 init_type (TYPE_CODE_INT, TARGET_INT_BIT / TARGET_CHAR_BIT,
1251 "INTEGER", (struct objfile *) NULL);
1252 builtin_type_m2_card =
1253 init_type (TYPE_CODE_INT, TARGET_INT_BIT / TARGET_CHAR_BIT,
1255 "CARDINAL", (struct objfile *) NULL);
1256 builtin_type_m2_real =
1257 init_type (TYPE_CODE_FLT, TARGET_FLOAT_BIT / TARGET_CHAR_BIT,
1259 "REAL", (struct objfile *) NULL);
1260 builtin_type_m2_char =
1261 init_type (TYPE_CODE_CHAR, TARGET_CHAR_BIT / TARGET_CHAR_BIT,
1263 "CHAR", (struct objfile *) NULL);
1264 builtin_type_m2_bool =
1265 init_type (TYPE_CODE_BOOL, TARGET_INT_BIT / TARGET_CHAR_BIT,
1267 "BOOLEAN", (struct objfile *) NULL);
1269 TYPE_NFIELDS(builtin_type_m2_bool) = 2;
1270 TYPE_FIELDS(builtin_type_m2_bool) =
1271 (struct field *) malloc (sizeof (struct field) * 2);
1272 TYPE_FIELD_BITPOS(builtin_type_m2_bool,0) = 0;
1273 TYPE_FIELD_NAME(builtin_type_m2_bool,0) = (char *)malloc(6);
1274 strcpy(TYPE_FIELD_NAME(builtin_type_m2_bool,0),"FALSE");
1275 TYPE_FIELD_BITPOS(builtin_type_m2_bool,1) = 1;
1276 TYPE_FIELD_NAME(builtin_type_m2_bool,1) = (char *)malloc(5);
1277 strcpy(TYPE_FIELD_NAME(builtin_type_m2_bool,1),"TRUE");
1279 add_language (&m2_language_defn);