Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(2810)

Delta Between Two Patch Sets: src/cmd/gc/go.y

Issue 10743046: code review 10743046: cmd/gc: support x[i:j:k] (Closed)
Left Patch Set: Created 10 years, 9 months ago
Right Patch Set: diff -r ef3ed5705640 https://code.google.com/p/go/ Created 10 years, 9 months ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
Right: Side by side diff | Download
« no previous file with change/comment | « src/cmd/gc/go.h ('k') | src/cmd/gc/racewalk.c » ('j') | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
(no file at all)
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 908 matching lines...) Expand 10 before | Expand all | Expand 10 after
943 $$ = nod(OTYPESW, N, $1); 945 $$ = nod(OTYPESW, N, $1);
944 } 946 }
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 }
955 | pexpr '[' oexpr ':' oexpr ':' oexpr ']'
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
964 if($5 == N)
965 yyerror("middle index required in 3-index slice");
966 if($7 == N)
967 yyerror("final index required in 3-index slice");
968 $$ = nod(OSLICE3, $1, nod(OKEY, $3, nod(OKEY, $5, $7)));
969 }
953 | pseudocall 970 | pseudocall
954 | convtype '(' expr ocomma ')' 971 | convtype '(' expr ocomma ')'
955 { 972 {
956 // conversion 973 // conversion
957 $$ = nod(OCALL, $1, N); 974 $$ = nod(OCALL, $1, N);
958 $$->list = list1($3); 975 $$->list = list1($3);
959 } 976 }
960 | comptype lbrace start_complit braced_keyval_list '}' 977 | comptype lbrace start_complit braced_keyval_list '}'
961 { 978 {
962 $$ = $3; 979 $$ = $3;
(...skipping 1210 matching lines...) Expand 10 before | Expand all | Expand 10 after
2173 static void 2190 static void
2174 fixlbrace(int lbr) 2191 fixlbrace(int lbr)
2175 { 2192 {
2176 // If the opening brace was an LBODY, 2193 // If the opening brace was an LBODY,
2177 // set up for another one now that we're done. 2194 // set up for another one now that we're done.
2178 // See comment in lex.c about loophack. 2195 // See comment in lex.c about loophack.
2179 if(lbr == LBODY) 2196 if(lbr == LBODY)
2180 loophack = 1; 2197 loophack = 1;
2181 } 2198 }
2182 2199
LEFTRIGHT

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b