declar.g 16 KB

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