/*---------------------------------------------------------------------------*/ static void next_statement(void) { int var; struct for_state *fs; struct typevalue t; /* FIXME: support 'NEXT' on its own, also loop down the stack so if you GOTO out of a layer of NEXT the right thing occurs */ var = tokenizer_variable_num(); accept_tok(TOKENIZER_INTVAR); /* FIXME: make the for stack just use pointers so it compiles better */ fs = &for_stack[for_stack_ptr - 1]; if(for_stack_ptr > 0 && var == fs->for_variable) { ubasic_get_variable(var, &t, 0, NULL); t.d.i += fs->step; ubasic_set_variable(var, &t, 0,NULL); /* NEXT end depends upon sign of STEP */ if ((fs->step >= 0 && t.d.i <= fs->to) || (fs->step < 0 && t.d.i >= fs->to)) tokenizer_goto(fs->resume_token); else for_stack_ptr--; } else ubasic_error("Mismatched NEXT"); }
/*---------------------------------------------------------------------------*/ static void return_statement(void) { if(gosub_stack_ptr > 0) { gosub_stack_ptr--; tokenizer_goto(gosub_stack[gosub_stack_ptr]); } else { DEBUG_PRINTF("return_statement: non-matching return\n"); } }
/*---------------------------------------------------------------------------*/ static void jump_linenum(int linenum) { char const* pos = index_find(linenum); if(pos != NULL) { DEBUG_PRINTF("jump_linenum: Going to line %d.\n", linenum); tokenizer_goto(pos); } else { /* We'll try to find a yet-unindexed line to jump to. */ DEBUG_PRINTF("jump_linenum: Calling jump_linenum_slow %d.\n", linenum); jump_linenum_slow(linenum); } }
/*---------------------------------------------------------------------------*/ void tokenizer_init(const char *program) { tokenizer_goto(program); current_token = get_next_token(); }