home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / unix / volume14 / cdecl2 / part01 next >
Encoding:
Internet Message Format  |  1988-05-09  |  43.1 KB

  1. Subject:  v14i090:  New version of Cdecl, parse C declarations, Part01/02
  2. Newsgroups: comp.sources.unix,comp.lang.c
  3. Sender: sources
  4. Approved: rsalz@uunet.UU.NET
  5.  
  6. Submitted-by: cbosgd!pegasus!hansen (Tony Hansen)
  7. Posting-number: Volume 14, Issue 90
  8. Archive-name: cdecl2/part01
  9.  
  10. [  Cdecl converts C declarations to English and vice-versa.  That is,
  11.    if you say 
  12.     echo declare x as pointer to array of char | cdecl
  13.    you'll get
  14.     Warning: Unsupported in C -- Pointer to array of unspecified dimension
  15.     char (*x)[]
  16.   --r$  ]
  17.  
  18. This version comes with a test suite, many new options, and it also
  19. understands C++.
  20.  
  21. #! /bin/sh
  22. # This is a shell archive.  Remove anything before this line, then unpack
  23. # it by saving it into a file and typing "sh file".  To overwrite existing
  24. # files, type "sh file -c".  You can also feed this as standard input via
  25. # unshar, or by typing "sh <file", e.g..  If this archive is complete, you
  26. # will see the following message at the end:
  27. #        "End of archive 1 (of 2)."
  28. # Contents:  MANIFEST cdecl.1 cdgram.y cdlex.l makefile testset
  29. #   testset++
  30. # Wrapped by rsalz@fig.bbn.com on Mon May  9 20:40:46 1988
  31. PATH=/bin:/usr/bin:/usr/ucb ; export PATH
  32. if test -f 'MANIFEST' -a "${1}" != "-c" ; then 
  33.   echo shar: Will not clobber existing file \"'MANIFEST'\"
  34. else
  35. echo shar: Extracting \"'MANIFEST'\" \(362 characters\)
  36. sed "s/^X//" >'MANIFEST' <<'END_OF_FILE'
  37. X   File Name        Archive #    Description
  38. X-----------------------------------------------------------
  39. X MANIFEST                   1    This shipping list
  40. X cdecl.1                    1    
  41. X cdecl.c                    2    
  42. X cdgram.y                   1    
  43. X cdlex.l                    1    
  44. X makefile                   1    
  45. X testset                    1    
  46. X testset++                  1    
  47. END_OF_FILE
  48. if test 362 -ne `wc -c <'MANIFEST'`; then
  49.     echo shar: \"'MANIFEST'\" unpacked with wrong size!
  50. fi
  51. # end of 'MANIFEST'
  52. fi
  53. if test -f 'cdecl.1' -a "${1}" != "-c" ; then 
  54.   echo shar: Will not clobber existing file \"'cdecl.1'\"
  55. else
  56. echo shar: Extracting \"'cdecl.1'\" \(9817 characters\)
  57. sed "s/^X//" >'cdecl.1' <<'END_OF_FILE'
  58. X'\" @(#)cdecl.1    2.4 3/30/88
  59. X.TH CDECL 1
  60. X.SH NAME
  61. cdecl, c++decl \- Compose C and C++ type declarations
  62. X.SH SYNOPSIS
  63. X.B cdecl
  64. X[\-a | \-+ | \-p | \-r]
  65. X[\-cidDV]
  66. X.br
  67. X.RS .5i
  68. X.RI [[ files
  69. X\&...] |
  70. X.B explain
  71. X\&... |
  72. X.B declare
  73. X\&... |
  74. X.B cast
  75. X\&... |
  76. X.B set
  77. X\&... |
  78. X.B help
  79. X\&... |
  80. X.B ?
  81. X\&... ]
  82. X.RE
  83. X.br
  84. X.B c++decl
  85. X[\-a | \-+ | \-p | \-r]
  86. X[\-cidDV]
  87. X.br
  88. X.RS .5i
  89. X.RI [[ files
  90. X\&...] |
  91. X.B explain
  92. X\&... |
  93. X.B declare
  94. X\&... |
  95. X.B cast
  96. X\&... |
  97. X.B set
  98. X\&... |
  99. X.B help
  100. X\&... |
  101. X.B ?
  102. X\&... ]
  103. X.RE
  104. X.br
  105. X.B explain
  106. X\&...
  107. X.br
  108. X.B declare
  109. X\&...
  110. X.br
  111. X.B cast
  112. X\&...
  113. X.SH DESCRIPTION
  114. X.I Cdecl
  115. X(and
  116. X.I c++decl )
  117. is a program for encoding and decoding C (C++) type-declarations.
  118. The C language (the default for 
  119. X.I cdecl ,
  120. or with the
  121. X.B \-a
  122. option) is based on the (draft proposed) X3J11 ANSI
  123. Standard;
  124. optionally, the C language may be based on the pre-ANSI definition defined by
  125. Kernighan & Ritchie's 
  126. X.I "The C Programming Language"
  127. book (the
  128. X.B \-p
  129. option is used), or
  130. the C language defined by the Ritchie PDP-11 C compiler (the
  131. X.B \-r
  132. option is used).
  133. The C++ language (the default for
  134. X.I c++decl ,
  135. or with the
  136. X.B \-+
  137. option) is based on Stroustrup's
  138. X.IR "The C++ Programming Language" ,
  139. plus the version 2.0 additions to the language.
  140. X.PP
  141. X.I Cdecl
  142. reads the named files for statements in the language described below.
  143. A transformation is made from that language to C (C++) or pseudo-English.
  144. The results of this transformation are written on standard output.
  145. If no files are named, or a filename of ``\-'' is encountered, standard input
  146. will be read.
  147. If standard input is coming from a terminal, (or the
  148. X.B \-i
  149. option is used), a prompt will be written to the terminal before each line.
  150. If
  151. X.I cdecl
  152. is invoked as 
  153. X.IR explain ,
  154. X.IR declare
  155. or
  156. X.IR cast ,
  157. or the first argument is one of the commands discussed below, the argument
  158. list will be interpreted according to the grammar shown below instead of as
  159. file names.
  160. X.PP
  161. You can use
  162. X.I cdecl
  163. as you create a C program with an editor like vi(1) or emacs(1).
  164. You simply type in the pseudo-English version of the declaration and apply
  165. X.I cdecl
  166. as a filter to the line.
  167. X(In vi(1), type ``!!cdecl<cr>''.)
  168. X.PP
  169. If the 
  170. X.I "create program"
  171. option
  172. X.B \-c
  173. is used, the output will include semi-colons after variable declarations and
  174. curly brace pairs after function declarations.
  175. X.PP
  176. The
  177. X.B \-V
  178. option will print out the version numbers of the files used to create the
  179. process.
  180. If the source is compiled with debugging information turned on, the
  181. X.B \-d
  182. option will enable it to be output.
  183. If the source is compiled with YACC debugging information turned on, the
  184. X.B \-D
  185. option will enable it to be output.
  186. X.SH "COMMAND LANGUAGE"
  187. There are six statements in the language.
  188. The
  189. X.I "declare"
  190. statement composes a C type-declaration from a verbose description.
  191. The
  192. X.I "cast"
  193. statement composes a C type-cast as might appear in an expression.
  194. The
  195. X.I "explain"
  196. statement decodes a C type-declaration or cast, producing a verbose
  197. description.
  198. The
  199. X.I "help"
  200. X(or
  201. X.IR ? )
  202. statement provides a help message.
  203. The
  204. X.I "quit"
  205. X(or
  206. X.IR "exit" )
  207. statement (or the end of file) exits the program.
  208. The
  209. X.I "set"
  210. statement allows the command line options to be set interactively.
  211. Each statement is separated by a semi-colon or a newline.
  212. X.PP
  213. The following grammar describes the language.
  214. In the grammar, words in "<>" are non-terminals,
  215. bare lower-case words are terminals that stand for themselves.
  216. Bare upper-case words are other lexical tokens:
  217. NOTHING means the empty string;
  218. NAME means a C identifier;
  219. NUMBER means a string of decimal digits; and
  220. NL means the new-line or semi-colon characters.
  221. X.PP
  222. Some synonyms are permitted during a declaration:
  223. character \(-> char,
  224. constant \(-> const,
  225. enumeration \(-> enum,
  226. func \(-> function,
  227. integer \(-> int,
  228. ptr \(-> pointer,
  229. ref \(-> reference,
  230. ret \(-> returning,
  231. structure \(-> struct,
  232. and
  233. vector \(-> array.
  234. X.PP
  235. X.nf
  236. X.ft CW
  237. X.ta .5i 1.5i
  238. X    <program>    ::= NOTHING
  239. X        | <program> <stmt> NL
  240. X    <stmt>    ::= NOTHING
  241. X        | declare NAME as <adecl>
  242. X        | declare <adecl>
  243. X        | cast NAME into <adecl>
  244. X        | cast <adecl>
  245. X        | explain <optstorage> <ptrmodlist> <type> <cdecl>
  246. X        | explain <storage> <ptrmodlist> <cdecl>
  247. X        | explain ( <ptrmodlist> <type> <cast> ) optional-NAME
  248. X        | set <options>
  249. X        | help | ?
  250. X        | quit
  251. X        | exit
  252. X    <adecl>    ::= array of <adecl>
  253. X        | array NUMBER of <adecl>
  254. X        | function returning <adecl>
  255. X        | function ( <adecl-list> ) returning <adecl>
  256. X        | <ptrmodlist> pointer to <adecl>
  257. X        | <ptrmodlist> pointer to member of class NAME <adecl>
  258. X        | <ptrmodlist> reference to <adecl>
  259. X        | <ptrmodlist> <type>
  260. X    <cdecl>    ::= <cdecl1>
  261. X        | * <ptrmodlist> <cdecl>
  262. X        | NAME :: * <cdecl>
  263. X        | & <ptrmodlist> <cdecl>
  264. X    <cdecl1>    ::= <cdecl1> ( )
  265. X        | <cdecl1> ( <castlist> )
  266. X        | <cdecl1> [ ]
  267. X        | <cdecl1> [ NUMBER ]
  268. X        | ( <cdecl> )
  269. X        | NAME
  270. X    <cast>    ::= NOTHING
  271. X        | ( )
  272. X        | ( <cast> ) ( )
  273. X        | ( <cast> ) ( <castlist> )
  274. X        | ( <cast> )
  275. X        | NAME :: * <cast>
  276. X        | * <cast>
  277. X        | & <cast>
  278. X        | <cast> [ ]
  279. X        | <cast> [ NUMBER ]
  280. X    <type>    ::= <typename> | <modlist>
  281. X        | <modlist> <typename>
  282. X        | struct NAME | union NAME | enum NAME | class NAME
  283. X    <castlist>    ::= <castlist> , <castlist>
  284. X        | <ptrmodlist> <type> <cast>
  285. X        | <name>
  286. X    <adecllist>    ::= <adecllist> , <adecllist>
  287. X        | NOTHING
  288. X        | <name>
  289. X        | <adecl>
  290. X        | <name> as <adecl>
  291. X    <typename>    ::= int | char | double | float | void
  292. X    <modlist>    ::= <modifier> | <modlist> <modifier>
  293. X    <modifier>    ::= short | long | unsigned | signed | <ptrmod>
  294. X    <ptrmodlist>    ::= <ptrmod> <ptrmodlist> | NOTHING
  295. X    <ptrmod>    ::= const | volatile | noalias
  296. X    <storage>    ::= auto | extern | register | auto
  297. X    <optstorage>    ::= NOTHING | <storage>
  298. X    <options>    ::= NOTHING | <options>
  299. X        | create | nocreate
  300. X        | interactive | nointeractive
  301. X        | ritchie | preansi | ansi | cplusplus
  302. X        | debug | nodebug | yydebug | noyydebug
  303. X.ft P
  304. X.fi
  305. X.SH EXAMPLES
  306. X.de Ex
  307. X.    PP
  308. X.    RS .5i
  309. X..
  310. X.de Ee
  311. X.    RE
  312. X.    PP
  313. X..
  314. To declare an array of pointers to functions like malloc(3), do
  315. X.Ex
  316. declare fptab as array of pointer to function returning pointer to char
  317. X.Ee
  318. The result of this command is
  319. X.Ex
  320. char *(*fptab[])()
  321. X.Ee
  322. When you see this declaration in someone else's code, you
  323. can make sense out of it by doing
  324. X.Ex
  325. explain char *(*fptab[])()
  326. X.Ee
  327. The proper declaration for signal(2), ignoring function prototypes, is easily
  328. described in
  329. X.IR cdecl 's
  330. language:
  331. X.Ex
  332. declare signal as function returning pointer to function returning void
  333. X.Ee
  334. which produces
  335. X.Ex
  336. void (*signal())()
  337. X.Ee
  338. The function declaration that results has two sets of empty parentheses.
  339. The author of such a function might wonder where to put the parameters:
  340. X.Ex
  341. declare signal as function (arg1,arg2) returning pointer to function returning
  342. void
  343. X.Ee
  344. provides the following solution (when run with the
  345. X.I \-c
  346. option):
  347. X.Ex
  348. void (*signal(arg1,arg2))()
  349. X{
  350. X}
  351. X.Ee
  352. If we want to add in the function prototypes, the function prototype for a
  353. function such as _exit(2) would be declared with:
  354. X.Ex
  355. declare _exit as function (retvalue as int) returning void
  356. X.Ee
  357. giving
  358. X.Ex
  359. void _exit(int retvalue)
  360. X{
  361. X}
  362. X.Ee
  363. As a more complex example using function prototypes, signal(2) could be fully
  364. defined as:
  365. X.Ex
  366. declare signal as function(x as int, y as pointer to function(int)
  367. returning void) returning pointer to function(int) returning void
  368. X.Ee
  369. giving (with \-c)
  370. X.Ex
  371. void (*signal(int x, void (*y)(int )))(int )
  372. X{
  373. X}
  374. X.Ee
  375. X.I Cdecl
  376. can help figure out the where to put the "const" and "volatile" modifiers
  377. in declarations, thus
  378. X.Ex
  379. declare foo as pointer to const int
  380. X.Ee
  381. gives
  382. X.Ex
  383. const int *foo
  384. X.Ee
  385. while
  386. X.Ex
  387. declare foo as const pointer to int
  388. X.Ee
  389. gives
  390. X.Ex
  391. int * const foo
  392. X.Ee
  393. X.I C++decl
  394. can help with declaring references, thus
  395. X.Ex
  396. declare x as reference to pointer to character
  397. X.Ee
  398. gives
  399. X.Ex
  400. char *&x
  401. X.Ee
  402. X.I C++decl
  403. can help with pointers to member of classes, thus
  404. declaring a pointer to an integer member of a class X with
  405. X.Ex
  406. declare foo as pointer to member of class X int
  407. X.Ee
  408. gives
  409. X.Ex
  410. int X::*foo
  411. X.Ee
  412. and
  413. X.Ex
  414. declare foo as pointer to member of class X function (arg1, arg2) returning
  415. pointer to class Y
  416. X.Ee
  417. gives
  418. X.Ex
  419. class Y *(X::*foo)(arg1, arg2)
  420. X.Ee
  421. X.SH DIAGNOSTICS
  422. The declare, cast and explain statements try to point out constructions that
  423. are not supported in C.
  424. In some cases, a guess is made as to what was really intended.
  425. In these cases, the C result is a toy declaration whose semantics will work
  426. only in Algol-68.
  427. The list of unsupported C constructs is dependent on which version of the C
  428. language is being used (see the ANSI, pre-ANSI, and Ritchie options).
  429. The set of supported C++ constructs is a superset of the ANSI set, with the
  430. exception of the
  431. X.B noalias
  432. keyword.
  433. X.SH "SEE ALSO"
  434. X(draft proposed) ANSI National Standard X3J11
  435. X.sp
  436. X\(sc8.4 of the C Reference Manual within
  437. X.I "The C Programming Language"
  438. by B. Kernighan & D. Ritchie.
  439. X.sp
  440. X\(sc8 of the C++ Reference Manual within
  441. X.I "The C++ Programming Language"
  442. by B. Stroustrup.
  443. X.SH CAVEATS
  444. The pseudo-English syntax is excessively verbose.
  445. X.PP
  446. There is a wealth of semantic checking that isn't being done.
  447. X.PP
  448. X.I Cdecl's
  449. scope is intentionally small.
  450. It doesn't help you figure out initializations.
  451. It expects storage classes to be at the beginning of a declaration,
  452. followed by the the const, volatile and noalias modifiers, followed by the
  453. type of the variable.
  454. X.I Cdecl
  455. doesn't know anything about variable length argument lists.
  456. X(This includes the ``\f(CW,...\fP'' syntax.)
  457. X.PP
  458. X.I Cdecl
  459. thinks all the declarations you utter are going to be used as external
  460. definitions.
  461. Some declaration contexts in C allow more flexibility than this.
  462. An example of this is:
  463. X.Ex
  464. declare argv as array of array of char
  465. X.Ee
  466. where
  467. X.I cdecl
  468. responds with
  469. X.Ex
  470. X.nf
  471. Warning: Unsupported in C -- 'Inner array of unspecified size'
  472. X        (maybe you mean "array of pointer")
  473. char argv[][]
  474. X.fi
  475. X.Ee
  476. X.PP
  477. Tentative support for the
  478. X.I noalias
  479. keyword has been put in because it is in the current ANSI specifications.
  480. END_OF_FILE
  481. if test 9817 -ne `wc -c <'cdecl.1'`; then
  482.     echo shar: \"'cdecl.1'\" unpacked with wrong size!
  483. fi
  484. # end of 'cdecl.1'
  485. fi
  486. if test -f 'cdgram.y' -a "${1}" != "-c" ; then 
  487.   echo shar: Will not clobber existing file \"'cdgram.y'\"
  488. else
  489. echo shar: Extracting \"'cdgram.y'\" \(22746 characters\)
  490. sed "s/^X//" >'cdgram.y' <<'END_OF_FILE'
  491. X%{
  492. X/* Yacc grammar for ANSI and C++ cdecl. */
  493. X/* The output of this file is included */
  494. X/* into the C file cdecl.c. */
  495. char cdgramsccsid[] = "@(#)cdgram.y    2.2 3/30/88";
  496. X%}
  497. X
  498. X%union {
  499. X    char *dynstr;
  500. X    struct {
  501. X        char *left;
  502. X        char *right;
  503. X        char *type;
  504. X    } halves;
  505. X}
  506. X
  507. X%token ARRAY AS CAST COMMA DECLARE DOUBLECOLON EXPLAIN FUNCTION
  508. X%token HELP INTO OF MEMBER POINTER REFERENCE RETURNING SET TO
  509. X%token <dynstr> CHAR CLASS CONSTVOLATILE DOUBLE ENUM FLOAT INT LONG NAME
  510. X%token <dynstr> NUMBER SHORT SIGNED STRUCT UNION UNSIGNED VOID
  511. X%token <dynstr> AUTO EXTERN REGISTER STATIC
  512. X%type <dynstr> adecllist adims c_type cast castlist cdecl cdecl1 cdims
  513. X%type <dynstr> constvol_list ClassStruct mod_list mod_list1 modifier
  514. X%type <dynstr> opt_constvol_list optNAME opt_storage storage StrClaUniEnum
  515. X%type <dynstr> tname type
  516. X%type <halves> adecl
  517. X
  518. X%start prog
  519. X
  520. X%%
  521. prog        : /* empty */
  522. X        | prog stmt
  523. X            {
  524. X            prompt();
  525. X            prev = 0;
  526. X            }
  527. X        ;
  528. X
  529. stmt        : HELP NL
  530. X            {
  531. X            Debug((stderr, "stmt: help\n"));
  532. X            dohelp();
  533. X            }
  534. X
  535. X        | DECLARE NAME AS opt_storage adecl NL
  536. X            {
  537. X            Debug((stderr, "stmt: DECLARE NAME AS opt_storage adecl\n"));
  538. X            Debug((stderr, "\tNAME='%s'\n", $2));
  539. X            Debug((stderr, "\topt_storage='%s'\n", $4));
  540. X            Debug((stderr, "\tacdecl.left='%s'\n", $5.left));
  541. X            Debug((stderr, "\tacdecl.right='%s'\n", $5.right));
  542. X            Debug((stderr, "\tacdecl.type='%s'\n", $5.type));
  543. X            Debug((stderr, "\tprev = '%s'\n", visible(prev)));
  544. X            dodeclare($2, $4, $5.left, $5.right, $5.type);
  545. X            }
  546. X
  547. X        | DECLARE opt_storage adecl NL
  548. X            {
  549. X            Debug((stderr, "stmt: DECLARE opt_storage adecl\n"));
  550. X            Debug((stderr, "\topt_storage='%s'\n", $2));
  551. X            Debug((stderr, "\tacdecl.left='%s'\n", $3.left));
  552. X            Debug((stderr, "\tacdecl.right='%s'\n", $3.right));
  553. X            Debug((stderr, "\tacdecl.type='%s'\n", $3.type));
  554. X            Debug((stderr, "\tprev = '%s'\n", visible(prev)));
  555. X            dodeclare(NullCP, $2, $3.left, $3.right, $3.type);
  556. X            }
  557. X
  558. X        | CAST NAME INTO adecl NL
  559. X            {
  560. X            Debug((stderr, "stmt: CAST NAME AS adecl\n"));
  561. X            Debug((stderr, "\tNAME='%s'\n", $2));
  562. X            Debug((stderr, "\tacdecl.left='%s'\n", $4.left));
  563. X            Debug((stderr, "\tacdecl.right='%s'\n", $4.right));
  564. X            Debug((stderr, "\tacdecl.type='%s'\n", $4.type));
  565. X            docast($2, $4.left, $4.right, $4.type);
  566. X            }
  567. X
  568. X        | CAST adecl NL
  569. X            {
  570. X            Debug((stderr, "stmt: CAST adecl\n"));
  571. X            Debug((stderr, "\tacdecl.left='%s'\n", $2.left));
  572. X            Debug((stderr, "\tacdecl.right='%s'\n", $2.right));
  573. X            Debug((stderr, "\tacdecl.type='%s'\n", $2.type));
  574. X            docast(NullCP, $2.left, $2.right, $2.type);
  575. X            }
  576. X
  577. X        | EXPLAIN opt_storage opt_constvol_list type cdecl NL
  578. X            {
  579. X            Debug((stderr, "stmt: EXPLAIN opt_storage opt_constvol_list type cdecl\n"));
  580. X            Debug((stderr, "\topt_storage='%s'\n", $2));
  581. X            Debug((stderr, "\topt_constvol_list='%s'\n", $3));
  582. X            Debug((stderr, "\ttype='%s'\n", $4));
  583. X            Debug((stderr, "\tcdecl='%s'\n", $5));
  584. X            Debug((stderr, "\tprev = '%s'\n", visible(prev)));
  585. X            dodexplain($2, $3, $4, $5);
  586. X            }
  587. X
  588. X        | EXPLAIN storage opt_constvol_list cdecl NL
  589. X            {
  590. X            Debug((stderr, "stmt: EXPLAIN storage opt_constvol_list cdecl\n"));
  591. X            Debug((stderr, "\tstorage='%s'\n", $2));
  592. X            Debug((stderr, "\topt_constvol_list='%s'\n", $3));
  593. X            Debug((stderr, "\tcdecl='%s'\n", $4));
  594. X            Debug((stderr, "\tprev = '%s'\n", visible(prev)));
  595. X            dodexplain($2, $3, NullCP, $4);
  596. X            }
  597. X
  598. X        | EXPLAIN opt_storage constvol_list cdecl NL
  599. X            {
  600. X            Debug((stderr, "stmt: EXPLAIN opt_storage constvol_list cdecl\n"));
  601. X            Debug((stderr, "\topt_storage='%s'\n", $2));
  602. X            Debug((stderr, "\tconstvol_list='%s'\n", $3));
  603. X            Debug((stderr, "\tcdecl='%s'\n", $4));
  604. X            Debug((stderr, "\tprev = '%s'\n", visible(prev)));
  605. X            dodexplain($2, $3, NullCP, $4);
  606. X            }
  607. X
  608. X        | EXPLAIN '(' opt_constvol_list type cast ')' optNAME NL
  609. X            {
  610. X            Debug((stderr, "stmt: EXPLAIN ( opt_constvol_list type cast ) optNAME\n"));
  611. X            Debug((stderr, "\topt_constvol_list='%s'\n", $3));
  612. X            Debug((stderr, "\ttype='%s'\n", $4));
  613. X            Debug((stderr, "\tcast='%s'\n", $5));
  614. X            Debug((stderr, "\tNAME='%s'\n", $7));
  615. X            Debug((stderr, "\tprev = '%s'\n", visible(prev)));
  616. X            docexplain($3, $4, $5, $7);
  617. X            }
  618. X
  619. X        | SET optNAME NL
  620. X            {
  621. X            Debug((stderr, "stmt: SET optNAME\n"));
  622. X            Debug((stderr, "\toptNAME='%s'\n", $2));
  623. X            doset($2);
  624. X            }
  625. X
  626. X        | NL
  627. X        | error NL
  628. X            {
  629. X            yyerrok;
  630. X            }
  631. X        ;
  632. X
  633. NL        : '\n'
  634. X            {
  635. X            doprompt();
  636. X            }
  637. X        | ';'
  638. X            {
  639. X            noprompt();
  640. X            }
  641. X        ;
  642. X
  643. optNAME        : NAME
  644. X            {
  645. X            Debug((stderr, "optNAME: NAME\n"));
  646. X            Debug((stderr, "\tNAME='%s'\n", $1));
  647. X            $$ = $1;
  648. X            }
  649. X
  650. X        | /* empty */
  651. X            {
  652. X            Debug((stderr, "optNAME: EMPTY\n"));
  653. X            $$ = ds(unknown_name);
  654. X            }
  655. X        ;
  656. X
  657. cdecl        : cdecl1
  658. X        | '*' opt_constvol_list cdecl
  659. X            {
  660. X            Debug((stderr, "cdecl: * opt_constvol_list cdecl\n"));
  661. X            Debug((stderr, "\topt_constvol_list='%s'\n", $2));
  662. X            Debug((stderr, "\tcdecl='%s'\n", $3));
  663. X            $$ = cat($3,$2,ds(strlen($2)?" pointer to ":"pointer to "),NullCP);
  664. X            prev = 'p';
  665. X            Debug((stderr, "\tprev = '%s'\n", visible(prev)));
  666. X            }
  667. X
  668. X        | NAME DOUBLECOLON '*' cdecl
  669. X            {
  670. X            Debug((stderr, "cdecl: NAME DOUBLECOLON '*' cdecl\n"));
  671. X            Debug((stderr, "\tNAME='%s'\n", $1));
  672. X            Debug((stderr, "\tcdecl='%s'\n", $4));
  673. X            if (!CplusplusFlag)
  674. X                unsupp("pointer to member of class", NullCP);
  675. X            $$ = cat($4,ds("pointer to member of class "),$1,ds(" "),NullCP);
  676. X            prev = 'p';
  677. X            Debug((stderr, "\tprev = '%s'\n", visible(prev)));
  678. X            }
  679. X
  680. X        | '&' opt_constvol_list cdecl
  681. X            {
  682. X            Debug((stderr, "cdecl: & opt_constvol_list cdecl\n"));
  683. X            Debug((stderr, "\topt_constvol_list='%s'\n", $2));
  684. X            Debug((stderr, "\tcdecl='%s'\n", $3));
  685. X            if (!CplusplusFlag)
  686. X                unsupp("reference", NullCP);
  687. X            $$ = cat($3,$2,ds(strlen($2)?" reference to ":"reference to "),NullCP);
  688. X            prev = 'r';
  689. X            Debug((stderr, "\tprev = '%s'\n", visible(prev)));
  690. X            }
  691. X        ;
  692. X
  693. cdecl1        : cdecl1 '(' ')'
  694. X            {
  695. X            Debug((stderr, "cdecl1: cdecl1()\n"));
  696. X            Debug((stderr, "\tcdecl1='%s'\n", $1));
  697. X            $$ = cat($1,ds("function returning "),NullCP);
  698. X            prev = 'f';
  699. X            Debug((stderr, "\tprev = '%s'\n", visible(prev)));
  700. X            }
  701. X
  702. X        | cdecl1 '(' castlist ')'
  703. X            {
  704. X            Debug((stderr, "cdecl1: cdecl1(castlist)\n"));
  705. X            Debug((stderr, "\tcdecl1='%s'\n", $1));
  706. X            Debug((stderr, "\tcastlist='%s'\n", $3));
  707. X            $$ = cat($1, ds("function ("),
  708. X                  $3, ds(") returning "), NullCP);
  709. X            prev = 'f';
  710. X            Debug((stderr, "\tprev = '%s'\n", visible(prev)));
  711. X            }
  712. X
  713. X        | cdecl1 cdims
  714. X            {
  715. X            Debug((stderr, "cdecl1: cdecl1 cdims\n"));
  716. X            Debug((stderr, "\tcdecl1='%s'\n", $1));
  717. X            Debug((stderr, "\tcdims='%s'\n", $2));
  718. X            $$ = cat($1,ds("array "),$2,NullCP);
  719. X            prev = 'a';
  720. X            Debug((stderr, "\tprev = '%s'\n", visible(prev)));
  721. X            }
  722. X
  723. X        | '(' cdecl ')'
  724. X            {
  725. X            Debug((stderr, "cdecl1: (cdecl)\n"));
  726. X            Debug((stderr, "\tcdecl='%s'\n", $2));
  727. X            $$ = $2;
  728. X            /* prev = prev; */
  729. X            Debug((stderr, "\tprev = '%s'\n", visible(prev)));
  730. X            }
  731. X
  732. X        | NAME
  733. X            {
  734. X            Debug((stderr, "cdecl1: NAME\n"));
  735. X            Debug((stderr, "\tNAME='%s'\n", $1));
  736. X            savedname = $1;
  737. X            $$ = ds("");
  738. X            prev = 'n';
  739. X            Debug((stderr, "\tprev = '%s'\n", visible(prev)));
  740. X            }
  741. X        ;
  742. X
  743. castlist    : castlist COMMA castlist
  744. X            {
  745. X            Debug((stderr, "castlist: castlist1, castlist2\n"));
  746. X            Debug((stderr, "\tcastlist1='%s'\n", $1));
  747. X            Debug((stderr, "\tcastlist2='%s'\n", $3));
  748. X            $$ = cat($1, ds(", "), $3, NullCP);
  749. X            }
  750. X
  751. X        | opt_constvol_list type cast
  752. X            {
  753. X            Debug((stderr, "castlist: opt_constvol_list type cast\n"));
  754. X            Debug((stderr, "\topt_constvol_list='%s'\n", $1));
  755. X            Debug((stderr, "\ttype='%s'\n", $2));
  756. X            Debug((stderr, "\tcast='%s'\n", $3));
  757. X            $$ = cat($3, $1, ds(strlen($1) ? " " : ""), $2, NullCP);
  758. X            }
  759. X
  760. X        | NAME
  761. X            {
  762. X            $$ = $1;
  763. X            }
  764. X        ;
  765. X
  766. adecllist    : /* empty */
  767. X            {
  768. X            Debug((stderr, "adecllist: EMPTY\n"));
  769. X            $$ = ds("");
  770. X            }
  771. X
  772. X        | adecllist COMMA adecllist
  773. X            {
  774. X            Debug((stderr, "adecllist: adecllist1, adecllist2\n"));
  775. X            Debug((stderr, "\tadecllist1='%s'\n", $1));
  776. X            Debug((stderr, "\tadecllist2='%s'\n", $3));
  777. X            $$ = cat($1, ds(", "), $3, NullCP);
  778. X            }
  779. X
  780. X        | NAME
  781. X            {
  782. X            Debug((stderr, "adecllist: NAME\n"));
  783. X            Debug((stderr, "\tNAME='%s'\n", $1));
  784. X            $$ = $1;
  785. X            }
  786. X
  787. X        | adecl
  788. X            {
  789. X            Debug((stderr, "adecllist: adecl\n"));
  790. X            Debug((stderr, "\tadecl.left='%s'\n", $1.left));
  791. X            Debug((stderr, "\tadecl.right='%s'\n", $1.right));
  792. X            Debug((stderr, "\tadecl.type='%s'\n", $1.type));
  793. X            $$ = cat($1.type, ds(" "), $1.left, $1.right, NullCP);
  794. X            }
  795. X
  796. X        | NAME AS adecl
  797. X            {
  798. X            Debug((stderr, "adecllist: NAME AS adecl\n"));
  799. X            Debug((stderr, "\tNAME='%s'\n", $1));
  800. X            Debug((stderr, "\tadecl.left='%s'\n", $3.left));
  801. X            Debug((stderr, "\tadecl.right='%s'\n", $3.right));
  802. X            Debug((stderr, "\tadecl.type='%s'\n", $3.type));
  803. X            $$ = cat($3.type, ds(" "), $3.left, $1, $3.right, NullCP);
  804. X            }
  805. X        ;
  806. X
  807. cast        : /* empty */
  808. X            {
  809. X            Debug((stderr, "cast: EMPTY\n"));
  810. X            $$ = ds("");
  811. X            /* prev = prev; */
  812. X            Debug((stderr, "\tprev = '%s'\n", visible(prev)));
  813. X            }
  814. X
  815. X        | '(' ')'
  816. X            {
  817. X            Debug((stderr, "cast: ()\n"));
  818. X            $$ = ds("function returning ");
  819. X            prev = 'f';
  820. X            Debug((stderr, "\tprev = '%s'\n", visible(prev)));
  821. X            }
  822. X
  823. X        | '(' cast ')' '(' ')'
  824. X            {
  825. X            Debug((stderr, "cast: (cast)()\n"));
  826. X            Debug((stderr, "\tcast='%s'\n", $2));
  827. X            $$ = cat($2,ds("function returning "),NullCP);
  828. X            prev = 'f';
  829. X            Debug((stderr, "\tprev = '%s'\n", visible(prev)));
  830. X            }
  831. X
  832. X        | '(' cast ')' '(' castlist ')'
  833. X            {
  834. X            Debug((stderr, "cast: (cast)(castlist)\n"));
  835. X            Debug((stderr, "\tcast='%s'\n", $2));
  836. X            Debug((stderr, "\tcastlist='%s'\n", $5));
  837. X            $$ = cat($2,ds("function ("),$5,ds(") returning "),NullCP);
  838. X            prev = 'f';
  839. X            Debug((stderr, "\tprev = '%s'\n", visible(prev)));
  840. X            }
  841. X
  842. X        | '(' cast ')'
  843. X            {
  844. X            Debug((stderr, "cast: (cast)\n"));
  845. X            Debug((stderr, "\tcast='%s'\n", $2));
  846. X            $$ = $2;
  847. X            /* prev = prev; */
  848. X            Debug((stderr, "\tprev = '%s'\n", visible(prev)));
  849. X            }
  850. X
  851. X        | NAME DOUBLECOLON '*' cast
  852. X            {
  853. X            Debug((stderr, "cast: NAME::*cast\n"));
  854. X            Debug((stderr, "\tcast='%s'\n", $4));
  855. X            if (!CplusplusFlag)
  856. X                unsupp("pointer to member of class", NullCP);
  857. X            $$ = cat($4,ds("pointer to member of class "),$1,ds(" "),NullCP);
  858. X            prev = 'p';
  859. X            Debug((stderr, "\tprev = '%s'\n", visible(prev)));
  860. X            }
  861. X
  862. X        | '*' cast
  863. X            {
  864. X            Debug((stderr, "cast: *cast\n"));
  865. X            Debug((stderr, "\tcast='%s'\n", $2));
  866. X            $$ = cat($2,ds("pointer to "),NullCP);
  867. X            prev = 'p';
  868. X            Debug((stderr, "\tprev = '%s'\n", visible(prev)));
  869. X            }
  870. X
  871. X        | '&' cast
  872. X            {
  873. X            Debug((stderr, "cast: &cast\n"));
  874. X            Debug((stderr, "\tcast='%s'\n", $2));
  875. X            if (!CplusplusFlag)
  876. X                unsupp("reference", NullCP);
  877. X            $$ = cat($2,ds("reference to "),NullCP);
  878. X            prev = 'r';
  879. X            Debug((stderr, "\tprev = '%s'\n", visible(prev)));
  880. X            }
  881. X
  882. X        | cast cdims
  883. X            {
  884. X            Debug((stderr, "cast: cast cdims\n"));
  885. X            Debug((stderr, "\tcast='%s'\n", $1));
  886. X            Debug((stderr, "\tcdims='%s'\n", $2));
  887. X            $$ = cat($1,ds("array "),$2,NullCP);
  888. X            prev = 'a';
  889. X            Debug((stderr, "\tprev = '%s'\n", visible(prev)));
  890. X            }
  891. X        ;
  892. X
  893. cdims        : '[' ']'
  894. X            {
  895. X            Debug((stderr, "cdims: []\n"));
  896. X            $$ = ds("of ");
  897. X            }
  898. X
  899. X        | '[' NUMBER ']'
  900. X            {
  901. X            Debug((stderr, "cdims: [NUMBER]\n"));
  902. X            Debug((stderr, "\tNUMBER='%s'\n", $2));
  903. X            $$ = cat($2,ds(" of "),NullCP);
  904. X            }
  905. X        ;
  906. X
  907. adecl        : FUNCTION RETURNING adecl
  908. X            {
  909. X            Debug((stderr, "adecl: FUNCTION RETURNING adecl\n"));
  910. X            Debug((stderr, "\tadecl.left='%s'\n", $3.left));
  911. X            Debug((stderr, "\tadecl.right='%s'\n", $3.right));
  912. X            Debug((stderr, "\tadecl.type='%s'\n", $3.type));
  913. X            if (prev == 'f')
  914. X                unsupp("Function returning function",
  915. X                       "function returning pointer to function");
  916. X            else if (prev=='A' || prev=='a')
  917. X                unsupp("Function returning array",
  918. X                       "function returning pointer");
  919. X            $$.left = $3.left;
  920. X            $$.right = cat(ds("()"),$3.right,NullCP);
  921. X            $$.type = $3.type;
  922. X            prev = 'f';
  923. X            Debug((stderr, "\n\tadecl now =\n"));
  924. X            Debug((stderr, "\t\tadecl.left='%s'\n", $$.left));
  925. X            Debug((stderr, "\t\tadecl.right='%s'\n", $$.right));
  926. X            Debug((stderr, "\t\tadecl.type='%s'\n", $$.type));
  927. X            Debug((stderr, "\tprev = '%s'\n", visible(prev)));
  928. X            }
  929. X
  930. X        | FUNCTION '(' adecllist ')' RETURNING adecl
  931. X            {
  932. X            Debug((stderr, "adecl: FUNCTION (adecllist) RETURNING adecl\n"));
  933. X            Debug((stderr, "\tadecllist='%s'\n", $3));
  934. X            Debug((stderr, "\tadecl.left='%s'\n", $6.left));
  935. X            Debug((stderr, "\tadecl.right='%s'\n", $6.right));
  936. X            Debug((stderr, "\tadecl.type='%s'\n", $6.type));
  937. X            if (prev == 'f')
  938. X                unsupp("Function returning function",
  939. X                       "function returning pointer to function");
  940. X            else if (prev=='A' || prev=='a')
  941. X                unsupp("Function returning array",
  942. X                       "function returning pointer");
  943. X            $$.left = $6.left;
  944. X            $$.right = cat(ds("("),$3,ds(")"),$6.right,NullCP);
  945. X            $$.type = $6.type;
  946. X            prev = 'f';
  947. X            Debug((stderr, "\n\tadecl now =\n"));
  948. X            Debug((stderr, "\t\tadecl.left='%s'\n", $$.left));
  949. X            Debug((stderr, "\t\tadecl.right='%s'\n", $$.right));
  950. X            Debug((stderr, "\t\tadecl.type='%s'\n", $$.type));
  951. X            Debug((stderr, "\tprev = '%s'\n", visible(prev)));
  952. X            }
  953. X
  954. X        | ARRAY adims OF adecl
  955. X            {
  956. X            Debug((stderr, "adecl: ARRAY adims OF adecl\n"));
  957. X            Debug((stderr, "\tadims='%s'\n", $2));
  958. X            Debug((stderr, "\tadecl.left='%s'\n", $4.left));
  959. X            Debug((stderr, "\tadecl.right='%s'\n", $4.right));
  960. X            Debug((stderr, "\tadecl.type='%s'\n", $4.type));
  961. X            if (prev == 'f')
  962. X                unsupp("Array of function",
  963. X                       "array of pointer to function");
  964. X            else if (prev == 'a')
  965. X                unsupp("Inner array of unspecified size",
  966. X                       "array of pointer");
  967. X            else if (prev == 'v')
  968. X                unsupp("Array of void",
  969. X                       "pointer to void");
  970. X            if (arbdims)
  971. X                prev = 'a';
  972. X            else
  973. X                prev = 'A';
  974. X            $$.left = $4.left;
  975. X            $$.right = cat($2,$4.right,NullCP);
  976. X            $$.type = $4.type;
  977. X            Debug((stderr, "\n\tadecl now =\n"));
  978. X            Debug((stderr, "\t\tadecl.left='%s'\n", $$.left));
  979. X            Debug((stderr, "\t\tadecl.right='%s'\n", $$.right));
  980. X            Debug((stderr, "\t\tadecl.type='%s'\n", $$.type));
  981. X            Debug((stderr, "\tprev = '%s'\n", visible(prev)));
  982. X            }
  983. X
  984. X        | opt_constvol_list POINTER TO adecl
  985. X            {
  986. X            char *op = "", *cp = "", *sp = "";
  987. X
  988. X            Debug((stderr, "adecl: opt_constvol_list POINTER TO adecl\n"));
  989. X            Debug((stderr, "\topt_constvol_list='%s'\n", $1));
  990. X            Debug((stderr, "\tadecl.left='%s'\n", $4.left));
  991. X            Debug((stderr, "\tadecl.right='%s'\n", $4.right));
  992. X            Debug((stderr, "\tadecl.type='%s'\n", $4.type));
  993. X            if (prev == 'a')
  994. X                unsupp("Pointer to array of unspecified dimension",
  995. X                       "pointer to object");
  996. X            if (prev=='a' || prev=='A' || prev=='f') {
  997. X                op = "(";
  998. X                cp = ")";
  999. X            }
  1000. X            if (strlen($1) != 0)
  1001. X                sp = " ";
  1002. X            $$.left = cat($4.left,ds(op),ds("*"),
  1003. X                       ds(sp),$1,ds(sp),NullCP);
  1004. X            $$.right = cat(ds(cp),$4.right,NullCP);
  1005. X            $$.type = $4.type;
  1006. X            prev = 'p';
  1007. X            Debug((stderr, "\n\tadecl now =\n"));
  1008. X            Debug((stderr, "\t\tadecl.left='%s'\n", $$.left));
  1009. X            Debug((stderr, "\t\tadecl.right='%s'\n", $$.right));
  1010. X            Debug((stderr, "\t\tadecl.type='%s'\n", $$.type));
  1011. X            Debug((stderr, "\tprev = '%s'\n", visible(prev)));
  1012. X            }
  1013. X
  1014. X        | opt_constvol_list POINTER TO MEMBER OF ClassStruct NAME adecl
  1015. X            {
  1016. X            char *op = "", *cp = "", *sp = "";
  1017. X
  1018. X            Debug((stderr, "adecl: opt_constvol_list POINTER TO MEMBER OF ClassStruct NAME adecl\n"));
  1019. X            Debug((stderr, "\topt_constvol_list='%s'\n", $1));
  1020. X            Debug((stderr, "\tClassStruct='%s'\n", $6));
  1021. X            Debug((stderr, "\tNAME='%s'\n", $7));
  1022. X            Debug((stderr, "\tadecl.left='%s'\n", $8.left));
  1023. X            Debug((stderr, "\tadecl.right='%s'\n", $8.right));
  1024. X            Debug((stderr, "\tadecl.type='%s'\n", $8.type));
  1025. X            if (!CplusplusFlag)
  1026. X                unsupp("pointer to member of class", NullCP);
  1027. X            if (prev == 'a')
  1028. X                unsupp("Pointer to array of unspecified dimension",
  1029. X                       "pointer to object");
  1030. X            if (prev=='a' || prev=='A' || prev=='f') {
  1031. X                op = "(";
  1032. X                cp = ")";
  1033. X            }
  1034. X            if (strlen($1) != 0)
  1035. X                sp = " ";
  1036. X            $$.left = cat($8.left,ds(op),$7,ds("::*"),
  1037. X                      ds(sp),$1,ds(sp),NullCP);
  1038. X            $$.right = cat(ds(cp),$8.right,NullCP);
  1039. X            $$.type = $8.type;
  1040. X            prev = 'p';
  1041. X            Debug((stderr, "\n\tadecl now =\n"));
  1042. X            Debug((stderr, "\t\tadecl.left='%s'\n", $$.left));
  1043. X            Debug((stderr, "\t\tadecl.right='%s'\n", $$.right));
  1044. X            Debug((stderr, "\t\tadecl.type='%s'\n", $$.type));
  1045. X            Debug((stderr, "\tprev = '%s'\n", visible(prev)));
  1046. X            }
  1047. X
  1048. X        | opt_constvol_list REFERENCE TO adecl
  1049. X            {
  1050. X            char *op = "", *cp = "", *sp = "";
  1051. X
  1052. X            Debug((stderr, "adecl: opt_constvol_list REFERENCE TO adecl\n"));
  1053. X            Debug((stderr, "\topt_constvol_list='%s'\n", $1));
  1054. X            Debug((stderr, "\tadecl.left='%s'\n", $4.left));
  1055. X            Debug((stderr, "\tadecl.right='%s'\n", $4.right));
  1056. X            Debug((stderr, "\tadecl.type='%s'\n", $4.type));
  1057. X            if (!CplusplusFlag)
  1058. X                unsupp("reference", NullCP);
  1059. X            if (prev == 'v')
  1060. X                unsupp("Reference to void",
  1061. X                       "pointer to void");
  1062. X            else if (prev == 'a')
  1063. X                unsupp("Reference to array of unspecified dimension",
  1064. X                       "reference to object");
  1065. X            if (prev=='a' || prev=='A' || prev=='f') {
  1066. X                op = "(";
  1067. X                cp = ")";
  1068. X            }
  1069. X            if (strlen($1) != 0)
  1070. X                sp = " ";
  1071. X            $$.left = cat($4.left,ds(op),ds("&"),
  1072. X                       ds(sp),$1,ds(sp),NullCP);
  1073. X            $$.right = cat(ds(cp),$4.right,NullCP);
  1074. X            $$.type = $4.type;
  1075. X            prev = 'r';
  1076. X            Debug((stderr, "\n\tadecl now =\n"));
  1077. X            Debug((stderr, "\t\tadecl.left='%s'\n", $$.left));
  1078. X            Debug((stderr, "\t\tadecl.right='%s'\n", $$.right));
  1079. X            Debug((stderr, "\t\tadecl.type='%s'\n", $$.type));
  1080. X            Debug((stderr, "\tprev = '%s'\n", visible(prev)));
  1081. X            }
  1082. X
  1083. X        | opt_constvol_list type
  1084. X            {
  1085. X            Debug((stderr, "adecl: opt_constvol_list type\n"));
  1086. X            Debug((stderr, "\topt_constvol_list='%s'\n", $1));
  1087. X            Debug((stderr, "\ttype='%s'\n", $2));
  1088. X            $$.left = ds("");
  1089. X            $$.right = ds("");
  1090. X            $$.type = cat($1,ds(strlen($1)?" ":""),$2,NullCP);
  1091. X            if (strcmp($2, "void") == 0)
  1092. X                prev = 'v';
  1093. X            else if ((strncmp($2, "struct", 6) == 0) ||
  1094. X                     (strncmp($2, "class", 5) == 0))
  1095. X                prev = 's';
  1096. X            else
  1097. X                prev = 't';
  1098. X            Debug((stderr, "\n\tadecl now =\n"));
  1099. X            Debug((stderr, "\t\tadecl.left='%s'\n", $$.left));
  1100. X            Debug((stderr, "\t\tadecl.right='%s'\n", $$.right));
  1101. X            Debug((stderr, "\t\tadecl.type='%s'\n", $$.type));
  1102. X            Debug((stderr, "\tprev = '%s'\n", visible(prev)));
  1103. X            }
  1104. X        ;
  1105. X
  1106. adims        : /* empty */
  1107. X            {
  1108. X            Debug((stderr, "adims: EMPTY\n"));
  1109. X            arbdims = 1;
  1110. X            $$ = ds("[]");
  1111. X            }
  1112. X
  1113. X        | NUMBER
  1114. X            {
  1115. X            Debug((stderr, "adims: NUMBER\n"));
  1116. X            Debug((stderr, "\tNUMBER='%s'\n", $1));
  1117. X            arbdims = 0;
  1118. X            $$ = cat(ds("["),$1,ds("]"),NullCP);
  1119. X            }
  1120. X        ;
  1121. X
  1122. type        : tinit c_type
  1123. X            {
  1124. X            Debug((stderr, "type: tinit c_type\n"));
  1125. X            Debug((stderr, "\ttinit=''\n"));
  1126. X            Debug((stderr, "\tc_type='%s'\n", $2));
  1127. X            mbcheck();
  1128. X            $$ = $2;
  1129. X            }
  1130. X        ;
  1131. X
  1132. tinit        : /* empty */
  1133. X            {
  1134. X            Debug((stderr, "tinit: EMPTY\n"));
  1135. X            modbits = 0;
  1136. X            }
  1137. X        ;
  1138. X
  1139. c_type        : mod_list
  1140. X            {
  1141. X            Debug((stderr, "c_type: mod_list\n"));
  1142. X            Debug((stderr, "\tmod_list='%s'\n", $1));
  1143. X            $$ = $1;
  1144. X            }
  1145. X
  1146. X        | tname
  1147. X            {
  1148. X            Debug((stderr, "c_type: tname\n"));
  1149. X            Debug((stderr, "\ttname='%s'\n", $1));
  1150. X            $$ = $1;
  1151. X            }
  1152. X
  1153. X        | mod_list tname
  1154. X            {
  1155. X            Debug((stderr, "c_type: mod_list tname\n"));
  1156. X            Debug((stderr, "\tmod_list='%s'\n", $1));
  1157. X            Debug((stderr, "\ttname='%s'\n", $2));
  1158. X            $$ = cat($1,ds(" "),$2,NullCP);
  1159. X            }
  1160. X
  1161. X        | StrClaUniEnum NAME
  1162. X            {
  1163. X            Debug((stderr, "c_type: StrClaUniEnum NAME\n"));
  1164. X            Debug((stderr, "\tStrClaUniEnum='%s'\n", $1));
  1165. X            Debug((stderr, "\tNAME='%s'\n", $2));
  1166. X            $$ = cat($1,ds(" "),$2,NullCP);
  1167. X            }
  1168. X        ;
  1169. X
  1170. StrClaUniEnum    : ClassStruct
  1171. X        | ENUM
  1172. X        | UNION
  1173. X            {
  1174. X            $$ = $1;
  1175. X            }
  1176. X        ;
  1177. X
  1178. ClassStruct    : STRUCT
  1179. X        | CLASS
  1180. X            {
  1181. X            $$ = $1;
  1182. X            }
  1183. X        ;
  1184. X
  1185. tname        : INT
  1186. X            {
  1187. X            Debug((stderr, "tname: INT\n"));
  1188. X            Debug((stderr, "\tINT='%s'\n", $1));
  1189. X            modbits |= MB_INT; $$ = $1;
  1190. X            }
  1191. X
  1192. X        | CHAR
  1193. X            {
  1194. X            Debug((stderr, "tname: CHAR\n"));
  1195. X            Debug((stderr, "\tCHAR='%s'\n", $1));
  1196. X            modbits |= MB_CHAR; $$ = $1;
  1197. X            }
  1198. X
  1199. X        | FLOAT
  1200. X            {
  1201. X            Debug((stderr, "tname: FLOAT\n"));
  1202. X            Debug((stderr, "\tFLOAT='%s'\n", $1));
  1203. X            modbits |= MB_FLOAT; $$ = $1;
  1204. X            }
  1205. X
  1206. X        | DOUBLE
  1207. X            {
  1208. X            Debug((stderr, "tname: DOUBLE\n"));
  1209. X            Debug((stderr, "\tDOUBLE='%s'\n", $1));
  1210. X            modbits |= MB_DOUBLE; $$ = $1;
  1211. X            }
  1212. X
  1213. X        | VOID
  1214. X            {
  1215. X            Debug((stderr, "tname: VOID\n"));
  1216. X            Debug((stderr, "\tVOID='%s'\n", $1));
  1217. X            modbits |= MB_VOID; $$ = $1;
  1218. X            }
  1219. X        ;
  1220. X
  1221. mod_list    : modifier mod_list1
  1222. X            {
  1223. X            Debug((stderr, "mod_list: modifier mod_list1\n"));
  1224. X            Debug((stderr, "\tmodifier='%s'\n", $1));
  1225. X            Debug((stderr, "\tmod_list1='%s'\n", $2));
  1226. X            $$ = cat($1,ds(" "),$2,NullCP);
  1227. X            }
  1228. X
  1229. X        | modifier
  1230. X            {
  1231. X            Debug((stderr, "mod_list: modifier\n"));
  1232. X            Debug((stderr, "\tmodifier='%s'\n", $1));
  1233. X            $$ = $1;
  1234. X            }
  1235. X        ;
  1236. X
  1237. mod_list1    : mod_list
  1238. X            {
  1239. X            Debug((stderr, "mod_list1: mod_list\n"));
  1240. X            Debug((stderr, "\tmod_list='%s'\n", $1));
  1241. X            $$ = $1;
  1242. X            }
  1243. X
  1244. X        | CONSTVOLATILE
  1245. X            {
  1246. X            Debug((stderr, "mod_list1: CONSTVOLATILE\n"));
  1247. X            Debug((stderr, "\tCONSTVOLATILE='%s'\n", $1));
  1248. X            if (PreANSIFlag)
  1249. X                notsupported(" (Pre-ANSI Compiler)", $1, NullCP);
  1250. X            else if (RitchieFlag)
  1251. X                notsupported(" (Ritchie Compiler)", $1, NullCP);
  1252. X            else if ((strcmp($1, "noalias") == 0) && CplusplusFlag)
  1253. X                unsupp($1, NullCP);
  1254. X            $$ = $1;
  1255. X            }
  1256. X        ;
  1257. X
  1258. modifier    : UNSIGNED
  1259. X            {
  1260. X            Debug((stderr, "modifier: UNSIGNED\n"));
  1261. X            Debug((stderr, "\tUNSIGNED='%s'\n", $1));
  1262. X            modbits |= MB_UNSIGNED; $$ = $1;
  1263. X            }
  1264. X
  1265. X        | SIGNED
  1266. X            {
  1267. X            Debug((stderr, "modifier: SIGNED\n"));
  1268. X            Debug((stderr, "\tSIGNED='%s'\n", $1));
  1269. X            modbits |= MB_SIGNED; $$ = $1;
  1270. X            }
  1271. X
  1272. X        | LONG
  1273. X            {
  1274. X            Debug((stderr, "modifier: LONG\n"));
  1275. X            Debug((stderr, "\tLONG='%s'\n", $1));
  1276. X            modbits |= MB_LONG; $$ = $1;
  1277. X            }
  1278. X
  1279. X        | SHORT
  1280. X            {
  1281. X            Debug((stderr, "modifier: SHORT\n"));
  1282. X            Debug((stderr, "\tSHORT='%s'\n", $1));
  1283. X            modbits |= MB_SHORT; $$ = $1;
  1284. X            }
  1285. X        ;
  1286. X
  1287. opt_constvol_list: CONSTVOLATILE opt_constvol_list
  1288. X            {
  1289. X            Debug((stderr, "opt_constvol_list: CONSTVOLATILE opt_constvol_list\n"));
  1290. X            Debug((stderr, "\tCONSTVOLATILE='%s'\n", $1));
  1291. X            Debug((stderr, "\topt_constvol_list='%s'\n", $2));
  1292. X            if (PreANSIFlag)
  1293. X                notsupported(" (Pre-ANSI Compiler)", $1, NullCP);
  1294. X            else if (RitchieFlag)
  1295. X                notsupported(" (Ritchie Compiler)", $1, NullCP);
  1296. X            else if ((strcmp($1, "noalias") == 0) && CplusplusFlag)
  1297. X                unsupp($1, NullCP);
  1298. X            $$ = cat($1,ds(strlen($2) ? " " : ""),$2,NullCP);
  1299. X            }
  1300. X
  1301. X        | /* empty */
  1302. X            {
  1303. X            Debug((stderr, "opt_constvol_list: EMPTY\n"));
  1304. X            $$ = ds("");
  1305. X            }
  1306. X        ;
  1307. X
  1308. constvol_list: CONSTVOLATILE opt_constvol_list
  1309. X            {
  1310. X            Debug((stderr, "constvol_list: CONSTVOLATILE opt_constvol_list\n"));
  1311. X            Debug((stderr, "\tCONSTVOLATILE='%s'\n", $1));
  1312. X            Debug((stderr, "\topt_constvol_list='%s'\n", $2));
  1313. X            if (PreANSIFlag)
  1314. X                notsupported(" (Pre-ANSI Compiler)", $1, NullCP);
  1315. X            else if (RitchieFlag)
  1316. X                notsupported(" (Ritchie Compiler)", $1, NullCP);
  1317. X            else if ((strcmp($1, "noalias") == 0) && CplusplusFlag)
  1318. X                unsupp($1, NullCP);
  1319. X            $$ = cat($1,ds(strlen($2) ? " " : ""),$2,NullCP);
  1320. X            }
  1321. X        ;
  1322. X
  1323. storage        : AUTO
  1324. X        | EXTERN
  1325. X        | REGISTER
  1326. X        | STATIC
  1327. X            {
  1328. X            Debug((stderr, "storage: AUTO,EXTERN,STATIC,REGISTER (%s)\n", $1));
  1329. X            $$ = $1;
  1330. X            }
  1331. X        ;
  1332. X
  1333. opt_storage    : storage
  1334. X            {
  1335. X            Debug((stderr, "opt_storage: storage=%s\n", $1));
  1336. X            $$ = $1;
  1337. X            }
  1338. X
  1339. X        | /* empty */
  1340. X            {
  1341. X            Debug((stderr, "opt_storage: EMPTY\n"));
  1342. X            $$ = ds("");
  1343. X            }
  1344. X        ;
  1345. X%%
  1346. END_OF_FILE
  1347. if test 22746 -ne `wc -c <'cdgram.y'`; then
  1348.     echo shar: \"'cdgram.y'\" unpacked with wrong size!
  1349. fi
  1350. # end of 'cdgram.y'
  1351. fi
  1352. if test -f 'cdlex.l' -a "${1}" != "-c" ; then 
  1353.   echo shar: Will not clobber existing file \"'cdlex.l'\"
  1354. else
  1355. echo shar: Extracting \"'cdlex.l'\" \(2380 characters\)
  1356. sed "s/^X//" >'cdlex.l' <<'END_OF_FILE'
  1357. X%{
  1358. X/* Lexical analyzer description for ANSI and C++ cdecl. */
  1359. X/* The output of this file is included */
  1360. X/* into the C file cdecl.c. */
  1361. char cdlexsccsid[] = "@(#)cdlex.l    2.2 3/30/88";
  1362. X%}
  1363. X
  1364. N    [0-9]
  1365. A    [A-Z_a-z]
  1366. AN    [0-9A-Z_a-z]
  1367. X
  1368. X%%
  1369. array        return ARRAY;
  1370. as        return AS;
  1371. cast        return CAST;
  1372. declare        return DECLARE;
  1373. exit        return 0;
  1374. explain        return EXPLAIN;
  1375. function    return FUNCTION;
  1376. func        return FUNCTION;
  1377. help        return HELP;
  1378. into        return INTO;
  1379. member        return MEMBER;
  1380. of        return OF;
  1381. pointer        return POINTER;
  1382. ptr        return POINTER;
  1383. quit        return 0;
  1384. reference    return REFERENCE;
  1385. ref        return REFERENCE;
  1386. returning    return RETURNING;
  1387. ret        return RETURNING;
  1388. set        return SET;
  1389. to        return TO;
  1390. vector        return ARRAY;
  1391. X::        return DOUBLECOLON;
  1392. X[?]        return HELP;
  1393. X[,]        return COMMA;
  1394. X
  1395. auto        { yylval.dynstr = ds(yytext);    return AUTO; }
  1396. character    { yylval.dynstr = ds("char");    return CHAR; }
  1397. char        { yylval.dynstr = ds(yytext);    return CHAR; }
  1398. class        { yylval.dynstr = ds(yytext);    return CLASS; }
  1399. constant    { yylval.dynstr = ds("const");    return CONSTVOLATILE; }
  1400. const        { yylval.dynstr = ds(yytext);    return CONSTVOLATILE; }
  1401. double        { yylval.dynstr = ds(yytext);    return DOUBLE; }
  1402. enumeration    { yylval.dynstr = ds("enum");    return ENUM; }
  1403. enum        { yylval.dynstr = ds(yytext);    return ENUM; }
  1404. extern        { yylval.dynstr = ds(yytext);    return EXTERN; }
  1405. float        { yylval.dynstr = ds(yytext);    return FLOAT; }
  1406. integer        { yylval.dynstr = ds("int");    return INT; }
  1407. int        { yylval.dynstr = ds(yytext);    return INT; }
  1408. long        { yylval.dynstr = ds(yytext);    return LONG; }
  1409. noalias        { yylval.dynstr = ds(yytext);    return CONSTVOLATILE; }
  1410. register    { yylval.dynstr = ds(yytext);    return REGISTER; }
  1411. short        { yylval.dynstr = ds(yytext);    return SHORT; }
  1412. signed        { yylval.dynstr = ds(yytext);    return SIGNED; }
  1413. static        { yylval.dynstr = ds(yytext);    return STATIC; }
  1414. structure    { yylval.dynstr = ds("struct");    return STRUCT; }
  1415. struct        { yylval.dynstr = ds(yytext);    return STRUCT; }
  1416. union        { yylval.dynstr = ds(yytext);    return UNION; }
  1417. unsigned    { yylval.dynstr = ds(yytext);    return UNSIGNED; }
  1418. void        { yylval.dynstr = ds(yytext);    return VOID; }
  1419. volatile    { yylval.dynstr = ds(yytext);    return CONSTVOLATILE; }
  1420. X
  1421. X{A}{AN}*    { yylval.dynstr = ds(yytext);    return NAME; }
  1422. X{N}+        { yylval.dynstr = ds(yytext);    return NUMBER; }
  1423. X
  1424. X[#].*        ;
  1425. X[\t ]        ;
  1426. X[&*[\]();\n]    return *yytext;
  1427. X.        {
  1428. X            (void) printf("bad character '%s'\n",visible(*yytext));
  1429. X            return *yytext;
  1430. X        }
  1431. X%%
  1432. END_OF_FILE
  1433. if test 2380 -ne `wc -c <'cdlex.l'`; then
  1434.     echo shar: \"'cdlex.l'\" unpacked with wrong size!
  1435. fi
  1436. # end of 'cdlex.l'
  1437. fi
  1438. if test -f 'makefile' -a "${1}" != "-c" ; then 
  1439.   echo shar: Will not clobber existing file \"'makefile'\"
  1440. else
  1441. echo shar: Extracting \"'makefile'\" \(1340 characters\)
  1442. sed "s/^X//" >'makefile' <<'END_OF_FILE'
  1443. X# @(#)makefile    2.2 1/20/88
  1444. X# the following can be added to CFLAGS for various things
  1445. X#
  1446. X# add -DNOVOID        If your compiler can not handle the void keyword.
  1447. X# add -DBSD        For BSD4.[23] UNIX Systems.
  1448. X# add -DDOS        For MS-DOS/PC-DOS Systems, Micro-Soft C 4.0, Turbo C
  1449. X#                Use the ANSI option.
  1450. X# add -DNOGETOPT    If your library doesn't have getopt().
  1451. X#                Another routine will be used in its place.
  1452. X# add -DNOVARARGS    If you have neither <stdarg.h> (ANSI C) or
  1453. X#                <varargs.h> (pre-ANSI C).
  1454. X#                Another method will be compiled instead.
  1455. X# add -Ddodebug        To compile in debugging trace statements.
  1456. X# add -Ddoyydebug    To compile in yacc trace statements.
  1457. X
  1458. CFLAGS= -g -Ddodebug -Ddoyydebug
  1459. CC= cc
  1460. ALLFILES= makefile cdgram.y cdlex.l cdecl.c cdecl.1 testset testset++
  1461. BIN= /usr/lubin
  1462. X
  1463. cdecl: c++decl test
  1464. X
  1465. c++decl: cdgram.c cdlex.c cdecl.c
  1466. X    $(CC) $(CFLAGS) -o cdecl cdecl.c
  1467. X    -ln cdecl c++decl
  1468. X
  1469. cdlex.c: cdlex.l
  1470. X    lex cdlex.l && mv lex.yy.c cdlex.c
  1471. X
  1472. cdgram.c: cdgram.y
  1473. X    yacc cdgram.y && mv y.tab.c cdgram.c
  1474. X
  1475. test:
  1476. X    ./cdecl < testset
  1477. X    ./c++decl < testset++
  1478. X
  1479. install: c++decl
  1480. X    mv cdecl $(BIN)/cdecl
  1481. X    ln $(BIN)/cdecl $(BIN)/c++decl
  1482. X
  1483. clean:
  1484. X    rm -f cdgram.c cdlex.c cdecl y.output c++decl
  1485. X
  1486. clobber: clean
  1487. X    rm -f $(BIN)/cdecl $(BIN)/c++decl
  1488. X
  1489. cdecl.cpio: $(ALLFILES)
  1490. X    ls $(ALLFILES) | cpio -ocv > cdecl.cpio
  1491. X
  1492. cdecl.shar: $(ALLFILES)
  1493. X    shar $(ALLFILES) > cdecl.shar
  1494. END_OF_FILE
  1495. if test 1340 -ne `wc -c <'makefile'`; then
  1496.     echo shar: \"'makefile'\" unpacked with wrong size!
  1497. fi
  1498. # end of 'makefile'
  1499. fi
  1500. if test -f 'testset' -a "${1}" != "-c" ; then 
  1501.   echo shar: Will not clobber existing file \"'testset'\"
  1502. else
  1503. echo shar: Extracting \"'testset'\" \(1038 characters\)
  1504. sed "s/^X//" >'testset' <<'END_OF_FILE'
  1505. help
  1506. set options
  1507. X# test some declarations
  1508. declare x as ptr to character
  1509. declare x as func(w as ptr to char, y as int) ret ptr to int
  1510. declare x as func(ptr to char) ret ptr to int
  1511. declare x as func(int) ret ptr to int
  1512. declare x as func(ptr to char, int) ret ptr to int
  1513. declare x as function (args) returning pointer to int
  1514. X# test some explain functions
  1515. explain char *x
  1516. explain int *x()
  1517. explain int *x(args)
  1518. explain int *x(char *)
  1519. explain int *x(char *, int )
  1520. explain int *x(char *, int, float)
  1521. explain int *x(int )
  1522. X# test some casts
  1523. cast x into ptr to char
  1524. cast x into ptr to func ret int
  1525. cast x into ptr to func() ret int
  1526. cast x into ptr to func(args) ret int
  1527. cast x into ptr to func(x as ptr to char, y as int) ret int
  1528. cast x into ptr to func(ptr to char) ret int
  1529. cast x into ptr to func(ptr to char, int) ret int
  1530. cast x into ptr to func(ptr to char, int, float) ret int
  1531. X# test explaining some casts
  1532. explain (char *)x
  1533. explain (int (*)())x
  1534. explain (int (*)(char *))x
  1535. explain (int (*)(char *, int))x
  1536. explain (int (*)(char *, int, float))x
  1537. END_OF_FILE
  1538. if test 1038 -ne `wc -c <'testset'`; then
  1539.     echo shar: \"'testset'\" unpacked with wrong size!
  1540. fi
  1541. # end of 'testset'
  1542. fi
  1543. if test -f 'testset++' -a "${1}" != "-c" ; then 
  1544.   echo shar: Will not clobber existing file \"'testset++'\"
  1545. else
  1546. echo shar: Extracting \"'testset++'\" \(1337 characters\)
  1547. sed "s/^X//" >'testset++' <<'END_OF_FILE'
  1548. help
  1549. set options
  1550. X# test some declarations
  1551. declare x as ptr to character
  1552. declare x as reference to character
  1553. declare foo as pointer to member of class X int
  1554. declare foo as pointer to member of class X function (arg1, arg2) returning pointer to class Y
  1555. declare x as func(w as ptr to char, y as int) ret ptr to int
  1556. declare x as func(ptr to char) ret ptr to int
  1557. declare x as func(int) ret ptr to int
  1558. declare x as func(ptr to char, int) ret ptr to int
  1559. declare x as function (args) returning pointer to int
  1560. X# test some explain functions
  1561. explain char *x
  1562. explain int X::*foo
  1563. explain class Y *(X::*foo)(arg1, arg2)
  1564. explain int *x()
  1565. explain int *x(args)
  1566. explain int *x(char *)
  1567. explain int *x(char *, int )
  1568. explain int *x(char *, int, float)
  1569. explain int *x(int )
  1570. X# test some casts
  1571. cast x into ptr to char
  1572. cast x into ptr to member of class X int
  1573. cast x into ptr to func ret int
  1574. cast x into ptr to func() ret int
  1575. cast x into ptr to func(args) ret int
  1576. cast x into ptr to func(x as ptr to char, y as int) ret int
  1577. cast x into ptr to func(ptr to char) ret int
  1578. cast x into ptr to func(ptr to char, int) ret int
  1579. cast x into ptr to func(ptr to char, int, float) ret int
  1580. X# test explaining some casts
  1581. explain (char *)x
  1582. explain (int X::*)x
  1583. explain (int (*)())x
  1584. explain (int (*)(char *))x
  1585. explain (int (*)(char *, int))x
  1586. explain (int (*)(char *, int, float))x
  1587. END_OF_FILE
  1588. if test 1337 -ne `wc -c <'testset++'`; then
  1589.     echo shar: \"'testset++'\" unpacked with wrong size!
  1590. fi
  1591. # end of 'testset++'
  1592. fi
  1593. echo shar: End of archive 1 \(of 2\).
  1594. cp /dev/null ark1isdone
  1595. MISSING=""
  1596. for I in 1 2 ; do
  1597.     if test ! -f ark${I}isdone ; then
  1598.     MISSING="${MISSING} ${I}"
  1599.     fi
  1600. done
  1601. if test "${MISSING}" = "" ; then
  1602.     echo You have unpacked both archives.
  1603.     rm -f ark[1-9]isdone
  1604. else
  1605.     echo You still need to unpack the following archives:
  1606.     echo "        " ${MISSING}
  1607. fi
  1608. ##  End of shell archive.
  1609. exit 0
  1610.