p-exp.y revision 130803
142421Syokota/* YACC parser for Pascal expressions, for GDB.
242421Syokota   Copyright 2000
342421Syokota   Free Software Foundation, Inc.
442421Syokota
542421SyokotaThis file is part of GDB.
642421Syokota
742421SyokotaThis program is free software; you can redistribute it and/or modify
842421Syokotait under the terms of the GNU General Public License as published by
942421Syokotathe Free Software Foundation; either version 2 of the License, or
1042421Syokota(at your option) any later version.
1142421Syokota
1242421SyokotaThis program is distributed in the hope that it will be useful,
1342421Syokotabut WITHOUT ANY WARRANTY; without even the implied warranty of
1442421SyokotaMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
1542421SyokotaGNU General Public License for more details.
1642421Syokota
1742421SyokotaYou should have received a copy of the GNU General Public License
1842421Syokotaalong with this program; if not, write to the Free Software
1942421SyokotaFoundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */
2042421Syokota
2142421Syokota/* This file is derived from c-exp.y */
2242421Syokota
2342421Syokota/* Parse a Pascal expression from text in a string,
2442421Syokota   and return the result as a  struct expression  pointer.
2542421Syokota   That structure contains arithmetic operations in reverse polish,
2650477Speter   with constants represented by operations that are followed by special data.
2742421Syokota   See expression.h for the details of the format.
2842421Syokota   What is important here is that it can be built up sequentially
2942421Syokota   during the process of parsing; the lower levels of the tree always
3044628Syokota   come first in the result.
3142421Syokota
3242421Syokota   Note that malloc's and realloc's in this file are transformed to
3342421Syokota   xmalloc and xrealloc respectively by the same sed command in the
3442421Syokota   makefile that remaps any other malloc/realloc inserted by the parser
3547336Syokota   generator.  Doing this with #defines and trying to control the interaction
3642421Syokota   with include files (<malloc.h> and <stdlib.h> for example) just became
3742421Syokota   too messy, particularly when such includes can be inserted at random
3842421Syokota   times by the parser generator.  */
3958271Syokota
4058271Syokota/* Known bugs or limitations:
4158271Syokota    - pascal string operations are not supported at all.
4255731Syokota    - there are some problems with boolean types.
4355731Syokota    - Pascal type hexadecimal constants are not supported
4455731Syokota      because they conflict with the internal variables format.
4555731Syokota   Probably also lots of other problems, less well defined PM */
4655731Syokota%{
4755731Syokota
4855731Syokota#include "defs.h"
4955731Syokota#include "gdb_string.h"
5055731Syokota#include <ctype.h>
5155731Syokota#include "expression.h"
5280040Syokota#include "value.h"
5342421Syokota#include "parser-defs.h"
5442421Syokota#include "language.h"
5542421Syokota#include "p-lang.h"
5642421Syokota#include "bfd.h" /* Required by objfiles.h.  */
5742831Syokota#include "symfile.h" /* Required by objfiles.h.  */
5842831Syokota#include "objfiles.h" /* For have_full_symbols and have_partial_symbols */
5942421Syokota#include "block.h"
6042421Syokota
6142421Syokota/* Remap normal yacc parser interface names (yyparse, yylex, yyerror, etc),
6258271Syokota   as well as gratuitiously global symbol names, so we can have multiple
6342421Syokota   yacc generated parsers in gdb.  Note that these are only the variables
6442421Syokota   produced by yacc.  If other parser generators (bison, byacc, etc) produce
6542421Syokota   additional global names that conflict at link time, then those parser
6644628Syokota   generators need to be fixed instead of adding those names to this list. */
6742421Syokota
6842421Syokota#define	yymaxdepth pascal_maxdepth
6942421Syokota#define	yyparse	pascal_parse
7042421Syokota#define	yylex	pascal_lex
7142421Syokota#define	yyerror	pascal_error
7258271Syokota#define	yylval	pascal_lval
7342421Syokota#define	yychar	pascal_char
7444628Syokota#define	yydebug	pascal_debug
7544628Syokota#define	yypact	pascal_pact
7644628Syokota#define	yyr1	pascal_r1
7744628Syokota#define	yyr2	pascal_r2
7842421Syokota#define	yydef	pascal_def
7942421Syokota#define	yychk	pascal_chk
8042421Syokota#define	yypgo	pascal_pgo
8158271Syokota#define	yyact	pascal_act
8242421Syokota#define	yyexca	pascal_exca
8342421Syokota#define yyerrflag pascal_errflag
8444628Syokota#define yynerrs	pascal_nerrs
8542421Syokota#define	yyps	pascal_ps
8642421Syokota#define	yypv	pascal_pv
8742421Syokota#define	yys	pascal_s
8842421Syokota#define	yy_yys	pascal_yys
8942421Syokota#define	yystate	pascal_state
9042421Syokota#define	yytmp	pascal_tmp
9142421Syokota#define	yyv	pascal_v
9258271Syokota#define	yy_yyv	pascal_yyv
9344628Syokota#define	yyval	pascal_val
9450154Syokota#define	yylloc	pascal_lloc
9544628Syokota#define yyreds	pascal_reds		/* With YYDEBUG defined */
9642421Syokota#define yytoks	pascal_toks		/* With YYDEBUG defined */
9744628Syokota#define yyname	pascal_name		/* With YYDEBUG defined */
9850154Syokota#define yyrule	pascal_rule		/* With YYDEBUG defined */
9944628Syokota#define yylhs	pascal_yylhs
10044628Syokota#define yylen	pascal_yylen
10150154Syokota#define yydefred pascal_yydefred
10242421Syokota#define yydgoto	pascal_yydgoto
10342421Syokota#define yysindex pascal_yysindex
10442421Syokota#define yyrindex pascal_yyrindex
10550154Syokota#define yygindex pascal_yygindex
10642421Syokota#define yytable	 pascal_yytable
10742421Syokota#define yycheck	 pascal_yycheck
10842421Syokota
10942421Syokota#ifndef YYDEBUG
11042421Syokota#define	YYDEBUG 1		/* Default to yydebug support */
11142421Syokota#endif
11242421Syokota
11342421Syokota#define YYFPRINTF parser_fprintf
11450154Syokota
11542421Syokotaint yyparse (void);
11642421Syokota
11750154Syokotastatic int yylex (void);
11842421Syokota
11942421Syokotavoid
12042421Syokotayyerror (char *);
12142421Syokota
12242421Syokotastatic char * uptok (char *, int);
12342421Syokota%}
12442421Syokota
12542421Syokota/* Although the yacc "value" of an expression is not used,
12642421Syokota   since the result is stored in the structure being created,
12756334Syokota   other node types do have values.  */
12856334Syokota
12956334Syokota%union
13056334Syokota  {
13142421Syokota    LONGEST lval;
13242421Syokota    struct {
13342421Syokota      LONGEST val;
13456334Syokota      struct type *type;
13556334Syokota    } typed_val_int;
13656334Syokota    struct {
13756334Syokota      DOUBLEST dval;
13856334Syokota      struct type *type;
13956334Syokota    } typed_val_float;
14056334Syokota    struct symbol *sym;
14142421Syokota    struct type *tval;
14242421Syokota    struct stoken sval;
14356334Syokota    struct ttype tsym;
14456334Syokota    struct symtoken ssym;
14556334Syokota    int voidval;
14656334Syokota    struct block *bval;
14756334Syokota    enum exp_opcode opcode;
14856334Syokota    struct internalvar *ivar;
14956334Syokota
15056334Syokota    struct type **tvec;
15142421Syokota    int *ivec;
15242421Syokota  }
15342421Syokota
15442421Syokota%{
15542421Syokota/* YYSTYPE gets defined by %union */
15642421Syokotastatic int
15742421Syokotaparse_number (char *, int, int, YYSTYPE *);
15842421Syokota
15942421Syokotastatic struct type *current_type;
16042421Syokota
16142421Syokotastatic void push_current_type (void);
16244628Syokotastatic void pop_current_type (void);
16342421Syokotastatic int search_field;
16442421Syokota%}
16542421Syokota
16642421Syokota%type <voidval> exp exp1 type_exp start normal_start variable qualified_name
16742421Syokota%type <tval> type typebase
16842421Syokota/* %type <bval> block */
16942421Syokota
17042421Syokota/* Fancy type parsing.  */
17142421Syokota%type <tval> ptype
17242421Syokota
17342421Syokota%token <typed_val_int> INT
17442421Syokota%token <typed_val_float> FLOAT
17542421Syokota
17642421Syokota/* Both NAME and TYPENAME tokens represent symbols in the input,
17742421Syokota   and both convey their data as strings.
17842421Syokota   But a TYPENAME is a string that happens to be defined as a typedef
17942421Syokota   or builtin type name (such as int or char)
18042421Syokota   and a NAME is any other symbol.
18142421Syokota   Contexts where this distinction is not important can use the
18244628Syokota   nonterminal "name", which matches either NAME or TYPENAME.  */
18342421Syokota
18442421Syokota%token <sval> STRING
18542421Syokota%token <sval> FIELDNAME
18642421Syokota%token <ssym> NAME /* BLOCKNAME defined below to give it higher precedence. */
18742421Syokota%token <tsym> TYPENAME
18842421Syokota%type <sval> name
18942421Syokota%type <ssym> name_not_typename
19042421Syokota
19142421Syokota/* A NAME_OR_INT is a symbol which is not known in the symbol table,
19242421Syokota   but which would parse as a valid number in the current input radix.
19342421Syokota   E.g. "c" when input_radix==16.  Depending on the parse, it will be
19442421Syokota   turned into a name or into a number.  */
19542421Syokota
19642421Syokota%token <ssym> NAME_OR_INT
19742421Syokota
19842421Syokota%token STRUCT CLASS SIZEOF COLONCOLON
19942421Syokota%token ERROR
20042421Syokota
20142421Syokota/* Special type cases, put in to allow the parser to distinguish different
20242421Syokota   legal basetypes.  */
20342421Syokota
20442421Syokota%token <voidval> VARIABLE
20542421Syokota
20642421Syokota
20744628Syokota/* Object pascal */
20842421Syokota%token THIS
20942421Syokota%token <lval> TRUEKEYWORD FALSEKEYWORD
21042421Syokota
21142421Syokota%left ','
21242421Syokota%left ABOVE_COMMA
21342421Syokota%right ASSIGN
21442421Syokota%left NOT
21542421Syokota%left OR
21642421Syokota%left XOR
21742421Syokota%left ANDAND
21842421Syokota%left '=' NOTEQUAL
21942421Syokota%left '<' '>' LEQ GEQ
22042421Syokota%left LSH RSH DIV MOD
22142421Syokota%left '@'
22242421Syokota%left '+' '-'
22342421Syokota%left '*' '/'
22442421Syokota%right UNARY INCREMENT DECREMENT
22542421Syokota%right ARROW '.' '[' '('
22642421Syokota%left '^'
22744628Syokota%token <ssym> BLOCKNAME
22842421Syokota%type <bval> block
22942421Syokota%left COLONCOLON
23042421Syokota
23142421Syokota
23242421Syokota%%
23342421Syokota
23455731Syokotastart   :	{ current_type = NULL;
23542421Syokota		  search_field = 0;
23642421Syokota		}
23742421Syokota		normal_start {}
23842421Syokota	;
23942421Syokota
24042421Syokotanormal_start	:
24144628Syokota		exp1
24254543Syokota	|	type_exp
24354543Syokota	;
24442421Syokota
24542421Syokotatype_exp:	type
24642421Syokota			{ write_exp_elt_opcode(OP_TYPE);
24742421Syokota			  write_exp_elt_type($1);
24844628Syokota			  write_exp_elt_opcode(OP_TYPE);
24944628Syokota			  current_type = $1; } ;
25044628Syokota
25144628Syokota/* Expressions, including the comma operator.  */
25242831Syokotaexp1	:	exp
25342421Syokota	|	exp1 ',' exp
25442421Syokota			{ write_exp_elt_opcode (BINOP_COMMA); }
25542421Syokota	;
25642421Syokota
25742421Syokota/* Expressions, not including the comma operator.  */
25842421Syokotaexp	:	exp '^'   %prec UNARY
25942421Syokota			{ write_exp_elt_opcode (UNOP_IND);
26042421Syokota			  if (current_type)
26142421Syokota			    current_type = TYPE_TARGET_TYPE (current_type); }
26242421Syokota	;
26342421Syokota
26442421Syokotaexp	:	'@' exp    %prec UNARY
26542421Syokota			{ write_exp_elt_opcode (UNOP_ADDR);
26642421Syokota			  if (current_type)
26794228Sasmodai			    current_type = TYPE_POINTER_TYPE (current_type); }
26842421Syokota	;
26942421Syokota
27042421Syokotaexp	:	'-' exp    %prec UNARY
27142421Syokota			{ write_exp_elt_opcode (UNOP_NEG); }
27242421Syokota	;
27342421Syokota
27442421Syokotaexp	:	NOT exp    %prec UNARY
27544628Syokota			{ write_exp_elt_opcode (UNOP_LOGICAL_NOT); }
27642421Syokota	;
27748878Syokota
27848878Syokotaexp	:	INCREMENT '(' exp ')'   %prec UNARY
27948878Syokota			{ write_exp_elt_opcode (UNOP_PREINCREMENT); }
28046764Syokota	;
28146764Syokota
28246764Syokotaexp	:	DECREMENT  '(' exp ')'   %prec UNARY
28346764Syokota			{ write_exp_elt_opcode (UNOP_PREDECREMENT); }
28446764Syokota	;
28546764Syokota
28646764Syokotaexp	:	exp '.' { search_field = 1; }
28746764Syokota		FIELDNAME
28844628Syokota		/* name */
28948878Syokota			{ write_exp_elt_opcode (STRUCTOP_STRUCT);
29044628Syokota			  write_exp_string ($4);
29145720Speter			  write_exp_elt_opcode (STRUCTOP_STRUCT);
29246764Syokota			  search_field = 0;
29346764Syokota			  if (current_type)
29446764Syokota			    { while (TYPE_CODE (current_type) == TYPE_CODE_PTR)
29546764Syokota				current_type = TYPE_TARGET_TYPE (current_type);
29642421Syokota			      current_type = lookup_struct_elt_type (
29742421Syokota				current_type, $4.ptr, 0); };
29842421Syokota			 } ;
29944628Syokotaexp	:	exp '['
30044628Syokota			/* We need to save the current_type value */
30142421Syokota			{ char *arrayname;
30244628Syokota			  int arrayfieldindex;
30344628Syokota			  arrayfieldindex = is_pascal_string_type (
30442421Syokota				current_type, NULL, NULL,
30544628Syokota				NULL, NULL, &arrayname);
30644628Syokota			  if (arrayfieldindex)
30744628Syokota			    {
30844628Syokota			      struct stoken stringsval;
30944628Syokota			      stringsval.ptr = alloca (strlen (arrayname) + 1);
31044628Syokota			      stringsval.length = strlen (arrayname);
31144628Syokota			      strcpy (stringsval.ptr, arrayname);
31244628Syokota			      current_type = TYPE_FIELD_TYPE (current_type,
31344628Syokota				arrayfieldindex - 1);
31444628Syokota			      write_exp_elt_opcode (STRUCTOP_STRUCT);
31544628Syokota			      write_exp_string (stringsval);
31658271Syokota			      write_exp_elt_opcode (STRUCTOP_STRUCT);
31744628Syokota			    }
31844628Syokota			  push_current_type ();  }
31944628Syokota		exp1 ']'
32044628Syokota			{ pop_current_type ();
32142421Syokota			  write_exp_elt_opcode (BINOP_SUBSCRIPT);
32242421Syokota			  if (current_type)
32342421Syokota			    current_type = TYPE_TARGET_TYPE (current_type); }
32458271Syokota	;
32544628Syokota
32644628Syokotaexp	:	exp '('
32744628Syokota			/* This is to save the value of arglist_len
32844628Syokota			   being accumulated by an outer function call.  */
32944628Syokota			{ push_current_type ();
33042421Syokota			  start_arglist (); }
33144628Syokota		arglist ')'	%prec ARROW
33242421Syokota			{ write_exp_elt_opcode (OP_FUNCALL);
33342421Syokota			  write_exp_elt_longcst ((LONGEST) end_arglist ());
33444628Syokota			  write_exp_elt_opcode (OP_FUNCALL);
33542421Syokota			  pop_current_type (); }
33644628Syokota	;
33742421Syokota
33842421Syokotaarglist	:
33942421Syokota         | exp
34042421Syokota			{ arglist_len = 1; }
34142421Syokota	 | arglist ',' exp   %prec ABOVE_COMMA
34242421Syokota			{ arglist_len++; }
34342421Syokota	;
34455731Syokota
34558271Syokotaexp	:	type '(' exp ')' %prec UNARY
34642421Syokota			{ if (current_type)
34742421Syokota			    {
34842421Syokota			      /* Allow automatic dereference of classes.  */
34942421Syokota			      if ((TYPE_CODE (current_type) == TYPE_CODE_PTR)
35044628Syokota				  && (TYPE_CODE (TYPE_TARGET_TYPE (current_type)) == TYPE_CODE_CLASS)
35142421Syokota				  && (TYPE_CODE ($1) == TYPE_CODE_CLASS))
35242421Syokota				write_exp_elt_opcode (UNOP_IND);
35342421Syokota			    }
35442421Syokota			  write_exp_elt_opcode (UNOP_CAST);
35542421Syokota			  write_exp_elt_type ($1);
35642421Syokota			  write_exp_elt_opcode (UNOP_CAST);
35742421Syokota			  current_type = $1; }
35842421Syokota	;
35969781Sdwmalone
36069781Sdwmaloneexp	:	'(' exp1 ')'
36142421Syokota			{ }
36242421Syokota	;
36342421Syokota
36442421Syokota/* Binary operators in order of decreasing precedence.  */
36569781Sdwmalone
36669781Sdwmaloneexp	:	exp '*' exp
36742421Syokota			{ write_exp_elt_opcode (BINOP_MUL); }
36842421Syokota	;
36942421Syokota
37042421Syokotaexp	:	exp '/' exp
37142421Syokota			{ write_exp_elt_opcode (BINOP_DIV); }
37242421Syokota	;
37342421Syokota
37442421Syokotaexp	:	exp DIV exp
37571394Sdwmalone			{ write_exp_elt_opcode (BINOP_INTDIV); }
37669781Sdwmalone	;
37742421Syokota
37842421Syokotaexp	:	exp MOD exp
37944628Syokota			{ write_exp_elt_opcode (BINOP_REM); }
38042421Syokota	;
38142421Syokota
38242421Syokotaexp	:	exp '+' exp
38342421Syokota			{ write_exp_elt_opcode (BINOP_ADD); }
38442421Syokota	;
38542421Syokota
38642421Syokotaexp	:	exp '-' exp
38742421Syokota			{ write_exp_elt_opcode (BINOP_SUB); }
38842421Syokota	;
38942421Syokota
39042421Syokotaexp	:	exp LSH exp
39144628Syokota			{ write_exp_elt_opcode (BINOP_LSH); }
39258271Syokota	;
39344628Syokota
39442421Syokotaexp	:	exp RSH exp
39544628Syokota			{ write_exp_elt_opcode (BINOP_RSH); }
39658271Syokota	;
39744628Syokota
39844628Syokotaexp	:	exp '=' exp
39944628Syokota			{ write_exp_elt_opcode (BINOP_EQUAL); }
40044628Syokota	;
40144628Syokota
40244628Syokotaexp	:	exp NOTEQUAL exp
40344628Syokota			{ write_exp_elt_opcode (BINOP_NOTEQUAL); }
40444628Syokota	;
40544628Syokota
40644628Syokotaexp	:	exp LEQ exp
40744628Syokota			{ write_exp_elt_opcode (BINOP_LEQ); }
40844628Syokota	;
40944628Syokota
41044628Syokotaexp	:	exp GEQ exp
41144628Syokota			{ write_exp_elt_opcode (BINOP_GEQ); }
41244628Syokota	;
41344628Syokota
41444628Syokotaexp	:	exp '<' exp
41544628Syokota			{ write_exp_elt_opcode (BINOP_LESS); }
41644628Syokota	;
41742421Syokota
41844628Syokotaexp	:	exp '>' exp
41949820Syokota			{ write_exp_elt_opcode (BINOP_GTR); }
42042421Syokota	;
42144628Syokota
42244628Syokotaexp	:	exp ANDAND exp
42342421Syokota			{ write_exp_elt_opcode (BINOP_BITWISE_AND); }
42444628Syokota	;
42555731Syokota
42655731Syokotaexp	:	exp XOR exp
42755731Syokota			{ write_exp_elt_opcode (BINOP_BITWISE_XOR); }
42855731Syokota	;
42942421Syokota
43042421Syokotaexp	:	exp OR exp
43142421Syokota			{ write_exp_elt_opcode (BINOP_BITWISE_IOR); }
43242421Syokota	;
43342421Syokota
43442421Syokotaexp	:	exp ASSIGN exp
43542421Syokota			{ write_exp_elt_opcode (BINOP_ASSIGN); }
43642421Syokota	;
43742421Syokota
43842421Syokotaexp	:	TRUEKEYWORD
43942421Syokota			{ write_exp_elt_opcode (OP_BOOL);
44042421Syokota			  write_exp_elt_longcst ((LONGEST) $1);
44142421Syokota			  write_exp_elt_opcode (OP_BOOL); }
44242421Syokota	;
44342421Syokota
44442421Syokotaexp	:	FALSEKEYWORD
44542421Syokota			{ write_exp_elt_opcode (OP_BOOL);
44642421Syokota			  write_exp_elt_longcst ((LONGEST) $1);
44742421Syokota			  write_exp_elt_opcode (OP_BOOL); }
44842421Syokota	;
44942421Syokota
45044628Syokotaexp	:	INT
45142421Syokota			{ write_exp_elt_opcode (OP_LONG);
45242421Syokota			  write_exp_elt_type ($1.type);
45355731Syokota			  write_exp_elt_longcst ((LONGEST)($1.val));
45442421Syokota			  write_exp_elt_opcode (OP_LONG); }
45542421Syokota	;
45642421Syokota
45742421Syokotaexp	:	NAME_OR_INT
45842421Syokota			{ YYSTYPE val;
45942421Syokota			  parse_number ($1.stoken.ptr, $1.stoken.length, 0, &val);
46042421Syokota			  write_exp_elt_opcode (OP_LONG);
46142421Syokota			  write_exp_elt_type (val.typed_val_int.type);
46242421Syokota			  write_exp_elt_longcst ((LONGEST)val.typed_val_int.val);
46342421Syokota			  write_exp_elt_opcode (OP_LONG);
46442421Syokota			}
46542421Syokota	;
46642421Syokota
46742421Syokota
46842421Syokotaexp	:	FLOAT
46942421Syokota			{ write_exp_elt_opcode (OP_DOUBLE);
47042421Syokota			  write_exp_elt_type ($1.type);
47142421Syokota			  write_exp_elt_dblcst ($1.dval);
47242421Syokota			  write_exp_elt_opcode (OP_DOUBLE); }
47342421Syokota	;
47442421Syokota
47555731Syokotaexp	:	variable
47655731Syokota	;
47755731Syokota
47855731Syokotaexp	:	VARIABLE
47942421Syokota			/* Already written by write_dollar_variable. */
48042421Syokota	;
48142421Syokota
48242421Syokotaexp	:	SIZEOF '(' type ')'	%prec UNARY
48342421Syokota			{ write_exp_elt_opcode (OP_LONG);
48442421Syokota			  write_exp_elt_type (builtin_type_int);
48542421Syokota			  CHECK_TYPEDEF ($3);
48642421Syokota			  write_exp_elt_longcst ((LONGEST) TYPE_LENGTH ($3));
48742421Syokota			  write_exp_elt_opcode (OP_LONG); }
48842421Syokota	;
48942421Syokota
49042421Syokotaexp	:	STRING
49142421Syokota			{ /* C strings are converted into array constants with
49242421Syokota			     an explicit null byte added at the end.  Thus
49342421Syokota			     the array upper bound is the string length.
49442421Syokota			     There is no such thing in C as a completely empty
49542421Syokota			     string. */
49642421Syokota			  char *sp = $1.ptr; int count = $1.length;
49742421Syokota			  while (count-- > 0)
49842421Syokota			    {
49942421Syokota			      write_exp_elt_opcode (OP_LONG);
50042421Syokota			      write_exp_elt_type (builtin_type_char);
50142421Syokota			      write_exp_elt_longcst ((LONGEST)(*sp++));
50242421Syokota			      write_exp_elt_opcode (OP_LONG);
50342421Syokota			    }
50442421Syokota			  write_exp_elt_opcode (OP_LONG);
50542421Syokota			  write_exp_elt_type (builtin_type_char);
50642421Syokota			  write_exp_elt_longcst ((LONGEST)'\0');
50742421Syokota			  write_exp_elt_opcode (OP_LONG);
50842421Syokota			  write_exp_elt_opcode (OP_ARRAY);
50942421Syokota			  write_exp_elt_longcst ((LONGEST) 0);
51042421Syokota			  write_exp_elt_longcst ((LONGEST) ($1.length));
51142421Syokota			  write_exp_elt_opcode (OP_ARRAY); }
51242421Syokota	;
51342421Syokota
51442421Syokota/* Object pascal  */
51542421Syokotaexp	:	THIS
51642421Syokota			{
51742421Syokota			  struct value * this_val;
51842421Syokota			  struct type * this_type;
51942421Syokota			  write_exp_elt_opcode (OP_THIS);
52042421Syokota			  write_exp_elt_opcode (OP_THIS);
52142421Syokota			  /* we need type of this */
52242421Syokota			  this_val = value_of_this (0);
52342421Syokota			  if (this_val)
52442421Syokota			    this_type = this_val->type;
52542421Syokota			  else
52642421Syokota			    this_type = NULL;
52742421Syokota			  if (this_type)
52842421Syokota			    {
52942421Syokota			      if (TYPE_CODE (this_type) == TYPE_CODE_PTR)
53042421Syokota				{
53142421Syokota				  this_type = TYPE_TARGET_TYPE (this_type);
53242421Syokota				  write_exp_elt_opcode (UNOP_IND);
53342421Syokota				}
53442421Syokota			    }
53542421Syokota
53642421Syokota			  current_type = this_type;
53742421Syokota			}
53842421Syokota	;
53942421Syokota
54042421Syokota/* end of object pascal.  */
54154382Syokota
54254382Syokotablock	:	BLOCKNAME
54342421Syokota			{
54442421Syokota			  if ($1.sym != 0)
54542421Syokota			      $$ = SYMBOL_BLOCK_VALUE ($1.sym);
54642421Syokota			  else
54742421Syokota			    {
54842421Syokota			      struct symtab *tem =
54942421Syokota				  lookup_symtab (copy_name ($1.stoken));
55042421Syokota			      if (tem)
55142421Syokota				$$ = BLOCKVECTOR_BLOCK (BLOCKVECTOR (tem), STATIC_BLOCK);
55242421Syokota			      else
55342421Syokota				error ("No file or function \"%s\".",
55442421Syokota				       copy_name ($1.stoken));
55542421Syokota			    }
55642421Syokota			}
55742421Syokota	;
55842421Syokota
55942421Syokotablock	:	block COLONCOLON name
56042421Syokota			{ struct symbol *tem
56142421Syokota			    = lookup_symbol (copy_name ($3), $1,
56242421Syokota					     VAR_DOMAIN, (int *) NULL,
56342421Syokota					     (struct symtab **) NULL);
56442421Syokota			  if (!tem || SYMBOL_CLASS (tem) != LOC_BLOCK)
56542421Syokota			    error ("No function \"%s\" in specified context.",
56642421Syokota				   copy_name ($3));
56742421Syokota			  $$ = SYMBOL_BLOCK_VALUE (tem); }
56842421Syokota	;
56942421Syokota
57042421Syokotavariable:	block COLONCOLON name
57142421Syokota			{ struct symbol *sym;
57242421Syokota			  sym = lookup_symbol (copy_name ($3), $1,
57342421Syokota					       VAR_DOMAIN, (int *) NULL,
57442421Syokota					       (struct symtab **) NULL);
57542421Syokota			  if (sym == 0)
57642421Syokota			    error ("No symbol \"%s\" in specified context.",
57742421Syokota				   copy_name ($3));
57842421Syokota
57942421Syokota			  write_exp_elt_opcode (OP_VAR_VALUE);
58042421Syokota			  /* block_found is set by lookup_symbol.  */
58142421Syokota			  write_exp_elt_block (block_found);
58242421Syokota			  write_exp_elt_sym (sym);
58342421Syokota			  write_exp_elt_opcode (OP_VAR_VALUE); }
58442421Syokota	;
58554382Syokota
58642421Syokotaqualified_name:	typebase COLONCOLON name
58754382Syokota			{
58854382Syokota			  struct type *type = $1;
58954382Syokota			  if (TYPE_CODE (type) != TYPE_CODE_STRUCT
59054382Syokota			      && TYPE_CODE (type) != TYPE_CODE_UNION)
59142421Syokota			    error ("`%s' is not defined as an aggregate type.",
59242421Syokota				   TYPE_NAME (type));
59342421Syokota
59442421Syokota			  write_exp_elt_opcode (OP_SCOPE);
59542421Syokota			  write_exp_elt_type (type);
59642421Syokota			  write_exp_string ($3);
59742421Syokota			  write_exp_elt_opcode (OP_SCOPE);
59842421Syokota			}
59942421Syokota	;
60042421Syokota
60142421Syokotavariable:	qualified_name
60242421Syokota	|	COLONCOLON name
60342421Syokota			{
60442421Syokota			  char *name = copy_name ($2);
60542421Syokota			  struct symbol *sym;
60642421Syokota			  struct minimal_symbol *msymbol;
60742421Syokota
60842421Syokota			  sym =
60942421Syokota			    lookup_symbol (name, (const struct block *) NULL,
61042421Syokota					   VAR_DOMAIN, (int *) NULL,
61142421Syokota					   (struct symtab **) NULL);
61242421Syokota			  if (sym)
61342421Syokota			    {
61442421Syokota			      write_exp_elt_opcode (OP_VAR_VALUE);
61542421Syokota			      write_exp_elt_block (NULL);
61642421Syokota			      write_exp_elt_sym (sym);
61742421Syokota			      write_exp_elt_opcode (OP_VAR_VALUE);
61842421Syokota			      break;
61942421Syokota			    }
62042421Syokota
62142421Syokota			  msymbol = lookup_minimal_symbol (name, NULL, NULL);
62242421Syokota			  if (msymbol != NULL)
62342421Syokota			    {
62442421Syokota			      write_exp_msymbol (msymbol,
62542421Syokota						 lookup_function_type (builtin_type_int),
62642421Syokota						 builtin_type_int);
62742421Syokota			    }
62842421Syokota			  else
62942421Syokota			    if (!have_full_symbols () && !have_partial_symbols ())
63042421Syokota			      error ("No symbol table is loaded.  Use the \"file\" command.");
63142421Syokota			    else
63242421Syokota			      error ("No symbol \"%s\" in current context.", name);
63342421Syokota			}
63442421Syokota	;
63542421Syokota
63642421Syokotavariable:	name_not_typename
63743337Syokota			{ struct symbol *sym = $1.sym;
63843337Syokota
63943337Syokota			  if (sym)
64042421Syokota			    {
64142421Syokota			      if (symbol_read_needs_frame (sym))
64242421Syokota				{
64342421Syokota				  if (innermost_block == 0 ||
64442421Syokota				      contained_in (block_found,
64542421Syokota						    innermost_block))
64642421Syokota				    innermost_block = block_found;
64742421Syokota				}
64842421Syokota
64942421Syokota			      write_exp_elt_opcode (OP_VAR_VALUE);
65042421Syokota			      /* We want to use the selected frame, not
65142421Syokota				 another more inner frame which happens to
65242421Syokota				 be in the same block.  */
65342421Syokota			      write_exp_elt_block (NULL);
65442421Syokota			      write_exp_elt_sym (sym);
65542421Syokota			      write_exp_elt_opcode (OP_VAR_VALUE);
65642421Syokota			      current_type = sym->type; }
65742421Syokota			  else if ($1.is_a_field_of_this)
65842421Syokota			    {
65942421Syokota			      struct value * this_val;
66042421Syokota			      struct type * this_type;
66142421Syokota			      /* Object pascal: it hangs off of `this'.  Must
66242421Syokota			         not inadvertently convert from a method call
66342421Syokota				 to data ref.  */
66442421Syokota			      if (innermost_block == 0 ||
66542421Syokota				  contained_in (block_found, innermost_block))
66642421Syokota				innermost_block = block_found;
66742421Syokota			      write_exp_elt_opcode (OP_THIS);
66842421Syokota			      write_exp_elt_opcode (OP_THIS);
66942421Syokota			      write_exp_elt_opcode (STRUCTOP_PTR);
67042421Syokota			      write_exp_string ($1.stoken);
67142421Syokota			      write_exp_elt_opcode (STRUCTOP_PTR);
67242421Syokota			      /* we need type of this */
67342421Syokota			      this_val = value_of_this (0);
67442421Syokota			      if (this_val)
67542421Syokota				this_type = this_val->type;
67642421Syokota			      else
67742421Syokota				this_type = NULL;
67842421Syokota			      if (this_type)
67942421Syokota				current_type = lookup_struct_elt_type (
68042421Syokota				  this_type,
68142421Syokota				  copy_name ($1.stoken), 0);
68242421Syokota			      else
68342421Syokota				current_type = NULL;
68442421Syokota			    }
68543337Syokota			  else
68643337Syokota			    {
68743337Syokota			      struct minimal_symbol *msymbol;
68843337Syokota			      char *arg = copy_name ($1.stoken);
68943337Syokota
69043337Syokota			      msymbol =
69142421Syokota				lookup_minimal_symbol (arg, NULL, NULL);
69242421Syokota			      if (msymbol != NULL)
69342421Syokota				{
69442421Syokota				  write_exp_msymbol (msymbol,
69542421Syokota						     lookup_function_type (builtin_type_int),
69642421Syokota						     builtin_type_int);
69742421Syokota				}
69842421Syokota			      else if (!have_full_symbols () && !have_partial_symbols ())
69943337Syokota				error ("No symbol table is loaded.  Use the \"file\" command.");
70042421Syokota			      else
70142421Syokota				error ("No symbol \"%s\" in current context.",
70242421Syokota				       copy_name ($1.stoken));
70342421Syokota			    }
70443337Syokota			}
70543337Syokota	;
70643337Syokota
70743337Syokota
70843337Syokotaptype	:	typebase
70943337Syokota	;
71043337Syokota
71143337Syokota/* We used to try to recognize more pointer to member types here, but
71243337Syokota   that didn't work (shift/reduce conflicts meant that these rules never
71343337Syokota   got executed).  The problem is that
71443337Syokota     int (foo::bar::baz::bizzle)
71543337Syokota   is a function type but
71643337Syokota     int (foo::bar::baz::bizzle::*)
71743337Syokota   is a pointer to member type.  Stroustrup loses again!  */
71843337Syokota
71943337Syokotatype	:	ptype
72043337Syokota	|	typebase COLONCOLON '*'
72143337Syokota			{ $$ = lookup_member_type (builtin_type_int, $1); }
72243337Syokota	;
72343337Syokota
72443337Syokotatypebase  /* Implements (approximately): (type-qualifier)* type-specifier */
72543337Syokota	:	'^' typebase
72643337Syokota			{ $$ = lookup_pointer_type ($2); }
72743337Syokota	|	TYPENAME
72843337Syokota			{ $$ = $1.type; }
72943337Syokota	|	STRUCT name
73043337Syokota			{ $$ = lookup_struct (copy_name ($2),
73143337Syokota					      expression_context_block); }
73242421Syokota	|	CLASS name
73342421Syokota			{ $$ = lookup_struct (copy_name ($2),
73442421Syokota					      expression_context_block); }
73542421Syokota	/* "const" and "volatile" are curently ignored.  A type qualifier
73642421Syokota	   after the type is handled in the ptype rule.  I think these could
73742421Syokota	   be too.  */
73847293Syokota	;
73942421Syokota
74042421Syokotaname	:	NAME { $$ = $1.stoken; }
74142421Syokota	|	BLOCKNAME { $$ = $1.stoken; }
74246765Syokota	|	TYPENAME { $$ = $1.stoken; }
74342421Syokota	|	NAME_OR_INT  { $$ = $1.stoken; }
74442421Syokota	;
74542421Syokota
74642421Syokotaname_not_typename :	NAME
74742421Syokota	|	BLOCKNAME
74846765Syokota/* These would be useful if name_not_typename was useful, but it is just
74942421Syokota   a fake for "variable", so these cause reduce/reduce conflicts because
75042421Syokota   the parser can't tell whether NAME_OR_INT is a name_not_typename (=variable,
75142421Syokota   =exp) or just an exp.  If name_not_typename was ever used in an lvalue
75242421Syokota   context where only a name could occur, this might be useful.
75342421Syokota  	|	NAME_OR_INT
75446765Syokota */
75542421Syokota	;
75642421Syokota
75742421Syokota%%
75842421Syokota
75942421Syokota/* Take care of parsing a number (anything that starts with a digit).
76042421Syokota   Set yylval and return the token type; update lexptr.
76142421Syokota   LEN is the number of characters in it.  */
76242421Syokota
76342421Syokota/*** Needs some error checking for the float case ***/
76442421Syokota
76542421Syokotastatic int
76642421Syokotaparse_number (p, len, parsed_float, putithere)
76742421Syokota     char *p;
76842421Syokota     int len;
76942421Syokota     int parsed_float;
77042421Syokota     YYSTYPE *putithere;
77142421Syokota{
77242421Syokota  /* FIXME: Shouldn't these be unsigned?  We don't deal with negative values
77342421Syokota     here, and we do kind of silly things like cast to unsigned.  */
77442421Syokota  LONGEST n = 0;
77542421Syokota  LONGEST prevn = 0;
77642421Syokota  ULONGEST un;
77742421Syokota
77842421Syokota  int i = 0;
77942421Syokota  int c;
78042421Syokota  int base = input_radix;
78142421Syokota  int unsigned_p = 0;
78242421Syokota
78342421Syokota  /* Number of "L" suffixes encountered.  */
78442421Syokota  int long_p = 0;
78542421Syokota
78642421Syokota  /* We have found a "L" or "U" suffix.  */
78742421Syokota  int found_suffix = 0;
78842421Syokota
78942421Syokota  ULONGEST high_bit;
79042421Syokota  struct type *signed_type;
79142421Syokota  struct type *unsigned_type;
79242421Syokota
79342421Syokota  if (parsed_float)
79442421Syokota    {
79542421Syokota      /* It's a float since it contains a point or an exponent.  */
79642421Syokota      char c;
79742421Syokota      int num = 0;	/* number of tokens scanned by scanf */
79842421Syokota      char saved_char = p[len];
79942421Syokota
80042421Syokota      p[len] = 0;	/* null-terminate the token */
80142421Syokota      if (sizeof (putithere->typed_val_float.dval) <= sizeof (float))
80242421Syokota	num = sscanf (p, "%g%c", (float *) &putithere->typed_val_float.dval,&c);
80342421Syokota      else if (sizeof (putithere->typed_val_float.dval) <= sizeof (double))
80442421Syokota	num = sscanf (p, "%lg%c", (double *) &putithere->typed_val_float.dval,&c);
80542421Syokota      else
80642421Syokota	{
80742421Syokota#ifdef SCANF_HAS_LONG_DOUBLE
80842421Syokota	  num = sscanf (p, "%Lg%c", &putithere->typed_val_float.dval,&c);
80942421Syokota#else
81042421Syokota	  /* Scan it into a double, then assign it to the long double.
81142421Syokota	     This at least wins with values representable in the range
81242421Syokota	     of doubles. */
81342421Syokota	  double temp;
81442421Syokota	  num = sscanf (p, "%lg%c", &temp,&c);
81542421Syokota	  putithere->typed_val_float.dval = temp;
81642421Syokota#endif
81742421Syokota	}
81842421Syokota      p[len] = saved_char;	/* restore the input stream */
81942421Syokota      if (num != 1) 		/* check scanf found ONLY a float ... */
82042421Syokota	return ERROR;
82142421Syokota      /* See if it has `f' or `l' suffix (float or long double).  */
82242421Syokota
82342421Syokota      c = tolower (p[len - 1]);
82442421Syokota
82542421Syokota      if (c == 'f')
82642421Syokota	putithere->typed_val_float.type = builtin_type_float;
82742421Syokota      else if (c == 'l')
82842421Syokota	putithere->typed_val_float.type = builtin_type_long_double;
82942421Syokota      else if (isdigit (c) || c == '.')
83042421Syokota	putithere->typed_val_float.type = builtin_type_double;
83142421Syokota      else
83242421Syokota	return ERROR;
83342421Syokota
83442421Syokota      return FLOAT;
83542421Syokota    }
83642421Syokota
83742421Syokota  /* Handle base-switching prefixes 0x, 0t, 0d, 0 */
83842421Syokota  if (p[0] == '0')
83942421Syokota    switch (p[1])
84042421Syokota      {
84142421Syokota      case 'x':
84242421Syokota      case 'X':
84342421Syokota	if (len >= 3)
84442421Syokota	  {
84542421Syokota	    p += 2;
84642421Syokota	    base = 16;
84742421Syokota	    len -= 2;
84842421Syokota	  }
84942421Syokota	break;
85042421Syokota
85142421Syokota      case 't':
85242421Syokota      case 'T':
85342421Syokota      case 'd':
85442421Syokota      case 'D':
85542421Syokota	if (len >= 3)
85642421Syokota	  {
85742421Syokota	    p += 2;
85842421Syokota	    base = 10;
85961004Sache	    len -= 2;
86061004Sache	  }
86142421Syokota	break;
86242421Syokota
86342421Syokota      default:
86442421Syokota	base = 8;
86542421Syokota	break;
86642421Syokota      }
86742421Syokota
86842421Syokota  while (len-- > 0)
86942421Syokota    {
87042421Syokota      c = *p++;
87142421Syokota      if (c >= 'A' && c <= 'Z')
87242421Syokota	c += 'a' - 'A';
87342421Syokota      if (c != 'l' && c != 'u')
87442421Syokota	n *= base;
87542421Syokota      if (c >= '0' && c <= '9')
87642421Syokota	{
87742421Syokota	  if (found_suffix)
87842421Syokota	    return ERROR;
87942421Syokota	  n += i = c - '0';
88042421Syokota	}
88142421Syokota      else
88242421Syokota	{
88342421Syokota	  if (base > 10 && c >= 'a' && c <= 'f')
88442421Syokota	    {
88542421Syokota	      if (found_suffix)
88642421Syokota		return ERROR;
88742421Syokota	      n += i = c - 'a' + 10;
88842421Syokota	    }
88942421Syokota	  else if (c == 'l')
89042421Syokota	    {
89144628Syokota	      ++long_p;
89242421Syokota	      found_suffix = 1;
89342421Syokota	    }
89442421Syokota	  else if (c == 'u')
89544628Syokota	    {
89654543Syokota	      unsigned_p = 1;
89754543Syokota	      found_suffix = 1;
89854543Syokota	    }
89954543Syokota	  else
90054543Syokota	    return ERROR;	/* Char not a digit */
90154543Syokota	}
90242421Syokota      if (i >= base)
90344628Syokota	return ERROR;		/* Invalid digit in this base */
90444628Syokota
90544628Syokota      /* Portably test for overflow (only works for nonzero values, so make
90644628Syokota	 a second check for zero).  FIXME: Can't we just make n and prevn
90754543Syokota	 unsigned and avoid this?  */
90854543Syokota      if (c != 'l' && c != 'u' && (prevn >= n) && n != 0)
90954543Syokota	unsigned_p = 1;		/* Try something unsigned */
91054543Syokota
91154543Syokota      /* Portably test for unsigned overflow.
91254543Syokota	 FIXME: This check is wrong; for example it doesn't find overflow
91344628Syokota	 on 0x123456789 when LONGEST is 32 bits.  */
91442421Syokota      if (c != 'l' && c != 'u' && n != 0)
91542421Syokota	{
91642421Syokota	  if ((unsigned_p && (ULONGEST) prevn >= (ULONGEST) n))
91742421Syokota	    error ("Numeric constant too large.");
91842421Syokota	}
91942421Syokota      prevn = n;
92042421Syokota    }
92142421Syokota
92242421Syokota  /* An integer constant is an int, a long, or a long long.  An L
92342421Syokota     suffix forces it to be long; an LL suffix forces it to be long
92442421Syokota     long.  If not forced to a larger size, it gets the first type of
92542421Syokota     the above that it fits in.  To figure out whether it fits, we
92642421Syokota     shift it right and see whether anything remains.  Note that we
92742421Syokota     can't shift sizeof (LONGEST) * HOST_CHAR_BIT bits or more in one
92842421Syokota     operation, because many compilers will warn about such a shift
92942421Syokota     (which always produces a zero result).  Sometimes TARGET_INT_BIT
93042421Syokota     or TARGET_LONG_BIT will be that big, sometimes not.  To deal with
93142421Syokota     the case where it is we just always shift the value more than
93242421Syokota     once, with fewer bits each time.  */
93342421Syokota
93442421Syokota  un = (ULONGEST)n >> 2;
93542421Syokota  if (long_p == 0
93642421Syokota      && (un >> (TARGET_INT_BIT - 2)) == 0)
93742421Syokota    {
93842421Syokota      high_bit = ((ULONGEST)1) << (TARGET_INT_BIT-1);
93942421Syokota
94042421Syokota      /* A large decimal (not hex or octal) constant (between INT_MAX
94142421Syokota	 and UINT_MAX) is a long or unsigned long, according to ANSI,
94242421Syokota	 never an unsigned int, but this code treats it as unsigned
94344628Syokota	 int.  This probably should be fixed.  GCC gives a warning on
94442421Syokota	 such constants.  */
94542421Syokota
94642421Syokota      unsigned_type = builtin_type_unsigned_int;
94742421Syokota      signed_type = builtin_type_int;
94842421Syokota    }
94942421Syokota  else if (long_p <= 1
95042421Syokota	   && (un >> (TARGET_LONG_BIT - 2)) == 0)
95142421Syokota    {
95242421Syokota      high_bit = ((ULONGEST)1) << (TARGET_LONG_BIT-1);
95342421Syokota      unsigned_type = builtin_type_unsigned_long;
95442421Syokota      signed_type = builtin_type_long;
95542421Syokota    }
95642421Syokota  else
95742421Syokota    {
95842421Syokota      int shift;
95942421Syokota      if (sizeof (ULONGEST) * HOST_CHAR_BIT < TARGET_LONG_LONG_BIT)
96042421Syokota	/* A long long does not fit in a LONGEST.  */
96142421Syokota	shift = (sizeof (ULONGEST) * HOST_CHAR_BIT - 1);
96242421Syokota      else
96342421Syokota	shift = (TARGET_LONG_LONG_BIT - 1);
96442421Syokota      high_bit = (ULONGEST) 1 << shift;
96542421Syokota      unsigned_type = builtin_type_unsigned_long_long;
96642421Syokota      signed_type = builtin_type_long_long;
96742421Syokota    }
96842421Syokota
96942421Syokota   putithere->typed_val_int.val = n;
97042421Syokota
97142421Syokota   /* If the high bit of the worked out type is set then this number
97242421Syokota      has to be unsigned. */
97342421Syokota
97442421Syokota   if (unsigned_p || (n & high_bit))
97542421Syokota     {
97642421Syokota       putithere->typed_val_int.type = unsigned_type;
97744628Syokota     }
97844628Syokota   else
97944628Syokota     {
98044628Syokota       putithere->typed_val_int.type = signed_type;
98144628Syokota     }
98244628Syokota
98344628Syokota   return INT;
98444628Syokota}
98544628Syokota
98644628Syokota
98744628Syokotastruct type_push
98844628Syokota{
98944628Syokota  struct type *stored;
99044628Syokota  struct type_push *next;
99144628Syokota};
99244628Syokota
99342421Syokotastatic struct type_push *tp_top = NULL;
99442421Syokota
99542421Syokotastatic void
99655731Syokotapush_current_type (void)
99755731Syokota{
99855731Syokota  struct type_push *tpnew;
99955731Syokota  tpnew = (struct type_push *) malloc (sizeof (struct type_push));
100055731Syokota  tpnew->next = tp_top;
100155731Syokota  tpnew->stored = current_type;
100255731Syokota  current_type = NULL;
100355731Syokota  tp_top = tpnew;
100455731Syokota}
100555731Syokota
100655731Syokotastatic void
100755731Syokotapop_current_type (void)
100855731Syokota{
100955731Syokota  struct type_push *tp = tp_top;
101055731Syokota  if (tp)
101155731Syokota    {
101255731Syokota      current_type = tp->stored;
101355731Syokota      tp_top = tp->next;
101455731Syokota      xfree (tp);
101555731Syokota    }
101655731Syokota}
101755731Syokota
101855731Syokotastruct token
101955731Syokota{
102055731Syokota  char *operator;
102155731Syokota  int token;
102255731Syokota  enum exp_opcode opcode;
102355731Syokota};
102455731Syokota
102555731Syokotastatic const struct token tokentab3[] =
102655731Syokota  {
102755731Syokota    {"shr", RSH, BINOP_END},
102855731Syokota    {"shl", LSH, BINOP_END},
102942421Syokota    {"and", ANDAND, BINOP_END},
103042421Syokota    {"div", DIV, BINOP_END},
103142421Syokota    {"not", NOT, BINOP_END},
103242421Syokota    {"mod", MOD, BINOP_END},
103342421Syokota    {"inc", INCREMENT, BINOP_END},
103442421Syokota    {"dec", DECREMENT, BINOP_END},
103542421Syokota    {"xor", XOR, BINOP_END}
103642421Syokota  };
103742421Syokota
103842421Syokotastatic const struct token tokentab2[] =
103942421Syokota  {
104042421Syokota    {"or", OR, BINOP_END},
104142421Syokota    {"<>", NOTEQUAL, BINOP_END},
104242421Syokota    {"<=", LEQ, BINOP_END},
104342421Syokota    {">=", GEQ, BINOP_END},
104442421Syokota    {":=", ASSIGN, BINOP_END},
104542421Syokota    {"::", COLONCOLON, BINOP_END} };
104642421Syokota
104742421Syokota/* Allocate uppercased var */
104842421Syokota/* make an uppercased copy of tokstart */
104942421Syokotastatic char * uptok (tokstart, namelen)
105042421Syokota  char *tokstart;
105142421Syokota  int namelen;
105242421Syokota{
105342421Syokota  int i;
105442421Syokota  char *uptokstart = (char *)malloc(namelen+1);
105542421Syokota  for (i = 0;i <= namelen;i++)
105642421Syokota    {
105742421Syokota      if ((tokstart[i]>='a' && tokstart[i]<='z'))
105842421Syokota        uptokstart[i] = tokstart[i]-('a'-'A');
105942421Syokota      else
106042421Syokota        uptokstart[i] = tokstart[i];
106142421Syokota    }
106242421Syokota  uptokstart[namelen]='\0';
106342421Syokota  return uptokstart;
106442421Syokota}
106542421Syokota/* Read one token, getting characters through lexptr.  */
106642421Syokota
106742421Syokota
106842421Syokotastatic int
106942421Syokotayylex ()
107042421Syokota{
107142421Syokota  int c;
107242421Syokota  int namelen;
107342421Syokota  unsigned int i;
107442421Syokota  char *tokstart;
107542421Syokota  char *uptokstart;
107642421Syokota  char *tokptr;
107742421Syokota  char *p;
107842421Syokota  int explen, tempbufindex;
107942421Syokota  static char *tempbuf;
108042421Syokota  static int tempbufsize;
108142421Syokota
108242421Syokota retry:
108342421Syokota
108457131Syokota  prev_lexptr = lexptr;
108557131Syokota
108657131Syokota  tokstart = lexptr;
108742421Syokota  explen = strlen (lexptr);
108857131Syokota  /* See if it is a special token of length 3.  */
108942421Syokota  if (explen > 2)
109042421Syokota    for (i = 0; i < sizeof (tokentab3) / sizeof (tokentab3[0]); i++)
109142421Syokota      if (strncasecmp (tokstart, tokentab3[i].operator, 3) == 0
109242421Syokota          && (!isalpha (tokentab3[i].operator[0]) || explen == 3
109342421Syokota              || (!isalpha (tokstart[3]) && !isdigit (tokstart[3]) && tokstart[3] != '_')))
109442421Syokota        {
109542421Syokota          lexptr += 3;
109642421Syokota          yylval.opcode = tokentab3[i].opcode;
109742421Syokota          return tokentab3[i].token;
109842421Syokota        }
109942421Syokota
110042421Syokota  /* See if it is a special token of length 2.  */
110142421Syokota  if (explen > 1)
110242421Syokota  for (i = 0; i < sizeof (tokentab2) / sizeof (tokentab2[0]); i++)
110342421Syokota      if (strncasecmp (tokstart, tokentab2[i].operator, 2) == 0
110442421Syokota          && (!isalpha (tokentab2[i].operator[0]) || explen == 2
110542421Syokota              || (!isalpha (tokstart[2]) && !isdigit (tokstart[2]) && tokstart[2] != '_')))
110642421Syokota        {
110742421Syokota          lexptr += 2;
110842421Syokota          yylval.opcode = tokentab2[i].opcode;
110942421Syokota          return tokentab2[i].token;
111042421Syokota        }
111157902Syokota
111257902Syokota  switch (c = *tokstart)
111357902Syokota    {
111457902Syokota    case 0:
111557902Syokota      return 0;
111657902Syokota
111757902Syokota    case ' ':
111857902Syokota    case '\t':
111957902Syokota    case '\n':
112057902Syokota      lexptr++;
112157902Syokota      goto retry;
112242421Syokota
112342421Syokota    case '\'':
112442421Syokota      /* We either have a character constant ('0' or '\177' for example)
112557131Syokota	 or we have a quoted symbol reference ('foo(int,int)' in object pascal
112657131Syokota	 for example). */
112742421Syokota      lexptr++;
112842421Syokota      c = *lexptr++;
112957902Syokota      if (c == '\\')
113042421Syokota	c = parse_escape (&lexptr);
113142421Syokota      else if (c == '\'')
113242421Syokota	error ("Empty character constant.");
113342421Syokota
113442421Syokota      yylval.typed_val_int.val = c;
113542421Syokota      yylval.typed_val_int.type = builtin_type_char;
113642421Syokota
113742421Syokota      c = *lexptr++;
113842421Syokota      if (c != '\'')
113942421Syokota	{
114042421Syokota	  namelen = skip_quoted (tokstart) - tokstart;
114142421Syokota	  if (namelen > 2)
114242421Syokota	    {
114342421Syokota	      lexptr = tokstart + namelen;
114442421Syokota	      if (lexptr[-1] != '\'')
114542421Syokota		error ("Unmatched single quote.");
114642421Syokota	      namelen -= 2;
114757131Syokota              tokstart++;
114857131Syokota              uptokstart = uptok(tokstart,namelen);
114957131Syokota	      goto tryname;
115042421Syokota	    }
115154382Syokota	  error ("Invalid character constant.");
115242421Syokota	}
115342421Syokota      return INT;
115442421Syokota
115542421Syokota    case '(':
115642421Syokota      paren_depth++;
115742421Syokota      lexptr++;
115842421Syokota      return c;
115942421Syokota
116042421Syokota    case ')':
116142421Syokota      if (paren_depth == 0)
116242421Syokota	return 0;
116342421Syokota      paren_depth--;
116442421Syokota      lexptr++;
116542421Syokota      return c;
116642421Syokota
116742421Syokota    case ',':
116842421Syokota      if (comma_terminates && paren_depth == 0)
116942421Syokota	return 0;
117042421Syokota      lexptr++;
117142421Syokota      return c;
117242421Syokota
117342421Syokota    case '.':
117442421Syokota      /* Might be a floating point number.  */
117542421Syokota      if (lexptr[1] < '0' || lexptr[1] > '9')
117642421Syokota	goto symbol;		/* Nope, must be a symbol. */
117742421Syokota      /* FALL THRU into number case.  */
117842421Syokota
117942421Syokota    case '0':
118042421Syokota    case '1':
118142421Syokota    case '2':
118242421Syokota    case '3':
118342421Syokota    case '4':
118442421Syokota    case '5':
118542421Syokota    case '6':
118642421Syokota    case '7':
118742421Syokota    case '8':
118842421Syokota    case '9':
118942421Syokota      {
119042421Syokota	/* It's a number.  */
119142421Syokota	int got_dot = 0, got_e = 0, toktype;
119242421Syokota	char *p = tokstart;
119342421Syokota	int hex = input_radix > 10;
119442421Syokota
119542421Syokota	if (c == '0' && (p[1] == 'x' || p[1] == 'X'))
119642421Syokota	  {
119742421Syokota	    p += 2;
119842421Syokota	    hex = 1;
119955730Syokota	  }
120055730Syokota	else if (c == '0' && (p[1]=='t' || p[1]=='T' || p[1]=='d' || p[1]=='D'))
120155730Syokota	  {
120255730Syokota	    p += 2;
120355730Syokota	    hex = 0;
120455730Syokota	  }
120555730Syokota
120655730Syokota	for (;; ++p)
120755730Syokota	  {
120842421Syokota	    /* This test includes !hex because 'e' is a valid hex digit
120942421Syokota	       and thus does not indicate a floating point number when
121042421Syokota	       the radix is hex.  */
121142421Syokota	    if (!hex && !got_e && (*p == 'e' || *p == 'E'))
121242421Syokota	      got_dot = got_e = 1;
121342421Syokota	    /* This test does not include !hex, because a '.' always indicates
121442421Syokota	       a decimal floating point number regardless of the radix.  */
121542421Syokota	    else if (!got_dot && *p == '.')
121642421Syokota	      got_dot = 1;
121742421Syokota	    else if (got_e && (p[-1] == 'e' || p[-1] == 'E')
121842421Syokota		     && (*p == '-' || *p == '+'))
121942421Syokota	      /* This is the sign of the exponent, not the end of the
122042421Syokota		 number.  */
122142421Syokota	      continue;
122242421Syokota	    /* We will take any letters or digits.  parse_number will
122342421Syokota	       complain if past the radix, or if L or U are not final.  */
122442421Syokota	    else if ((*p < '0' || *p > '9')
122542421Syokota		     && ((*p < 'a' || *p > 'z')
122642421Syokota				  && (*p < 'A' || *p > 'Z')))
122742421Syokota	      break;
122842421Syokota	  }
122942421Syokota	toktype = parse_number (tokstart, p - tokstart, got_dot|got_e, &yylval);
123042421Syokota        if (toktype == ERROR)
123142421Syokota	  {
123242421Syokota	    char *err_copy = (char *) alloca (p - tokstart + 1);
123342421Syokota
123442421Syokota	    memcpy (err_copy, tokstart, p - tokstart);
123542421Syokota	    err_copy[p - tokstart] = 0;
123642421Syokota	    error ("Invalid number \"%s\".", err_copy);
123742421Syokota	  }
123842421Syokota	lexptr = p;
123942421Syokota	return toktype;
124042421Syokota      }
124142421Syokota
124242421Syokota    case '+':
124342421Syokota    case '-':
124442421Syokota    case '*':
124542421Syokota    case '/':
124642421Syokota    case '|':
124742421Syokota    case '&':
124894275Sphk    case '^':
124942421Syokota    case '~':
125042421Syokota    case '!':
125142421Syokota    case '@':
125242421Syokota    case '<':
125342421Syokota    case '>':
125442421Syokota    case '[':
125542421Syokota    case ']':
125642421Syokota    case '?':
125742421Syokota    case ':':
125842421Syokota    case '=':
125942421Syokota    case '{':
126042421Syokota    case '}':
126142421Syokota    symbol:
126242421Syokota      lexptr++;
126342421Syokota      return c;
126442421Syokota
126542421Syokota    case '"':
126642421Syokota
126742421Syokota      /* Build the gdb internal form of the input string in tempbuf,
126842421Syokota	 translating any standard C escape forms seen.  Note that the
126942421Syokota	 buffer is null byte terminated *only* for the convenience of
127042831Syokota	 debugging gdb itself and printing the buffer contents when
127142831Syokota	 the buffer contains no embedded nulls.  Gdb does not depend
127242831Syokota	 upon the buffer being null byte terminated, it uses the length
127342831Syokota	 string instead.  This allows gdb to handle C strings (as well
127442831Syokota	 as strings in other languages) with embedded null bytes */
127542831Syokota
127642831Syokota      tokptr = ++tokstart;
127742831Syokota      tempbufindex = 0;
127842831Syokota
127942421Syokota      do {
128042421Syokota	/* Grow the static temp buffer if necessary, including allocating
128142421Syokota	   the first one on demand. */
128242421Syokota	if (tempbufindex + 1 >= tempbufsize)
128342421Syokota	  {
128442421Syokota	    tempbuf = (char *) realloc (tempbuf, tempbufsize += 64);
128542421Syokota	  }
128642421Syokota
128742421Syokota	switch (*tokptr)
128842421Syokota	  {
128942421Syokota	  case '\0':
129042421Syokota	  case '"':
129142421Syokota	    /* Do nothing, loop will terminate. */
129242421Syokota	    break;
129342421Syokota	  case '\\':
129442421Syokota	    tokptr++;
129542421Syokota	    c = parse_escape (&tokptr);
129642421Syokota	    if (c == -1)
129742421Syokota	      {
129842421Syokota		continue;
129942421Syokota	      }
130042421Syokota	    tempbuf[tempbufindex++] = c;
130142421Syokota	    break;
130242421Syokota	  default:
130342421Syokota	    tempbuf[tempbufindex++] = *tokptr++;
130442421Syokota	    break;
130542421Syokota	  }
130642421Syokota      } while ((*tokptr != '"') && (*tokptr != '\0'));
130742421Syokota      if (*tokptr++ != '"')
130842421Syokota	{
130942421Syokota	  error ("Unterminated string in expression.");
131042421Syokota	}
131142421Syokota      tempbuf[tempbufindex] = '\0';	/* See note above */
131242421Syokota      yylval.sval.ptr = tempbuf;
131342421Syokota      yylval.sval.length = tempbufindex;
131442421Syokota      lexptr = tokptr;
131542421Syokota      return (STRING);
131642421Syokota    }
131742421Syokota
131842421Syokota  if (!(c == '_' || c == '$'
131942421Syokota	|| (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z')))
132042421Syokota    /* We must have come across a bad character (e.g. ';').  */
132142421Syokota    error ("Invalid character '%c' in expression.", c);
132242421Syokota
132342421Syokota  /* It's a name.  See how long it is.  */
132442421Syokota  namelen = 0;
132542421Syokota  for (c = tokstart[namelen];
132642421Syokota       (c == '_' || c == '$' || (c >= '0' && c <= '9')
132742421Syokota	|| (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || c == '<');)
132842421Syokota    {
132942421Syokota      /* Template parameter lists are part of the name.
133042421Syokota	 FIXME: This mishandles `print $a<4&&$a>3'.  */
133142421Syokota      if (c == '<')
133242421Syokota	{
133342421Syokota	  int i = namelen;
133442421Syokota	  int nesting_level = 1;
133542421Syokota	  while (tokstart[++i])
133642421Syokota	    {
133742421Syokota	      if (tokstart[i] == '<')
133842421Syokota		nesting_level++;
133942421Syokota	      else if (tokstart[i] == '>')
134042421Syokota		{
134142421Syokota		  if (--nesting_level == 0)
134242421Syokota		    break;
134342421Syokota		}
134442421Syokota	    }
134542421Syokota	  if (tokstart[i] == '>')
134642421Syokota	    namelen = i;
134742421Syokota	  else
134842421Syokota	    break;
134942421Syokota	}
135042421Syokota
135142421Syokota      /* do NOT uppercase internals because of registers !!! */
135242421Syokota      c = tokstart[++namelen];
135342421Syokota    }
135442421Syokota
135542421Syokota  uptokstart = uptok(tokstart,namelen);
135642421Syokota
135742421Syokota  /* The token "if" terminates the expression and is NOT
135842421Syokota     removed from the input stream.  */
135942421Syokota  if (namelen == 2 && uptokstart[0] == 'I' && uptokstart[1] == 'F')
136042421Syokota    {
136142421Syokota      return 0;
136242421Syokota    }
136342421Syokota
136442421Syokota  lexptr += namelen;
136542421Syokota
136642421Syokota  tryname:
136742421Syokota
136842421Syokota  /* Catch specific keywords.  Should be done with a data structure.  */
136942421Syokota  switch (namelen)
137042421Syokota    {
137142421Syokota    case 6:
137242421Syokota      if (DEPRECATED_STREQ (uptokstart, "OBJECT"))
137342421Syokota	return CLASS;
137454543Syokota      if (DEPRECATED_STREQ (uptokstart, "RECORD"))
137554543Syokota	return STRUCT;
137654543Syokota      if (DEPRECATED_STREQ (uptokstart, "SIZEOF"))
137754543Syokota	return SIZEOF;
137854543Syokota      break;
137954543Syokota    case 5:
138044628Syokota      if (DEPRECATED_STREQ (uptokstart, "CLASS"))
138154543Syokota	return CLASS;
138254543Syokota      if (DEPRECATED_STREQ (uptokstart, "FALSE"))
138354543Syokota	{
138454543Syokota          yylval.lval = 0;
138554543Syokota          return FALSEKEYWORD;
138654543Syokota        }
138754543Syokota      break;
138854543Syokota    case 4:
138954543Syokota      if (DEPRECATED_STREQ (uptokstart, "TRUE"))
139054543Syokota	{
139154543Syokota          yylval.lval = 1;
139254543Syokota  	  return TRUEKEYWORD;
139344628Syokota        }
139444628Syokota      if (DEPRECATED_STREQ (uptokstart, "SELF"))
139544628Syokota        {
139644628Syokota          /* here we search for 'this' like
139744628Syokota             inserted in FPC stabs debug info */
139844628Syokota	  static const char this_name[] = "this";
139944628Syokota
140044628Syokota	  if (lookup_symbol (this_name, expression_context_block,
140144628Syokota			     VAR_DOMAIN, (int *) NULL,
140244628Syokota			     (struct symtab **) NULL))
140344628Syokota	    return THIS;
140444628Syokota	}
140544628Syokota      break;
140644628Syokota    default:
140744628Syokota      break;
140844628Syokota    }
140944628Syokota
1410  yylval.sval.ptr = tokstart;
1411  yylval.sval.length = namelen;
1412
1413  if (*tokstart == '$')
1414    {
1415      /* $ is the normal prefix for pascal hexadecimal values
1416        but this conflicts with the GDB use for debugger variables
1417        so in expression to enter hexadecimal values
1418        we still need to use C syntax with 0xff  */
1419      write_dollar_variable (yylval.sval);
1420      return VARIABLE;
1421    }
1422
1423  /* Use token-type BLOCKNAME for symbols that happen to be defined as
1424     functions or symtabs.  If this is not so, then ...
1425     Use token-type TYPENAME for symbols that happen to be defined
1426     currently as names of types; NAME for other symbols.
1427     The caller is not constrained to care about the distinction.  */
1428  {
1429    char *tmp = copy_name (yylval.sval);
1430    struct symbol *sym;
1431    int is_a_field_of_this = 0;
1432    int is_a_field = 0;
1433    int hextype;
1434
1435
1436    if (search_field && current_type)
1437      is_a_field = (lookup_struct_elt_type (current_type, tmp, 1) != NULL);
1438    if (is_a_field)
1439      sym = NULL;
1440    else
1441      sym = lookup_symbol (tmp, expression_context_block,
1442			   VAR_DOMAIN,
1443			   &is_a_field_of_this,
1444			   (struct symtab **) NULL);
1445    /* second chance uppercased (as Free Pascal does).  */
1446    if (!sym && !is_a_field_of_this && !is_a_field)
1447      {
1448       for (i = 0; i <= namelen; i++)
1449         {
1450           if ((tmp[i] >= 'a' && tmp[i] <= 'z'))
1451             tmp[i] -= ('a'-'A');
1452         }
1453       if (search_field && current_type)
1454	 is_a_field = (lookup_struct_elt_type (current_type, tmp, 1) != NULL);
1455       if (is_a_field)
1456	 sym = NULL;
1457       else
1458	 sym = lookup_symbol (tmp, expression_context_block,
1459                        VAR_DOMAIN,
1460                        &is_a_field_of_this,
1461                        (struct symtab **) NULL);
1462       if (sym || is_a_field_of_this || is_a_field)
1463         for (i = 0; i <= namelen; i++)
1464           {
1465             if ((tokstart[i] >= 'a' && tokstart[i] <= 'z'))
1466               tokstart[i] -= ('a'-'A');
1467           }
1468      }
1469    /* Third chance Capitalized (as GPC does).  */
1470    if (!sym && !is_a_field_of_this && !is_a_field)
1471      {
1472       for (i = 0; i <= namelen; i++)
1473         {
1474           if (i == 0)
1475             {
1476              if ((tmp[i] >= 'a' && tmp[i] <= 'z'))
1477                tmp[i] -= ('a'-'A');
1478             }
1479           else
1480           if ((tmp[i] >= 'A' && tmp[i] <= 'Z'))
1481             tmp[i] -= ('A'-'a');
1482          }
1483       if (search_field && current_type)
1484	 is_a_field = (lookup_struct_elt_type (current_type, tmp, 1) != NULL);
1485       if (is_a_field)
1486	 sym = NULL;
1487       else
1488	 sym = lookup_symbol (tmp, expression_context_block,
1489                         VAR_DOMAIN,
1490                         &is_a_field_of_this,
1491                         (struct symtab **) NULL);
1492       if (sym || is_a_field_of_this || is_a_field)
1493          for (i = 0; i <= namelen; i++)
1494            {
1495              if (i == 0)
1496                {
1497                  if ((tokstart[i] >= 'a' && tokstart[i] <= 'z'))
1498                    tokstart[i] -= ('a'-'A');
1499                }
1500              else
1501                if ((tokstart[i] >= 'A' && tokstart[i] <= 'Z'))
1502                  tokstart[i] -= ('A'-'a');
1503            }
1504      }
1505
1506    if (is_a_field)
1507      {
1508	tempbuf = (char *) realloc (tempbuf, namelen + 1);
1509	strncpy (tempbuf, tokstart, namelen); tempbuf [namelen] = 0;
1510	yylval.sval.ptr = tempbuf;
1511	yylval.sval.length = namelen;
1512	return FIELDNAME;
1513      }
1514    /* Call lookup_symtab, not lookup_partial_symtab, in case there are
1515       no psymtabs (coff, xcoff, or some future change to blow away the
1516       psymtabs once once symbols are read).  */
1517    if ((sym && SYMBOL_CLASS (sym) == LOC_BLOCK) ||
1518        lookup_symtab (tmp))
1519      {
1520	yylval.ssym.sym = sym;
1521	yylval.ssym.is_a_field_of_this = is_a_field_of_this;
1522	return BLOCKNAME;
1523      }
1524    if (sym && SYMBOL_CLASS (sym) == LOC_TYPEDEF)
1525        {
1526#if 1
1527	  /* Despite the following flaw, we need to keep this code enabled.
1528	     Because we can get called from check_stub_method, if we don't
1529	     handle nested types then it screws many operations in any
1530	     program which uses nested types.  */
1531	  /* In "A::x", if x is a member function of A and there happens
1532	     to be a type (nested or not, since the stabs don't make that
1533	     distinction) named x, then this code incorrectly thinks we
1534	     are dealing with nested types rather than a member function.  */
1535
1536	  char *p;
1537	  char *namestart;
1538	  struct symbol *best_sym;
1539
1540	  /* Look ahead to detect nested types.  This probably should be
1541	     done in the grammar, but trying seemed to introduce a lot
1542	     of shift/reduce and reduce/reduce conflicts.  It's possible
1543	     that it could be done, though.  Or perhaps a non-grammar, but
1544	     less ad hoc, approach would work well.  */
1545
1546	  /* Since we do not currently have any way of distinguishing
1547	     a nested type from a non-nested one (the stabs don't tell
1548	     us whether a type is nested), we just ignore the
1549	     containing type.  */
1550
1551	  p = lexptr;
1552	  best_sym = sym;
1553	  while (1)
1554	    {
1555	      /* Skip whitespace.  */
1556	      while (*p == ' ' || *p == '\t' || *p == '\n')
1557		++p;
1558	      if (*p == ':' && p[1] == ':')
1559		{
1560		  /* Skip the `::'.  */
1561		  p += 2;
1562		  /* Skip whitespace.  */
1563		  while (*p == ' ' || *p == '\t' || *p == '\n')
1564		    ++p;
1565		  namestart = p;
1566		  while (*p == '_' || *p == '$' || (*p >= '0' && *p <= '9')
1567			 || (*p >= 'a' && *p <= 'z')
1568			 || (*p >= 'A' && *p <= 'Z'))
1569		    ++p;
1570		  if (p != namestart)
1571		    {
1572		      struct symbol *cur_sym;
1573		      /* As big as the whole rest of the expression, which is
1574			 at least big enough.  */
1575		      char *ncopy = alloca (strlen (tmp)+strlen (namestart)+3);
1576		      char *tmp1;
1577
1578		      tmp1 = ncopy;
1579		      memcpy (tmp1, tmp, strlen (tmp));
1580		      tmp1 += strlen (tmp);
1581		      memcpy (tmp1, "::", 2);
1582		      tmp1 += 2;
1583		      memcpy (tmp1, namestart, p - namestart);
1584		      tmp1[p - namestart] = '\0';
1585		      cur_sym = lookup_symbol (ncopy, expression_context_block,
1586					       VAR_DOMAIN, (int *) NULL,
1587					       (struct symtab **) NULL);
1588		      if (cur_sym)
1589			{
1590			  if (SYMBOL_CLASS (cur_sym) == LOC_TYPEDEF)
1591			    {
1592			      best_sym = cur_sym;
1593			      lexptr = p;
1594			    }
1595			  else
1596			    break;
1597			}
1598		      else
1599			break;
1600		    }
1601		  else
1602		    break;
1603		}
1604	      else
1605		break;
1606	    }
1607
1608	  yylval.tsym.type = SYMBOL_TYPE (best_sym);
1609#else /* not 0 */
1610	  yylval.tsym.type = SYMBOL_TYPE (sym);
1611#endif /* not 0 */
1612	  return TYPENAME;
1613        }
1614    if ((yylval.tsym.type = lookup_primitive_typename (tmp)) != 0)
1615	return TYPENAME;
1616
1617    /* Input names that aren't symbols but ARE valid hex numbers,
1618       when the input radix permits them, can be names or numbers
1619       depending on the parse.  Note we support radixes > 16 here.  */
1620    if (!sym &&
1621        ((tokstart[0] >= 'a' && tokstart[0] < 'a' + input_radix - 10) ||
1622         (tokstart[0] >= 'A' && tokstart[0] < 'A' + input_radix - 10)))
1623      {
1624 	YYSTYPE newlval;	/* Its value is ignored.  */
1625	hextype = parse_number (tokstart, namelen, 0, &newlval);
1626	if (hextype == INT)
1627	  {
1628	    yylval.ssym.sym = sym;
1629	    yylval.ssym.is_a_field_of_this = is_a_field_of_this;
1630	    return NAME_OR_INT;
1631	  }
1632      }
1633
1634    free(uptokstart);
1635    /* Any other kind of symbol */
1636    yylval.ssym.sym = sym;
1637    yylval.ssym.is_a_field_of_this = is_a_field_of_this;
1638    return NAME;
1639  }
1640}
1641
1642void
1643yyerror (msg)
1644     char *msg;
1645{
1646  if (prev_lexptr)
1647    lexptr = prev_lexptr;
1648
1649  error ("A %s in expression, near `%s'.", (msg ? msg : "error"), lexptr);
1650}
1651