/*---------------------------------------------------------------------------*/ 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 line_statements(void) { line_num = tokenizer_num(); DEBUG_PRINTF("----------- Line number %d ---------\n", line_num); index_add(line_num, tokenizer_pos()); accept_tok(TOKENIZER_NUMBER); statements(); return; }
/*---------------------------------------------------------------------------*/ static void line_statement(void) { DEBUG_PRINTF("----------- Line number %d ---------\n", tokenizer_num()); index_add(tokenizer_num(), tokenizer_pos()); accept(TOKENIZER_NUMBER); statement(); return; }
/*---------------------------------------------------------------------------*/ 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 for_statement(void) { var_t for_variable; value_t to, step = 1; struct typevalue t; for_variable = tokenizer_variable_num(); accept_tok(TOKENIZER_INTVAR); accept_tok(TOKENIZER_EQ); expr(&t); typecheck_int(&t); /* The set also typechecks the variable */ ubasic_set_variable(for_variable, &t, 0, NULL); accept_tok(TOKENIZER_TO); to = intexpr(); if (current_token == TOKENIZER_STEP) { accept_tok(TOKENIZER_STEP); step = intexpr(); } if (!statement_end()) syntax_error(); /* Save a pointer to the : or CR, when we return to statements it will do the right thing */ if(for_stack_ptr < MAX_FOR_STACK_DEPTH) { struct for_state *fs = &for_stack[for_stack_ptr]; fs->resume_token = tokenizer_pos(); fs->for_variable = for_variable; fs->to = to; fs->step = step; DEBUG_PRINTF("for_statement: new for, var %d to %d step %d\n", fs->for_variable, fs->to, fs->step); for_stack_ptr++; } else { DEBUG_PRINTF("for_statement: for stack depth exceeded\n"); } }