mirror of
https://github.com/golang/go
synced 2024-11-21 20:04:44 -07:00
gc: clean up if grammar
Fixes #2248. R=ken2 CC=golang-dev https://golang.org/cl/4978064
This commit is contained in:
parent
48e9c771a1
commit
9fc687392c
@ -67,4 +67,7 @@ static struct {
|
|||||||
|
|
||||||
% loadsys package imports LFUNC LNAME '(' ')' '{' LFUNC LNAME
|
% loadsys package imports LFUNC LNAME '(' ')' '{' LFUNC LNAME
|
||||||
"nested func not allowed",
|
"nested func not allowed",
|
||||||
|
|
||||||
|
% loadsys package imports LFUNC LNAME '(' ')' '{' LIF if_header loop_body LELSE ';'
|
||||||
|
"else must be followed by if or statement block"
|
||||||
};
|
};
|
||||||
|
@ -57,7 +57,7 @@ static void fixlbrace(int);
|
|||||||
%type <node> compound_stmt dotname embed expr complitexpr
|
%type <node> compound_stmt dotname embed expr complitexpr
|
||||||
%type <node> expr_or_type
|
%type <node> expr_or_type
|
||||||
%type <node> fndcl fnliteral
|
%type <node> fndcl fnliteral
|
||||||
%type <node> for_body for_header for_stmt if_header if_stmt non_dcl_stmt
|
%type <node> for_body for_header for_stmt if_header if_stmt else non_dcl_stmt
|
||||||
%type <node> interfacedcl keyval labelname name
|
%type <node> interfacedcl keyval labelname name
|
||||||
%type <node> name_or_type non_expr_type
|
%type <node> name_or_type non_expr_type
|
||||||
%type <node> new_name dcl_name oexpr typedclname
|
%type <node> new_name dcl_name oexpr typedclname
|
||||||
@ -640,6 +640,7 @@ if_header:
|
|||||||
$$->ntest = $3;
|
$$->ntest = $3;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* IF cond body (ELSE IF cond body)* (ELSE block)? */
|
||||||
if_stmt:
|
if_stmt:
|
||||||
LIF
|
LIF
|
||||||
{
|
{
|
||||||
@ -652,9 +653,27 @@ if_stmt:
|
|||||||
}
|
}
|
||||||
loop_body
|
loop_body
|
||||||
{
|
{
|
||||||
|
$3->nbody = $5;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
popdcl();
|
||||||
$$ = $3;
|
$$ = $3;
|
||||||
$$->nbody = $5;
|
if($7 != N)
|
||||||
// no popdcl; maybe there's an LELSE
|
$$->nelse = list1($7);
|
||||||
|
}
|
||||||
|
|
||||||
|
else:
|
||||||
|
{
|
||||||
|
$$ = N;
|
||||||
|
}
|
||||||
|
| LELSE if_stmt
|
||||||
|
{
|
||||||
|
$$ = $2;
|
||||||
|
}
|
||||||
|
| LELSE compound_stmt
|
||||||
|
{
|
||||||
|
$$ = $2;
|
||||||
}
|
}
|
||||||
|
|
||||||
switch_stmt:
|
switch_stmt:
|
||||||
@ -1474,19 +1493,6 @@ non_dcl_stmt:
|
|||||||
| switch_stmt
|
| switch_stmt
|
||||||
| select_stmt
|
| select_stmt
|
||||||
| if_stmt
|
| if_stmt
|
||||||
{
|
|
||||||
popdcl();
|
|
||||||
$$ = $1;
|
|
||||||
}
|
|
||||||
| if_stmt LELSE stmt
|
|
||||||
{
|
|
||||||
if($3->op != OIF && $3->op != OBLOCK)
|
|
||||||
yyerror("missing { } after else");
|
|
||||||
|
|
||||||
popdcl();
|
|
||||||
$$ = $1;
|
|
||||||
$$->nelse = list1($3);
|
|
||||||
}
|
|
||||||
| labelname ':'
|
| labelname ':'
|
||||||
{
|
{
|
||||||
$1 = nod(OLABEL, $1, N);
|
$1 = nod(OLABEL, $1, N);
|
||||||
|
12
test/syntax/else.go
Normal file
12
test/syntax/else.go
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
// errchk $G $D/$F.go
|
||||||
|
|
||||||
|
// Copyright 2011 The Go Authors. All rights reserved.
|
||||||
|
// Use of this source code is governed by a BSD-style
|
||||||
|
// license that can be found in the LICENSE file.
|
||||||
|
|
||||||
|
package main
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
if true {
|
||||||
|
} else ; // ERROR "else must be followed by if or statement block"
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user