LEFT | RIGHT |
1 // Copyright 2009 The Go Authors. All rights reserved. | 1 // Copyright 2009 The Go Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style | 2 // Use of this source code is governed by a BSD-style |
3 // license that can be found in the LICENSE file. | 3 // license that can be found in the LICENSE file. |
4 | 4 |
5 /* | 5 /* |
6 * Go language grammar. | 6 * Go language grammar. |
7 * | 7 * |
8 * The Go semicolon rules are: | 8 * The Go semicolon rules are: |
9 * | 9 * |
10 * 1. all statements and declarations are terminated by semicolons. | 10 * 1. all statements and declarations are terminated by semicolons. |
11 * 2. semicolons can be omitted before a closing ) or }. | 11 * 2. semicolons can be omitted before a closing ) or }. |
12 * 3. semicolons are inserted by the lexer before a newline | 12 * 3. semicolons are inserted by the lexer before a newline |
13 * following a specific list of tokens. | 13 * following a specific list of tokens. |
14 * | 14 * |
15 * Rules #1 and #2 are accomplished by writing the lists as | 15 * Rules #1 and #2 are accomplished by writing the lists as |
16 * semicolon-separated lists with an optional trailing semicolon. | 16 * semicolon-separated lists with an optional trailing semicolon. |
17 * Rule #3 is implemented in yylex. | 17 * Rule #3 is implemented in yylex. |
18 */ | 18 */ |
19 | 19 |
20 %{ | 20 %{ |
21 #include <u.h> | 21 #include <u.h> |
22 #include <stdio.h> /* if we don't, bison will, and go.h re-#defines getc */ | 22 #include <stdio.h> /* if we don't, bison will, and go.h re-#defines getc */ |
23 #include <libc.h> | 23 #include <libc.h> |
24 #include "go.h" | 24 #include "go.h" |
| 25 |
| 26 static int isrelease = -1; |
25 | 27 |
26 static void fixlbrace(int); | 28 static void fixlbrace(int); |
27 %} | 29 %} |
28 %union { | 30 %union { |
29 Node* node; | 31 Node* node; |
30 NodeList* list; | 32 NodeList* list; |
31 Type* type; | 33 Type* type; |
32 Sym* sym; | 34 Sym* sym; |
33 struct Val val; | 35 struct Val val; |
34 int i; | 36 int i; |
(...skipping 910 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
945 | pexpr '[' expr ']' | 947 | pexpr '[' expr ']' |
946 { | 948 { |
947 $$ = nod(OINDEX, $1, $3); | 949 $$ = nod(OINDEX, $1, $3); |
948 } | 950 } |
949 | pexpr '[' oexpr ':' oexpr ']' | 951 | pexpr '[' oexpr ':' oexpr ']' |
950 { | 952 { |
951 $$ = nod(OSLICE, $1, nod(OKEY, $3, $5)); | 953 $$ = nod(OSLICE, $1, nod(OKEY, $3, $5)); |
952 } | 954 } |
953 | pexpr '[' oexpr ':' oexpr ':' oexpr ']' | 955 | pexpr '[' oexpr ':' oexpr ':' oexpr ']' |
954 { | 956 { |
| 957 // Make sure we don't accidentally release this experimental fea
ture. |
| 958 // http://golang.org/s/go12slice. |
| 959 if(isrelease < 0) |
| 960 isrelease = strstr(getgoversion(), "release") != nil; |
| 961 if(isrelease) |
| 962 yyerror("3-index slice not available in release"); |
| 963 |
955 if($5 == N) | 964 if($5 == N) |
956 yyerror("middle index required in 3-index slice"); | 965 yyerror("middle index required in 3-index slice"); |
957 if($7 == N) | 966 if($7 == N) |
958 yyerror("final index required in 3-index slice"); | 967 yyerror("final index required in 3-index slice"); |
959 $$ = nod(OSLICE3, $1, nod(OKEY, $3, nod(OKEY, $5, $7))); | 968 $$ = nod(OSLICE3, $1, nod(OKEY, $3, nod(OKEY, $5, $7))); |
960 } | 969 } |
961 | pseudocall | 970 | pseudocall |
962 | convtype '(' expr ocomma ')' | 971 | convtype '(' expr ocomma ')' |
963 { | 972 { |
964 // conversion | 973 // conversion |
(...skipping 1216 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2181 static void | 2190 static void |
2182 fixlbrace(int lbr) | 2191 fixlbrace(int lbr) |
2183 { | 2192 { |
2184 // If the opening brace was an LBODY, | 2193 // If the opening brace was an LBODY, |
2185 // set up for another one now that we're done. | 2194 // set up for another one now that we're done. |
2186 // See comment in lex.c about loophack. | 2195 // See comment in lex.c about loophack. |
2187 if(lbr == LBODY) | 2196 if(lbr == LBODY) |
2188 loophack = 1; | 2197 loophack = 1; |
2189 } | 2198 } |
2190 | 2199 |
LEFT | RIGHT |