declar.g 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761
  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. IDENTIFIER
  141. {
  142. error("%s is not a type identifier", dot.tk_idf->id_text);
  143. ds->ds_type = error_type;
  144. if (dot.tk_idf->id_def) {
  145. dot.tk_idf->id_def->df_type = error_type;
  146. dot.tk_idf->id_def->df_sc = TYPEDEF;
  147. }
  148. }
  149. |
  150. struct_or_union_specifier(&ds->ds_type)
  151. |
  152. enum_specifier(&ds->ds_type)
  153. ;
  154. /* 3.5.2 */
  155. type_specifier(struct type **tpp;)
  156. /* Used in struct/union declarations and in casts; only the
  157. type is relevant.
  158. */
  159. {struct decspecs Ds; Ds = null_decspecs;}
  160. :
  161. decl_specifiers(&Ds)
  162. {
  163. if (Ds.ds_sc_given)
  164. error("storage class ignored");
  165. if (Ds.ds_sc == REGISTER)
  166. error("register ignored");
  167. }
  168. {*tpp = Ds.ds_type;}
  169. ;
  170. /* 3.5 */
  171. init_declarator_list(struct decspecs *ds;):
  172. init_declarator(ds)
  173. [ ',' init_declarator(ds) ]*
  174. ;
  175. init_declarator(register struct decspecs *ds;)
  176. {
  177. struct declarator Dc;
  178. }
  179. :
  180. {
  181. Dc = null_declarator;
  182. }
  183. [
  184. declarator(&Dc)
  185. {
  186. reject_params(&Dc);
  187. declare_idf(ds, &Dc, level);
  188. #ifdef LINT
  189. lint_declare_idf(Dc.dc_idf, ds->ds_sc);
  190. #endif /* LINT */
  191. }
  192. [
  193. initializer(Dc.dc_idf, ds->ds_sc)
  194. |
  195. { code_declaration(Dc.dc_idf, (struct expr *) 0, level, ds->ds_sc); }
  196. ]
  197. ]
  198. {
  199. #ifdef LINT
  200. add_auto(Dc.dc_idf);
  201. #endif /* LINT */
  202. remove_declarator(&Dc);
  203. }
  204. ;
  205. /* 3.5.7: initializer */
  206. initializer(struct idf *idf; int sc;)
  207. {
  208. struct expr *expr = (struct expr *) 0;
  209. int fund = idf->id_def->df_type->tp_fund;
  210. int autoagg = (level >= L_LOCAL
  211. && sc != STATIC
  212. && ( fund == STRUCT
  213. || fund == UNION
  214. || fund == ARRAY));
  215. int globalflag = level == L_GLOBAL
  216. || (level >= L_LOCAL && sc == STATIC);
  217. }
  218. :
  219. { if (idf->id_def->df_type->tp_fund == FUNCTION) {
  220. error("illegal initialization of function");
  221. idf->id_def->df_type->tp_fund = ERRONEOUS;
  222. }
  223. if (level == L_FORMAL2)
  224. error("illegal initialization of formal parameter");
  225. }
  226. '='
  227. {
  228. if (AHEAD != '{' && AHEAD != STRING ) autoagg = 0;
  229. #ifdef LINT
  230. lint_statement();
  231. #endif /* LINT */
  232. if (globalflag) {
  233. struct expr ex;
  234. code_declaration(idf, &ex, level, sc);
  235. }
  236. else if (autoagg)
  237. loc_init((struct expr *) 0, idf);
  238. }
  239. initial_value((globalflag || autoagg) ?
  240. &(idf->id_def->df_type)
  241. : (struct type **)0,
  242. &expr)
  243. { if (! globalflag) {
  244. if (idf->id_def->df_type->tp_fund == FUNCTION) {
  245. free_expression(expr);
  246. expr = 0;
  247. }
  248. #ifdef DEBUG
  249. print_expr("initializer-expression", expr);
  250. #endif /* DEBUG */
  251. #ifdef LINT
  252. change_state(idf, SET);
  253. #endif /* LINT */
  254. #ifdef DBSYMTAB
  255. if (options['g'] && level >= L_LOCAL && expr) {
  256. db_line(expr->ex_file, (unsigned) expr->ex_line);
  257. }
  258. #endif /* DBSYMTAB */
  259. if (autoagg)
  260. loc_init((struct expr *) 0, idf);
  261. else code_declaration(idf, expr, level, sc);
  262. }
  263. #ifdef DBSYMTAB
  264. if (options['g'] && globalflag) {
  265. stb_string(idf->id_def, sc, idf->id_text);
  266. }
  267. #endif /* DBSYMTAB */
  268. idf_initialized(idf);
  269. }
  270. ;
  271. /*
  272. Functions yielding pointers to functions must be declared as, e.g.,
  273. int (*hehe(par1, par2))() char *par1, *par2; {}
  274. Since the function heading is read as a normal declarator,
  275. we just include the (formal) parameter list in the declarator
  276. description list dc.
  277. */
  278. /* 3.5.4 */
  279. declarator(register struct declarator *dc;)
  280. { struct formal *fm = NO_PARAMS;
  281. struct proto *pl = NO_PROTO;
  282. arith count;
  283. int qual;
  284. }
  285. :
  286. primary_declarator(dc)
  287. [/*%while(1)*/
  288. '('
  289. [ %if (DOT != IDENTIFIER)
  290. parameter_type_list(&pl)
  291. |
  292. formal_list(&fm)
  293. |
  294. /* empty */
  295. ]
  296. ')'
  297. { add_decl_unary(dc, FUNCTION, 0, (arith)0, fm, pl);
  298. fm = NO_PARAMS;
  299. }
  300. |
  301. arrayer(&count)
  302. {add_decl_unary(dc, ARRAY, 0, count, NO_PARAMS, NO_PROTO);}
  303. ]*
  304. |
  305. pointer(&qual) declarator(dc)
  306. {add_decl_unary(dc, POINTER, qual, (arith)0, NO_PARAMS, NO_PROTO);}
  307. ;
  308. primary_declarator(register struct declarator *dc;) :
  309. identifier(&dc->dc_idf)
  310. |
  311. '(' declarator(dc) ')'
  312. ;
  313. arrayer(arith *sizep;)
  314. { struct expr *expr; }
  315. :
  316. '['
  317. { *sizep = (arith)-1; }
  318. [
  319. constant_expression(&expr)
  320. {
  321. check_array_subscript(expr);
  322. *sizep = expr->VL_VALUE;
  323. free_expression(expr);
  324. }
  325. ]?
  326. ']'
  327. ;
  328. formal_list (struct formal **fmp;)
  329. :
  330. formal(fmp) [ %persistent ',' formal(fmp) ]*
  331. ;
  332. formal(struct formal **fmp;)
  333. {struct idf *idf; }
  334. :
  335. identifier(&idf)
  336. {
  337. register struct formal *new = new_formal();
  338. new->fm_idf = idf;
  339. new->next = *fmp;
  340. *fmp = new;
  341. if (idf->id_def && idf->id_def->df_sc == TYPEDEF) {
  342. error("typedef name %s may not be redeclared as a parameter", idf->id_text);
  343. }
  344. }
  345. ;
  346. /* Change 2 */
  347. enum_specifier(register struct type **tpp;)
  348. {
  349. struct idf *idf;
  350. arith l = (arith)0;
  351. }
  352. :
  353. {if (*tpp) error("multiple types in declaration");}
  354. ENUM
  355. [
  356. {declare_struct(ENUM, (struct idf *) 0, tpp);}
  357. enumerator_pack(*tpp, &l)
  358. |
  359. identifier(&idf)
  360. [
  361. {declare_struct(ENUM, idf, tpp);}
  362. enumerator_pack(*tpp, &l)
  363. {
  364. #ifdef DBSYMTAB
  365. if (options['g']) {
  366. stb_tag(idf->id_tag, idf->id_text);
  367. }
  368. #endif /*DBSYMTAB */
  369. }
  370. |
  371. {apply_struct(ENUM, idf, tpp);}
  372. /* empty */
  373. ]
  374. ]
  375. ;
  376. enumerator_pack(register struct type *tp; arith *lp;) :
  377. '{'
  378. enumerator(tp, lp)
  379. [%while (AHEAD != '}')
  380. ','
  381. enumerator(tp, lp)
  382. ]*
  383. [
  384. ',' {warning("unexpected trailing comma in enumerator pack");}
  385. ]?
  386. '}'
  387. {tp->tp_size = int_size;}
  388. /* fancy implementations that put small enums in 1 byte
  389. or so should start here.
  390. */
  391. ;
  392. enumerator(struct type *tp; arith *lp;)
  393. {
  394. struct idf *idf;
  395. struct expr *expr;
  396. }
  397. :
  398. identifier(&idf)
  399. [
  400. '='
  401. constant_expression(&expr)
  402. {
  403. *lp = expr->VL_VALUE;
  404. free_expression(expr);
  405. }
  406. ]?
  407. {declare_enum(tp, idf, (*lp)++);}
  408. ;
  409. /* 8.5 */
  410. struct_or_union_specifier(register struct type **tpp;)
  411. {
  412. int fund;
  413. struct idf *idfX;
  414. register struct idf *idf;
  415. }
  416. :
  417. {if (*tpp) error("multiple types in declaration");}
  418. [ STRUCT | UNION ]
  419. {fund = DOT;}
  420. [
  421. {
  422. declare_struct(fund, (struct idf *)0, tpp);
  423. }
  424. struct_declaration_pack(*tpp)
  425. |
  426. identifier(&idfX) { idf = idfX; }
  427. [
  428. {
  429. declare_struct(fund, idf, tpp);
  430. (idf->id_tag->tg_busy)++;
  431. }
  432. struct_declaration_pack(*tpp)
  433. {
  434. (idf->id_tag->tg_busy)--;
  435. #ifdef DBSYMTAB
  436. if (options['g']) {
  437. stb_tag(idf->id_tag, idf->id_text);
  438. }
  439. #endif /*DBSYMTAB */
  440. }
  441. |
  442. {
  443. /* a ';' means an empty declaration (probably)
  444. * this means that we have to declare a new
  445. * structure. (yegh)
  446. */
  447. if (DOT == ';' &&
  448. ( !idf->id_tag ||
  449. idf->id_tag->tg_level != level ||
  450. idf->id_tag->tg_type->tp_size < 0
  451. )) declare_struct(fund, idf, tpp);
  452. else apply_struct(fund, idf, tpp);
  453. }
  454. /* empty */
  455. ]
  456. ]
  457. ;
  458. struct_declaration_pack(register struct type *stp;)
  459. {
  460. struct sdef **sdefp = &stp->tp_sdef;
  461. arith size = (arith)0;
  462. }
  463. :
  464. /* The size is only filled in after the whole struct has
  465. been read, to prevent recursive definitions.
  466. */
  467. '{'
  468. struct_declaration(stp, &sdefp, &size)+
  469. '}'
  470. {stp->tp_size = align(size, stp->tp_align);
  471. completed(stp);
  472. }
  473. ;
  474. struct_declaration(struct type *stp; struct sdef ***sdefpp; arith *szp;)
  475. {struct type *tp;}
  476. :
  477. type_specifier(&tp) struct_declarator_list(tp, stp, sdefpp, szp) ';'
  478. ;
  479. struct_declarator_list(struct type *tp; struct type *stp;
  480. struct sdef ***sdefpp; arith *szp;)
  481. :
  482. struct_declarator(tp, stp, sdefpp, szp)
  483. [ ',' struct_declarator(tp, stp, sdefpp, szp) ]*
  484. ;
  485. struct_declarator(struct type *tp; struct type *stp;
  486. struct sdef ***sdefpp; arith *szp;)
  487. {
  488. struct declarator Dc;
  489. struct field *fd = 0;
  490. }
  491. :
  492. {
  493. Dc = null_declarator;
  494. }
  495. [
  496. declarator(&Dc)
  497. {reject_params(&Dc);}
  498. bit_expression(&fd)?
  499. |
  500. {Dc.dc_idf = gen_idf();}
  501. bit_expression(&fd)
  502. ]
  503. {add_sel(stp, declare_type(tp, &Dc), Dc.dc_idf, sdefpp, szp, fd);}
  504. {remove_declarator(&Dc);}
  505. ;
  506. bit_expression(struct field **fd;)
  507. { struct expr *expr; }
  508. :
  509. {
  510. *fd = new_field();
  511. }
  512. ':'
  513. constant_expression(&expr)
  514. {
  515. (*fd)->fd_width = expr->VL_VALUE;
  516. free_expression(expr);
  517. #ifdef NOBITFIELD
  518. error("bitfields are not implemented");
  519. #endif /* NOBITFIELD */
  520. }
  521. ;
  522. /* 8.7 */
  523. cast(struct type **tpp;)
  524. {struct declarator Dc;}
  525. :
  526. {Dc = null_declarator;}
  527. '('
  528. type_specifier(tpp)
  529. abstract_declarator(&Dc)
  530. ')'
  531. {*tpp = declare_type(*tpp, &Dc);}
  532. {remove_declarator(&Dc);}
  533. ;
  534. /* This code is an abject copy of that of 'declarator', for lack of
  535. a two-level grammar.
  536. */
  537. abstract_declarator(register struct declarator *dc;)
  538. { struct proto *pl = NO_PROTO;
  539. arith count;
  540. int qual;
  541. }
  542. :
  543. primary_abstract_declarator(dc)
  544. [
  545. '('
  546. [
  547. parameter_type_list(&pl)
  548. |
  549. /* empty */
  550. ]
  551. ')'
  552. {add_decl_unary(dc, FUNCTION, 0, (arith)0, NO_PARAMS, pl);}
  553. |
  554. arrayer(&count)
  555. {add_decl_unary(dc, ARRAY, 0, count, NO_PARAMS, NO_PROTO);}
  556. ]*
  557. |
  558. pointer(&qual) abstract_declarator(dc)
  559. {add_decl_unary(dc, POINTER, qual, (arith)0, NO_PARAMS, NO_PROTO);}
  560. ;
  561. %first first_of_parameter_type_list, parameter_type_list;
  562. primary_abstract_declarator(struct declarator *dc;)
  563. :
  564. [%if (AHEAD == ')' || first_of_parameter_type_list(AHEAD))
  565. /* empty */
  566. |
  567. '(' abstract_declarator(dc) ')'
  568. ]
  569. ;
  570. parameter_type_list(struct proto **plp;)
  571. { int save_level; }
  572. :
  573. { if (level > L_PROTO) {
  574. save_level = level;
  575. level = L_PROTO;
  576. } else level--;
  577. }
  578. parameter_decl_list(plp)
  579. [
  580. ',' ELLIPSIS
  581. { register struct proto *new = new_proto();
  582. new->next = *plp;
  583. new->pl_flag = PL_ELLIPSIS;
  584. *plp = new;
  585. }
  586. ]?
  587. { check_for_void(*plp);
  588. if (level == L_PROTO)
  589. level = save_level;
  590. else level++;
  591. }
  592. ;
  593. parameter_decl_list(struct proto **plp;)
  594. :
  595. parameter_decl(plp)
  596. [ %while (AHEAD != ELLIPSIS)
  597. %persistent
  598. ',' parameter_decl(plp)
  599. ]*
  600. ;
  601. parameter_decl(struct proto **plp;)
  602. { register struct proto *new = new_proto();
  603. struct declarator Dc;
  604. struct decspecs Ds;
  605. }
  606. :
  607. { Dc = null_declarator;
  608. Ds = null_decspecs;
  609. }
  610. decl_specifiers(&Ds)
  611. parameter_declarator(&Dc)
  612. { add_proto(new, &Ds, &Dc, level);
  613. new->next = *plp;
  614. *plp = new;
  615. remove_declarator(&Dc);
  616. }
  617. ;
  618. /* This is weird. Due to the LR structure of the ANSI C grammar
  619. we have to duplicate the actions of 'declarator' and
  620. 'abstract_declarator'. Calling these separately, as in
  621. parameter_decl:
  622. decl_specifiers
  623. [
  624. declarator
  625. |
  626. abstract_declarator
  627. ]
  628. gives us a conflict on the terminals '(' and '*'. E.i. on
  629. some input, it is impossible to decide which rule we take.
  630. Combining the two declarators into one common declarator
  631. is out of the question, since this results in an empty
  632. string for the non-terminal 'declarator'.
  633. So we combine the two only for the use of parameter_decl,
  634. since this is the only place where they don't give
  635. conflicts. However, this makes the grammar messy.
  636. */
  637. parameter_declarator(register struct declarator *dc;)
  638. { struct formal *fm = NO_PARAMS;
  639. struct proto *pl = NO_PROTO;
  640. arith count;
  641. int qual;
  642. }
  643. :
  644. primary_parameter_declarator(dc)
  645. [
  646. '('
  647. [ %if (DOT != IDENTIFIER)
  648. parameter_type_list(&pl)
  649. |
  650. formal_list(&fm)
  651. |
  652. /* empty */
  653. ]
  654. ')'
  655. { add_decl_unary(dc, FUNCTION, 0, (arith)0, fm, pl);
  656. reject_params(dc);
  657. }
  658. |
  659. arrayer(&count)
  660. {add_decl_unary(dc, ARRAY, 0, count, NO_PARAMS, NO_PROTO);}
  661. ]*
  662. |
  663. pointer(&qual) parameter_declarator(dc)
  664. {add_decl_unary(dc, POINTER, qual, (arith)0, NO_PARAMS, NO_PROTO);}
  665. ;
  666. primary_parameter_declarator(register struct declarator *dc;)
  667. :
  668. [%if (AHEAD == ')' || first_of_parameter_type_list(AHEAD)
  669. && (AHEAD != IDENTIFIER))
  670. /* empty */
  671. |
  672. identifier(&dc->dc_idf)
  673. |
  674. '(' parameter_declarator(dc) ')'
  675. ]
  676. ;
  677. pointer(int *qual;)
  678. :
  679. '*' type_qualifier_list(qual)
  680. ;
  681. /* Type qualifiers may come in three flavours:
  682. volatile, const, const volatile.
  683. These all have different semantic properties:
  684. volatile:
  685. means that the object can be modified
  686. without prior knowledge of the implementation.
  687. const:
  688. means that the object can not be modified; thus
  689. it's illegal to use this as a l-value.
  690. const volatile:
  691. means that the object can be modified without
  692. prior knowledge of the implementation, but may
  693. not be used as a l-value.
  694. */
  695. /* 3.5.4 */
  696. type_qualifier_list(int *qual;)
  697. :
  698. { *qual = 0; }
  699. [
  700. VOLATILE
  701. { if (*qual & TQ_VOLATILE)
  702. error("repeated type qualifier");
  703. *qual |= TQ_VOLATILE;
  704. }
  705. |
  706. CONST
  707. { if (*qual & TQ_CONST)
  708. error("repeated type qualifier");
  709. *qual |= TQ_CONST;
  710. }
  711. ]*
  712. ;
  713. empty:
  714. ;