comparison src/parse.y @ 1229:7d7c3eaa1d3b

[project @ 1995-04-10 01:04:13 by jwe]
author jwe
date Mon, 10 Apr 1995 01:04:46 +0000
parents c210c5a25a48
children e1ddfb12566d
comparison
equal deleted inserted replaced
1228:38b876e46ff6 1229:7d7c3eaa1d3b
26 26
27 %{ 27 %{
28 #define YYDEBUG 1 28 #define YYDEBUG 1
29 29
30 #ifdef HAVE_CONFIG_H 30 #ifdef HAVE_CONFIG_H
31 #include "config.h" 31 #include <config.h>
32 #endif 32 #endif
33 33
34 #include <strstream.h> 34 #include <strstream.h>
35 35
36 #include "SLStack.h" 36 #include "SLStack.h"
149 static tree_expression *make_unary_op 149 static tree_expression *make_unary_op
150 (int op, tree_expression *op1, token *tok_val); 150 (int op, tree_expression *op1, token *tok_val);
151 151
152 // Make an expression that handles assignment of multiple values. 152 // Make an expression that handles assignment of multiple values.
153 static tree_expression *make_multi_val_ret 153 static tree_expression *make_multi_val_ret
154 (tree_expression *rhs, int l = -1, int c = -1); 154 (tree_matrix *m, tree_expression *rhs, int l = -1, int c = -1);
155 155
156 // Make an index expression. 156 // Make an index expression.
157 static tree_index_expression *make_index_expression 157 static tree_index_expression *make_index_expression
158 (tree_indirect_ref *indir, tree_argument_list *args); 158 (tree_indirect_ref *indir, tree_argument_list *args);
159 159
626 ABORT_PARSE; 626 ABORT_PARSE;
627 looping--; 627 looping--;
628 $$ = new tree_for_command ($2, $4, $6, 628 $$ = new tree_for_command ($2, $4, $6,
629 $1->line (), $1->column ()); 629 $1->line (), $1->column ());
630 } 630 }
631 | FOR '[' screwed_again matrix_row SCREW_TWO '='
632 expression optsep opt_list END
633 {
634 if (check_end ($10, token::for_end))
635 ABORT_PARSE;
636 looping--;
637 tree_matrix *tmp = ml.pop ();
638 tmp = tmp->reverse ();
639 tree_return_list *id_list = tmp->to_return_list ();
640 $$ = new tree_for_command (id_list, $7, $9,
641 $1->line (), $1->column ());
642 }
631 | BREAK 643 | BREAK
632 { 644 {
633 if (! (looping || defining_func)) 645 if (! (looping || defining_func))
634 { 646 {
635 yyerror ("break: only meaningful within a loop\ 647 yyerror ("break: only meaningful within a loop\
720 $$ = 0; 732 $$ = 0;
721 ABORT_PARSE; 733 ABORT_PARSE;
722 } 734 }
723 | '[' screwed_again matrix_row SCREW_TWO '=' expression 735 | '[' screwed_again matrix_row SCREW_TWO '=' expression
724 { 736 {
725 $$ = make_multi_val_ret ($6, $5->line (), $5->column ()); 737 tree_matrix *tmp = ml.pop ();
726 738 tmp = tmp->reverse ();
739 $$ = make_multi_val_ret (tmp, $6, $5->line (),
740 $5->column ());
727 if (! $$) 741 if (! $$)
728 ABORT_PARSE; 742 ABORT_PARSE;
729 } 743 }
730 | simple_expr 744 | simple_expr
731 { $$ = $1; } 745 { $$ = $1; }
1550 } 1564 }
1551 1565
1552 // Make an expression that handles assignment of multiple values. 1566 // Make an expression that handles assignment of multiple values.
1553 1567
1554 static tree_expression * 1568 static tree_expression *
1555 make_multi_val_ret (tree_expression *rhs, int l, int c) 1569 make_multi_val_ret (tree_matrix *m, tree_expression *rhs, int l, int c)
1556 { 1570 {
1557 // Convert the matrix list to a list of identifiers. If that fails, 1571 // Convert the matrix list to a list of identifiers. If that fails,
1558 // we can abort here, without losing anything -- no other possible 1572 // we can abort here, without losing anything -- no other possible
1559 // syntax is valid if we've seen the equals sign as the next token 1573 // syntax is valid if we've seen the equals sign as the next token
1560 // after the `]'. 1574 // after the `]'.
1561 1575
1562 tree_expression *retval = 0; 1576 tree_expression *retval = 0;
1563 1577
1564 maybe_screwed_again--; 1578 maybe_screwed_again--;
1565 1579
1566 tree_matrix *tmp = ml.pop (); 1580 tree_return_list *id_list = m->to_return_list ();
1567
1568 tmp = tmp->reverse ();
1569
1570 tree_return_list *id_list = tmp->to_return_list ();
1571 1581
1572 if (id_list) 1582 if (id_list)
1573 { 1583 {
1574 int list_len = id_list->length (); 1584 int list_len = id_list->length ();
1575 1585
1583 else if (list_len > 1) 1593 else if (list_len > 1)
1584 { 1594 {
1585 if (rhs->is_multi_val_ret_expression ()) 1595 if (rhs->is_multi_val_ret_expression ())
1586 { 1596 {
1587 tree_multi_val_ret *t = (tree_multi_val_ret *) rhs; 1597 tree_multi_val_ret *t = (tree_multi_val_ret *) rhs;
1588 retval = new tree_multi_assignment_expression (id_list, t, l, c); 1598 retval = new tree_multi_assignment_expression (id_list, t,
1599 0, l, c);
1589 } 1600 }
1590 else 1601 else
1591 yyerror ("RHS must be an expression that returns multiple values"); 1602 yyerror ("RHS must be an expression that returns multiple values");
1592 } 1603 }
1593 else 1604 else