PageRenderTime 65ms CodeModel.GetById 27ms RepoModel.GetById 0ms app.codeStats 0ms

/opensource.apple.com/source/gdb/gdb-1708/src/gdb/f-exp.y

#
Happy | 1217 lines | 1043 code | 174 blank | 0 comment | 0 complexity | 5872978fdda91896688dfdaf2711ef7d MD5 | raw file
Possible License(s): MPL-2.0-no-copyleft-exception, GPL-2.0, BSD-3-Clause, GPL-3.0, MPL-2.0, LGPL-2.0, LGPL-2.1, CC-BY-SA-3.0, IPL-1.0, ISC, AGPL-1.0, AGPL-3.0, JSON, Apache-2.0, 0BSD
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
  2. "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
  3. <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
  4. <head>
  5. <title>f-exp.y</title>
  6. <style type="text/css">
  7. .enscript-comment { font-style: italic; color: rgb(178,34,34); }
  8. .enscript-function-name { font-weight: bold; color: rgb(0,0,255); }
  9. .enscript-variable-name { font-weight: bold; color: rgb(184,134,11); }
  10. .enscript-keyword { font-weight: bold; color: rgb(160,32,240); }
  11. .enscript-reference { font-weight: bold; color: rgb(95,158,160); }
  12. .enscript-string { font-weight: bold; color: rgb(188,143,143); }
  13. .enscript-builtin { font-weight: bold; color: rgb(218,112,214); }
  14. .enscript-type { font-weight: bold; color: rgb(34,139,34); }
  15. .enscript-highlight { text-decoration: underline; color: 0; }
  16. </style>
  17. </head>
  18. <body id="top">
  19. <h1 style="margin:8px;" id="f1">f-exp.y&nbsp;&nbsp;&nbsp;<span style="font-weight: normal; font-size: 0.5em;">[<a href="?txt">plain text</a>]</span></h1>
  20. <hr/>
  21. <div></div>
  22. <pre>
  23. /* YACC parser for Fortran expressions, for GDB.
  24. Copyright 1986, 1989, 1990, 1991, 1993, 1994, 1995, 1996, 2000, 2001,
  25. 2002, 2003, 2004, 2005 Free Software Foundation, Inc.
  26. Contributed by Motorola. Adapted from the C parser by Farooq Butt
  27. (<a href="mailto:fmbutt@engage.sps.mot.com">fmbutt@engage.sps.mot.com</a>).
  28. This file is part of GDB.
  29. This program is free software; you can redistribute it and/or modify
  30. it under the terms of the GNU General Public License as published by
  31. the Free Software Foundation; either version 2 of the License, or
  32. (at your option) any later version.
  33. This program is distributed in the hope that it will be useful,
  34. but WITHOUT ANY WARRANTY; without even the implied warranty of
  35. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  36. GNU General Public License for more details.
  37. You should have received a copy of the GNU General Public License
  38. along with this program; if not, write to the Free Software
  39. Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
  40. /* This was blantantly ripped off the C expression parser, please
  41. be aware of that as you look at its basic structure -FMB */
  42. /* Parse a F77 expression from text in a string,
  43. and return the result as a struct expression pointer.
  44. That structure contains arithmetic operations in reverse polish,
  45. with constants represented by operations that are followed by special data.
  46. See expression.h for the details of the format.
  47. What is important here is that it can be built up sequentially
  48. during the process of parsing; the lower levels of the tree always
  49. come first in the result.
  50. Note that malloc's and realloc's in this file are transformed to
  51. xmalloc and xrealloc respectively by the same sed command in the
  52. makefile that remaps any other malloc/realloc inserted by the parser
  53. generator. Doing this with #defines and trying to control the interaction
  54. with include files (&lt;malloc.h&gt; and &lt;stdlib.h&gt; for example) just became
  55. too messy, particularly when such includes can be inserted at random
  56. times by the parser generator. */
  57. %{
  58. #include &quot;defs.h&quot;
  59. #include &quot;gdb_string.h&quot;
  60. #include &quot;expression.h&quot;
  61. #include &quot;value.h&quot;
  62. #include &quot;parser-defs.h&quot;
  63. #include &quot;language.h&quot;
  64. #include &quot;f-lang.h&quot;
  65. #include &quot;bfd.h&quot; /* Required by objfiles.h. */
  66. #include &quot;symfile.h&quot; /* Required by objfiles.h. */
  67. #include &quot;objfiles.h&quot; /* For have_full_symbols and have_partial_symbols */
  68. #include &quot;block.h&quot;
  69. #include &lt;ctype.h&gt;
  70. /* Remap normal yacc parser interface names (yyparse, yylex, yyerror, etc),
  71. as well as gratuitiously global symbol names, so we can have multiple
  72. yacc generated parsers in gdb. Note that these are only the variables
  73. produced by yacc. If other parser generators (bison, byacc, etc) produce
  74. additional global names that conflict at link time, then those parser
  75. generators need to be fixed instead of adding those names to this list. */
  76. #define yymaxdepth f_maxdepth
  77. #define yyparse f_parse
  78. #define yylex f_lex
  79. #define yyerror f_error
  80. #define yylval f_lval
  81. #define yychar f_char
  82. #define yydebug f_debug
  83. #define yypact f_pact
  84. #define yyr1 f_r1
  85. #define yyr2 f_r2
  86. #define yydef f_def
  87. #define yychk f_chk
  88. #define yypgo f_pgo
  89. #define yyact f_act
  90. #define yyexca f_exca
  91. #define yyerrflag f_errflag
  92. #define yynerrs f_nerrs
  93. #define yyps f_ps
  94. #define yypv f_pv
  95. #define yys f_s
  96. #define yy_yys f_yys
  97. #define yystate f_state
  98. #define yytmp f_tmp
  99. #define yyv f_v
  100. #define yy_yyv f_yyv
  101. #define yyval f_val
  102. #define yylloc f_lloc
  103. #define yyreds f_reds /* With YYDEBUG defined */
  104. #define yytoks f_toks /* With YYDEBUG defined */
  105. #define yyname f_name /* With YYDEBUG defined */
  106. #define yyrule f_rule /* With YYDEBUG defined */
  107. #define yylhs f_yylhs
  108. #define yylen f_yylen
  109. #define yydefred f_yydefred
  110. #define yydgoto f_yydgoto
  111. #define yysindex f_yysindex
  112. #define yyrindex f_yyrindex
  113. #define yygindex f_yygindex
  114. #define yytable f_yytable
  115. #define yycheck f_yycheck
  116. #ifndef YYDEBUG
  117. #define YYDEBUG 1 /* Default to yydebug support */
  118. #endif
  119. #define YYFPRINTF parser_fprintf
  120. int yyparse (void);
  121. static int yylex (void);
  122. void yyerror (char *);
  123. static void growbuf_by_size (int);
  124. static int match_string_literal (void);
  125. %}
  126. /* Although the yacc &quot;value&quot; of an expression is not used,
  127. since the result is stored in the structure being created,
  128. other node types do have values. */
  129. %union
  130. {
  131. LONGEST lval;
  132. struct {
  133. LONGEST val;
  134. struct type *type;
  135. } typed_val;
  136. DOUBLEST dval;
  137. struct symbol *sym;
  138. struct type *tval;
  139. struct stoken sval;
  140. struct ttype tsym;
  141. struct symtoken ssym;
  142. int voidval;
  143. struct block *bval;
  144. enum exp_opcode opcode;
  145. struct internalvar *ivar;
  146. struct type **tvec;
  147. int *ivec;
  148. }
  149. %{
  150. /* YYSTYPE gets defined by %union */
  151. static int parse_number (char *, int, int, YYSTYPE *);
  152. %}
  153. %type &lt;voidval&gt; exp type_exp start variable
  154. %type &lt;tval&gt; type typebase
  155. %type &lt;tvec&gt; nonempty_typelist
  156. /* %type &lt;bval&gt; block */
  157. /* Fancy type parsing. */
  158. %type &lt;voidval&gt; func_mod direct_abs_decl abs_decl
  159. %type &lt;tval&gt; ptype
  160. %token &lt;typed_val&gt; INT
  161. %token &lt;dval&gt; FLOAT
  162. /* Both NAME and TYPENAME tokens represent symbols in the input,
  163. and both convey their data as strings.
  164. But a TYPENAME is a string that happens to be defined as a typedef
  165. or builtin type name (such as int or char)
  166. and a NAME is any other symbol.
  167. Contexts where this distinction is not important can use the
  168. nonterminal &quot;name&quot;, which matches either NAME or TYPENAME. */
  169. %token &lt;sval&gt; STRING_LITERAL
  170. %token &lt;lval&gt; BOOLEAN_LITERAL
  171. %token &lt;ssym&gt; NAME
  172. %token &lt;tsym&gt; TYPENAME
  173. %type &lt;ssym&gt; name_not_typename
  174. /* A NAME_OR_INT is a symbol which is not known in the symbol table,
  175. but which would parse as a valid number in the current input radix.
  176. E.g. &quot;c&quot; when input_radix==16. Depending on the parse, it will be
  177. turned into a name or into a number. */
  178. %token &lt;ssym&gt; NAME_OR_INT
  179. %token SIZEOF
  180. %token ERROR
  181. /* Special type cases, put in to allow the parser to distinguish different
  182. legal basetypes. */
  183. %token INT_KEYWORD INT_S2_KEYWORD LOGICAL_S1_KEYWORD LOGICAL_S2_KEYWORD
  184. %token LOGICAL_KEYWORD REAL_KEYWORD REAL_S8_KEYWORD REAL_S16_KEYWORD
  185. %token COMPLEX_S8_KEYWORD COMPLEX_S16_KEYWORD COMPLEX_S32_KEYWORD
  186. %token BOOL_AND BOOL_OR BOOL_NOT
  187. %token &lt;lval&gt; CHARACTER
  188. %token &lt;voidval&gt; VARIABLE
  189. %token &lt;opcode&gt; ASSIGN_MODIFY
  190. %left ','
  191. %left ABOVE_COMMA
  192. %right '=' ASSIGN_MODIFY
  193. %right '?'
  194. %left BOOL_OR
  195. %right BOOL_NOT
  196. %left BOOL_AND
  197. %left '|'
  198. %left '^'
  199. %left '&amp;'
  200. %left EQUAL NOTEQUAL
  201. %left LESSTHAN GREATERTHAN LEQ GEQ
  202. %left LSH RSH
  203. %left '@'
  204. %left '+' '-'
  205. %left '*' '/' '%'
  206. %right STARSTAR
  207. %right UNARY
  208. %right '('
  209. %%
  210. start : exp
  211. | type_exp
  212. ;
  213. type_exp: type
  214. { write_exp_elt_opcode(OP_TYPE);
  215. write_exp_elt_type($1);
  216. write_exp_elt_opcode(OP_TYPE); }
  217. ;
  218. exp : '(' exp ')'
  219. { }
  220. ;
  221. /* Expressions, not including the comma operator. */
  222. exp : '*' exp %prec UNARY
  223. { write_exp_elt_opcode (UNOP_IND); }
  224. ;
  225. exp : '&amp;' exp %prec UNARY
  226. { write_exp_elt_opcode (UNOP_ADDR); }
  227. ;
  228. exp : '-' exp %prec UNARY
  229. { write_exp_elt_opcode (UNOP_NEG); }
  230. ;
  231. exp : BOOL_NOT exp %prec UNARY
  232. { write_exp_elt_opcode (UNOP_LOGICAL_NOT); }
  233. ;
  234. exp : '~' exp %prec UNARY
  235. { write_exp_elt_opcode (UNOP_COMPLEMENT); }
  236. ;
  237. exp : SIZEOF exp %prec UNARY
  238. { write_exp_elt_opcode (UNOP_SIZEOF); }
  239. ;
  240. /* No more explicit array operators, we treat everything in F77 as
  241. a function call. The disambiguation as to whether we are
  242. doing a subscript operation or a function call is done
  243. later in eval.c. */
  244. exp : exp '('
  245. { start_arglist (); }
  246. arglist ')'
  247. { write_exp_elt_opcode (OP_F77_UNDETERMINED_ARGLIST);
  248. write_exp_elt_longcst ((LONGEST) end_arglist ());
  249. write_exp_elt_opcode (OP_F77_UNDETERMINED_ARGLIST); }
  250. ;
  251. arglist :
  252. ;
  253. arglist : exp
  254. { arglist_len = 1; }
  255. ;
  256. arglist : substring
  257. { arglist_len = 2;}
  258. ;
  259. arglist : arglist ',' exp %prec ABOVE_COMMA
  260. { arglist_len++; }
  261. ;
  262. substring: exp ':' exp %prec ABOVE_COMMA
  263. { }
  264. ;
  265. complexnum: exp ',' exp
  266. { }
  267. ;
  268. exp : '(' complexnum ')'
  269. { write_exp_elt_opcode(OP_COMPLEX); }
  270. ;
  271. exp : '(' type ')' exp %prec UNARY
  272. { write_exp_elt_opcode (UNOP_CAST);
  273. write_exp_elt_type ($2);
  274. write_exp_elt_opcode (UNOP_CAST); }
  275. ;
  276. /* Binary operators in order of decreasing precedence. */
  277. exp : exp '@' exp
  278. { write_exp_elt_opcode (BINOP_REPEAT); }
  279. ;
  280. exp : exp STARSTAR exp
  281. { write_exp_elt_opcode (BINOP_EXP); }
  282. ;
  283. exp : exp '*' exp
  284. { write_exp_elt_opcode (BINOP_MUL); }
  285. ;
  286. exp : exp '/' exp
  287. { write_exp_elt_opcode (BINOP_DIV); }
  288. ;
  289. exp : exp '%' exp
  290. { write_exp_elt_opcode (BINOP_REM); }
  291. ;
  292. exp : exp '+' exp
  293. { write_exp_elt_opcode (BINOP_ADD); }
  294. ;
  295. exp : exp '-' exp
  296. { write_exp_elt_opcode (BINOP_SUB); }
  297. ;
  298. exp : exp LSH exp
  299. { write_exp_elt_opcode (BINOP_LSH); }
  300. ;
  301. exp : exp RSH exp
  302. { write_exp_elt_opcode (BINOP_RSH); }
  303. ;
  304. exp : exp EQUAL exp
  305. { write_exp_elt_opcode (BINOP_EQUAL); }
  306. ;
  307. exp : exp NOTEQUAL exp
  308. { write_exp_elt_opcode (BINOP_NOTEQUAL); }
  309. ;
  310. exp : exp LEQ exp
  311. { write_exp_elt_opcode (BINOP_LEQ); }
  312. ;
  313. exp : exp GEQ exp
  314. { write_exp_elt_opcode (BINOP_GEQ); }
  315. ;
  316. exp : exp LESSTHAN exp
  317. { write_exp_elt_opcode (BINOP_LESS); }
  318. ;
  319. exp : exp GREATERTHAN exp
  320. { write_exp_elt_opcode (BINOP_GTR); }
  321. ;
  322. exp : exp '&amp;' exp
  323. { write_exp_elt_opcode (BINOP_BITWISE_AND); }
  324. ;
  325. exp : exp '^' exp
  326. { write_exp_elt_opcode (BINOP_BITWISE_XOR); }
  327. ;
  328. exp : exp '|' exp
  329. { write_exp_elt_opcode (BINOP_BITWISE_IOR); }
  330. ;
  331. exp : exp BOOL_AND exp
  332. { write_exp_elt_opcode (BINOP_LOGICAL_AND); }
  333. ;
  334. exp : exp BOOL_OR exp
  335. { write_exp_elt_opcode (BINOP_LOGICAL_OR); }
  336. ;
  337. exp : exp '=' exp
  338. { write_exp_elt_opcode (BINOP_ASSIGN); }
  339. ;
  340. exp : exp ASSIGN_MODIFY exp
  341. { write_exp_elt_opcode (BINOP_ASSIGN_MODIFY);
  342. write_exp_elt_opcode ($2);
  343. write_exp_elt_opcode (BINOP_ASSIGN_MODIFY); }
  344. ;
  345. exp : INT
  346. { write_exp_elt_opcode (OP_LONG);
  347. write_exp_elt_type ($1.type);
  348. write_exp_elt_longcst ((LONGEST)($1.val));
  349. write_exp_elt_opcode (OP_LONG); }
  350. ;
  351. exp : NAME_OR_INT
  352. { YYSTYPE val;
  353. parse_number ($1.stoken.ptr, $1.stoken.length, 0, &amp;val);
  354. write_exp_elt_opcode (OP_LONG);
  355. write_exp_elt_type (val.typed_val.type);
  356. write_exp_elt_longcst ((LONGEST)val.typed_val.val);
  357. write_exp_elt_opcode (OP_LONG); }
  358. ;
  359. exp : FLOAT
  360. { write_exp_elt_opcode (OP_DOUBLE);
  361. write_exp_elt_type (builtin_type_f_real_s8);
  362. write_exp_elt_dblcst ($1);
  363. write_exp_elt_opcode (OP_DOUBLE); }
  364. ;
  365. exp : variable
  366. ;
  367. exp : VARIABLE
  368. ;
  369. exp : SIZEOF '(' type ')' %prec UNARY
  370. { write_exp_elt_opcode (OP_LONG);
  371. write_exp_elt_type (builtin_type_f_integer);
  372. CHECK_TYPEDEF ($3);
  373. write_exp_elt_longcst ((LONGEST) TYPE_LENGTH ($3));
  374. write_exp_elt_opcode (OP_LONG); }
  375. ;
  376. exp : BOOLEAN_LITERAL
  377. { write_exp_elt_opcode (OP_BOOL);
  378. write_exp_elt_longcst ((LONGEST) $1);
  379. write_exp_elt_opcode (OP_BOOL);
  380. }
  381. ;
  382. exp : STRING_LITERAL
  383. {
  384. write_exp_elt_opcode (OP_STRING);
  385. write_exp_string ($1);
  386. write_exp_elt_opcode (OP_STRING);
  387. }
  388. ;
  389. variable: name_not_typename
  390. { struct symbol *sym = $1.sym;
  391. if (sym)
  392. {
  393. if (symbol_read_needs_frame (sym))
  394. {
  395. if (innermost_block == 0 ||
  396. contained_in (block_found,
  397. innermost_block))
  398. innermost_block = block_found;
  399. }
  400. write_exp_elt_opcode (OP_VAR_VALUE);
  401. /* We want to use the selected frame, not
  402. another more inner frame which happens to
  403. be in the same block. */
  404. write_exp_elt_block (NULL);
  405. write_exp_elt_sym (sym);
  406. write_exp_elt_opcode (OP_VAR_VALUE);
  407. break;
  408. }
  409. else
  410. {
  411. struct minimal_symbol *msymbol;
  412. char *arg = copy_name ($1.stoken);
  413. msymbol =
  414. lookup_minimal_symbol (arg, NULL, NULL);
  415. if (msymbol != NULL)
  416. {
  417. write_exp_msymbol (msymbol,
  418. lookup_function_type (builtin_type_int),
  419. builtin_type_int);
  420. }
  421. else if (!have_full_symbols () &amp;&amp; !have_partial_symbols ())
  422. error (&quot;No symbol table is loaded. Use the \&quot;file\&quot; command.&quot;);
  423. else
  424. error (&quot;No symbol \&quot;%s\&quot; in current context.&quot;,
  425. copy_name ($1.stoken));
  426. }
  427. }
  428. ;
  429. type : ptype
  430. ;
  431. ptype : typebase
  432. | typebase abs_decl
  433. {
  434. /* This is where the interesting stuff happens. */
  435. int done = 0;
  436. int array_size;
  437. struct type *follow_type = $1;
  438. struct type *range_type;
  439. while (!done)
  440. switch (pop_type ())
  441. {
  442. case tp_end:
  443. done = 1;
  444. break;
  445. case tp_pointer:
  446. follow_type = lookup_pointer_type (follow_type);
  447. break;
  448. case tp_reference:
  449. follow_type = lookup_reference_type (follow_type);
  450. break;
  451. case tp_array:
  452. array_size = pop_type_int ();
  453. if (array_size != -1)
  454. {
  455. range_type =
  456. create_range_type ((struct type *) NULL,
  457. builtin_type_f_integer, 0,
  458. array_size - 1);
  459. follow_type =
  460. create_array_type ((struct type *) NULL,
  461. follow_type, range_type);
  462. }
  463. else
  464. follow_type = lookup_pointer_type (follow_type);
  465. break;
  466. case tp_function:
  467. follow_type = lookup_function_type (follow_type);
  468. break;
  469. }
  470. $$ = follow_type;
  471. }
  472. ;
  473. abs_decl: '*'
  474. { push_type (tp_pointer); $$ = 0; }
  475. | '*' abs_decl
  476. { push_type (tp_pointer); $$ = $2; }
  477. | '&amp;'
  478. { push_type (tp_reference); $$ = 0; }
  479. | '&amp;' abs_decl
  480. { push_type (tp_reference); $$ = $2; }
  481. | direct_abs_decl
  482. ;
  483. direct_abs_decl: '(' abs_decl ')'
  484. { $$ = $2; }
  485. | direct_abs_decl func_mod
  486. { push_type (tp_function); }
  487. | func_mod
  488. { push_type (tp_function); }
  489. ;
  490. func_mod: '(' ')'
  491. { $$ = 0; }
  492. | '(' nonempty_typelist ')'
  493. { free ($2); $$ = 0; }
  494. ;
  495. typebase /* Implements (approximately): (type-qualifier)* type-specifier */
  496. : TYPENAME
  497. { $$ = $1.type; }
  498. | INT_KEYWORD
  499. { $$ = builtin_type_f_integer; }
  500. | INT_S2_KEYWORD
  501. { $$ = builtin_type_f_integer_s2; }
  502. | CHARACTER
  503. { $$ = builtin_type_f_character; }
  504. | LOGICAL_KEYWORD
  505. { $$ = builtin_type_f_logical;}
  506. | LOGICAL_S2_KEYWORD
  507. { $$ = builtin_type_f_logical_s2;}
  508. | LOGICAL_S1_KEYWORD
  509. { $$ = builtin_type_f_logical_s1;}
  510. | REAL_KEYWORD
  511. { $$ = builtin_type_f_real;}
  512. | REAL_S8_KEYWORD
  513. { $$ = builtin_type_f_real_s8;}
  514. | REAL_S16_KEYWORD
  515. { $$ = builtin_type_f_real_s16;}
  516. | COMPLEX_S8_KEYWORD
  517. { $$ = builtin_type_f_complex_s8;}
  518. | COMPLEX_S16_KEYWORD
  519. { $$ = builtin_type_f_complex_s16;}
  520. | COMPLEX_S32_KEYWORD
  521. { $$ = builtin_type_f_complex_s32;}
  522. ;
  523. nonempty_typelist
  524. : type
  525. { $$ = (struct type **) malloc (sizeof (struct type *) * 2);
  526. $&lt;ivec&gt;$[0] = 1; /* Number of types in vector */
  527. $$[1] = $1;
  528. }
  529. | nonempty_typelist ',' type
  530. { int len = sizeof (struct type *) * (++($&lt;ivec&gt;1[0]) + 1);
  531. $$ = (struct type **) realloc ((char *) $1, len);
  532. $$[$&lt;ivec&gt;$[0]] = $3;
  533. }
  534. ;
  535. name_not_typename : NAME
  536. /* These would be useful if name_not_typename was useful, but it is just
  537. a fake for &quot;variable&quot;, so these cause reduce/reduce conflicts because
  538. the parser can't tell whether NAME_OR_INT is a name_not_typename (=variable,
  539. =exp) or just an exp. If name_not_typename was ever used in an lvalue
  540. context where only a name could occur, this might be useful.
  541. | NAME_OR_INT
  542. */
  543. ;
  544. %%
  545. /* Take care of parsing a number (anything that starts with a digit).
  546. Set yylval and return the token type; update lexptr.
  547. LEN is the number of characters in it. */
  548. /*** Needs some error checking for the float case ***/
  549. static int
  550. parse_number (p, len, parsed_float, putithere)
  551. char *p;
  552. int len;
  553. int parsed_float;
  554. YYSTYPE *putithere;
  555. {
  556. LONGEST n = 0;
  557. LONGEST prevn = 0;
  558. int c;
  559. int base = input_radix;
  560. int unsigned_p = 0;
  561. int long_p = 0;
  562. ULONGEST high_bit;
  563. struct type *signed_type;
  564. struct type *unsigned_type;
  565. if (parsed_float)
  566. {
  567. /* It's a float since it contains a point or an exponent. */
  568. /* [dD] is not understood as an exponent by atof, change it to 'e'. */
  569. char *tmp, *tmp2;
  570. tmp = xstrdup (p);
  571. for (tmp2 = tmp; *tmp2; ++tmp2)
  572. if (*tmp2 == 'd' || *tmp2 == 'D')
  573. *tmp2 = 'e';
  574. putithere-&gt;dval = atof (tmp);
  575. free (tmp);
  576. return FLOAT;
  577. }
  578. /* Handle base-switching prefixes 0x, 0t, 0d, 0 */
  579. if (p[0] == '0')
  580. switch (p[1])
  581. {
  582. case 'x':
  583. case 'X':
  584. if (len &gt;= 3)
  585. {
  586. p += 2;
  587. base = 16;
  588. len -= 2;
  589. }
  590. break;
  591. case 't':
  592. case 'T':
  593. case 'd':
  594. case 'D':
  595. if (len &gt;= 3)
  596. {
  597. p += 2;
  598. base = 10;
  599. len -= 2;
  600. }
  601. break;
  602. default:
  603. base = 8;
  604. break;
  605. }
  606. while (len-- &gt; 0)
  607. {
  608. c = *p++;
  609. if (isupper (c))
  610. c = tolower (c);
  611. if (len == 0 &amp;&amp; c == 'l')
  612. long_p = 1;
  613. else if (len == 0 &amp;&amp; c == 'u')
  614. unsigned_p = 1;
  615. else
  616. {
  617. int i;
  618. if (c &gt;= '0' &amp;&amp; c &lt;= '9')
  619. i = c - '0';
  620. else if (c &gt;= 'a' &amp;&amp; c &lt;= 'f')
  621. i = c - 'a' + 10;
  622. else
  623. return ERROR; /* Char not a digit */
  624. if (i &gt;= base)
  625. return ERROR; /* Invalid digit in this base */
  626. n *= base;
  627. n += i;
  628. }
  629. /* Portably test for overflow (only works for nonzero values, so make
  630. a second check for zero). */
  631. if ((prevn &gt;= n) &amp;&amp; n != 0)
  632. unsigned_p=1; /* Try something unsigned */
  633. /* If range checking enabled, portably test for unsigned overflow. */
  634. if (RANGE_CHECK &amp;&amp; n != 0)
  635. {
  636. if ((unsigned_p &amp;&amp; (unsigned)prevn &gt;= (unsigned)n))
  637. range_error(&quot;Overflow on numeric constant.&quot;);
  638. }
  639. prevn = n;
  640. }
  641. /* If the number is too big to be an int, or it's got an l suffix
  642. then it's a long. Work out if this has to be a long by
  643. shifting right and and seeing if anything remains, and the
  644. target int size is different to the target long size.
  645. In the expression below, we could have tested
  646. (n &gt;&gt; TARGET_INT_BIT)
  647. to see if it was zero,
  648. but too many compilers warn about that, when ints and longs
  649. are the same size. So we shift it twice, with fewer bits
  650. each time, for the same result. */
  651. if ((TARGET_INT_BIT != TARGET_LONG_BIT
  652. &amp;&amp; ((n &gt;&gt; 2) &gt;&gt; (TARGET_INT_BIT-2))) /* Avoid shift warning */
  653. || long_p)
  654. {
  655. high_bit = ((ULONGEST)1) &lt;&lt; (TARGET_LONG_BIT-1);
  656. unsigned_type = builtin_type_unsigned_long;
  657. signed_type = builtin_type_long;
  658. }
  659. else
  660. {
  661. high_bit = ((ULONGEST)1) &lt;&lt; (TARGET_INT_BIT-1);
  662. unsigned_type = builtin_type_unsigned_int;
  663. signed_type = builtin_type_int;
  664. }
  665. putithere-&gt;typed_val.val = n;
  666. /* If the high bit of the worked out type is set then this number
  667. has to be unsigned. */
  668. if (unsigned_p || (n &amp; high_bit))
  669. putithere-&gt;typed_val.type = unsigned_type;
  670. else
  671. putithere-&gt;typed_val.type = signed_type;
  672. return INT;
  673. }
  674. struct token
  675. {
  676. char *operator;
  677. int token;
  678. enum exp_opcode opcode;
  679. };
  680. static const struct token dot_ops[] =
  681. {
  682. { &quot;.and.&quot;, BOOL_AND, BINOP_END },
  683. { &quot;.AND.&quot;, BOOL_AND, BINOP_END },
  684. { &quot;.or.&quot;, BOOL_OR, BINOP_END },
  685. { &quot;.OR.&quot;, BOOL_OR, BINOP_END },
  686. { &quot;.not.&quot;, BOOL_NOT, BINOP_END },
  687. { &quot;.NOT.&quot;, BOOL_NOT, BINOP_END },
  688. { &quot;.eq.&quot;, EQUAL, BINOP_END },
  689. { &quot;.EQ.&quot;, EQUAL, BINOP_END },
  690. { &quot;.eqv.&quot;, EQUAL, BINOP_END },
  691. { &quot;.NEQV.&quot;, NOTEQUAL, BINOP_END },
  692. { &quot;.neqv.&quot;, NOTEQUAL, BINOP_END },
  693. { &quot;.EQV.&quot;, EQUAL, BINOP_END },
  694. { &quot;.ne.&quot;, NOTEQUAL, BINOP_END },
  695. { &quot;.NE.&quot;, NOTEQUAL, BINOP_END },
  696. { &quot;.le.&quot;, LEQ, BINOP_END },
  697. { &quot;.LE.&quot;, LEQ, BINOP_END },
  698. { &quot;.ge.&quot;, GEQ, BINOP_END },
  699. { &quot;.GE.&quot;, GEQ, BINOP_END },
  700. { &quot;.gt.&quot;, GREATERTHAN, BINOP_END },
  701. { &quot;.GT.&quot;, GREATERTHAN, BINOP_END },
  702. { &quot;.lt.&quot;, LESSTHAN, BINOP_END },
  703. { &quot;.LT.&quot;, LESSTHAN, BINOP_END },
  704. { NULL, 0, 0 }
  705. };
  706. struct f77_boolean_val
  707. {
  708. char *name;
  709. int value;
  710. };
  711. static const struct f77_boolean_val boolean_values[] =
  712. {
  713. { &quot;.true.&quot;, 1 },
  714. { &quot;.TRUE.&quot;, 1 },
  715. { &quot;.false.&quot;, 0 },
  716. { &quot;.FALSE.&quot;, 0 },
  717. { NULL, 0 }
  718. };
  719. static const struct token f77_keywords[] =
  720. {
  721. { &quot;complex_16&quot;, COMPLEX_S16_KEYWORD, BINOP_END },
  722. { &quot;complex_32&quot;, COMPLEX_S32_KEYWORD, BINOP_END },
  723. { &quot;character&quot;, CHARACTER, BINOP_END },
  724. { &quot;integer_2&quot;, INT_S2_KEYWORD, BINOP_END },
  725. { &quot;logical_1&quot;, LOGICAL_S1_KEYWORD, BINOP_END },
  726. { &quot;logical_2&quot;, LOGICAL_S2_KEYWORD, BINOP_END },
  727. { &quot;complex_8&quot;, COMPLEX_S8_KEYWORD, BINOP_END },
  728. { &quot;integer&quot;, INT_KEYWORD, BINOP_END },
  729. { &quot;logical&quot;, LOGICAL_KEYWORD, BINOP_END },
  730. { &quot;real_16&quot;, REAL_S16_KEYWORD, BINOP_END },
  731. { &quot;complex&quot;, COMPLEX_S8_KEYWORD, BINOP_END },
  732. { &quot;sizeof&quot;, SIZEOF, BINOP_END },
  733. { &quot;real_8&quot;, REAL_S8_KEYWORD, BINOP_END },
  734. { &quot;real&quot;, REAL_KEYWORD, BINOP_END },
  735. { NULL, 0, 0 }
  736. };
  737. /* Implementation of a dynamically expandable buffer for processing input
  738. characters acquired through lexptr and building a value to return in
  739. yylval. Ripped off from ch-exp.y */
  740. static char *tempbuf; /* Current buffer contents */
  741. static int tempbufsize; /* Size of allocated buffer */
  742. static int tempbufindex; /* Current index into buffer */
  743. #define GROWBY_MIN_SIZE 64 /* Minimum amount to grow buffer by */
  744. #define CHECKBUF(size) \
  745. do { \
  746. if (tempbufindex + (size) &gt;= tempbufsize) \
  747. { \
  748. growbuf_by_size (size); \
  749. } \
  750. } while (0);
  751. /* Grow the static temp buffer if necessary, including allocating the first one
  752. on demand. */
  753. static void
  754. growbuf_by_size (count)
  755. int count;
  756. {
  757. int growby;
  758. growby = max (count, GROWBY_MIN_SIZE);
  759. tempbufsize += growby;
  760. if (tempbuf == NULL)
  761. tempbuf = (char *) malloc (tempbufsize);
  762. else
  763. tempbuf = (char *) realloc (tempbuf, tempbufsize);
  764. }
  765. /* Blatantly ripped off from ch-exp.y. This routine recognizes F77
  766. string-literals.
  767. Recognize a string literal. A string literal is a nonzero sequence
  768. of characters enclosed in matching single quotes, except that
  769. a single character inside single quotes is a character literal, which
  770. we reject as a string literal. To embed the terminator character inside
  771. a string, it is simply doubled (I.E. 'this''is''one''string') */
  772. static int
  773. match_string_literal ()
  774. {
  775. char *tokptr = lexptr;
  776. for (tempbufindex = 0, tokptr++; *tokptr != '\0'; tokptr++)
  777. {
  778. CHECKBUF (1);
  779. if (*tokptr == *lexptr)
  780. {
  781. if (*(tokptr + 1) == *lexptr)
  782. tokptr++;
  783. else
  784. break;
  785. }
  786. tempbuf[tempbufindex++] = *tokptr;
  787. }
  788. if (*tokptr == '\0' /* no terminator */
  789. || tempbufindex == 0) /* no string */
  790. return 0;
  791. else
  792. {
  793. tempbuf[tempbufindex] = '\0';
  794. yylval.sval.ptr = tempbuf;
  795. yylval.sval.length = tempbufindex;
  796. lexptr = ++tokptr;
  797. return STRING_LITERAL;
  798. }
  799. }
  800. /* Read one token, getting characters through lexptr. */
  801. static int
  802. yylex ()
  803. {
  804. int c;
  805. int namelen;
  806. unsigned int i,token;
  807. char *tokstart;
  808. retry:
  809. prev_lexptr = lexptr;
  810. tokstart = lexptr;
  811. /* First of all, let us make sure we are not dealing with the
  812. special tokens .true. and .false. which evaluate to 1 and 0. */
  813. if (*lexptr == '.')
  814. {
  815. for (i = 0; boolean_values[i].name != NULL; i++)
  816. {
  817. if (strncmp (tokstart, boolean_values[i].name,
  818. strlen (boolean_values[i].name)) == 0)
  819. {
  820. lexptr += strlen (boolean_values[i].name);
  821. yylval.lval = boolean_values[i].value;
  822. return BOOLEAN_LITERAL;
  823. }
  824. }
  825. }
  826. /* See if it is a special .foo. operator. */
  827. for (i = 0; dot_ops[i].operator != NULL; i++)
  828. if (strncmp (tokstart, dot_ops[i].operator, strlen (dot_ops[i].operator)) == 0)
  829. {
  830. lexptr += strlen (dot_ops[i].operator);
  831. yylval.opcode = dot_ops[i].opcode;
  832. return dot_ops[i].token;
  833. }
  834. /* See if it is an exponentiation operator. */
  835. if (strncmp (tokstart, &quot;**&quot;, 2) == 0)
  836. {
  837. lexptr += 2;
  838. yylval.opcode = BINOP_EXP;
  839. return STARSTAR;
  840. }
  841. switch (c = *tokstart)
  842. {
  843. case 0:
  844. return 0;
  845. case ' ':
  846. case '\t':
  847. case '\n':
  848. lexptr++;
  849. goto retry;
  850. case '\'':
  851. token = match_string_literal ();
  852. if (token != 0)
  853. return (token);
  854. break;
  855. case '(':
  856. paren_depth++;
  857. lexptr++;
  858. return c;
  859. case ')':
  860. if (paren_depth == 0)
  861. return 0;
  862. paren_depth--;
  863. lexptr++;
  864. return c;
  865. case ',':
  866. if (comma_terminates &amp;&amp; paren_depth == 0)
  867. return 0;
  868. lexptr++;
  869. return c;
  870. case '.':
  871. /* Might be a floating point number. */
  872. if (lexptr[1] &lt; '0' || lexptr[1] &gt; '9')
  873. goto symbol; /* Nope, must be a symbol. */
  874. /* FALL THRU into number case. */
  875. case '0':
  876. case '1':
  877. case '2':
  878. case '3':
  879. case '4':
  880. case '5':
  881. case '6':
  882. case '7':
  883. case '8':
  884. case '9':
  885. {
  886. /* It's a number. */
  887. int got_dot = 0, got_e = 0, got_d = 0, toktype;
  888. char *p = tokstart;
  889. int hex = input_radix &gt; 10;
  890. if (c == '0' &amp;&amp; (p[1] == 'x' || p[1] == 'X'))
  891. {
  892. p += 2;
  893. hex = 1;
  894. }
  895. else if (c == '0' &amp;&amp; (p[1]=='t' || p[1]=='T' || p[1]=='d' || p[1]=='D'))
  896. {
  897. p += 2;
  898. hex = 0;
  899. }
  900. for (;; ++p)
  901. {
  902. if (!hex &amp;&amp; !got_e &amp;&amp; (*p == 'e' || *p == 'E'))
  903. got_dot = got_e = 1;
  904. else if (!hex &amp;&amp; !got_d &amp;&amp; (*p == 'd' || *p == 'D'))
  905. got_dot = got_d = 1;
  906. else if (!hex &amp;&amp; !got_dot &amp;&amp; *p == '.')
  907. got_dot = 1;
  908. else if (((got_e &amp;&amp; (p[-1] == 'e' || p[-1] == 'E'))
  909. || (got_d &amp;&amp; (p[-1] == 'd' || p[-1] == 'D')))
  910. &amp;&amp; (*p == '-' || *p == '+'))
  911. /* This is the sign of the exponent, not the end of the
  912. number. */
  913. continue;
  914. /* We will take any letters or digits. parse_number will
  915. complain if past the radix, or if L or U are not final. */
  916. else if ((*p &lt; '0' || *p &gt; '9')
  917. &amp;&amp; ((*p &lt; 'a' || *p &gt; 'z')
  918. &amp;&amp; (*p &lt; 'A' || *p &gt; 'Z')))
  919. break;
  920. }
  921. toktype = parse_number (tokstart, p - tokstart, got_dot|got_e|got_d,
  922. &amp;yylval);
  923. if (toktype == ERROR)
  924. {
  925. char *err_copy = (char *) alloca (p - tokstart + 1);
  926. memcpy (err_copy, tokstart, p - tokstart);
  927. err_copy[p - tokstart] = 0;
  928. error (&quot;Invalid number \&quot;%s\&quot;.&quot;, err_copy);
  929. }
  930. lexptr = p;
  931. return toktype;
  932. }
  933. case '+':
  934. case '-':
  935. case '*':
  936. case '/':
  937. case '%':
  938. case '|':
  939. case '&amp;':
  940. case '^':
  941. case '~':
  942. case '!':
  943. case '@':
  944. case '&lt;':
  945. case '&gt;':
  946. case '[':
  947. case ']':
  948. case '?':
  949. case ':':
  950. case '=':
  951. case '{':
  952. case '}':
  953. symbol:
  954. lexptr++;
  955. return c;
  956. }
  957. if (!(c == '_' || c == '$'
  958. || (c &gt;= 'a' &amp;&amp; c &lt;= 'z') || (c &gt;= 'A' &amp;&amp; c &lt;= 'Z')))
  959. /* We must have come across a bad character (e.g. ';'). */
  960. error (&quot;Invalid character '%c' in expression.&quot;, c);
  961. namelen = 0;
  962. for (c = tokstart[namelen];
  963. (c == '_' || c == '$' || (c &gt;= '0' &amp;&amp; c &lt;= '9')
  964. || (c &gt;= 'a' &amp;&amp; c &lt;= 'z') || (c &gt;= 'A' &amp;&amp; c &lt;= 'Z'));
  965. c = tokstart[++namelen]);
  966. /* The token &quot;if&quot; terminates the expression and is NOT
  967. removed from the input stream. */
  968. if (namelen == 2 &amp;&amp; tokstart[0] == 'i' &amp;&amp; tokstart[1] == 'f')
  969. return 0;
  970. lexptr += namelen;
  971. /* Catch specific keywords. */
  972. for (i = 0; f77_keywords[i].operator != NULL; i++)
  973. if (strncmp (tokstart, f77_keywords[i].operator,
  974. strlen(f77_keywords[i].operator)) == 0)
  975. {
  976. /* lexptr += strlen(f77_keywords[i].operator); */
  977. yylval.opcode = f77_keywords[i].opcode;
  978. return f77_keywords[i].token;
  979. }
  980. yylval.sval.ptr = tokstart;
  981. yylval.sval.length = namelen;
  982. if (*tokstart == '$')
  983. {
  984. write_dollar_variable (yylval.sval);
  985. return VARIABLE;
  986. }
  987. /* Use token-type TYPENAME for symbols that happen to be defined
  988. currently as names of types; NAME for other symbols.
  989. The caller is not constrained to care about the distinction. */
  990. {
  991. char *tmp = copy_name (yylval.sval);
  992. struct symbol *sym;
  993. int is_a_field_of_this = 0;
  994. int hextype;
  995. sym = lookup_symbol (tmp, expression_context_block,
  996. VAR_DOMAIN,
  997. current_language-&gt;la_language == language_cplus
  998. ? &amp;is_a_field_of_this : NULL,
  999. NULL);
  1000. if (sym &amp;&amp; SYMBOL_CLASS (sym) == LOC_TYPEDEF)
  1001. {
  1002. yylval.tsym.type = SYMBOL_TYPE (sym);
  1003. return TYPENAME;
  1004. }
  1005. yylval.tsym.type
  1006. = language_lookup_primitive_type_by_name (current_language,
  1007. current_gdbarch, tmp);
  1008. if (yylval.tsym.type != NULL)
  1009. return TYPENAME;
  1010. /* Input names that aren't symbols but ARE valid hex numbers,
  1011. when the input radix permits them, can be names or numbers
  1012. depending on the parse. Note we support radixes &gt; 16 here. */
  1013. if (!sym
  1014. &amp;&amp; ((tokstart[0] &gt;= 'a' &amp;&amp; tokstart[0] &lt; 'a' + input_radix - 10)
  1015. || (tokstart[0] &gt;= 'A' &amp;&amp; tokstart[0] &lt; 'A' + input_radix - 10)))
  1016. {
  1017. YYSTYPE newlval; /* Its value is ignored. */
  1018. hextype = parse_number (tokstart, namelen, 0, &amp;newlval);
  1019. if (hextype == INT)
  1020. {
  1021. yylval.ssym.sym = sym;
  1022. yylval.ssym.is_a_field_of_this = is_a_field_of_this;
  1023. return NAME_OR_INT;
  1024. }
  1025. }
  1026. /* Any other kind of symbol */
  1027. yylval.ssym.sym = sym;
  1028. yylval.ssym.is_a_field_of_this = is_a_field_of_this;
  1029. return NAME;
  1030. }
  1031. }
  1032. void
  1033. yyerror (msg)
  1034. char *msg;
  1035. {
  1036. if (prev_lexptr)
  1037. lexptr = prev_lexptr;
  1038. error (&quot;A %s in expression, near `%s'.&quot;, (msg ? msg : &quot;error&quot;), lexptr);
  1039. }
  1040. </pre>
  1041. <hr />
  1042. </body></html>