Commit ae5a475e authored by Ken Thompson's avatar Ken Thompson

range clause must have = or :=

:= illegal in for-increment

R=r
OCL=21204
CL=21204
parent 7df571ae
...@@ -197,6 +197,7 @@ struct Node ...@@ -197,6 +197,7 @@ struct Node
uchar method; // OCALLMETH name uchar method; // OCALLMETH name
uchar iota; // OLITERAL made from iota uchar iota; // OLITERAL made from iota
uchar embedded; // ODCLFIELD embedded type uchar embedded; // ODCLFIELD embedded type
uchar colas; // OAS resulting from :=
// most nodes // most nodes
Node* left; Node* left;
......
...@@ -419,6 +419,7 @@ simple_stmt: ...@@ -419,6 +419,7 @@ simple_stmt:
$$ = rev($1); $$ = rev($1);
$$ = colas($$, $3); $$ = colas($$, $3);
$$ = nod(OAS, $$, $3); $$ = nod(OAS, $$, $3);
$$->colas = 1;
addtotop($$); addtotop($$);
} }
| LPRINT '(' oexpr_list ')' | LPRINT '(' oexpr_list ')'
...@@ -554,9 +555,6 @@ compound_stmt: ...@@ -554,9 +555,6 @@ compound_stmt:
popdcl(); popdcl();
} }
ocolas:
| LCOLAS
orange_stmt: orange_stmt:
osimple_stmt osimple_stmt
| exprsym3_list_r '=' LRANGE expr | exprsym3_list_r '=' LRANGE expr
...@@ -570,12 +568,12 @@ orange_stmt: ...@@ -570,12 +568,12 @@ orange_stmt:
$$ = nod(ORANGE, $$, $6); $$ = nod(ORANGE, $$, $6);
$$->etype = 0; $$->etype = 0;
} }
| exprsym3_list_r ocolas LRANGE expr | exprsym3_list_r LCOLAS LRANGE expr
{ {
$$ = nod(ORANGE, $1, $4); $$ = nod(ORANGE, $1, $4);
$$->etype = 1; $$->etype = 1;
} }
| exprsym3 ':' exprsym3 ocolas LRANGE expr | exprsym3 ':' exprsym3 LCOLAS LRANGE expr
{ {
$$ = nod(OLIST, $1, $3); $$ = nod(OLIST, $1, $3);
$$ = nod(ORANGE, $$, $6); $$ = nod(ORANGE, $$, $6);
...@@ -592,6 +590,8 @@ for_header: ...@@ -592,6 +590,8 @@ for_header:
break; break;
} }
// init ; test ; incr // init ; test ; incr
if($5 != N && $5->colas != 0)
yyerror("cannot declare in the for-increment");
$$ = nod(OFOR, N, N); $$ = nod(OFOR, N, N);
$$->ninit = $1; $$->ninit = $1;
$$->ntest = $3; $$->ntest = $3;
......
...@@ -114,7 +114,7 @@ func (j *Map) Get(s string) Json { ...@@ -114,7 +114,7 @@ func (j *Map) Get(s string) Json {
func (j *Map) String() string { func (j *Map) String() string {
s := "{"; s := "{";
first := true; first := true;
for k,v range j.m { for k,v := range j.m {
if first { if first {
first = false; first = false;
} else { } else {
...@@ -188,7 +188,7 @@ export func Equal(a, b Json) bool { ...@@ -188,7 +188,7 @@ export func Equal(a, b Json) bool {
if len(m) != len(b.(*Map).m) { if len(m) != len(b.(*Map).m) {
return false; return false;
} }
for k,v range m { for k,v := range m {
if !Equal(v, b.Get(k)) { if !Equal(v, b.Get(k)) {
return false; return false;
} }
......
...@@ -64,7 +64,7 @@ export func TestJsonMap(t *testing.T) { ...@@ -64,7 +64,7 @@ export func TestJsonMap(t *testing.T) {
if mapv == nil { if mapv == nil {
t.Fatalf("StringToJson(%#q) => nil, %v, %v", mapstr, ok, errtok); t.Fatalf("StringToJson(%#q) => nil, %v, %v", mapstr, ok, errtok);
} }
for k,v range values { for k,v := range values {
if v1 := mapv.Get(k); !Equal(v1, v) { if v1 := mapv.Get(k); !Equal(v1, v) {
t.Errorf("MapTest: Walk(%#q) => %v, want %v", k, v1, v); t.Errorf("MapTest: Walk(%#q) => %v, want %v", k, v1, v);
} }
......
...@@ -40,7 +40,7 @@ main() ...@@ -40,7 +40,7 @@ main()
* key only * key only
*/ */
i = 0; i = 0;
for k range a { for k := range a {
v := a[k]; v := a[k];
if v != f(k) { if v != f(k) {
panicln("key array range", k, v, a[k]); panicln("key array range", k, v, a[k]);
...@@ -52,7 +52,7 @@ main() ...@@ -52,7 +52,7 @@ main()
} }
i = 0; i = 0;
for k range p { for k := range p {
v := p[k]; v := p[k];
if v != f(k) { if v != f(k) {
panicln("key pointer range", k, v, p[k]); panicln("key pointer range", k, v, p[k]);
...@@ -64,7 +64,7 @@ main() ...@@ -64,7 +64,7 @@ main()
} }
i = 0; i = 0;
for k range m { for k := range m {
v := m[k]; v := m[k];
if v != f(k) { if v != f(k) {
panicln("key map range", k, v, m[k]); panicln("key map range", k, v, m[k]);
...@@ -79,7 +79,7 @@ main() ...@@ -79,7 +79,7 @@ main()
* key:value * key:value
*/ */
i = 0; i = 0;
for k:v range a { for k:v := range a {
if v != f(k) { if v != f(k) {
panicln("key:value array range", k, v, a[k]); panicln("key:value array range", k, v, a[k]);
} }
...@@ -90,7 +90,7 @@ main() ...@@ -90,7 +90,7 @@ main()
} }
i = 0; i = 0;
for k:v range p { for k:v := range p {
if v != f(k) { if v != f(k) {
panicln("key:value pointer range", k, v, p[k]); panicln("key:value pointer range", k, v, p[k]);
} }
...@@ -101,7 +101,7 @@ main() ...@@ -101,7 +101,7 @@ main()
} }
i = 0; i = 0;
for k:v range m { for k:v := range m {
if v != f(k) { if v != f(k) {
panicln("key:value map range", k, v, m[k]); panicln("key:value map range", k, v, m[k]);
} }
......
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