From 47919799b411f0c1e47591887a233d3692bf19b6 Mon Sep 17 00:00:00 2001 From: Rob Pike Date: Tue, 16 Sep 2008 19:14:33 -0700 Subject: [PATCH] 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 --- src/cmd/gc/go.y | 83 +++++++++++++++++++++++++++++++++--------------- src/cmd/gc/lex.c | 6 +--- 2 files changed, 58 insertions(+), 31 deletions(-) diff --git a/src/cmd/gc/go.y b/src/cmd/gc/go.y index 9d05bf43dd..8204b6d21d 100644 --- a/src/cmd/gc/go.y +++ b/src/cmd/gc/go.y @@ -25,11 +25,10 @@ %token LNIL LTRUE LFALSE LIOTA %token LOROR LANDAND LEQ LNE LLE LLT LGE LGT -%token LLSH LRSH LINC LDEC LSEND LRECV +%token LLSH LRSH LINC LDEC LCOMM %token LIGNORE %type sym sym1 sym2 keyword laconst lname latype non_type_sym -%type chandir %type xdcl xdcl_list_r oxdcl_list %type common_dcl Acommon_dcl Bcommon_dcl %type oarg_type_list arg_type_list_r arg_type @@ -55,10 +54,11 @@ %type fntype fnlitdcl Afntype Bfntype fullAtype %type type Atype Btype indcl new_type fullBtype %type structtype interfacetype convtype +%type Achantype Bchantype %left LOROR %left LANDAND -%left LSEND LRECV +%left LCOMM %left LEQ LNE LLE LGE LLT LGT %left '+' '-' '|' '^' %left '*' '/' '%' '&' LLSH LRSH @@ -412,6 +412,24 @@ complex_stmt: poptodcl(); $$ = 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 ':' { poptodcl(); @@ -644,14 +662,10 @@ expr: { $$ = nod(ORSH, $1, $3); } -| expr LSEND expr +| expr LCOMM expr { $$ = nod(OSEND, $1, $3); } -| expr LRECV expr - { - $$ = nod(ORECV, $1, $3); - } uexpr: pexpr @@ -684,7 +698,7 @@ uexpr: { $$ = nod(OCOM, $2, N); } -| LRECV uexpr +| LCOMM uexpr { $$ = nod(ORECV, $2, N); } @@ -931,11 +945,17 @@ Atype: { $$ = aindex($2, $4); } -| LCHAN chandir fullAtype +| LCOMM LCHAN fullAtype + { + $$ = typ(TCHAN); + $$->type = $3; + $$->chan = Crecv; + } +| LCHAN LCOMM Atype // not full Atype { $$ = typ(TCHAN); $$->type = $3; - $$->chan = $2; + $$->chan = Csend; } | LMAP '[' type ']' fullAtype { @@ -951,20 +971,35 @@ Atype: $$ = ptrto($2); } +Achantype: + LCHAN fullAtype + { + $$ = typ(TCHAN); + $$->type = $2; + $$->chan = Cboth; + } + fullAtype: Atype | Afntype +| Achantype Btype: '[' oexpr ']' fullBtype { $$ = aindex($2, $4); } -| LCHAN chandir fullBtype +| LCOMM LCHAN fullBtype + { + $$ = typ(TCHAN); + $$->type = $3; + $$->chan = Crecv; + } +| LCHAN LCOMM Btype // not full Btype { $$ = typ(TCHAN); $$->type = $3; - $$->chan = $2; + $$->chan = Csend; } | LMAP '[' type ']' fullBtype { @@ -985,9 +1020,18 @@ Btype: $$ = forwdcl($2); } +Bchantype: + LCHAN fullBtype + { + $$ = typ(TCHAN); + $$->type = $2; + $$->chan = Cboth; + } + fullBtype: Btype | Bfntype +| Bchantype structtype: LSTRUCT '{' structdcl_list_r osemi '}' @@ -1010,19 +1054,6 @@ interfacetype: $$ = dostruct(N, TINTER); } -chandir: - { - $$ = Cboth; - } -| LRECV - { - $$ = Crecv; - } -| LSEND - { - $$ = Csend; - } - keyval: expr ':' expr { diff --git a/src/cmd/gc/lex.c b/src/cmd/gc/lex.c index b03762332d..dce5c1453a 100644 --- a/src/cmd/gc/lex.c +++ b/src/cmd/gc/lex.c @@ -485,10 +485,6 @@ l0: c = LDEC; goto lx; } - if(c1 == '<') { - c = LSEND; - goto lx; - } if(c1 == '=') { c = OSUB; goto asop; @@ -529,7 +525,7 @@ l0: goto lx; } if(c1 == '-') { - c = LRECV; + c = LCOMM; goto lx; } c = LLT; -- 2.48.1