comparison src/parse.y @ 2846:52e7c4509983

[project @ 1997-03-26 23:27:35 by jwe]
author jwe
date Wed, 26 Mar 1997 23:29:12 +0000
parents 60ae49e1284f
children 8b262e771614
comparison
equal deleted inserted replaced
2845:b11fb5e85dc5 2846:52e7c4509983
77 77
78 // If TRUE, generate a warning for the comma in things like 78 // If TRUE, generate a warning for the comma in things like
79 // 79 //
80 // octave> global a, b = 2 80 // octave> global a, b = 2
81 // 81 //
82 static bool Vwarn_comma_in_global_decl; 82 static bool Vwarn_comma_in_declaration;
83 83
84 // If TRUE, generate warning if declared function name disagrees with 84 // If TRUE, generate warning if declared function name disagrees with
85 // the name of the file in which it is defined. 85 // the name of the file in which it is defined.
86 static bool Vwarn_function_name_clash; 86 static bool Vwarn_function_name_clash;
87 87
237 237
238 // Make an index expression. 238 // Make an index expression.
239 static tree_index_expression *make_index_expression 239 static tree_index_expression *make_index_expression
240 (tree_indirect_ref *indir, tree_argument_list *args); 240 (tree_indirect_ref *indir, tree_argument_list *args);
241 241
242 // Make a declaration command.
243 static tree_decl_command *make_decl_command
244 (int tok, token *tok_val, tree_decl_init_list *lst);
245
242 // Finish building a matrix list. 246 // Finish building a matrix list.
243 static tree_expression *finish_matrix (tree_matrix *m); 247 static tree_expression *finish_matrix (tree_matrix *m);
244 248
245 // Maybe print a warning. Duh. 249 // Maybe print a warning. Duh.
246 static void maybe_warn_missing_semi (tree_statement_list *); 250 static void maybe_warn_missing_semi (tree_statement_list *);
251
252 // Maybe print a warning. Duh.
253 static void maybe_warn_comma_in_decl (void);
247 254
248 // Set the print flag for a statement based on the separator type. 255 // Set the print flag for a statement based on the separator type.
249 static void set_stmt_print_flag (tree_statement_list *, char, bool); 256 static void set_stmt_print_flag (tree_statement_list *, char, bool);
250 257
251 #define ABORT_PARSE \ 258 #define ABORT_PARSE \
288 tree_if_clause *tree_if_clause_type; 295 tree_if_clause *tree_if_clause_type;
289 tree_if_command_list *tree_if_command_list_type; 296 tree_if_command_list *tree_if_command_list_type;
290 tree_switch_command *tree_switch_command_type; 297 tree_switch_command *tree_switch_command_type;
291 tree_switch_case *tree_switch_case_type; 298 tree_switch_case *tree_switch_case_type;
292 tree_switch_case_list *tree_switch_case_list_type; 299 tree_switch_case_list *tree_switch_case_list_type;
293 tree_global *tree_global_type; 300 tree_decl_elt *tree_decl_elt_type;
294 tree_global_init_list *tree_global_init_list_type; 301 tree_decl_init_list *tree_decl_init_list_type;
295 tree_global_command *tree_global_command_type; 302 tree_decl_command *tree_decl_command_type;
296 tree_statement *tree_statement_type; 303 tree_statement *tree_statement_type;
297 tree_statement_list *tree_statement_list_type; 304 tree_statement_list *tree_statement_list_type;
298 tree_plot_command *tree_plot_command_type; 305 tree_plot_command *tree_plot_command_type;
299 subplot *subplot_type; 306 subplot *subplot_type;
300 subplot_list *subplot_list_type; 307 subplot_list *subplot_list_type;
321 %token <tok_val> IF ELSEIF ELSE 328 %token <tok_val> IF ELSEIF ELSE
322 %token <tok_val> SWITCH CASE OTHERWISE 329 %token <tok_val> SWITCH CASE OTHERWISE
323 %token <tok_val> BREAK CONTINUE FUNC_RET 330 %token <tok_val> BREAK CONTINUE FUNC_RET
324 %token <tok_val> UNWIND CLEANUP 331 %token <tok_val> UNWIND CLEANUP
325 %token <tok_val> TRY CATCH 332 %token <tok_val> TRY CATCH
326 %token <tok_val> GLOBAL 333 %token <tok_val> GLOBAL STATIC
327 %token <tok_val> TEXT_ID 334 %token <tok_val> TEXT_ID
328 335
329 // Other tokens. 336 // Other tokens.
330 %token LEXICAL_ERROR 337 %token LEXICAL_ERROR
331 %token FCN SCREW_TWO 338 %token FCN SCREW_TWO
354 %type <tree_if_clause_type> elseif_clause else_clause 361 %type <tree_if_clause_type> elseif_clause else_clause
355 %type <tree_if_command_list_type> if_cmd_list1 if_cmd_list 362 %type <tree_if_command_list_type> if_cmd_list1 if_cmd_list
356 %type <tree_switch_command_type> switch_command 363 %type <tree_switch_command_type> switch_command
357 %type <tree_switch_case_type> switch_case default_case 364 %type <tree_switch_case_type> switch_case default_case
358 %type <tree_switch_case_list_type> case_list1 case_list 365 %type <tree_switch_case_list_type> case_list1 case_list
359 %type <tree_global_type> global_decl2 366 %type <tree_decl_elt_type> decl2
360 %type <tree_global_init_list_type> global_decl1 367 %type <tree_decl_init_list_type> decl1
361 %type <tree_global_command_type> global_decl 368 %type <tree_decl_command_type> declaration
362 %type <tree_statement_type> statement 369 %type <tree_statement_type> statement
363 %type <tree_statement_list_type> simple_list simple_list1 list list1 370 %type <tree_statement_list_type> simple_list simple_list1 list list1
364 %type <tree_statement_list_type> opt_list input1 371 %type <tree_statement_list_type> opt_list input1
365 %type <tree_plot_command_type> plot_command 372 %type <tree_plot_command_type> plot_command
366 %type <subplot_type> plot_command2 plot_options 373 %type <subplot_type> plot_command2 plot_options
598 605
599 ans_expression : expression 606 ans_expression : expression
600 { $$ = maybe_convert_to_ans_assign ($1); } 607 { $$ = maybe_convert_to_ans_assign ($1); }
601 ; 608 ;
602 609
603 global_decl : GLOBAL global_decl1 610 decl1 : decl2
604 { 611 { $$ = new tree_decl_init_list ($1); }
605 $$ = new tree_global_command ($2, $1->line (), 612 | decl1 decl2
606 $1->column ()); 613 {
607 } 614 $1->append ($2);
608 ; 615 $$ = $1;
609 616 }
610 global_decl1 : global_decl2 617 | decl1 ',' decl2
611 { $$ = new tree_global_init_list ($1); } 618 {
612 | global_decl1 optcomma global_decl2 619 maybe_warn_comma_in_decl ();
613 {
614 $1->append ($3); 620 $1->append ($3);
615 $$ = $1; 621 $$ = $1;
616 } 622 }
617 623 ;
618 global_decl2 : identifier 624
619 { $$ = new tree_global ($1); } 625 decl2 : identifier
626 { $$ = new tree_decl_elt ($1); }
620 | identifier '=' expression 627 | identifier '=' expression
621 { 628 {
622 tree_simple_assignment_expression *tmp_ass; 629 tree_simple_assignment_expression *tmp_ass;
623 tmp_ass = new tree_simple_assignment_expression 630 tmp_ass = new tree_simple_assignment_expression
624 ($1, $3, 0, 0, $2->line (), $2->column ()); 631 ($1, $3, 0, 0, $2->line (), $2->column ());
625 $$ = new tree_global (tmp_ass); 632 $$ = new tree_decl_elt (tmp_ass);
626 } 633 }
627 ; 634 ;
628 635
629 optcomma : // empty 636 declaration : GLOBAL decl1
630 | ',' 637 { $$ = make_decl_command (GLOBAL, $1, $2); }
631 { 638 | STATIC decl1
632 if (Vwarn_comma_in_global_decl) 639 { $$ = make_decl_command (STATIC, $1, $2); }
633 warning ("comma in global declaration not\
634 interpreted as a command separator");
635 }
636 ; 640 ;
637 641
638 command : plot_command 642 command : plot_command
639 { $$ = $1; } 643 { $$ = $1; }
640 | func_def 644 | func_def
641 { $$ = $1; } 645 { $$ = $1; }
642 | global_decl 646 | declaration
643 { $$ = $1; } 647 { $$ = $1; }
644 | switch_command 648 | switch_command
645 { $$ = $1; } 649 { $$ = $1; }
646 | if_command 650 | if_command
647 { $$ = $1; } 651 { $$ = $1; }
2244 ret_list->mark_as_formal_parameters (); 2248 ret_list->mark_as_formal_parameters ();
2245 2249
2246 return fcn->define_ret_list (ret_list); 2250 return fcn->define_ret_list (ret_list);
2247 } 2251 }
2248 2252
2253 // Make an index expression.
2254
2249 static tree_index_expression * 2255 static tree_index_expression *
2250 make_index_expression (tree_indirect_ref *indir, tree_argument_list *args) 2256 make_index_expression (tree_indirect_ref *indir, tree_argument_list *args)
2251 { 2257 {
2252 tree_index_expression *retval = 0; 2258 tree_index_expression *retval = 0;
2253 2259
2260 retval = new tree_index_expression (indir->ident (), args, l, c); 2266 retval = new tree_index_expression (indir->ident (), args, l, c);
2261 delete indir; 2267 delete indir;
2262 } 2268 }
2263 else 2269 else
2264 retval = new tree_index_expression (indir, args, l, c); 2270 retval = new tree_index_expression (indir, args, l, c);
2271
2272 return retval;
2273 }
2274
2275 // Make a declaration command.
2276
2277 static tree_decl_command *
2278 make_decl_command (int tok, token *tok_val, tree_decl_init_list *lst)
2279 {
2280 tree_decl_command *retval = 0;
2281
2282 int l = tok_val->line ();
2283 int c = tok_val->column ();
2284
2285 switch (tok)
2286 {
2287 case GLOBAL:
2288 retval = new tree_global_command (lst, l, c);
2289 break;
2290
2291 case STATIC:
2292 if (lexer_flags.defining_func)
2293 retval = new tree_static_command (lst, l, c);
2294 else
2295 {
2296 if (reading_script_file)
2297 warning ("ignoring static declaration near line %d of file `%s'",
2298 l, curr_fcn_file_full_name.c_str ());
2299 else
2300 warning ("ignoring static declaration near line %d", l);
2301 }
2302 break;
2303
2304 default:
2305 panic_impossible ();
2306 break;
2307 }
2265 2308
2266 return retval; 2309 return retval;
2267 } 2310 }
2268 2311
2269 // Finish building a matrix list. 2312 // Finish building a matrix list.
2348 warning ("unrecognized separator type!"); 2391 warning ("unrecognized separator type!");
2349 break; 2392 break;
2350 } 2393 }
2351 } 2394 }
2352 2395
2396 static void
2397 maybe_warn_comma_in_decl (void)
2398 {
2399 if (Vwarn_comma_in_declaration)\
2400 {
2401 warning ("comma in declaration not interpreted as a command separator");
2402
2403 if (reading_fcn_file || reading_script_file)
2404 warning ("near line %d of file `%s'", input_line_number,
2405 curr_fcn_file_full_name.c_str ());
2406 }
2407 }
2408
2353 static int 2409 static int
2354 warn_assign_as_truth_value (void) 2410 warn_assign_as_truth_value (void)
2355 { 2411 {
2356 Vwarn_assign_as_truth_value 2412 Vwarn_assign_as_truth_value
2357 = check_preference ("warn_assign_as_truth_value"); 2413 = check_preference ("warn_assign_as_truth_value");
2358 2414
2359 return 0; 2415 return 0;
2360 } 2416 }
2361 2417
2362 static int 2418 static int
2363 warn_comma_in_global_decl (void) 2419 warn_comma_in_declaration (void)
2364 { 2420 {
2365 Vwarn_comma_in_global_decl = check_preference ("warn_comma_in_global_decl"); 2421 Vwarn_comma_in_declaration = check_preference ("warn_comma_in_declaration");
2366 2422
2367 return 0; 2423 return 0;
2368 } 2424 }
2369 2425
2370 static int 2426 static int
2396 symbols_of_parse (void) 2452 symbols_of_parse (void)
2397 { 2453 {
2398 DEFVAR (warn_assign_as_truth_value, 1.0, 0, warn_assign_as_truth_value, 2454 DEFVAR (warn_assign_as_truth_value, 1.0, 0, warn_assign_as_truth_value,
2399 "produce warning for assignments used as truth values"); 2455 "produce warning for assignments used as truth values");
2400 2456
2401 DEFVAR (warn_comma_in_global_decl, 1.0, 0, warn_comma_in_global_decl, 2457 DEFVAR (warn_comma_in_declaration, 1.0, 0, warn_comma_in_declaration,
2402 "produce warning for commas in global declarations"); 2458 "produce warning for commas in declaration statements");
2403 2459
2404 DEFVAR (warn_function_name_clash, 1.0, 0, warn_function_name_clash, 2460 DEFVAR (warn_function_name_clash, 1.0, 0, warn_function_name_clash,
2405 "produce warning if function name conflicts with file name"); 2461 "produce warning if function name conflicts with file name");
2406 2462
2407 DEFVAR (warn_missing_semicolon, 0.0, 0, warn_missing_semicolon, 2463 DEFVAR (warn_missing_semicolon, 0.0, 0, warn_missing_semicolon,