K & R C Programs Exercise 5-20.

K and R C, Solution to Exercise 5-20:
K and R C Programs Exercises provides the solution to all the exercises in the C Programming Language (2nd Edition). You can learn and solve K&R C Programs Exercise.
C Program to expand dcl to handle declarations with function argument types, qualifiers like const, and so on. Read more about C Programming Language .
/***********************************************************
* You can use all the programs on www.c-program-example.com
* for personal and learning purposes. For permissions to use the
* programs for commercial purposes,
* contact info@c-program-example.com
* To find more C programs, do visit www.c-program-example.com
* and browse!
*
* Happy Coding
***********************************************************/


#include<stdio.h>
#include<string.h>
#include<ctype.h>
enum { NAME, PARENS, BRACKETS};
enum { NO, YES};
void dcl(void);
void dirdcl(void);
void errmsg(char *);
void dclspec(void);
int typespec(void);
int typeequal(void);
int compare(char **, char**);
void parmdcl(void);

int gettoken(void);
extern int tokentype;
extern char token[];
extern char name[];
extern char datatype[];
extern char out[];
extern int prevtoken;


//dcl:parse a declarator
void dcl(void)
{
int ns;
for(ns = 0; gettoken() == '*';)
ns++;
dirdcl();
while(ns --> 0)
strcat(out, "pointer to");
}


//dirdcl: parse a direct declaration
void dirdcl(void)
{
int type;
void parmdcl(void);
if(tokentype == '('){
dcl();
if(tokentype != ')')
errmsg("error:missimg)n");
}
else if(tokentype == NAME){
if(name[0] == '