PageRenderTime 62ms CodeModel.GetById 24ms RepoModel.GetById 0ms app.codeStats 0ms

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

#
Happy | 1133 lines | 954 code | 179 blank | 0 comment | 0 complexity | 430493ec3e88ce8712771460e03bb53b 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>m2-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">m2-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 grammar for Modula-2 expressions, for GDB.
  24. Copyright 1986, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1999,
  25. 2000
  26. Free Software Foundation, Inc.
  27. Generated from expread.y (now c-exp.y) and contributed by the Department
  28. of Computer Science at the State University of New York at Buffalo, 1991.
  29. This file is part of GDB.
  30. This program is free software; you can redistribute it and/or modify
  31. it under the terms of the GNU General Public License as published by
  32. the Free Software Foundation; either version 2 of the License, or
  33. (at your option) any later version.
  34. This program is distributed in the hope that it will be useful,
  35. but WITHOUT ANY WARRANTY; without even the implied warranty of
  36. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  37. GNU General Public License for more details.
  38. You should have received a copy of the GNU General Public License
  39. along with this program; if not, write to the Free Software
  40. Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
  41. /* Parse a Modula-2 expression from text in a string,
  42. and return the result as a struct expression pointer.
  43. That structure contains arithmetic operations in reverse polish,
  44. with constants represented by operations that are followed by special data.
  45. See expression.h for the details of the format.
  46. What is important here is that it can be built up sequentially
  47. during the process of parsing; the lower levels of the tree always
  48. come first in the result.
  49. Note that malloc's and realloc's in this file are transformed to
  50. xmalloc and xrealloc respectively by the same sed command in the
  51. makefile that remaps any other malloc/realloc inserted by the parser
  52. generator. Doing this with #defines and trying to control the interaction
  53. with include files (&lt;malloc.h&gt; and &lt;stdlib.h&gt; for example) just became
  54. too messy, particularly when such includes can be inserted at random
  55. times by the parser generator. */
  56. %{
  57. #include &quot;defs.h&quot;
  58. #include &quot;gdb_string.h&quot;
  59. #include &quot;expression.h&quot;
  60. #include &quot;language.h&quot;
  61. #include &quot;value.h&quot;
  62. #include &quot;parser-defs.h&quot;
  63. #include &quot;m2-lang.h&quot;
  64. #include &quot;bfd.h&quot; /* Required by objfiles.h. */
  65. #include &quot;symfile.h&quot; /* Required by objfiles.h. */
  66. #include &quot;objfiles.h&quot; /* For have_full_symbols and have_partial_symbols */
  67. #include &quot;block.h&quot;
  68. /* Remap normal yacc parser interface names (yyparse, yylex, yyerror, etc),
  69. as well as gratuitiously global symbol names, so we can have multiple
  70. yacc generated parsers in gdb. Note that these are only the variables
  71. produced by yacc. If other parser generators (bison, byacc, etc) produce
  72. additional global names that conflict at link time, then those parser
  73. generators need to be fixed instead of adding those names to this list. */
  74. #define yymaxdepth m2_maxdepth
  75. #define yyparse m2_parse
  76. #define yylex m2_lex
  77. #define yyerror m2_error
  78. #define yylval m2_lval
  79. #define yychar m2_char
  80. #define yydebug m2_debug
  81. #define yypact m2_pact
  82. #define yyr1 m2_r1
  83. #define yyr2 m2_r2
  84. #define yydef m2_def
  85. #define yychk m2_chk
  86. #define yypgo m2_pgo
  87. #define yyact m2_act
  88. #define yyexca m2_exca
  89. #define yyerrflag m2_errflag
  90. #define yynerrs m2_nerrs
  91. #define yyps m2_ps
  92. #define yypv m2_pv
  93. #define yys m2_s
  94. #define yy_yys m2_yys
  95. #define yystate m2_state
  96. #define yytmp m2_tmp
  97. #define yyv m2_v
  98. #define yy_yyv m2_yyv
  99. #define yyval m2_val
  100. #define yylloc m2_lloc
  101. #define yyreds m2_reds /* With YYDEBUG defined */
  102. #define yytoks m2_toks /* With YYDEBUG defined */
  103. #define yyname m2_name /* With YYDEBUG defined */
  104. #define yyrule m2_rule /* With YYDEBUG defined */
  105. #define yylhs m2_yylhs
  106. #define yylen m2_yylen
  107. #define yydefred m2_yydefred
  108. #define yydgoto m2_yydgoto
  109. #define yysindex m2_yysindex
  110. #define yyrindex m2_yyrindex
  111. #define yygindex m2_yygindex
  112. #define yytable m2_yytable
  113. #define yycheck m2_yycheck
  114. #ifndef YYDEBUG
  115. #define YYDEBUG 1 /* Default to yydebug support */
  116. #endif
  117. #define YYFPRINTF parser_fprintf
  118. int yyparse (void);
  119. static int yylex (void);
  120. void yyerror (char *);
  121. #if 0
  122. static char *make_qualname (char *, char *);
  123. #endif
  124. static int parse_number (int);
  125. /* The sign of the number being parsed. */
  126. static int number_sign = 1;
  127. /* The block that the module specified by the qualifer on an identifer is
  128. contained in, */
  129. #if 0
  130. static struct block *modblock=0;
  131. #endif
  132. %}
  133. /* Although the yacc &quot;value&quot; of an expression is not used,
  134. since the result is stored in the structure being created,
  135. other node types do have values. */
  136. %union
  137. {
  138. LONGEST lval;
  139. ULONGEST ulval;
  140. DOUBLEST dval;
  141. struct symbol *sym;
  142. struct type *tval;
  143. struct stoken sval;
  144. int voidval;
  145. struct block *bval;
  146. enum exp_opcode opcode;
  147. struct internalvar *ivar;
  148. struct type **tvec;
  149. int *ivec;
  150. }
  151. %type &lt;voidval&gt; exp type_exp start set
  152. %type &lt;voidval&gt; variable
  153. %type &lt;tval&gt; type
  154. %type &lt;bval&gt; block
  155. %type &lt;sym&gt; fblock
  156. %token &lt;lval&gt; INT HEX ERROR
  157. %token &lt;ulval&gt; UINT M2_TRUE M2_FALSE CHAR
  158. %token &lt;dval&gt; FLOAT
  159. /* Both NAME and TYPENAME tokens represent symbols in the input,
  160. and both convey their data as strings.
  161. But a TYPENAME is a string that happens to be defined as a typedef
  162. or builtin type name (such as int or char)
  163. and a NAME is any other symbol.
  164. Contexts where this distinction is not important can use the
  165. nonterminal &quot;name&quot;, which matches either NAME or TYPENAME. */
  166. %token &lt;sval&gt; STRING
  167. %token &lt;sval&gt; NAME BLOCKNAME IDENT VARNAME
  168. %token &lt;sval&gt; TYPENAME
  169. %token SIZE CAP ORD HIGH ABS MIN_FUNC MAX_FUNC FLOAT_FUNC VAL CHR ODD TRUNC
  170. %token INC DEC INCL EXCL
  171. /* The GDB scope operator */
  172. %token COLONCOLON
  173. %token &lt;voidval&gt; INTERNAL_VAR
  174. /* M2 tokens */
  175. %left ','
  176. %left ABOVE_COMMA
  177. %nonassoc ASSIGN
  178. %left '&lt;' '&gt;' LEQ GEQ '=' NOTEQUAL '#' IN
  179. %left OROR
  180. %left LOGICAL_AND '&amp;'
  181. %left '@'
  182. %left '+' '-'
  183. %left '*' '/' DIV MOD
  184. %right UNARY
  185. %right '^' DOT '[' '('
  186. %right NOT '~'
  187. %left COLONCOLON QID
  188. /* This is not an actual token ; it is used for precedence.
  189. %right QID
  190. */
  191. %%
  192. start : exp
  193. | type_exp
  194. ;
  195. type_exp: type
  196. { write_exp_elt_opcode(OP_TYPE);
  197. write_exp_elt_type($1);
  198. write_exp_elt_opcode(OP_TYPE);
  199. }
  200. ;
  201. /* Expressions */
  202. exp : exp '^' %prec UNARY
  203. { write_exp_elt_opcode (UNOP_IND); }
  204. ;
  205. exp : '-'
  206. { number_sign = -1; }
  207. exp %prec UNARY
  208. { number_sign = 1;
  209. write_exp_elt_opcode (UNOP_NEG); }
  210. ;
  211. exp : '+' exp %prec UNARY
  212. { write_exp_elt_opcode(UNOP_PLUS); }
  213. ;
  214. exp : not_exp exp %prec UNARY
  215. { write_exp_elt_opcode (UNOP_LOGICAL_NOT); }
  216. ;
  217. not_exp : NOT
  218. | '~'
  219. ;
  220. exp : CAP '(' exp ')'
  221. { write_exp_elt_opcode (UNOP_CAP); }
  222. ;
  223. exp : ORD '(' exp ')'
  224. { write_exp_elt_opcode (UNOP_ORD); }
  225. ;
  226. exp : ABS '(' exp ')'
  227. { write_exp_elt_opcode (UNOP_ABS); }
  228. ;
  229. exp : HIGH '(' exp ')'
  230. { write_exp_elt_opcode (UNOP_HIGH); }
  231. ;
  232. exp : MIN_FUNC '(' type ')'
  233. { write_exp_elt_opcode (UNOP_MIN);
  234. write_exp_elt_type ($3);
  235. write_exp_elt_opcode (UNOP_MIN); }
  236. ;
  237. exp : MAX_FUNC '(' type ')'
  238. { write_exp_elt_opcode (UNOP_MAX);
  239. write_exp_elt_type ($3);
  240. write_exp_elt_opcode (UNOP_MIN); }
  241. ;
  242. exp : FLOAT_FUNC '(' exp ')'
  243. { write_exp_elt_opcode (UNOP_FLOAT); }
  244. ;
  245. exp : VAL '(' type ',' exp ')'
  246. { write_exp_elt_opcode (BINOP_VAL);
  247. write_exp_elt_type ($3);
  248. write_exp_elt_opcode (BINOP_VAL); }
  249. ;
  250. exp : CHR '(' exp ')'
  251. { write_exp_elt_opcode (UNOP_CHR); }
  252. ;
  253. exp : ODD '(' exp ')'
  254. { write_exp_elt_opcode (UNOP_ODD); }
  255. ;
  256. exp : TRUNC '(' exp ')'
  257. { write_exp_elt_opcode (UNOP_TRUNC); }
  258. ;
  259. exp : SIZE exp %prec UNARY
  260. { write_exp_elt_opcode (UNOP_SIZEOF); }
  261. ;
  262. exp : INC '(' exp ')'
  263. { write_exp_elt_opcode(UNOP_PREINCREMENT); }
  264. ;
  265. exp : INC '(' exp ',' exp ')'
  266. { write_exp_elt_opcode(BINOP_ASSIGN_MODIFY);
  267. write_exp_elt_opcode(BINOP_ADD);
  268. write_exp_elt_opcode(BINOP_ASSIGN_MODIFY); }
  269. ;
  270. exp : DEC '(' exp ')'
  271. { write_exp_elt_opcode(UNOP_PREDECREMENT);}
  272. ;
  273. exp : DEC '(' exp ',' exp ')'
  274. { write_exp_elt_opcode(BINOP_ASSIGN_MODIFY);
  275. write_exp_elt_opcode(BINOP_SUB);
  276. write_exp_elt_opcode(BINOP_ASSIGN_MODIFY); }
  277. ;
  278. exp : exp DOT NAME
  279. { write_exp_elt_opcode (STRUCTOP_STRUCT);
  280. write_exp_string ($3);
  281. write_exp_elt_opcode (STRUCTOP_STRUCT); }
  282. ;
  283. exp : set
  284. ;
  285. exp : exp IN set
  286. { error(&quot;Sets are not implemented.&quot;);}
  287. ;
  288. exp : INCL '(' exp ',' exp ')'
  289. { error(&quot;Sets are not implemented.&quot;);}
  290. ;
  291. exp : EXCL '(' exp ',' exp ')'
  292. { error(&quot;Sets are not implemented.&quot;);}
  293. ;
  294. set : '{' arglist '}'
  295. { error(&quot;Sets are not implemented.&quot;);}
  296. | type '{' arglist '}'
  297. { error(&quot;Sets are not implemented.&quot;);}
  298. ;
  299. /* Modula-2 array subscript notation [a,b,c...] */
  300. exp : exp '['
  301. /* This function just saves the number of arguments
  302. that follow in the list. It is *not* specific to
  303. function types */
  304. { start_arglist(); }
  305. non_empty_arglist ']' %prec DOT
  306. { write_exp_elt_opcode (MULTI_SUBSCRIPT);
  307. write_exp_elt_longcst ((LONGEST) end_arglist());
  308. write_exp_elt_opcode (MULTI_SUBSCRIPT); }
  309. ;
  310. exp : exp '('
  311. /* This is to save the value of arglist_len
  312. being accumulated by an outer function call. */
  313. { start_arglist (); }
  314. arglist ')' %prec DOT
  315. { write_exp_elt_opcode (OP_FUNCALL);
  316. write_exp_elt_longcst ((LONGEST) end_arglist ());
  317. write_exp_elt_opcode (OP_FUNCALL); }
  318. ;
  319. arglist :
  320. ;
  321. arglist : exp
  322. { arglist_len = 1; }
  323. ;
  324. arglist : arglist ',' exp %prec ABOVE_COMMA
  325. { arglist_len++; }
  326. ;
  327. non_empty_arglist
  328. : exp
  329. { arglist_len = 1; }
  330. ;
  331. non_empty_arglist
  332. : non_empty_arglist ',' exp %prec ABOVE_COMMA
  333. { arglist_len++; }
  334. ;
  335. /* GDB construct */
  336. exp : '{' type '}' exp %prec UNARY
  337. { write_exp_elt_opcode (UNOP_MEMVAL);
  338. write_exp_elt_type ($2);
  339. write_exp_elt_opcode (UNOP_MEMVAL); }
  340. ;
  341. exp : type '(' exp ')' %prec UNARY
  342. { write_exp_elt_opcode (UNOP_CAST);
  343. write_exp_elt_type ($1);
  344. write_exp_elt_opcode (UNOP_CAST); }
  345. ;
  346. exp : '(' exp ')'
  347. { }
  348. ;
  349. /* Binary operators in order of decreasing precedence. Note that some
  350. of these operators are overloaded! (ie. sets) */
  351. /* GDB construct */
  352. exp : exp '@' exp
  353. { write_exp_elt_opcode (BINOP_REPEAT); }
  354. ;
  355. exp : exp '*' exp
  356. { write_exp_elt_opcode (BINOP_MUL); }
  357. ;
  358. exp : exp '/' exp
  359. { write_exp_elt_opcode (BINOP_DIV); }
  360. ;
  361. exp : exp DIV exp
  362. { write_exp_elt_opcode (BINOP_INTDIV); }
  363. ;
  364. exp : exp MOD exp
  365. { write_exp_elt_opcode (BINOP_REM); }
  366. ;
  367. exp : exp '+' exp
  368. { write_exp_elt_opcode (BINOP_ADD); }
  369. ;
  370. exp : exp '-' exp
  371. { write_exp_elt_opcode (BINOP_SUB); }
  372. ;
  373. exp : exp '=' exp
  374. { write_exp_elt_opcode (BINOP_EQUAL); }
  375. ;
  376. exp : exp NOTEQUAL exp
  377. { write_exp_elt_opcode (BINOP_NOTEQUAL); }
  378. | exp '#' exp
  379. { write_exp_elt_opcode (BINOP_NOTEQUAL); }
  380. ;
  381. exp : exp LEQ exp
  382. { write_exp_elt_opcode (BINOP_LEQ); }
  383. ;
  384. exp : exp GEQ exp
  385. { write_exp_elt_opcode (BINOP_GEQ); }
  386. ;
  387. exp : exp '&lt;' exp
  388. { write_exp_elt_opcode (BINOP_LESS); }
  389. ;
  390. exp : exp '&gt;' exp
  391. { write_exp_elt_opcode (BINOP_GTR); }
  392. ;
  393. exp : exp LOGICAL_AND exp
  394. { write_exp_elt_opcode (BINOP_LOGICAL_AND); }
  395. ;
  396. exp : exp OROR exp
  397. { write_exp_elt_opcode (BINOP_LOGICAL_OR); }
  398. ;
  399. exp : exp ASSIGN exp
  400. { write_exp_elt_opcode (BINOP_ASSIGN); }
  401. ;
  402. /* Constants */
  403. exp : M2_TRUE
  404. { write_exp_elt_opcode (OP_BOOL);
  405. write_exp_elt_longcst ((LONGEST) $1);
  406. write_exp_elt_opcode (OP_BOOL); }
  407. ;
  408. exp : M2_FALSE
  409. { write_exp_elt_opcode (OP_BOOL);
  410. write_exp_elt_longcst ((LONGEST) $1);
  411. write_exp_elt_opcode (OP_BOOL); }
  412. ;
  413. exp : INT
  414. { write_exp_elt_opcode (OP_LONG);
  415. write_exp_elt_type (builtin_type_m2_int);
  416. write_exp_elt_longcst ((LONGEST) $1);
  417. write_exp_elt_opcode (OP_LONG); }
  418. ;
  419. exp : UINT
  420. {
  421. write_exp_elt_opcode (OP_LONG);
  422. write_exp_elt_type (builtin_type_m2_card);
  423. write_exp_elt_longcst ((LONGEST) $1);
  424. write_exp_elt_opcode (OP_LONG);
  425. }
  426. ;
  427. exp : CHAR
  428. { write_exp_elt_opcode (OP_LONG);
  429. write_exp_elt_type (builtin_type_m2_char);
  430. write_exp_elt_longcst ((LONGEST) $1);
  431. write_exp_elt_opcode (OP_LONG); }
  432. ;
  433. exp : FLOAT
  434. { write_exp_elt_opcode (OP_DOUBLE);
  435. write_exp_elt_type (builtin_type_m2_real);
  436. write_exp_elt_dblcst ($1);
  437. write_exp_elt_opcode (OP_DOUBLE); }
  438. ;
  439. exp : variable
  440. ;
  441. exp : SIZE '(' type ')' %prec UNARY
  442. { write_exp_elt_opcode (OP_LONG);
  443. write_exp_elt_type (builtin_type_int);
  444. write_exp_elt_longcst ((LONGEST) TYPE_LENGTH ($3));
  445. write_exp_elt_opcode (OP_LONG); }
  446. ;
  447. exp : STRING
  448. { write_exp_elt_opcode (OP_M2_STRING);
  449. write_exp_string ($1);
  450. write_exp_elt_opcode (OP_M2_STRING); }
  451. ;
  452. /* This will be used for extensions later. Like adding modules. */
  453. block : fblock
  454. { $$ = SYMBOL_BLOCK_VALUE($1); }
  455. ;
  456. fblock : BLOCKNAME
  457. { struct symbol *sym
  458. = lookup_symbol (copy_name ($1), expression_context_block,
  459. VAR_DOMAIN, 0, NULL);
  460. $$ = sym;}
  461. ;
  462. /* GDB scope operator */
  463. fblock : block COLONCOLON BLOCKNAME
  464. { struct symbol *tem
  465. = lookup_symbol (copy_name ($3), $1,
  466. VAR_DOMAIN, 0, NULL);
  467. if (!tem || SYMBOL_CLASS (tem) != LOC_BLOCK)
  468. error (&quot;No function \&quot;%s\&quot; in specified context.&quot;,
  469. copy_name ($3));
  470. $$ = tem;
  471. }
  472. ;
  473. /* Useful for assigning to PROCEDURE variables */
  474. variable: fblock
  475. { write_exp_elt_opcode(OP_VAR_VALUE);
  476. write_exp_elt_block (NULL);
  477. write_exp_elt_sym ($1);
  478. write_exp_elt_opcode (OP_VAR_VALUE); }
  479. ;
  480. /* GDB internal ($foo) variable */
  481. variable: INTERNAL_VAR
  482. ;
  483. /* GDB scope operator */
  484. variable: block COLONCOLON NAME
  485. { struct symbol *sym;
  486. sym = lookup_symbol (copy_name ($3), $1,
  487. VAR_DOMAIN, 0, NULL);
  488. if (sym == 0)
  489. error (&quot;No symbol \&quot;%s\&quot; in specified context.&quot;,
  490. copy_name ($3));
  491. write_exp_elt_opcode (OP_VAR_VALUE);
  492. /* block_found is set by lookup_symbol. */
  493. write_exp_elt_block (block_found);
  494. write_exp_elt_sym (sym);
  495. write_exp_elt_opcode (OP_VAR_VALUE); }
  496. ;
  497. /* Base case for variables. */
  498. variable: NAME
  499. { struct symbol *sym;
  500. int is_a_field_of_this;
  501. sym = lookup_symbol (copy_name ($1),
  502. expression_context_block,
  503. VAR_DOMAIN,
  504. &amp;is_a_field_of_this,
  505. NULL);
  506. if (sym)
  507. {
  508. if (symbol_read_needs_frame (sym))
  509. {
  510. if (innermost_block == 0 ||
  511. contained_in (block_found,
  512. innermost_block))
  513. innermost_block = block_found;
  514. }
  515. write_exp_elt_opcode (OP_VAR_VALUE);
  516. /* We want to use the selected frame, not
  517. another more inner frame which happens to
  518. be in the same block. */
  519. write_exp_elt_block (NULL);
  520. write_exp_elt_sym (sym);
  521. write_exp_elt_opcode (OP_VAR_VALUE);
  522. }
  523. else
  524. {
  525. struct minimal_symbol *msymbol;
  526. char *arg = copy_name ($1);
  527. msymbol =
  528. lookup_minimal_symbol (arg, NULL, NULL);
  529. if (msymbol != NULL)
  530. {
  531. write_exp_msymbol
  532. (msymbol,
  533. lookup_function_type (builtin_type_int),
  534. builtin_type_int);
  535. }
  536. else if (!have_full_symbols () &amp;&amp; !have_partial_symbols ())
  537. error (&quot;No symbol table is loaded. Use the \&quot;symbol-file\&quot; command.&quot;);
  538. else
  539. error (&quot;No symbol \&quot;%s\&quot; in current context.&quot;,
  540. copy_name ($1));
  541. }
  542. }
  543. ;
  544. type
  545. : TYPENAME
  546. { $$ = lookup_typename (copy_name ($1),
  547. expression_context_block, 0); }
  548. ;
  549. %%
  550. #if 0 /* FIXME! */
  551. int
  552. overflow(a,b)
  553. long a,b;
  554. {
  555. return (MAX_OF_TYPE(builtin_type_m2_int) - b) &lt; a;
  556. }
  557. int
  558. uoverflow(a,b)
  559. unsigned long a,b;
  560. {
  561. return (MAX_OF_TYPE(builtin_type_m2_card) - b) &lt; a;
  562. }
  563. #endif /* FIXME */
  564. /* Take care of parsing a number (anything that starts with a digit).
  565. Set yylval and return the token type; update lexptr.
  566. LEN is the number of characters in it. */
  567. /*** Needs some error checking for the float case ***/
  568. static int
  569. parse_number (olen)
  570. int olen;
  571. {
  572. char *p = lexptr;
  573. LONGEST n = 0;
  574. LONGEST prevn = 0;
  575. int c,i,ischar=0;
  576. int base = input_radix;
  577. int len = olen;
  578. int unsigned_p = number_sign == 1 ? 1 : 0;
  579. if(p[len-1] == 'H')
  580. {
  581. base = 16;
  582. len--;
  583. }
  584. else if(p[len-1] == 'C' || p[len-1] == 'B')
  585. {
  586. base = 8;
  587. ischar = p[len-1] == 'C';
  588. len--;
  589. }
  590. /* Scan the number */
  591. for (c = 0; c &lt; len; c++)
  592. {
  593. if (p[c] == '.' &amp;&amp; base == 10)
  594. {
  595. /* It's a float since it contains a point. */
  596. yylval.dval = atof (p);
  597. lexptr += len;
  598. return FLOAT;
  599. }
  600. if (p[c] == '.' &amp;&amp; base != 10)
  601. error(&quot;Floating point numbers must be base 10.&quot;);
  602. if (base == 10 &amp;&amp; (p[c] &lt; '0' || p[c] &gt; '9'))
  603. error(&quot;Invalid digit \'%c\' in number.&quot;,p[c]);
  604. }
  605. while (len-- &gt; 0)
  606. {
  607. c = *p++;
  608. n *= base;
  609. if( base == 8 &amp;&amp; (c == '8' || c == '9'))
  610. error(&quot;Invalid digit \'%c\' in octal number.&quot;,c);
  611. if (c &gt;= '0' &amp;&amp; c &lt;= '9')
  612. i = c - '0';
  613. else
  614. {
  615. if (base == 16 &amp;&amp; c &gt;= 'A' &amp;&amp; c &lt;= 'F')
  616. i = c - 'A' + 10;
  617. else
  618. return ERROR;
  619. }
  620. n+=i;
  621. if(i &gt;= base)
  622. return ERROR;
  623. if(!unsigned_p &amp;&amp; number_sign == 1 &amp;&amp; (prevn &gt;= n))
  624. unsigned_p=1; /* Try something unsigned */
  625. /* Don't do the range check if n==i and i==0, since that special
  626. case will give an overflow error. */
  627. if(RANGE_CHECK &amp;&amp; n!=i &amp;&amp; i)
  628. {
  629. if((unsigned_p &amp;&amp; (unsigned)prevn &gt;= (unsigned)n) ||
  630. ((!unsigned_p &amp;&amp; number_sign==-1) &amp;&amp; -prevn &lt;= -n))
  631. range_error(&quot;Overflow on numeric constant.&quot;);
  632. }
  633. prevn=n;
  634. }
  635. lexptr = p;
  636. if(*p == 'B' || *p == 'C' || *p == 'H')
  637. lexptr++; /* Advance past B,C or H */
  638. if (ischar)
  639. {
  640. yylval.ulval = n;
  641. return CHAR;
  642. }
  643. else if ( unsigned_p &amp;&amp; number_sign == 1)
  644. {
  645. yylval.ulval = n;
  646. return UINT;
  647. }
  648. else if((unsigned_p &amp;&amp; (n&lt;0))) {
  649. range_error(&quot;Overflow on numeric constant -- number too large.&quot;);
  650. /* But, this can return if range_check == range_warn. */
  651. }
  652. yylval.lval = n;
  653. return INT;
  654. }
  655. /* Some tokens */
  656. static struct
  657. {
  658. char name[2];
  659. int token;
  660. } tokentab2[] =
  661. {
  662. { {'&lt;', '&gt;'}, NOTEQUAL },
  663. { {':', '='}, ASSIGN },
  664. { {'&lt;', '='}, LEQ },
  665. { {'&gt;', '='}, GEQ },
  666. { {':', ':'}, COLONCOLON },
  667. };
  668. /* Some specific keywords */
  669. struct keyword {
  670. char keyw[10];
  671. int token;
  672. };
  673. static struct keyword keytab[] =
  674. {
  675. {&quot;OR&quot; , OROR },
  676. {&quot;IN&quot;, IN },/* Note space after IN */
  677. {&quot;AND&quot;, LOGICAL_AND},
  678. {&quot;ABS&quot;, ABS },
  679. {&quot;CHR&quot;, CHR },
  680. {&quot;DEC&quot;, DEC },
  681. {&quot;NOT&quot;, NOT },
  682. {&quot;DIV&quot;, DIV },
  683. {&quot;INC&quot;, INC },
  684. {&quot;MAX&quot;, MAX_FUNC },
  685. {&quot;MIN&quot;, MIN_FUNC },
  686. {&quot;MOD&quot;, MOD },
  687. {&quot;ODD&quot;, ODD },
  688. {&quot;CAP&quot;, CAP },
  689. {&quot;ORD&quot;, ORD },
  690. {&quot;VAL&quot;, VAL },
  691. {&quot;EXCL&quot;, EXCL },
  692. {&quot;HIGH&quot;, HIGH },
  693. {&quot;INCL&quot;, INCL },
  694. {&quot;SIZE&quot;, SIZE },
  695. {&quot;FLOAT&quot;, FLOAT_FUNC },
  696. {&quot;TRUNC&quot;, TRUNC },
  697. };
  698. /* Read one token, getting characters through lexptr. */
  699. /* This is where we will check to make sure that the language and the operators used are
  700. compatible */
  701. static int
  702. yylex ()
  703. {
  704. int c;
  705. int namelen;
  706. int i;
  707. char *tokstart;
  708. char quote;
  709. retry:
  710. prev_lexptr = lexptr;
  711. tokstart = lexptr;
  712. /* See if it is a special token of length 2 */
  713. for( i = 0 ; i &lt; (int) (sizeof tokentab2 / sizeof tokentab2[0]) ; i++)
  714. if(DEPRECATED_STREQN(tokentab2[i].name, tokstart, 2))
  715. {
  716. lexptr += 2;
  717. return tokentab2[i].token;
  718. }
  719. switch (c = *tokstart)
  720. {
  721. case 0:
  722. return 0;
  723. case ' ':
  724. case '\t':
  725. case '\n':
  726. lexptr++;
  727. goto retry;
  728. case '(':
  729. paren_depth++;
  730. lexptr++;
  731. return c;
  732. case ')':
  733. if (paren_depth == 0)
  734. return 0;
  735. paren_depth--;
  736. lexptr++;
  737. return c;
  738. case ',':
  739. if (comma_terminates &amp;&amp; paren_depth == 0)
  740. return 0;
  741. lexptr++;
  742. return c;
  743. case '.':
  744. /* Might be a floating point number. */
  745. if (lexptr[1] &gt;= '0' &amp;&amp; lexptr[1] &lt;= '9')
  746. break; /* Falls into number code. */
  747. else
  748. {
  749. lexptr++;
  750. return DOT;
  751. }
  752. /* These are character tokens that appear as-is in the YACC grammar */
  753. case '+':
  754. case '-':
  755. case '*':
  756. case '/':
  757. case '^':
  758. case '&lt;':
  759. case '&gt;':
  760. case '[':
  761. case ']':
  762. case '=':
  763. case '{':
  764. case '}':
  765. case '#':
  766. case '@':
  767. case '~':
  768. case '&amp;':
  769. lexptr++;
  770. return c;
  771. case '\'' :
  772. case '&quot;':
  773. quote = c;
  774. for (namelen = 1; (c = tokstart[namelen]) != quote &amp;&amp; c != '\0'; namelen++)
  775. if (c == '\\')
  776. {
  777. c = tokstart[++namelen];
  778. if (c &gt;= '0' &amp;&amp; c &lt;= '9')
  779. {
  780. c = tokstart[++namelen];
  781. if (c &gt;= '0' &amp;&amp; c &lt;= '9')
  782. c = tokstart[++namelen];
  783. }
  784. }
  785. if(c != quote)
  786. error(&quot;Unterminated string or character constant.&quot;);
  787. yylval.sval.ptr = tokstart + 1;
  788. yylval.sval.length = namelen - 1;
  789. lexptr += namelen + 1;
  790. if(namelen == 2) /* Single character */
  791. {
  792. yylval.ulval = tokstart[1];
  793. return CHAR;
  794. }
  795. else
  796. return STRING;
  797. }
  798. /* Is it a number? */
  799. /* Note: We have already dealt with the case of the token '.'.
  800. See case '.' above. */
  801. if ((c &gt;= '0' &amp;&amp; c &lt;= '9'))
  802. {
  803. /* It's a number. */
  804. int got_dot = 0, got_e = 0;
  805. char *p = tokstart;
  806. int toktype;
  807. for (++p ;; ++p)
  808. {
  809. if (!got_e &amp;&amp; (*p == 'e' || *p == 'E'))
  810. got_dot = got_e = 1;
  811. else if (!got_dot &amp;&amp; *p == '.')
  812. got_dot = 1;
  813. else if (got_e &amp;&amp; (p[-1] == 'e' || p[-1] == 'E')
  814. &amp;&amp; (*p == '-' || *p == '+'))
  815. /* This is the sign of the exponent, not the end of the
  816. number. */
  817. continue;
  818. else if ((*p &lt; '0' || *p &gt; '9') &amp;&amp;
  819. (*p &lt; 'A' || *p &gt; 'F') &amp;&amp;
  820. (*p != 'H')) /* Modula-2 hexadecimal number */
  821. break;
  822. }
  823. toktype = parse_number (p - tokstart);
  824. if (toktype == ERROR)
  825. {
  826. char *err_copy = (char *) alloca (p - tokstart + 1);
  827. memcpy (err_copy, tokstart, p - tokstart);
  828. err_copy[p - tokstart] = 0;
  829. error (&quot;Invalid number \&quot;%s\&quot;.&quot;, err_copy);
  830. }
  831. lexptr = p;
  832. return toktype;
  833. }
  834. if (!(c == '_' || c == '$'
  835. || (c &gt;= 'a' &amp;&amp; c &lt;= 'z') || (c &gt;= 'A' &amp;&amp; c &lt;= 'Z')))
  836. /* We must have come across a bad character (e.g. ';'). */
  837. error (&quot;Invalid character '%c' in expression.&quot;, c);
  838. /* It's a name. See how long it is. */
  839. namelen = 0;
  840. for (c = tokstart[namelen];
  841. (c == '_' || c == '$' || (c &gt;= '0' &amp;&amp; c &lt;= '9')
  842. || (c &gt;= 'a' &amp;&amp; c &lt;= 'z') || (c &gt;= 'A' &amp;&amp; c &lt;= 'Z'));
  843. c = tokstart[++namelen])
  844. ;
  845. /* The token &quot;if&quot; terminates the expression and is NOT
  846. removed from the input stream. */
  847. if (namelen == 2 &amp;&amp; tokstart[0] == 'i' &amp;&amp; tokstart[1] == 'f')
  848. {
  849. return 0;
  850. }
  851. lexptr += namelen;
  852. /* Lookup special keywords */
  853. for(i = 0 ; i &lt; (int) (sizeof(keytab) / sizeof(keytab[0])) ; i++)
  854. if(namelen == strlen(keytab[i].keyw) &amp;&amp; DEPRECATED_STREQN(tokstart,keytab[i].keyw,namelen))
  855. return keytab[i].token;
  856. yylval.sval.ptr = tokstart;
  857. yylval.sval.length = namelen;
  858. if (*tokstart == '$')
  859. {
  860. write_dollar_variable (yylval.sval);
  861. return INTERNAL_VAR;
  862. }
  863. /* Use token-type BLOCKNAME for symbols that happen to be defined as
  864. functions. If this is not so, then ...
  865. Use token-type TYPENAME for symbols that happen to be defined
  866. currently as names of types; NAME for other symbols.
  867. The caller is not constrained to care about the distinction. */
  868. {
  869. char *tmp = copy_name (yylval.sval);
  870. struct symbol *sym;
  871. if (lookup_partial_symtab (tmp))
  872. return BLOCKNAME;
  873. sym = lookup_symbol (tmp, expression_context_block,
  874. VAR_DOMAIN, 0, NULL);
  875. if (sym &amp;&amp; SYMBOL_CLASS (sym) == LOC_BLOCK)
  876. return BLOCKNAME;
  877. if (lookup_typename (copy_name (yylval.sval), expression_context_block, 1))
  878. return TYPENAME;
  879. if(sym)
  880. {
  881. switch(sym-&gt;aclass)
  882. {
  883. case LOC_STATIC:
  884. case LOC_REGISTER:
  885. case LOC_ARG:
  886. case LOC_REF_ARG:
  887. case LOC_REGPARM:
  888. case LOC_REGPARM_ADDR:
  889. case LOC_LOCAL:
  890. case LOC_LOCAL_ARG:
  891. case LOC_BASEREG:
  892. case LOC_BASEREG_ARG:
  893. case LOC_CONST:
  894. case LOC_CONST_BYTES:
  895. case LOC_OPTIMIZED_OUT:
  896. case LOC_COMPUTED:
  897. case LOC_COMPUTED_ARG:
  898. return NAME;
  899. case LOC_TYPEDEF:
  900. return TYPENAME;
  901. case LOC_BLOCK:
  902. return BLOCKNAME;
  903. case LOC_UNDEF:
  904. error(&quot;internal: Undefined class in m2lex()&quot;);
  905. case LOC_LABEL:
  906. case LOC_UNRESOLVED:
  907. error(&quot;internal: Unforseen case in m2lex()&quot;);
  908. default:
  909. error (&quot;unhandled token in m2lex()&quot;);
  910. break;
  911. }
  912. }
  913. else
  914. {
  915. /* Built-in BOOLEAN type. This is sort of a hack. */
  916. if(DEPRECATED_STREQN(tokstart,&quot;TRUE&quot;,4))
  917. {
  918. yylval.ulval = 1;
  919. return M2_TRUE;
  920. }
  921. else if(DEPRECATED_STREQN(tokstart,&quot;FALSE&quot;,5))
  922. {
  923. yylval.ulval = 0;
  924. return M2_FALSE;
  925. }
  926. }
  927. /* Must be another type of name... */
  928. return NAME;
  929. }
  930. }
  931. #if 0 /* Unused */
  932. static char *
  933. make_qualname(mod,ident)
  934. char *mod, *ident;
  935. {
  936. char *new = malloc(strlen(mod)+strlen(ident)+2);
  937. strcpy(new,mod);
  938. strcat(new,&quot;.&quot;);
  939. strcat(new,ident);
  940. return new;
  941. }
  942. #endif /* 0 */
  943. void
  944. yyerror (msg)
  945. char *msg;
  946. {
  947. if (prev_lexptr)
  948. lexptr = prev_lexptr;
  949. error (&quot;A %s in expression, near `%s'.&quot;, (msg ? msg : &quot;error&quot;), lexptr);
  950. }
  951. </pre>
  952. <hr />
  953. </body></html>