Expert C Programming

(Jeff_L) #1

/ figure out the identifier type /


{


char *s = this.string;


if (!strcmp(s, "const")) {


strcpy(s, "read-only");


return QUALIFIER;


}


if (!strcmp(s, "volatile")) return QUALIFIER;


if (!strcmp(s, "void")) return TYPE;


if (!strcmp(s, "char")) return TYPE;


if (!strcmp(s, "signed")) return TYPE;


if (!strcmp(s, "unsigned")) return TYPE;


if (!strcmp(s, "short")) return TYPE;


if (!strcmp(s, "int")) return TYPE;


if (!strcmp(s, "long")) return TYPE;


if (!strcmp(s, "float")) return TYPE;


if (!strcmp(s, "double")) return TYPE;


if (!strcmp(s, "struct")) return TYPE;


if (!strcmp(s, "union")) return TYPE;


if (!strcmp(s, "enum")) return TYPE;


return IDENTIFIER;


}


void gettoken(void)


{ / read next token into "this" /


char *p = this.string;


/ read past any spaces /


while ((*p = getchar()) == ' ');


if (isalnum(*p)) {


/ it starts with A-Z,1-9 read in identifier /


while (isalnum(*++p = getchar()));


ungetc(*p, stdin);


*p = '\0';


this.type = classify_string();


return;


}


this.string[1] = '\0';


this.type = *p;


return;


}


void initialize(),


get_array(), get_params(), get_lparen(),


get_ptr_part(), get_type();


void (*nextstate)(void) = initialize;

Free download pdf