main(){ /* 将标记压入堆栈中,直到遇见标识符 */ read_to_first_identifer(); deal_with_declarator(); printf("\n"); return 0; }
int _tmain(int argc, _TCHAR* argv[]){ read_to_first_identifier(); deal_with_declarator(); printf("\n"); getchar(); return 0; }
void deal_with_declarator(){ //Check if array/func exist switch(currToken.mType){ case '[': deal_with_arrays(); break; case '(': deal_with_function_args(); } deal_with_pointers(); while(top >= 0 ){ if(tokenStack[top].mType == '('){ pop; getToken(); deal_with_declarator(); }else{ printf("%s ",pop.mStr); } } }
deal_with_declarator(){ /*处理标识符之后可能存在的数组/函数 */ switch(cur.type){ case '[': deal_with_arrays(); break; case '(': deal_with_function_args(); } deal_with_pointers(); /* 处理在读入到标识符之前压入到堆栈中的符号 */ while(top >= 0){ if(stack[top].type == '('){ pop; gettoken(); deal_with_declarator(); }else{ printf("%s ", pop.string); } } }
void deal_with_declarator() { if(curr_token.type == '[') deal_with_arrays(); if(curr_token.type == '(') deal_with_function_args(); deal_with_any_pointers(); while(stack_top > -1) { if(token_stack[stack_top].type == '(') { if(curr_token.type != ')') { printf("Bad Syntax! Expected ')', got %s\n", curr_token.string); done(); } get_token(); stack_top--; deal_with_declarator(); } else { printf("%s ", token_stack[stack_top].string); stack_top--; } } }
int main() { read_to_first_identifier(); deal_with_declarator(); done(); }