/* Interpret a single statement or block of code. When interp_block() returns from its initial call, the final brace (or a return) in main() has been encountered. */ void interp_block(void) { int value; char block = 0; do { token_type = get_token(); /* If interpreting single statement, return on first semicolon. */ /* see what kind of token is up */ if(token_type == IDENTIFIER) { /* Not a keyword, so process expression. */ putback(); /* restore token to input stream for further processing by eval_exp() */ eval_exp(&value); /* process the expression */ if(*token!=';') sntx_err(SEMI_EXPECTED); } else if(token_type==BLOCK) { /* if block delimiter */ if(*token == '{') /* is a block */ block = 1; /* interpreting block, not statement */ else return; /* is a }, so return */ } else /* is keyword */ switch(tok) { case CHAR: case INT: /* declare local variables */ putback(); decl_local(); break; case RETURN: /* return from function call */ func_ret(); return; case IF: /* process an if statement */ exec_if(); break; case ELSE: /* process an else statement */ find_eob(); /* find end of else block and continue execution */ break; case WHILE: /* process a while loop */ exec_while(); break; case DO: /* process a do-while loop */ exec_do(); break; case FOR: /* process a for loop */ exec_for(); break; case END: exit(0); } } while (tok != FINISHED && block); }
void interp_block() { int value; char block = 0; do { token_type = get_token(); if(token_type==IDENTIFIER) { putback(); eval_exp(&value); if(*token!=';') sntx_err(SEMI_EXPECTED); } else if(token_type==BLOCK) { if(*token=='{') block = 1; else return; } else switch(tok) { case CHAR: case INT: putback(); decl_local(); break; case RETURN: func_ret(); return; case IF: exec_if(); break; case ELSE: find_eob(); break; case WHILE: exec_while(); break; case DO: exec_do(); break; case FOR: exec_for(); break; case END: return; } } while (tok != FINISHED && block); }