From: Russ Cox Date: Wed, 28 Jan 2009 23:41:50 +0000 (-0800) Subject: clean up range grammar X-Git-Tag: weekly.2009-11-06~2271 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=3ec4675220f18c3bc6680e71c6ce09a76b641c8c;p=gostls13.git clean up range grammar R=ken OCL=23712 CL=23714 --- diff --git a/src/cmd/gc/go.y b/src/cmd/gc/go.y index 4aafd0b0c1..d04991dc47 100644 --- a/src/cmd/gc/go.y +++ b/src/cmd/gc/go.y @@ -52,7 +52,7 @@ %type Astmt Bstmt %type for_stmt for_body for_header %type if_stmt if_body if_header select_stmt -%type simple_stmt osimple_stmt orange_stmt semi_stmt +%type simple_stmt osimple_stmt range_stmt semi_stmt %type expr uexpr pexpr expr_list oexpr oexpr_list expr_list_r %type exprsym3_list_r exprsym3 %type name onew_name new_name new_name_list_r new_field @@ -536,9 +536,8 @@ compound_stmt: popdcl(); } -orange_stmt: - osimple_stmt -| exprsym3_list_r '=' LRANGE expr +range_stmt: + exprsym3_list_r '=' LRANGE expr { $$ = nod(ORANGE, $1, $4); $$->etype = 0; // := flag @@ -550,14 +549,8 @@ orange_stmt: } for_header: - osimple_stmt ';' orange_stmt ';' osimple_stmt + osimple_stmt ';' osimple_stmt ';' osimple_stmt { - if($3 != N && $3->op == ORANGE) { - $$ = dorange($3); - $$->ninit = list($$->ninit, $1); - $$->nincr = list($$->nincr, $5); - break; - } // init ; test ; incr if($5 != N && $5->colas != 0) yyerror("cannot declare in the for-increment"); @@ -566,19 +559,19 @@ for_header: $$->ntest = $3; $$->nincr = $5; } -| orange_stmt +| osimple_stmt { - // range - if($1 != N && $1->op == ORANGE) { - $$ = dorange($1); - break; - } // normal test $$ = nod(OFOR, N, N); $$->ninit = N; $$->ntest = $1; $$->nincr = N; } +| range_stmt + { + $$ = dorange($1); + addtotop($$); + } for_body: for_header compound_stmt