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 */
107 /* !@&%ing AIX defines these! Prevent cpp complaints by undeffing them */
112 /* Although the yacc "value" of an expression is not used,
113 since the result is stored in the structure being created,
114 other node types do have values. */
119 unsigned LONGEST ulval;
126 enum exp_opcode opcode;
127 struct internalvar *ivar;
133 %type <voidval> exp type_exp start set
134 %type <voidval> variable
139 %token <lval> INT HEX ERROR
140 %token <ulval> UINT TRUE FALSE CHAR
143 /* Both NAME and TYPENAME tokens represent symbols in the input,
144 and both convey their data as strings.
145 But a TYPENAME is a string that happens to be defined as a typedef
146 or builtin type name (such as int or char)
147 and a NAME is any other symbol.
149 Contexts where this distinction is not important can use the
150 nonterminal "name", which matches either NAME or TYPENAME. */
153 %token <sval> NAME BLOCKNAME IDENT VARNAME
154 %token <sval> TYPENAME
156 %token SIZE CAP ORD HIGH ABS MIN_FUNC MAX_FUNC FLOAT_FUNC VAL CHR ODD TRUNC
157 %token INC DEC INCL EXCL
159 /* The GDB scope operator */
162 %token <lval> LAST REGNAME
164 %token <ivar> INTERNAL_VAR
170 %left '<' '>' LEQ GEQ '=' NOTEQUAL '#' IN
175 %left '*' '/' DIV MOD
177 %right '^' DOT '[' '('
180 /* This is not an actual token ; it is used for precedence.
186 /* Ensure that if the generated parser contains any calls to malloc/realloc,
187 that they get mapped to xmalloc/xrealloc. We have to do this here
188 rather than earlier in the file because this is the first point after
189 the place where the SVR4 yacc includes <malloc.h>, and if we do it
190 before that, then the remapped declarations in <malloc.h> will collide
191 with the ones in "defs.h". */
193 #define malloc xmalloc
194 #define realloc xrealloc
202 { write_exp_elt_opcode(OP_TYPE);
203 write_exp_elt_type($1);
204 write_exp_elt_opcode(OP_TYPE);
210 exp : exp '^' %prec UNARY
211 { write_exp_elt_opcode (UNOP_IND); }
214 { number_sign = -1; }
217 write_exp_elt_opcode (UNOP_NEG); }
220 exp : '+' exp %prec UNARY
221 { write_exp_elt_opcode(UNOP_PLUS); }
224 exp : not_exp exp %prec UNARY
225 { write_exp_elt_opcode (UNOP_ZEROP); }
232 exp : CAP '(' exp ')'
233 { write_exp_elt_opcode (UNOP_CAP); }
236 exp : ORD '(' exp ')'
237 { write_exp_elt_opcode (UNOP_ORD); }
240 exp : ABS '(' exp ')'
241 { write_exp_elt_opcode (UNOP_ABS); }
244 exp : HIGH '(' exp ')'
245 { write_exp_elt_opcode (UNOP_HIGH); }
248 exp : MIN_FUNC '(' type ')'
249 { write_exp_elt_opcode (UNOP_MIN);
250 write_exp_elt_type ($3);
251 write_exp_elt_opcode (UNOP_MIN); }
254 exp : MAX_FUNC '(' type ')'
255 { write_exp_elt_opcode (UNOP_MAX);
256 write_exp_elt_type ($3);
257 write_exp_elt_opcode (UNOP_MIN); }
260 exp : FLOAT_FUNC '(' exp ')'
261 { write_exp_elt_opcode (UNOP_FLOAT); }
264 exp : VAL '(' type ',' exp ')'
265 { write_exp_elt_opcode (BINOP_VAL);
266 write_exp_elt_type ($3);
267 write_exp_elt_opcode (BINOP_VAL); }
270 exp : CHR '(' exp ')'
271 { write_exp_elt_opcode (UNOP_CHR); }
274 exp : ODD '(' exp ')'
275 { write_exp_elt_opcode (UNOP_ODD); }
278 exp : TRUNC '(' exp ')'
279 { write_exp_elt_opcode (UNOP_TRUNC); }
282 exp : SIZE exp %prec UNARY
283 { write_exp_elt_opcode (UNOP_SIZEOF); }
287 exp : INC '(' exp ')'
288 { write_exp_elt_opcode(UNOP_PREINCREMENT); }
291 exp : INC '(' exp ',' exp ')'
292 { write_exp_elt_opcode(BINOP_ASSIGN_MODIFY);
293 write_exp_elt_opcode(BINOP_ADD);
294 write_exp_elt_opcode(BINOP_ASSIGN_MODIFY); }
297 exp : DEC '(' exp ')'
298 { write_exp_elt_opcode(UNOP_PREDECREMENT);}
301 exp : DEC '(' exp ',' exp ')'
302 { write_exp_elt_opcode(BINOP_ASSIGN_MODIFY);
303 write_exp_elt_opcode(BINOP_SUB);
304 write_exp_elt_opcode(BINOP_ASSIGN_MODIFY); }
308 { write_exp_elt_opcode (STRUCTOP_STRUCT);
309 write_exp_string ($3);
310 write_exp_elt_opcode (STRUCTOP_STRUCT); }
317 { error("Sets are not implemented.");}
320 exp : INCL '(' exp ',' exp ')'
321 { error("Sets are not implemented.");}
324 exp : EXCL '(' exp ',' exp ')'
325 { error("Sets are not implemented.");}
327 set : '{' arglist '}'
328 { error("Sets are not implemented.");}
329 | type '{' arglist '}'
330 { error("Sets are not implemented.");}
334 /* Modula-2 array subscript notation [a,b,c...] */
336 /* This function just saves the number of arguments
337 that follow in the list. It is *not* specific to
340 non_empty_arglist ']' %prec DOT
341 { write_exp_elt_opcode (BINOP_MULTI_SUBSCRIPT);
342 write_exp_elt_longcst ((LONGEST) end_arglist());
343 write_exp_elt_opcode (BINOP_MULTI_SUBSCRIPT); }
347 /* This is to save the value of arglist_len
348 being accumulated by an outer function call. */
349 { start_arglist (); }
350 arglist ')' %prec DOT
351 { write_exp_elt_opcode (OP_FUNCALL);
352 write_exp_elt_longcst ((LONGEST) end_arglist ());
353 write_exp_elt_opcode (OP_FUNCALL); }
363 arglist : arglist ',' exp %prec ABOVE_COMMA
373 : non_empty_arglist ',' exp %prec ABOVE_COMMA
378 exp : '{' type '}' exp %prec UNARY
379 { write_exp_elt_opcode (UNOP_MEMVAL);
380 write_exp_elt_type ($2);
381 write_exp_elt_opcode (UNOP_MEMVAL); }
384 exp : type '(' exp ')' %prec UNARY
385 { write_exp_elt_opcode (UNOP_CAST);
386 write_exp_elt_type ($1);
387 write_exp_elt_opcode (UNOP_CAST); }
394 /* Binary operators in order of decreasing precedence. Note that some
395 of these operators are overloaded! (ie. sets) */
399 { write_exp_elt_opcode (BINOP_REPEAT); }
403 { write_exp_elt_opcode (BINOP_MUL); }
407 { write_exp_elt_opcode (BINOP_DIV); }
411 { write_exp_elt_opcode (BINOP_INTDIV); }
415 { write_exp_elt_opcode (BINOP_REM); }
419 { write_exp_elt_opcode (BINOP_ADD); }
423 { write_exp_elt_opcode (BINOP_SUB); }
427 { write_exp_elt_opcode (BINOP_EQUAL); }
430 exp : exp NOTEQUAL exp
431 { write_exp_elt_opcode (BINOP_NOTEQUAL); }
433 { write_exp_elt_opcode (BINOP_NOTEQUAL); }
437 { write_exp_elt_opcode (BINOP_LEQ); }
441 { write_exp_elt_opcode (BINOP_GEQ); }
445 { write_exp_elt_opcode (BINOP_LESS); }
449 { write_exp_elt_opcode (BINOP_GTR); }
453 { write_exp_elt_opcode (BINOP_AND); }
457 { write_exp_elt_opcode (BINOP_AND); }
461 { write_exp_elt_opcode (BINOP_OR); }
465 { write_exp_elt_opcode (BINOP_ASSIGN); }
472 { write_exp_elt_opcode (OP_BOOL);
473 write_exp_elt_longcst ((LONGEST) $1);
474 write_exp_elt_opcode (OP_BOOL); }
478 { write_exp_elt_opcode (OP_BOOL);
479 write_exp_elt_longcst ((LONGEST) $1);
480 write_exp_elt_opcode (OP_BOOL); }
484 { write_exp_elt_opcode (OP_LONG);
485 write_exp_elt_type (builtin_type_m2_int);
486 write_exp_elt_longcst ((LONGEST) $1);
487 write_exp_elt_opcode (OP_LONG); }
492 write_exp_elt_opcode (OP_LONG);
493 write_exp_elt_type (builtin_type_m2_card);
494 write_exp_elt_longcst ((LONGEST) $1);
495 write_exp_elt_opcode (OP_LONG);
500 { write_exp_elt_opcode (OP_LONG);
501 write_exp_elt_type (builtin_type_m2_char);
502 write_exp_elt_longcst ((LONGEST) $1);
503 write_exp_elt_opcode (OP_LONG); }
508 { write_exp_elt_opcode (OP_DOUBLE);
509 write_exp_elt_type (builtin_type_m2_real);
510 write_exp_elt_dblcst ($1);
511 write_exp_elt_opcode (OP_DOUBLE); }
517 /* The GDB internal variable $$, et al. */
519 { write_exp_elt_opcode (OP_LAST);
520 write_exp_elt_longcst ((LONGEST) $1);
521 write_exp_elt_opcode (OP_LAST); }
525 { write_exp_elt_opcode (OP_REGISTER);
526 write_exp_elt_longcst ((LONGEST) $1);
527 write_exp_elt_opcode (OP_REGISTER); }
530 exp : SIZE '(' type ')' %prec UNARY
531 { write_exp_elt_opcode (OP_LONG);
532 write_exp_elt_type (builtin_type_int);
533 write_exp_elt_longcst ((LONGEST) TYPE_LENGTH ($3));
534 write_exp_elt_opcode (OP_LONG); }
538 { write_exp_elt_opcode (OP_M2_STRING);
539 write_exp_string ($1);
540 write_exp_elt_opcode (OP_M2_STRING); }
543 /* This will be used for extensions later. Like adding modules. */
545 { $$ = SYMBOL_BLOCK_VALUE($1); }
550 = lookup_symbol (copy_name ($1), expression_context_block,
551 VAR_NAMESPACE, 0, NULL);
556 /* GDB scope operator */
557 fblock : block COLONCOLON BLOCKNAME
559 = lookup_symbol (copy_name ($3), $1,
560 VAR_NAMESPACE, 0, NULL);
561 if (!tem || SYMBOL_CLASS (tem) != LOC_BLOCK)
562 error ("No function \"%s\" in specified context.",
568 /* Useful for assigning to PROCEDURE variables */
570 { write_exp_elt_opcode(OP_VAR_VALUE);
571 write_exp_elt_sym ($1);
572 write_exp_elt_opcode (OP_VAR_VALUE); }
575 /* GDB internal ($foo) variable */
576 variable: INTERNAL_VAR
577 { write_exp_elt_opcode (OP_INTERNALVAR);
578 write_exp_elt_intern ($1);
579 write_exp_elt_opcode (OP_INTERNALVAR); }
582 /* GDB scope operator */
583 variable: block COLONCOLON NAME
584 { struct symbol *sym;
585 sym = lookup_symbol (copy_name ($3), $1,
586 VAR_NAMESPACE, 0, NULL);
588 error ("No symbol \"%s\" in specified context.",
591 write_exp_elt_opcode (OP_VAR_VALUE);
592 write_exp_elt_sym (sym);
593 write_exp_elt_opcode (OP_VAR_VALUE); }
596 /* Base case for variables. */
598 { struct symbol *sym;
599 int is_a_field_of_this;
601 sym = lookup_symbol (copy_name ($1),
602 expression_context_block,
616 if (innermost_block == 0 ||
617 contained_in (block_found,
619 innermost_block = block_found;
626 case LOC_LABEL: /* maybe should go above? */
628 case LOC_CONST_BYTES:
629 /* These are listed so gcc -Wall will reveal
633 write_exp_elt_opcode (OP_VAR_VALUE);
634 write_exp_elt_sym (sym);
635 write_exp_elt_opcode (OP_VAR_VALUE);
639 struct minimal_symbol *msymbol;
640 register char *arg = copy_name ($1);
642 msymbol = lookup_minimal_symbol (arg,
643 (struct objfile *) NULL);
646 write_exp_elt_opcode (OP_LONG);
647 write_exp_elt_type (builtin_type_int);
648 write_exp_elt_longcst ((LONGEST) msymbol -> address);
649 write_exp_elt_opcode (OP_LONG);
650 write_exp_elt_opcode (UNOP_MEMVAL);
651 if (msymbol -> type == mst_data ||
652 msymbol -> type == mst_bss)
653 write_exp_elt_type (builtin_type_int);
654 else if (msymbol -> type == mst_text)
655 write_exp_elt_type (lookup_function_type (builtin_type_int));
657 write_exp_elt_type (builtin_type_char);
658 write_exp_elt_opcode (UNOP_MEMVAL);
660 else if (!have_full_symbols () && !have_partial_symbols ())
661 error ("No symbol table is loaded. Use the \"symbol-file\" command.");
663 error ("No symbol \"%s\" in current context.",
671 { $$ = lookup_typename (copy_name ($1),
672 expression_context_block, 0); }
683 return (MAX_OF_TYPE(builtin_type_m2_int) - b) < a;
690 return (MAX_OF_TYPE(builtin_type_m2_card) - b) < a;
694 /* Take care of parsing a number (anything that starts with a digit).
695 Set yylval and return the token type; update lexptr.
696 LEN is the number of characters in it. */
698 /*** Needs some error checking for the float case ***/
704 register char *p = lexptr;
705 register LONGEST n = 0;
706 register LONGEST prevn = 0;
707 register int c,i,ischar=0;
708 register int base = input_radix;
709 register int len = olen;
710 int unsigned_p = number_sign == 1 ? 1 : 0;
717 else if(p[len-1] == 'C' || p[len-1] == 'B')
720 ischar = p[len-1] == 'C';
724 /* Scan the number */
725 for (c = 0; c < len; c++)
727 if (p[c] == '.' && base == 10)
729 /* It's a float since it contains a point. */
730 yylval.dval = atof (p);
734 if (p[c] == '.' && base != 10)
735 error("Floating point numbers must be base 10.");
736 if (base == 10 && (p[c] < '0' || p[c] > '9'))
737 error("Invalid digit \'%c\' in number.",p[c]);
744 if( base == 8 && (c == '8' || c == '9'))
745 error("Invalid digit \'%c\' in octal number.",c);
746 if (c >= '0' && c <= '9')
750 if (base == 16 && c >= 'A' && c <= 'F')
758 if(!unsigned_p && number_sign == 1 && (prevn >= n))
759 unsigned_p=1; /* Try something unsigned */
760 /* Don't do the range check if n==i and i==0, since that special
761 case will give an overflow error. */
762 if(RANGE_CHECK && n!=i && i)
764 if((unsigned_p && (unsigned)prevn >= (unsigned)n) ||
765 ((!unsigned_p && number_sign==-1) && -prevn <= -n))
766 range_error("Overflow on numeric constant.");
772 if(*p == 'B' || *p == 'C' || *p == 'H')
773 lexptr++; /* Advance past B,C or H */
780 else if ( unsigned_p && number_sign == 1)
785 else if((unsigned_p && (n<0))) {
786 range_error("Overflow on numeric constant -- number too large.");
787 /* But, this can return if range_check == range_warn. */
802 { {'<', '>'}, NOTEQUAL },
803 { {':', '='}, ASSIGN },
806 { {':', ':'}, COLONCOLON },
810 /* Some specific keywords */
817 static struct keyword keytab[] =
820 {"IN", IN },/* Note space after IN */
839 {"FLOAT", FLOAT_FUNC },
844 /* Read one token, getting characters through lexptr. */
846 /* This is where we will check to make sure that the language and the operators used are
853 register int namelen;
855 register char *tokstart;
863 /* See if it is a special token of length 2 */
864 for( i = 0 ; i < sizeof tokentab2 / sizeof tokentab2[0] ; i++)
865 if(!strncmp(tokentab2[i].name, tokstart, 2))
868 return tokentab2[i].token;
871 switch (c = *tokstart)
888 if (paren_depth == 0)
895 if (comma_terminates && paren_depth == 0)
901 /* Might be a floating point number. */
902 if (lexptr[1] >= '0' && lexptr[1] <= '9')
903 break; /* Falls into number code. */
910 /* These are character tokens that appear as-is in the YACC grammar */
933 for (namelen = 1; (c = tokstart[namelen]) != quote && c != '\0'; namelen++)
936 c = tokstart[++namelen];
937 if (c >= '0' && c <= '9')
939 c = tokstart[++namelen];
940 if (c >= '0' && c <= '9')
941 c = tokstart[++namelen];
945 error("Unterminated string or character constant.");
946 yylval.sval.ptr = tokstart + 1;
947 yylval.sval.length = namelen - 1;
948 lexptr += namelen + 1;
950 if(namelen == 2) /* Single character */
952 yylval.ulval = tokstart[1];
959 /* Is it a number? */
960 /* Note: We have already dealt with the case of the token '.'.
961 See case '.' above. */
962 if ((c >= '0' && c <= '9'))
965 int got_dot = 0, got_e = 0;
966 register char *p = tokstart;
971 if (!got_e && (*p == 'e' || *p == 'E'))
973 else if (!got_dot && *p == '.')
975 else if (got_e && (p[-1] == 'e' || p[-1] == 'E')
976 && (*p == '-' || *p == '+'))
977 /* This is the sign of the exponent, not the end of the
980 else if ((*p < '0' || *p > '9') &&
981 (*p < 'A' || *p > 'F') &&
982 (*p != 'H')) /* Modula-2 hexadecimal number */
985 toktype = parse_number (p - tokstart);
986 if (toktype == ERROR)
988 char *err_copy = (char *) alloca (p - tokstart + 1);
990 memcpy (err_copy, tokstart, p - tokstart);
991 err_copy[p - tokstart] = 0;
992 error ("Invalid number \"%s\".", err_copy);
998 if (!(c == '_' || c == '$'
999 || (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z')))
1000 /* We must have come across a bad character (e.g. ';'). */
1001 error ("Invalid character '%c' in expression.", c);
1003 /* It's a name. See how long it is. */
1005 for (c = tokstart[namelen];
1006 (c == '_' || c == '$' || (c >= '0' && c <= '9')
1007 || (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z'));
1008 c = tokstart[++namelen])
1011 /* The token "if" terminates the expression and is NOT
1012 removed from the input stream. */
1013 if (namelen == 2 && tokstart[0] == 'i' && tokstart[1] == 'f')
1020 /* Handle the tokens $digits; also $ (short for $0) and $$ (short for $$1)
1021 and $$digits (equivalent to $<-digits> if you could type that).
1022 Make token type LAST, and put the number (the digits) in yylval. */
1024 if (*tokstart == '$')
1026 register int negate = 0;
1028 /* Double dollar means negate the number and add -1 as well.
1029 Thus $$ alone means -1. */
1030 if (namelen >= 2 && tokstart[1] == '$')
1037 /* Just dollars (one or two) */
1038 yylval.lval = - negate;
1041 /* Is the rest of the token digits? */
1042 for (; c < namelen; c++)
1043 if (!(tokstart[c] >= '0' && tokstart[c] <= '9'))
1047 yylval.lval = atoi (tokstart + 1 + negate);
1049 yylval.lval = - yylval.lval;
1054 /* Handle tokens that refer to machine registers:
1055 $ followed by a register name. */
1057 if (*tokstart == '$') {
1058 for (c = 0; c < NUM_REGS; c++)
1059 if (namelen - 1 == strlen (reg_names[c])
1060 && !strncmp (tokstart + 1, reg_names[c], namelen - 1))
1065 for (c = 0; c < num_std_regs; c++)
1066 if (namelen - 1 == strlen (std_regs[c].name)
1067 && !strncmp (tokstart + 1, std_regs[c].name, namelen - 1))
1069 yylval.lval = std_regs[c].regnum;
1075 /* Lookup special keywords */
1076 for(i = 0 ; i < sizeof(keytab) / sizeof(keytab[0]) ; i++)
1077 if(namelen == strlen(keytab[i].keyw) && !strncmp(tokstart,keytab[i].keyw,namelen))
1078 return keytab[i].token;
1080 yylval.sval.ptr = tokstart;
1081 yylval.sval.length = namelen;
1083 /* Any other names starting in $ are debugger internal variables. */
1085 if (*tokstart == '$')
1087 yylval.ivar = (struct internalvar *) lookup_internalvar (copy_name (yylval.sval) + 1);
1088 return INTERNAL_VAR;
1092 /* Use token-type BLOCKNAME for symbols that happen to be defined as
1093 functions. If this is not so, then ...
1094 Use token-type TYPENAME for symbols that happen to be defined
1095 currently as names of types; NAME for other symbols.
1096 The caller is not constrained to care about the distinction. */
1100 char *tmp = copy_name (yylval.sval);
1103 if (lookup_partial_symtab (tmp))
1105 sym = lookup_symbol (tmp, expression_context_block,
1106 VAR_NAMESPACE, 0, NULL);
1107 if (sym && SYMBOL_CLASS (sym) == LOC_BLOCK)
1109 if (lookup_typename (copy_name (yylval.sval), expression_context_block, 1))
1124 case LOC_CONST_BYTES:
1134 error("internal: Undefined class in m2lex()");
1137 error("internal: Unforseen case in m2lex()");
1142 /* Built-in BOOLEAN type. This is sort of a hack. */
1143 if(!strncmp(tokstart,"TRUE",4))
1148 else if(!strncmp(tokstart,"FALSE",5))
1155 /* Must be another type of name... */
1162 make_qualname(mod,ident)
1165 char *new = xmalloc(strlen(mod)+strlen(ident)+2);
1176 char *msg; /* unused */
1178 printf("Parsing: %s\n",lexptr);
1180 error("Invalid syntax in expression near character '%c'.",yychar);
1182 error("Invalid syntax in expression");
1185 /* Table of operators and their precedences for printing expressions. */
1187 const static struct op_print m2_op_print_tab[] = {
1188 {"+", BINOP_ADD, PREC_ADD, 0},
1189 {"+", UNOP_PLUS, PREC_PREFIX, 0},
1190 {"-", BINOP_SUB, PREC_ADD, 0},
1191 {"-", UNOP_NEG, PREC_PREFIX, 0},
1192 {"*", BINOP_MUL, PREC_MUL, 0},
1193 {"/", BINOP_DIV, PREC_MUL, 0},
1194 {"DIV", BINOP_INTDIV, PREC_MUL, 0},
1195 {"MOD", BINOP_REM, PREC_MUL, 0},
1196 {":=", BINOP_ASSIGN, PREC_ASSIGN, 1},
1197 {"OR", BINOP_OR, PREC_OR, 0},
1198 {"AND", BINOP_AND, PREC_AND, 0},
1199 {"NOT", UNOP_ZEROP, PREC_PREFIX, 0},
1200 {"=", BINOP_EQUAL, PREC_EQUAL, 0},
1201 {"<>", BINOP_NOTEQUAL, PREC_EQUAL, 0},
1202 {"<=", BINOP_LEQ, PREC_ORDER, 0},
1203 {">=", BINOP_GEQ, PREC_ORDER, 0},
1204 {">", BINOP_GTR, PREC_ORDER, 0},
1205 {"<", BINOP_LESS, PREC_ORDER, 0},
1206 {"^", UNOP_IND, PREC_PREFIX, 0},
1207 {"@", BINOP_REPEAT, PREC_REPEAT, 0},
1210 /* The built-in types of Modula-2. */
1212 struct type *builtin_type_m2_char;
1213 struct type *builtin_type_m2_int;
1214 struct type *builtin_type_m2_card;
1215 struct type *builtin_type_m2_real;
1216 struct type *builtin_type_m2_bool;
1218 struct type ** const (m2_builtin_types[]) =
1220 &builtin_type_m2_char,
1221 &builtin_type_m2_int,
1222 &builtin_type_m2_card,
1223 &builtin_type_m2_real,
1224 &builtin_type_m2_bool,
1228 const struct language_defn m2_language_defn = {
1234 m2_parse, /* parser */
1235 m2_error, /* parser error function */
1236 &builtin_type_m2_int, /* longest signed integral type */
1237 &builtin_type_m2_card, /* longest unsigned integral type */
1238 &builtin_type_m2_real, /* longest floating point type */
1239 "0%XH", "0%", "XH", /* Hex format string, prefix, suffix */
1240 "%oB", "%", "oB", /* Octal format string, prefix, suffix */
1241 m2_op_print_tab, /* expression operators for printing */
1245 /* Initialization for Modula-2 */
1248 _initialize_m2_exp ()
1250 /* Modula-2 "pervasive" types. NOTE: these can be redefined!!! */
1251 builtin_type_m2_int =
1252 init_type (TYPE_CODE_INT, TARGET_INT_BIT / TARGET_CHAR_BIT,
1254 "INTEGER", (struct objfile *) NULL);
1255 builtin_type_m2_card =
1256 init_type (TYPE_CODE_INT, TARGET_INT_BIT / TARGET_CHAR_BIT,
1258 "CARDINAL", (struct objfile *) NULL);
1259 builtin_type_m2_real =
1260 init_type (TYPE_CODE_FLT, TARGET_FLOAT_BIT / TARGET_CHAR_BIT,
1262 "REAL", (struct objfile *) NULL);
1263 builtin_type_m2_char =
1264 init_type (TYPE_CODE_CHAR, TARGET_CHAR_BIT / TARGET_CHAR_BIT,
1266 "CHAR", (struct objfile *) NULL);
1267 builtin_type_m2_bool =
1268 init_type (TYPE_CODE_BOOL, TARGET_INT_BIT / TARGET_CHAR_BIT,
1270 "BOOLEAN", (struct objfile *) NULL);
1272 TYPE_NFIELDS(builtin_type_m2_bool) = 2;
1273 TYPE_FIELDS(builtin_type_m2_bool) =
1274 (struct field *) malloc (sizeof (struct field) * 2);
1275 TYPE_FIELD_BITPOS(builtin_type_m2_bool,0) = 0;
1276 TYPE_FIELD_NAME(builtin_type_m2_bool,0) = (char *)malloc(6);
1277 strcpy(TYPE_FIELD_NAME(builtin_type_m2_bool,0),"FALSE");
1278 TYPE_FIELD_BITPOS(builtin_type_m2_bool,1) = 1;
1279 TYPE_FIELD_NAME(builtin_type_m2_bool,1) = (char *)malloc(5);
1280 strcpy(TYPE_FIELD_NAME(builtin_type_m2_bool,1),"TRUE");
1282 add_language (&m2_language_defn);