Mercurial > octave-nkf
comparison src/parse.y @ 5861:2a6cb4ed8f1e
[project @ 2006-06-16 05:09:41 by jwe]
author | jwe |
---|---|
date | Fri, 16 Jun 2006 05:09:42 +0000 |
parents | 415ae81d331b |
children | e884ab4f29ee |
comparison
equal
deleted
inserted
replaced
5860:b645066d40ad | 5861:2a6cb4ed8f1e |
---|---|
156 // Build a function handle. | 156 // Build a function handle. |
157 static tree_fcn_handle * | 157 static tree_fcn_handle * |
158 make_fcn_handle (token *tok_val); | 158 make_fcn_handle (token *tok_val); |
159 | 159 |
160 // Build an anonymous function handle. | 160 // Build an anonymous function handle. |
161 static tree_constant * | 161 static tree_anon_fcn_handle * |
162 make_anon_fcn_handle (tree_parameter_list *param_list, tree_statement *stmt); | 162 make_anon_fcn_handle (tree_parameter_list *param_list, tree_statement *stmt); |
163 | 163 |
164 // Build a binary expression. | 164 // Build a binary expression. |
165 static tree_expression * | 165 static tree_expression * |
166 make_binary_op (int op, tree_expression *op1, token *tok_val, | 166 make_binary_op (int op, tree_expression *op1, token *tok_val, |
345 tree_matrix *tree_matrix_type; | 345 tree_matrix *tree_matrix_type; |
346 tree_cell *tree_cell_type; | 346 tree_cell *tree_cell_type; |
347 tree_expression *tree_expression_type; | 347 tree_expression *tree_expression_type; |
348 tree_constant *tree_constant_type; | 348 tree_constant *tree_constant_type; |
349 tree_fcn_handle *tree_fcn_handle_type; | 349 tree_fcn_handle *tree_fcn_handle_type; |
350 tree_anon_fcn_handle *tree_anon_fcn_handle_type; | |
350 tree_identifier *tree_identifier_type; | 351 tree_identifier *tree_identifier_type; |
351 tree_index_expression *tree_index_expression_type; | 352 tree_index_expression *tree_index_expression_type; |
352 tree_colon_expression *tree_colon_expression_type; | 353 tree_colon_expression *tree_colon_expression_type; |
353 tree_argument_list *tree_argument_list_type; | 354 tree_argument_list *tree_argument_list_type; |
354 tree_parameter_list *tree_parameter_list_type; | 355 tree_parameter_list *tree_parameter_list_type; |
399 | 400 |
400 // Nonterminals we construct. | 401 // Nonterminals we construct. |
401 %type <comment_type> stash_comment function_beg | 402 %type <comment_type> stash_comment function_beg |
402 %type <sep_type> sep_no_nl opt_sep_no_nl sep opt_sep | 403 %type <sep_type> sep_no_nl opt_sep_no_nl sep opt_sep |
403 %type <tree_type> input | 404 %type <tree_type> input |
404 %type <tree_constant_type> string constant magic_colon anon_fcn_handle | 405 %type <tree_constant_type> string constant magic_colon |
406 %type <tree_anon_fcn_handle_type> anon_fcn_handle | |
405 %type <tree_fcn_handle_type> fcn_handle | 407 %type <tree_fcn_handle_type> fcn_handle |
406 %type <tree_matrix_type> matrix_rows matrix_rows1 | 408 %type <tree_matrix_type> matrix_rows matrix_rows1 |
407 %type <tree_cell_type> cell_rows cell_rows1 | 409 %type <tree_cell_type> cell_rows cell_rows1 |
408 %type <tree_expression_type> matrix cell | 410 %type <tree_expression_type> matrix cell |
409 %type <tree_expression_type> primary_expr postfix_expr prefix_expr binary_expr | 411 %type <tree_expression_type> primary_expr postfix_expr prefix_expr binary_expr |
1754 return retval; | 1756 return retval; |
1755 } | 1757 } |
1756 | 1758 |
1757 // Make an anonymous function handle. | 1759 // Make an anonymous function handle. |
1758 | 1760 |
1759 static tree_constant * | 1761 static tree_anon_fcn_handle * |
1760 make_anon_fcn_handle (tree_parameter_list *param_list, tree_statement *stmt) | 1762 make_anon_fcn_handle (tree_parameter_list *param_list, tree_statement *stmt) |
1761 { | 1763 { |
1762 // FIXME -- need to get these from the location of the @ symbol. | 1764 // FIXME -- need to get these from the location of the @ symbol. |
1763 | 1765 |
1764 int l = -1; | 1766 int l = -1; |
1765 int c = -1; | 1767 int c = -1; |
1766 | 1768 |
1767 tree_parameter_list *ret_list = 0; | 1769 tree_parameter_list *ret_list = 0; |
1768 | 1770 |
1771 symbol_table *fcn_sym_tab = curr_sym_tab; | |
1772 | |
1773 if (symtab_context.empty ()) | |
1774 panic_impossible (); | |
1775 | |
1776 curr_sym_tab = symtab_context.top (); | |
1777 | |
1778 symtab_context.pop (); | |
1779 | |
1769 if (stmt && stmt->is_expression ()) | 1780 if (stmt && stmt->is_expression ()) |
1770 { | 1781 { |
1771 symbol_record *sr = curr_sym_tab->lookup ("__retval__", true); | 1782 symbol_record *sr = fcn_sym_tab->lookup ("__retval__", true); |
1772 | 1783 |
1773 tree_expression *e = stmt->expression (); | 1784 tree_expression *e = stmt->expression (); |
1774 | 1785 |
1775 tree_identifier *id = new tree_identifier (sr); | 1786 tree_identifier *id = new tree_identifier (sr); |
1776 | 1787 |
1791 | 1802 |
1792 tree_statement_list *body = new tree_statement_list (stmt); | 1803 tree_statement_list *body = new tree_statement_list (stmt); |
1793 | 1804 |
1794 body->mark_as_function_body (); | 1805 body->mark_as_function_body (); |
1795 | 1806 |
1796 octave_value fcn (new octave_user_function (param_list, ret_list, | 1807 tree_anon_fcn_handle *retval |
1797 body, curr_sym_tab)); | 1808 = new tree_anon_fcn_handle (param_list, ret_list, body, fcn_sym_tab, l, c); |
1798 | |
1799 if (symtab_context.empty ()) | |
1800 panic_impossible (); | |
1801 | |
1802 curr_sym_tab = symtab_context.top (); | |
1803 symtab_context.pop (); | |
1804 | |
1805 octave_value fh (new octave_fcn_handle (fcn, "@<anonymous>")); | |
1806 | |
1807 tree_constant *retval = new tree_constant (fh, l, c); | |
1808 | 1809 |
1809 return retval; | 1810 return retval; |
1810 } | 1811 } |
1811 | 1812 |
1812 static void | 1813 static void |