declar.g 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767
  1. /*
  2. * (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
  3. * See the copyright notice in the ACK home directory, in the file "Copyright".
  4. */
  5. /* $Id$ */
  6. /* DECLARATION SYNTAX PARSER */
  7. {
  8. #include "lint.h"
  9. #include "dbsymtab.h"
  10. #include <alloc.h>
  11. #include "nobitfield.h"
  12. #include "debug.h"
  13. #include <flt_arith.h>
  14. #include "arith.h"
  15. #include "LLlex.h"
  16. #include "label.h"
  17. #include "code.h"
  18. #include "idf.h"
  19. #include "type.h"
  20. #include "proto.h"
  21. #include "struct.h"
  22. #include "field.h"
  23. #include "decspecs.h"
  24. #include "def.h"
  25. #include "declar.h"
  26. #include "label.h"
  27. #include "expr.h"
  28. #include "sizes.h"
  29. #include "level.h"
  30. #ifdef LINT
  31. #include "l_lint.h"
  32. #endif /* LINT */
  33. extern char options[];
  34. }
  35. /* 3.5 */
  36. declaration
  37. {struct decspecs Ds;}
  38. :
  39. {Ds = null_decspecs;}
  40. decl_specifiers(&Ds)
  41. init_declarator_list(&Ds)?
  42. ';'
  43. ;
  44. /* A `decl_specifiers' describes a sequence of a storage_class_specifier,
  45. an unsigned_specifier, a size_specifier and a simple type_specifier,
  46. which may occur in arbitrary order and each of which may be absent;
  47. at least one of them must be present, however, since the totally
  48. empty case has already be dealt with in `external_definition'.
  49. This means that something like:
  50. unsigned extern int short xx;
  51. is perfectly legal C.
  52. On top of that, multiple occurrences of storage_class_specifiers,
  53. unsigned_specifiers and size_specifiers are errors, but a second
  54. type_specifier should end the decl_specifiers and be treated as
  55. the name to be declared.
  56. Such a language is not easily expressed in a grammar; enumeration
  57. of the permutations is unattractive. We solve the problem by
  58. having a regular grammar for the "soft" items, handling the single
  59. occurrence of the type_specifier in the grammar (we have no choice),
  60. collecting all data in a `struct decspecs' and turning that data
  61. structure into what we want.
  62. The existence of declarations like
  63. short typedef yepp;
  64. makes all hope of writing a specific grammar for typedefs illusory.
  65. */
  66. /* Accept a single declaration specifier. Then accept zero or more
  67. declaration specifiers. There can be a conflict on both
  68. TYPE_IDENTIFIER and IDENTIFIER.
  69. The following rule is used:
  70. When we see a TYPE_IDENTIFIER, we accept it if no type-specifier was
  71. given, and it is not directly followed by an identifier. If a
  72. type-specifier was given, it is taken as the identifier being
  73. declared. If it is followed by an identifier, we assume that an
  74. error has been made, (e.g. unsigned typedeffed_int x;) and that
  75. this will be detected later on.
  76. When we see an IDENTIFIER, directly followed by another IDENTIFIER,
  77. we assume that a typing mistake has been made, and we accept it as
  78. an erroneous type-identifier.
  79. */
  80. decl_specifiers /* non-empty */ (register struct decspecs *ds;)
  81. /* Reads a non-empty decl_specifiers and fills the struct
  82. decspecs *ds.
  83. */
  84. :
  85. single_decl_specifier(ds)
  86. [ %while( (DOT==TYPE_IDENTIFIER
  87. && ds->ds_size == 0
  88. && ds->ds_unsigned == 0
  89. && ds->ds_type == (struct type *)0)
  90. || AHEAD == IDENTIFIER) /* always an error */
  91. single_decl_specifier(ds)
  92. ]*
  93. {do_decspecs(ds);}
  94. ;
  95. single_decl_specifier /* non_empty */ (register struct decspecs *ds;)
  96. :
  97. [ AUTO | STATIC | EXTERN | TYPEDEF | REGISTER ]
  98. { if (ds->ds_sc_given)
  99. error("repeated storage class specifier");
  100. ds->ds_sc_given = 1;
  101. ds->ds_sc = DOT;
  102. }
  103. |
  104. VOLATILE
  105. { if (ds->ds_typequal & TQ_VOLATILE)
  106. error("repeated type qualifier");
  107. ds->ds_typequal |= TQ_VOLATILE;
  108. }
  109. |
  110. CONST
  111. { if (ds->ds_typequal & TQ_CONST)
  112. error("repeated type qualifier");
  113. ds->ds_typequal |= TQ_CONST;
  114. }
  115. |
  116. [ SHORT | LONG ]
  117. { if (ds->ds_size)
  118. error("repeated size specifier");
  119. ds->ds_size = DOT;
  120. }
  121. |
  122. [ SIGNED | UNSIGNED ]
  123. { if (ds->ds_unsigned != 0)
  124. error("repeated sign specifier");
  125. ds->ds_unsigned = DOT;
  126. }
  127. |
  128. [ VOID | CHAR | INT | FLOAT | DOUBLE ]
  129. {
  130. idf2type(dot.tk_idf, &ds->ds_type);
  131. ds->ds_typedef = 0;
  132. }
  133. |
  134. %default TYPE_IDENTIFIER
  135. {
  136. idf2type(dot.tk_idf, &ds->ds_type);
  137. ds->ds_typedef = 1;
  138. }
  139. |
  140. %erroneous
  141. IDENTIFIER
  142. {
  143. error("%s is not a type identifier", dot.tk_idf->id_text);
  144. ds->ds_type = error_type;
  145. if (dot.tk_idf->id_def) {
  146. dot.tk_idf->id_def->df_type = error_type;
  147. dot.tk_idf->id_def->df_sc = TYPEDEF;
  148. }
  149. }
  150. |
  151. %illegal
  152. IDENTIFIER
  153. |
  154. struct_or_union_specifier(&ds->ds_type)
  155. |
  156. enum_specifier(&ds->ds_type)
  157. ;
  158. /* 3.5.2 */
  159. type_specifier(struct type **tpp;)
  160. /* Used in struct/union declarations and in casts; only the
  161. type is relevant.
  162. */
  163. {struct decspecs Ds; Ds = null_decspecs;}
  164. :
  165. decl_specifiers(&Ds)
  166. {
  167. if (Ds.ds_sc_given)
  168. error("storage class ignored");
  169. if (Ds.ds_sc == REGISTER)
  170. error("register ignored");
  171. }
  172. {*tpp = Ds.ds_type;}
  173. ;
  174. /* 3.5 */
  175. init_declarator_list(struct decspecs *ds;):
  176. init_declarator(ds)
  177. [ ',' init_declarator(ds) ]*
  178. ;
  179. init_declarator(register struct decspecs *ds;)
  180. {
  181. struct declarator Dc;
  182. }
  183. :
  184. {
  185. Dc = null_declarator;
  186. }
  187. [
  188. declarator(&Dc)
  189. {
  190. reject_params(&Dc);
  191. declare_idf(ds, &Dc, level);
  192. #ifdef LINT
  193. lint_declare_idf(Dc.dc_idf, ds->ds_sc);
  194. #endif /* LINT */
  195. }
  196. [
  197. initializer(Dc.dc_idf, ds->ds_sc)
  198. |
  199. { code_declaration(Dc.dc_idf, (struct expr *) 0, level, ds->ds_sc); }
  200. ]
  201. ]
  202. {
  203. #ifdef LINT
  204. add_auto(Dc.dc_idf);
  205. #endif /* LINT */
  206. remove_declarator(&Dc);
  207. }
  208. ;
  209. /* 3.5.7: initializer */
  210. initializer(struct idf *idf; int sc;)
  211. {
  212. struct expr *expr = (struct expr *) 0;
  213. int fund = idf->id_def->df_type->tp_fund;
  214. int autoagg = (level >= L_LOCAL
  215. && sc != STATIC
  216. && ( fund == STRUCT
  217. || fund == UNION
  218. || fund == ARRAY));
  219. int globalflag = level == L_GLOBAL
  220. || (level >= L_LOCAL && sc == STATIC);
  221. }
  222. :
  223. { if (idf->id_def->df_type->tp_fund == FUNCTION) {
  224. error("illegal initialization of function");
  225. idf->id_def->df_type->tp_fund = ERRONEOUS;
  226. }
  227. if (level == L_FORMAL2)
  228. error("illegal initialization of formal parameter");
  229. }
  230. '='
  231. {
  232. if (AHEAD != '{' && AHEAD != STRING ) autoagg = 0;
  233. #ifdef LINT
  234. lint_statement();
  235. #endif /* LINT */
  236. if (globalflag) {
  237. struct expr ex;
  238. code_declaration(idf, &ex, level, sc);
  239. }
  240. else if (autoagg)
  241. loc_init((struct expr *) 0, idf);
  242. }
  243. initial_value((globalflag || autoagg) ?
  244. &(idf->id_def->df_type)
  245. : (struct type **)0,
  246. &expr)
  247. { if (! globalflag) {
  248. if (idf->id_def->df_type->tp_fund == FUNCTION) {
  249. free_expression(expr);
  250. expr = 0;
  251. }
  252. #ifdef DEBUG
  253. print_expr("initializer-expression", expr);
  254. #endif /* DEBUG */
  255. #ifdef LINT
  256. change_state(idf, SET);
  257. #endif /* LINT */
  258. #ifdef DBSYMTAB
  259. if (options['g'] && level >= L_LOCAL && expr) {
  260. db_line(expr->ex_file, (unsigned) expr->ex_line);
  261. }
  262. #endif /* DBSYMTAB */
  263. if (autoagg)
  264. loc_init((struct expr *) 0, idf);
  265. else code_declaration(idf, expr, level, sc);
  266. }
  267. #ifdef DBSYMTAB
  268. if (options['g'] && globalflag) {
  269. stb_string(idf->id_def, sc, idf->id_text);
  270. }
  271. #endif /* DBSYMTAB */
  272. idf_initialized(idf);
  273. }
  274. ;
  275. /*
  276. Functions yielding pointers to functions must be declared as, e.g.,
  277. int (*hehe(par1, par2))() char *par1, *par2; {}
  278. Since the function heading is read as a normal declarator,
  279. we just include the (formal) parameter list in the declarator
  280. description list dc.
  281. */
  282. /* 3.5.4 */
  283. declarator(register struct declarator *dc;)
  284. { struct formal *fm = NO_PARAMS;
  285. struct proto *pl = NO_PROTO;
  286. arith count;
  287. int qual;
  288. }
  289. :
  290. primary_declarator(dc)
  291. [/*%while(1)*/
  292. '('
  293. [ %if (DOT != IDENTIFIER)
  294. parameter_type_list(&pl)
  295. |
  296. formal_list(&fm)
  297. |
  298. /* empty */
  299. ]
  300. ')'
  301. { add_decl_unary(dc, FUNCTION, 0, (arith)0, fm, pl);
  302. fm = NO_PARAMS;
  303. }
  304. |
  305. arrayer(&count)
  306. {add_decl_unary(dc, ARRAY, 0, count, NO_PARAMS, NO_PROTO);}
  307. ]*
  308. |
  309. pointer(&qual) declarator(dc)
  310. {add_decl_unary(dc, POINTER, qual, (arith)0, NO_PARAMS, NO_PROTO);}
  311. ;
  312. primary_declarator(register struct declarator *dc;) :
  313. identifier(&dc->dc_idf)
  314. |
  315. '(' declarator(dc) ')'
  316. ;
  317. arrayer(arith *sizep;)
  318. { struct expr *expr; }
  319. :
  320. '['
  321. { *sizep = (arith)-1; }
  322. [
  323. constant_expression(&expr)
  324. {
  325. check_array_subscript(expr);
  326. *sizep = expr->VL_VALUE;
  327. free_expression(expr);
  328. }
  329. ]?
  330. ']'
  331. ;
  332. formal_list (struct formal **fmp;)
  333. :
  334. formal(fmp) [ %persistent ',' formal(fmp) ]*
  335. ;
  336. formal(struct formal **fmp;)
  337. {struct idf *idf; }
  338. :
  339. identifier(&idf)
  340. {
  341. register struct formal *new = new_formal();
  342. new->fm_idf = idf;
  343. new->next = *fmp;
  344. *fmp = new;
  345. if (idf->id_def && idf->id_def->df_sc == TYPEDEF) {
  346. error("typedef name %s may not be redeclared as a parameter", idf->id_text);
  347. }
  348. }
  349. ;
  350. /* Change 2 */
  351. enum_specifier(register struct type **tpp;)
  352. {
  353. struct idf *idf;
  354. arith l = (arith)0;
  355. }
  356. :
  357. {if (*tpp) error("multiple types in declaration");}
  358. ENUM
  359. [
  360. {declare_struct(ENUM, (struct idf *) 0, tpp);}
  361. enumerator_pack(*tpp, &l)
  362. |
  363. identifier(&idf)
  364. [
  365. {declare_struct(ENUM, idf, tpp);}
  366. enumerator_pack(*tpp, &l)
  367. {
  368. #ifdef DBSYMTAB
  369. if (options['g']) {
  370. stb_tag(idf->id_tag, idf->id_text);
  371. }
  372. #endif /*DBSYMTAB */
  373. }
  374. |
  375. {apply_struct(ENUM, idf, tpp);}
  376. /* empty */
  377. ]
  378. ]
  379. ;
  380. enumerator_pack(register struct type *tp; arith *lp;) :
  381. '{'
  382. enumerator(tp, lp)
  383. [%while (AHEAD != '}')
  384. ','
  385. enumerator(tp, lp)
  386. ]*
  387. [
  388. ',' {warning("unexpected trailing comma in enumerator pack");}
  389. ]?
  390. '}'
  391. {tp->tp_size = int_size;}
  392. /* fancy implementations that put small enums in 1 byte
  393. or so should start here.
  394. */
  395. ;
  396. enumerator(struct type *tp; arith *lp;)
  397. {
  398. struct idf *idf;
  399. struct expr *expr;
  400. }
  401. :
  402. identifier(&idf)
  403. [
  404. '='
  405. constant_expression(&expr)
  406. {
  407. *lp = expr->VL_VALUE;
  408. free_expression(expr);
  409. }
  410. ]?
  411. {declare_enum(tp, idf, (*lp)++);}
  412. ;
  413. /* 8.5 */
  414. struct_or_union_specifier(register struct type **tpp;)
  415. {
  416. int fund;
  417. struct idf *idfX;
  418. register struct idf *idf;
  419. }
  420. :
  421. {if (*tpp) error("multiple types in declaration");}
  422. [ STRUCT | UNION ]
  423. {fund = DOT;}
  424. [
  425. {
  426. declare_struct(fund, (struct idf *)0, tpp);
  427. }
  428. struct_declaration_pack(*tpp)
  429. |
  430. identifier(&idfX) { idf = idfX; }
  431. [
  432. {
  433. declare_struct(fund, idf, tpp);
  434. (idf->id_tag->tg_busy)++;
  435. }
  436. struct_declaration_pack(*tpp)
  437. {
  438. (idf->id_tag->tg_busy)--;
  439. #ifdef DBSYMTAB
  440. if (options['g']) {
  441. stb_tag(idf->id_tag, idf->id_text);
  442. }
  443. #endif /*DBSYMTAB */
  444. }
  445. |
  446. {
  447. /* a ';' means an empty declaration (probably)
  448. * this means that we have to declare a new
  449. * structure. (yegh)
  450. */
  451. if (DOT == ';' &&
  452. ( !idf->id_tag ||
  453. idf->id_tag->tg_level != level ||
  454. idf->id_tag->tg_type->tp_size < 0
  455. )) declare_struct(fund, idf, tpp);
  456. else apply_struct(fund, idf, tpp);
  457. }
  458. /* empty */
  459. ]
  460. ]
  461. ;
  462. struct_declaration_pack(register struct type *stp;)
  463. {
  464. struct sdef **sdefp = &stp->tp_sdef;
  465. arith size = (arith)0;
  466. }
  467. :
  468. /* The size is only filled in after the whole struct has
  469. been read, to prevent recursive definitions.
  470. */
  471. '{'
  472. struct_declaration(stp, &sdefp, &size)+
  473. '}'
  474. {stp->tp_size = align(size, stp->tp_align);
  475. completed(stp);
  476. }
  477. ;
  478. struct_declaration(struct type *stp; struct sdef ***sdefpp; arith *szp;)
  479. {struct type *tp;}
  480. :
  481. type_specifier(&tp) struct_declarator_list(tp, stp, sdefpp, szp) ';'
  482. ;
  483. struct_declarator_list(struct type *tp; struct type *stp;
  484. struct sdef ***sdefpp; arith *szp;)
  485. :
  486. struct_declarator(tp, stp, sdefpp, szp)
  487. [ ',' struct_declarator(tp, stp, sdefpp, szp) ]*
  488. ;
  489. struct_declarator(struct type *tp; struct type *stp;
  490. struct sdef ***sdefpp; arith *szp;)
  491. {
  492. struct declarator Dc;
  493. struct field *fd = 0;
  494. }
  495. :
  496. {
  497. Dc = null_declarator;
  498. }
  499. [
  500. declarator(&Dc)
  501. {reject_params(&Dc);}
  502. bit_expression(&fd)?
  503. |
  504. {Dc.dc_idf = gen_idf();}
  505. bit_expression(&fd)
  506. ]
  507. {add_sel(stp, declare_type(tp, &Dc), Dc.dc_idf, sdefpp, szp, fd);}
  508. {remove_declarator(&Dc);}
  509. ;
  510. bit_expression(struct field **fd;)
  511. { struct expr *expr; }
  512. :
  513. {
  514. *fd = new_field();
  515. }
  516. ':'
  517. constant_expression(&expr)
  518. {
  519. (*fd)->fd_width = expr->VL_VALUE;
  520. free_expression(expr);
  521. #ifdef NOBITFIELD
  522. error("bitfields are not implemented");
  523. #endif /* NOBITFIELD */
  524. }
  525. ;
  526. /* 8.7 */
  527. cast(struct type **tpp;)
  528. {struct declarator Dc;}
  529. :
  530. {Dc = null_declarator;}
  531. '('
  532. type_specifier(tpp)
  533. abstract_declarator(&Dc)
  534. ')'
  535. {*tpp = declare_type(*tpp, &Dc);}
  536. {remove_declarator(&Dc);}
  537. ;
  538. /* This code is an abject copy of that of 'declarator', for lack of
  539. a two-level grammar.
  540. */
  541. abstract_declarator(register struct declarator *dc;)
  542. { struct proto *pl = NO_PROTO;
  543. arith count;
  544. int qual;
  545. }
  546. :
  547. primary_abstract_declarator(dc)
  548. [
  549. '('
  550. [
  551. parameter_type_list(&pl)
  552. |
  553. /* empty */
  554. ]
  555. ')'
  556. {add_decl_unary(dc, FUNCTION, 0, (arith)0, NO_PARAMS, pl);
  557. if (pl) remove_proto_idfs(pl);
  558. }
  559. |
  560. arrayer(&count)
  561. {add_decl_unary(dc, ARRAY, 0, count, NO_PARAMS, NO_PROTO);}
  562. ]*
  563. |
  564. pointer(&qual) abstract_declarator(dc)
  565. {add_decl_unary(dc, POINTER, qual, (arith)0, NO_PARAMS, NO_PROTO);}
  566. ;
  567. %first first_of_parameter_type_list, parameter_type_list;
  568. primary_abstract_declarator(struct declarator *dc;)
  569. :
  570. [%if (AHEAD == ')' || first_of_parameter_type_list(AHEAD))
  571. /* empty */
  572. |
  573. '(' abstract_declarator(dc) ')'
  574. ]
  575. ;
  576. parameter_type_list(struct proto **plp;)
  577. { int save_level; }
  578. :
  579. { if (level > L_PROTO) {
  580. save_level = level;
  581. level = L_PROTO;
  582. } else level--;
  583. }
  584. parameter_decl_list(plp)
  585. [
  586. ',' ELLIPSIS
  587. { register struct proto *new = new_proto();
  588. new->next = *plp;
  589. new->pl_flag = PL_ELLIPSIS;
  590. *plp = new;
  591. }
  592. ]?
  593. { check_for_void(*plp);
  594. if (level == L_PROTO)
  595. level = save_level;
  596. else level++;
  597. }
  598. ;
  599. parameter_decl_list(struct proto **plp;)
  600. :
  601. parameter_decl(plp)
  602. [ %while (AHEAD != ELLIPSIS)
  603. %persistent
  604. ',' parameter_decl(plp)
  605. ]*
  606. ;
  607. parameter_decl(struct proto **plp;)
  608. { register struct proto *new = new_proto();
  609. struct declarator Dc;
  610. struct decspecs Ds;
  611. }
  612. :
  613. { Dc = null_declarator;
  614. Ds = null_decspecs;
  615. }
  616. decl_specifiers(&Ds)
  617. parameter_declarator(&Dc)
  618. { add_proto(new, &Ds, &Dc, level);
  619. new->next = *plp;
  620. *plp = new;
  621. remove_declarator(&Dc);
  622. }
  623. ;
  624. /* This is weird. Due to the LR structure of the ANSI C grammar
  625. we have to duplicate the actions of 'declarator' and
  626. 'abstract_declarator'. Calling these separately, as in
  627. parameter_decl:
  628. decl_specifiers
  629. [
  630. declarator
  631. |
  632. abstract_declarator
  633. ]
  634. gives us a conflict on the terminals '(' and '*'. E.i. on
  635. some input, it is impossible to decide which rule we take.
  636. Combining the two declarators into one common declarator
  637. is out of the question, since this results in an empty
  638. string for the non-terminal 'declarator'.
  639. So we combine the two only for the use of parameter_decl,
  640. since this is the only place where they don't give
  641. conflicts. However, this makes the grammar messy.
  642. */
  643. parameter_declarator(register struct declarator *dc;)
  644. { struct formal *fm = NO_PARAMS;
  645. struct proto *pl = NO_PROTO;
  646. arith count;
  647. int qual;
  648. }
  649. :
  650. primary_parameter_declarator(dc)
  651. [
  652. '('
  653. [ %if (DOT != IDENTIFIER)
  654. parameter_type_list(&pl)
  655. |
  656. formal_list(&fm)
  657. |
  658. /* empty */
  659. ]
  660. ')'
  661. { add_decl_unary(dc, FUNCTION, 0, (arith)0, fm, pl);
  662. reject_params(dc);
  663. }
  664. |
  665. arrayer(&count)
  666. {add_decl_unary(dc, ARRAY, 0, count, NO_PARAMS, NO_PROTO);}
  667. ]*
  668. |
  669. pointer(&qual) parameter_declarator(dc)
  670. {add_decl_unary(dc, POINTER, qual, (arith)0, NO_PARAMS, NO_PROTO);}
  671. ;
  672. primary_parameter_declarator(register struct declarator *dc;)
  673. :
  674. [%if (AHEAD == ')' || first_of_parameter_type_list(AHEAD)
  675. && (AHEAD != IDENTIFIER))
  676. /* empty */
  677. |
  678. identifier(&dc->dc_idf)
  679. |
  680. '(' parameter_declarator(dc) ')'
  681. ]
  682. ;
  683. pointer(int *qual;)
  684. :
  685. '*' type_qualifier_list(qual)
  686. ;
  687. /* Type qualifiers may come in three flavours:
  688. volatile, const, const volatile.
  689. These all have different semantic properties:
  690. volatile:
  691. means that the object can be modified
  692. without prior knowledge of the implementation.
  693. const:
  694. means that the object can not be modified; thus
  695. it's illegal to use this as a l-value.
  696. const volatile:
  697. means that the object can be modified without
  698. prior knowledge of the implementation, but may
  699. not be used as a l-value.
  700. */
  701. /* 3.5.4 */
  702. type_qualifier_list(int *qual;)
  703. :
  704. { *qual = 0; }
  705. [
  706. VOLATILE
  707. { if (*qual & TQ_VOLATILE)
  708. error("repeated type qualifier");
  709. *qual |= TQ_VOLATILE;
  710. }
  711. |
  712. CONST
  713. { if (*qual & TQ_CONST)
  714. error("repeated type qualifier");
  715. *qual |= TQ_CONST;
  716. }
  717. ]*
  718. ;
  719. empty:
  720. ;