comparison src/parse.y @ 4173:2aea727f516f

[project @ 2002-11-12 23:05:40 by jwe]
author jwe
date Tue, 12 Nov 2002 23:05:41 +0000
parents 04694e5b4239
children bf9c5ca4c3f3
comparison
equal deleted inserted replaced
4172:2e94b2abfe6d 4173:2aea727f516f
217 static tree_command * 217 static tree_command *
218 make_for_command (token *for_tok, tree_argument_list *lhs, 218 make_for_command (token *for_tok, tree_argument_list *lhs,
219 tree_expression *expr, tree_statement_list *body, 219 tree_expression *expr, tree_statement_list *body,
220 token *end_tok, octave_comment_list *lc); 220 token *end_tok, octave_comment_list *lc);
221 221
222 // Build a break command. 222 // Build a break expression.
223 static tree_command * 223 static tree_expression *
224 make_break_command (token *break_tok); 224 make_break_expression (token *break_tok);
225 225
226 // Build a continue command. 226 // Build a continue expression.
227 static tree_command * 227 static tree_expression *
228 make_continue_command (token *continue_tok); 228 make_continue_expression (token *continue_tok);
229 229
230 // Build a return command. 230 // Build a return expression.
231 static tree_command * 231 static tree_expression *
232 make_return_command (token *return_tok); 232 make_return_expression (token *return_tok);
233 233
234 // Start an if command. 234 // Start an if command.
235 static tree_if_command_list * 235 static tree_if_command_list *
236 start_if_command (tree_expression *expr, tree_statement_list *list); 236 start_if_command (tree_expression *expr, tree_statement_list *list);
237 237
416 %type <tree_type> input 416 %type <tree_type> input
417 %type <tree_constant_type> constant magic_colon 417 %type <tree_constant_type> constant magic_colon
418 %type <tree_matrix_type> matrix_rows matrix_rows1 418 %type <tree_matrix_type> matrix_rows matrix_rows1
419 %type <tree_cell_type> cell_rows cell_rows1 419 %type <tree_cell_type> cell_rows cell_rows1
420 %type <tree_expression_type> title matrix cell 420 %type <tree_expression_type> title matrix cell
421 %type <tree_expression_type> primary_expr postfix_expr prefix_expr binary_expr 421 %type <tree_expression_type> primary_expr postfix_expr prefix_expr
422 %type <tree_expression_type> simple_expr colon_expr assign_expr expression 422 %type <tree_expression_type> binary_expr simple_expr colon_expr
423 %type <tree_expression_type> assign_expr jump_expr expression
423 %type <tree_identifier_type> identifier 424 %type <tree_identifier_type> identifier
424 %type <octave_user_function_type> function1 function2 function3 425 %type <octave_user_function_type> function1 function2 function3
425 %type <tree_index_expression_type> word_list_cmd 426 %type <tree_index_expression_type> word_list_cmd
426 %type <tree_colon_expression_type> colon_expr1 427 %type <tree_colon_expression_type> colon_expr1
427 %type <tree_argument_list_type> arg_list word_list assign_lhs 428 %type <tree_argument_list_type> arg_list word_list assign_lhs
428 %type <tree_argument_list_type> cell_or_matrix_row 429 %type <tree_argument_list_type> cell_or_matrix_row
429 %type <tree_parameter_list_type> param_list param_list1 430 %type <tree_parameter_list_type> param_list param_list1
430 %type <tree_parameter_list_type> return_list return_list1 431 %type <tree_parameter_list_type> return_list return_list1
431 %type <tree_command_type> command select_command loop_command 432 %type <tree_command_type> command select_command loop_command
432 %type <tree_command_type> jump_command except_command function 433 %type <tree_command_type> except_command function
433 %type <tree_if_command_type> if_command 434 %type <tree_if_command_type> if_command
434 %type <tree_if_clause_type> elseif_clause else_clause 435 %type <tree_if_clause_type> elseif_clause else_clause
435 %type <tree_if_command_list_type> if_cmd_list1 if_cmd_list 436 %type <tree_if_command_list_type> if_cmd_list1 if_cmd_list
436 %type <tree_switch_command_type> switch_command 437 %type <tree_switch_command_type> switch_command
437 %type <tree_switch_case_type> switch_case default_case 438 %type <tree_switch_case_type> switch_case default_case
783 ABORT_PARSE; 784 ABORT_PARSE;
784 } 785 }
785 ; 786 ;
786 787
787 simple_expr : colon_expr 788 simple_expr : colon_expr
789 { $$ = $1; }
790 | jump_expr
788 { $$ = $1; } 791 { $$ = $1; }
789 | simple_expr LSHIFT simple_expr 792 | simple_expr LSHIFT simple_expr
790 { $$ = make_binary_op (LSHIFT, $1, $2, $3); } 793 { $$ = make_binary_op (LSHIFT, $1, $2, $3); }
791 | simple_expr RSHIFT simple_expr 794 | simple_expr RSHIFT simple_expr
792 { $$ = make_binary_op (RSHIFT, $1, $2, $3); } 795 { $$ = make_binary_op (RSHIFT, $1, $2, $3); }
889 { $$ = $1; } 892 { $$ = $1; }
890 | select_command 893 | select_command
891 { $$ = $1; } 894 { $$ = $1; }
892 | loop_command 895 | loop_command
893 { $$ = $1; } 896 { $$ = $1; }
894 | jump_command
895 { $$ = $1; }
896 | except_command 897 | except_command
897 { $$ = $1; } 898 { $$ = $1; }
898 | function 899 | function
899 { $$ = $1; } 900 { $$ = $1; }
900 | plot_command 901 | plot_command
1039 1040
1040 // ======= 1041 // =======
1041 // Jumping 1042 // Jumping
1042 // ======= 1043 // =======
1043 1044
1044 jump_command : BREAK 1045 jump_expr : BREAK
1045 { 1046 {
1046 if (! ($$ = make_break_command ($1))) 1047 if (! ($$ = make_break_expression ($1)))
1047 ABORT_PARSE; 1048 ABORT_PARSE;
1048 } 1049 }
1049 | CONTINUE 1050 | CONTINUE
1050 { 1051 {
1051 if (! ($$ = make_continue_command ($1))) 1052 if (! ($$ = make_continue_expression ($1)))
1052 ABORT_PARSE; 1053 ABORT_PARSE;
1053 } 1054 }
1054 | FUNC_RET 1055 | FUNC_RET
1055 { 1056 {
1056 if (! ($$ = make_return_command ($1))) 1057 if (! ($$ = make_return_expression ($1)))
1057 ABORT_PARSE; 1058 ABORT_PARSE;
1058 } 1059 }
1059 ; 1060 ;
1060 1061
1061 // ========== 1062 // ==========
2241 } 2242 }
2242 2243
2243 return retval; 2244 return retval;
2244 } 2245 }
2245 2246
2246 // Build a break command. 2247 // Build a break expression.
2247 2248
2248 static tree_command * 2249 static tree_expression *
2249 make_break_command (token *break_tok) 2250 make_break_expression (token *break_tok)
2250 { 2251 {
2251 tree_command *retval = 0; 2252 tree_expression *retval = 0;
2252 2253
2253 int l = break_tok->line (); 2254 int l = break_tok->line ();
2254 int c = break_tok->column (); 2255 int c = break_tok->column ();
2255 2256
2256 if (lexer_flags.looping || lexer_flags.defining_func 2257 if (lexer_flags.looping || lexer_flags.defining_func
2257 || reading_script_file || evaluating_function_body 2258 || reading_script_file || evaluating_function_body
2258 || evaluating_looping_command) 2259 || evaluating_looping_command)
2259 retval = new tree_break_command (l, c); 2260 retval = new tree_break_expression (l, c);
2260 else 2261 else
2261 retval = new tree_no_op_command ("break", l, c); 2262 yyerror ("invalid use of break");
2262 2263
2263 return retval; 2264 return retval;
2264 } 2265 }
2265 2266
2266 // Build a continue command. 2267 // Build a continue expression.
2267 2268
2268 static tree_command * 2269 static tree_expression *
2269 make_continue_command (token *continue_tok) 2270 make_continue_expression (token *continue_tok)
2270 { 2271 {
2271 tree_command *retval = 0; 2272 tree_expression *retval = 0;
2272 2273
2273 int l = continue_tok->line (); 2274 int l = continue_tok->line ();
2274 int c = continue_tok->column (); 2275 int c = continue_tok->column ();
2275 2276
2276 if (lexer_flags.looping || evaluating_looping_command) 2277 if (lexer_flags.looping || evaluating_looping_command)
2277 retval = new tree_continue_command (l, c); 2278 retval = new tree_continue_expression (l, c);
2278 else 2279 else
2279 retval = new tree_no_op_command ("continue", l, c); 2280 yyerror ("invalid use of continue");
2280 2281
2281 return retval; 2282 return retval;
2282 } 2283 }
2283 2284
2284 // Build a return command. 2285 // Build a return expression.
2285 2286
2286 static tree_command * 2287 static tree_expression *
2287 make_return_command (token *return_tok) 2288 make_return_expression (token *return_tok)
2288 { 2289 {
2289 tree_command *retval = 0; 2290 tree_expression *retval = 0;
2290 2291
2291 int l = return_tok->line (); 2292 int l = return_tok->line ();
2292 int c = return_tok->column (); 2293 int c = return_tok->column ();
2293 2294
2294 if (lexer_flags.defining_func || reading_script_file 2295 if (lexer_flags.defining_func || reading_script_file
2295 || evaluating_function_body) 2296 || evaluating_function_body)
2296 retval = new tree_return_command (l, c); 2297 retval = new tree_return_expression (l, c);
2297 else 2298 else
2298 retval = new tree_no_op_command ("return", l, c); 2299 yyerror ("invalid use of return");
2299 2300
2300 return retval; 2301 return retval;
2301 } 2302 }
2302 2303
2303 // Start an if command. 2304 // Start an if command.
2863 2864
2864 global_command = 0; 2865 global_command = 0;
2865 2866
2866 OCTAVE_QUIT; 2867 OCTAVE_QUIT;
2867 2868
2868 bool quit = (tree_return_command::returning 2869 bool quit = (tree_return_expression::returning
2869 || tree_break_command::breaking); 2870 || tree_break_expression::breaking);
2870 2871
2871 if (tree_return_command::returning) 2872 if (tree_return_expression::returning)
2872 tree_return_command::returning = 0; 2873 tree_return_expression::returning = 0;
2873 2874
2874 if (tree_break_command::breaking) 2875 if (tree_break_expression::breaking)
2875 tree_break_command::breaking--; 2876 tree_break_expression::breaking--;
2876 2877
2877 if (error_state) 2878 if (error_state)
2878 { 2879 {
2879 error ("near line %d of file `%s'", input_line_number, 2880 error ("near line %d of file `%s'", input_line_number,
2880 curr_fcn_file_full_name.c_str ()); 2881 curr_fcn_file_full_name.c_str ());
3556 delete command; 3557 delete command;
3557 3558
3558 command = 0; 3559 command = 0;
3559 3560
3560 if (error_state 3561 if (error_state
3561 || tree_return_command::returning 3562 || tree_return_expression::returning
3562 || tree_break_command::breaking 3563 || tree_break_expression::breaking
3563 || tree_continue_command::continuing) 3564 || tree_continue_expression::continuing)
3564 break; 3565 break;
3565 } 3566 }
3566 else if (parser_end_of_input) 3567 else if (parser_end_of_input)
3567 break; 3568 break;
3568 } 3569 }