Expert C Programming

(Jeff_L) #1

int main()


/ Cdecl written as a finite state machine /


{


/* transition through the states, until the pointer


is null */


while (nextstate != NULL)


(*nextstate)();


return 0;


}


void initialize()


{


gettoken();


while (this.type != IDENTIFIER) {


push(this);


gettoken();


}


printf("%s is ", this.string);


gettoken();


nextstate = get_array;


}


void get_array()


{


nextstate = get_params;


while (this.type == '[') {


printf("array ");


gettoken();/ a number or ']' /


if (isdigit(this.string[0])) {


printf("0..%d ", atoi(this.string) - 1);


gettoken();/ read the ']' /


}


gettoken();/ read next past the ']' /


printf("of ");


nextstate = get_lparen;


}


}


void get_params()


{


nextstate = get_lparen;


if (this.type == '(') {


while (this.type != ')') {


gettoken();


}


gettoken();


printf("function returning ");

Free download pdf