]> Cypherpunks repositories - gostls13.git/commitdiff
new grammar:
authorRob Pike <r@golang.org>
Wed, 17 Sep 2008 02:14:33 +0000 (19:14 -0700)
committerRob Pike <r@golang.org>
Wed, 17 Sep 2008 02:14:33 +0000 (19:14 -0700)
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
src/cmd/gc/lex.c

index 9d05bf43dd0ea4a48e3ee6c4b399e1a3afcb9fd4..8204b6d21d5d5fb45c6074cb752788747f138b2d 100644 (file)
 %token <sym>           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>           sym sym1 sym2 keyword laconst lname latype non_type_sym
-%type  <lint>          chandir
 %type  <node>          xdcl xdcl_list_r oxdcl_list
 %type  <node>          common_dcl Acommon_dcl Bcommon_dcl
 %type  <node>          oarg_type_list arg_type_list_r arg_type
 %type  <type>          fntype fnlitdcl Afntype Bfntype fullAtype
 %type  <type>          type Atype Btype indcl new_type fullBtype
 %type  <type>          structtype interfacetype convtype
+%type  <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
        {
index b03762332d91538bcc200533fc128cfff549edd8..dce5c1453a9f4bcde56555c5642a0c660b1f0c47 100644 (file)
@@ -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;