blob: 02e941c16f9ba1e74932e2ff2cf5021de74a8164 [file] [log] [blame]
Rob Pike0cafb9e2008-06-04 14:37:38 -07001// Copyright 2009 The Go Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style
3// license that can be found in the LICENSE file.
4
Russ Cox8f4af6d2009-06-06 12:46:38 -07005/*
6 * Go language grammar.
7 *
Russ Cox8f4af6d2009-06-06 12:46:38 -07008 * The Go semicolon rules are:
9 *
10 * 1. all statements and declarations are terminated by semicolons
11 * 2. semicolons can be omitted at top level.
12 * 3. semicolons can be omitted before and after the closing ) or }
13 * on a list of statements or declarations.
14 *
Russ Cox8abcdee2009-06-06 19:27:48 -070015 * This is accomplished by calling yyoptsemi() to mark the places
16 * where semicolons are optional. That tells the lexer that if a
17 * semicolon isn't the next token, it should insert one for us.
Russ Cox8f4af6d2009-06-06 12:46:38 -070018 */
19
Rob Pike0cafb9e2008-06-04 14:37:38 -070020%{
21#include "go.h"
22%}
23%union {
24 Node* node;
Russ Coxe52e9ca2009-07-17 01:00:44 -070025 NodeList* list;
Rob Pike0cafb9e2008-06-04 14:37:38 -070026 Type* type;
27 Sym* sym;
28 struct Val val;
29 int lint;
30}
Ken Thompsona8a9dbc2008-08-11 19:17:28 -070031
Russ Cox8f4af6d2009-06-06 12:46:38 -070032// |sed 's/.* //' |9 fmt -l1 |sort |9 fmt -l50 | sed 's/^/%xxx /'
33
34%token <val> LLITERAL
35%token <lint> LASOP
36%token <sym> LBREAK LCASE LCHAN LCOLAS LCONST LCONTINUE LDDD
37%token <sym> LDEFAULT LDEFER LELSE LFALL LFOR LFUNC LGO LGOTO
38%token <sym> LIF LIMPORT LINTERFACE LMAKE LMAP LNAME LNEW
39%token <sym> LPACKAGE LRANGE LRETURN LSELECT LSTRUCT LSWITCH
40%token <sym> LTYPE LVAR
41
42%token LANDAND LANDNOT LBODY LCOMM LDEC LEQ LGE LGT
43%token LIGNORE LINC LLE LLSH LLT LNE LOROR LRSH
Russ Cox8abcdee2009-06-06 19:27:48 -070044%token LSEMIBRACE
Russ Cox8f4af6d2009-06-06 12:46:38 -070045
Russ Cox38df5ec2009-08-19 15:18:08 -070046%type <lint> lbrace import_here
Russ Cox8f4af6d2009-06-06 12:46:38 -070047%type <sym> sym packname
48%type <val> oliteral
49
Russ Coxbe16caf2009-07-13 23:38:39 -070050%type <node> stmt ntype
Russ Coxe52e9ca2009-07-17 01:00:44 -070051%type <node> arg_type
52%type <node> case caseblock
53%type <node> compound_stmt dotname embed expr
54%type <node> expr_or_type
55%type <node> fndcl fnliteral
Russ Cox8f4af6d2009-06-06 12:46:38 -070056%type <node> for_body for_header for_stmt if_header if_stmt
Russ Cox7743ffe2009-09-28 14:05:34 -070057%type <node> interfacedcl keyval labelname name
Russ Cox35e59062009-07-17 14:42:14 -070058%type <node> name_or_type non_expr_type
Russ Coxb6487162009-08-07 12:50:26 -070059%type <node> new_name dcl_name oexpr typedclname
Russ Coxe52e9ca2009-07-17 01:00:44 -070060%type <node> onew_name
61%type <node> osimple_stmt pexpr
Russ Cox8abcdee2009-06-06 19:27:48 -070062%type <node> pseudocall range_stmt select_stmt
Russ Coxe52e9ca2009-07-17 01:00:44 -070063%type <node> simple_stmt
64%type <node> switch_stmt uexpr
Russ Coxdb508ccbf2009-07-17 13:38:16 -070065%type <node> xfndcl typedcl
Russ Coxe52e9ca2009-07-17 01:00:44 -070066
Russ Coxdb508ccbf2009-07-17 13:38:16 -070067%type <list> xdcl fnbody fnres switch_body loop_body dcl_name_list
68%type <list> new_name_list expr_list keyval_list braced_keyval_list expr_or_type_list xdcl_list
Russ Coxe52e9ca2009-07-17 01:00:44 -070069%type <list> oexpr_list oexpr_or_type_list caseblock_list stmt_list oarg_type_list arg_type_list
Russ Cox7743ffe2009-09-28 14:05:34 -070070%type <list> interfacedcl_list vardcl vardcl_list structdcl structdcl_list
Russ Coxdb508ccbf2009-07-17 13:38:16 -070071%type <list> common_dcl constdcl constdcl1 constdcl_list typedcl_list
Russ Cox8f4af6d2009-06-06 12:46:38 -070072
Russ Cox6f169872009-09-29 21:21:14 -070073%type <node> convtype dotdotdot
Russ Cox35e59062009-07-17 14:42:14 -070074%type <node> indcl interfacetype structtype ptrtype
Russ Coxb6487162009-08-07 12:50:26 -070075%type <node> chantype non_chan_type othertype non_fn_type fntype
Russ Cox8f4af6d2009-06-06 12:46:38 -070076
77%type <sym> hidden_importsym hidden_pkg_importsym
78
Russ Coxe52e9ca2009-07-17 01:00:44 -070079%type <node> hidden_constant hidden_dcl hidden_interfacedcl hidden_structdcl
80
81%type <list> hidden_funres
82%type <list> ohidden_funres
83%type <list> hidden_funarg_list ohidden_funarg_list
84%type <list> hidden_interfacedcl_list ohidden_interfacedcl_list
85%type <list> hidden_structdcl_list ohidden_structdcl_list
Russ Cox8f4af6d2009-06-06 12:46:38 -070086
Russ Coxb6487162009-08-07 12:50:26 -070087%type <type> hidden_type hidden_type1 hidden_type2 hidden_pkgtype
Russ Cox8f4af6d2009-06-06 12:46:38 -070088
89%left LOROR
90%left LANDAND
91%left LCOMM
92%left LEQ LNE LLE LGE LLT LGT
93%left '+' '-' '|' '^'
94%left '*' '/' '%' '&' LLSH LRSH LANDNOT
Rob Pike0cafb9e2008-06-04 14:37:38 -070095
Russ Coxd364d282008-10-07 12:36:30 -070096/*
Russ Cox8f4af6d2009-06-06 12:46:38 -070097 * manual override of shift/reduce conflicts.
98 * the general form is that we assign a precedence
99 * to the token being shifted and then introduce
100 * NotToken with lower precedence or PreferToToken with higher
101 * and annotate the reducing rule accordingly.
Russ Coxd364d282008-10-07 12:36:30 -0700102 */
Russ Cox8f4af6d2009-06-06 12:46:38 -0700103%left NotPackage
104%left LPACKAGE
Russ Coxd364d282008-10-07 12:36:30 -0700105
Russ Cox8f4af6d2009-06-06 12:46:38 -0700106%left NotParen
107%left '('
Rob Pike0cafb9e2008-06-04 14:37:38 -0700108
Russ Cox8f4af6d2009-06-06 12:46:38 -0700109%left ')'
110%left PreferToRightParen
Rob Pike0cafb9e2008-06-04 14:37:38 -0700111
Russ Cox8f4af6d2009-06-06 12:46:38 -0700112%left '.'
Russ Coxc3d841f2008-09-26 11:44:20 -0700113
Russ Cox8f4af6d2009-06-06 12:46:38 -0700114%left '{'
Russ Cox49cc6492009-03-03 08:41:02 -0800115
Russ Coxaaaa1fc2009-09-15 17:29:08 -0700116%left NotSemi
117%left ';'
118
Rob Pike0cafb9e2008-06-04 14:37:38 -0700119%%
120file:
Russ Coxb3533df2009-05-08 15:40:31 -0700121 loadsys
122 package
123 imports
Russ Coxe52e9ca2009-07-17 01:00:44 -0700124 xdcl_list
Rob Pike0cafb9e2008-06-04 14:37:38 -0700125 {
Russ Cox66bb3992009-08-12 13:18:19 -0700126 xtop = concat(xtop, $4);
Rob Pike0cafb9e2008-06-04 14:37:38 -0700127 }
128
129package:
Russ Cox63985b42009-03-05 15:57:03 -0800130 %prec NotPackage
Rob Pike0cafb9e2008-06-04 14:37:38 -0700131 {
Russ Cox38df5ec2009-08-19 15:18:08 -0700132 prevlineno = lineno;
Rob Pike0cafb9e2008-06-04 14:37:38 -0700133 yyerror("package statement must be first");
134 mkpackage("main");
Rob Pike0cafb9e2008-06-04 14:37:38 -0700135 }
136| LPACKAGE sym
137 {
138 mkpackage($2->name);
Russ Coxb3533df2009-05-08 15:40:31 -0700139 }
140
141/*
Russ Cox22a5c782009-10-15 23:10:49 -0700142 * this loads the definitions for the low-level runtime functions,
Russ Coxb3533df2009-05-08 15:40:31 -0700143 * so that the compiler can generate calls to them,
Russ Cox22a5c782009-10-15 23:10:49 -0700144 * but does not make the name "runtime" visible as a package.
Russ Coxb3533df2009-05-08 15:40:31 -0700145 */
146loadsys:
147 {
Russ Cox22a5c782009-10-15 23:10:49 -0700148 cannedimports("runtime.builtin", runtimeimport);
Rob Pike0cafb9e2008-06-04 14:37:38 -0700149 }
Russ Coxb3533df2009-05-08 15:40:31 -0700150 import_package
151 import_there
152 {
153 pkgimportname = S;
154 }
Rob Pike0cafb9e2008-06-04 14:37:38 -0700155
156imports:
157| imports import
158
159import:
Russ Coxaaaa1fc2009-09-15 17:29:08 -0700160 LIMPORT import_stmt osemi
161| LIMPORT '(' import_stmt_list osemi ')' osemi
162| LIMPORT '(' ')' osemi
Rob Pike0cafb9e2008-06-04 14:37:38 -0700163
164import_stmt:
Russ Cox38df5ec2009-08-19 15:18:08 -0700165 import_here import_package import_there
Russ Coxb3533df2009-05-08 15:40:31 -0700166 {
167 Sym *import, *my;
Russ Cox73e52ae2009-09-17 16:42:10 -0700168 Node *pack;
Russ Coxb3533df2009-05-08 15:40:31 -0700169
170 import = pkgimportname;
171 my = pkgmyname;
172 pkgmyname = S;
173 pkgimportname = S;
174
175 if(import == S)
176 break;
Russ Cox73e52ae2009-09-17 16:42:10 -0700177
178 pack = nod(OPACK, N, N);
179 pack->sym = import;
180 pack->lineno = $1;
Russ Cox73e52ae2009-09-17 16:42:10 -0700181
Russ Coxb3533df2009-05-08 15:40:31 -0700182 if(my == S)
183 my = import;
184 if(my->name[0] == '.') {
Russ Cox73e52ae2009-09-17 16:42:10 -0700185 importdot(import, pack);
Russ Coxb3533df2009-05-08 15:40:31 -0700186 break;
187 }
Russ Coxaa6e81dd2009-09-09 16:59:41 -0700188 if(my->name[0] == '_' && my->name[1] == '\0')
189 break;
Russ Coxb3533df2009-05-08 15:40:31 -0700190
Russ Coxfd76b4f2009-10-12 10:12:37 -0700191 // Can end up with my->def->op set to ONONAME
192 // if one package refers to p without importing it.
193 // Don't want to give an error on a good import
194 // in another file.
195 if(my->def && my->def->op != ONONAME) {
Russ Coxd5150632009-10-07 14:55:12 -0700196 lineno = $1;
197 redeclare(my, "as imported package name");
198 }
Russ Cox73e52ae2009-09-17 16:42:10 -0700199 my->def = pack;
Russ Cox38df5ec2009-08-19 15:18:08 -0700200 my->lastlineno = $1;
Russ Cox56004352009-08-19 17:27:08 -0700201 import->block = 1; // at top level
Russ Coxb3533df2009-05-08 15:40:31 -0700202 }
Russ Cox5d16d232009-09-09 00:18:16 -0700203
Russ Cox38df5ec2009-08-19 15:18:08 -0700204
205import_stmt_list:
206 import_stmt
207| import_stmt_list ';' import_stmt
208
209import_here:
210 LLITERAL
211 {
212 // import with original name
213 $$ = parserline();
214 pkgimportname = S;
215 pkgmyname = S;
Russ Cox73e52ae2009-09-17 16:42:10 -0700216 importfile(&$1, $$);
Russ Cox38df5ec2009-08-19 15:18:08 -0700217 }
218| sym LLITERAL
219 {
220 // import with given name
221 $$ = parserline();
222 pkgimportname = S;
223 pkgmyname = $1;
Russ Cox73e52ae2009-09-17 16:42:10 -0700224 importfile(&$2, $$);
Russ Cox38df5ec2009-08-19 15:18:08 -0700225 }
226| '.' LLITERAL
227 {
228 // import into my name space
229 $$ = parserline();
230 pkgmyname = lookup(".");
Russ Cox73e52ae2009-09-17 16:42:10 -0700231 importfile(&$2, $$);
Russ Cox38df5ec2009-08-19 15:18:08 -0700232 }
233
234import_package:
235 LPACKAGE sym
236 {
237 pkgimportname = $2;
238 if(strcmp($2->name, "main") == 0)
239 yyerror("cannot import package main");
Russ Cox5d16d232009-09-09 00:18:16 -0700240
Russ Cox27c4e7e2009-09-01 14:12:09 -0700241 // TODO(rsc): This is not quite precise enough a check
242 // (it excludes google/util/hash from importing hash)
Russ Cox5d16d232009-09-09 00:18:16 -0700243 // but it is enough to reduce confusion during the
Russ Cox27c4e7e2009-09-01 14:12:09 -0700244 // 2009/09/01 release when all the "import myself"
245 // statements have to go away in programs building
246 // against the release. Once the programs have converted
247 // it should probably just go away.
Russ Cox22a5c782009-10-15 23:10:49 -0700248 if(strcmp($2->name, package) == 0 && strcmp(package, "runtime") != 0)
Russ Cox27c4e7e2009-09-01 14:12:09 -0700249 yyerror("package cannot import itself (anymore)");
Russ Cox38df5ec2009-08-19 15:18:08 -0700250 }
251
252import_there:
253 {
254 defercheckwidth();
255 }
256 hidden_import_list '$' '$'
257 {
258 resumecheckwidth();
259 checkimports();
260 unimportfile();
261 }
262| LIMPORT '$' '$'
263 {
264 defercheckwidth();
265 }
266 hidden_import_list '$' '$'
267 {
268 resumecheckwidth();
269 checkimports();
270 }
Russ Coxb3533df2009-05-08 15:40:31 -0700271
Rob Pike0cafb9e2008-06-04 14:37:38 -0700272/*
273 * declarations
274 */
275xdcl:
Russ Coxaaaa1fc2009-09-15 17:29:08 -0700276 common_dcl osemi
277| xfndcl osemi
Ken Thompson989676d2008-08-03 18:47:02 -0700278 {
Russ Coxb6487162009-08-07 12:50:26 -0700279 $$ = list1($1);
Ken Thompson989676d2008-08-03 18:47:02 -0700280 }
Russ Coxaaaa1fc2009-09-15 17:29:08 -0700281| error osemi
Rob Pike0cafb9e2008-06-04 14:37:38 -0700282 {
Russ Coxe52e9ca2009-07-17 01:00:44 -0700283 $$ = nil;
Rob Pike0cafb9e2008-06-04 14:37:38 -0700284 }
Russ Coxaaaa1fc2009-09-15 17:29:08 -0700285| ';'
Ken Thompson1efa6a02008-07-03 18:05:20 -0700286 {
Russ Coxaaaa1fc2009-09-15 17:29:08 -0700287 yyerror("empty top-level declaration");
288 $$ = nil;
Ken Thompson1efa6a02008-07-03 18:05:20 -0700289 }
Rob Pike0cafb9e2008-06-04 14:37:38 -0700290
291common_dcl:
Russ Cox8abcdee2009-06-06 19:27:48 -0700292 LVAR vardcl
Rob Pike0cafb9e2008-06-04 14:37:38 -0700293 {
294 $$ = $2;
Russ Cox8abcdee2009-06-06 19:27:48 -0700295 if(yylast == LSEMIBRACE)
296 yyoptsemi(0);
Rob Pike0cafb9e2008-06-04 14:37:38 -0700297 }
Russ Coxe52e9ca2009-07-17 01:00:44 -0700298| LVAR '(' vardcl_list osemi ')'
Rob Pike0cafb9e2008-06-04 14:37:38 -0700299 {
Russ Coxe52e9ca2009-07-17 01:00:44 -0700300 $$ = $3;
Russ Cox8abcdee2009-06-06 19:27:48 -0700301 yyoptsemi(0);
Rob Pike0cafb9e2008-06-04 14:37:38 -0700302 }
Russ Cox5f1202422008-10-08 15:33:09 -0700303| LVAR '(' ')'
304 {
Russ Coxe52e9ca2009-07-17 01:00:44 -0700305 $$ = nil;
Russ Cox8abcdee2009-06-06 19:27:48 -0700306 yyoptsemi(0);
Ken Thompson54abac62008-06-21 15:11:29 -0700307 }
308| LCONST constdcl
309 {
Russ Coxb6487162009-08-07 12:50:26 -0700310 $$ = $2;
Ken Thompson54abac62008-06-21 15:11:29 -0700311 iota = 0;
Russ Coxe52e9ca2009-07-17 01:00:44 -0700312 lastconst = nil;
Ken Thompson54abac62008-06-21 15:11:29 -0700313 }
Russ Cox8abcdee2009-06-06 19:27:48 -0700314| LCONST '(' constdcl osemi ')'
315 {
Russ Coxb6487162009-08-07 12:50:26 -0700316 $$ = $3;
Russ Cox8abcdee2009-06-06 19:27:48 -0700317 iota = 0;
Russ Coxe52e9ca2009-07-17 01:00:44 -0700318 lastconst = nil;
Russ Cox8abcdee2009-06-06 19:27:48 -0700319 yyoptsemi(0);
320 }
Russ Coxe52e9ca2009-07-17 01:00:44 -0700321| LCONST '(' constdcl ';' constdcl_list osemi ')'
Russ Cox8abcdee2009-06-06 19:27:48 -0700322 {
Russ Coxb6487162009-08-07 12:50:26 -0700323 $$ = concat($3, $5);
Russ Cox8abcdee2009-06-06 19:27:48 -0700324 iota = 0;
Russ Coxe52e9ca2009-07-17 01:00:44 -0700325 lastconst = nil;
Russ Cox8abcdee2009-06-06 19:27:48 -0700326 yyoptsemi(0);
327 }
328| LCONST '(' ')'
Ken Thompson54abac62008-06-21 15:11:29 -0700329 {
Russ Coxe52e9ca2009-07-17 01:00:44 -0700330 $$ = nil;
Russ Cox8abcdee2009-06-06 19:27:48 -0700331 yyoptsemi(0);
332 }
333| LTYPE typedcl
334 {
Russ Coxb6487162009-08-07 12:50:26 -0700335 $$ = list1($2);
Russ Cox8abcdee2009-06-06 19:27:48 -0700336 if(yylast == LSEMIBRACE)
337 yyoptsemi(0);
338 }
Russ Coxe52e9ca2009-07-17 01:00:44 -0700339| LTYPE '(' typedcl_list osemi ')'
Russ Cox8abcdee2009-06-06 19:27:48 -0700340 {
Russ Coxb6487162009-08-07 12:50:26 -0700341 $$ = $3;
Russ Cox8abcdee2009-06-06 19:27:48 -0700342 yyoptsemi(0);
343 }
344| LTYPE '(' ')'
345 {
Russ Coxe52e9ca2009-07-17 01:00:44 -0700346 $$ = nil;
Russ Cox8abcdee2009-06-06 19:27:48 -0700347 yyoptsemi(0);
348 }
349
350varoptsemi:
351 {
Russ Cox5d5904b2009-06-29 17:46:22 -0700352 if(yylast == LSEMIBRACE)
353 yyoptsemi('=');
Ken Thompson54abac62008-06-21 15:11:29 -0700354 }
355
Rob Pike0cafb9e2008-06-04 14:37:38 -0700356vardcl:
Russ Cox35e59062009-07-17 14:42:14 -0700357 dcl_name_list ntype varoptsemi
Ken Thompson54abac62008-06-21 15:11:29 -0700358 {
Russ Coxe52e9ca2009-07-17 01:00:44 -0700359 $$ = variter($1, $2, nil);
Ken Thompson54abac62008-06-21 15:11:29 -0700360 }
Russ Cox35e59062009-07-17 14:42:14 -0700361| dcl_name_list ntype varoptsemi '=' expr_list
Rob Pike0cafb9e2008-06-04 14:37:38 -0700362 {
Russ Cox8abcdee2009-06-06 19:27:48 -0700363 $$ = variter($1, $2, $5);
Rob Pike0cafb9e2008-06-04 14:37:38 -0700364 }
Russ Coxdb508ccbf2009-07-17 13:38:16 -0700365| dcl_name_list '=' expr_list
Rob Pike0cafb9e2008-06-04 14:37:38 -0700366 {
Russ Cox35e59062009-07-17 14:42:14 -0700367 $$ = variter($1, nil, $3);
Rob Pike0cafb9e2008-06-04 14:37:38 -0700368 }
369
370constdcl:
Russ Coxdb508ccbf2009-07-17 13:38:16 -0700371 dcl_name_list ntype '=' expr_list
Ken Thompsond915b962008-07-03 16:41:32 -0700372 {
Russ Coxdb508ccbf2009-07-17 13:38:16 -0700373 $$ = constiter($1, $2, $4);
Rob Pike0cafb9e2008-06-04 14:37:38 -0700374 }
Russ Coxdb508ccbf2009-07-17 13:38:16 -0700375| dcl_name_list '=' expr_list
Rob Pike0cafb9e2008-06-04 14:37:38 -0700376 {
Russ Coxdb508ccbf2009-07-17 13:38:16 -0700377 $$ = constiter($1, N, $3);
Ken Thompson9dbaab52008-09-04 12:21:10 -0700378 }
379
380constdcl1:
381 constdcl
Russ Coxdb508ccbf2009-07-17 13:38:16 -0700382| dcl_name_list ntype
Ken Thompson9dbaab52008-09-04 12:21:10 -0700383 {
Russ Coxdb508ccbf2009-07-17 13:38:16 -0700384 $$ = constiter($1, $2, nil);
Ken Thompson9dbaab52008-09-04 12:21:10 -0700385 }
Russ Coxdb508ccbf2009-07-17 13:38:16 -0700386| dcl_name_list
Ken Thompson9dbaab52008-09-04 12:21:10 -0700387 {
Russ Coxdb508ccbf2009-07-17 13:38:16 -0700388 $$ = constiter($1, N, nil);
Rob Pike0cafb9e2008-06-04 14:37:38 -0700389 }
390
Russ Cox74e2e082008-10-06 16:44:17 -0700391typedclname:
Russ Coxb6487162009-08-07 12:50:26 -0700392 sym
Ken Thompson54abac62008-06-21 15:11:29 -0700393 {
Russ Coxb6487162009-08-07 12:50:26 -0700394 // different from dclname because the name
395 // becomes visible right here, not at the end
396 // of the declaration.
397 $$ = typedcl0($1);
Ken Thompson54abac62008-06-21 15:11:29 -0700398 }
399
Russ Coxd364d282008-10-07 12:36:30 -0700400typedcl:
Russ Cox35e59062009-07-17 14:42:14 -0700401 typedclname ntype
Rob Pike0cafb9e2008-06-04 14:37:38 -0700402 {
Russ Coxb6487162009-08-07 12:50:26 -0700403 $$ = typedcl1($1, $2, 1);
Russ Cox74e2e082008-10-06 16:44:17 -0700404 }
Russ Coxb6487162009-08-07 12:50:26 -0700405
Rob Pike0cafb9e2008-06-04 14:37:38 -0700406simple_stmt:
407 expr
408 {
409 $$ = $1;
410 }
Rob Pike0cafb9e2008-06-04 14:37:38 -0700411| expr LASOP expr
412 {
413 $$ = nod(OASOP, $1, $3);
Ken Thompson9c2ade32008-08-08 17:13:31 -0700414 $$->etype = $2; // rathole to pass opcode
Rob Pike0cafb9e2008-06-04 14:37:38 -0700415 }
Russ Cox8f4af6d2009-06-06 12:46:38 -0700416| expr_list '=' expr_list
Rob Pike0cafb9e2008-06-04 14:37:38 -0700417 {
Russ Coxe52e9ca2009-07-17 01:00:44 -0700418 if($1->next == nil && $3->next == nil) {
419 // simple
420 $$ = nod(OAS, $1->n, $3->n);
421 break;
422 }
423 // multiple
424 $$ = nod(OAS2, N, N);
425 $$->list = $1;
426 $$->rlist = $3;
Rob Pike0cafb9e2008-06-04 14:37:38 -0700427 }
Russ Cox8f4af6d2009-06-06 12:46:38 -0700428| expr_list LCOLAS expr_list
Rob Pike0cafb9e2008-06-04 14:37:38 -0700429 {
Russ Coxe52e9ca2009-07-17 01:00:44 -0700430 if($3->n->op == OTYPESW) {
431 if($3->next != nil)
432 yyerror("expr.(type) must be alone in list");
433 else if($1->next != nil)
434 yyerror("argument count mismatch: %d = %d", count($1), 1);
Russ Cox5d16d232009-09-09 00:18:16 -0700435 $$ = nod(OTYPESW, $1->n, $3->n->right);
Ken Thompsona4a10ed2009-03-06 17:50:43 -0800436 break;
437 }
Russ Coxe52e9ca2009-07-17 01:00:44 -0700438 $$ = colas($1, $3);
Rob Pike0cafb9e2008-06-04 14:37:38 -0700439 }
Russ Coxd364d282008-10-07 12:36:30 -0700440| expr LINC
Ken Thompsonc242b532008-06-17 22:33:32 -0700441 {
Russ Cox8f194bf2009-03-12 19:04:38 -0700442 $$ = nod(OASOP, $1, nodintconst(1));
Ken Thompsonc242b532008-06-17 22:33:32 -0700443 $$->etype = OADD;
444 }
445| expr LDEC
446 {
Russ Cox8f194bf2009-03-12 19:04:38 -0700447 $$ = nod(OASOP, $1, nodintconst(1));
Ken Thompsonc242b532008-06-17 22:33:32 -0700448 $$->etype = OSUB;
449 }
450
Russ Coxd6a98172009-05-30 21:18:15 -0700451case:
Russ Cox35e59062009-07-17 14:42:14 -0700452 LCASE expr_or_type_list ':'
Rob Pike0cafb9e2008-06-04 14:37:38 -0700453 {
Russ Cox5d16d232009-09-09 00:18:16 -0700454 Node *n;
Russ Cox0dadc4f2009-07-10 16:29:26 -0700455
Rob Pike0cafb9e2008-06-04 14:37:38 -0700456 // will be converted to OCASE
457 // right will point to next case
458 // done in casebody()
459 poptodcl();
Russ Coxe52e9ca2009-07-17 01:00:44 -0700460 $$ = nod(OXCASE, N, N);
Russ Cox5d16d232009-09-09 00:18:16 -0700461 $$->list = $2;
462 if(typesw != N && typesw->right != N && (n=typesw->right->left) != N) {
463 // type switch - declare variable
464 n = newname(n->sym);
Russ Cox59914722009-09-14 18:38:30 -0700465 n->used = 1; // TODO(rsc): better job here
Russ Cox26097312009-08-05 02:33:30 -0700466 declare(n, dclcontext);
Russ Cox5d16d232009-09-09 00:18:16 -0700467 $$->nname = n;
Ken Thompson0f469a92009-03-17 13:58:38 -0700468 }
Russ Coxe52e9ca2009-07-17 01:00:44 -0700469 break;
Rob Pike0cafb9e2008-06-04 14:37:38 -0700470 }
Rob Pike47919792008-09-16 19:14:33 -0700471| LCASE name '=' expr ':'
472 {
473 // will be converted to OCASE
474 // right will point to next case
475 // done in casebody()
476 poptodcl();
Russ Coxe52e9ca2009-07-17 01:00:44 -0700477 $$ = nod(OXCASE, N, N);
478 $$->list = list1(nod(OAS, $2, $4));
Rob Pike47919792008-09-16 19:14:33 -0700479 }
480| LCASE name LCOLAS expr ':'
481 {
482 // will be converted to OCASE
483 // right will point to next case
484 // done in casebody()
485 poptodcl();
Russ Coxe52e9ca2009-07-17 01:00:44 -0700486 $$ = nod(OXCASE, N, N);
Russ Cox54b40372009-08-05 00:42:44 -0700487 $$->list = list1(colas(list1($2), list1($4)));
Rob Pike47919792008-09-16 19:14:33 -0700488 }
Rob Pike0cafb9e2008-06-04 14:37:38 -0700489| LDEFAULT ':'
490 {
Russ Cox5d16d232009-09-09 00:18:16 -0700491 Node *n;
492
Rob Pike0cafb9e2008-06-04 14:37:38 -0700493 poptodcl();
494 $$ = nod(OXCASE, N, N);
Russ Cox5d16d232009-09-09 00:18:16 -0700495 if(typesw != N && typesw->right != N && (n=typesw->right->left) != N) {
496 // type switch - declare variable
497 n = newname(n->sym);
Russ Cox59914722009-09-14 18:38:30 -0700498 n->used = 1; // TODO(rsc): better job here
Russ Cox5d16d232009-09-09 00:18:16 -0700499 declare(n, dclcontext);
500 $$->nname = n;
501 }
Rob Pike0cafb9e2008-06-04 14:37:38 -0700502 }
Ken Thompson8200a0b2008-06-08 12:48:37 -0700503
Rob Pike0cafb9e2008-06-04 14:37:38 -0700504compound_stmt:
505 '{'
506 {
Ken Thompson417a9712008-07-05 12:49:25 -0700507 markdcl();
Russ Cox8f4af6d2009-06-06 12:46:38 -0700508 }
Russ Coxe52e9ca2009-07-17 01:00:44 -0700509 stmt_list '}'
Rob Pike0cafb9e2008-06-04 14:37:38 -0700510 {
Russ Coxe52e9ca2009-07-17 01:00:44 -0700511 $$ = liststmt($3);
Ken Thompson417a9712008-07-05 12:49:25 -0700512 popdcl();
Russ Cox8abcdee2009-06-06 19:27:48 -0700513 yyoptsemi(0);
Rob Pike0cafb9e2008-06-04 14:37:38 -0700514 }
515
Russ Coxd6a98172009-05-30 21:18:15 -0700516switch_body:
Russ Cox8f4af6d2009-06-06 12:46:38 -0700517 LBODY
Russ Coxd6a98172009-05-30 21:18:15 -0700518 {
519 markdcl();
520 }
Russ Coxe52e9ca2009-07-17 01:00:44 -0700521 caseblock_list '}'
Russ Coxd6a98172009-05-30 21:18:15 -0700522 {
523 $$ = $3;
Russ Coxd6a98172009-05-30 21:18:15 -0700524 popdcl();
Russ Cox8abcdee2009-06-06 19:27:48 -0700525 yyoptsemi(0);
Russ Coxd6a98172009-05-30 21:18:15 -0700526 }
527
528caseblock:
Russ Coxe52e9ca2009-07-17 01:00:44 -0700529 case stmt_list
Russ Coxd6a98172009-05-30 21:18:15 -0700530 {
531 $$ = $1;
532 $$->nbody = $2;
533 }
534
Russ Coxe52e9ca2009-07-17 01:00:44 -0700535caseblock_list:
Russ Coxd6a98172009-05-30 21:18:15 -0700536 {
Russ Coxe52e9ca2009-07-17 01:00:44 -0700537 $$ = nil;
538 }
539| caseblock_list caseblock
540 {
541 $$ = list($1, $2);
Russ Coxd6a98172009-05-30 21:18:15 -0700542 }
543
Russ Cox8f4af6d2009-06-06 12:46:38 -0700544loop_body:
545 LBODY
546 {
547 markdcl();
548 }
Russ Coxe52e9ca2009-07-17 01:00:44 -0700549 stmt_list '}'
Russ Cox8f4af6d2009-06-06 12:46:38 -0700550 {
551 $$ = $3;
Russ Cox8f4af6d2009-06-06 12:46:38 -0700552 popdcl();
553 }
554
Russ Cox3ec46752009-01-28 15:41:50 -0800555range_stmt:
Russ Cox8f4af6d2009-06-06 12:46:38 -0700556 expr_list '=' LRANGE expr
Rob Pike0cafb9e2008-06-04 14:37:38 -0700557 {
Russ Coxe52e9ca2009-07-17 01:00:44 -0700558 $$ = nod(ORANGE, N, $4);
559 $$->list = $1;
Ken Thompsonb79272d2008-12-06 13:40:30 -0800560 $$->etype = 0; // := flag
561 }
Russ Cox8f4af6d2009-06-06 12:46:38 -0700562| expr_list LCOLAS LRANGE expr
Ken Thompsonb79272d2008-12-06 13:40:30 -0800563 {
Russ Coxe52e9ca2009-07-17 01:00:44 -0700564 $$ = nod(ORANGE, N, $4);
565 $$->list = $1;
Russ Cox26097312009-08-05 02:33:30 -0700566 $$->colas = 1;
567 colasdefn($1, $$);
Ken Thompsonb79272d2008-12-06 13:40:30 -0800568 }
Ken Thompsonb79272d2008-12-06 13:40:30 -0800569
570for_header:
Russ Cox3ec46752009-01-28 15:41:50 -0800571 osimple_stmt ';' osimple_stmt ';' osimple_stmt
Ken Thompsonb79272d2008-12-06 13:40:30 -0800572 {
Rob Pike0cafb9e2008-06-04 14:37:38 -0700573 // init ; test ; incr
Ken Thompsonae5a4752008-12-15 13:44:27 -0800574 if($5 != N && $5->colas != 0)
575 yyerror("cannot declare in the for-increment");
Rob Pike0cafb9e2008-06-04 14:37:38 -0700576 $$ = nod(OFOR, N, N);
Russ Coxe52e9ca2009-07-17 01:00:44 -0700577 if($1 != N)
578 $$->ninit = list1($1);
Rob Pike0cafb9e2008-06-04 14:37:38 -0700579 $$->ntest = $3;
580 $$->nincr = $5;
581 }
Russ Cox8f4af6d2009-06-06 12:46:38 -0700582| osimple_stmt
Rob Pike0cafb9e2008-06-04 14:37:38 -0700583 {
Ken Thompsonb79272d2008-12-06 13:40:30 -0800584 // normal test
Rob Pike0cafb9e2008-06-04 14:37:38 -0700585 $$ = nod(OFOR, N, N);
Rob Pike0cafb9e2008-06-04 14:37:38 -0700586 $$->ntest = $1;
Rob Pike0cafb9e2008-06-04 14:37:38 -0700587 }
Russ Cox3ec46752009-01-28 15:41:50 -0800588| range_stmt
Rob Pike0cafb9e2008-06-04 14:37:38 -0700589
590for_body:
Russ Cox8f4af6d2009-06-06 12:46:38 -0700591 for_header loop_body
Rob Pike0cafb9e2008-06-04 14:37:38 -0700592 {
593 $$ = $1;
Russ Coxe52e9ca2009-07-17 01:00:44 -0700594 $$->nbody = concat($$->nbody, $2);
Russ Cox8abcdee2009-06-06 19:27:48 -0700595 yyoptsemi(0);
Rob Pike0cafb9e2008-06-04 14:37:38 -0700596 }
597
598for_stmt:
Russ Coxd6a98172009-05-30 21:18:15 -0700599 LFOR
Rob Pike0cafb9e2008-06-04 14:37:38 -0700600 {
Ken Thompson417a9712008-07-05 12:49:25 -0700601 markdcl();
Russ Coxd6a98172009-05-30 21:18:15 -0700602 }
603 for_body
Rob Pike0cafb9e2008-06-04 14:37:38 -0700604 {
Russ Coxd6a98172009-05-30 21:18:15 -0700605 $$ = $3;
606 popdcl();
Rob Pike0cafb9e2008-06-04 14:37:38 -0700607 }
608
609if_header:
Russ Cox8f4af6d2009-06-06 12:46:38 -0700610 osimple_stmt
Rob Pike0cafb9e2008-06-04 14:37:38 -0700611 {
612 // test
613 $$ = nod(OIF, N, N);
Rob Pike0cafb9e2008-06-04 14:37:38 -0700614 $$->ntest = $1;
615 }
Russ Cox8f4af6d2009-06-06 12:46:38 -0700616| osimple_stmt ';' osimple_stmt
Rob Pike0cafb9e2008-06-04 14:37:38 -0700617 {
618 // init ; test
619 $$ = nod(OIF, N, N);
Russ Coxe52e9ca2009-07-17 01:00:44 -0700620 if($1 != N)
621 $$->ninit = list1($1);
Rob Pike0cafb9e2008-06-04 14:37:38 -0700622 $$->ntest = $3;
623 }
624
Russ Coxd6a98172009-05-30 21:18:15 -0700625if_stmt:
626 LIF
627 {
628 markdcl();
629 }
Russ Cox8f4af6d2009-06-06 12:46:38 -0700630 if_header loop_body
Russ Coxd6a98172009-05-30 21:18:15 -0700631 {
632 $$ = $3;
633 $$->nbody = $4;
634 // no popdcl; maybe there's an LELSE
Russ Cox8abcdee2009-06-06 19:27:48 -0700635 yyoptsemi(LELSE);
Russ Coxd6a98172009-05-30 21:18:15 -0700636 }
637
638switch_stmt:
639 LSWITCH
640 {
641 markdcl();
642 }
Ken Thompsona4a10ed2009-03-06 17:50:43 -0800643 if_header
644 {
645 Node *n;
Russ Coxd6a98172009-05-30 21:18:15 -0700646 n = $3->ntest;
Russ Cox5d16d232009-09-09 00:18:16 -0700647 if(n != N && n->op != OTYPESW)
Ken Thompsona4a10ed2009-03-06 17:50:43 -0800648 n = N;
Russ Cox5d16d232009-09-09 00:18:16 -0700649 typesw = nod(OXXX, typesw, n);
Rob Pike0cafb9e2008-06-04 14:37:38 -0700650 }
Russ Coxd6a98172009-05-30 21:18:15 -0700651 switch_body
Rob Pike0cafb9e2008-06-04 14:37:38 -0700652 {
Russ Coxd6a98172009-05-30 21:18:15 -0700653 $$ = $3;
654 $$->op = OSWITCH;
Russ Coxe52e9ca2009-07-17 01:00:44 -0700655 $$->list = $5;
Russ Cox5d16d232009-09-09 00:18:16 -0700656 typesw = typesw->left;
Russ Coxd6a98172009-05-30 21:18:15 -0700657 popdcl();
Rob Pike0cafb9e2008-06-04 14:37:38 -0700658 }
659
Ken Thompsonb78676a2008-07-20 20:13:07 -0700660select_stmt:
Russ Coxd6a98172009-05-30 21:18:15 -0700661 LSELECT
Ken Thompsonb78676a2008-07-20 20:13:07 -0700662 {
663 markdcl();
664 }
Russ Coxd6a98172009-05-30 21:18:15 -0700665 switch_body
Ken Thompsonb78676a2008-07-20 20:13:07 -0700666 {
Russ Coxe52e9ca2009-07-17 01:00:44 -0700667 $$ = nod(OSELECT, N, N);
668 $$->list = $3;
Russ Coxd6a98172009-05-30 21:18:15 -0700669 popdcl();
Ken Thompsonb78676a2008-07-20 20:13:07 -0700670 }
671
Rob Pike0cafb9e2008-06-04 14:37:38 -0700672/*
673 * expressions
674 */
675expr:
676 uexpr
677| expr LOROR expr
678 {
679 $$ = nod(OOROR, $1, $3);
680 }
681| expr LANDAND expr
682 {
683 $$ = nod(OANDAND, $1, $3);
684 }
685| expr LEQ expr
686 {
687 $$ = nod(OEQ, $1, $3);
688 }
689| expr LNE expr
690 {
691 $$ = nod(ONE, $1, $3);
692 }
693| expr LLT expr
694 {
695 $$ = nod(OLT, $1, $3);
696 }
697| expr LLE expr
698 {
699 $$ = nod(OLE, $1, $3);
700 }
701| expr LGE expr
702 {
703 $$ = nod(OGE, $1, $3);
704 }
705| expr LGT expr
706 {
707 $$ = nod(OGT, $1, $3);
708 }
709| expr '+' expr
710 {
711 $$ = nod(OADD, $1, $3);
712 }
713| expr '-' expr
714 {
715 $$ = nod(OSUB, $1, $3);
716 }
717| expr '|' expr
718 {
719 $$ = nod(OOR, $1, $3);
720 }
721| expr '^' expr
722 {
723 $$ = nod(OXOR, $1, $3);
724 }
725| expr '*' expr
726 {
727 $$ = nod(OMUL, $1, $3);
728 }
729| expr '/' expr
730 {
731 $$ = nod(ODIV, $1, $3);
732 }
733| expr '%' expr
734 {
735 $$ = nod(OMOD, $1, $3);
736 }
737| expr '&' expr
738 {
739 $$ = nod(OAND, $1, $3);
740 }
Ken Thompsonbb02e482009-03-11 19:59:35 -0700741| expr LANDNOT expr
742 {
743 $$ = nod(OANDNOT, $1, $3);
744 }
Rob Pike0cafb9e2008-06-04 14:37:38 -0700745| expr LLSH expr
746 {
747 $$ = nod(OLSH, $1, $3);
748 }
749| expr LRSH expr
750 {
751 $$ = nod(ORSH, $1, $3);
752 }
Rob Pike47919792008-09-16 19:14:33 -0700753| expr LCOMM expr
Ken Thompsonac048ce2008-07-15 21:07:59 -0700754 {
755 $$ = nod(OSEND, $1, $3);
756 }
Rob Pike0cafb9e2008-06-04 14:37:38 -0700757
758uexpr:
759 pexpr
760| '*' uexpr
761 {
762 $$ = nod(OIND, $2, N);
763 }
764| '&' uexpr
765 {
766 $$ = nod(OADDR, $2, N);
767 }
768| '+' uexpr
769 {
770 $$ = nod(OPLUS, $2, N);
771 }
772| '-' uexpr
773 {
774 $$ = nod(OMINUS, $2, N);
775 }
776| '!' uexpr
777 {
778 $$ = nod(ONOT, $2, N);
779 }
780| '~' uexpr
781 {
782 yyerror("the OCOM operator is ^");
783 $$ = nod(OCOM, $2, N);
784 }
785| '^' uexpr
786 {
787 $$ = nod(OCOM, $2, N);
788 }
Rob Pike47919792008-09-16 19:14:33 -0700789| LCOMM uexpr
Rob Pike0cafb9e2008-06-04 14:37:38 -0700790 {
791 $$ = nod(ORECV, $2, N);
792 }
Rob Pike0cafb9e2008-06-04 14:37:38 -0700793
Ken Thompson7a983152009-04-28 17:20:18 -0700794/*
795 * call-like statements that
Russ Coxe52e9ca2009-07-17 01:00:44 -0700796 * can be preceded by 'defer' and 'go'
Ken Thompson7a983152009-04-28 17:20:18 -0700797 */
798pseudocall:
Russ Cox8f4af6d2009-06-06 12:46:38 -0700799 pexpr '(' oexpr_or_type_list ')'
Ken Thompson7a983152009-04-28 17:20:18 -0700800 {
Russ Coxe52e9ca2009-07-17 01:00:44 -0700801 $$ = nod(OCALL, $1, N);
802 $$->list = $3;
Ken Thompson7a983152009-04-28 17:20:18 -0700803 }
804
Rob Pike0cafb9e2008-06-04 14:37:38 -0700805pexpr:
806 LLITERAL
807 {
Russ Cox8f194bf2009-03-12 19:04:38 -0700808 $$ = nodlit($1);
809 }
Russ Cox35e59062009-07-17 14:42:14 -0700810| name
Russ Cox8f4af6d2009-06-06 12:46:38 -0700811| pexpr '.' sym
Russ Cox8f194bf2009-03-12 19:04:38 -0700812 {
Russ Cox8f4af6d2009-06-06 12:46:38 -0700813 if($1->op == OPACK) {
814 Sym *s;
Russ Coxbe16caf2009-07-13 23:38:39 -0700815 s = restrictlookup($3->name, $1->sym->name);
Russ Cox73e52ae2009-09-17 16:42:10 -0700816 $1->used = 1;
Russ Cox8f4af6d2009-06-06 12:46:38 -0700817 $$ = oldname(s);
818 break;
819 }
Russ Cox26097312009-08-05 02:33:30 -0700820 $$ = nod(OXDOT, $1, newname($3));
Rob Pike0cafb9e2008-06-04 14:37:38 -0700821 }
Russ Cox8f4af6d2009-06-06 12:46:38 -0700822| '(' expr_or_type ')'
823 {
824 $$ = $2;
825 }
826| pexpr '.' '(' expr_or_type ')'
Rob Pike0cafb9e2008-06-04 14:37:38 -0700827 {
Russ Coxbe16caf2009-07-13 23:38:39 -0700828 $$ = nod(ODOTTYPE, $1, $4);
Rob Pike0cafb9e2008-06-04 14:37:38 -0700829 }
Ken Thompsona4a10ed2009-03-06 17:50:43 -0800830| pexpr '.' '(' LTYPE ')'
831 {
Russ Cox5d16d232009-09-09 00:18:16 -0700832 $$ = nod(OTYPESW, N, $1);
Ken Thompsona4a10ed2009-03-06 17:50:43 -0800833 }
Rob Pike0cafb9e2008-06-04 14:37:38 -0700834| pexpr '[' expr ']'
835 {
836 $$ = nod(OINDEX, $1, $3);
837 }
838| pexpr '[' keyval ']'
839 {
840 $$ = nod(OSLICE, $1, $3);
841 }
Ken Thompson7a983152009-04-28 17:20:18 -0700842| pseudocall
Russ Cox49cc6492009-03-03 08:41:02 -0800843| convtype '(' expr ')'
Ken Thompson0194aaf2008-09-05 19:50:34 -0700844 {
Russ Cox49cc6492009-03-03 08:41:02 -0800845 // conversion
Russ Coxe52e9ca2009-07-17 01:00:44 -0700846 $$ = nod(OCALL, $1, N);
847 $$->list = list1($3);
Ken Thompson0194aaf2008-09-05 19:50:34 -0700848 }
Russ Coxe52e9ca2009-07-17 01:00:44 -0700849| convtype lbrace braced_keyval_list '}'
Ken Thompson0194aaf2008-09-05 19:50:34 -0700850 {
Russ Cox49cc6492009-03-03 08:41:02 -0800851 // composite expression
Russ Cox9dc22b62009-08-03 11:58:52 -0700852 $$ = nod(OCOMPLIT, N, $1);
Russ Coxe52e9ca2009-07-17 01:00:44 -0700853 $$->list = $3;
Russ Cox8f4af6d2009-06-06 12:46:38 -0700854
855 // If the opening brace was an LBODY,
856 // set up for another one now that we're done.
857 // See comment in lex.c about loophack.
858 if($2 == LBODY)
859 loophack = 1;
860 }
Russ Cox6f169872009-09-29 21:21:14 -0700861| pexpr '{' braced_keyval_list '}'
Russ Cox8f4af6d2009-06-06 12:46:38 -0700862 {
863 // composite expression
Russ Cox9dc22b62009-08-03 11:58:52 -0700864 $$ = nod(OCOMPLIT, N, $1);
Russ Coxe52e9ca2009-07-17 01:00:44 -0700865 $$->list = $3;
Ken Thompson0194aaf2008-09-05 19:50:34 -0700866 }
867| fnliteral
Rob Pike0cafb9e2008-06-04 14:37:38 -0700868
Russ Cox8f4af6d2009-06-06 12:46:38 -0700869expr_or_type:
870 expr
Russ Cox35e59062009-07-17 14:42:14 -0700871| non_expr_type %prec PreferToRightParen
Rob Pike0cafb9e2008-06-04 14:37:38 -0700872
Russ Cox8f4af6d2009-06-06 12:46:38 -0700873name_or_type:
Russ Cox35e59062009-07-17 14:42:14 -0700874 ntype
Russ Cox8f4af6d2009-06-06 12:46:38 -0700875
876lbrace:
877 LBODY
878 {
879 $$ = LBODY;
880 }
881| '{'
882 {
883 $$ = '{';
Rob Pike0cafb9e2008-06-04 14:37:38 -0700884 }
885
886/*
887 * names and types
888 * newname is used before declared
889 * oldname is used after declared
890 */
Rob Pike0cafb9e2008-06-04 14:37:38 -0700891new_name:
Russ Cox8f4af6d2009-06-06 12:46:38 -0700892 sym
Rob Pike0cafb9e2008-06-04 14:37:38 -0700893 {
894 $$ = newname($1);
895 }
896
Russ Coxdb508ccbf2009-07-17 13:38:16 -0700897dcl_name:
898 sym
899 {
900 $$ = dclname($1);
901 }
902
Ken Thompson33ee5272008-08-29 20:30:19 -0700903onew_name:
904 {
905 $$ = N;
906 }
907| new_name
908
Rob Pike0cafb9e2008-06-04 14:37:38 -0700909sym:
Russ Cox8f4af6d2009-06-06 12:46:38 -0700910 LNAME
Ken Thompsone8278bc2008-10-26 14:04:09 -0700911
Rob Pike0cafb9e2008-06-04 14:37:38 -0700912name:
Russ Cox35e59062009-07-17 14:42:14 -0700913 sym
Russ Cox63985b42009-03-05 15:57:03 -0800914 {
915 $$ = oldname($1);
Russ Cox73e52ae2009-09-17 16:42:10 -0700916 if($$->pack != N)
917 $$->pack->used = 1;
Russ Cox63985b42009-03-05 15:57:03 -0800918 }
919
920labelname:
Russ Coxb6487162009-08-07 12:50:26 -0700921 new_name
Rob Pike0cafb9e2008-06-04 14:37:38 -0700922
Ken Thompson0194aaf2008-09-05 19:50:34 -0700923convtype:
Russ Coxbe16caf2009-07-13 23:38:39 -0700924 '[' oexpr ']' ntype
Ken Thompson8200a0b2008-06-08 12:48:37 -0700925 {
Ken Thompson4539ced2008-09-03 14:09:29 -0700926 // array literal
Russ Coxbe16caf2009-07-13 23:38:39 -0700927 $$ = nod(OTARRAY, $2, $4);
Ken Thompson8200a0b2008-06-08 12:48:37 -0700928 }
Russ Coxbe16caf2009-07-13 23:38:39 -0700929| '[' dotdotdot ']' ntype
Ken Thompsonb0f627a2009-01-06 17:31:24 -0800930 {
931 // array literal of nelem
Russ Coxbe16caf2009-07-13 23:38:39 -0700932 $$ = nod(OTARRAY, $2, $4);
Ken Thompsonb0f627a2009-01-06 17:31:24 -0800933 }
Russ Coxbe16caf2009-07-13 23:38:39 -0700934| LMAP '[' ntype ']' ntype
Ken Thompson8200a0b2008-06-08 12:48:37 -0700935 {
Ken Thompson4539ced2008-09-03 14:09:29 -0700936 // map literal
Russ Coxbe16caf2009-07-13 23:38:39 -0700937 $$ = nod(OTMAP, $3, $5);
Ken Thompson8200a0b2008-06-08 12:48:37 -0700938 }
Ken Thompson0194aaf2008-09-05 19:50:34 -0700939| structtype
Ken Thompson8200a0b2008-06-08 12:48:37 -0700940
Russ Coxd364d282008-10-07 12:36:30 -0700941/*
942 * to avoid parsing conflicts, type is split into
Russ Coxd364d282008-10-07 12:36:30 -0700943 * channel types
944 * function types
Russ Cox8abcdee2009-06-06 19:27:48 -0700945 * parenthesized types
Russ Coxd364d282008-10-07 12:36:30 -0700946 * any other type
Russ Coxd364d282008-10-07 12:36:30 -0700947 * the type system makes additional restrictions,
948 * but those are not implemented in the grammar.
949 */
Ken Thompsonc21d9a12008-10-29 12:46:44 -0700950dotdotdot:
951 LDDD
952 {
Russ Coxbe16caf2009-07-13 23:38:39 -0700953 $$ = typenod(typ(TDDD));
Ken Thompsonc21d9a12008-10-29 12:46:44 -0700954 }
Russ Coxd364d282008-10-07 12:36:30 -0700955
Russ Coxbe16caf2009-07-13 23:38:39 -0700956ntype:
Russ Cox8abcdee2009-06-06 19:27:48 -0700957 chantype
Russ Coxdb508ccbf2009-07-17 13:38:16 -0700958| fntype
Russ Cox8abcdee2009-06-06 19:27:48 -0700959| othertype
Russ Cox35e59062009-07-17 14:42:14 -0700960| ptrtype
961| dotname
Russ Coxbe16caf2009-07-13 23:38:39 -0700962| '(' ntype ')'
Russ Coxebc10db2009-02-18 10:07:46 -0800963 {
964 $$ = $2;
965 }
Russ Coxd364d282008-10-07 12:36:30 -0700966
Russ Cox35e59062009-07-17 14:42:14 -0700967non_expr_type:
968 chantype
969| fntype
970| othertype
971| '*' non_expr_type
972 {
973 $$ = nod(OIND, $2, N);
974 }
975| '(' non_expr_type ')'
976 {
977 $$ = $2;
978 }
979
Russ Cox8abcdee2009-06-06 19:27:48 -0700980non_chan_type:
Russ Coxdb508ccbf2009-07-17 13:38:16 -0700981 fntype
Russ Cox8abcdee2009-06-06 19:27:48 -0700982| othertype
Russ Cox35e59062009-07-17 14:42:14 -0700983| ptrtype
984| dotname
Russ Coxbe16caf2009-07-13 23:38:39 -0700985| '(' ntype ')'
Russ Cox4d571c92008-09-30 12:53:11 -0700986 {
Russ Cox8abcdee2009-06-06 19:27:48 -0700987 $$ = $2;
Russ Cox4d571c92008-09-30 12:53:11 -0700988 }
Russ Cox4d571c92008-09-30 12:53:11 -0700989
Russ Cox8abcdee2009-06-06 19:27:48 -0700990non_fn_type:
991 chantype
992| othertype
Russ Cox35e59062009-07-17 14:42:14 -0700993| ptrtype
994| dotname
Russ Cox8abcdee2009-06-06 19:27:48 -0700995
Russ Cox8f4af6d2009-06-06 12:46:38 -0700996dotname:
Russ Cox35e59062009-07-17 14:42:14 -0700997 name
Russ Cox8f4af6d2009-06-06 12:46:38 -0700998| name '.' sym
999 {
1000 if($1->op == OPACK) {
1001 Sym *s;
Russ Coxbe16caf2009-07-13 23:38:39 -07001002 s = restrictlookup($3->name, $1->sym->name);
Russ Cox73e52ae2009-09-17 16:42:10 -07001003 $1->used = 1;
Russ Cox8f4af6d2009-06-06 12:46:38 -07001004 $$ = oldname(s);
1005 break;
1006 }
Russ Cox26097312009-08-05 02:33:30 -07001007 $$ = nod(OXDOT, $1, newname($3));
Russ Cox8f4af6d2009-06-06 12:46:38 -07001008 }
Russ Coxd364d282008-10-07 12:36:30 -07001009
Russ Cox8abcdee2009-06-06 19:27:48 -07001010othertype:
Russ Cox35e59062009-07-17 14:42:14 -07001011 '[' oexpr ']' ntype
Russ Coxd364d282008-10-07 12:36:30 -07001012 {
Russ Cox35e59062009-07-17 14:42:14 -07001013 $$ = nod(OTARRAY, $2, $4);
Russ Coxd364d282008-10-07 12:36:30 -07001014 }
Russ Cox6f169872009-09-29 21:21:14 -07001015| '[' dotdotdot ']' ntype
1016 {
1017 // array literal of nelem
1018 $$ = nod(OTARRAY, $2, $4);
1019 }
Russ Coxbe16caf2009-07-13 23:38:39 -07001020| LCOMM LCHAN ntype
Russ Coxd364d282008-10-07 12:36:30 -07001021 {
Russ Coxbe16caf2009-07-13 23:38:39 -07001022 $$ = nod(OTCHAN, $3, N);
1023 $$->etype = Crecv;
Russ Coxd364d282008-10-07 12:36:30 -07001024 }
Russ Cox8abcdee2009-06-06 19:27:48 -07001025| LCHAN LCOMM non_chan_type
Russ Coxd364d282008-10-07 12:36:30 -07001026 {
Russ Coxbe16caf2009-07-13 23:38:39 -07001027 $$ = nod(OTCHAN, $3, N);
1028 $$->etype = Csend;
Russ Coxd364d282008-10-07 12:36:30 -07001029 }
Russ Coxbe16caf2009-07-13 23:38:39 -07001030| LMAP '[' ntype ']' ntype
Russ Coxd364d282008-10-07 12:36:30 -07001031 {
Russ Coxbe16caf2009-07-13 23:38:39 -07001032 $$ = nod(OTMAP, $3, $5);
Russ Coxd364d282008-10-07 12:36:30 -07001033 }
Russ Cox35e59062009-07-17 14:42:14 -07001034| structtype
1035| interfacetype
1036
1037ptrtype:
1038 '*' ntype
Russ Coxd364d282008-10-07 12:36:30 -07001039 {
Russ Coxbe16caf2009-07-13 23:38:39 -07001040 $$ = nod(OIND, $2, N);
Russ Coxd364d282008-10-07 12:36:30 -07001041 }
Rob Pike0cafb9e2008-06-04 14:37:38 -07001042
Russ Cox8abcdee2009-06-06 19:27:48 -07001043chantype:
Russ Coxbe16caf2009-07-13 23:38:39 -07001044 LCHAN ntype
Russ Coxd364d282008-10-07 12:36:30 -07001045 {
Russ Coxbe16caf2009-07-13 23:38:39 -07001046 $$ = nod(OTCHAN, $2, N);
1047 $$->etype = Cboth;
Russ Coxd364d282008-10-07 12:36:30 -07001048 }
Ken Thompson0194aaf2008-09-05 19:50:34 -07001049
1050structtype:
Russ Coxe52e9ca2009-07-17 01:00:44 -07001051 LSTRUCT '{' structdcl_list osemi '}'
Ken Thompson0194aaf2008-09-05 19:50:34 -07001052 {
Russ Coxe52e9ca2009-07-17 01:00:44 -07001053 $$ = nod(OTSTRUCT, N, N);
1054 $$->list = $3;
Russ Cox8abcdee2009-06-06 19:27:48 -07001055 // Distinguish closing brace in struct from
1056 // other closing braces by explicitly marking it.
1057 // Used above (yylast == LSEMIBRACE).
1058 yylast = LSEMIBRACE;
Ken Thompson0194aaf2008-09-05 19:50:34 -07001059 }
1060| LSTRUCT '{' '}'
1061 {
Russ Coxbe16caf2009-07-13 23:38:39 -07001062 $$ = nod(OTSTRUCT, N, N);
Russ Cox8abcdee2009-06-06 19:27:48 -07001063 yylast = LSEMIBRACE;
Ken Thompson0194aaf2008-09-05 19:50:34 -07001064 }
1065
1066interfacetype:
Russ Coxe52e9ca2009-07-17 01:00:44 -07001067 LINTERFACE '{' interfacedcl_list osemi '}'
Ken Thompson0194aaf2008-09-05 19:50:34 -07001068 {
Russ Coxe52e9ca2009-07-17 01:00:44 -07001069 $$ = nod(OTINTER, N, N);
1070 $$->list = $3;
Russ Cox8abcdee2009-06-06 19:27:48 -07001071 yylast = LSEMIBRACE;
Ken Thompson0194aaf2008-09-05 19:50:34 -07001072 }
1073| LINTERFACE '{' '}'
1074 {
Russ Coxbe16caf2009-07-13 23:38:39 -07001075 $$ = nod(OTINTER, N, N);
Russ Cox8abcdee2009-06-06 19:27:48 -07001076 yylast = LSEMIBRACE;
Ken Thompson0194aaf2008-09-05 19:50:34 -07001077 }
1078
Rob Pike0cafb9e2008-06-04 14:37:38 -07001079keyval:
1080 expr ':' expr
1081 {
Ken Thompson182f91f2008-09-03 14:40:22 -07001082 $$ = nod(OKEY, $1, $3);
Rob Pike0cafb9e2008-06-04 14:37:38 -07001083 }
Russ Coxc2fa45b2009-05-21 16:31:10 -07001084
Rob Pike0cafb9e2008-06-04 14:37:38 -07001085
1086/*
1087 * function stuff
1088 * all in one place to show how crappy it all is
1089 */
1090xfndcl:
Russ Coxb6487162009-08-07 12:50:26 -07001091 LFUNC fndcl fnbody
Rob Pike0cafb9e2008-06-04 14:37:38 -07001092 {
Russ Coxb6487162009-08-07 12:50:26 -07001093 $$ = $2;
1094 $$->nbody = $3;
Rob Pike0cafb9e2008-06-04 14:37:38 -07001095 funcbody($$);
1096 }
1097
1098fndcl:
Russ Coxdb508ccbf2009-07-17 13:38:16 -07001099 dcl_name '(' oarg_type_list ')' fnres
Rob Pike0cafb9e2008-06-04 14:37:38 -07001100 {
Russ Cox35e59062009-07-17 14:42:14 -07001101 Node *n;
1102
Rob Pike0cafb9e2008-06-04 14:37:38 -07001103 $$ = nod(ODCLFUNC, N, N);
1104 $$->nname = $1;
Russ Coxe52e9ca2009-07-17 01:00:44 -07001105 if($3 == nil && $5 == nil)
Ken Thompsonf24f8ff2008-07-19 18:39:12 -07001106 $$->nname = renameinit($1);
Russ Cox35e59062009-07-17 14:42:14 -07001107 n = nod(OTFUNC, N, N);
1108 n->list = $3;
1109 n->rlist = $5;
Russ Coxb6487162009-08-07 12:50:26 -07001110 // TODO: check if nname already has an ntype
1111 $$->nname->ntype = n;
Rob Pike0cafb9e2008-06-04 14:37:38 -07001112 funchdr($$);
1113 }
1114| '(' oarg_type_list ')' new_name '(' oarg_type_list ')' fnres
1115 {
Russ Coxb6487162009-08-07 12:50:26 -07001116 Node *rcvr, *t;
Russ Coxe52e9ca2009-07-17 01:00:44 -07001117
1118 rcvr = $2->n;
1119 if($2->next != nil || $2->n->op != ODCLFIELD) {
1120 yyerror("bad receiver in method");
1121 rcvr = N;
1122 }
1123
Rob Pike0cafb9e2008-06-04 14:37:38 -07001124 $$ = nod(ODCLFUNC, N, N);
Russ Coxb6487162009-08-07 12:50:26 -07001125 $$->nname = methodname1($4, rcvr->right);
1126 t = nod(OTFUNC, rcvr, N);
1127 t->list = $6;
1128 t->rlist = $8;
1129 $$->nname->ntype = t;
1130 $$->shortname = $4;
Russ Coxe52e9ca2009-07-17 01:00:44 -07001131 funchdr($$);
Rob Pike0cafb9e2008-06-04 14:37:38 -07001132 }
1133
Rob Pike0cafb9e2008-06-04 14:37:38 -07001134fntype:
Russ Cox8abcdee2009-06-06 19:27:48 -07001135 LFUNC '(' oarg_type_list ')' fnres
Ken Thompson0194aaf2008-09-05 19:50:34 -07001136 {
Russ Coxdb508ccbf2009-07-17 13:38:16 -07001137 $$ = nod(OTFUNC, N, N);
1138 $$->list = $3;
1139 $$->rlist = $5;
Rob Pike0cafb9e2008-06-04 14:37:38 -07001140 }
1141
Rob Pike0cafb9e2008-06-04 14:37:38 -07001142fnbody:
Russ Coxe52e9ca2009-07-17 01:00:44 -07001143 {
1144 $$ = nil;
1145 }
1146| '{' stmt_list '}'
Rob Pike0cafb9e2008-06-04 14:37:38 -07001147 {
Ken Thompson417a9712008-07-05 12:49:25 -07001148 $$ = $2;
Russ Coxe52e9ca2009-07-17 01:00:44 -07001149 if($$ == nil)
Russ Cox0b2683d2009-07-27 14:36:32 -07001150 $$ = list1(nod(OEMPTY, N, N));
Russ Cox8abcdee2009-06-06 19:27:48 -07001151 yyoptsemi(0);
Rob Pike0cafb9e2008-06-04 14:37:38 -07001152 }
Ken Thompson417a9712008-07-05 12:49:25 -07001153
Rob Pike0cafb9e2008-06-04 14:37:38 -07001154fnres:
Russ Cox63985b42009-03-05 15:57:03 -08001155 %prec NotParen
Russ Coxd364d282008-10-07 12:36:30 -07001156 {
Russ Coxe52e9ca2009-07-17 01:00:44 -07001157 $$ = nil;
Russ Coxd364d282008-10-07 12:36:30 -07001158 }
Russ Cox8abcdee2009-06-06 19:27:48 -07001159| non_fn_type
Rob Pike0cafb9e2008-06-04 14:37:38 -07001160 {
Russ Coxe52e9ca2009-07-17 01:00:44 -07001161 $$ = list1(nod(ODCLFIELD, N, $1));
Rob Pike0cafb9e2008-06-04 14:37:38 -07001162 }
1163| '(' oarg_type_list ')'
1164 {
1165 $$ = $2;
1166 }
1167
Russ Coxb6487162009-08-07 12:50:26 -07001168fnlitdcl:
1169 fntype
1170 {
1171 closurehdr($1);
1172 }
1173
1174fnliteral:
1175 fnlitdcl '{' stmt_list '}'
1176 {
1177 $$ = closurebody($3);
1178 }
1179
1180
Rob Pike0cafb9e2008-06-04 14:37:38 -07001181/*
1182 * lists of things
1183 * note that they are left recursive
1184 * to conserve yacc stack. they need to
1185 * be reversed to interpret correctly
1186 */
Russ Coxe52e9ca2009-07-17 01:00:44 -07001187xdcl_list:
Rob Pike0cafb9e2008-06-04 14:37:38 -07001188 {
Russ Coxe52e9ca2009-07-17 01:00:44 -07001189 $$ = nil;
1190 }
1191| xdcl_list xdcl
1192 {
1193 $$ = concat($1, $2);
Russ Cox23724082009-10-12 11:03:48 -07001194 if(nsyntaxerrors == 0)
1195 testdclstack();
Rob Pike0cafb9e2008-06-04 14:37:38 -07001196 }
1197
Russ Coxe52e9ca2009-07-17 01:00:44 -07001198vardcl_list:
Rob Pike0cafb9e2008-06-04 14:37:38 -07001199 vardcl
Russ Coxe52e9ca2009-07-17 01:00:44 -07001200| vardcl_list ';' vardcl
Rob Pike0cafb9e2008-06-04 14:37:38 -07001201 {
Russ Coxe52e9ca2009-07-17 01:00:44 -07001202 $$ = concat($1, $3);
Rob Pike0cafb9e2008-06-04 14:37:38 -07001203 }
1204
Russ Coxe52e9ca2009-07-17 01:00:44 -07001205constdcl_list:
Ken Thompson9dbaab52008-09-04 12:21:10 -07001206 constdcl1
Russ Coxe52e9ca2009-07-17 01:00:44 -07001207| constdcl_list ';' constdcl1
Russ Coxdb508ccbf2009-07-17 13:38:16 -07001208 {
1209 $$ = concat($1, $3);
1210 }
Rob Pike0cafb9e2008-06-04 14:37:38 -07001211
Russ Coxe52e9ca2009-07-17 01:00:44 -07001212typedcl_list:
Rob Pike0cafb9e2008-06-04 14:37:38 -07001213 typedcl
Russ Coxdb508ccbf2009-07-17 13:38:16 -07001214 {
1215 $$ = list1($1);
1216 }
Russ Coxe52e9ca2009-07-17 01:00:44 -07001217| typedcl_list ';' typedcl
Russ Coxdb508ccbf2009-07-17 13:38:16 -07001218 {
1219 $$ = list($1, $3);
1220 }
Rob Pike0cafb9e2008-06-04 14:37:38 -07001221
Russ Coxe52e9ca2009-07-17 01:00:44 -07001222structdcl_list:
Rob Pike0cafb9e2008-06-04 14:37:38 -07001223 structdcl
Russ Coxe52e9ca2009-07-17 01:00:44 -07001224| structdcl_list ';' structdcl
Rob Pike0cafb9e2008-06-04 14:37:38 -07001225 {
Russ Coxe52e9ca2009-07-17 01:00:44 -07001226 $$ = concat($1, $3);
Rob Pike0cafb9e2008-06-04 14:37:38 -07001227 }
1228
Russ Coxe52e9ca2009-07-17 01:00:44 -07001229interfacedcl_list:
Rob Pike0cafb9e2008-06-04 14:37:38 -07001230 interfacedcl
Russ Cox7743ffe2009-09-28 14:05:34 -07001231 {
1232 $$ = list1($1);
1233 }
Russ Coxe52e9ca2009-07-17 01:00:44 -07001234| interfacedcl_list ';' interfacedcl
Rob Pike0cafb9e2008-06-04 14:37:38 -07001235 {
Russ Cox7743ffe2009-09-28 14:05:34 -07001236 $$ = list($1, $3);
Rob Pike0cafb9e2008-06-04 14:37:38 -07001237 }
1238
1239structdcl:
Russ Coxdb508ccbf2009-07-17 13:38:16 -07001240 new_name_list ntype oliteral
Rob Pike0cafb9e2008-06-04 14:37:38 -07001241 {
Russ Coxe52e9ca2009-07-17 01:00:44 -07001242 NodeList *l;
1243
1244 for(l=$1; l; l=l->next) {
1245 l->n = nod(ODCLFIELD, l->n, $2);
1246 l->n->val = $3;
1247 }
Rob Pike0cafb9e2008-06-04 14:37:38 -07001248 }
Russ Coxf2b153632008-10-30 15:29:55 -07001249| embed oliteral
1250 {
Russ Coxe52e9ca2009-07-17 01:00:44 -07001251 $1->val = $2;
1252 $$ = list1($1);
Russ Coxf2b153632008-10-30 15:29:55 -07001253 }
1254| '*' embed oliteral
Ken Thompson9f3d6002008-09-26 21:27:26 -07001255 {
Russ Coxe52e9ca2009-07-17 01:00:44 -07001256 $2->right = nod(OIND, $2->right, N);
1257 $2->val = $3;
1258 $$ = list1($2);
Ken Thompson0347e952008-10-21 15:04:10 -07001259 }
1260
Russ Cox8f4af6d2009-06-06 12:46:38 -07001261packname:
1262 LNAME
Russ Cox73e52ae2009-09-17 16:42:10 -07001263 {
1264 Node *n;
1265
1266 $$ = $1;
1267 n = oldname($1);
1268 if(n->pack != N)
1269 n->pack->used = 1;
1270 }
Russ Cox8f4af6d2009-06-06 12:46:38 -07001271| LNAME '.' sym
1272 {
1273 char *pkg;
1274
1275 if($1->def == N || $1->def->op != OPACK) {
1276 yyerror("%S is not a package", $1);
1277 pkg = $1->name;
Russ Cox73e52ae2009-09-17 16:42:10 -07001278 } else {
1279 $1->def->used = 1;
Russ Cox8f4af6d2009-06-06 12:46:38 -07001280 pkg = $1->def->sym->name;
Russ Cox73e52ae2009-09-17 16:42:10 -07001281 }
Russ Coxbe16caf2009-07-13 23:38:39 -07001282 $$ = restrictlookup($3->name, pkg);
Russ Cox8f4af6d2009-06-06 12:46:38 -07001283 }
1284
Ken Thompson14c63912008-10-21 20:55:40 -07001285embed:
Russ Cox8f4af6d2009-06-06 12:46:38 -07001286 packname
Ken Thompson0347e952008-10-21 15:04:10 -07001287 {
Ken Thompson14c63912008-10-21 20:55:40 -07001288 $$ = embedded($1);
Ken Thompson61361af2008-10-19 20:13:37 -07001289 }
Rob Pike0cafb9e2008-06-04 14:37:38 -07001290
Russ Coxb4af09a2009-02-16 16:36:18 -08001291interfacedcl:
Russ Cox7743ffe2009-09-28 14:05:34 -07001292 new_name indcl
Russ Coxe52e9ca2009-07-17 01:00:44 -07001293 {
Russ Cox7743ffe2009-09-28 14:05:34 -07001294 $$ = nod(ODCLFIELD, $1, $2);
Russ Coxe52e9ca2009-07-17 01:00:44 -07001295 }
Russ Cox8f4af6d2009-06-06 12:46:38 -07001296| packname
Russ Coxb4af09a2009-02-16 16:36:18 -08001297 {
Russ Cox7743ffe2009-09-28 14:05:34 -07001298 $$ = nod(ODCLFIELD, N, oldname($1));
Russ Coxb4af09a2009-02-16 16:36:18 -08001299 }
1300
Ken Thompson0194aaf2008-09-05 19:50:34 -07001301indcl:
Rob Pike0cafb9e2008-06-04 14:37:38 -07001302 '(' oarg_type_list ')' fnres
1303 {
1304 // without func keyword
Russ Cox35e59062009-07-17 14:42:14 -07001305 $$ = nod(OTFUNC, fakethis(), N);
1306 $$->list = $2;
1307 $$->rlist = $4;
Rob Pike0cafb9e2008-06-04 14:37:38 -07001308 }
Rob Pike0cafb9e2008-06-04 14:37:38 -07001309
Russ Cox4d571c92008-09-30 12:53:11 -07001310/*
1311 * function arguments.
Russ Cox4d571c92008-09-30 12:53:11 -07001312 */
Russ Cox8f4af6d2009-06-06 12:46:38 -07001313arg_type:
1314 name_or_type
1315| sym name_or_type
Rob Pike0cafb9e2008-06-04 14:37:38 -07001316 {
Russ Cox5d16d232009-09-09 00:18:16 -07001317 $$ = nod(ONONAME, N, N);
1318 $$->sym = $1;
Russ Cox8f4af6d2009-06-06 12:46:38 -07001319 $$ = nod(OKEY, $$, $2);
Rob Pike0cafb9e2008-06-04 14:37:38 -07001320 }
Russ Cox8f4af6d2009-06-06 12:46:38 -07001321| sym dotdotdot
Ken Thompsonc21d9a12008-10-29 12:46:44 -07001322 {
Russ Cox5d16d232009-09-09 00:18:16 -07001323 $$ = nod(ONONAME, N, N);
1324 $$->sym = $1;
Russ Coxbe16caf2009-07-13 23:38:39 -07001325 $$ = nod(OKEY, $$, $2);
Ken Thompsonc21d9a12008-10-29 12:46:44 -07001326 }
Russ Cox8f4af6d2009-06-06 12:46:38 -07001327| dotdotdot
Rob Pike0cafb9e2008-06-04 14:37:38 -07001328
Russ Coxe52e9ca2009-07-17 01:00:44 -07001329arg_type_list:
Russ Cox8f4af6d2009-06-06 12:46:38 -07001330 arg_type
Russ Cox4d571c92008-09-30 12:53:11 -07001331 {
Russ Coxe52e9ca2009-07-17 01:00:44 -07001332 $$ = list1($1);
1333 }
1334| arg_type_list ',' arg_type
1335 {
1336 $$ = list($1, $3);
Russ Cox4d571c92008-09-30 12:53:11 -07001337 }
1338
Russ Coxe52e9ca2009-07-17 01:00:44 -07001339oarg_type_list:
Russ Cox4d571c92008-09-30 12:53:11 -07001340 {
Russ Coxe52e9ca2009-07-17 01:00:44 -07001341 $$ = nil;
1342 }
1343| arg_type_list
1344 {
1345 $$ = checkarglist($1);
Rob Pike0cafb9e2008-06-04 14:37:38 -07001346 }
1347
Ken Thompson36bfd2a2008-06-08 16:11:14 -07001348/*
Russ Cox8abcdee2009-06-06 19:27:48 -07001349 * statement
Ken Thompson36bfd2a2008-06-08 16:11:14 -07001350 */
Russ Cox8abcdee2009-06-06 19:27:48 -07001351stmt:
Ken Thompson610644a2008-06-08 17:21:46 -07001352 {
1353 $$ = N;
1354 }
Russ Coxd364d282008-10-07 12:36:30 -07001355| simple_stmt
Russ Cox8abcdee2009-06-06 19:27:48 -07001356| compound_stmt
1357| common_dcl
Russ Coxe52e9ca2009-07-17 01:00:44 -07001358 {
1359 $$ = liststmt($1);
1360 }
Russ Cox8abcdee2009-06-06 19:27:48 -07001361| for_stmt
1362| switch_stmt
1363| select_stmt
1364| if_stmt
Rob Pike0cafb9e2008-06-04 14:37:38 -07001365 {
Russ Cox8abcdee2009-06-06 19:27:48 -07001366 popdcl();
1367 $$ = $1;
Rob Pike0cafb9e2008-06-04 14:37:38 -07001368 }
Russ Cox8abcdee2009-06-06 19:27:48 -07001369| if_stmt LELSE stmt
Ken Thompson8200a0b2008-06-08 12:48:37 -07001370 {
Russ Cox8abcdee2009-06-06 19:27:48 -07001371 popdcl();
1372 $$ = $1;
Russ Coxe52e9ca2009-07-17 01:00:44 -07001373 $$->nelse = list1($3);
Russ Cox8abcdee2009-06-06 19:27:48 -07001374 }
1375| error
1376 {
1377 $$ = N;
1378 }
1379| labelname ':' stmt
1380 {
Russ Coxe52e9ca2009-07-17 01:00:44 -07001381 NodeList *l;
1382
1383 l = list1(nod(OLABEL, $1, N));
1384 if($3)
1385 l = list(l, $3);
1386 $$ = liststmt(l);
Russ Cox8abcdee2009-06-06 19:27:48 -07001387 }
1388| LFALL
1389 {
1390 // will be converted to OFALL
1391 $$ = nod(OXFALL, N, N);
1392 }
1393| LBREAK onew_name
1394 {
1395 $$ = nod(OBREAK, $2, N);
1396 }
1397| LCONTINUE onew_name
1398 {
1399 $$ = nod(OCONTINUE, $2, N);
1400 }
1401| LGO pseudocall
1402 {
1403 $$ = nod(OPROC, $2, N);
1404 }
1405| LDEFER pseudocall
1406 {
1407 $$ = nod(ODEFER, $2, N);
1408 }
1409| LGOTO new_name
1410 {
1411 $$ = nod(OGOTO, $2, N);
1412 }
1413| LRETURN oexpr_list
1414 {
Russ Coxe52e9ca2009-07-17 01:00:44 -07001415 $$ = nod(ORETURN, N, N);
1416 $$->list = $2;
Ken Thompson8200a0b2008-06-08 12:48:37 -07001417 }
Ken Thompson8200a0b2008-06-08 12:48:37 -07001418
Russ Coxe52e9ca2009-07-17 01:00:44 -07001419stmt_list:
Russ Cox8abcdee2009-06-06 19:27:48 -07001420 stmt
Russ Coxe52e9ca2009-07-17 01:00:44 -07001421 {
1422 $$ = nil;
1423 if($1 != N)
1424 $$ = list1($1);
1425 }
1426| stmt_list ';' stmt
1427 {
1428 $$ = $1;
1429 if($3 != N)
1430 $$ = list($$, $3);
1431 }
1432
Russ Coxdb508ccbf2009-07-17 13:38:16 -07001433new_name_list:
1434 new_name
Russ Coxe52e9ca2009-07-17 01:00:44 -07001435 {
Russ Coxdb508ccbf2009-07-17 13:38:16 -07001436 $$ = list1($1);
Russ Coxe52e9ca2009-07-17 01:00:44 -07001437 }
Russ Coxdb508ccbf2009-07-17 13:38:16 -07001438| new_name_list ',' new_name
Russ Coxe52e9ca2009-07-17 01:00:44 -07001439 {
Russ Coxdb508ccbf2009-07-17 13:38:16 -07001440 $$ = list($1, $3);
1441 }
1442
1443dcl_name_list:
1444 dcl_name
1445 {
1446 $$ = list1($1);
1447 }
1448| dcl_name_list ',' dcl_name
1449 {
1450 $$ = list($1, $3);
Russ Coxe52e9ca2009-07-17 01:00:44 -07001451 }
1452
1453expr_list:
1454 expr
1455 {
1456 $$ = list1($1);
1457 }
1458| expr_list ',' expr
Russ Cox8abcdee2009-06-06 19:27:48 -07001459 {
1460 $$ = list($1, $3);
1461 }
Rob Pike0cafb9e2008-06-04 14:37:38 -07001462
Russ Coxe52e9ca2009-07-17 01:00:44 -07001463expr_or_type_list:
Russ Cox8f4af6d2009-06-06 12:46:38 -07001464 expr_or_type
Ken Thompsone8278bc2008-10-26 14:04:09 -07001465 {
Russ Coxe52e9ca2009-07-17 01:00:44 -07001466 $$ = list1($1);
Ken Thompsone8278bc2008-10-26 14:04:09 -07001467 }
Russ Coxe52e9ca2009-07-17 01:00:44 -07001468| expr_or_type_list ',' expr_or_type
Rob Pike0cafb9e2008-06-04 14:37:38 -07001469 {
Russ Coxe52e9ca2009-07-17 01:00:44 -07001470 $$ = list($1, $3);
Rob Pike0cafb9e2008-06-04 14:37:38 -07001471 }
1472
Ken Thompsona0160812009-05-21 13:46:07 -07001473/*
1474 * list of combo of keyval and val
1475 */
Russ Coxe52e9ca2009-07-17 01:00:44 -07001476keyval_list:
Rob Pike0cafb9e2008-06-04 14:37:38 -07001477 keyval
Russ Coxe52e9ca2009-07-17 01:00:44 -07001478 {
1479 $$ = list1($1);
1480 }
Ken Thompsona0160812009-05-21 13:46:07 -07001481| expr
Rob Pike0cafb9e2008-06-04 14:37:38 -07001482 {
Russ Coxe52e9ca2009-07-17 01:00:44 -07001483 $$ = list1($1);
Rob Pike0cafb9e2008-06-04 14:37:38 -07001484 }
Russ Coxe52e9ca2009-07-17 01:00:44 -07001485| keyval_list ',' keyval
Ken Thompsona0160812009-05-21 13:46:07 -07001486 {
Russ Coxe52e9ca2009-07-17 01:00:44 -07001487 $$ = list($1, $3);
1488 }
1489| keyval_list ',' expr
1490 {
1491 $$ = list($1, $3);
Ken Thompsona0160812009-05-21 13:46:07 -07001492 }
Rob Pike0cafb9e2008-06-04 14:37:38 -07001493
Russ Coxe52e9ca2009-07-17 01:00:44 -07001494braced_keyval_list:
Russ Cox82e41cc2008-10-14 17:10:39 -07001495 {
Russ Coxe52e9ca2009-07-17 01:00:44 -07001496 $$ = nil;
Russ Cox82e41cc2008-10-14 17:10:39 -07001497 }
Russ Coxe52e9ca2009-07-17 01:00:44 -07001498| keyval_list ocomma
Russ Cox82e41cc2008-10-14 17:10:39 -07001499 {
Russ Coxe52e9ca2009-07-17 01:00:44 -07001500 $$ = $1;
Russ Cox82e41cc2008-10-14 17:10:39 -07001501 }
Russ Cox82e41cc2008-10-14 17:10:39 -07001502
Rob Pike0cafb9e2008-06-04 14:37:38 -07001503/*
1504 * optional things
1505 */
1506osemi:
Russ Coxaaaa1fc2009-09-15 17:29:08 -07001507 %prec NotSemi
Rob Pike0cafb9e2008-06-04 14:37:38 -07001508| ';'
1509
1510ocomma:
1511| ','
1512
1513oexpr:
1514 {
1515 $$ = N;
1516 }
1517| expr
1518
1519oexpr_list:
1520 {
Russ Coxe52e9ca2009-07-17 01:00:44 -07001521 $$ = nil;
Rob Pike0cafb9e2008-06-04 14:37:38 -07001522 }
1523| expr_list
1524
Russ Cox8f4af6d2009-06-06 12:46:38 -07001525oexpr_or_type_list:
1526 {
Russ Coxe52e9ca2009-07-17 01:00:44 -07001527 $$ = nil;
Russ Cox8f4af6d2009-06-06 12:46:38 -07001528 }
1529| expr_or_type_list
1530
Rob Pike0cafb9e2008-06-04 14:37:38 -07001531osimple_stmt:
1532 {
1533 $$ = N;
1534 }
1535| simple_stmt
1536
Russ Coxb8babed2008-10-03 16:15:55 -07001537ohidden_funarg_list:
1538 {
Russ Coxe52e9ca2009-07-17 01:00:44 -07001539 $$ = nil;
Russ Coxb8babed2008-10-03 16:15:55 -07001540 }
1541| hidden_funarg_list
1542
1543ohidden_structdcl_list:
1544 {
Russ Coxe52e9ca2009-07-17 01:00:44 -07001545 $$ = nil;
Russ Coxb8babed2008-10-03 16:15:55 -07001546 }
1547| hidden_structdcl_list
1548
1549ohidden_interfacedcl_list:
1550 {
Russ Coxe52e9ca2009-07-17 01:00:44 -07001551 $$ = nil;
Russ Coxb8babed2008-10-03 16:15:55 -07001552 }
1553| hidden_interfacedcl_list
1554
Russ Coxf27aaf42008-10-30 15:13:09 -07001555oliteral:
1556 {
1557 $$.ctype = CTxxx;
1558 }
1559| LLITERAL
1560
Rob Pike0cafb9e2008-06-04 14:37:38 -07001561/*
1562 * import syntax from header of
1563 * an output package
1564 */
1565hidden_import:
Russ Cox8f4af6d2009-06-06 12:46:38 -07001566 LPACKAGE sym
Rob Pike0cafb9e2008-06-04 14:37:38 -07001567 /* variables */
Russ Cox4efad582009-01-26 16:57:24 -08001568| LVAR hidden_pkg_importsym hidden_type
Rob Pike0cafb9e2008-06-04 14:37:38 -07001569 {
Russ Cox4a431982009-01-30 14:39:42 -08001570 importvar($2, $3, PEXTERN);
Russ Coxb8babed2008-10-03 16:15:55 -07001571 }
Russ Cox4efad582009-01-26 16:57:24 -08001572| LCONST hidden_pkg_importsym '=' hidden_constant
Russ Coxb8babed2008-10-03 16:15:55 -07001573 {
Russ Cox8f194bf2009-03-12 19:04:38 -07001574 importconst($2, types[TIDEAL], $4);
Russ Coxb8babed2008-10-03 16:15:55 -07001575 }
Russ Cox4efad582009-01-26 16:57:24 -08001576| LCONST hidden_pkg_importsym hidden_type '=' hidden_constant
Russ Coxb8babed2008-10-03 16:15:55 -07001577 {
Russ Cox8f194bf2009-03-12 19:04:38 -07001578 importconst($2, $3, $5);
Russ Coxb8babed2008-10-03 16:15:55 -07001579 }
Russ Coxb6487162009-08-07 12:50:26 -07001580| LTYPE hidden_pkgtype hidden_type
Russ Coxb8babed2008-10-03 16:15:55 -07001581 {
Russ Cox0183baa2009-01-20 14:40:00 -08001582 importtype($2, $3);
Russ Coxb8babed2008-10-03 16:15:55 -07001583 }
Russ Cox4efad582009-01-26 16:57:24 -08001584| LFUNC hidden_pkg_importsym '(' ohidden_funarg_list ')' ohidden_funres
Russ Coxb8babed2008-10-03 16:15:55 -07001585 {
Russ Cox4a431982009-01-30 14:39:42 -08001586 importvar($2, functype(N, $4, $6), PFUNC);
Russ Coxb8babed2008-10-03 16:15:55 -07001587 }
Russ Cox8f4af6d2009-06-06 12:46:38 -07001588| LFUNC '(' hidden_funarg_list ')' sym '(' ohidden_funarg_list ')' ohidden_funres
Russ Coxb8babed2008-10-03 16:15:55 -07001589 {
Russ Coxe52e9ca2009-07-17 01:00:44 -07001590 if($3->next != nil || $3->n->op != ODCLFIELD) {
Russ Coxb8babed2008-10-03 16:15:55 -07001591 yyerror("bad receiver in method");
1592 YYERROR;
1593 }
Russ Coxe52e9ca2009-07-17 01:00:44 -07001594 importmethod($5, functype($3->n, $7, $9));
Rob Pike0cafb9e2008-06-04 14:37:38 -07001595 }
1596
Russ Coxb6487162009-08-07 12:50:26 -07001597hidden_pkgtype:
1598 hidden_pkg_importsym
1599 {
1600 $$ = pkgtype($1);
1601 importsym($1, OTYPE);
1602 }
1603
Russ Coxb8babed2008-10-03 16:15:55 -07001604hidden_type:
1605 hidden_type1
1606| hidden_type2
1607
1608hidden_type1:
1609 hidden_importsym
Rob Pike0cafb9e2008-06-04 14:37:38 -07001610 {
Russ Cox8f4af6d2009-06-06 12:46:38 -07001611 $$ = pkgtype($1);
Rob Pike0cafb9e2008-06-04 14:37:38 -07001612 }
Russ Cox8f4af6d2009-06-06 12:46:38 -07001613| LNAME
Rob Pike0cafb9e2008-06-04 14:37:38 -07001614 {
Russ Coxa1214102009-08-04 22:59:23 -07001615 // predefined name like uint8
Russ Coxe780fa82009-09-09 01:01:39 -07001616 $1 = pkglookup($1->name, "/builtin/");
Russ Coxa1214102009-08-04 22:59:23 -07001617 if($1->def == N || $1->def->op != OTYPE) {
Russ Coxe780fa82009-09-09 01:01:39 -07001618 yyerror("%s is not a type", $1->name);
Russ Coxa1214102009-08-04 22:59:23 -07001619 $$ = T;
1620 } else
1621 $$ = $1->def->type;
Russ Coxb8babed2008-10-03 16:15:55 -07001622 }
1623| '[' ']' hidden_type
1624 {
1625 $$ = aindex(N, $3);
1626 }
1627| '[' LLITERAL ']' hidden_type
1628 {
Russ Cox8f194bf2009-03-12 19:04:38 -07001629 $$ = aindex(nodlit($2), $4);
Russ Coxb8babed2008-10-03 16:15:55 -07001630 }
1631| LMAP '[' hidden_type ']' hidden_type
1632 {
Russ Cox98b34e52009-03-04 17:38:37 -08001633 $$ = maptype($3, $5);
Russ Coxb8babed2008-10-03 16:15:55 -07001634 }
1635| LSTRUCT '{' ohidden_structdcl_list '}'
1636 {
1637 $$ = dostruct($3, TSTRUCT);
1638 }
1639| LINTERFACE '{' ohidden_interfacedcl_list '}'
1640 {
1641 $$ = dostruct($3, TINTER);
1642 $$ = sortinter($$);
1643 }
1644| '*' hidden_type
1645 {
Russ Coxb8babed2008-10-03 16:15:55 -07001646 $$ = ptrto($2);
1647 }
1648| LCOMM LCHAN hidden_type
1649 {
1650 $$ = typ(TCHAN);
1651 $$->type = $3;
1652 $$->chan = Crecv;
1653 }
1654| LCHAN LCOMM hidden_type1
1655 {
1656 $$ = typ(TCHAN);
1657 $$->type = $3;
1658 $$->chan = Csend;
Rob Pike0cafb9e2008-06-04 14:37:38 -07001659 }
Ken Thompson2fef4c72008-11-01 16:52:12 -07001660| LDDD
1661 {
1662 $$ = typ(TDDD);
1663 }
Rob Pike0cafb9e2008-06-04 14:37:38 -07001664
Russ Coxb8babed2008-10-03 16:15:55 -07001665hidden_type2:
1666 LCHAN hidden_type
Rob Pike0cafb9e2008-06-04 14:37:38 -07001667 {
Russ Coxb8babed2008-10-03 16:15:55 -07001668 $$ = typ(TCHAN);
1669 $$->type = $2;
1670 $$->chan = Cboth;
Rob Pike0cafb9e2008-06-04 14:37:38 -07001671 }
Russ Cox4a431982009-01-30 14:39:42 -08001672| LFUNC '(' ohidden_funarg_list ')' ohidden_funres
Rob Pike0cafb9e2008-06-04 14:37:38 -07001673 {
Russ Coxe52e9ca2009-07-17 01:00:44 -07001674 $$ = functype(nil, $3, $5);
Rob Pike0cafb9e2008-06-04 14:37:38 -07001675 }
Russ Coxb8babed2008-10-03 16:15:55 -07001676
1677hidden_dcl:
Russ Cox8f4af6d2009-06-06 12:46:38 -07001678 sym hidden_type
Ken Thompson66a603c2008-08-27 17:28:30 -07001679 {
Russ Coxb6487162009-08-07 12:50:26 -07001680 $$ = nod(ODCLFIELD, newname($1), typenod($2));
Ken Thompson66a603c2008-08-27 17:28:30 -07001681 }
Russ Coxb8babed2008-10-03 16:15:55 -07001682| '?' hidden_type
Rob Pike0cafb9e2008-06-04 14:37:38 -07001683 {
Russ Coxb6487162009-08-07 12:50:26 -07001684 $$ = nod(ODCLFIELD, N, typenod($2));
Rob Pike0cafb9e2008-06-04 14:37:38 -07001685 }
Russ Coxb8babed2008-10-03 16:15:55 -07001686
Russ Cox21617252008-10-22 13:22:56 -07001687hidden_structdcl:
Russ Cox8f4af6d2009-06-06 12:46:38 -07001688 sym hidden_type oliteral
Russ Cox21617252008-10-22 13:22:56 -07001689 {
Russ Coxbe16caf2009-07-13 23:38:39 -07001690 $$ = nod(ODCLFIELD, newname($1), typenod($2));
Russ Cox1850b292008-10-30 15:25:26 -07001691 $$->val = $3;
Russ Cox21617252008-10-22 13:22:56 -07001692 }
Russ Coxf2b153632008-10-30 15:29:55 -07001693| '?' hidden_type oliteral
Russ Cox21617252008-10-22 13:22:56 -07001694 {
Russ Coxe780fa82009-09-09 01:01:39 -07001695 Sym *s;
1696
1697 s = $2->sym;
1698 if(s == S && isptr[$2->etype])
1699 s = $2->type->sym;
1700 if(s && strcmp(s->package, "/builtin/") == 0)
1701 s = lookup(s->name);
1702 $$ = embedded(s);
1703 $$->right = typenod($2);
Russ Coxf2b153632008-10-30 15:29:55 -07001704 $$->val = $3;
Russ Cox21617252008-10-22 13:22:56 -07001705 }
1706
Russ Coxb8babed2008-10-03 16:15:55 -07001707hidden_interfacedcl:
Russ Cox8f4af6d2009-06-06 12:46:38 -07001708 sym '(' ohidden_funarg_list ')' ohidden_funres
Rob Pike0cafb9e2008-06-04 14:37:38 -07001709 {
Russ Coxbe16caf2009-07-13 23:38:39 -07001710 $$ = nod(ODCLFIELD, newname($1), typenod(functype(fakethis(), $3, $5)));
Rob Pike0cafb9e2008-06-04 14:37:38 -07001711 }
Russ Coxb8babed2008-10-03 16:15:55 -07001712
1713ohidden_funres:
Rob Pike0cafb9e2008-06-04 14:37:38 -07001714 {
Russ Coxe52e9ca2009-07-17 01:00:44 -07001715 $$ = nil;
Rob Pike0cafb9e2008-06-04 14:37:38 -07001716 }
Russ Coxb8babed2008-10-03 16:15:55 -07001717| hidden_funres
1718
1719hidden_funres:
1720 '(' ohidden_funarg_list ')'
Rob Pike0cafb9e2008-06-04 14:37:38 -07001721 {
Russ Coxb8babed2008-10-03 16:15:55 -07001722 $$ = $2;
Rob Pike0cafb9e2008-06-04 14:37:38 -07001723 }
Russ Coxb8babed2008-10-03 16:15:55 -07001724| hidden_type1
Rob Pike0cafb9e2008-06-04 14:37:38 -07001725 {
Russ Coxb6487162009-08-07 12:50:26 -07001726 $$ = list1(nod(ODCLFIELD, N, typenod($1)));
Ken Thompson21192942008-09-14 16:57:55 -07001727 }
Rob Pike0cafb9e2008-06-04 14:37:38 -07001728
Russ Coxc3d841f2008-09-26 11:44:20 -07001729hidden_constant:
1730 LLITERAL
Russ Cox8f194bf2009-03-12 19:04:38 -07001731 {
1732 $$ = nodlit($1);
1733 }
Russ Coxc3d841f2008-09-26 11:44:20 -07001734| '-' LLITERAL
1735 {
Russ Cox8f194bf2009-03-12 19:04:38 -07001736 $$ = nodlit($2);
1737 switch($$->val.ctype){
Russ Coxc3d841f2008-09-26 11:44:20 -07001738 case CTINT:
Russ Cox8f194bf2009-03-12 19:04:38 -07001739 mpnegfix($$->val.u.xval);
Russ Coxc3d841f2008-09-26 11:44:20 -07001740 break;
1741 case CTFLT:
Russ Cox8f194bf2009-03-12 19:04:38 -07001742 mpnegflt($$->val.u.fval);
Russ Coxc3d841f2008-09-26 11:44:20 -07001743 break;
1744 default:
1745 yyerror("bad negated constant");
1746 }
1747 }
Russ Coxe780fa82009-09-09 01:01:39 -07001748| sym
Russ Coxdec12d32009-01-16 10:45:28 -08001749 {
Russ Coxe780fa82009-09-09 01:01:39 -07001750 $$ = oldname(pkglookup($1->name, "/builtin/"));
Russ Cox8f4af6d2009-06-06 12:46:38 -07001751 if($$->op != OLITERAL)
1752 yyerror("bad constant %S", $$->sym);
Russ Coxdec12d32009-01-16 10:45:28 -08001753 }
Russ Coxc3d841f2008-09-26 11:44:20 -07001754
Russ Coxb8babed2008-10-03 16:15:55 -07001755hidden_importsym:
Russ Cox8f4af6d2009-06-06 12:46:38 -07001756 sym '.' sym
Rob Pike0cafb9e2008-06-04 14:37:38 -07001757 {
Russ Cox8f4af6d2009-06-06 12:46:38 -07001758 $$ = pkglookup($3->name, $1->name);
Rob Pike0cafb9e2008-06-04 14:37:38 -07001759 }
Russ Cox13f31492008-09-18 13:32:14 -07001760
Russ Cox4efad582009-01-26 16:57:24 -08001761hidden_pkg_importsym:
1762 hidden_importsym
1763 {
1764 $$ = $1;
Russ Cox8f4af6d2009-06-06 12:46:38 -07001765 structpkg = $$->package;
Russ Cox4efad582009-01-26 16:57:24 -08001766 }
1767
Russ Coxe52e9ca2009-07-17 01:00:44 -07001768hidden_import_list:
1769| hidden_import_list hidden_import
Russ Cox4efad582009-01-26 16:57:24 -08001770
Russ Coxe52e9ca2009-07-17 01:00:44 -07001771hidden_funarg_list:
1772 hidden_dcl
1773 {
1774 $$ = list1($1);
1775 }
1776| hidden_funarg_list ',' hidden_dcl
1777 {
1778 $$ = list($1, $3);
1779 }
1780
1781hidden_structdcl_list:
1782 hidden_structdcl
1783 {
1784 $$ = list1($1);
1785 }
1786| hidden_structdcl_list ';' hidden_structdcl
1787 {
1788 $$ = list($1, $3);
1789 }
1790
1791hidden_interfacedcl_list:
1792 hidden_interfacedcl
1793 {
1794 $$ = list1($1);
1795 }
1796| hidden_interfacedcl_list ';' hidden_interfacedcl
1797 {
1798 $$ = list($1, $3);
1799 }