/*---------------------------------------------------------------------------*/ static void go_statement(void) { int linenum; uint8_t t; t = accept_either(TOKENIZER_TO, TOKENIZER_SUB); if (t == TOKENIZER_TO) { linenum = intexpr(); DEBUG_PRINTF("go_statement: go to %d.\n", linenum); if (!statement_end()) syntax_error(); DEBUG_PRINTF("go_statement: jumping.\n"); jump_linenum(linenum); return; } linenum = intexpr(); if (!statement_end()) syntax_error(); if(gosub_stack_ptr < MAX_GOSUB_STACK_DEPTH) { gosub_stack[gosub_stack_ptr] = tokenizer_pos(); gosub_stack_ptr++; jump_linenum(linenum); } else { DEBUG_PRINTF("gosub_statement: gosub stack exhausted\n"); ubasic_error("Return without gosub"); } }
//static void gosub_statement(void) void gosub_statement(void) { int linenum,nextnum; char *tmpptr, *tmpnextptr; accept(TOKENIZER_GOSUB); linenum = tokenizer_num(); accept(TOKENIZER_NUMBER); tmpptr = ptr; tmpnextptr = nextptr; while(tokenizer_token() != TOKENIZER_CR && tokenizer_token() != TOKENIZER_ENDOFINPUT){ tokenizer_next(); } accept(TOKENIZER_CR); nextnum = tokenizer_num(); ptr = tmpptr; nextptr = tmpnextptr; if(gosub_stack_ptr < MAX_GOSUB_STACK_DEPTH) { gosub_stack[gosub_stack_ptr] = nextnum; gosub_stack_ptr++; jump_linenum(linenum); }else{ } }
//static void return_statement(void) void return_statement(void) { accept(TOKENIZER_RETURN); if(gosub_stack_ptr > 0) { gosub_stack_ptr--; jump_linenum(gosub_stack[gosub_stack_ptr]); }else{ } }
static void goto_statement (void) { int to; accept(T_GOTO); to = tokenizer_num(); accept(T_NUMBER); accept(T_EOL); jump_linenum(to); }
/*---------------------------------------------------------------------------*/ static void return_statement(void) { accept(TOKENIZER_RETURN); if(gosub_stack_ptr > 0) { gosub_stack_ptr--; jump_linenum(gosub_stack[gosub_stack_ptr]); } else { DEBUG_PRINTF("return_statement: non-matching return\n"); } }
static void if_statement (void) { int r, to; accept(T_IF); r = relation(); accept(T_THEN); to = tokenizer_num(); accept(T_NUMBER); accept(T_EOL); if (r) jump_linenum(to); }
/*---------------------------------------------------------------------------*/ void restore_statement(void) { int linenum = 0; if (!statement_end()) linenum = intexpr(); if (linenum) { tokenizer_push(); jump_linenum(linenum); data_position = tokenizer_pos(); tokenizer_pop(); } else data_position = program_ptr; data_seek = 1; }
/*---------------------------------------------------------------------------*/ static void gosub_statement(void) { int linenum; accept(TOKENIZER_GOSUB); linenum = tokenizer_num(); accept(TOKENIZER_NUMBER); accept(TOKENIZER_CR); if(gosub_stack_ptr < MAX_GOSUB_STACK_DEPTH) { gosub_stack[gosub_stack_ptr] = tokenizer_num(); gosub_stack_ptr++; jump_linenum(linenum); } else { DEBUG_PRINTF("gosub_statement: gosub stack exhausted\n"); } }
//static void next_statement(void) void next_statement(void) { long var; accept(TOKENIZER_NEXT); var = tokenizer_variable_num(); accept(TOKENIZER_VARIABLE); if(for_stack_ptr > 0 && var == for_stack[for_stack_ptr - 1].for_variable) { ubasic_set_variable(var, ubasic_get_variable(var) + 1); if(ubasic_get_variable(var) <= for_stack[for_stack_ptr - 1].to) { jump_linenum(for_stack[for_stack_ptr - 1].line_after_for); }else{ for_stack_ptr--; accept(TOKENIZER_CR); } }else{ accept(TOKENIZER_CR); } }
/*---------------------------------------------------------------------------*/ static void next_statement(void) { int var; accept(TOKENIZER_NEXT); var = tokenizer_variable_num(); accept(TOKENIZER_VARIABLE); if(for_stack_ptr > 0 && var == for_stack[for_stack_ptr - 1].for_variable) { ubasic_set_variable(var, ubasic_get_variable(var) + 1); if(ubasic_get_variable(var) <= for_stack[for_stack_ptr - 1].to) { jump_linenum(for_stack[for_stack_ptr - 1].line_after_for); } else { for_stack_ptr--; accept(TOKENIZER_CR); } } else { DEBUG_PRINTF("next_statement: non-matching next (expected %d, found %d)\n", for_stack[for_stack_ptr - 1].for_variable, var); accept(TOKENIZER_CR); } }
//static void goto_statement(void) void goto_statement(void) { accept(TOKENIZER_GOTO); jump_linenum(tokenizer_num()); }