Mercurial > octave-dspies
comparison libinterp/parse-tree/oct-parse.yy @ 16134:ec9c6222ef5a
move static parser helper functions to octave_parser class
* oct-parse.yy, parse.h (append_statement_list, end_error,
end_token_ok, finish_cell, finish_colon_expression, finish_function,
finish_if_command, finish_matrix, finish_switch_command,
frob_function, make_anon_fcn_handle, make_assign_op, make_binary_op,
make_boolean_op, make_break_command, make_constant,
make_continue_command, make_decl_command, make_do_until_command,
make_elseif_clause, make_end, make_fcn_handle, make_for_command,
make_index_expression, make_indirect_ref, make_postfix_op,
make_prefix_op, make_return_command, make_script,
make_statement_list, make_switch_case, make_try_command,
make_unwind_command, make_while_command,
maybe_warn_assign_as_truth_value, maybe_warn_missing_semi,
maybe_warn_variable_switch_label, recover_from_parsing_function,
set_stmt_print_flag, start_function, start_if_command,
validate_matrix_row): Declare as members of octave_parser class.
Change all callers.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Tue, 26 Feb 2013 21:04:40 -0500 |
parents | 249d62b3fac8 |
children | ed36d5543b27 |
comparison
equal
deleted
inserted
replaced
16133:249d62b3fac8 | 16134:ec9c6222ef5a |
---|---|
156 // the file. | 156 // the file. |
157 | 157 |
158 // Generic error messages. | 158 // Generic error messages. |
159 static void | 159 static void |
160 yyerror (const char *s); | 160 yyerror (const char *s); |
161 | |
162 // Error mesages for mismatched end tokens. | |
163 static void | |
164 end_error (const char *type, token::end_tok_type ettype, int l, int c); | |
165 | |
166 // Check to see that end tokens are properly matched. | |
167 static bool | |
168 end_token_ok (token *tok, token::end_tok_type expected); | |
169 | |
170 // Maybe print a warning if an assignment expression is used as the | |
171 // test in a logical expression. | |
172 static void | |
173 maybe_warn_assign_as_truth_value (tree_expression *expr); | |
174 | |
175 // Maybe print a warning about switch labels that aren't constants. | |
176 static void | |
177 maybe_warn_variable_switch_label (tree_expression *expr); | |
178 | |
179 // Finish building a range. | |
180 static tree_expression * | |
181 finish_colon_expression (tree_colon_expression *e); | |
182 | |
183 // Build a constant. | |
184 static tree_constant * | |
185 make_constant (int op, token *tok_val); | |
186 | |
187 // Build a function handle. | |
188 static tree_fcn_handle * | |
189 make_fcn_handle (token *tok_val); | |
190 | |
191 // Build an anonymous function handle. | |
192 static tree_anon_fcn_handle * | |
193 make_anon_fcn_handle (tree_parameter_list *param_list, tree_statement *stmt); | |
194 | |
195 // Build a binary expression. | |
196 static tree_expression * | |
197 make_binary_op (int op, tree_expression *op1, token *tok_val, | |
198 tree_expression *op2); | |
199 | |
200 // Build a boolean expression. | |
201 static tree_expression * | |
202 make_boolean_op (int op, tree_expression *op1, token *tok_val, | |
203 tree_expression *op2); | |
204 | |
205 // Build a prefix expression. | |
206 static tree_expression * | |
207 make_prefix_op (int op, tree_expression *op1, token *tok_val); | |
208 | |
209 // Build a postfix expression. | |
210 static tree_expression * | |
211 make_postfix_op (int op, tree_expression *op1, token *tok_val); | |
212 | |
213 // Build an unwind-protect command. | |
214 static tree_command * | |
215 make_unwind_command (token *unwind_tok, tree_statement_list *body, | |
216 tree_statement_list *cleanup, token *end_tok, | |
217 octave_comment_list *lc, octave_comment_list *mc); | |
218 | |
219 // Build a try-catch command. | |
220 static tree_command * | |
221 make_try_command (token *try_tok, tree_statement_list *body, | |
222 tree_statement_list *cleanup, token *end_tok, | |
223 octave_comment_list *lc, octave_comment_list *mc); | |
224 | |
225 // Build a while command. | |
226 static tree_command * | |
227 make_while_command (token *while_tok, tree_expression *expr, | |
228 tree_statement_list *body, token *end_tok, | |
229 octave_comment_list *lc); | |
230 | |
231 // Build a do-until command. | |
232 static tree_command * | |
233 make_do_until_command (token *until_tok, tree_statement_list *body, | |
234 tree_expression *expr, octave_comment_list *lc); | |
235 | |
236 // Build a for command. | |
237 static tree_command * | |
238 make_for_command (int tok_id, token *for_tok, tree_argument_list *lhs, | |
239 tree_expression *expr, tree_expression *maxproc, | |
240 tree_statement_list *body, token *end_tok, | |
241 octave_comment_list *lc); | |
242 | |
243 // Build a break command. | |
244 static tree_command * | |
245 make_break_command (token *break_tok); | |
246 | |
247 // Build a continue command. | |
248 static tree_command * | |
249 make_continue_command (token *continue_tok); | |
250 | |
251 // Build a return command. | |
252 static tree_command * | |
253 make_return_command (token *return_tok); | |
254 | |
255 // Start an if command. | |
256 static tree_if_command_list * | |
257 start_if_command (tree_expression *expr, tree_statement_list *list); | |
258 | |
259 // Finish an if command. | |
260 static tree_if_command * | |
261 finish_if_command (token *if_tok, tree_if_command_list *list, | |
262 token *end_tok, octave_comment_list *lc); | |
263 | |
264 // Build an elseif clause. | |
265 static tree_if_clause * | |
266 make_elseif_clause (token *elseif_tok, tree_expression *expr, | |
267 tree_statement_list *list, octave_comment_list *lc); | |
268 | |
269 // Finish a switch command. | |
270 static tree_switch_command * | |
271 finish_switch_command (token *switch_tok, tree_expression *expr, | |
272 tree_switch_case_list *list, token *end_tok, | |
273 octave_comment_list *lc); | |
274 | |
275 // Build a switch case. | |
276 static tree_switch_case * | |
277 make_switch_case (token *case_tok, tree_expression *expr, | |
278 tree_statement_list *list, octave_comment_list *lc); | |
279 | |
280 // Build an assignment to a variable. | |
281 static tree_expression * | |
282 make_assign_op (int op, tree_argument_list *lhs, token *eq_tok, | |
283 tree_expression *rhs); | |
284 | |
285 // Define a script. | |
286 static void | |
287 make_script (tree_statement_list *cmds, tree_statement *end_script); | |
288 | |
289 // Begin defining a function. | |
290 static octave_user_function * | |
291 start_function (tree_parameter_list *param_list, tree_statement_list *body, | |
292 tree_statement *end_function); | |
293 | |
294 // Create a no-op statement for end_function. | |
295 static tree_statement * | |
296 make_end (const std::string& type, int l, int c); | |
297 | |
298 // Do most of the work for defining a function. | |
299 static octave_user_function * | |
300 frob_function (const std::string& fname, octave_user_function *fcn); | |
301 | |
302 // Finish defining a function. | |
303 static tree_function_def * | |
304 finish_function (tree_parameter_list *ret_list, | |
305 octave_user_function *fcn, octave_comment_list *lc); | |
306 | |
307 // Reset state after parsing function. | |
308 static void | |
309 recover_from_parsing_function (void); | |
310 | |
311 // Make an index expression. | |
312 static tree_index_expression * | |
313 make_index_expression (tree_expression *expr, | |
314 tree_argument_list *args, char type); | |
315 | |
316 // Make an indirect reference expression. | |
317 static tree_index_expression * | |
318 make_indirect_ref (tree_expression *expr, const std::string&); | |
319 | |
320 // Make an indirect reference expression with dynamic field name. | |
321 static tree_index_expression * | |
322 make_indirect_ref (tree_expression *expr, tree_expression *field); | |
323 | |
324 // Make a declaration command. | |
325 static tree_decl_command * | |
326 make_decl_command (int tok, token *tok_val, tree_decl_init_list *lst); | |
327 | |
328 // Validate argument list forming a matrix or cell row. | |
329 static tree_argument_list * | |
330 validate_matrix_row (tree_argument_list *row); | |
331 | |
332 // Finish building a matrix list. | |
333 static tree_expression * | |
334 finish_matrix (tree_matrix *m); | |
335 | |
336 // Finish building a cell list. | |
337 static tree_expression * | |
338 finish_cell (tree_cell *c); | |
339 | |
340 // Maybe print a warning. Duh. | |
341 static void | |
342 maybe_warn_missing_semi (tree_statement_list *); | |
343 | |
344 // Set the print flag for a statement based on the separator type. | |
345 static tree_statement_list * | |
346 set_stmt_print_flag (tree_statement_list *, char, bool); | |
347 | |
348 // Create a statement list. | |
349 static tree_statement_list *make_statement_list (tree_statement *stmt); | |
350 | |
351 // Append a statement to an existing statement list. | |
352 static tree_statement_list * | |
353 append_statement_list (tree_statement_list *list, char sep, | |
354 tree_statement *stmt, bool warn_missing_semi); | |
355 | 161 |
356 // Finish building a statement. | 162 // Finish building a statement. |
357 template <class T> | 163 template <class T> |
358 static tree_statement * | 164 static tree_statement * |
359 make_statement (T *arg) | 165 make_statement (T *arg) |
569 | simple_list END_OF_INPUT | 375 | simple_list END_OF_INPUT |
570 { $$ = $1; } | 376 { $$ = $1; } |
571 ; | 377 ; |
572 | 378 |
573 simple_list : simple_list1 opt_sep_no_nl | 379 simple_list : simple_list1 opt_sep_no_nl |
574 { $$ = set_stmt_print_flag ($1, $2, false); } | 380 { $$ = curr_parser->set_stmt_print_flag ($1, $2, false); } |
575 ; | 381 ; |
576 | 382 |
577 simple_list1 : statement | 383 simple_list1 : statement |
578 { $$ = make_statement_list ($1); } | 384 { $$ = curr_parser->make_statement_list ($1); } |
579 | simple_list1 sep_no_nl statement | 385 | simple_list1 sep_no_nl statement |
580 { $$ = append_statement_list ($1, $2, $3, false); } | 386 { $$ = curr_parser->append_statement_list ($1, $2, $3, false); } |
581 ; | 387 ; |
582 | 388 |
583 opt_list : // empty | 389 opt_list : // empty |
584 { $$ = new tree_statement_list (); } | 390 { $$ = new tree_statement_list (); } |
585 | list | 391 | list |
586 { $$ = $1; } | 392 { $$ = $1; } |
587 ; | 393 ; |
588 | 394 |
589 list : list1 opt_sep | 395 list : list1 opt_sep |
590 { $$ = set_stmt_print_flag ($1, $2, true); } | 396 { $$ = curr_parser->set_stmt_print_flag ($1, $2, true); } |
591 ; | 397 ; |
592 | 398 |
593 list1 : statement | 399 list1 : statement |
594 { $$ = make_statement_list ($1); } | 400 { $$ = curr_parser->make_statement_list ($1); } |
595 | list1 sep statement | 401 | list1 sep statement |
596 { $$ = append_statement_list ($1, $2, $3, true); } | 402 { $$ = curr_parser->append_statement_list ($1, $2, $3, true); } |
597 ; | 403 ; |
598 | 404 |
599 statement : expression | 405 statement : expression |
600 { $$ = make_statement ($1); } | 406 { $$ = make_statement ($1); } |
601 | command | 407 | command |
611 // These are not really like expressions since they can't appear on | 417 // These are not really like expressions since they can't appear on |
612 // the RHS of an assignment. But they are also not like commands (IF, | 418 // the RHS of an assignment. But they are also not like commands (IF, |
613 // WHILE, etc. | 419 // WHILE, etc. |
614 | 420 |
615 word_list_cmd : identifier word_list | 421 word_list_cmd : identifier word_list |
616 { $$ = make_index_expression ($1, $2, '('); } | 422 { $$ = curr_parser->make_index_expression ($1, $2, '('); } |
617 ; | 423 ; |
618 | 424 |
619 word_list : string | 425 word_list : string |
620 { $$ = new tree_argument_list ($1); } | 426 { $$ = new tree_argument_list ($1); } |
621 | word_list string | 427 | word_list string |
644 meta_identifier : METAQUERY | 450 meta_identifier : METAQUERY |
645 { $$ = new tree_identifier ($1->line (), $1->column ()); } | 451 { $$ = new tree_identifier ($1->line (), $1->column ()); } |
646 ; | 452 ; |
647 | 453 |
648 string : DQ_STRING | 454 string : DQ_STRING |
649 { $$ = make_constant (DQ_STRING, $1); } | 455 { $$ = curr_parser->make_constant (DQ_STRING, $1); } |
650 | SQ_STRING | 456 | SQ_STRING |
651 { $$ = make_constant (SQ_STRING, $1); } | 457 { $$ = curr_parser->make_constant (SQ_STRING, $1); } |
652 ; | 458 ; |
653 | 459 |
654 constant : NUM | 460 constant : NUM |
655 { $$ = make_constant (NUM, $1); } | 461 { $$ = curr_parser->make_constant (NUM, $1); } |
656 | IMAG_NUM | 462 | IMAG_NUM |
657 { $$ = make_constant (IMAG_NUM, $1); } | 463 { $$ = curr_parser->make_constant (IMAG_NUM, $1); } |
658 | string | 464 | string |
659 { $$ = $1; } | 465 { $$ = $1; } |
660 ; | 466 ; |
661 | 467 |
662 matrix : '[' ']' | 468 matrix : '[' ']' |
677 curr_lexer->looking_at_matrix_or_assign_lhs = false; | 483 curr_lexer->looking_at_matrix_or_assign_lhs = false; |
678 curr_lexer->pending_local_variables.clear (); | 484 curr_lexer->pending_local_variables.clear (); |
679 } | 485 } |
680 | '[' matrix_rows ']' | 486 | '[' matrix_rows ']' |
681 { | 487 { |
682 $$ = finish_matrix ($2); | 488 $$ = curr_parser->finish_matrix ($2); |
683 curr_lexer->looking_at_matrix_or_assign_lhs = false; | 489 curr_lexer->looking_at_matrix_or_assign_lhs = false; |
684 curr_lexer->pending_local_variables.clear (); | 490 curr_lexer->pending_local_variables.clear (); |
685 } | 491 } |
686 ; | 492 ; |
687 | 493 |
703 cell : '{' '}' | 509 cell : '{' '}' |
704 { $$ = new tree_constant (octave_value (Cell ())); } | 510 { $$ = new tree_constant (octave_value (Cell ())); } |
705 | '{' ';' '}' | 511 | '{' ';' '}' |
706 { $$ = new tree_constant (octave_value (Cell ())); } | 512 { $$ = new tree_constant (octave_value (Cell ())); } |
707 | '{' cell_rows '}' | 513 | '{' cell_rows '}' |
708 { $$ = finish_cell ($2); } | 514 { $$ = curr_parser->finish_cell ($2); } |
709 ; | 515 ; |
710 | 516 |
711 cell_rows : cell_rows1 | 517 cell_rows : cell_rows1 |
712 { $$ = $1; } | 518 { $$ = $1; } |
713 | cell_rows1 ';' // Ignore trailing semicolon. | 519 | cell_rows1 ';' // Ignore trailing semicolon. |
723 } | 529 } |
724 ; | 530 ; |
725 | 531 |
726 cell_or_matrix_row | 532 cell_or_matrix_row |
727 : arg_list | 533 : arg_list |
728 { $$ = validate_matrix_row ($1); } | 534 { $$ = curr_parser->validate_matrix_row ($1); } |
729 | arg_list ',' // Ignore trailing comma. | 535 | arg_list ',' // Ignore trailing comma. |
730 { $$ = validate_matrix_row ($1); } | 536 { $$ = curr_parser->validate_matrix_row ($1); } |
731 ; | 537 ; |
732 | 538 |
733 fcn_handle : '@' FCN_HANDLE | 539 fcn_handle : '@' FCN_HANDLE |
734 { | 540 { |
735 $$ = make_fcn_handle ($2); | 541 $$ = curr_parser->make_fcn_handle ($2); |
736 curr_lexer->looking_at_function_handle--; | 542 curr_lexer->looking_at_function_handle--; |
737 } | 543 } |
738 ; | 544 ; |
739 | 545 |
740 anon_fcn_handle : '@' param_list statement | 546 anon_fcn_handle : '@' param_list statement |
741 { | 547 { |
742 curr_lexer->quote_is_transpose = false; | 548 curr_lexer->quote_is_transpose = false; |
743 $$ = make_anon_fcn_handle ($2, $3); | 549 $$ = curr_parser->make_anon_fcn_handle ($2, $3); |
744 } | 550 } |
745 ; | 551 ; |
746 | 552 |
747 primary_expr : identifier | 553 primary_expr : identifier |
748 { $$ = $1; } | 554 { $$ = $1; } |
803 ; | 609 ; |
804 | 610 |
805 oper_expr : primary_expr | 611 oper_expr : primary_expr |
806 { $$ = $1; } | 612 { $$ = $1; } |
807 | oper_expr PLUS_PLUS | 613 | oper_expr PLUS_PLUS |
808 { $$ = make_postfix_op (PLUS_PLUS, $1, $2); } | 614 { $$ = curr_parser->make_postfix_op (PLUS_PLUS, $1, $2); } |
809 | oper_expr MINUS_MINUS | 615 | oper_expr MINUS_MINUS |
810 { $$ = make_postfix_op (MINUS_MINUS, $1, $2); } | 616 { $$ = curr_parser->make_postfix_op (MINUS_MINUS, $1, $2); } |
811 | oper_expr '(' ')' | 617 | oper_expr '(' ')' |
812 { $$ = make_index_expression ($1, 0, '('); } | 618 { $$ = curr_parser->make_index_expression ($1, 0, '('); } |
813 | oper_expr '(' arg_list ')' | 619 | oper_expr '(' arg_list ')' |
814 { $$ = make_index_expression ($1, $3, '('); } | 620 { $$ = curr_parser->make_index_expression ($1, $3, '('); } |
815 | oper_expr '{' '}' | 621 | oper_expr '{' '}' |
816 { $$ = make_index_expression ($1, 0, '{'); } | 622 { $$ = curr_parser->make_index_expression ($1, 0, '{'); } |
817 | oper_expr '{' arg_list '}' | 623 | oper_expr '{' arg_list '}' |
818 { $$ = make_index_expression ($1, $3, '{'); } | 624 { $$ = curr_parser->make_index_expression ($1, $3, '{'); } |
819 | oper_expr QUOTE | 625 | oper_expr QUOTE |
820 { $$ = make_postfix_op (QUOTE, $1, $2); } | 626 { $$ = curr_parser->make_postfix_op (QUOTE, $1, $2); } |
821 | oper_expr TRANSPOSE | 627 | oper_expr TRANSPOSE |
822 { $$ = make_postfix_op (TRANSPOSE, $1, $2); } | 628 { $$ = curr_parser->make_postfix_op (TRANSPOSE, $1, $2); } |
823 | oper_expr indirect_ref_op STRUCT_ELT | 629 | oper_expr indirect_ref_op STRUCT_ELT |
824 { $$ = make_indirect_ref ($1, $3->text ()); } | 630 { $$ = curr_parser->make_indirect_ref ($1, $3->text ()); } |
825 | oper_expr indirect_ref_op '(' expression ')' | 631 | oper_expr indirect_ref_op '(' expression ')' |
826 { $$ = make_indirect_ref ($1, $4); } | 632 { $$ = curr_parser->make_indirect_ref ($1, $4); } |
827 | PLUS_PLUS oper_expr %prec UNARY | 633 | PLUS_PLUS oper_expr %prec UNARY |
828 { $$ = make_prefix_op (PLUS_PLUS, $2, $1); } | 634 { $$ = curr_parser->make_prefix_op (PLUS_PLUS, $2, $1); } |
829 | MINUS_MINUS oper_expr %prec UNARY | 635 | MINUS_MINUS oper_expr %prec UNARY |
830 { $$ = make_prefix_op (MINUS_MINUS, $2, $1); } | 636 { $$ = curr_parser->make_prefix_op (MINUS_MINUS, $2, $1); } |
831 | EXPR_NOT oper_expr %prec UNARY | 637 | EXPR_NOT oper_expr %prec UNARY |
832 { $$ = make_prefix_op (EXPR_NOT, $2, $1); } | 638 { $$ = curr_parser->make_prefix_op (EXPR_NOT, $2, $1); } |
833 | '+' oper_expr %prec UNARY | 639 | '+' oper_expr %prec UNARY |
834 { $$ = make_prefix_op ('+', $2, $1); } | 640 { $$ = curr_parser->make_prefix_op ('+', $2, $1); } |
835 | '-' oper_expr %prec UNARY | 641 | '-' oper_expr %prec UNARY |
836 { $$ = make_prefix_op ('-', $2, $1); } | 642 { $$ = curr_parser->make_prefix_op ('-', $2, $1); } |
837 | oper_expr POW oper_expr | 643 | oper_expr POW oper_expr |
838 { $$ = make_binary_op (POW, $1, $2, $3); } | 644 { $$ = curr_parser->make_binary_op (POW, $1, $2, $3); } |
839 | oper_expr EPOW oper_expr | 645 | oper_expr EPOW oper_expr |
840 { $$ = make_binary_op (EPOW, $1, $2, $3); } | 646 { $$ = curr_parser->make_binary_op (EPOW, $1, $2, $3); } |
841 | oper_expr '+' oper_expr | 647 | oper_expr '+' oper_expr |
842 { $$ = make_binary_op ('+', $1, $2, $3); } | 648 { $$ = curr_parser->make_binary_op ('+', $1, $2, $3); } |
843 | oper_expr '-' oper_expr | 649 | oper_expr '-' oper_expr |
844 { $$ = make_binary_op ('-', $1, $2, $3); } | 650 { $$ = curr_parser->make_binary_op ('-', $1, $2, $3); } |
845 | oper_expr '*' oper_expr | 651 | oper_expr '*' oper_expr |
846 { $$ = make_binary_op ('*', $1, $2, $3); } | 652 { $$ = curr_parser->make_binary_op ('*', $1, $2, $3); } |
847 | oper_expr '/' oper_expr | 653 | oper_expr '/' oper_expr |
848 { $$ = make_binary_op ('/', $1, $2, $3); } | 654 { $$ = curr_parser->make_binary_op ('/', $1, $2, $3); } |
849 | oper_expr EPLUS oper_expr | 655 | oper_expr EPLUS oper_expr |
850 { $$ = make_binary_op ('+', $1, $2, $3); } | 656 { $$ = curr_parser->make_binary_op ('+', $1, $2, $3); } |
851 | oper_expr EMINUS oper_expr | 657 | oper_expr EMINUS oper_expr |
852 { $$ = make_binary_op ('-', $1, $2, $3); } | 658 { $$ = curr_parser->make_binary_op ('-', $1, $2, $3); } |
853 | oper_expr EMUL oper_expr | 659 | oper_expr EMUL oper_expr |
854 { $$ = make_binary_op (EMUL, $1, $2, $3); } | 660 { $$ = curr_parser->make_binary_op (EMUL, $1, $2, $3); } |
855 | oper_expr EDIV oper_expr | 661 | oper_expr EDIV oper_expr |
856 { $$ = make_binary_op (EDIV, $1, $2, $3); } | 662 { $$ = curr_parser->make_binary_op (EDIV, $1, $2, $3); } |
857 | oper_expr LEFTDIV oper_expr | 663 | oper_expr LEFTDIV oper_expr |
858 { $$ = make_binary_op (LEFTDIV, $1, $2, $3); } | 664 { $$ = curr_parser->make_binary_op (LEFTDIV, $1, $2, $3); } |
859 | oper_expr ELEFTDIV oper_expr | 665 | oper_expr ELEFTDIV oper_expr |
860 { $$ = make_binary_op (ELEFTDIV, $1, $2, $3); } | 666 { $$ = curr_parser->make_binary_op (ELEFTDIV, $1, $2, $3); } |
861 ; | 667 ; |
862 | 668 |
863 colon_expr : colon_expr1 | 669 colon_expr : colon_expr1 |
864 { $$ = finish_colon_expression ($1); } | 670 { $$ = curr_parser->finish_colon_expression ($1); } |
865 ; | 671 ; |
866 | 672 |
867 colon_expr1 : oper_expr | 673 colon_expr1 : oper_expr |
868 { $$ = new tree_colon_expression ($1); } | 674 { $$ = new tree_colon_expression ($1); } |
869 | colon_expr1 ':' oper_expr | 675 | colon_expr1 ':' oper_expr |
874 ; | 680 ; |
875 | 681 |
876 simple_expr : colon_expr | 682 simple_expr : colon_expr |
877 { $$ = $1; } | 683 { $$ = $1; } |
878 | simple_expr LSHIFT simple_expr | 684 | simple_expr LSHIFT simple_expr |
879 { $$ = make_binary_op (LSHIFT, $1, $2, $3); } | 685 { $$ = curr_parser->make_binary_op (LSHIFT, $1, $2, $3); } |
880 | simple_expr RSHIFT simple_expr | 686 | simple_expr RSHIFT simple_expr |
881 { $$ = make_binary_op (RSHIFT, $1, $2, $3); } | 687 { $$ = curr_parser->make_binary_op (RSHIFT, $1, $2, $3); } |
882 | simple_expr EXPR_LT simple_expr | 688 | simple_expr EXPR_LT simple_expr |
883 { $$ = make_binary_op (EXPR_LT, $1, $2, $3); } | 689 { $$ = curr_parser->make_binary_op (EXPR_LT, $1, $2, $3); } |
884 | simple_expr EXPR_LE simple_expr | 690 | simple_expr EXPR_LE simple_expr |
885 { $$ = make_binary_op (EXPR_LE, $1, $2, $3); } | 691 { $$ = curr_parser->make_binary_op (EXPR_LE, $1, $2, $3); } |
886 | simple_expr EXPR_EQ simple_expr | 692 | simple_expr EXPR_EQ simple_expr |
887 { $$ = make_binary_op (EXPR_EQ, $1, $2, $3); } | 693 { $$ = curr_parser->make_binary_op (EXPR_EQ, $1, $2, $3); } |
888 | simple_expr EXPR_GE simple_expr | 694 | simple_expr EXPR_GE simple_expr |
889 { $$ = make_binary_op (EXPR_GE, $1, $2, $3); } | 695 { $$ = curr_parser->make_binary_op (EXPR_GE, $1, $2, $3); } |
890 | simple_expr EXPR_GT simple_expr | 696 | simple_expr EXPR_GT simple_expr |
891 { $$ = make_binary_op (EXPR_GT, $1, $2, $3); } | 697 { $$ = curr_parser->make_binary_op (EXPR_GT, $1, $2, $3); } |
892 | simple_expr EXPR_NE simple_expr | 698 | simple_expr EXPR_NE simple_expr |
893 { $$ = make_binary_op (EXPR_NE, $1, $2, $3); } | 699 { $$ = curr_parser->make_binary_op (EXPR_NE, $1, $2, $3); } |
894 | simple_expr EXPR_AND simple_expr | 700 | simple_expr EXPR_AND simple_expr |
895 { $$ = make_binary_op (EXPR_AND, $1, $2, $3); } | 701 { $$ = curr_parser->make_binary_op (EXPR_AND, $1, $2, $3); } |
896 | simple_expr EXPR_OR simple_expr | 702 | simple_expr EXPR_OR simple_expr |
897 { $$ = make_binary_op (EXPR_OR, $1, $2, $3); } | 703 { $$ = curr_parser->make_binary_op (EXPR_OR, $1, $2, $3); } |
898 | simple_expr EXPR_AND_AND simple_expr | 704 | simple_expr EXPR_AND_AND simple_expr |
899 { $$ = make_boolean_op (EXPR_AND_AND, $1, $2, $3); } | 705 { $$ = curr_parser->make_boolean_op (EXPR_AND_AND, $1, $2, $3); } |
900 | simple_expr EXPR_OR_OR simple_expr | 706 | simple_expr EXPR_OR_OR simple_expr |
901 { $$ = make_boolean_op (EXPR_OR_OR, $1, $2, $3); } | 707 { $$ = curr_parser->make_boolean_op (EXPR_OR_OR, $1, $2, $3); } |
902 ; | 708 ; |
903 | 709 |
904 // Arrange for the lexer to return CLOSE_BRACE for ']' by looking ahead | 710 // Arrange for the lexer to return CLOSE_BRACE for ']' by looking ahead |
905 // one token for an assignment op. | 711 // one token for an assignment op. |
906 | 712 |
922 curr_lexer->pending_local_variables.clear (); | 728 curr_lexer->pending_local_variables.clear (); |
923 } | 729 } |
924 ; | 730 ; |
925 | 731 |
926 assign_expr : assign_lhs '=' expression | 732 assign_expr : assign_lhs '=' expression |
927 { $$ = make_assign_op ('=', $1, $2, $3); } | 733 { $$ = curr_parser->make_assign_op ('=', $1, $2, $3); } |
928 | assign_lhs ADD_EQ expression | 734 | assign_lhs ADD_EQ expression |
929 { $$ = make_assign_op (ADD_EQ, $1, $2, $3); } | 735 { $$ = curr_parser->make_assign_op (ADD_EQ, $1, $2, $3); } |
930 | assign_lhs SUB_EQ expression | 736 | assign_lhs SUB_EQ expression |
931 { $$ = make_assign_op (SUB_EQ, $1, $2, $3); } | 737 { $$ = curr_parser->make_assign_op (SUB_EQ, $1, $2, $3); } |
932 | assign_lhs MUL_EQ expression | 738 | assign_lhs MUL_EQ expression |
933 { $$ = make_assign_op (MUL_EQ, $1, $2, $3); } | 739 { $$ = curr_parser->make_assign_op (MUL_EQ, $1, $2, $3); } |
934 | assign_lhs DIV_EQ expression | 740 | assign_lhs DIV_EQ expression |
935 { $$ = make_assign_op (DIV_EQ, $1, $2, $3); } | 741 { $$ = curr_parser->make_assign_op (DIV_EQ, $1, $2, $3); } |
936 | assign_lhs LEFTDIV_EQ expression | 742 | assign_lhs LEFTDIV_EQ expression |
937 { $$ = make_assign_op (LEFTDIV_EQ, $1, $2, $3); } | 743 { $$ = curr_parser->make_assign_op (LEFTDIV_EQ, $1, $2, $3); } |
938 | assign_lhs POW_EQ expression | 744 | assign_lhs POW_EQ expression |
939 { $$ = make_assign_op (POW_EQ, $1, $2, $3); } | 745 { $$ = curr_parser->make_assign_op (POW_EQ, $1, $2, $3); } |
940 | assign_lhs LSHIFT_EQ expression | 746 | assign_lhs LSHIFT_EQ expression |
941 { $$ = make_assign_op (LSHIFT_EQ, $1, $2, $3); } | 747 { $$ = curr_parser->make_assign_op (LSHIFT_EQ, $1, $2, $3); } |
942 | assign_lhs RSHIFT_EQ expression | 748 | assign_lhs RSHIFT_EQ expression |
943 { $$ = make_assign_op (RSHIFT_EQ, $1, $2, $3); } | 749 { $$ = curr_parser->make_assign_op (RSHIFT_EQ, $1, $2, $3); } |
944 | assign_lhs EMUL_EQ expression | 750 | assign_lhs EMUL_EQ expression |
945 { $$ = make_assign_op (EMUL_EQ, $1, $2, $3); } | 751 { $$ = curr_parser->make_assign_op (EMUL_EQ, $1, $2, $3); } |
946 | assign_lhs EDIV_EQ expression | 752 | assign_lhs EDIV_EQ expression |
947 { $$ = make_assign_op (EDIV_EQ, $1, $2, $3); } | 753 { $$ = curr_parser->make_assign_op (EDIV_EQ, $1, $2, $3); } |
948 | assign_lhs ELEFTDIV_EQ expression | 754 | assign_lhs ELEFTDIV_EQ expression |
949 { $$ = make_assign_op (ELEFTDIV_EQ, $1, $2, $3); } | 755 { $$ = curr_parser->make_assign_op (ELEFTDIV_EQ, $1, $2, $3); } |
950 | assign_lhs EPOW_EQ expression | 756 | assign_lhs EPOW_EQ expression |
951 { $$ = make_assign_op (EPOW_EQ, $1, $2, $3); } | 757 { $$ = curr_parser->make_assign_op (EPOW_EQ, $1, $2, $3); } |
952 | assign_lhs AND_EQ expression | 758 | assign_lhs AND_EQ expression |
953 { $$ = make_assign_op (AND_EQ, $1, $2, $3); } | 759 { $$ = curr_parser->make_assign_op (AND_EQ, $1, $2, $3); } |
954 | assign_lhs OR_EQ expression | 760 | assign_lhs OR_EQ expression |
955 { $$ = make_assign_op (OR_EQ, $1, $2, $3); } | 761 { $$ = curr_parser->make_assign_op (OR_EQ, $1, $2, $3); } |
956 ; | 762 ; |
957 | 763 |
958 expression : simple_expr | 764 expression : simple_expr |
959 { $$ = $1; } | 765 { $$ = $1; } |
960 | assign_expr | 766 | assign_expr |
993 : // empty | 799 : // empty |
994 { curr_lexer->looking_at_decl_list = true; } | 800 { curr_lexer->looking_at_decl_list = true; } |
995 | 801 |
996 declaration : GLOBAL parsing_decl_list decl1 | 802 declaration : GLOBAL parsing_decl_list decl1 |
997 { | 803 { |
998 $$ = make_decl_command (GLOBAL, $1, $3); | 804 $$ = curr_parser->make_decl_command (GLOBAL, $1, $3); |
999 curr_lexer->looking_at_decl_list = false; | 805 curr_lexer->looking_at_decl_list = false; |
1000 } | 806 } |
1001 | PERSISTENT parsing_decl_list decl1 | 807 | PERSISTENT parsing_decl_list decl1 |
1002 { | 808 { |
1003 $$ = make_decl_command (PERSISTENT, $1, $3); | 809 $$ = curr_parser->make_decl_command (PERSISTENT, $1, $3); |
1004 curr_lexer->looking_at_decl_list = false; | 810 curr_lexer->looking_at_decl_list = false; |
1005 } | 811 } |
1006 ; | 812 ; |
1007 | 813 |
1008 decl1 : decl2 | 814 decl1 : decl2 |
1044 // If statement | 850 // If statement |
1045 // ============ | 851 // ============ |
1046 | 852 |
1047 if_command : IF stash_comment if_cmd_list END | 853 if_command : IF stash_comment if_cmd_list END |
1048 { | 854 { |
1049 if (! ($$ = finish_if_command ($1, $3, $4, $2))) | 855 if (! ($$ = curr_parser->finish_if_command ($1, $3, $4, $2))) |
1050 ABORT_PARSE; | 856 ABORT_PARSE; |
1051 } | 857 } |
1052 ; | 858 ; |
1053 | 859 |
1054 if_cmd_list : if_cmd_list1 | 860 if_cmd_list : if_cmd_list1 |
1062 | 868 |
1063 if_cmd_list1 : expression opt_sep opt_list | 869 if_cmd_list1 : expression opt_sep opt_list |
1064 { | 870 { |
1065 $1->mark_braindead_shortcircuit (curr_fcn_file_full_name); | 871 $1->mark_braindead_shortcircuit (curr_fcn_file_full_name); |
1066 | 872 |
1067 $$ = start_if_command ($1, $3); | 873 $$ = curr_parser->start_if_command ($1, $3); |
1068 } | 874 } |
1069 | if_cmd_list1 elseif_clause | 875 | if_cmd_list1 elseif_clause |
1070 { | 876 { |
1071 $1->append ($2); | 877 $1->append ($2); |
1072 $$ = $1; | 878 $$ = $1; |
1075 | 881 |
1076 elseif_clause : ELSEIF stash_comment opt_sep expression opt_sep opt_list | 882 elseif_clause : ELSEIF stash_comment opt_sep expression opt_sep opt_list |
1077 { | 883 { |
1078 $4->mark_braindead_shortcircuit (curr_fcn_file_full_name); | 884 $4->mark_braindead_shortcircuit (curr_fcn_file_full_name); |
1079 | 885 |
1080 $$ = make_elseif_clause ($1, $4, $6, $2); | 886 $$ = curr_parser->make_elseif_clause ($1, $4, $6, $2); |
1081 } | 887 } |
1082 ; | 888 ; |
1083 | 889 |
1084 else_clause : ELSE stash_comment opt_sep opt_list | 890 else_clause : ELSE stash_comment opt_sep opt_list |
1085 { $$ = new tree_if_clause ($4, $2); } | 891 { $$ = new tree_if_clause ($4, $2); } |
1089 // Switch statement | 895 // Switch statement |
1090 // ================ | 896 // ================ |
1091 | 897 |
1092 switch_command : SWITCH stash_comment expression opt_sep case_list END | 898 switch_command : SWITCH stash_comment expression opt_sep case_list END |
1093 { | 899 { |
1094 if (! ($$ = finish_switch_command ($1, $3, $5, $6, $2))) | 900 if (! ($$ = curr_parser->finish_switch_command ($1, $3, $5, $6, $2))) |
1095 ABORT_PARSE; | 901 ABORT_PARSE; |
1096 } | 902 } |
1097 ; | 903 ; |
1098 | 904 |
1099 case_list : // empty | 905 case_list : // empty |
1117 $$ = $1; | 923 $$ = $1; |
1118 } | 924 } |
1119 ; | 925 ; |
1120 | 926 |
1121 switch_case : CASE stash_comment opt_sep expression opt_sep opt_list | 927 switch_case : CASE stash_comment opt_sep expression opt_sep opt_list |
1122 { $$ = make_switch_case ($1, $4, $6, $2); } | 928 { $$ = curr_parser->make_switch_case ($1, $4, $6, $2); } |
1123 ; | 929 ; |
1124 | 930 |
1125 default_case : OTHERWISE stash_comment opt_sep opt_list | 931 default_case : OTHERWISE stash_comment opt_sep opt_list |
1126 { | 932 { |
1127 $$ = new tree_switch_case ($4, $2); | 933 $$ = new tree_switch_case ($4, $2); |
1134 | 940 |
1135 loop_command : WHILE stash_comment expression opt_sep opt_list END | 941 loop_command : WHILE stash_comment expression opt_sep opt_list END |
1136 { | 942 { |
1137 $3->mark_braindead_shortcircuit (curr_fcn_file_full_name); | 943 $3->mark_braindead_shortcircuit (curr_fcn_file_full_name); |
1138 | 944 |
1139 if (! ($$ = make_while_command ($1, $3, $5, $6, $2))) | 945 if (! ($$ = curr_parser->make_while_command ($1, $3, $5, $6, $2))) |
1140 ABORT_PARSE; | 946 ABORT_PARSE; |
1141 } | 947 } |
1142 | DO stash_comment opt_sep opt_list UNTIL expression | 948 | DO stash_comment opt_sep opt_list UNTIL expression |
1143 { | 949 { |
1144 if (! ($$ = make_do_until_command ($5, $4, $6, $2))) | 950 if (! ($$ = curr_parser->make_do_until_command ($5, $4, $6, $2))) |
1145 ABORT_PARSE; | 951 ABORT_PARSE; |
1146 } | 952 } |
1147 | FOR stash_comment assign_lhs '=' expression opt_sep opt_list END | 953 | FOR stash_comment assign_lhs '=' expression opt_sep opt_list END |
1148 { | 954 { |
1149 if (! ($$ = make_for_command (FOR, $1, $3, $5, 0, | 955 if (! ($$ = curr_parser->make_for_command (FOR, $1, $3, $5, 0, |
1150 $7, $8, $2))) | 956 $7, $8, $2))) |
1151 ABORT_PARSE; | 957 ABORT_PARSE; |
1152 } | 958 } |
1153 | FOR stash_comment '(' assign_lhs '=' expression ')' opt_sep opt_list END | 959 | FOR stash_comment '(' assign_lhs '=' expression ')' opt_sep opt_list END |
1154 { | 960 { |
1155 if (! ($$ = make_for_command (FOR, $1, $4, $6, 0, | 961 if (! ($$ = curr_parser->make_for_command (FOR, $1, $4, $6, 0, |
1156 $9, $10, $2))) | 962 $9, $10, $2))) |
1157 ABORT_PARSE; | 963 ABORT_PARSE; |
1158 } | 964 } |
1159 | PARFOR stash_comment assign_lhs '=' expression opt_sep opt_list END | 965 | PARFOR stash_comment assign_lhs '=' expression opt_sep opt_list END |
1160 { | 966 { |
1161 if (! ($$ = make_for_command (PARFOR, $1, $3, $5, | 967 if (! ($$ = curr_parser->make_for_command (PARFOR, $1, $3, $5, |
1162 0, $7, $8, $2))) | 968 0, $7, $8, $2))) |
1163 ABORT_PARSE; | 969 ABORT_PARSE; |
1164 } | 970 } |
1165 | PARFOR stash_comment '(' assign_lhs '=' expression ',' expression ')' opt_sep opt_list END | 971 | PARFOR stash_comment '(' assign_lhs '=' expression ',' expression ')' opt_sep opt_list END |
1166 { | 972 { |
1167 if (! ($$ = make_for_command (PARFOR, $1, $4, $6, | 973 if (! ($$ = curr_parser->make_for_command (PARFOR, $1, $4, $6, |
1168 $8, $11, $12, $2))) | 974 $8, $11, $12, $2))) |
1169 ABORT_PARSE; | 975 ABORT_PARSE; |
1170 } | 976 } |
1171 ; | 977 ; |
1172 | 978 |
1174 // Jumping | 980 // Jumping |
1175 // ======= | 981 // ======= |
1176 | 982 |
1177 jump_command : BREAK | 983 jump_command : BREAK |
1178 { | 984 { |
1179 if (! ($$ = make_break_command ($1))) | 985 if (! ($$ = curr_parser->make_break_command ($1))) |
1180 ABORT_PARSE; | 986 ABORT_PARSE; |
1181 } | 987 } |
1182 | CONTINUE | 988 | CONTINUE |
1183 { | 989 { |
1184 if (! ($$ = make_continue_command ($1))) | 990 if (! ($$ = curr_parser->make_continue_command ($1))) |
1185 ABORT_PARSE; | 991 ABORT_PARSE; |
1186 } | 992 } |
1187 | FUNC_RET | 993 | FUNC_RET |
1188 { | 994 { |
1189 if (! ($$ = make_return_command ($1))) | 995 if (! ($$ = curr_parser->make_return_command ($1))) |
1190 ABORT_PARSE; | 996 ABORT_PARSE; |
1191 } | 997 } |
1192 ; | 998 ; |
1193 | 999 |
1194 // ========== | 1000 // ========== |
1196 // ========== | 1002 // ========== |
1197 | 1003 |
1198 except_command : UNWIND stash_comment opt_sep opt_list CLEANUP | 1004 except_command : UNWIND stash_comment opt_sep opt_list CLEANUP |
1199 stash_comment opt_sep opt_list END | 1005 stash_comment opt_sep opt_list END |
1200 { | 1006 { |
1201 if (! ($$ = make_unwind_command ($1, $4, $8, $9, $2, $6))) | 1007 if (! ($$ = curr_parser->make_unwind_command ($1, $4, $8, $9, $2, $6))) |
1202 ABORT_PARSE; | 1008 ABORT_PARSE; |
1203 } | 1009 } |
1204 | TRY stash_comment opt_sep opt_list CATCH | 1010 | TRY stash_comment opt_sep opt_list CATCH |
1205 stash_comment opt_sep opt_list END | 1011 stash_comment opt_sep opt_list END |
1206 { | 1012 { |
1207 if (! ($$ = make_try_command ($1, $4, $8, $9, $2, $6))) | 1013 if (! ($$ = curr_parser->make_try_command ($1, $4, $8, $9, $2, $6))) |
1208 ABORT_PARSE; | 1014 ABORT_PARSE; |
1209 } | 1015 } |
1210 | TRY stash_comment opt_sep opt_list END | 1016 | TRY stash_comment opt_sep opt_list END |
1211 { | 1017 { |
1212 if (! ($$ = make_try_command ($1, $4, 0, $5, $2, 0))) | 1018 if (! ($$ = curr_parser->make_try_command ($1, $4, 0, $5, $2, 0))) |
1213 ABORT_PARSE; | 1019 ABORT_PARSE; |
1214 } | 1020 } |
1215 ; | 1021 ; |
1216 | 1022 |
1217 // =========================================== | 1023 // =========================================== |
1340 // =========== | 1146 // =========== |
1341 | 1147 |
1342 script_file : SCRIPT_FILE opt_list END_OF_INPUT | 1148 script_file : SCRIPT_FILE opt_list END_OF_INPUT |
1343 { | 1149 { |
1344 tree_statement *end_of_script | 1150 tree_statement *end_of_script |
1345 = make_end ("endscript", curr_lexer->input_line_number, | 1151 = curr_parser->make_end ("endscript", |
1346 curr_lexer->current_input_column); | 1152 curr_lexer->input_line_number, |
1347 | 1153 curr_lexer->current_input_column); |
1348 make_script ($2, end_of_script); | 1154 |
1155 curr_parser->make_script ($2, end_of_script); | |
1349 | 1156 |
1350 $$ = 0; | 1157 $$ = 0; |
1351 } | 1158 } |
1352 ; | 1159 ; |
1353 | 1160 |
1376 } | 1183 } |
1377 ; | 1184 ; |
1378 | 1185 |
1379 function : function_beg function1 | 1186 function : function_beg function1 |
1380 { | 1187 { |
1381 $$ = finish_function (0, $2, $1); | 1188 $$ = curr_parser->finish_function (0, $2, $1); |
1382 recover_from_parsing_function (); | 1189 curr_parser->recover_from_parsing_function (); |
1383 } | 1190 } |
1384 | function_beg return_list '=' function1 | 1191 | function_beg return_list '=' function1 |
1385 { | 1192 { |
1386 $$ = finish_function ($2, $4, $1); | 1193 $$ = curr_parser->finish_function ($2, $4, $1); |
1387 recover_from_parsing_function (); | 1194 curr_parser->recover_from_parsing_function (); |
1388 } | 1195 } |
1389 ; | 1196 ; |
1390 | 1197 |
1391 fcn_name : identifier | 1198 fcn_name : identifier |
1392 { | 1199 { |
1415 { | 1222 { |
1416 std::string fname = $1->name (); | 1223 std::string fname = $1->name (); |
1417 | 1224 |
1418 delete $1; | 1225 delete $1; |
1419 | 1226 |
1420 if (! ($$ = frob_function (fname, $2))) | 1227 if (! ($$ = curr_parser->frob_function (fname, $2))) |
1421 ABORT_PARSE; | 1228 ABORT_PARSE; |
1422 } | 1229 } |
1423 ; | 1230 ; |
1424 | 1231 |
1425 function2 : param_list opt_sep opt_list function_end | 1232 function2 : param_list opt_sep opt_list function_end |
1426 { $$ = start_function ($1, $3, $4); } | 1233 { $$ = curr_parser->start_function ($1, $3, $4); } |
1427 | opt_sep opt_list function_end | 1234 | opt_sep opt_list function_end |
1428 { $$ = start_function (0, $2, $3); } | 1235 { $$ = curr_parser->start_function (0, $2, $3); } |
1429 ; | 1236 ; |
1430 | 1237 |
1431 function_end : END | 1238 function_end : END |
1432 { | 1239 { |
1433 endfunction_found = true; | 1240 endfunction_found = true; |
1434 if (end_token_ok ($1, token::function_end)) | 1241 if (curr_parser->end_token_ok ($1, token::function_end)) |
1435 $$ = make_end ("endfunction", $1->line (), $1->column ()); | 1242 $$ = curr_parser->make_end ("endfunction", $1->line (), $1->column ()); |
1436 else | 1243 else |
1437 ABORT_PARSE; | 1244 ABORT_PARSE; |
1438 } | 1245 } |
1439 | END_OF_INPUT | 1246 | END_OF_INPUT |
1440 { | 1247 { |
1464 { | 1271 { |
1465 yyerror ("classdef body open at end of input"); | 1272 yyerror ("classdef body open at end of input"); |
1466 YYABORT; | 1273 YYABORT; |
1467 } | 1274 } |
1468 | 1275 |
1469 $$ = make_end ("endfunction", curr_lexer->input_line_number, | 1276 $$ = curr_parser->make_end ("endfunction", |
1470 curr_lexer->current_input_column); | 1277 curr_lexer->input_line_number, |
1278 curr_lexer->current_input_column); | |
1471 } | 1279 } |
1472 ; | 1280 ; |
1473 | 1281 |
1474 // ======== | 1282 // ======== |
1475 // Classdef | 1283 // Classdef |
1484 | 1292 |
1485 classdef_end : END | 1293 classdef_end : END |
1486 { | 1294 { |
1487 curr_lexer->parsing_classdef = false; | 1295 curr_lexer->parsing_classdef = false; |
1488 | 1296 |
1489 if (end_token_ok ($1, token::classdef_end)) | 1297 if (curr_parser->end_token_ok ($1, token::classdef_end)) |
1490 $$ = make_end ("endclassdef", $1->line (), $1->column ()); | 1298 $$ = curr_parser->make_end ("endclassdef", $1->line (), $1->column ()); |
1491 else | 1299 else |
1492 ABORT_PARSE; | 1300 ABORT_PARSE; |
1493 } | 1301 } |
1494 ; | 1302 ; |
1495 | 1303 |
1732 parse_error ("%s", msg.c_str ()); | 1540 parse_error ("%s", msg.c_str ()); |
1733 } | 1541 } |
1734 | 1542 |
1735 // Error mesages for mismatched end tokens. | 1543 // Error mesages for mismatched end tokens. |
1736 | 1544 |
1737 static void | 1545 void |
1738 end_error (const char *type, token::end_tok_type ettype, int l, int c) | 1546 octave_parser::end_error (const char *type, token::end_tok_type ettype, |
1547 int l, int c) | |
1739 { | 1548 { |
1740 static const char *fmt | 1549 static const char *fmt |
1741 = "'%s' command matched by '%s' near line %d column %d"; | 1550 = "'%s' command matched by '%s' near line %d column %d"; |
1742 | 1551 |
1743 switch (ettype) | 1552 switch (ettype) |
1784 } | 1593 } |
1785 } | 1594 } |
1786 | 1595 |
1787 // Check to see that end tokens are properly matched. | 1596 // Check to see that end tokens are properly matched. |
1788 | 1597 |
1789 static bool | 1598 bool |
1790 end_token_ok (token *tok, token::end_tok_type expected) | 1599 octave_parser::end_token_ok (token *tok, token::end_tok_type expected) |
1791 { | 1600 { |
1792 bool retval = true; | 1601 bool retval = true; |
1793 | 1602 |
1794 token::end_tok_type ettype = tok->ettype (); | 1603 token::end_tok_type ettype = tok->ettype (); |
1795 | 1604 |
1854 } | 1663 } |
1855 | 1664 |
1856 // Maybe print a warning if an assignment expression is used as the | 1665 // Maybe print a warning if an assignment expression is used as the |
1857 // test in a logical expression. | 1666 // test in a logical expression. |
1858 | 1667 |
1859 static void | 1668 void |
1860 maybe_warn_assign_as_truth_value (tree_expression *expr) | 1669 octave_parser::maybe_warn_assign_as_truth_value (tree_expression *expr) |
1861 { | 1670 { |
1862 if (expr->is_assignment_expression () | 1671 if (expr->is_assignment_expression () |
1863 && expr->paren_count () < 2) | 1672 && expr->paren_count () < 2) |
1864 { | 1673 { |
1865 if (curr_fcn_file_full_name.empty ()) | 1674 if (curr_fcn_file_full_name.empty ()) |
1874 } | 1683 } |
1875 } | 1684 } |
1876 | 1685 |
1877 // Maybe print a warning about switch labels that aren't constants. | 1686 // Maybe print a warning about switch labels that aren't constants. |
1878 | 1687 |
1879 static void | 1688 void |
1880 maybe_warn_variable_switch_label (tree_expression *expr) | 1689 octave_parser::maybe_warn_variable_switch_label (tree_expression *expr) |
1881 { | 1690 { |
1882 if (! expr->is_constant ()) | 1691 if (! expr->is_constant ()) |
1883 { | 1692 { |
1884 if (curr_fcn_file_full_name.empty ()) | 1693 if (curr_fcn_file_full_name.empty ()) |
1885 warning_with_id ("Octave:variable-switch-label", | 1694 warning_with_id ("Octave:variable-switch-label", |
1981 return retval; | 1790 return retval; |
1982 } | 1791 } |
1983 | 1792 |
1984 // Finish building a range. | 1793 // Finish building a range. |
1985 | 1794 |
1986 static tree_expression * | 1795 tree_expression * |
1987 finish_colon_expression (tree_colon_expression *e) | 1796 octave_parser::finish_colon_expression (tree_colon_expression *e) |
1988 { | 1797 { |
1989 tree_expression *retval = e; | 1798 tree_expression *retval = e; |
1990 | 1799 |
1991 unwind_protect frame; | 1800 unwind_protect frame; |
1992 | 1801 |
2045 return retval; | 1854 return retval; |
2046 } | 1855 } |
2047 | 1856 |
2048 // Make a constant. | 1857 // Make a constant. |
2049 | 1858 |
2050 static tree_constant * | 1859 tree_constant * |
2051 make_constant (int op, token *tok_val) | 1860 octave_parser::make_constant (int op, token *tok_val) |
2052 { | 1861 { |
2053 int l = tok_val->line (); | 1862 int l = tok_val->line (); |
2054 int c = tok_val->column (); | 1863 int c = tok_val->column (); |
2055 | 1864 |
2056 tree_constant *retval = 0; | 1865 tree_constant *retval = 0; |
2108 return retval; | 1917 return retval; |
2109 } | 1918 } |
2110 | 1919 |
2111 // Make a function handle. | 1920 // Make a function handle. |
2112 | 1921 |
2113 static tree_fcn_handle * | 1922 tree_fcn_handle * |
2114 make_fcn_handle (token *tok_val) | 1923 octave_parser::make_fcn_handle (token *tok_val) |
2115 { | 1924 { |
2116 int l = tok_val->line (); | 1925 int l = tok_val->line (); |
2117 int c = tok_val->column (); | 1926 int c = tok_val->column (); |
2118 | 1927 |
2119 tree_fcn_handle *retval = new tree_fcn_handle (tok_val->text (), l, c); | 1928 tree_fcn_handle *retval = new tree_fcn_handle (tok_val->text (), l, c); |
2121 return retval; | 1930 return retval; |
2122 } | 1931 } |
2123 | 1932 |
2124 // Make an anonymous function handle. | 1933 // Make an anonymous function handle. |
2125 | 1934 |
2126 static tree_anon_fcn_handle * | 1935 tree_anon_fcn_handle * |
2127 make_anon_fcn_handle (tree_parameter_list *param_list, tree_statement *stmt) | 1936 octave_parser::make_anon_fcn_handle (tree_parameter_list *param_list, |
1937 tree_statement *stmt) | |
2128 { | 1938 { |
2129 // FIXME -- need to get these from the location of the @ symbol. | 1939 // FIXME -- need to get these from the location of the @ symbol. |
2130 int l = curr_lexer->input_line_number; | 1940 int l = curr_lexer->input_line_number; |
2131 int c = curr_lexer->current_input_column; | 1941 int c = curr_lexer->current_input_column; |
2132 | 1942 |
2154 return retval; | 1964 return retval; |
2155 } | 1965 } |
2156 | 1966 |
2157 // Build a binary expression. | 1967 // Build a binary expression. |
2158 | 1968 |
2159 static tree_expression * | 1969 tree_expression * |
2160 make_binary_op (int op, tree_expression *op1, token *tok_val, | 1970 octave_parser::make_binary_op (int op, tree_expression *op1, token *tok_val, |
2161 tree_expression *op2) | 1971 tree_expression *op2) |
2162 { | 1972 { |
2163 octave_value::binary_op t = octave_value::unknown_binary_op; | 1973 octave_value::binary_op t = octave_value::unknown_binary_op; |
2164 | 1974 |
2165 switch (op) | 1975 switch (op) |
2166 { | 1976 { |
2258 return fold (e); | 2068 return fold (e); |
2259 } | 2069 } |
2260 | 2070 |
2261 // Build a boolean expression. | 2071 // Build a boolean expression. |
2262 | 2072 |
2263 static tree_expression * | 2073 tree_expression * |
2264 make_boolean_op (int op, tree_expression *op1, token *tok_val, | 2074 octave_parser::make_boolean_op (int op, tree_expression *op1, token *tok_val, |
2265 tree_expression *op2) | 2075 tree_expression *op2) |
2266 { | 2076 { |
2267 tree_boolean_expression::type t; | 2077 tree_boolean_expression::type t; |
2268 | 2078 |
2269 switch (op) | 2079 switch (op) |
2270 { | 2080 { |
2290 return fold (e); | 2100 return fold (e); |
2291 } | 2101 } |
2292 | 2102 |
2293 // Build a prefix expression. | 2103 // Build a prefix expression. |
2294 | 2104 |
2295 static tree_expression * | 2105 tree_expression * |
2296 make_prefix_op (int op, tree_expression *op1, token *tok_val) | 2106 octave_parser::make_prefix_op (int op, tree_expression *op1, token *tok_val) |
2297 { | 2107 { |
2298 octave_value::unary_op t = octave_value::unknown_unary_op; | 2108 octave_value::unary_op t = octave_value::unknown_unary_op; |
2299 | 2109 |
2300 switch (op) | 2110 switch (op) |
2301 { | 2111 { |
2333 return fold (e); | 2143 return fold (e); |
2334 } | 2144 } |
2335 | 2145 |
2336 // Build a postfix expression. | 2146 // Build a postfix expression. |
2337 | 2147 |
2338 static tree_expression * | 2148 tree_expression * |
2339 make_postfix_op (int op, tree_expression *op1, token *tok_val) | 2149 octave_parser::make_postfix_op (int op, tree_expression *op1, token *tok_val) |
2340 { | 2150 { |
2341 octave_value::unary_op t = octave_value::unknown_unary_op; | 2151 octave_value::unary_op t = octave_value::unknown_unary_op; |
2342 | 2152 |
2343 switch (op) | 2153 switch (op) |
2344 { | 2154 { |
2372 return fold (e); | 2182 return fold (e); |
2373 } | 2183 } |
2374 | 2184 |
2375 // Build an unwind-protect command. | 2185 // Build an unwind-protect command. |
2376 | 2186 |
2377 static tree_command * | 2187 tree_command * |
2378 make_unwind_command (token *unwind_tok, tree_statement_list *body, | 2188 octave_parser::make_unwind_command (token *unwind_tok, |
2379 tree_statement_list *cleanup, token *end_tok, | 2189 tree_statement_list *body, |
2380 octave_comment_list *lc, octave_comment_list *mc) | 2190 tree_statement_list *cleanup, |
2191 token *end_tok, | |
2192 octave_comment_list *lc, | |
2193 octave_comment_list *mc) | |
2381 { | 2194 { |
2382 tree_command *retval = 0; | 2195 tree_command *retval = 0; |
2383 | 2196 |
2384 if (end_token_ok (end_tok, token::unwind_protect_end)) | 2197 if (end_token_ok (end_tok, token::unwind_protect_end)) |
2385 { | 2198 { |
2395 return retval; | 2208 return retval; |
2396 } | 2209 } |
2397 | 2210 |
2398 // Build a try-catch command. | 2211 // Build a try-catch command. |
2399 | 2212 |
2400 static tree_command * | 2213 tree_command * |
2401 make_try_command (token *try_tok, tree_statement_list *body, | 2214 octave_parser::make_try_command (token *try_tok, tree_statement_list *body, |
2402 tree_statement_list *cleanup, token *end_tok, | 2215 tree_statement_list *cleanup, token *end_tok, |
2403 octave_comment_list *lc, octave_comment_list *mc) | 2216 octave_comment_list *lc, |
2217 octave_comment_list *mc) | |
2404 { | 2218 { |
2405 tree_command *retval = 0; | 2219 tree_command *retval = 0; |
2406 | 2220 |
2407 if (end_token_ok (end_tok, token::try_catch_end)) | 2221 if (end_token_ok (end_tok, token::try_catch_end)) |
2408 { | 2222 { |
2418 return retval; | 2232 return retval; |
2419 } | 2233 } |
2420 | 2234 |
2421 // Build a while command. | 2235 // Build a while command. |
2422 | 2236 |
2423 static tree_command * | 2237 tree_command * |
2424 make_while_command (token *while_tok, tree_expression *expr, | 2238 octave_parser::make_while_command (token *while_tok, tree_expression *expr, |
2425 tree_statement_list *body, token *end_tok, | 2239 tree_statement_list *body, token *end_tok, |
2426 octave_comment_list *lc) | 2240 octave_comment_list *lc) |
2427 { | 2241 { |
2428 tree_command *retval = 0; | 2242 tree_command *retval = 0; |
2429 | 2243 |
2430 maybe_warn_assign_as_truth_value (expr); | 2244 maybe_warn_assign_as_truth_value (expr); |
2431 | 2245 |
2444 return retval; | 2258 return retval; |
2445 } | 2259 } |
2446 | 2260 |
2447 // Build a do-until command. | 2261 // Build a do-until command. |
2448 | 2262 |
2449 static tree_command * | 2263 tree_command * |
2450 make_do_until_command (token *until_tok, tree_statement_list *body, | 2264 octave_parser::make_do_until_command (token *until_tok, |
2451 tree_expression *expr, octave_comment_list *lc) | 2265 tree_statement_list *body, |
2266 tree_expression *expr, | |
2267 octave_comment_list *lc) | |
2452 { | 2268 { |
2453 tree_command *retval = 0; | 2269 tree_command *retval = 0; |
2454 | 2270 |
2455 maybe_warn_assign_as_truth_value (expr); | 2271 maybe_warn_assign_as_truth_value (expr); |
2456 | 2272 |
2466 return retval; | 2282 return retval; |
2467 } | 2283 } |
2468 | 2284 |
2469 // Build a for command. | 2285 // Build a for command. |
2470 | 2286 |
2471 static tree_command * | 2287 tree_command * |
2472 make_for_command (int tok_id, token *for_tok, tree_argument_list *lhs, | 2288 octave_parser::make_for_command (int tok_id, token *for_tok, |
2473 tree_expression *expr, tree_expression *maxproc, | 2289 tree_argument_list *lhs, |
2474 tree_statement_list *body, token *end_tok, | 2290 tree_expression *expr, |
2475 octave_comment_list *lc) | 2291 tree_expression *maxproc, |
2292 tree_statement_list *body, token *end_tok, | |
2293 octave_comment_list *lc) | |
2476 { | 2294 { |
2477 tree_command *retval = 0; | 2295 tree_command *retval = 0; |
2478 | 2296 |
2479 bool parfor = tok_id == PARFOR; | 2297 bool parfor = tok_id == PARFOR; |
2480 | 2298 |
2509 return retval; | 2327 return retval; |
2510 } | 2328 } |
2511 | 2329 |
2512 // Build a break command. | 2330 // Build a break command. |
2513 | 2331 |
2514 static tree_command * | 2332 tree_command * |
2515 make_break_command (token *break_tok) | 2333 octave_parser::make_break_command (token *break_tok) |
2516 { | 2334 { |
2517 tree_command *retval = 0; | 2335 tree_command *retval = 0; |
2518 | 2336 |
2519 int l = break_tok->line (); | 2337 int l = break_tok->line (); |
2520 int c = break_tok->column (); | 2338 int c = break_tok->column (); |
2524 return retval; | 2342 return retval; |
2525 } | 2343 } |
2526 | 2344 |
2527 // Build a continue command. | 2345 // Build a continue command. |
2528 | 2346 |
2529 static tree_command * | 2347 tree_command * |
2530 make_continue_command (token *continue_tok) | 2348 octave_parser::make_continue_command (token *continue_tok) |
2531 { | 2349 { |
2532 tree_command *retval = 0; | 2350 tree_command *retval = 0; |
2533 | 2351 |
2534 int l = continue_tok->line (); | 2352 int l = continue_tok->line (); |
2535 int c = continue_tok->column (); | 2353 int c = continue_tok->column (); |
2539 return retval; | 2357 return retval; |
2540 } | 2358 } |
2541 | 2359 |
2542 // Build a return command. | 2360 // Build a return command. |
2543 | 2361 |
2544 static tree_command * | 2362 tree_command * |
2545 make_return_command (token *return_tok) | 2363 octave_parser::make_return_command (token *return_tok) |
2546 { | 2364 { |
2547 tree_command *retval = 0; | 2365 tree_command *retval = 0; |
2548 | 2366 |
2549 int l = return_tok->line (); | 2367 int l = return_tok->line (); |
2550 int c = return_tok->column (); | 2368 int c = return_tok->column (); |
2554 return retval; | 2372 return retval; |
2555 } | 2373 } |
2556 | 2374 |
2557 // Start an if command. | 2375 // Start an if command. |
2558 | 2376 |
2559 static tree_if_command_list * | 2377 tree_if_command_list * |
2560 start_if_command (tree_expression *expr, tree_statement_list *list) | 2378 octave_parser::start_if_command (tree_expression *expr, |
2379 tree_statement_list *list) | |
2561 { | 2380 { |
2562 maybe_warn_assign_as_truth_value (expr); | 2381 maybe_warn_assign_as_truth_value (expr); |
2563 | 2382 |
2564 tree_if_clause *t = new tree_if_clause (expr, list); | 2383 tree_if_clause *t = new tree_if_clause (expr, list); |
2565 | 2384 |
2566 return new tree_if_command_list (t); | 2385 return new tree_if_command_list (t); |
2567 } | 2386 } |
2568 | 2387 |
2569 // Finish an if command. | 2388 // Finish an if command. |
2570 | 2389 |
2571 static tree_if_command * | 2390 tree_if_command * |
2572 finish_if_command (token *if_tok, tree_if_command_list *list, | 2391 octave_parser::finish_if_command (token *if_tok, tree_if_command_list *list, |
2573 token *end_tok, octave_comment_list *lc) | 2392 token *end_tok, octave_comment_list *lc) |
2574 { | 2393 { |
2575 tree_if_command *retval = 0; | 2394 tree_if_command *retval = 0; |
2576 | 2395 |
2577 if (end_token_ok (end_tok, token::if_end)) | 2396 if (end_token_ok (end_tok, token::if_end)) |
2578 { | 2397 { |
2598 return retval; | 2417 return retval; |
2599 } | 2418 } |
2600 | 2419 |
2601 // Build an elseif clause. | 2420 // Build an elseif clause. |
2602 | 2421 |
2603 static tree_if_clause * | 2422 tree_if_clause * |
2604 make_elseif_clause (token *elseif_tok, tree_expression *expr, | 2423 octave_parser::make_elseif_clause (token *elseif_tok, tree_expression *expr, |
2605 tree_statement_list *list, octave_comment_list *lc) | 2424 tree_statement_list *list, |
2425 octave_comment_list *lc) | |
2606 { | 2426 { |
2607 maybe_warn_assign_as_truth_value (expr); | 2427 maybe_warn_assign_as_truth_value (expr); |
2608 | 2428 |
2609 int l = elseif_tok->line (); | 2429 int l = elseif_tok->line (); |
2610 int c = elseif_tok->column (); | 2430 int c = elseif_tok->column (); |
2612 return new tree_if_clause (expr, list, lc, l, c); | 2432 return new tree_if_clause (expr, list, lc, l, c); |
2613 } | 2433 } |
2614 | 2434 |
2615 // Finish a switch command. | 2435 // Finish a switch command. |
2616 | 2436 |
2617 static tree_switch_command * | 2437 tree_switch_command * |
2618 finish_switch_command (token *switch_tok, tree_expression *expr, | 2438 octave_parser::finish_switch_command (token *switch_tok, tree_expression *expr, |
2619 tree_switch_case_list *list, token *end_tok, | 2439 tree_switch_case_list *list, |
2620 octave_comment_list *lc) | 2440 token *end_tok, octave_comment_list *lc) |
2621 { | 2441 { |
2622 tree_switch_command *retval = 0; | 2442 tree_switch_command *retval = 0; |
2623 | 2443 |
2624 if (end_token_ok (end_tok, token::switch_end)) | 2444 if (end_token_ok (end_tok, token::switch_end)) |
2625 { | 2445 { |
2645 return retval; | 2465 return retval; |
2646 } | 2466 } |
2647 | 2467 |
2648 // Build a switch case. | 2468 // Build a switch case. |
2649 | 2469 |
2650 static tree_switch_case * | 2470 tree_switch_case * |
2651 make_switch_case (token *case_tok, tree_expression *expr, | 2471 octave_parser::make_switch_case (token *case_tok, tree_expression *expr, |
2652 tree_statement_list *list, octave_comment_list *lc) | 2472 tree_statement_list *list, |
2473 octave_comment_list *lc) | |
2653 { | 2474 { |
2654 maybe_warn_variable_switch_label (expr); | 2475 maybe_warn_variable_switch_label (expr); |
2655 | 2476 |
2656 int l = case_tok->line (); | 2477 int l = case_tok->line (); |
2657 int c = case_tok->column (); | 2478 int c = case_tok->column (); |
2659 return new tree_switch_case (expr, list, lc, l, c); | 2480 return new tree_switch_case (expr, list, lc, l, c); |
2660 } | 2481 } |
2661 | 2482 |
2662 // Build an assignment to a variable. | 2483 // Build an assignment to a variable. |
2663 | 2484 |
2664 static tree_expression * | 2485 tree_expression * |
2665 make_assign_op (int op, tree_argument_list *lhs, token *eq_tok, | 2486 octave_parser::make_assign_op (int op, tree_argument_list *lhs, token *eq_tok, |
2666 tree_expression *rhs) | 2487 tree_expression *rhs) |
2667 { | 2488 { |
2668 tree_expression *retval = 0; | 2489 tree_expression *retval = 0; |
2669 | 2490 |
2670 octave_value::assign_op t = octave_value::unknown_assign_op; | 2491 octave_value::assign_op t = octave_value::unknown_assign_op; |
2671 | 2492 |
2755 return retval; | 2576 return retval; |
2756 } | 2577 } |
2757 | 2578 |
2758 // Define a script. | 2579 // Define a script. |
2759 | 2580 |
2760 static void | 2581 void |
2761 make_script (tree_statement_list *cmds, tree_statement *end_script) | 2582 octave_parser::make_script (tree_statement_list *cmds, |
2583 tree_statement *end_script) | |
2762 { | 2584 { |
2763 std::string doc_string; | 2585 std::string doc_string; |
2764 | 2586 |
2765 if (! help_buf.empty ()) | 2587 if (! help_buf.empty ()) |
2766 { | 2588 { |
2789 symbol_table::unmark_forced_variables (); | 2611 symbol_table::unmark_forced_variables (); |
2790 } | 2612 } |
2791 | 2613 |
2792 // Begin defining a function. | 2614 // Begin defining a function. |
2793 | 2615 |
2794 static octave_user_function * | 2616 octave_user_function * |
2795 start_function (tree_parameter_list *param_list, tree_statement_list *body, | 2617 octave_parser::start_function (tree_parameter_list *param_list, |
2796 tree_statement *end_fcn_stmt) | 2618 tree_statement_list *body, |
2619 tree_statement *end_fcn_stmt) | |
2797 { | 2620 { |
2798 // We'll fill in the return list later. | 2621 // We'll fill in the return list later. |
2799 | 2622 |
2800 if (! body) | 2623 if (! body) |
2801 body = new tree_statement_list (); | 2624 body = new tree_statement_list (); |
2814 } | 2637 } |
2815 | 2638 |
2816 return fcn; | 2639 return fcn; |
2817 } | 2640 } |
2818 | 2641 |
2819 static tree_statement * | 2642 tree_statement * |
2820 make_end (const std::string& type, int l, int c) | 2643 octave_parser::make_end (const std::string& type, int l, int c) |
2821 { | 2644 { |
2822 return make_statement (new tree_no_op_command (type, l, c)); | 2645 return make_statement (new tree_no_op_command (type, l, c)); |
2823 } | 2646 } |
2824 | 2647 |
2825 // Do most of the work for defining a function. | 2648 // Do most of the work for defining a function. |
2826 | 2649 |
2827 static octave_user_function * | 2650 octave_user_function * |
2828 frob_function (const std::string& fname, octave_user_function *fcn) | 2651 octave_parser::frob_function (const std::string& fname, |
2652 octave_user_function *fcn) | |
2829 { | 2653 { |
2830 std::string id_name = fname; | 2654 std::string id_name = fname; |
2831 | 2655 |
2832 // If input is coming from a file, issue a warning if the name of | 2656 // If input is coming from a file, issue a warning if the name of |
2833 // the file does not match the name of the function stated in the | 2657 // the file does not match the name of the function stated in the |
2922 primary_fcn_ptr = fcn; | 2746 primary_fcn_ptr = fcn; |
2923 | 2747 |
2924 return fcn; | 2748 return fcn; |
2925 } | 2749 } |
2926 | 2750 |
2927 static tree_function_def * | 2751 tree_function_def * |
2928 finish_function (tree_parameter_list *ret_list, | 2752 octave_parser::finish_function (tree_parameter_list *ret_list, |
2929 octave_user_function *fcn, octave_comment_list *lc) | 2753 octave_user_function *fcn, |
2754 octave_comment_list *lc) | |
2930 { | 2755 { |
2931 tree_function_def *retval = 0; | 2756 tree_function_def *retval = 0; |
2932 | 2757 |
2933 if (ret_list) | 2758 if (ret_list) |
2934 ret_list->mark_as_formal_parameters (); | 2759 ret_list->mark_as_formal_parameters (); |
2992 } | 2817 } |
2993 | 2818 |
2994 return retval; | 2819 return retval; |
2995 } | 2820 } |
2996 | 2821 |
2997 static void | 2822 void |
2998 recover_from_parsing_function (void) | 2823 octave_parser::recover_from_parsing_function (void) |
2999 { | 2824 { |
3000 if (parser_symtab_context.empty ()) | 2825 if (parser_symtab_context.empty ()) |
3001 panic_impossible (); | 2826 panic_impossible (); |
3002 | 2827 |
3003 parser_symtab_context.pop (); | 2828 parser_symtab_context.pop (); |
3015 curr_lexer->looking_at_parameter_list = false; | 2840 curr_lexer->looking_at_parameter_list = false; |
3016 } | 2841 } |
3017 | 2842 |
3018 // Make an index expression. | 2843 // Make an index expression. |
3019 | 2844 |
3020 static tree_index_expression * | 2845 tree_index_expression * |
3021 make_index_expression (tree_expression *expr, tree_argument_list *args, | 2846 octave_parser::make_index_expression (tree_expression *expr, |
3022 char type) | 2847 tree_argument_list *args, char type) |
3023 { | 2848 { |
3024 tree_index_expression *retval = 0; | 2849 tree_index_expression *retval = 0; |
3025 | 2850 |
3026 if (args && args->has_magic_tilde ()) | 2851 if (args && args->has_magic_tilde ()) |
3027 { | 2852 { |
3048 return retval; | 2873 return retval; |
3049 } | 2874 } |
3050 | 2875 |
3051 // Make an indirect reference expression. | 2876 // Make an indirect reference expression. |
3052 | 2877 |
3053 static tree_index_expression * | 2878 tree_index_expression * |
3054 make_indirect_ref (tree_expression *expr, const std::string& elt) | 2879 octave_parser::make_indirect_ref (tree_expression *expr, |
2880 const std::string& elt) | |
3055 { | 2881 { |
3056 tree_index_expression *retval = 0; | 2882 tree_index_expression *retval = 0; |
3057 | 2883 |
3058 int l = expr->line (); | 2884 int l = expr->line (); |
3059 int c = expr->column (); | 2885 int c = expr->column (); |
3074 return retval; | 2900 return retval; |
3075 } | 2901 } |
3076 | 2902 |
3077 // Make an indirect reference expression with dynamic field name. | 2903 // Make an indirect reference expression with dynamic field name. |
3078 | 2904 |
3079 static tree_index_expression * | 2905 tree_index_expression * |
3080 make_indirect_ref (tree_expression *expr, tree_expression *elt) | 2906 octave_parser::make_indirect_ref (tree_expression *expr, tree_expression *elt) |
3081 { | 2907 { |
3082 tree_index_expression *retval = 0; | 2908 tree_index_expression *retval = 0; |
3083 | 2909 |
3084 int l = expr->line (); | 2910 int l = expr->line (); |
3085 int c = expr->column (); | 2911 int c = expr->column (); |
3100 return retval; | 2926 return retval; |
3101 } | 2927 } |
3102 | 2928 |
3103 // Make a declaration command. | 2929 // Make a declaration command. |
3104 | 2930 |
3105 static tree_decl_command * | 2931 tree_decl_command * |
3106 make_decl_command (int tok, token *tok_val, tree_decl_init_list *lst) | 2932 octave_parser::make_decl_command (int tok, token *tok_val, |
2933 tree_decl_init_list *lst) | |
3107 { | 2934 { |
3108 tree_decl_command *retval = 0; | 2935 tree_decl_command *retval = 0; |
3109 | 2936 |
3110 int l = tok_val->line (); | 2937 int l = tok_val->line (); |
3111 int c = tok_val->column (); | 2938 int c = tok_val->column (); |
3135 } | 2962 } |
3136 | 2963 |
3137 return retval; | 2964 return retval; |
3138 } | 2965 } |
3139 | 2966 |
3140 static tree_argument_list * | 2967 tree_argument_list * |
3141 validate_matrix_row (tree_argument_list *row) | 2968 octave_parser::validate_matrix_row (tree_argument_list *row) |
3142 { | 2969 { |
3143 if (row && row->has_magic_tilde ()) | 2970 if (row && row->has_magic_tilde ()) |
3144 yyerror ("invalid use of tilde (~) in matrix expression"); | 2971 yyerror ("invalid use of tilde (~) in matrix expression"); |
3145 return row; | 2972 return row; |
3146 } | 2973 } |
3147 | 2974 |
3148 // Finish building a matrix list. | 2975 // Finish building a matrix list. |
3149 | 2976 |
3150 static tree_expression * | 2977 tree_expression * |
3151 finish_matrix (tree_matrix *m) | 2978 octave_parser::finish_matrix (tree_matrix *m) |
3152 { | 2979 { |
3153 tree_expression *retval = m; | 2980 tree_expression *retval = m; |
3154 | 2981 |
3155 unwind_protect frame; | 2982 unwind_protect frame; |
3156 | 2983 |
3189 return retval; | 3016 return retval; |
3190 } | 3017 } |
3191 | 3018 |
3192 // Finish building a cell list. | 3019 // Finish building a cell list. |
3193 | 3020 |
3194 static tree_expression * | 3021 tree_expression * |
3195 finish_cell (tree_cell *c) | 3022 octave_parser::finish_cell (tree_cell *c) |
3196 { | 3023 { |
3197 return finish_matrix (c); | 3024 return finish_matrix (c); |
3198 } | 3025 } |
3199 | 3026 |
3200 static void | 3027 void |
3201 maybe_warn_missing_semi (tree_statement_list *t) | 3028 octave_parser::maybe_warn_missing_semi (tree_statement_list *t) |
3202 { | 3029 { |
3203 if (current_function_depth > 0) | 3030 if (current_function_depth > 0) |
3204 { | 3031 { |
3205 tree_statement *tmp = t->back (); | 3032 tree_statement *tmp = t->back (); |
3206 | 3033 |
3210 "missing semicolon near line %d, column %d in file '%s'", | 3037 "missing semicolon near line %d, column %d in file '%s'", |
3211 tmp->line (), tmp->column (), curr_fcn_file_full_name.c_str ()); | 3038 tmp->line (), tmp->column (), curr_fcn_file_full_name.c_str ()); |
3212 } | 3039 } |
3213 } | 3040 } |
3214 | 3041 |
3215 static tree_statement_list * | 3042 tree_statement_list * |
3216 set_stmt_print_flag (tree_statement_list *list, char sep, | 3043 octave_parser::set_stmt_print_flag (tree_statement_list *list, char sep, |
3217 bool warn_missing_semi) | 3044 bool warn_missing_semi) |
3218 { | 3045 { |
3219 tree_statement *tmp = list->back (); | 3046 tree_statement *tmp = list->back (); |
3220 | 3047 |
3221 switch (sep) | 3048 switch (sep) |
3222 { | 3049 { |
3247 } | 3074 } |
3248 | 3075 |
3249 return list; | 3076 return list; |
3250 } | 3077 } |
3251 | 3078 |
3252 static tree_statement_list * | 3079 tree_statement_list * |
3253 make_statement_list (tree_statement *stmt) | 3080 octave_parser::make_statement_list (tree_statement *stmt) |
3254 { | 3081 { |
3255 return new tree_statement_list (stmt); | 3082 return new tree_statement_list (stmt); |
3256 } | 3083 } |
3257 | 3084 |
3258 static tree_statement_list * | 3085 tree_statement_list * |
3259 append_statement_list (tree_statement_list *list, char sep, | 3086 octave_parser::append_statement_list (tree_statement_list *list, char sep, |
3260 tree_statement *stmt, bool warn_missing_semi) | 3087 tree_statement *stmt, |
3088 bool warn_missing_semi) | |
3261 { | 3089 { |
3262 set_stmt_print_flag (list, sep, warn_missing_semi); | 3090 set_stmt_print_flag (list, sep, warn_missing_semi); |
3263 | 3091 |
3264 list->append (stmt); | 3092 list->append (stmt); |
3265 | 3093 |
3610 file_type.c_str (), ff.c_str ()); | 3438 file_type.c_str (), ff.c_str ()); |
3611 } | 3439 } |
3612 else | 3440 else |
3613 { | 3441 { |
3614 tree_statement *end_of_script | 3442 tree_statement *end_of_script |
3615 = make_end ("endscript", curr_lexer->input_line_number, | 3443 = curr_parser->make_end ("endscript", curr_lexer->input_line_number, |
3616 curr_lexer->current_input_column); | 3444 curr_lexer->current_input_column); |
3617 | 3445 |
3618 make_script (0, end_of_script); | 3446 curr_parser->make_script (0, end_of_script); |
3619 | 3447 |
3620 fcn_ptr = primary_fcn_ptr; | 3448 fcn_ptr = primary_fcn_ptr; |
3621 } | 3449 } |
3622 } | 3450 } |
3623 else if (require_file) | 3451 else if (require_file) |