From: Nobuyoshi Nakada Date: 2007-04-12T12:30:10+09:00 Subject: Re: memory exhausted Hi, At Thu, 12 Apr 2007 04:19:02 +0900, Nobuyoshi Nakada wrote in [ruby-talk:247527]: > A patch to inverse the order of shift/reduce. And for if/elsif/else. Index: parse.y =================================================================== --- parse.y (revision 12169) +++ parse.y (working copy) @@ -273,5 +273,5 @@ static void top_local_setup(); %type bodystmt compstmt stmts stmt expr arg primary command command_call method_call %type expr_value arg_value primary_value -%type if_tail opt_else case_body cases opt_rescue exc_list exc_var opt_ensure +%type if_then opt_else case_body cases opt_rescue exc_list exc_var opt_ensure %type args when_args call_args call_args2 open_args paren_args opt_paren_args %type command_args aref_args opt_block_arg block_arg var_ref var_lhs @@ -1553,11 +1553,9 @@ primary : literal fixpos($$, $1); } - | kIF expr_value then - compstmt - if_tail - kEND + | if_then opt_else kEND { - $$ = NEW_IF(cond($2), $4, $5); - fixpos($$, $2); + $1->nd_else->nd_else = $2; + $$ = $1->nd_body; + rb_gc_force_recycle((VALUE)$1); if (cond_negative(&$$->nd_cond)) { NODE *tmp = $$->nd_body; @@ -1744,18 +1742,26 @@ do : term ; -if_tail : opt_else - | kELSIF expr_value then - compstmt - if_tail +opt_else : none + | kELSE compstmt { - $$ = NEW_IF(cond($2), $4, $5); - fixpos($$, $2); + $$ = $2; } ; -opt_else : none - | kELSE compstmt +if_then : kIF expr_value then + compstmt { - $$ = $2; + $$ = NEW_IF(cond($2), $4, 0); + fixpos($$, $2); + $$ = NEW_IF(0, $$, $$); + } + | if_then kELSIF expr_value then + compstmt + { + NODE *elsif = NEW_IF(cond($3), $5, 0); + fixpos(elsif, $3); + $$ = $1; + $$->nd_else->nd_else = elsif; + $$->nd_else = elsif; } ; -- Nobu Nakada