Mercurial > hg > octave-max
comparison src/oct-parse.yy @ 10188:97ae300aa73a
improve implementation of break, continue, and return commands
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Fri, 22 Jan 2010 14:37:33 -0500 |
parents | cd96d29c5efa |
children | 37a08e0ce2dc |
comparison
equal
deleted
inserted
replaced
10187:a44d15813a39 | 10188:97ae300aa73a |
---|---|
2486 tree_command *retval = 0; | 2486 tree_command *retval = 0; |
2487 | 2487 |
2488 int l = break_tok->line (); | 2488 int l = break_tok->line (); |
2489 int c = break_tok->column (); | 2489 int c = break_tok->column (); |
2490 | 2490 |
2491 // We check to see if we are evaluating a function, script, or loop | 2491 retval = new tree_break_command (l, c); |
2492 // so that we don't turn eval ("break;") inside a function, script, | |
2493 // or loop into a no-op command. | |
2494 | |
2495 if (lexer_flags.looping || current_function_depth > 0 | |
2496 || reading_script_file || tree_evaluator::in_fcn_or_script_body | |
2497 || tree_evaluator::in_loop_command) | |
2498 retval = new tree_break_command (l, c); | |
2499 else | |
2500 retval = new tree_no_op_command ("break", l, c); | |
2501 | 2492 |
2502 return retval; | 2493 return retval; |
2503 } | 2494 } |
2504 | 2495 |
2505 // Build a continue command. | 2496 // Build a continue command. |
2510 tree_command *retval = 0; | 2501 tree_command *retval = 0; |
2511 | 2502 |
2512 int l = continue_tok->line (); | 2503 int l = continue_tok->line (); |
2513 int c = continue_tok->column (); | 2504 int c = continue_tok->column (); |
2514 | 2505 |
2515 // We check to see if we are evaluating a loop so that we don't turn | 2506 retval = new tree_continue_command (l, c); |
2516 // eval ("continue;") into a no-op command inside a loop. | |
2517 | |
2518 if (lexer_flags.looping || tree_evaluator::in_loop_command) | |
2519 retval = new tree_continue_command (l, c); | |
2520 else | |
2521 retval = new tree_no_op_command ("continue", l, c); | |
2522 | 2507 |
2523 return retval; | 2508 return retval; |
2524 } | 2509 } |
2525 | 2510 |
2526 // Build a return command. | 2511 // Build a return command. |
2531 tree_command *retval = 0; | 2516 tree_command *retval = 0; |
2532 | 2517 |
2533 int l = return_tok->line (); | 2518 int l = return_tok->line (); |
2534 int c = return_tok->column (); | 2519 int c = return_tok->column (); |
2535 | 2520 |
2536 if (Vdebugging) | 2521 retval = new tree_return_command (l, c); |
2537 { | |
2538 Vdebugging = false; | |
2539 | |
2540 retval = new tree_no_op_command ("return", l, c); | |
2541 } | |
2542 else | |
2543 { | |
2544 // We check to see if we are evaluating a function or script so | |
2545 // that we don't turn eval ("return;") inside a function, script, | |
2546 // or loop into a no-op command. | |
2547 | |
2548 if (current_function_depth > 0 || reading_script_file | |
2549 || tree_evaluator::in_fcn_or_script_body) | |
2550 retval = new tree_return_command (l, c); | |
2551 else | |
2552 retval = new tree_no_op_command ("return", l, c); | |
2553 } | |
2554 | 2522 |
2555 return retval; | 2523 return retval; |
2556 } | 2524 } |
2557 | 2525 |
2558 // Start an if command. | 2526 // Start an if command. |