K
Keith Thompson
Ben Bacarisse said:Keith Thompson said:Joe Pfeiffer <[email protected]> writes:So... does anybody know what cdecl does with "array" that making it a
reserved word makes sense? Or is it plain and simply a bug?
It's a reserved word in the English-like syntax it uses to explain
declarations:
cdecl> explain int arr[42]
declare arr as array 42 of int
cdecl> explain int array[42]
syntax error
cdecl>
This *shouldn't* cause it to be reserved for the C-like syntax it uses,
but apparently it treats it that way. I've never looked into the
internals, so I can't be sure what's going on.
cdecl uses the same grammar for both "directions" of it's translation.
'array' is a keyword when used like this:
cdecl> declare arr as array 42 of int
int arr[42]
so it's also one when reading an 'explain' command. You can't name your
array "declare", "explain", "help" or any number of other words that are
considered special. It's a shame, because the error that gets reported
might be confusing. Is it really a syntax error in the declaration, or
did you just use a keyword without knowing?
Even when this is taken into account, cdecl is rather lax in admitting
some things that are not valid C, and rejecting others that are (though
the latter may just be that it has not kept up with recent standards).
It would be an interesting project for someone to clean up cdecl and
release a new version. (Perhaps someone has already done so, but I see
no sign of it at cdecl.org.) I might play around with it myself, but I
honestly don't expect to produce anything worth releasing.
My suggestion: Rather than using a single grammar, recognize the first
word on a line ("declare", "explain", etc.) and use it to determine how
to parse the rest of the line. For bonus points, print more meaningful
error messages than "syntax error".
The source code can be downloaded from:
http://cdecl.org/files/cdecl-blocks-2.5.tar.gz
It apparently hasn't been updated since 1996.
As for licensing, here's an excerpt from the README file, written by
David R. Conrad:
You may well be wondering what the status of cdecl is. So am I.
It was twice posted to comp.sources.unix, but neither edition
carried any mention of copyright. This version is derived from
the second edition. I have no reason to believe there are any
limitations on its use, and strongly believe it to be in the
Public Domain. GNU readline is, of course, covered by the GNU
General Public License.
GNU readline isn't included in the distributed sources, but it links to
it if possible when it's built from source.
One interesting tidbit: cdecl 2.5 treats "noalias" as a keyword.
"noalias" was a proposed keyword, roughly an early attempt at what later
became "restrict", that never made it into the 1989 ANSI C standard.
Dennis Ritchie famously sent an official comment to X3J11 which included
the demand "Noalias must go. This is non-negotiable."