Commit 47919799 authored by Rob Pike's avatar Rob Pike

new grammar:

	binary <- is send
	unary <- is recv
	-< is gone
	case a := <-ch: works in select
	case a = <-ch: works in select
support for new cases is not yet in the compiler but all non-select
code works

second CL will update affected go source

R=ken
OCL=15414
CL=15414
parent 4dfc7f0f
...@@ -25,11 +25,10 @@ ...@@ -25,11 +25,10 @@
%token <sym> LNIL LTRUE LFALSE LIOTA %token <sym> LNIL LTRUE LFALSE LIOTA
%token LOROR LANDAND LEQ LNE LLE LLT LGE LGT %token LOROR LANDAND LEQ LNE LLE LLT LGE LGT
%token LLSH LRSH LINC LDEC LSEND LRECV %token LLSH LRSH LINC LDEC LCOMM
%token LIGNORE %token LIGNORE
%type <sym> sym sym1 sym2 keyword laconst lname latype non_type_sym %type <sym> sym sym1 sym2 keyword laconst lname latype non_type_sym
%type <lint> chandir
%type <node> xdcl xdcl_list_r oxdcl_list %type <node> xdcl xdcl_list_r oxdcl_list
%type <node> common_dcl Acommon_dcl Bcommon_dcl %type <node> common_dcl Acommon_dcl Bcommon_dcl
%type <node> oarg_type_list arg_type_list_r arg_type %type <node> oarg_type_list arg_type_list_r arg_type
...@@ -55,10 +54,11 @@ ...@@ -55,10 +54,11 @@
%type <type> fntype fnlitdcl Afntype Bfntype fullAtype %type <type> fntype fnlitdcl Afntype Bfntype fullAtype
%type <type> type Atype Btype indcl new_type fullBtype %type <type> type Atype Btype indcl new_type fullBtype
%type <type> structtype interfacetype convtype %type <type> structtype interfacetype convtype
%type <type> Achantype Bchantype
%left LOROR %left LOROR
%left LANDAND %left LANDAND
%left LSEND LRECV %left LCOMM
%left LEQ LNE LLE LGE LLT LGT %left LEQ LNE LLE LGE LLT LGT
%left '+' '-' '|' '^' %left '+' '-' '|' '^'
%left '*' '/' '%' '&' LLSH LRSH %left '*' '/' '%' '&' LLSH LRSH
...@@ -412,6 +412,24 @@ complex_stmt: ...@@ -412,6 +412,24 @@ complex_stmt:
poptodcl(); poptodcl();
$$ = nod(OXCASE, $2, N); $$ = nod(OXCASE, $2, N);
} }
| LCASE name '=' expr ':'
{
// will be converted to OCASE
// right will point to next case
// done in casebody()
poptodcl();
$$ = nod(OAS, $2, $4);
$$ = nod(OXCASE, $$, N);
}
| LCASE name LCOLAS expr ':'
{
// will be converted to OCASE
// right will point to next case
// done in casebody()
poptodcl();
$$ = nod(OAS, colas($2, $4), $4);
$$ = nod(OXCASE, $$, N);
}
| LDEFAULT ':' | LDEFAULT ':'
{ {
poptodcl(); poptodcl();
...@@ -644,14 +662,10 @@ expr: ...@@ -644,14 +662,10 @@ expr:
{ {
$$ = nod(ORSH, $1, $3); $$ = nod(ORSH, $1, $3);
} }
| expr LSEND expr | expr LCOMM expr
{ {
$$ = nod(OSEND, $1, $3); $$ = nod(OSEND, $1, $3);
} }
| expr LRECV expr
{
$$ = nod(ORECV, $1, $3);
}
uexpr: uexpr:
pexpr pexpr
...@@ -684,7 +698,7 @@ uexpr: ...@@ -684,7 +698,7 @@ uexpr:
{ {
$$ = nod(OCOM, $2, N); $$ = nod(OCOM, $2, N);
} }
| LRECV uexpr | LCOMM uexpr
{ {
$$ = nod(ORECV, $2, N); $$ = nod(ORECV, $2, N);
} }
...@@ -931,11 +945,17 @@ Atype: ...@@ -931,11 +945,17 @@ Atype:
{ {
$$ = aindex($2, $4); $$ = aindex($2, $4);
} }
| LCHAN chandir fullAtype | LCOMM LCHAN fullAtype
{
$$ = typ(TCHAN);
$$->type = $3;
$$->chan = Crecv;
}
| LCHAN LCOMM Atype // not full Atype
{ {
$$ = typ(TCHAN); $$ = typ(TCHAN);
$$->type = $3; $$->type = $3;
$$->chan = $2; $$->chan = Csend;
} }
| LMAP '[' type ']' fullAtype | LMAP '[' type ']' fullAtype
{ {
...@@ -951,20 +971,35 @@ Atype: ...@@ -951,20 +971,35 @@ Atype:
$$ = ptrto($2); $$ = ptrto($2);
} }
Achantype:
LCHAN fullAtype
{
$$ = typ(TCHAN);
$$->type = $2;
$$->chan = Cboth;
}
fullAtype: fullAtype:
Atype Atype
| Afntype | Afntype
| Achantype
Btype: Btype:
'[' oexpr ']' fullBtype '[' oexpr ']' fullBtype
{ {
$$ = aindex($2, $4); $$ = aindex($2, $4);
} }
| LCHAN chandir fullBtype | LCOMM LCHAN fullBtype
{
$$ = typ(TCHAN);
$$->type = $3;
$$->chan = Crecv;
}
| LCHAN LCOMM Btype // not full Btype
{ {
$$ = typ(TCHAN); $$ = typ(TCHAN);
$$->type = $3; $$->type = $3;
$$->chan = $2; $$->chan = Csend;
} }
| LMAP '[' type ']' fullBtype | LMAP '[' type ']' fullBtype
{ {
...@@ -985,9 +1020,18 @@ Btype: ...@@ -985,9 +1020,18 @@ Btype:
$$ = forwdcl($2); $$ = forwdcl($2);
} }
Bchantype:
LCHAN fullBtype
{
$$ = typ(TCHAN);
$$->type = $2;
$$->chan = Cboth;
}
fullBtype: fullBtype:
Btype Btype
| Bfntype | Bfntype
| Bchantype
structtype: structtype:
LSTRUCT '{' structdcl_list_r osemi '}' LSTRUCT '{' structdcl_list_r osemi '}'
...@@ -1010,19 +1054,6 @@ interfacetype: ...@@ -1010,19 +1054,6 @@ interfacetype:
$$ = dostruct(N, TINTER); $$ = dostruct(N, TINTER);
} }
chandir:
{
$$ = Cboth;
}
| LRECV
{
$$ = Crecv;
}
| LSEND
{
$$ = Csend;
}
keyval: keyval:
expr ':' expr expr ':' expr
{ {
......
...@@ -485,10 +485,6 @@ l0: ...@@ -485,10 +485,6 @@ l0:
c = LDEC; c = LDEC;
goto lx; goto lx;
} }
if(c1 == '<') {
c = LSEND;
goto lx;
}
if(c1 == '=') { if(c1 == '=') {
c = OSUB; c = OSUB;
goto asop; goto asop;
...@@ -529,7 +525,7 @@ l0: ...@@ -529,7 +525,7 @@ l0:
goto lx; goto lx;
} }
if(c1 == '-') { if(c1 == '-') {
c = LRECV; c = LCOMM;
goto lx; goto lx;
} }
c = LLT; c = LLT;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment