Mercurial > hg > octave-nkf
comparison src/parse.y @ 4297:59a2ba0fb205
[project @ 2003-01-11 20:22:09 by jwe]
author | jwe |
---|---|
date | Sat, 11 Jan 2003 20:22:09 +0000 |
parents | 0253850a08d7 |
children | 115bffcecfd3 |
comparison
equal
deleted
inserted
replaced
4296:399595b12ca7 | 4297:59a2ba0fb205 |
---|---|
3730 print_usage ("eval"); | 3730 print_usage ("eval"); |
3731 | 3731 |
3732 return retval; | 3732 return retval; |
3733 } | 3733 } |
3734 | 3734 |
3735 DEFUN (assignin, args, nargout, | |
3736 "-*- texinfo -*-\n\ | |
3737 @deftypefn {Built-in Function} {} assignin (@var{context}, @var{varname}, @var{value})\n\ | |
3738 Assign @var{value} to @var{varname} in context @var{context}, which\n\ | |
3739 may be either @code{\"base\"} or @code{\"caller\"}.\n\ | |
3740 @end deftypefn") | |
3741 { | |
3742 octave_value_list retval; | |
3743 | |
3744 int nargin = args.length (); | |
3745 | |
3746 if (nargin == 3) | |
3747 { | |
3748 std::string context = args(0).string_value (); | |
3749 | |
3750 if (! error_state) | |
3751 { | |
3752 unwind_protect::begin_frame ("Fassignin"); | |
3753 | |
3754 unwind_protect_ptr (curr_sym_tab); | |
3755 | |
3756 if (context == "caller") | |
3757 curr_sym_tab = curr_caller_sym_tab; | |
3758 else if (context == "base") | |
3759 curr_sym_tab = top_level_sym_tab; | |
3760 else | |
3761 error ("assignin: context must be \"caller\" or \"base\""); | |
3762 | |
3763 if (! error_state) | |
3764 { | |
3765 std::string nm = args(1).string_value (); | |
3766 | |
3767 if (! error_state) | |
3768 { | |
3769 if (valid_identifier (nm)) | |
3770 { | |
3771 symbol_record *sr = curr_sym_tab->lookup (nm, true); | |
3772 | |
3773 if (sr) | |
3774 { | |
3775 tree_identifier *id = new tree_identifier (sr); | |
3776 tree_constant *rhs = new tree_constant (args(2)); | |
3777 | |
3778 tree_simple_assignment tsa (id, rhs); | |
3779 | |
3780 tsa.rvalue (); | |
3781 } | |
3782 } | |
3783 else | |
3784 error ("assignin: invalid variable name"); | |
3785 } | |
3786 else | |
3787 error ("assignin: expecting variable name as second argument"); | |
3788 } | |
3789 | |
3790 unwind_protect::run_frame ("Fassignin"); | |
3791 } | |
3792 else | |
3793 error ("assignin: expecting string as first argument"); | |
3794 } | |
3795 else | |
3796 print_usage ("assignin"); | |
3797 | |
3798 return retval; | |
3799 } | |
3800 | |
3735 DEFUN (evalin, args, nargout, | 3801 DEFUN (evalin, args, nargout, |
3736 "-*- texinfo -*-\n\ | 3802 "-*- texinfo -*-\n\ |
3737 @deftypefn {Built-in Function} {} evalin (@var{context}, @var{try}, @var{catch})\n\ | 3803 @deftypefn {Built-in Function} {} evalin (@var{context}, @var{try}, @var{catch})\n\ |
3738 Like @code{eval}, except that the expressions are evaluated in the\n\ | 3804 Like @code{eval}, except that the expressions are evaluated in the\n\ |
3739 context @var{context}, which may be either @code{\"caller\"} or\n\ | 3805 context @var{context}, which may be either @code{\"caller\"} or\n\ |
3759 else if (context == "base") | 3825 else if (context == "base") |
3760 curr_sym_tab = top_level_sym_tab; | 3826 curr_sym_tab = top_level_sym_tab; |
3761 else | 3827 else |
3762 error ("evalin: context must be \"caller\" or \"base\""); | 3828 error ("evalin: context must be \"caller\" or \"base\""); |
3763 | 3829 |
3764 if (nargin > 2) | 3830 if (! error_state) |
3765 { | 3831 { |
3766 unwind_protect_bool (buffer_error_messages); | 3832 if (nargin > 2) |
3767 buffer_error_messages = true; | 3833 { |
3768 } | 3834 unwind_protect_bool (buffer_error_messages); |
3769 | 3835 buffer_error_messages = true; |
3770 int parse_status = 0; | 3836 } |
3771 | 3837 |
3772 retval = eval_string (args(1), ! Vdefault_eval_print_flag, | 3838 int parse_status = 0; |
3773 parse_status, nargout); | 3839 |
3774 | 3840 retval = eval_string (args(1), ! Vdefault_eval_print_flag, |
3775 if (nargin > 2 && (parse_status != 0 || error_state)) | 3841 parse_status, nargout); |
3776 { | 3842 |
3777 error_state = 0; | 3843 if (nargin > 2 && (parse_status != 0 || error_state)) |
3778 | 3844 { |
3779 // Set up for letting the user print any messages from | 3845 error_state = 0; |
3780 // errors that occurred in the first part of this eval(). | 3846 |
3781 | 3847 // Set up for letting the user print any messages from |
3782 buffer_error_messages = false; | 3848 // errors that occurred in the first part of this eval(). |
3783 | 3849 |
3784 bind_global_error_variable (); | 3850 buffer_error_messages = false; |
3785 | 3851 |
3786 unwind_protect::add (clear_global_error_variable, 0); | 3852 bind_global_error_variable (); |
3787 | 3853 |
3788 eval_string (args(2), 0, parse_status, nargout); | 3854 unwind_protect::add (clear_global_error_variable, 0); |
3789 | 3855 |
3790 retval = octave_value_list (); | 3856 eval_string (args(2), 0, parse_status, nargout); |
3857 | |
3858 retval = octave_value_list (); | |
3859 } | |
3791 } | 3860 } |
3792 | 3861 |
3793 unwind_protect::run_frame ("Fevalin"); | 3862 unwind_protect::run_frame ("Fevalin"); |
3794 } | 3863 } |
3795 else | 3864 else |