Is there a list of this very nasty 1970s styles of coding somewhere? Is it mainly that it is outdated and doesn't describe the lastest C standards?
Who are these Kernighan and Ritchie guys? They obviously just don't understand "good code", terrible book!
(And I say this as someone who likes K&R.)
enum { NAME, PARENS, BRACKETS };
void dcl(void);
void dirdcl(void);
int gettoken(void);
int tokentype;
char token[MAXTOKEN];
char name[MAXTOKEN];
char datatype[MAXTOKEN]; /* data type = char, int, etc. */
char out[1000];
main() /* convert declaration to words */
{
while (gettoken() != EOF) { /* 1st token on line */
strcpy(datatype, token); /* is the datatype */
out[0] = '\0';
dcl(); /* parse rest of line */
if (tokentype != '\n')
printf("syntax error\n");
printf("%s: %s %s\n", name, out, datatype);
}
return 0;
}"[T]he programs are intended to be illustrative, not bullet-proof, there are significant restrictions on dcl."
In context this code illustrates the points they're trying to convey about complicated declarations quite well and is a precursor to understanding typedef later in the book.
Also, you left the nice inline comments off the variable declaration block.