/* 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 exec_conditional(env_t* env, ast_t* ast) { /* if */ if(exec_if(env, ast->data.conditional.if_statement)) { return; } else { if(ast->data.conditional.elif_statements != NULL) { size_t i; /* elif */ for(i = 0; i < ast->data.conditional.elif_statements->data.elif_statements.count; i++) { if(exec_if(env, ast->data.conditional.elif_statements->data.elif_statements.elif_statements[i])) { return; } } } if(ast->data.conditional.else_statement != NULL) { /* else */ exec_statements(env, ast->data.conditional.else_statement); } } }
static void unit_mod_inet_time(XmlTag *tag, XmlTag **ans) { DEFINE_XTV(XTV_INET_ID, XTV_ETIME_START_, XTV_ETIME_END_); MbbInetPoolEntry *entry; time_t start, end; gint id; start = end = MBB_TIME_UNSET; MBB_XTV_CALL(&id, &start, &end); if (start == MBB_TIME_UNSET && end == MBB_TIME_UNSET) final *ans = mbb_xml_msg(MBB_MSG_TIME_MISSED); mbb_lock_writer_lock(); on_final { mbb_lock_writer_unlock(); } entry = mbb_inet_pool_get(mbb_unit_get_pool(), id); if (entry == NULL) final *ans = mbb_xml_msg(MBB_MSG_UNKNOWN_INET); exec_if(start = entry->start, start == MBB_TIME_UNSET); exec_if(end = entry->end, end == MBB_TIME_UNSET); *ans = mbb_time_test_order(start, end, mbb_unit_get_start(entry->owner->ptr), mbb_unit_get_end(entry->owner->ptr)); if (*ans == NULL) { GError *error = NULL; if (! mbb_db_inet_pool_mod_time(entry->id, start, end, &error)) final *ans = mbb_xml_msg_from_error(error); }
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); }
int run_program(char* p_buf){ int i; // I REMOVED THIS AND PUT IT IN FRONT OF THE CALL... //NMS-REMOVAL init_namespace();// Do you need it? May be you want to use the same namespace prog = p_buf; scan_labels(); /* find the labels in the program */ ftos = 0; /* initialize the FOR stack index */ gtos = 0; /* initialize the GOSUB stack index */ do { bas_token_type = get_token(); // printf("ttype=%d bas_tok=%d <%s>\n", bas_token_type, bas_tok, bas_token); /* check for assignment statement */ if(bas_token_type==VARIABLE) { putback(); /* return the var to the input stream */ assignment(); /* must be assignment statement */ } else /* is command */ switch(bas_tok) { case PRINT: print(); break; case GOTO: exec_goto(); break; case IF: exec_if(); break; case FOR: exec_for(); break; case NEXT: next(); break; case INPUT: input(); break; case GOSUB: gosub(); break; case RETURN: greturn(); break; case COMMENT: do{ get_token(); if(bas_tok==EOL || bas_tok==FINISHED) break; } while (1==1); break; case CONTINUE: do{ get_token(); if(bas_tok==EOL || bas_tok==FINISHED) break; } while (1==1); break; case END: printf("variables----------------------------%s\n",""); for (i=0;i<varnamelast;i++){ printf("%14s - %19.7f\n", varname[i] , variables[i] ); } exit(0); } } while (bas_tok != FINISHED); return 0; }// run_program