Mercurial > hg > octave-lyh
comparison src/parse.y @ 3523:b80bbb43a1a9
[project @ 2000-02-02 10:25:52 by jwe]
author | jwe |
---|---|
date | Wed, 02 Feb 2000 10:26:25 +0000 |
parents | cbee5fbb696d |
children | 6cfa474c5b99 |
comparison
equal
deleted
inserted
replaced
3522:bd422cf62f0c | 3523:b80bbb43a1a9 |
---|---|
99 | 99 |
100 // The column of the current token. | 100 // The column of the current token. |
101 int current_input_column = 1; | 101 int current_input_column = 1; |
102 | 102 |
103 // Buffer for help text snagged from function files. | 103 // Buffer for help text snagged from function files. |
104 string help_buf; | 104 std::string help_buf; |
105 | 105 |
106 // TRUE means we are using readline. | 106 // TRUE means we are using readline. |
107 // (--no-line-editing) | 107 // (--no-line-editing) |
108 bool line_editing = true; | 108 bool line_editing = true; |
109 | 109 |
264 static tree_index_expression * | 264 static tree_index_expression * |
265 make_index_expression (tree_expression *expr, tree_argument_list *args); | 265 make_index_expression (tree_expression *expr, tree_argument_list *args); |
266 | 266 |
267 // Make an indirect reference expression. | 267 // Make an indirect reference expression. |
268 static tree_indirect_ref * | 268 static tree_indirect_ref * |
269 make_indirect_ref (tree_expression *expr, const string&); | 269 make_indirect_ref (tree_expression *expr, const std::string&); |
270 | 270 |
271 // Make a declaration command. | 271 // Make a declaration command. |
272 static tree_decl_command * | 272 static tree_decl_command * |
273 make_decl_command (int tok, token *tok_val, tree_decl_init_list *lst); | 273 make_decl_command (int tok, token *tok_val, tree_decl_init_list *lst); |
274 | 274 |
1403 static void | 1403 static void |
1404 yyerror (const char *s) | 1404 yyerror (const char *s) |
1405 { | 1405 { |
1406 int err_col = current_input_column - 1; | 1406 int err_col = current_input_column - 1; |
1407 | 1407 |
1408 ostrstream output_buf; | 1408 std::ostrstream output_buf; |
1409 | 1409 |
1410 if (reading_fcn_file || reading_script_file) | 1410 if (reading_fcn_file || reading_script_file) |
1411 output_buf << "parse error near line " << input_line_number | 1411 output_buf << "parse error near line " << input_line_number |
1412 << " of file " << curr_fcn_file_full_name; | 1412 << " of file " << curr_fcn_file_full_name; |
1413 else | 1413 else |
1624 | 1624 |
1625 if (! (error_state || warning_state)) | 1625 if (! (error_state || warning_state)) |
1626 { | 1626 { |
1627 tree_constant *tc_retval = new tree_constant (tmp); | 1627 tree_constant *tc_retval = new tree_constant (tmp); |
1628 | 1628 |
1629 ostrstream buf; | 1629 std::ostrstream buf; |
1630 | 1630 |
1631 tree_print_code tpc (buf); | 1631 tree_print_code tpc (buf); |
1632 | 1632 |
1633 e->accept (tpc); | 1633 e->accept (tpc); |
1634 | 1634 |
1673 | 1673 |
1674 if (! (error_state || warning_state)) | 1674 if (! (error_state || warning_state)) |
1675 { | 1675 { |
1676 tree_constant *tc_retval = new tree_constant (tmp); | 1676 tree_constant *tc_retval = new tree_constant (tmp); |
1677 | 1677 |
1678 ostrstream buf; | 1678 std::ostrstream buf; |
1679 | 1679 |
1680 tree_print_code tpc (buf); | 1680 tree_print_code tpc (buf); |
1681 | 1681 |
1682 e->accept (tpc); | 1682 e->accept (tpc); |
1683 | 1683 |
1731 | 1731 |
1732 if (! (error_state || warning_state)) | 1732 if (! (error_state || warning_state)) |
1733 { | 1733 { |
1734 tree_constant *tc_retval = new tree_constant (tmp); | 1734 tree_constant *tc_retval = new tree_constant (tmp); |
1735 | 1735 |
1736 ostrstream buf; | 1736 std::ostrstream buf; |
1737 | 1737 |
1738 tree_print_code tpc (buf); | 1738 tree_print_code tpc (buf); |
1739 | 1739 |
1740 e->accept (tpc); | 1740 e->accept (tpc); |
1741 | 1741 |
2368 // Do most of the work for defining a function. | 2368 // Do most of the work for defining a function. |
2369 | 2369 |
2370 static octave_user_function * | 2370 static octave_user_function * |
2371 frob_function (tree_identifier *id, octave_user_function *fcn) | 2371 frob_function (tree_identifier *id, octave_user_function *fcn) |
2372 { | 2372 { |
2373 string id_name = id->name (); | 2373 std::string id_name = id->name (); |
2374 | 2374 |
2375 // If input is coming from a file, issue a warning if the name of | 2375 // If input is coming from a file, issue a warning if the name of |
2376 // the file does not match the name of the function stated in the | 2376 // the file does not match the name of the function stated in the |
2377 // file. Matlab doesn't provide a diagnostic (it ignores the stated | 2377 // file. Matlab doesn't provide a diagnostic (it ignores the stated |
2378 // name). | 2378 // name). |
2402 fcn->stash_fcn_file_time (now); | 2402 fcn->stash_fcn_file_time (now); |
2403 fcn->mark_as_system_fcn_file (); | 2403 fcn->mark_as_system_fcn_file (); |
2404 | 2404 |
2405 if (Vwarn_future_time_stamp) | 2405 if (Vwarn_future_time_stamp) |
2406 { | 2406 { |
2407 string nm = fcn->fcn_file_name (); | 2407 std::string nm = fcn->fcn_file_name (); |
2408 | 2408 |
2409 file_stat fs (nm); | 2409 file_stat fs (nm); |
2410 | 2410 |
2411 if (fs && fs.is_newer (now)) | 2411 if (fs && fs.is_newer (now)) |
2412 warning ("time stamp for `%s' is in the future", nm.c_str ()); | 2412 warning ("time stamp for `%s' is in the future", nm.c_str ()); |
2488 } | 2488 } |
2489 | 2489 |
2490 // Make an indirect reference expression. | 2490 // Make an indirect reference expression. |
2491 | 2491 |
2492 static tree_indirect_ref * | 2492 static tree_indirect_ref * |
2493 make_indirect_ref (tree_expression *expr, const string& elt) | 2493 make_indirect_ref (tree_expression *expr, const std::string& elt) |
2494 { | 2494 { |
2495 tree_indirect_ref *retval = 0; | 2495 tree_indirect_ref *retval = 0; |
2496 | 2496 |
2497 int l = expr->line (); | 2497 int l = expr->line (); |
2498 int c = expr->column (); | 2498 int c = expr->column (); |
2563 | 2563 |
2564 if (! (error_state || warning_state)) | 2564 if (! (error_state || warning_state)) |
2565 { | 2565 { |
2566 tree_constant *tc_retval = new tree_constant (tmp); | 2566 tree_constant *tc_retval = new tree_constant (tmp); |
2567 | 2567 |
2568 ostrstream buf; | 2568 std::ostrstream buf; |
2569 | 2569 |
2570 tree_print_code tpc (buf); | 2570 tree_print_code tpc (buf); |
2571 | 2571 |
2572 m->accept (tpc); | 2572 m->accept (tpc); |
2573 | 2573 |
2708 if (f) | 2708 if (f) |
2709 fclose (static_cast<FILE *> (f)); | 2709 fclose (static_cast<FILE *> (f)); |
2710 } | 2710 } |
2711 | 2711 |
2712 void | 2712 void |
2713 parse_and_execute (const string& s, bool verbose, const char *warn_for) | 2713 parse_and_execute (const std::string& s, bool verbose, const char *warn_for) |
2714 { | 2714 { |
2715 unwind_protect::begin_frame ("parse_and_execute_2"); | 2715 unwind_protect::begin_frame ("parse_and_execute_2"); |
2716 | 2716 |
2717 unwind_protect_bool (reading_script_file); | 2717 unwind_protect_bool (reading_script_file); |
2718 unwind_protect_str (curr_fcn_file_full_name); | 2718 unwind_protect_str (curr_fcn_file_full_name); |
2749 | 2749 |
2750 unwind_protect::run_frame ("parse_and_execute_2"); | 2750 unwind_protect::run_frame ("parse_and_execute_2"); |
2751 } | 2751 } |
2752 | 2752 |
2753 static bool | 2753 static bool |
2754 looks_like_octave_copyright (const string& s) | 2754 looks_like_octave_copyright (const std::string& s) |
2755 { | 2755 { |
2756 bool retval = false; | 2756 bool retval = false; |
2757 | 2757 |
2758 string t = s.substr (0, 14); | 2758 std::string t = s.substr (0, 14); |
2759 | 2759 |
2760 if (t == "Copyright (C) ") | 2760 if (t == "Copyright (C) ") |
2761 { | 2761 { |
2762 size_t pos = s.find ('\n'); | 2762 size_t pos = s.find ('\n'); |
2763 | 2763 |
2791 // code! | 2791 // code! |
2792 | 2792 |
2793 static string | 2793 static string |
2794 gobble_leading_white_space (FILE *ffile, bool in_parts, bool update_pos) | 2794 gobble_leading_white_space (FILE *ffile, bool in_parts, bool update_pos) |
2795 { | 2795 { |
2796 string help_txt; | 2796 std::string help_txt; |
2797 | 2797 |
2798 bool first_comments_seen = false; | 2798 bool first_comments_seen = false; |
2799 bool begin_comment = false; | 2799 bool begin_comment = false; |
2800 bool have_help_text = false; | 2800 bool have_help_text = false; |
2801 bool in_comment = false; | 2801 bool in_comment = false; |
2902 | 2902 |
2903 return help_txt; | 2903 return help_txt; |
2904 } | 2904 } |
2905 | 2905 |
2906 string | 2906 string |
2907 get_help_from_file (const string& path) | 2907 get_help_from_file (const std::string& path) |
2908 { | 2908 { |
2909 string retval; | 2909 std::string retval; |
2910 | 2910 |
2911 if (! path.empty ()) | 2911 if (! path.empty ()) |
2912 { | 2912 { |
2913 FILE *fptr = fopen (path.c_str (), "r"); | 2913 FILE *fptr = fopen (path.c_str (), "r"); |
2914 | 2914 |
2963 { | 2963 { |
2964 bind_builtin_variable ("current_script_file_name", octave_value ()); | 2964 bind_builtin_variable ("current_script_file_name", octave_value ()); |
2965 } | 2965 } |
2966 | 2966 |
2967 static bool | 2967 static bool |
2968 parse_fcn_file (const string& ff, bool exec_script, bool force_script = false) | 2968 parse_fcn_file (const std::string& ff, bool exec_script, bool force_script = false) |
2969 { | 2969 { |
2970 unwind_protect::begin_frame ("parse_fcn_file"); | 2970 unwind_protect::begin_frame ("parse_fcn_file"); |
2971 | 2971 |
2972 int script_file_executed = false; | 2972 int script_file_executed = false; |
2973 | 2973 |
3082 bool | 3082 bool |
3083 load_fcn_from_file (symbol_record *sym_rec, bool exec_script) | 3083 load_fcn_from_file (symbol_record *sym_rec, bool exec_script) |
3084 { | 3084 { |
3085 bool script_file_executed = false; | 3085 bool script_file_executed = false; |
3086 | 3086 |
3087 string nm = sym_rec->name (); | 3087 std::string nm = sym_rec->name (); |
3088 | 3088 |
3089 if (octave_dynamic_loader::load (nm)) | 3089 if (octave_dynamic_loader::load (nm)) |
3090 { | 3090 { |
3091 force_link_to_function (nm); | 3091 force_link_to_function (nm); |
3092 } | 3092 } |
3093 else | 3093 else |
3094 { | 3094 { |
3095 string ff = fcn_file_in_path (nm); | 3095 std::string ff = fcn_file_in_path (nm); |
3096 | 3096 |
3097 // These are needed by yyparse. | 3097 // These are needed by yyparse. |
3098 | 3098 |
3099 unwind_protect::begin_frame ("load_fcn_from_file"); | 3099 unwind_protect::begin_frame ("load_fcn_from_file"); |
3100 | 3100 |
3128 | 3128 |
3129 int nargin = args.length (); | 3129 int nargin = args.length (); |
3130 | 3130 |
3131 if (nargin == 1) | 3131 if (nargin == 1) |
3132 { | 3132 { |
3133 string file_name = args(0).string_value (); | 3133 std::string file_name = args(0).string_value (); |
3134 | 3134 |
3135 if (! error_state) | 3135 if (! error_state) |
3136 { | 3136 { |
3137 string file_full_name = file_ops::tilde_expand (file_name); | 3137 std::string file_full_name = file_ops::tilde_expand (file_name); |
3138 | 3138 |
3139 unwind_protect::begin_frame ("Fsource"); | 3139 unwind_protect::begin_frame ("Fsource"); |
3140 | 3140 |
3141 unwind_protect_str (curr_fcn_file_name); | 3141 unwind_protect_str (curr_fcn_file_name); |
3142 unwind_protect_str (curr_fcn_file_full_name); | 3142 unwind_protect_str (curr_fcn_file_full_name); |
3160 | 3160 |
3161 return retval; | 3161 return retval; |
3162 } | 3162 } |
3163 | 3163 |
3164 octave_value_list | 3164 octave_value_list |
3165 feval (const string& name, const octave_value_list& args, int nargout) | 3165 feval (const std::string& name, const octave_value_list& args, int nargout) |
3166 { | 3166 { |
3167 octave_value_list retval; | 3167 octave_value_list retval; |
3168 | 3168 |
3169 octave_function *fcn = is_valid_function (name, "feval", 1); | 3169 octave_function *fcn = is_valid_function (name, "feval", 1); |
3170 | 3170 |
3179 { | 3179 { |
3180 octave_value_list retval; | 3180 octave_value_list retval; |
3181 | 3181 |
3182 if (args.length () > 0) | 3182 if (args.length () > 0) |
3183 { | 3183 { |
3184 string name = args(0).string_value (); | 3184 std::string name = args(0).string_value (); |
3185 | 3185 |
3186 if (! error_state) | 3186 if (! error_state) |
3187 { | 3187 { |
3188 int tmp_nargin = args.length () - 1; | 3188 int tmp_nargin = args.length () - 1; |
3189 | 3189 |
3246 | 3246 |
3247 return retval; | 3247 return retval; |
3248 } | 3248 } |
3249 | 3249 |
3250 octave_value_list | 3250 octave_value_list |
3251 eval_string (const string& s, bool silent, int& parse_status, int nargout) | 3251 eval_string (const std::string& s, bool silent, int& parse_status, int nargout) |
3252 { | 3252 { |
3253 unwind_protect::begin_frame ("eval_string"); | 3253 unwind_protect::begin_frame ("eval_string"); |
3254 | 3254 |
3255 unwind_protect_bool (get_input_from_eval_string); | 3255 unwind_protect_bool (get_input_from_eval_string); |
3256 unwind_protect_bool (input_from_command_line_file); | 3256 unwind_protect_bool (input_from_command_line_file); |
3293 | 3293 |
3294 return retval; | 3294 return retval; |
3295 } | 3295 } |
3296 | 3296 |
3297 octave_value | 3297 octave_value |
3298 eval_string (const string& s, bool silent, int& parse_status) | 3298 eval_string (const std::string& s, bool silent, int& parse_status) |
3299 { | 3299 { |
3300 octave_value retval; | 3300 octave_value retval; |
3301 | 3301 |
3302 octave_value_list tmp = eval_string (s, silent, parse_status, 1); | 3302 octave_value_list tmp = eval_string (s, silent, parse_status, 1); |
3303 | 3303 |
3309 | 3309 |
3310 static octave_value_list | 3310 static octave_value_list |
3311 eval_string (const octave_value& arg, bool silent, int& parse_status, | 3311 eval_string (const octave_value& arg, bool silent, int& parse_status, |
3312 int nargout) | 3312 int nargout) |
3313 { | 3313 { |
3314 string s = arg.string_value (); | 3314 std::string s = arg.string_value (); |
3315 | 3315 |
3316 if (error_state) | 3316 if (error_state) |
3317 { | 3317 { |
3318 error ("eval: expecting string argument"); | 3318 error ("eval: expecting std::string argument"); |
3319 return -1.0; | 3319 return -1.0; |
3320 } | 3320 } |
3321 | 3321 |
3322 return eval_string (s, silent, parse_status, nargout); | 3322 return eval_string (s, silent, parse_status, nargout); |
3323 } | 3323 } |