15796c8dcSSimon Schubert /* YACC grammar for Modula-2 expressions, for GDB.
2*ef5ccd6cSJohn Marino Copyright (C) 1986-2013 Free Software Foundation, Inc.
35796c8dcSSimon Schubert Generated from expread.y (now c-exp.y) and contributed by the Department
45796c8dcSSimon Schubert of Computer Science at the State University of New York at Buffalo, 1991.
55796c8dcSSimon Schubert
65796c8dcSSimon Schubert This file is part of GDB.
75796c8dcSSimon Schubert
85796c8dcSSimon Schubert This program is free software; you can redistribute it and/or modify
95796c8dcSSimon Schubert it under the terms of the GNU General Public License as published by
105796c8dcSSimon Schubert the Free Software Foundation; either version 3 of the License, or
115796c8dcSSimon Schubert (at your option) any later version.
125796c8dcSSimon Schubert
135796c8dcSSimon Schubert This program is distributed in the hope that it will be useful,
145796c8dcSSimon Schubert but WITHOUT ANY WARRANTY; without even the implied warranty of
155796c8dcSSimon Schubert MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
165796c8dcSSimon Schubert GNU General Public License for more details.
175796c8dcSSimon Schubert
185796c8dcSSimon Schubert You should have received a copy of the GNU General Public License
195796c8dcSSimon Schubert along with this program. If not, see <http://www.gnu.org/licenses/>. */
205796c8dcSSimon Schubert
215796c8dcSSimon Schubert /* Parse a Modula-2 expression from text in a string,
225796c8dcSSimon Schubert and return the result as a struct expression pointer.
235796c8dcSSimon Schubert That structure contains arithmetic operations in reverse polish,
245796c8dcSSimon Schubert with constants represented by operations that are followed by special data.
255796c8dcSSimon Schubert See expression.h for the details of the format.
265796c8dcSSimon Schubert What is important here is that it can be built up sequentially
275796c8dcSSimon Schubert during the process of parsing; the lower levels of the tree always
285796c8dcSSimon Schubert come first in the result.
295796c8dcSSimon Schubert
305796c8dcSSimon Schubert Note that malloc's and realloc's in this file are transformed to
315796c8dcSSimon Schubert xmalloc and xrealloc respectively by the same sed command in the
325796c8dcSSimon Schubert makefile that remaps any other malloc/realloc inserted by the parser
335796c8dcSSimon Schubert generator. Doing this with #defines and trying to control the interaction
345796c8dcSSimon Schubert with include files (<malloc.h> and <stdlib.h> for example) just became
355796c8dcSSimon Schubert too messy, particularly when such includes can be inserted at random
365796c8dcSSimon Schubert times by the parser generator. */
375796c8dcSSimon Schubert
385796c8dcSSimon Schubert %{
395796c8dcSSimon Schubert
405796c8dcSSimon Schubert #include "defs.h"
415796c8dcSSimon Schubert #include "gdb_string.h"
425796c8dcSSimon Schubert #include "expression.h"
435796c8dcSSimon Schubert #include "language.h"
445796c8dcSSimon Schubert #include "value.h"
455796c8dcSSimon Schubert #include "parser-defs.h"
465796c8dcSSimon Schubert #include "m2-lang.h"
475796c8dcSSimon Schubert #include "bfd.h" /* Required by objfiles.h. */
485796c8dcSSimon Schubert #include "symfile.h" /* Required by objfiles.h. */
495796c8dcSSimon Schubert #include "objfiles.h" /* For have_full_symbols and have_partial_symbols */
505796c8dcSSimon Schubert #include "block.h"
515796c8dcSSimon Schubert
525796c8dcSSimon Schubert #define parse_type builtin_type (parse_gdbarch)
535796c8dcSSimon Schubert #define parse_m2_type builtin_m2_type (parse_gdbarch)
545796c8dcSSimon Schubert
555796c8dcSSimon Schubert /* Remap normal yacc parser interface names (yyparse, yylex, yyerror, etc),
565796c8dcSSimon Schubert as well as gratuitiously global symbol names, so we can have multiple
575796c8dcSSimon Schubert yacc generated parsers in gdb. Note that these are only the variables
585796c8dcSSimon Schubert produced by yacc. If other parser generators (bison, byacc, etc) produce
595796c8dcSSimon Schubert additional global names that conflict at link time, then those parser
605796c8dcSSimon Schubert generators need to be fixed instead of adding those names to this list. */
615796c8dcSSimon Schubert
625796c8dcSSimon Schubert #define yymaxdepth m2_maxdepth
635796c8dcSSimon Schubert #define yyparse m2_parse
645796c8dcSSimon Schubert #define yylex m2_lex
655796c8dcSSimon Schubert #define yyerror m2_error
665796c8dcSSimon Schubert #define yylval m2_lval
675796c8dcSSimon Schubert #define yychar m2_char
685796c8dcSSimon Schubert #define yydebug m2_debug
695796c8dcSSimon Schubert #define yypact m2_pact
705796c8dcSSimon Schubert #define yyr1 m2_r1
715796c8dcSSimon Schubert #define yyr2 m2_r2
725796c8dcSSimon Schubert #define yydef m2_def
735796c8dcSSimon Schubert #define yychk m2_chk
745796c8dcSSimon Schubert #define yypgo m2_pgo
755796c8dcSSimon Schubert #define yyact m2_act
765796c8dcSSimon Schubert #define yyexca m2_exca
775796c8dcSSimon Schubert #define yyerrflag m2_errflag
785796c8dcSSimon Schubert #define yynerrs m2_nerrs
795796c8dcSSimon Schubert #define yyps m2_ps
805796c8dcSSimon Schubert #define yypv m2_pv
815796c8dcSSimon Schubert #define yys m2_s
825796c8dcSSimon Schubert #define yy_yys m2_yys
835796c8dcSSimon Schubert #define yystate m2_state
845796c8dcSSimon Schubert #define yytmp m2_tmp
855796c8dcSSimon Schubert #define yyv m2_v
865796c8dcSSimon Schubert #define yy_yyv m2_yyv
875796c8dcSSimon Schubert #define yyval m2_val
885796c8dcSSimon Schubert #define yylloc m2_lloc
895796c8dcSSimon Schubert #define yyreds m2_reds /* With YYDEBUG defined */
905796c8dcSSimon Schubert #define yytoks m2_toks /* With YYDEBUG defined */
915796c8dcSSimon Schubert #define yyname m2_name /* With YYDEBUG defined */
925796c8dcSSimon Schubert #define yyrule m2_rule /* With YYDEBUG defined */
935796c8dcSSimon Schubert #define yylhs m2_yylhs
945796c8dcSSimon Schubert #define yylen m2_yylen
955796c8dcSSimon Schubert #define yydefred m2_yydefred
965796c8dcSSimon Schubert #define yydgoto m2_yydgoto
975796c8dcSSimon Schubert #define yysindex m2_yysindex
985796c8dcSSimon Schubert #define yyrindex m2_yyrindex
995796c8dcSSimon Schubert #define yygindex m2_yygindex
1005796c8dcSSimon Schubert #define yytable m2_yytable
1015796c8dcSSimon Schubert #define yycheck m2_yycheck
102*ef5ccd6cSJohn Marino #define yyss m2_yyss
103*ef5ccd6cSJohn Marino #define yysslim m2_yysslim
104*ef5ccd6cSJohn Marino #define yyssp m2_yyssp
105*ef5ccd6cSJohn Marino #define yystacksize m2_yystacksize
106*ef5ccd6cSJohn Marino #define yyvs m2_yyvs
107*ef5ccd6cSJohn Marino #define yyvsp m2_yyvsp
1085796c8dcSSimon Schubert
1095796c8dcSSimon Schubert #ifndef YYDEBUG
1105796c8dcSSimon Schubert #define YYDEBUG 1 /* Default to yydebug support */
1115796c8dcSSimon Schubert #endif
1125796c8dcSSimon Schubert
1135796c8dcSSimon Schubert #define YYFPRINTF parser_fprintf
1145796c8dcSSimon Schubert
1155796c8dcSSimon Schubert int yyparse (void);
1165796c8dcSSimon Schubert
1175796c8dcSSimon Schubert static int yylex (void);
1185796c8dcSSimon Schubert
1195796c8dcSSimon Schubert void yyerror (char *);
1205796c8dcSSimon Schubert
1215796c8dcSSimon Schubert static int parse_number (int);
1225796c8dcSSimon Schubert
1235796c8dcSSimon Schubert /* The sign of the number being parsed. */
1245796c8dcSSimon Schubert static int number_sign = 1;
1255796c8dcSSimon Schubert
1265796c8dcSSimon Schubert %}
1275796c8dcSSimon Schubert
1285796c8dcSSimon Schubert /* Although the yacc "value" of an expression is not used,
1295796c8dcSSimon Schubert since the result is stored in the structure being created,
1305796c8dcSSimon Schubert other node types do have values. */
1315796c8dcSSimon Schubert
1325796c8dcSSimon Schubert %union
1335796c8dcSSimon Schubert {
1345796c8dcSSimon Schubert LONGEST lval;
1355796c8dcSSimon Schubert ULONGEST ulval;
1365796c8dcSSimon Schubert DOUBLEST dval;
1375796c8dcSSimon Schubert struct symbol *sym;
1385796c8dcSSimon Schubert struct type *tval;
1395796c8dcSSimon Schubert struct stoken sval;
1405796c8dcSSimon Schubert int voidval;
1415796c8dcSSimon Schubert struct block *bval;
1425796c8dcSSimon Schubert enum exp_opcode opcode;
1435796c8dcSSimon Schubert struct internalvar *ivar;
1445796c8dcSSimon Schubert
1455796c8dcSSimon Schubert struct type **tvec;
1465796c8dcSSimon Schubert int *ivec;
1475796c8dcSSimon Schubert }
1485796c8dcSSimon Schubert
1495796c8dcSSimon Schubert %type <voidval> exp type_exp start set
1505796c8dcSSimon Schubert %type <voidval> variable
1515796c8dcSSimon Schubert %type <tval> type
1525796c8dcSSimon Schubert %type <bval> block
1535796c8dcSSimon Schubert %type <sym> fblock
1545796c8dcSSimon Schubert
1555796c8dcSSimon Schubert %token <lval> INT HEX ERROR
1565796c8dcSSimon Schubert %token <ulval> UINT M2_TRUE M2_FALSE CHAR
1575796c8dcSSimon Schubert %token <dval> FLOAT
1585796c8dcSSimon Schubert
1595796c8dcSSimon Schubert /* Both NAME and TYPENAME tokens represent symbols in the input,
1605796c8dcSSimon Schubert and both convey their data as strings.
1615796c8dcSSimon Schubert But a TYPENAME is a string that happens to be defined as a typedef
1625796c8dcSSimon Schubert or builtin type name (such as int or char)
1635796c8dcSSimon Schubert and a NAME is any other symbol.
1645796c8dcSSimon Schubert
1655796c8dcSSimon Schubert Contexts where this distinction is not important can use the
1665796c8dcSSimon Schubert nonterminal "name", which matches either NAME or TYPENAME. */
1675796c8dcSSimon Schubert
1685796c8dcSSimon Schubert %token <sval> STRING
1695796c8dcSSimon Schubert %token <sval> NAME BLOCKNAME IDENT VARNAME
1705796c8dcSSimon Schubert %token <sval> TYPENAME
1715796c8dcSSimon Schubert
1725796c8dcSSimon Schubert %token SIZE CAP ORD HIGH ABS MIN_FUNC MAX_FUNC FLOAT_FUNC VAL CHR ODD TRUNC
1735796c8dcSSimon Schubert %token TSIZE
1745796c8dcSSimon Schubert %token INC DEC INCL EXCL
1755796c8dcSSimon Schubert
1765796c8dcSSimon Schubert /* The GDB scope operator */
1775796c8dcSSimon Schubert %token COLONCOLON
1785796c8dcSSimon Schubert
1795796c8dcSSimon Schubert %token <voidval> INTERNAL_VAR
1805796c8dcSSimon Schubert
1815796c8dcSSimon Schubert /* M2 tokens */
1825796c8dcSSimon Schubert %left ','
1835796c8dcSSimon Schubert %left ABOVE_COMMA
1845796c8dcSSimon Schubert %nonassoc ASSIGN
1855796c8dcSSimon Schubert %left '<' '>' LEQ GEQ '=' NOTEQUAL '#' IN
1865796c8dcSSimon Schubert %left OROR
1875796c8dcSSimon Schubert %left LOGICAL_AND '&'
1885796c8dcSSimon Schubert %left '@'
1895796c8dcSSimon Schubert %left '+' '-'
1905796c8dcSSimon Schubert %left '*' '/' DIV MOD
1915796c8dcSSimon Schubert %right UNARY
1925796c8dcSSimon Schubert %right '^' DOT '[' '('
1935796c8dcSSimon Schubert %right NOT '~'
1945796c8dcSSimon Schubert %left COLONCOLON QID
1955796c8dcSSimon Schubert /* This is not an actual token ; it is used for precedence.
1965796c8dcSSimon Schubert %right QID
1975796c8dcSSimon Schubert */
1985796c8dcSSimon Schubert
1995796c8dcSSimon Schubert
2005796c8dcSSimon Schubert %%
2015796c8dcSSimon Schubert
2025796c8dcSSimon Schubert start : exp
2035796c8dcSSimon Schubert | type_exp
2045796c8dcSSimon Schubert ;
2055796c8dcSSimon Schubert
2065796c8dcSSimon Schubert type_exp: type
2075796c8dcSSimon Schubert { write_exp_elt_opcode(OP_TYPE);
2085796c8dcSSimon Schubert write_exp_elt_type($1);
2095796c8dcSSimon Schubert write_exp_elt_opcode(OP_TYPE);
2105796c8dcSSimon Schubert }
2115796c8dcSSimon Schubert ;
2125796c8dcSSimon Schubert
2135796c8dcSSimon Schubert /* Expressions */
2145796c8dcSSimon Schubert
2155796c8dcSSimon Schubert exp : exp '^' %prec UNARY
2165796c8dcSSimon Schubert { write_exp_elt_opcode (UNOP_IND); }
2175796c8dcSSimon Schubert ;
2185796c8dcSSimon Schubert
2195796c8dcSSimon Schubert exp : '-'
2205796c8dcSSimon Schubert { number_sign = -1; }
2215796c8dcSSimon Schubert exp %prec UNARY
2225796c8dcSSimon Schubert { number_sign = 1;
2235796c8dcSSimon Schubert write_exp_elt_opcode (UNOP_NEG); }
2245796c8dcSSimon Schubert ;
2255796c8dcSSimon Schubert
2265796c8dcSSimon Schubert exp : '+' exp %prec UNARY
2275796c8dcSSimon Schubert { write_exp_elt_opcode(UNOP_PLUS); }
2285796c8dcSSimon Schubert ;
2295796c8dcSSimon Schubert
2305796c8dcSSimon Schubert exp : not_exp exp %prec UNARY
2315796c8dcSSimon Schubert { write_exp_elt_opcode (UNOP_LOGICAL_NOT); }
2325796c8dcSSimon Schubert ;
2335796c8dcSSimon Schubert
2345796c8dcSSimon Schubert not_exp : NOT
2355796c8dcSSimon Schubert | '~'
2365796c8dcSSimon Schubert ;
2375796c8dcSSimon Schubert
2385796c8dcSSimon Schubert exp : CAP '(' exp ')'
2395796c8dcSSimon Schubert { write_exp_elt_opcode (UNOP_CAP); }
2405796c8dcSSimon Schubert ;
2415796c8dcSSimon Schubert
2425796c8dcSSimon Schubert exp : ORD '(' exp ')'
2435796c8dcSSimon Schubert { write_exp_elt_opcode (UNOP_ORD); }
2445796c8dcSSimon Schubert ;
2455796c8dcSSimon Schubert
2465796c8dcSSimon Schubert exp : ABS '(' exp ')'
2475796c8dcSSimon Schubert { write_exp_elt_opcode (UNOP_ABS); }
2485796c8dcSSimon Schubert ;
2495796c8dcSSimon Schubert
2505796c8dcSSimon Schubert exp : HIGH '(' exp ')'
2515796c8dcSSimon Schubert { write_exp_elt_opcode (UNOP_HIGH); }
2525796c8dcSSimon Schubert ;
2535796c8dcSSimon Schubert
2545796c8dcSSimon Schubert exp : MIN_FUNC '(' type ')'
2555796c8dcSSimon Schubert { write_exp_elt_opcode (UNOP_MIN);
2565796c8dcSSimon Schubert write_exp_elt_type ($3);
2575796c8dcSSimon Schubert write_exp_elt_opcode (UNOP_MIN); }
2585796c8dcSSimon Schubert ;
2595796c8dcSSimon Schubert
2605796c8dcSSimon Schubert exp : MAX_FUNC '(' type ')'
2615796c8dcSSimon Schubert { write_exp_elt_opcode (UNOP_MAX);
2625796c8dcSSimon Schubert write_exp_elt_type ($3);
2635796c8dcSSimon Schubert write_exp_elt_opcode (UNOP_MAX); }
2645796c8dcSSimon Schubert ;
2655796c8dcSSimon Schubert
2665796c8dcSSimon Schubert exp : FLOAT_FUNC '(' exp ')'
2675796c8dcSSimon Schubert { write_exp_elt_opcode (UNOP_FLOAT); }
2685796c8dcSSimon Schubert ;
2695796c8dcSSimon Schubert
2705796c8dcSSimon Schubert exp : VAL '(' type ',' exp ')'
2715796c8dcSSimon Schubert { write_exp_elt_opcode (BINOP_VAL);
2725796c8dcSSimon Schubert write_exp_elt_type ($3);
2735796c8dcSSimon Schubert write_exp_elt_opcode (BINOP_VAL); }
2745796c8dcSSimon Schubert ;
2755796c8dcSSimon Schubert
2765796c8dcSSimon Schubert exp : CHR '(' exp ')'
2775796c8dcSSimon Schubert { write_exp_elt_opcode (UNOP_CHR); }
2785796c8dcSSimon Schubert ;
2795796c8dcSSimon Schubert
2805796c8dcSSimon Schubert exp : ODD '(' exp ')'
2815796c8dcSSimon Schubert { write_exp_elt_opcode (UNOP_ODD); }
2825796c8dcSSimon Schubert ;
2835796c8dcSSimon Schubert
2845796c8dcSSimon Schubert exp : TRUNC '(' exp ')'
2855796c8dcSSimon Schubert { write_exp_elt_opcode (UNOP_TRUNC); }
2865796c8dcSSimon Schubert ;
2875796c8dcSSimon Schubert
2885796c8dcSSimon Schubert exp : TSIZE '(' exp ')'
2895796c8dcSSimon Schubert { write_exp_elt_opcode (UNOP_SIZEOF); }
2905796c8dcSSimon Schubert ;
2915796c8dcSSimon Schubert
2925796c8dcSSimon Schubert exp : SIZE exp %prec UNARY
2935796c8dcSSimon Schubert { write_exp_elt_opcode (UNOP_SIZEOF); }
2945796c8dcSSimon Schubert ;
2955796c8dcSSimon Schubert
2965796c8dcSSimon Schubert
2975796c8dcSSimon Schubert exp : INC '(' exp ')'
2985796c8dcSSimon Schubert { write_exp_elt_opcode(UNOP_PREINCREMENT); }
2995796c8dcSSimon Schubert ;
3005796c8dcSSimon Schubert
3015796c8dcSSimon Schubert exp : INC '(' exp ',' exp ')'
3025796c8dcSSimon Schubert { write_exp_elt_opcode(BINOP_ASSIGN_MODIFY);
3035796c8dcSSimon Schubert write_exp_elt_opcode(BINOP_ADD);
3045796c8dcSSimon Schubert write_exp_elt_opcode(BINOP_ASSIGN_MODIFY); }
3055796c8dcSSimon Schubert ;
3065796c8dcSSimon Schubert
3075796c8dcSSimon Schubert exp : DEC '(' exp ')'
3085796c8dcSSimon Schubert { write_exp_elt_opcode(UNOP_PREDECREMENT);}
3095796c8dcSSimon Schubert ;
3105796c8dcSSimon Schubert
3115796c8dcSSimon Schubert exp : DEC '(' exp ',' exp ')'
3125796c8dcSSimon Schubert { write_exp_elt_opcode(BINOP_ASSIGN_MODIFY);
3135796c8dcSSimon Schubert write_exp_elt_opcode(BINOP_SUB);
3145796c8dcSSimon Schubert write_exp_elt_opcode(BINOP_ASSIGN_MODIFY); }
3155796c8dcSSimon Schubert ;
3165796c8dcSSimon Schubert
3175796c8dcSSimon Schubert exp : exp DOT NAME
3185796c8dcSSimon Schubert { write_exp_elt_opcode (STRUCTOP_STRUCT);
3195796c8dcSSimon Schubert write_exp_string ($3);
3205796c8dcSSimon Schubert write_exp_elt_opcode (STRUCTOP_STRUCT); }
3215796c8dcSSimon Schubert ;
3225796c8dcSSimon Schubert
3235796c8dcSSimon Schubert exp : set
3245796c8dcSSimon Schubert ;
3255796c8dcSSimon Schubert
3265796c8dcSSimon Schubert exp : exp IN set
327c50c785cSJohn Marino { error (_("Sets are not implemented."));}
3285796c8dcSSimon Schubert ;
3295796c8dcSSimon Schubert
3305796c8dcSSimon Schubert exp : INCL '(' exp ',' exp ')'
331c50c785cSJohn Marino { error (_("Sets are not implemented."));}
3325796c8dcSSimon Schubert ;
3335796c8dcSSimon Schubert
3345796c8dcSSimon Schubert exp : EXCL '(' exp ',' exp ')'
335c50c785cSJohn Marino { error (_("Sets are not implemented."));}
3365796c8dcSSimon Schubert ;
3375796c8dcSSimon Schubert
3385796c8dcSSimon Schubert set : '{' arglist '}'
339c50c785cSJohn Marino { error (_("Sets are not implemented."));}
3405796c8dcSSimon Schubert | type '{' arglist '}'
341c50c785cSJohn Marino { error (_("Sets are not implemented."));}
3425796c8dcSSimon Schubert ;
3435796c8dcSSimon Schubert
3445796c8dcSSimon Schubert
3455796c8dcSSimon Schubert /* Modula-2 array subscript notation [a,b,c...] */
3465796c8dcSSimon Schubert exp : exp '['
3475796c8dcSSimon Schubert /* This function just saves the number of arguments
3485796c8dcSSimon Schubert that follow in the list. It is *not* specific to
3495796c8dcSSimon Schubert function types */
3505796c8dcSSimon Schubert { start_arglist(); }
3515796c8dcSSimon Schubert non_empty_arglist ']' %prec DOT
3525796c8dcSSimon Schubert { write_exp_elt_opcode (MULTI_SUBSCRIPT);
3535796c8dcSSimon Schubert write_exp_elt_longcst ((LONGEST) end_arglist());
3545796c8dcSSimon Schubert write_exp_elt_opcode (MULTI_SUBSCRIPT); }
3555796c8dcSSimon Schubert ;
3565796c8dcSSimon Schubert
3575796c8dcSSimon Schubert exp : exp '[' exp ']'
3585796c8dcSSimon Schubert { write_exp_elt_opcode (BINOP_SUBSCRIPT); }
3595796c8dcSSimon Schubert ;
3605796c8dcSSimon Schubert
3615796c8dcSSimon Schubert exp : exp '('
3625796c8dcSSimon Schubert /* This is to save the value of arglist_len
3635796c8dcSSimon Schubert being accumulated by an outer function call. */
3645796c8dcSSimon Schubert { start_arglist (); }
3655796c8dcSSimon Schubert arglist ')' %prec DOT
3665796c8dcSSimon Schubert { write_exp_elt_opcode (OP_FUNCALL);
3675796c8dcSSimon Schubert write_exp_elt_longcst ((LONGEST) end_arglist ());
3685796c8dcSSimon Schubert write_exp_elt_opcode (OP_FUNCALL); }
3695796c8dcSSimon Schubert ;
3705796c8dcSSimon Schubert
3715796c8dcSSimon Schubert arglist :
3725796c8dcSSimon Schubert ;
3735796c8dcSSimon Schubert
3745796c8dcSSimon Schubert arglist : exp
3755796c8dcSSimon Schubert { arglist_len = 1; }
3765796c8dcSSimon Schubert ;
3775796c8dcSSimon Schubert
3785796c8dcSSimon Schubert arglist : arglist ',' exp %prec ABOVE_COMMA
3795796c8dcSSimon Schubert { arglist_len++; }
3805796c8dcSSimon Schubert ;
3815796c8dcSSimon Schubert
3825796c8dcSSimon Schubert non_empty_arglist
3835796c8dcSSimon Schubert : exp
3845796c8dcSSimon Schubert { arglist_len = 1; }
3855796c8dcSSimon Schubert ;
3865796c8dcSSimon Schubert
3875796c8dcSSimon Schubert non_empty_arglist
3885796c8dcSSimon Schubert : non_empty_arglist ',' exp %prec ABOVE_COMMA
3895796c8dcSSimon Schubert { arglist_len++; }
3905796c8dcSSimon Schubert ;
3915796c8dcSSimon Schubert
3925796c8dcSSimon Schubert /* GDB construct */
3935796c8dcSSimon Schubert exp : '{' type '}' exp %prec UNARY
3945796c8dcSSimon Schubert { write_exp_elt_opcode (UNOP_MEMVAL);
3955796c8dcSSimon Schubert write_exp_elt_type ($2);
3965796c8dcSSimon Schubert write_exp_elt_opcode (UNOP_MEMVAL); }
3975796c8dcSSimon Schubert ;
3985796c8dcSSimon Schubert
3995796c8dcSSimon Schubert exp : type '(' exp ')' %prec UNARY
4005796c8dcSSimon Schubert { write_exp_elt_opcode (UNOP_CAST);
4015796c8dcSSimon Schubert write_exp_elt_type ($1);
4025796c8dcSSimon Schubert write_exp_elt_opcode (UNOP_CAST); }
4035796c8dcSSimon Schubert ;
4045796c8dcSSimon Schubert
4055796c8dcSSimon Schubert exp : '(' exp ')'
4065796c8dcSSimon Schubert { }
4075796c8dcSSimon Schubert ;
4085796c8dcSSimon Schubert
4095796c8dcSSimon Schubert /* Binary operators in order of decreasing precedence. Note that some
4105796c8dcSSimon Schubert of these operators are overloaded! (ie. sets) */
4115796c8dcSSimon Schubert
4125796c8dcSSimon Schubert /* GDB construct */
4135796c8dcSSimon Schubert exp : exp '@' exp
4145796c8dcSSimon Schubert { write_exp_elt_opcode (BINOP_REPEAT); }
4155796c8dcSSimon Schubert ;
4165796c8dcSSimon Schubert
4175796c8dcSSimon Schubert exp : exp '*' exp
4185796c8dcSSimon Schubert { write_exp_elt_opcode (BINOP_MUL); }
4195796c8dcSSimon Schubert ;
4205796c8dcSSimon Schubert
4215796c8dcSSimon Schubert exp : exp '/' exp
4225796c8dcSSimon Schubert { write_exp_elt_opcode (BINOP_DIV); }
4235796c8dcSSimon Schubert ;
4245796c8dcSSimon Schubert
4255796c8dcSSimon Schubert exp : exp DIV exp
4265796c8dcSSimon Schubert { write_exp_elt_opcode (BINOP_INTDIV); }
4275796c8dcSSimon Schubert ;
4285796c8dcSSimon Schubert
4295796c8dcSSimon Schubert exp : exp MOD exp
4305796c8dcSSimon Schubert { write_exp_elt_opcode (BINOP_REM); }
4315796c8dcSSimon Schubert ;
4325796c8dcSSimon Schubert
4335796c8dcSSimon Schubert exp : exp '+' exp
4345796c8dcSSimon Schubert { write_exp_elt_opcode (BINOP_ADD); }
4355796c8dcSSimon Schubert ;
4365796c8dcSSimon Schubert
4375796c8dcSSimon Schubert exp : exp '-' exp
4385796c8dcSSimon Schubert { write_exp_elt_opcode (BINOP_SUB); }
4395796c8dcSSimon Schubert ;
4405796c8dcSSimon Schubert
4415796c8dcSSimon Schubert exp : exp '=' exp
4425796c8dcSSimon Schubert { write_exp_elt_opcode (BINOP_EQUAL); }
4435796c8dcSSimon Schubert ;
4445796c8dcSSimon Schubert
4455796c8dcSSimon Schubert exp : exp NOTEQUAL exp
4465796c8dcSSimon Schubert { write_exp_elt_opcode (BINOP_NOTEQUAL); }
4475796c8dcSSimon Schubert | exp '#' exp
4485796c8dcSSimon Schubert { write_exp_elt_opcode (BINOP_NOTEQUAL); }
4495796c8dcSSimon Schubert ;
4505796c8dcSSimon Schubert
4515796c8dcSSimon Schubert exp : exp LEQ exp
4525796c8dcSSimon Schubert { write_exp_elt_opcode (BINOP_LEQ); }
4535796c8dcSSimon Schubert ;
4545796c8dcSSimon Schubert
4555796c8dcSSimon Schubert exp : exp GEQ exp
4565796c8dcSSimon Schubert { write_exp_elt_opcode (BINOP_GEQ); }
4575796c8dcSSimon Schubert ;
4585796c8dcSSimon Schubert
4595796c8dcSSimon Schubert exp : exp '<' exp
4605796c8dcSSimon Schubert { write_exp_elt_opcode (BINOP_LESS); }
4615796c8dcSSimon Schubert ;
4625796c8dcSSimon Schubert
4635796c8dcSSimon Schubert exp : exp '>' exp
4645796c8dcSSimon Schubert { write_exp_elt_opcode (BINOP_GTR); }
4655796c8dcSSimon Schubert ;
4665796c8dcSSimon Schubert
4675796c8dcSSimon Schubert exp : exp LOGICAL_AND exp
4685796c8dcSSimon Schubert { write_exp_elt_opcode (BINOP_LOGICAL_AND); }
4695796c8dcSSimon Schubert ;
4705796c8dcSSimon Schubert
4715796c8dcSSimon Schubert exp : exp OROR exp
4725796c8dcSSimon Schubert { write_exp_elt_opcode (BINOP_LOGICAL_OR); }
4735796c8dcSSimon Schubert ;
4745796c8dcSSimon Schubert
4755796c8dcSSimon Schubert exp : exp ASSIGN exp
4765796c8dcSSimon Schubert { write_exp_elt_opcode (BINOP_ASSIGN); }
4775796c8dcSSimon Schubert ;
4785796c8dcSSimon Schubert
4795796c8dcSSimon Schubert
4805796c8dcSSimon Schubert /* Constants */
4815796c8dcSSimon Schubert
4825796c8dcSSimon Schubert exp : M2_TRUE
4835796c8dcSSimon Schubert { write_exp_elt_opcode (OP_BOOL);
4845796c8dcSSimon Schubert write_exp_elt_longcst ((LONGEST) $1);
4855796c8dcSSimon Schubert write_exp_elt_opcode (OP_BOOL); }
4865796c8dcSSimon Schubert ;
4875796c8dcSSimon Schubert
4885796c8dcSSimon Schubert exp : M2_FALSE
4895796c8dcSSimon Schubert { write_exp_elt_opcode (OP_BOOL);
4905796c8dcSSimon Schubert write_exp_elt_longcst ((LONGEST) $1);
4915796c8dcSSimon Schubert write_exp_elt_opcode (OP_BOOL); }
4925796c8dcSSimon Schubert ;
4935796c8dcSSimon Schubert
4945796c8dcSSimon Schubert exp : INT
4955796c8dcSSimon Schubert { write_exp_elt_opcode (OP_LONG);
4965796c8dcSSimon Schubert write_exp_elt_type (parse_m2_type->builtin_int);
4975796c8dcSSimon Schubert write_exp_elt_longcst ((LONGEST) $1);
4985796c8dcSSimon Schubert write_exp_elt_opcode (OP_LONG); }
4995796c8dcSSimon Schubert ;
5005796c8dcSSimon Schubert
5015796c8dcSSimon Schubert exp : UINT
5025796c8dcSSimon Schubert {
5035796c8dcSSimon Schubert write_exp_elt_opcode (OP_LONG);
5045796c8dcSSimon Schubert write_exp_elt_type (parse_m2_type->builtin_card);
5055796c8dcSSimon Schubert write_exp_elt_longcst ((LONGEST) $1);
5065796c8dcSSimon Schubert write_exp_elt_opcode (OP_LONG);
5075796c8dcSSimon Schubert }
5085796c8dcSSimon Schubert ;
5095796c8dcSSimon Schubert
5105796c8dcSSimon Schubert exp : CHAR
5115796c8dcSSimon Schubert { write_exp_elt_opcode (OP_LONG);
5125796c8dcSSimon Schubert write_exp_elt_type (parse_m2_type->builtin_char);
5135796c8dcSSimon Schubert write_exp_elt_longcst ((LONGEST) $1);
5145796c8dcSSimon Schubert write_exp_elt_opcode (OP_LONG); }
5155796c8dcSSimon Schubert ;
5165796c8dcSSimon Schubert
5175796c8dcSSimon Schubert
5185796c8dcSSimon Schubert exp : FLOAT
5195796c8dcSSimon Schubert { write_exp_elt_opcode (OP_DOUBLE);
5205796c8dcSSimon Schubert write_exp_elt_type (parse_m2_type->builtin_real);
5215796c8dcSSimon Schubert write_exp_elt_dblcst ($1);
5225796c8dcSSimon Schubert write_exp_elt_opcode (OP_DOUBLE); }
5235796c8dcSSimon Schubert ;
5245796c8dcSSimon Schubert
5255796c8dcSSimon Schubert exp : variable
5265796c8dcSSimon Schubert ;
5275796c8dcSSimon Schubert
5285796c8dcSSimon Schubert exp : SIZE '(' type ')' %prec UNARY
5295796c8dcSSimon Schubert { write_exp_elt_opcode (OP_LONG);
5305796c8dcSSimon Schubert write_exp_elt_type (parse_type->builtin_int);
5315796c8dcSSimon Schubert write_exp_elt_longcst ((LONGEST) TYPE_LENGTH ($3));
5325796c8dcSSimon Schubert write_exp_elt_opcode (OP_LONG); }
5335796c8dcSSimon Schubert ;
5345796c8dcSSimon Schubert
5355796c8dcSSimon Schubert exp : STRING
5365796c8dcSSimon Schubert { write_exp_elt_opcode (OP_M2_STRING);
5375796c8dcSSimon Schubert write_exp_string ($1);
5385796c8dcSSimon Schubert write_exp_elt_opcode (OP_M2_STRING); }
5395796c8dcSSimon Schubert ;
5405796c8dcSSimon Schubert
5415796c8dcSSimon Schubert /* This will be used for extensions later. Like adding modules. */
5425796c8dcSSimon Schubert block : fblock
5435796c8dcSSimon Schubert { $$ = SYMBOL_BLOCK_VALUE($1); }
5445796c8dcSSimon Schubert ;
5455796c8dcSSimon Schubert
5465796c8dcSSimon Schubert fblock : BLOCKNAME
5475796c8dcSSimon Schubert { struct symbol *sym
5485796c8dcSSimon Schubert = lookup_symbol (copy_name ($1), expression_context_block,
5495796c8dcSSimon Schubert VAR_DOMAIN, 0);
5505796c8dcSSimon Schubert $$ = sym;}
5515796c8dcSSimon Schubert ;
5525796c8dcSSimon Schubert
5535796c8dcSSimon Schubert
5545796c8dcSSimon Schubert /* GDB scope operator */
5555796c8dcSSimon Schubert fblock : block COLONCOLON BLOCKNAME
5565796c8dcSSimon Schubert { struct symbol *tem
5575796c8dcSSimon Schubert = lookup_symbol (copy_name ($3), $1,
5585796c8dcSSimon Schubert VAR_DOMAIN, 0);
5595796c8dcSSimon Schubert if (!tem || SYMBOL_CLASS (tem) != LOC_BLOCK)
560c50c785cSJohn Marino error (_("No function \"%s\" in specified context."),
5615796c8dcSSimon Schubert copy_name ($3));
5625796c8dcSSimon Schubert $$ = tem;
5635796c8dcSSimon Schubert }
5645796c8dcSSimon Schubert ;
5655796c8dcSSimon Schubert
5665796c8dcSSimon Schubert /* Useful for assigning to PROCEDURE variables */
5675796c8dcSSimon Schubert variable: fblock
5685796c8dcSSimon Schubert { write_exp_elt_opcode(OP_VAR_VALUE);
5695796c8dcSSimon Schubert write_exp_elt_block (NULL);
5705796c8dcSSimon Schubert write_exp_elt_sym ($1);
5715796c8dcSSimon Schubert write_exp_elt_opcode (OP_VAR_VALUE); }
5725796c8dcSSimon Schubert ;
5735796c8dcSSimon Schubert
5745796c8dcSSimon Schubert /* GDB internal ($foo) variable */
5755796c8dcSSimon Schubert variable: INTERNAL_VAR
5765796c8dcSSimon Schubert ;
5775796c8dcSSimon Schubert
5785796c8dcSSimon Schubert /* GDB scope operator */
5795796c8dcSSimon Schubert variable: block COLONCOLON NAME
5805796c8dcSSimon Schubert { struct symbol *sym;
5815796c8dcSSimon Schubert sym = lookup_symbol (copy_name ($3), $1,
5825796c8dcSSimon Schubert VAR_DOMAIN, 0);
5835796c8dcSSimon Schubert if (sym == 0)
584c50c785cSJohn Marino error (_("No symbol \"%s\" in specified context."),
5855796c8dcSSimon Schubert copy_name ($3));
586*ef5ccd6cSJohn Marino if (symbol_read_needs_frame (sym))
587*ef5ccd6cSJohn Marino {
588*ef5ccd6cSJohn Marino if (innermost_block == 0
589*ef5ccd6cSJohn Marino || contained_in (block_found,
590*ef5ccd6cSJohn Marino innermost_block))
591*ef5ccd6cSJohn Marino innermost_block = block_found;
592*ef5ccd6cSJohn Marino }
5935796c8dcSSimon Schubert
5945796c8dcSSimon Schubert write_exp_elt_opcode (OP_VAR_VALUE);
5955796c8dcSSimon Schubert /* block_found is set by lookup_symbol. */
5965796c8dcSSimon Schubert write_exp_elt_block (block_found);
5975796c8dcSSimon Schubert write_exp_elt_sym (sym);
5985796c8dcSSimon Schubert write_exp_elt_opcode (OP_VAR_VALUE); }
5995796c8dcSSimon Schubert ;
6005796c8dcSSimon Schubert
6015796c8dcSSimon Schubert /* Base case for variables. */
6025796c8dcSSimon Schubert variable: NAME
6035796c8dcSSimon Schubert { struct symbol *sym;
604*ef5ccd6cSJohn Marino struct field_of_this_result is_a_field_of_this;
6055796c8dcSSimon Schubert
6065796c8dcSSimon Schubert sym = lookup_symbol (copy_name ($1),
6075796c8dcSSimon Schubert expression_context_block,
6085796c8dcSSimon Schubert VAR_DOMAIN,
6095796c8dcSSimon Schubert &is_a_field_of_this);
6105796c8dcSSimon Schubert if (sym)
6115796c8dcSSimon Schubert {
6125796c8dcSSimon Schubert if (symbol_read_needs_frame (sym))
6135796c8dcSSimon Schubert {
6145796c8dcSSimon Schubert if (innermost_block == 0 ||
6155796c8dcSSimon Schubert contained_in (block_found,
6165796c8dcSSimon Schubert innermost_block))
6175796c8dcSSimon Schubert innermost_block = block_found;
6185796c8dcSSimon Schubert }
6195796c8dcSSimon Schubert
6205796c8dcSSimon Schubert write_exp_elt_opcode (OP_VAR_VALUE);
6215796c8dcSSimon Schubert /* We want to use the selected frame, not
6225796c8dcSSimon Schubert another more inner frame which happens to
6235796c8dcSSimon Schubert be in the same block. */
6245796c8dcSSimon Schubert write_exp_elt_block (NULL);
6255796c8dcSSimon Schubert write_exp_elt_sym (sym);
6265796c8dcSSimon Schubert write_exp_elt_opcode (OP_VAR_VALUE);
6275796c8dcSSimon Schubert }
6285796c8dcSSimon Schubert else
6295796c8dcSSimon Schubert {
6305796c8dcSSimon Schubert struct minimal_symbol *msymbol;
6315796c8dcSSimon Schubert char *arg = copy_name ($1);
6325796c8dcSSimon Schubert
6335796c8dcSSimon Schubert msymbol =
6345796c8dcSSimon Schubert lookup_minimal_symbol (arg, NULL, NULL);
6355796c8dcSSimon Schubert if (msymbol != NULL)
6365796c8dcSSimon Schubert write_exp_msymbol (msymbol);
6375796c8dcSSimon Schubert else if (!have_full_symbols () && !have_partial_symbols ())
638c50c785cSJohn Marino error (_("No symbol table is loaded. Use the \"symbol-file\" command."));
6395796c8dcSSimon Schubert else
640c50c785cSJohn Marino error (_("No symbol \"%s\" in current context."),
6415796c8dcSSimon Schubert copy_name ($1));
6425796c8dcSSimon Schubert }
6435796c8dcSSimon Schubert }
6445796c8dcSSimon Schubert ;
6455796c8dcSSimon Schubert
6465796c8dcSSimon Schubert type
6475796c8dcSSimon Schubert : TYPENAME
6485796c8dcSSimon Schubert { $$ = lookup_typename (parse_language, parse_gdbarch,
6495796c8dcSSimon Schubert copy_name ($1),
6505796c8dcSSimon Schubert expression_context_block, 0); }
6515796c8dcSSimon Schubert
6525796c8dcSSimon Schubert ;
6535796c8dcSSimon Schubert
6545796c8dcSSimon Schubert %%
6555796c8dcSSimon Schubert
6565796c8dcSSimon Schubert /* Take care of parsing a number (anything that starts with a digit).
6575796c8dcSSimon Schubert Set yylval and return the token type; update lexptr.
6585796c8dcSSimon Schubert LEN is the number of characters in it. */
6595796c8dcSSimon Schubert
6605796c8dcSSimon Schubert /*** Needs some error checking for the float case ***/
6615796c8dcSSimon Schubert
6625796c8dcSSimon Schubert static int
663*ef5ccd6cSJohn Marino parse_number (int olen)
6645796c8dcSSimon Schubert {
6655796c8dcSSimon Schubert char *p = lexptr;
6665796c8dcSSimon Schubert LONGEST n = 0;
6675796c8dcSSimon Schubert LONGEST prevn = 0;
6685796c8dcSSimon Schubert int c,i,ischar=0;
6695796c8dcSSimon Schubert int base = input_radix;
6705796c8dcSSimon Schubert int len = olen;
6715796c8dcSSimon Schubert int unsigned_p = number_sign == 1 ? 1 : 0;
6725796c8dcSSimon Schubert
6735796c8dcSSimon Schubert if(p[len-1] == 'H')
6745796c8dcSSimon Schubert {
6755796c8dcSSimon Schubert base = 16;
6765796c8dcSSimon Schubert len--;
6775796c8dcSSimon Schubert }
6785796c8dcSSimon Schubert else if(p[len-1] == 'C' || p[len-1] == 'B')
6795796c8dcSSimon Schubert {
6805796c8dcSSimon Schubert base = 8;
6815796c8dcSSimon Schubert ischar = p[len-1] == 'C';
6825796c8dcSSimon Schubert len--;
6835796c8dcSSimon Schubert }
6845796c8dcSSimon Schubert
6855796c8dcSSimon Schubert /* Scan the number */
6865796c8dcSSimon Schubert for (c = 0; c < len; c++)
6875796c8dcSSimon Schubert {
6885796c8dcSSimon Schubert if (p[c] == '.' && base == 10)
6895796c8dcSSimon Schubert {
6905796c8dcSSimon Schubert /* It's a float since it contains a point. */
6915796c8dcSSimon Schubert yylval.dval = atof (p);
6925796c8dcSSimon Schubert lexptr += len;
6935796c8dcSSimon Schubert return FLOAT;
6945796c8dcSSimon Schubert }
6955796c8dcSSimon Schubert if (p[c] == '.' && base != 10)
696c50c785cSJohn Marino error (_("Floating point numbers must be base 10."));
6975796c8dcSSimon Schubert if (base == 10 && (p[c] < '0' || p[c] > '9'))
698c50c785cSJohn Marino error (_("Invalid digit \'%c\' in number."),p[c]);
6995796c8dcSSimon Schubert }
7005796c8dcSSimon Schubert
7015796c8dcSSimon Schubert while (len-- > 0)
7025796c8dcSSimon Schubert {
7035796c8dcSSimon Schubert c = *p++;
7045796c8dcSSimon Schubert n *= base;
7055796c8dcSSimon Schubert if( base == 8 && (c == '8' || c == '9'))
706c50c785cSJohn Marino error (_("Invalid digit \'%c\' in octal number."),c);
7075796c8dcSSimon Schubert if (c >= '0' && c <= '9')
7085796c8dcSSimon Schubert i = c - '0';
7095796c8dcSSimon Schubert else
7105796c8dcSSimon Schubert {
7115796c8dcSSimon Schubert if (base == 16 && c >= 'A' && c <= 'F')
7125796c8dcSSimon Schubert i = c - 'A' + 10;
7135796c8dcSSimon Schubert else
7145796c8dcSSimon Schubert return ERROR;
7155796c8dcSSimon Schubert }
7165796c8dcSSimon Schubert n+=i;
7175796c8dcSSimon Schubert if(i >= base)
7185796c8dcSSimon Schubert return ERROR;
7195796c8dcSSimon Schubert if(!unsigned_p && number_sign == 1 && (prevn >= n))
7205796c8dcSSimon Schubert unsigned_p=1; /* Try something unsigned */
7215796c8dcSSimon Schubert /* Don't do the range check if n==i and i==0, since that special
7225796c8dcSSimon Schubert case will give an overflow error. */
7235796c8dcSSimon Schubert if(RANGE_CHECK && n!=i && i)
7245796c8dcSSimon Schubert {
7255796c8dcSSimon Schubert if((unsigned_p && (unsigned)prevn >= (unsigned)n) ||
7265796c8dcSSimon Schubert ((!unsigned_p && number_sign==-1) && -prevn <= -n))
727c50c785cSJohn Marino range_error (_("Overflow on numeric constant."));
7285796c8dcSSimon Schubert }
7295796c8dcSSimon Schubert prevn=n;
7305796c8dcSSimon Schubert }
7315796c8dcSSimon Schubert
7325796c8dcSSimon Schubert lexptr = p;
7335796c8dcSSimon Schubert if(*p == 'B' || *p == 'C' || *p == 'H')
7345796c8dcSSimon Schubert lexptr++; /* Advance past B,C or H */
7355796c8dcSSimon Schubert
7365796c8dcSSimon Schubert if (ischar)
7375796c8dcSSimon Schubert {
7385796c8dcSSimon Schubert yylval.ulval = n;
7395796c8dcSSimon Schubert return CHAR;
7405796c8dcSSimon Schubert }
7415796c8dcSSimon Schubert else if ( unsigned_p && number_sign == 1)
7425796c8dcSSimon Schubert {
7435796c8dcSSimon Schubert yylval.ulval = n;
7445796c8dcSSimon Schubert return UINT;
7455796c8dcSSimon Schubert }
7465796c8dcSSimon Schubert else if((unsigned_p && (n<0))) {
747c50c785cSJohn Marino range_error (_("Overflow on numeric constant -- number too large."));
7485796c8dcSSimon Schubert /* But, this can return if range_check == range_warn. */
7495796c8dcSSimon Schubert }
7505796c8dcSSimon Schubert yylval.lval = n;
7515796c8dcSSimon Schubert return INT;
7525796c8dcSSimon Schubert }
7535796c8dcSSimon Schubert
7545796c8dcSSimon Schubert
7555796c8dcSSimon Schubert /* Some tokens */
7565796c8dcSSimon Schubert
7575796c8dcSSimon Schubert static struct
7585796c8dcSSimon Schubert {
7595796c8dcSSimon Schubert char name[2];
7605796c8dcSSimon Schubert int token;
7615796c8dcSSimon Schubert } tokentab2[] =
7625796c8dcSSimon Schubert {
7635796c8dcSSimon Schubert { {'<', '>'}, NOTEQUAL },
7645796c8dcSSimon Schubert { {':', '='}, ASSIGN },
7655796c8dcSSimon Schubert { {'<', '='}, LEQ },
7665796c8dcSSimon Schubert { {'>', '='}, GEQ },
7675796c8dcSSimon Schubert { {':', ':'}, COLONCOLON },
7685796c8dcSSimon Schubert
7695796c8dcSSimon Schubert };
7705796c8dcSSimon Schubert
7715796c8dcSSimon Schubert /* Some specific keywords */
7725796c8dcSSimon Schubert
7735796c8dcSSimon Schubert struct keyword {
7745796c8dcSSimon Schubert char keyw[10];
7755796c8dcSSimon Schubert int token;
7765796c8dcSSimon Schubert };
7775796c8dcSSimon Schubert
7785796c8dcSSimon Schubert static struct keyword keytab[] =
7795796c8dcSSimon Schubert {
7805796c8dcSSimon Schubert {"OR" , OROR },
7815796c8dcSSimon Schubert {"IN", IN },/* Note space after IN */
7825796c8dcSSimon Schubert {"AND", LOGICAL_AND},
7835796c8dcSSimon Schubert {"ABS", ABS },
7845796c8dcSSimon Schubert {"CHR", CHR },
7855796c8dcSSimon Schubert {"DEC", DEC },
7865796c8dcSSimon Schubert {"NOT", NOT },
7875796c8dcSSimon Schubert {"DIV", DIV },
7885796c8dcSSimon Schubert {"INC", INC },
7895796c8dcSSimon Schubert {"MAX", MAX_FUNC },
7905796c8dcSSimon Schubert {"MIN", MIN_FUNC },
7915796c8dcSSimon Schubert {"MOD", MOD },
7925796c8dcSSimon Schubert {"ODD", ODD },
7935796c8dcSSimon Schubert {"CAP", CAP },
7945796c8dcSSimon Schubert {"ORD", ORD },
7955796c8dcSSimon Schubert {"VAL", VAL },
7965796c8dcSSimon Schubert {"EXCL", EXCL },
7975796c8dcSSimon Schubert {"HIGH", HIGH },
7985796c8dcSSimon Schubert {"INCL", INCL },
7995796c8dcSSimon Schubert {"SIZE", SIZE },
8005796c8dcSSimon Schubert {"FLOAT", FLOAT_FUNC },
8015796c8dcSSimon Schubert {"TRUNC", TRUNC },
8025796c8dcSSimon Schubert {"TSIZE", SIZE },
8035796c8dcSSimon Schubert };
8045796c8dcSSimon Schubert
8055796c8dcSSimon Schubert
8065796c8dcSSimon Schubert /* Read one token, getting characters through lexptr. */
8075796c8dcSSimon Schubert
8085796c8dcSSimon Schubert /* This is where we will check to make sure that the language and the operators used are
8095796c8dcSSimon Schubert compatible */
8105796c8dcSSimon Schubert
8115796c8dcSSimon Schubert static int
yylex(void)812c50c785cSJohn Marino yylex (void)
8135796c8dcSSimon Schubert {
8145796c8dcSSimon Schubert int c;
8155796c8dcSSimon Schubert int namelen;
8165796c8dcSSimon Schubert int i;
8175796c8dcSSimon Schubert char *tokstart;
8185796c8dcSSimon Schubert char quote;
8195796c8dcSSimon Schubert
8205796c8dcSSimon Schubert retry:
8215796c8dcSSimon Schubert
8225796c8dcSSimon Schubert prev_lexptr = lexptr;
8235796c8dcSSimon Schubert
8245796c8dcSSimon Schubert tokstart = lexptr;
8255796c8dcSSimon Schubert
8265796c8dcSSimon Schubert
8275796c8dcSSimon Schubert /* See if it is a special token of length 2 */
8285796c8dcSSimon Schubert for( i = 0 ; i < (int) (sizeof tokentab2 / sizeof tokentab2[0]) ; i++)
8295796c8dcSSimon Schubert if (strncmp (tokentab2[i].name, tokstart, 2) == 0)
8305796c8dcSSimon Schubert {
8315796c8dcSSimon Schubert lexptr += 2;
8325796c8dcSSimon Schubert return tokentab2[i].token;
8335796c8dcSSimon Schubert }
8345796c8dcSSimon Schubert
8355796c8dcSSimon Schubert switch (c = *tokstart)
8365796c8dcSSimon Schubert {
8375796c8dcSSimon Schubert case 0:
8385796c8dcSSimon Schubert return 0;
8395796c8dcSSimon Schubert
8405796c8dcSSimon Schubert case ' ':
8415796c8dcSSimon Schubert case '\t':
8425796c8dcSSimon Schubert case '\n':
8435796c8dcSSimon Schubert lexptr++;
8445796c8dcSSimon Schubert goto retry;
8455796c8dcSSimon Schubert
8465796c8dcSSimon Schubert case '(':
8475796c8dcSSimon Schubert paren_depth++;
8485796c8dcSSimon Schubert lexptr++;
8495796c8dcSSimon Schubert return c;
8505796c8dcSSimon Schubert
8515796c8dcSSimon Schubert case ')':
8525796c8dcSSimon Schubert if (paren_depth == 0)
8535796c8dcSSimon Schubert return 0;
8545796c8dcSSimon Schubert paren_depth--;
8555796c8dcSSimon Schubert lexptr++;
8565796c8dcSSimon Schubert return c;
8575796c8dcSSimon Schubert
8585796c8dcSSimon Schubert case ',':
8595796c8dcSSimon Schubert if (comma_terminates && paren_depth == 0)
8605796c8dcSSimon Schubert return 0;
8615796c8dcSSimon Schubert lexptr++;
8625796c8dcSSimon Schubert return c;
8635796c8dcSSimon Schubert
8645796c8dcSSimon Schubert case '.':
8655796c8dcSSimon Schubert /* Might be a floating point number. */
8665796c8dcSSimon Schubert if (lexptr[1] >= '0' && lexptr[1] <= '9')
8675796c8dcSSimon Schubert break; /* Falls into number code. */
8685796c8dcSSimon Schubert else
8695796c8dcSSimon Schubert {
8705796c8dcSSimon Schubert lexptr++;
8715796c8dcSSimon Schubert return DOT;
8725796c8dcSSimon Schubert }
8735796c8dcSSimon Schubert
8745796c8dcSSimon Schubert /* These are character tokens that appear as-is in the YACC grammar */
8755796c8dcSSimon Schubert case '+':
8765796c8dcSSimon Schubert case '-':
8775796c8dcSSimon Schubert case '*':
8785796c8dcSSimon Schubert case '/':
8795796c8dcSSimon Schubert case '^':
8805796c8dcSSimon Schubert case '<':
8815796c8dcSSimon Schubert case '>':
8825796c8dcSSimon Schubert case '[':
8835796c8dcSSimon Schubert case ']':
8845796c8dcSSimon Schubert case '=':
8855796c8dcSSimon Schubert case '{':
8865796c8dcSSimon Schubert case '}':
8875796c8dcSSimon Schubert case '#':
8885796c8dcSSimon Schubert case '@':
8895796c8dcSSimon Schubert case '~':
8905796c8dcSSimon Schubert case '&':
8915796c8dcSSimon Schubert lexptr++;
8925796c8dcSSimon Schubert return c;
8935796c8dcSSimon Schubert
8945796c8dcSSimon Schubert case '\'' :
8955796c8dcSSimon Schubert case '"':
8965796c8dcSSimon Schubert quote = c;
8975796c8dcSSimon Schubert for (namelen = 1; (c = tokstart[namelen]) != quote && c != '\0'; namelen++)
8985796c8dcSSimon Schubert if (c == '\\')
8995796c8dcSSimon Schubert {
9005796c8dcSSimon Schubert c = tokstart[++namelen];
9015796c8dcSSimon Schubert if (c >= '0' && c <= '9')
9025796c8dcSSimon Schubert {
9035796c8dcSSimon Schubert c = tokstart[++namelen];
9045796c8dcSSimon Schubert if (c >= '0' && c <= '9')
9055796c8dcSSimon Schubert c = tokstart[++namelen];
9065796c8dcSSimon Schubert }
9075796c8dcSSimon Schubert }
9085796c8dcSSimon Schubert if(c != quote)
909c50c785cSJohn Marino error (_("Unterminated string or character constant."));
9105796c8dcSSimon Schubert yylval.sval.ptr = tokstart + 1;
9115796c8dcSSimon Schubert yylval.sval.length = namelen - 1;
9125796c8dcSSimon Schubert lexptr += namelen + 1;
9135796c8dcSSimon Schubert
9145796c8dcSSimon Schubert if(namelen == 2) /* Single character */
9155796c8dcSSimon Schubert {
9165796c8dcSSimon Schubert yylval.ulval = tokstart[1];
9175796c8dcSSimon Schubert return CHAR;
9185796c8dcSSimon Schubert }
9195796c8dcSSimon Schubert else
9205796c8dcSSimon Schubert return STRING;
9215796c8dcSSimon Schubert }
9225796c8dcSSimon Schubert
9235796c8dcSSimon Schubert /* Is it a number? */
9245796c8dcSSimon Schubert /* Note: We have already dealt with the case of the token '.'.
9255796c8dcSSimon Schubert See case '.' above. */
9265796c8dcSSimon Schubert if ((c >= '0' && c <= '9'))
9275796c8dcSSimon Schubert {
9285796c8dcSSimon Schubert /* It's a number. */
9295796c8dcSSimon Schubert int got_dot = 0, got_e = 0;
9305796c8dcSSimon Schubert char *p = tokstart;
9315796c8dcSSimon Schubert int toktype;
9325796c8dcSSimon Schubert
9335796c8dcSSimon Schubert for (++p ;; ++p)
9345796c8dcSSimon Schubert {
9355796c8dcSSimon Schubert if (!got_e && (*p == 'e' || *p == 'E'))
9365796c8dcSSimon Schubert got_dot = got_e = 1;
9375796c8dcSSimon Schubert else if (!got_dot && *p == '.')
9385796c8dcSSimon Schubert got_dot = 1;
9395796c8dcSSimon Schubert else if (got_e && (p[-1] == 'e' || p[-1] == 'E')
9405796c8dcSSimon Schubert && (*p == '-' || *p == '+'))
9415796c8dcSSimon Schubert /* This is the sign of the exponent, not the end of the
9425796c8dcSSimon Schubert number. */
9435796c8dcSSimon Schubert continue;
9445796c8dcSSimon Schubert else if ((*p < '0' || *p > '9') &&
9455796c8dcSSimon Schubert (*p < 'A' || *p > 'F') &&
9465796c8dcSSimon Schubert (*p != 'H')) /* Modula-2 hexadecimal number */
9475796c8dcSSimon Schubert break;
9485796c8dcSSimon Schubert }
9495796c8dcSSimon Schubert toktype = parse_number (p - tokstart);
9505796c8dcSSimon Schubert if (toktype == ERROR)
9515796c8dcSSimon Schubert {
9525796c8dcSSimon Schubert char *err_copy = (char *) alloca (p - tokstart + 1);
9535796c8dcSSimon Schubert
9545796c8dcSSimon Schubert memcpy (err_copy, tokstart, p - tokstart);
9555796c8dcSSimon Schubert err_copy[p - tokstart] = 0;
956c50c785cSJohn Marino error (_("Invalid number \"%s\"."), err_copy);
9575796c8dcSSimon Schubert }
9585796c8dcSSimon Schubert lexptr = p;
9595796c8dcSSimon Schubert return toktype;
9605796c8dcSSimon Schubert }
9615796c8dcSSimon Schubert
9625796c8dcSSimon Schubert if (!(c == '_' || c == '$'
9635796c8dcSSimon Schubert || (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z')))
9645796c8dcSSimon Schubert /* We must have come across a bad character (e.g. ';'). */
965c50c785cSJohn Marino error (_("Invalid character '%c' in expression."), c);
9665796c8dcSSimon Schubert
9675796c8dcSSimon Schubert /* It's a name. See how long it is. */
9685796c8dcSSimon Schubert namelen = 0;
9695796c8dcSSimon Schubert for (c = tokstart[namelen];
9705796c8dcSSimon Schubert (c == '_' || c == '$' || (c >= '0' && c <= '9')
9715796c8dcSSimon Schubert || (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z'));
9725796c8dcSSimon Schubert c = tokstart[++namelen])
9735796c8dcSSimon Schubert ;
9745796c8dcSSimon Schubert
9755796c8dcSSimon Schubert /* The token "if" terminates the expression and is NOT
9765796c8dcSSimon Schubert removed from the input stream. */
9775796c8dcSSimon Schubert if (namelen == 2 && tokstart[0] == 'i' && tokstart[1] == 'f')
9785796c8dcSSimon Schubert {
9795796c8dcSSimon Schubert return 0;
9805796c8dcSSimon Schubert }
9815796c8dcSSimon Schubert
9825796c8dcSSimon Schubert lexptr += namelen;
9835796c8dcSSimon Schubert
9845796c8dcSSimon Schubert /* Lookup special keywords */
9855796c8dcSSimon Schubert for(i = 0 ; i < (int) (sizeof(keytab) / sizeof(keytab[0])) ; i++)
9865796c8dcSSimon Schubert if (namelen == strlen (keytab[i].keyw)
9875796c8dcSSimon Schubert && strncmp (tokstart, keytab[i].keyw, namelen) == 0)
9885796c8dcSSimon Schubert return keytab[i].token;
9895796c8dcSSimon Schubert
9905796c8dcSSimon Schubert yylval.sval.ptr = tokstart;
9915796c8dcSSimon Schubert yylval.sval.length = namelen;
9925796c8dcSSimon Schubert
9935796c8dcSSimon Schubert if (*tokstart == '$')
9945796c8dcSSimon Schubert {
9955796c8dcSSimon Schubert write_dollar_variable (yylval.sval);
9965796c8dcSSimon Schubert return INTERNAL_VAR;
9975796c8dcSSimon Schubert }
9985796c8dcSSimon Schubert
9995796c8dcSSimon Schubert /* Use token-type BLOCKNAME for symbols that happen to be defined as
10005796c8dcSSimon Schubert functions. If this is not so, then ...
10015796c8dcSSimon Schubert Use token-type TYPENAME for symbols that happen to be defined
10025796c8dcSSimon Schubert currently as names of types; NAME for other symbols.
10035796c8dcSSimon Schubert The caller is not constrained to care about the distinction. */
10045796c8dcSSimon Schubert {
10055796c8dcSSimon Schubert
10065796c8dcSSimon Schubert
10075796c8dcSSimon Schubert char *tmp = copy_name (yylval.sval);
10085796c8dcSSimon Schubert struct symbol *sym;
10095796c8dcSSimon Schubert
1010cf7f2e2dSJohn Marino if (lookup_symtab (tmp))
10115796c8dcSSimon Schubert return BLOCKNAME;
10125796c8dcSSimon Schubert sym = lookup_symbol (tmp, expression_context_block, VAR_DOMAIN, 0);
10135796c8dcSSimon Schubert if (sym && SYMBOL_CLASS (sym) == LOC_BLOCK)
10145796c8dcSSimon Schubert return BLOCKNAME;
10155796c8dcSSimon Schubert if (lookup_typename (parse_language, parse_gdbarch,
10165796c8dcSSimon Schubert copy_name (yylval.sval), expression_context_block, 1))
10175796c8dcSSimon Schubert return TYPENAME;
10185796c8dcSSimon Schubert
10195796c8dcSSimon Schubert if(sym)
10205796c8dcSSimon Schubert {
10215796c8dcSSimon Schubert switch(SYMBOL_CLASS (sym))
10225796c8dcSSimon Schubert {
10235796c8dcSSimon Schubert case LOC_STATIC:
10245796c8dcSSimon Schubert case LOC_REGISTER:
10255796c8dcSSimon Schubert case LOC_ARG:
10265796c8dcSSimon Schubert case LOC_REF_ARG:
10275796c8dcSSimon Schubert case LOC_REGPARM_ADDR:
10285796c8dcSSimon Schubert case LOC_LOCAL:
10295796c8dcSSimon Schubert case LOC_CONST:
10305796c8dcSSimon Schubert case LOC_CONST_BYTES:
10315796c8dcSSimon Schubert case LOC_OPTIMIZED_OUT:
10325796c8dcSSimon Schubert case LOC_COMPUTED:
10335796c8dcSSimon Schubert return NAME;
10345796c8dcSSimon Schubert
10355796c8dcSSimon Schubert case LOC_TYPEDEF:
10365796c8dcSSimon Schubert return TYPENAME;
10375796c8dcSSimon Schubert
10385796c8dcSSimon Schubert case LOC_BLOCK:
10395796c8dcSSimon Schubert return BLOCKNAME;
10405796c8dcSSimon Schubert
10415796c8dcSSimon Schubert case LOC_UNDEF:
1042c50c785cSJohn Marino error (_("internal: Undefined class in m2lex()"));
10435796c8dcSSimon Schubert
10445796c8dcSSimon Schubert case LOC_LABEL:
10455796c8dcSSimon Schubert case LOC_UNRESOLVED:
1046c50c785cSJohn Marino error (_("internal: Unforseen case in m2lex()"));
10475796c8dcSSimon Schubert
10485796c8dcSSimon Schubert default:
1049c50c785cSJohn Marino error (_("unhandled token in m2lex()"));
10505796c8dcSSimon Schubert break;
10515796c8dcSSimon Schubert }
10525796c8dcSSimon Schubert }
10535796c8dcSSimon Schubert else
10545796c8dcSSimon Schubert {
10555796c8dcSSimon Schubert /* Built-in BOOLEAN type. This is sort of a hack. */
10565796c8dcSSimon Schubert if (strncmp (tokstart, "TRUE", 4) == 0)
10575796c8dcSSimon Schubert {
10585796c8dcSSimon Schubert yylval.ulval = 1;
10595796c8dcSSimon Schubert return M2_TRUE;
10605796c8dcSSimon Schubert }
10615796c8dcSSimon Schubert else if (strncmp (tokstart, "FALSE", 5) == 0)
10625796c8dcSSimon Schubert {
10635796c8dcSSimon Schubert yylval.ulval = 0;
10645796c8dcSSimon Schubert return M2_FALSE;
10655796c8dcSSimon Schubert }
10665796c8dcSSimon Schubert }
10675796c8dcSSimon Schubert
10685796c8dcSSimon Schubert /* Must be another type of name... */
10695796c8dcSSimon Schubert return NAME;
10705796c8dcSSimon Schubert }
10715796c8dcSSimon Schubert }
10725796c8dcSSimon Schubert
10735796c8dcSSimon Schubert void
yyerror(char * msg)1074*ef5ccd6cSJohn Marino yyerror (char *msg)
10755796c8dcSSimon Schubert {
10765796c8dcSSimon Schubert if (prev_lexptr)
10775796c8dcSSimon Schubert lexptr = prev_lexptr;
10785796c8dcSSimon Schubert
1079c50c785cSJohn Marino error (_("A %s in expression, near `%s'."), (msg ? msg : "error"), lexptr);
10805796c8dcSSimon Schubert }
1081