blob: 6e100d1f4199a1da8d338933c84a4767032e4d9c [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
Russ Cox39974952009-12-11 15:59:41 -080011 * 2. semicolons can be omitted before and after the closing ) or }
Russ Cox8f4af6d2009-06-06 12:46:38 -070012 * on a list of statements or declarations.
Russ Cox39974952009-12-11 15:59:41 -080013 * 3. semicolons are inserted by the lexer before a newline
14 * following a specific list of tokens.
Russ Cox8f4af6d2009-06-06 12:46:38 -070015 *
Russ Cox39974952009-12-11 15:59:41 -080016 * Rules #1 and #2 are accomplished by writing the lists as
17 * semicolon-separated lists with an optional trailing semicolon.
18 * Rule #3 is implemented in yylex.
Russ Cox8f4af6d2009-06-06 12:46:38 -070019 */
20
Rob Pike0cafb9e2008-06-04 14:37:38 -070021%{
Russ Cox593ccd12009-11-12 23:38:48 -080022#include <stdio.h> /* if we don't, bison will, and go.h re-#defines getc */
Rob Pike0cafb9e2008-06-04 14:37:38 -070023#include "go.h"
24%}
25%union {
26 Node* node;
Russ Coxe52e9ca2009-07-17 01:00:44 -070027 NodeList* list;
Rob Pike0cafb9e2008-06-04 14:37:38 -070028 Type* type;
29 Sym* sym;
30 struct Val val;
31 int lint;
32}
Ken Thompsona8a9dbc2008-08-11 19:17:28 -070033
Russ Cox8f4af6d2009-06-06 12:46:38 -070034// |sed 's/.* //' |9 fmt -l1 |sort |9 fmt -l50 | sed 's/^/%xxx /'
35
36%token <val> LLITERAL
37%token <lint> LASOP
38%token <sym> LBREAK LCASE LCHAN LCOLAS LCONST LCONTINUE LDDD
39%token <sym> LDEFAULT LDEFER LELSE LFALL LFOR LFUNC LGO LGOTO
40%token <sym> LIF LIMPORT LINTERFACE LMAKE LMAP LNAME LNEW
41%token <sym> LPACKAGE LRANGE LRETURN LSELECT LSTRUCT LSWITCH
42%token <sym> LTYPE LVAR
43
44%token LANDAND LANDNOT LBODY LCOMM LDEC LEQ LGE LGT
45%token LIGNORE LINC LLE LLSH LLT LNE LOROR LRSH
Russ Cox8abcdee2009-06-06 19:27:48 -070046%token LSEMIBRACE
Russ Cox8f4af6d2009-06-06 12:46:38 -070047
Russ Cox38df5ec2009-08-19 15:18:08 -070048%type <lint> lbrace import_here
Russ Cox8f4af6d2009-06-06 12:46:38 -070049%type <sym> sym packname
50%type <val> oliteral
51
Russ Coxbe16caf2009-07-13 23:38:39 -070052%type <node> stmt ntype
Russ Coxe52e9ca2009-07-17 01:00:44 -070053%type <node> arg_type
54%type <node> case caseblock
55%type <node> compound_stmt dotname embed expr
56%type <node> expr_or_type
57%type <node> fndcl fnliteral
Russ Cox8f4af6d2009-06-06 12:46:38 -070058%type <node> for_body for_header for_stmt if_header if_stmt
Russ Cox7743ffe2009-09-28 14:05:34 -070059%type <node> interfacedcl keyval labelname name
Russ Cox35e59062009-07-17 14:42:14 -070060%type <node> name_or_type non_expr_type
Russ Coxb6487162009-08-07 12:50:26 -070061%type <node> new_name dcl_name oexpr typedclname
Russ Coxe52e9ca2009-07-17 01:00:44 -070062%type <node> onew_name
63%type <node> osimple_stmt pexpr
Russ Cox8abcdee2009-06-06 19:27:48 -070064%type <node> pseudocall range_stmt select_stmt
Russ Coxe52e9ca2009-07-17 01:00:44 -070065%type <node> simple_stmt
66%type <node> switch_stmt uexpr
Russ Coxdb508ccbf2009-07-17 13:38:16 -070067%type <node> xfndcl typedcl
Russ Coxe52e9ca2009-07-17 01:00:44 -070068
Russ Coxdb508ccbf2009-07-17 13:38:16 -070069%type <list> xdcl fnbody fnres switch_body loop_body dcl_name_list
70%type <list> new_name_list expr_list keyval_list braced_keyval_list expr_or_type_list xdcl_list
Russ Cox39974952009-12-11 15:59:41 -080071%type <list> oexpr_list oexpr_or_type_list_ocomma caseblock_list stmt_list oarg_type_list_ocomma arg_type_list
Russ Cox7743ffe2009-09-28 14:05:34 -070072%type <list> interfacedcl_list vardcl vardcl_list structdcl structdcl_list
Russ Coxdb508ccbf2009-07-17 13:38:16 -070073%type <list> common_dcl constdcl constdcl1 constdcl_list typedcl_list
Russ Cox8f4af6d2009-06-06 12:46:38 -070074
Russ Cox6f169872009-09-29 21:21:14 -070075%type <node> convtype dotdotdot
Russ Cox35e59062009-07-17 14:42:14 -070076%type <node> indcl interfacetype structtype ptrtype
Russ Coxb6487162009-08-07 12:50:26 -070077%type <node> chantype non_chan_type othertype non_fn_type fntype
Russ Cox8f4af6d2009-06-06 12:46:38 -070078
79%type <sym> hidden_importsym hidden_pkg_importsym
80
Russ Coxe52e9ca2009-07-17 01:00:44 -070081%type <node> hidden_constant hidden_dcl hidden_interfacedcl hidden_structdcl
82
83%type <list> hidden_funres
84%type <list> ohidden_funres
85%type <list> hidden_funarg_list ohidden_funarg_list
86%type <list> hidden_interfacedcl_list ohidden_interfacedcl_list
87%type <list> hidden_structdcl_list ohidden_structdcl_list
Russ Cox8f4af6d2009-06-06 12:46:38 -070088
Russ Coxe7337662009-12-03 00:10:32 -080089%type <type> hidden_type hidden_type_misc hidden_pkgtype
90%type <type> hidden_type_func hidden_type_non_func
91%type <type> hidden_type_chan hidden_type_non_chan
Russ Cox8f4af6d2009-06-06 12:46:38 -070092
93%left LOROR
94%left LANDAND
95%left LCOMM
96%left LEQ LNE LLE LGE LLT LGT
97%left '+' '-' '|' '^'
98%left '*' '/' '%' '&' LLSH LRSH LANDNOT
Rob Pike0cafb9e2008-06-04 14:37:38 -070099
Russ Coxd364d282008-10-07 12:36:30 -0700100/*
Russ Cox8f4af6d2009-06-06 12:46:38 -0700101 * manual override of shift/reduce conflicts.
102 * the general form is that we assign a precedence
103 * to the token being shifted and then introduce
104 * NotToken with lower precedence or PreferToToken with higher
105 * and annotate the reducing rule accordingly.
Russ Coxd364d282008-10-07 12:36:30 -0700106 */
Russ Cox8f4af6d2009-06-06 12:46:38 -0700107%left NotPackage
108%left LPACKAGE
Russ Coxd364d282008-10-07 12:36:30 -0700109
Russ Cox8f4af6d2009-06-06 12:46:38 -0700110%left NotParen
111%left '('
Rob Pike0cafb9e2008-06-04 14:37:38 -0700112
Russ Cox8f4af6d2009-06-06 12:46:38 -0700113%left ')'
114%left PreferToRightParen
Rob Pike0cafb9e2008-06-04 14:37:38 -0700115
Rob Pike0cafb9e2008-06-04 14:37:38 -0700116%%
117file:
Russ Coxb3533df2009-05-08 15:40:31 -0700118 loadsys
119 package
120 imports
Russ Coxe52e9ca2009-07-17 01:00:44 -0700121 xdcl_list
Rob Pike0cafb9e2008-06-04 14:37:38 -0700122 {
Russ Cox66bb3992009-08-12 13:18:19 -0700123 xtop = concat(xtop, $4);
Rob Pike0cafb9e2008-06-04 14:37:38 -0700124 }
125
126package:
Russ Cox63985b42009-03-05 15:57:03 -0800127 %prec NotPackage
Rob Pike0cafb9e2008-06-04 14:37:38 -0700128 {
Russ Cox38df5ec2009-08-19 15:18:08 -0700129 prevlineno = lineno;
Rob Pike0cafb9e2008-06-04 14:37:38 -0700130 yyerror("package statement must be first");
Russ Cox39974952009-12-11 15:59:41 -0800131 flusherrors();
Rob Pike0cafb9e2008-06-04 14:37:38 -0700132 mkpackage("main");
Rob Pike0cafb9e2008-06-04 14:37:38 -0700133 }
Russ Cox39974952009-12-11 15:59:41 -0800134| LPACKAGE sym ';'
Rob Pike0cafb9e2008-06-04 14:37:38 -0700135 {
136 mkpackage($2->name);
Russ Coxb3533df2009-05-08 15:40:31 -0700137 }
138
139/*
Russ Cox22a5c782009-10-15 23:10:49 -0700140 * this loads the definitions for the low-level runtime functions,
Russ Coxb3533df2009-05-08 15:40:31 -0700141 * so that the compiler can generate calls to them,
Russ Cox22a5c782009-10-15 23:10:49 -0700142 * but does not make the name "runtime" visible as a package.
Russ Coxb3533df2009-05-08 15:40:31 -0700143 */
144loadsys:
145 {
Russ Cox22a5c782009-10-15 23:10:49 -0700146 cannedimports("runtime.builtin", runtimeimport);
Rob Pike0cafb9e2008-06-04 14:37:38 -0700147 }
Russ Coxb3533df2009-05-08 15:40:31 -0700148 import_package
149 import_there
150 {
151 pkgimportname = S;
152 }
Rob Pike0cafb9e2008-06-04 14:37:38 -0700153
154imports:
Russ Cox39974952009-12-11 15:59:41 -0800155| imports import ';'
Rob Pike0cafb9e2008-06-04 14:37:38 -0700156
157import:
Russ Cox39974952009-12-11 15:59:41 -0800158 LIMPORT import_stmt
159| LIMPORT '(' import_stmt_list osemi ')'
160| LIMPORT '(' ')'
Rob Pike0cafb9e2008-06-04 14:37:38 -0700161
162import_stmt:
Russ Cox38df5ec2009-08-19 15:18:08 -0700163 import_here import_package import_there
Russ Coxb3533df2009-05-08 15:40:31 -0700164 {
165 Sym *import, *my;
Russ Cox73e52ae2009-09-17 16:42:10 -0700166 Node *pack;
Russ Coxb3533df2009-05-08 15:40:31 -0700167
168 import = pkgimportname;
169 my = pkgmyname;
170 pkgmyname = S;
171 pkgimportname = S;
172
173 if(import == S)
174 break;
Russ Cox73e52ae2009-09-17 16:42:10 -0700175
176 pack = nod(OPACK, N, N);
177 pack->sym = import;
178 pack->lineno = $1;
Russ Cox73e52ae2009-09-17 16:42:10 -0700179
Russ Coxb3533df2009-05-08 15:40:31 -0700180 if(my == S)
181 my = import;
182 if(my->name[0] == '.') {
Russ Cox73e52ae2009-09-17 16:42:10 -0700183 importdot(import, pack);
Russ Coxb3533df2009-05-08 15:40:31 -0700184 break;
185 }
Russ Coxaa6e81dd2009-09-09 16:59:41 -0700186 if(my->name[0] == '_' && my->name[1] == '\0')
187 break;
Russ Coxb3533df2009-05-08 15:40:31 -0700188
Russ Coxfd76b4f2009-10-12 10:12:37 -0700189 // Can end up with my->def->op set to ONONAME
190 // if one package refers to p without importing it.
191 // Don't want to give an error on a good import
192 // in another file.
193 if(my->def && my->def->op != ONONAME) {
Russ Coxd5150632009-10-07 14:55:12 -0700194 lineno = $1;
195 redeclare(my, "as imported package name");
196 }
Russ Cox73e52ae2009-09-17 16:42:10 -0700197 my->def = pack;
Russ Cox38df5ec2009-08-19 15:18:08 -0700198 my->lastlineno = $1;
Russ Cox56004352009-08-19 17:27:08 -0700199 import->block = 1; // at top level
Russ Coxb3533df2009-05-08 15:40:31 -0700200 }
Russ Cox5d16d232009-09-09 00:18:16 -0700201
Russ Cox38df5ec2009-08-19 15:18:08 -0700202
203import_stmt_list:
204 import_stmt
205| import_stmt_list ';' import_stmt
206
207import_here:
208 LLITERAL
209 {
210 // import with original name
211 $$ = parserline();
212 pkgimportname = S;
213 pkgmyname = S;
Russ Cox73e52ae2009-09-17 16:42:10 -0700214 importfile(&$1, $$);
Russ Cox38df5ec2009-08-19 15:18:08 -0700215 }
216| sym LLITERAL
217 {
218 // import with given name
219 $$ = parserline();
220 pkgimportname = S;
221 pkgmyname = $1;
Russ Cox73e52ae2009-09-17 16:42:10 -0700222 importfile(&$2, $$);
Russ Cox38df5ec2009-08-19 15:18:08 -0700223 }
224| '.' LLITERAL
225 {
226 // import into my name space
227 $$ = parserline();
228 pkgmyname = lookup(".");
Russ Cox73e52ae2009-09-17 16:42:10 -0700229 importfile(&$2, $$);
Russ Cox38df5ec2009-08-19 15:18:08 -0700230 }
231
232import_package:
Russ Cox39974952009-12-11 15:59:41 -0800233 LPACKAGE sym ';'
Russ Cox38df5ec2009-08-19 15:18:08 -0700234 {
235 pkgimportname = $2;
236 if(strcmp($2->name, "main") == 0)
237 yyerror("cannot import package main");
Russ Cox5d16d232009-09-09 00:18:16 -0700238
Russ Cox9f42ccb2009-11-09 15:25:18 -0800239 // TODO(rsc): This should go away once we get
240 // rid of the global package name space.
Russ Cox22a5c782009-10-15 23:10:49 -0700241 if(strcmp($2->name, package) == 0 && strcmp(package, "runtime") != 0)
Russ Cox9f42ccb2009-11-09 15:25:18 -0800242 yyerror("package cannot import itself");
Russ Cox38df5ec2009-08-19 15:18:08 -0700243 }
244
245import_there:
246 {
247 defercheckwidth();
248 }
249 hidden_import_list '$' '$'
250 {
251 resumecheckwidth();
252 checkimports();
253 unimportfile();
254 }
255| LIMPORT '$' '$'
256 {
257 defercheckwidth();
258 }
259 hidden_import_list '$' '$'
260 {
261 resumecheckwidth();
262 checkimports();
Russ Cox39974952009-12-11 15:59:41 -0800263 unimportfile();
Russ Cox38df5ec2009-08-19 15:18:08 -0700264 }
Russ Coxb3533df2009-05-08 15:40:31 -0700265
Rob Pike0cafb9e2008-06-04 14:37:38 -0700266/*
267 * declarations
268 */
269xdcl:
Russ Cox39974952009-12-11 15:59:41 -0800270 {
271 yyerror("empty top-level declaration");
272 $$ = nil;
273 }
274| common_dcl
275| xfndcl
Ken Thompson989676d2008-08-03 18:47:02 -0700276 {
Russ Coxb6487162009-08-07 12:50:26 -0700277 $$ = list1($1);
Ken Thompson989676d2008-08-03 18:47:02 -0700278 }
Russ Cox39974952009-12-11 15:59:41 -0800279| error
Rob Pike0cafb9e2008-06-04 14:37:38 -0700280 {
Russ Coxe52e9ca2009-07-17 01:00:44 -0700281 $$ = nil;
Rob Pike0cafb9e2008-06-04 14:37:38 -0700282 }
283
284common_dcl:
Russ Cox8abcdee2009-06-06 19:27:48 -0700285 LVAR vardcl
Rob Pike0cafb9e2008-06-04 14:37:38 -0700286 {
287 $$ = $2;
288 }
Russ Coxe52e9ca2009-07-17 01:00:44 -0700289| LVAR '(' vardcl_list osemi ')'
Rob Pike0cafb9e2008-06-04 14:37:38 -0700290 {
Russ Coxe52e9ca2009-07-17 01:00:44 -0700291 $$ = $3;
Rob Pike0cafb9e2008-06-04 14:37:38 -0700292 }
Russ Cox5f1202422008-10-08 15:33:09 -0700293| LVAR '(' ')'
294 {
Russ Coxe52e9ca2009-07-17 01:00:44 -0700295 $$ = nil;
Ken Thompson54abac62008-06-21 15:11:29 -0700296 }
297| LCONST constdcl
298 {
Russ Coxb6487162009-08-07 12:50:26 -0700299 $$ = $2;
Ken Thompson54abac62008-06-21 15:11:29 -0700300 iota = 0;
Russ Coxe52e9ca2009-07-17 01:00:44 -0700301 lastconst = nil;
Ken Thompson54abac62008-06-21 15:11:29 -0700302 }
Russ Cox8abcdee2009-06-06 19:27:48 -0700303| LCONST '(' constdcl osemi ')'
304 {
Russ Coxb6487162009-08-07 12:50:26 -0700305 $$ = $3;
Russ Cox8abcdee2009-06-06 19:27:48 -0700306 iota = 0;
Russ Coxe52e9ca2009-07-17 01:00:44 -0700307 lastconst = nil;
Russ Cox8abcdee2009-06-06 19:27:48 -0700308 }
Russ Coxe52e9ca2009-07-17 01:00:44 -0700309| LCONST '(' constdcl ';' constdcl_list osemi ')'
Russ Cox8abcdee2009-06-06 19:27:48 -0700310 {
Russ Coxb6487162009-08-07 12:50:26 -0700311 $$ = concat($3, $5);
Russ Cox8abcdee2009-06-06 19:27:48 -0700312 iota = 0;
Russ Coxe52e9ca2009-07-17 01:00:44 -0700313 lastconst = nil;
Russ Cox8abcdee2009-06-06 19:27:48 -0700314 }
315| LCONST '(' ')'
Ken Thompson54abac62008-06-21 15:11:29 -0700316 {
Russ Coxe52e9ca2009-07-17 01:00:44 -0700317 $$ = nil;
Russ Cox8abcdee2009-06-06 19:27:48 -0700318 }
319| LTYPE typedcl
320 {
Russ Coxb6487162009-08-07 12:50:26 -0700321 $$ = list1($2);
Russ Cox8abcdee2009-06-06 19:27:48 -0700322 }
Russ Coxe52e9ca2009-07-17 01:00:44 -0700323| LTYPE '(' typedcl_list osemi ')'
Russ Cox8abcdee2009-06-06 19:27:48 -0700324 {
Russ Coxb6487162009-08-07 12:50:26 -0700325 $$ = $3;
Russ Cox8abcdee2009-06-06 19:27:48 -0700326 }
327| LTYPE '(' ')'
328 {
Russ Coxe52e9ca2009-07-17 01:00:44 -0700329 $$ = nil;
Ken Thompson54abac62008-06-21 15:11:29 -0700330 }
331
Rob Pike0cafb9e2008-06-04 14:37:38 -0700332vardcl:
Russ Cox39974952009-12-11 15:59:41 -0800333 dcl_name_list ntype
Ken Thompson54abac62008-06-21 15:11:29 -0700334 {
Russ Coxe52e9ca2009-07-17 01:00:44 -0700335 $$ = variter($1, $2, nil);
Ken Thompson54abac62008-06-21 15:11:29 -0700336 }
Russ Cox39974952009-12-11 15:59:41 -0800337| dcl_name_list ntype '=' expr_list
Rob Pike0cafb9e2008-06-04 14:37:38 -0700338 {
Russ Cox39974952009-12-11 15:59:41 -0800339 $$ = variter($1, $2, $4);
Rob Pike0cafb9e2008-06-04 14:37:38 -0700340 }
Russ Coxdb508ccbf2009-07-17 13:38:16 -0700341| dcl_name_list '=' expr_list
Rob Pike0cafb9e2008-06-04 14:37:38 -0700342 {
Russ Cox35e59062009-07-17 14:42:14 -0700343 $$ = variter($1, nil, $3);
Rob Pike0cafb9e2008-06-04 14:37:38 -0700344 }
345
346constdcl:
Russ Coxdb508ccbf2009-07-17 13:38:16 -0700347 dcl_name_list ntype '=' expr_list
Ken Thompsond915b962008-07-03 16:41:32 -0700348 {
Russ Coxdb508ccbf2009-07-17 13:38:16 -0700349 $$ = constiter($1, $2, $4);
Rob Pike0cafb9e2008-06-04 14:37:38 -0700350 }
Russ Coxdb508ccbf2009-07-17 13:38:16 -0700351| dcl_name_list '=' expr_list
Rob Pike0cafb9e2008-06-04 14:37:38 -0700352 {
Russ Coxdb508ccbf2009-07-17 13:38:16 -0700353 $$ = constiter($1, N, $3);
Ken Thompson9dbaab52008-09-04 12:21:10 -0700354 }
355
356constdcl1:
357 constdcl
Russ Coxdb508ccbf2009-07-17 13:38:16 -0700358| dcl_name_list ntype
Ken Thompson9dbaab52008-09-04 12:21:10 -0700359 {
Russ Coxdb508ccbf2009-07-17 13:38:16 -0700360 $$ = constiter($1, $2, nil);
Ken Thompson9dbaab52008-09-04 12:21:10 -0700361 }
Russ Coxdb508ccbf2009-07-17 13:38:16 -0700362| dcl_name_list
Ken Thompson9dbaab52008-09-04 12:21:10 -0700363 {
Russ Coxdb508ccbf2009-07-17 13:38:16 -0700364 $$ = constiter($1, N, nil);
Rob Pike0cafb9e2008-06-04 14:37:38 -0700365 }
366
Russ Cox74e2e082008-10-06 16:44:17 -0700367typedclname:
Russ Coxb6487162009-08-07 12:50:26 -0700368 sym
Ken Thompson54abac62008-06-21 15:11:29 -0700369 {
Russ Coxb6487162009-08-07 12:50:26 -0700370 // different from dclname because the name
371 // becomes visible right here, not at the end
372 // of the declaration.
373 $$ = typedcl0($1);
Ken Thompson54abac62008-06-21 15:11:29 -0700374 }
375
Russ Coxd364d282008-10-07 12:36:30 -0700376typedcl:
Russ Cox35e59062009-07-17 14:42:14 -0700377 typedclname ntype
Rob Pike0cafb9e2008-06-04 14:37:38 -0700378 {
Russ Coxb6487162009-08-07 12:50:26 -0700379 $$ = typedcl1($1, $2, 1);
Russ Cox74e2e082008-10-06 16:44:17 -0700380 }
Russ Coxb6487162009-08-07 12:50:26 -0700381
Rob Pike0cafb9e2008-06-04 14:37:38 -0700382simple_stmt:
383 expr
384 {
385 $$ = $1;
386 }
Rob Pike0cafb9e2008-06-04 14:37:38 -0700387| expr LASOP expr
388 {
389 $$ = nod(OASOP, $1, $3);
Ken Thompson9c2ade32008-08-08 17:13:31 -0700390 $$->etype = $2; // rathole to pass opcode
Rob Pike0cafb9e2008-06-04 14:37:38 -0700391 }
Russ Cox8f4af6d2009-06-06 12:46:38 -0700392| expr_list '=' expr_list
Rob Pike0cafb9e2008-06-04 14:37:38 -0700393 {
Russ Coxe52e9ca2009-07-17 01:00:44 -0700394 if($1->next == nil && $3->next == nil) {
395 // simple
396 $$ = nod(OAS, $1->n, $3->n);
397 break;
398 }
399 // multiple
400 $$ = nod(OAS2, N, N);
401 $$->list = $1;
402 $$->rlist = $3;
Rob Pike0cafb9e2008-06-04 14:37:38 -0700403 }
Russ Cox8f4af6d2009-06-06 12:46:38 -0700404| expr_list LCOLAS expr_list
Rob Pike0cafb9e2008-06-04 14:37:38 -0700405 {
Russ Coxe52e9ca2009-07-17 01:00:44 -0700406 if($3->n->op == OTYPESW) {
407 if($3->next != nil)
408 yyerror("expr.(type) must be alone in list");
409 else if($1->next != nil)
410 yyerror("argument count mismatch: %d = %d", count($1), 1);
Russ Cox5d16d232009-09-09 00:18:16 -0700411 $$ = nod(OTYPESW, $1->n, $3->n->right);
Ken Thompsona4a10ed2009-03-06 17:50:43 -0800412 break;
413 }
Russ Coxe52e9ca2009-07-17 01:00:44 -0700414 $$ = colas($1, $3);
Rob Pike0cafb9e2008-06-04 14:37:38 -0700415 }
Russ Coxd364d282008-10-07 12:36:30 -0700416| expr LINC
Ken Thompsonc242b532008-06-17 22:33:32 -0700417 {
Russ Cox8f194bf2009-03-12 19:04:38 -0700418 $$ = nod(OASOP, $1, nodintconst(1));
Ken Thompsonc242b532008-06-17 22:33:32 -0700419 $$->etype = OADD;
420 }
421| expr LDEC
422 {
Russ Cox8f194bf2009-03-12 19:04:38 -0700423 $$ = nod(OASOP, $1, nodintconst(1));
Ken Thompsonc242b532008-06-17 22:33:32 -0700424 $$->etype = OSUB;
425 }
426
Russ Coxd6a98172009-05-30 21:18:15 -0700427case:
Russ Cox35e59062009-07-17 14:42:14 -0700428 LCASE expr_or_type_list ':'
Rob Pike0cafb9e2008-06-04 14:37:38 -0700429 {
Russ Cox5d16d232009-09-09 00:18:16 -0700430 Node *n;
Russ Cox0dadc4f2009-07-10 16:29:26 -0700431
Rob Pike0cafb9e2008-06-04 14:37:38 -0700432 // will be converted to OCASE
433 // right will point to next case
434 // done in casebody()
435 poptodcl();
Russ Coxe52e9ca2009-07-17 01:00:44 -0700436 $$ = nod(OXCASE, N, N);
Russ Cox5d16d232009-09-09 00:18:16 -0700437 $$->list = $2;
438 if(typesw != N && typesw->right != N && (n=typesw->right->left) != N) {
439 // type switch - declare variable
440 n = newname(n->sym);
Russ Cox59914722009-09-14 18:38:30 -0700441 n->used = 1; // TODO(rsc): better job here
Russ Cox26097312009-08-05 02:33:30 -0700442 declare(n, dclcontext);
Russ Cox5d16d232009-09-09 00:18:16 -0700443 $$->nname = n;
Ken Thompson0f469a92009-03-17 13:58:38 -0700444 }
Russ Coxe52e9ca2009-07-17 01:00:44 -0700445 break;
Rob Pike0cafb9e2008-06-04 14:37:38 -0700446 }
Rob Pike47919792008-09-16 19:14:33 -0700447| LCASE name '=' expr ':'
448 {
449 // will be converted to OCASE
450 // right will point to next case
451 // done in casebody()
452 poptodcl();
Russ Coxe52e9ca2009-07-17 01:00:44 -0700453 $$ = nod(OXCASE, N, N);
454 $$->list = list1(nod(OAS, $2, $4));
Rob Pike47919792008-09-16 19:14:33 -0700455 }
456| LCASE name LCOLAS expr ':'
457 {
458 // will be converted to OCASE
459 // right will point to next case
460 // done in casebody()
461 poptodcl();
Russ Coxe52e9ca2009-07-17 01:00:44 -0700462 $$ = nod(OXCASE, N, N);
Russ Cox54b40372009-08-05 00:42:44 -0700463 $$->list = list1(colas(list1($2), list1($4)));
Rob Pike47919792008-09-16 19:14:33 -0700464 }
Rob Pike0cafb9e2008-06-04 14:37:38 -0700465| LDEFAULT ':'
466 {
Russ Cox5d16d232009-09-09 00:18:16 -0700467 Node *n;
468
Rob Pike0cafb9e2008-06-04 14:37:38 -0700469 poptodcl();
470 $$ = nod(OXCASE, N, N);
Russ Cox5d16d232009-09-09 00:18:16 -0700471 if(typesw != N && typesw->right != N && (n=typesw->right->left) != N) {
472 // type switch - declare variable
473 n = newname(n->sym);
Russ Cox59914722009-09-14 18:38:30 -0700474 n->used = 1; // TODO(rsc): better job here
Russ Cox5d16d232009-09-09 00:18:16 -0700475 declare(n, dclcontext);
476 $$->nname = n;
477 }
Rob Pike0cafb9e2008-06-04 14:37:38 -0700478 }
Ken Thompson8200a0b2008-06-08 12:48:37 -0700479
Rob Pike0cafb9e2008-06-04 14:37:38 -0700480compound_stmt:
481 '{'
482 {
Ken Thompson417a9712008-07-05 12:49:25 -0700483 markdcl();
Russ Cox8f4af6d2009-06-06 12:46:38 -0700484 }
Russ Coxe52e9ca2009-07-17 01:00:44 -0700485 stmt_list '}'
Rob Pike0cafb9e2008-06-04 14:37:38 -0700486 {
Russ Coxe52e9ca2009-07-17 01:00:44 -0700487 $$ = liststmt($3);
Ken Thompson417a9712008-07-05 12:49:25 -0700488 popdcl();
Rob Pike0cafb9e2008-06-04 14:37:38 -0700489 }
490
Russ Coxd6a98172009-05-30 21:18:15 -0700491switch_body:
Russ Cox8f4af6d2009-06-06 12:46:38 -0700492 LBODY
Russ Coxd6a98172009-05-30 21:18:15 -0700493 {
494 markdcl();
495 }
Russ Coxe52e9ca2009-07-17 01:00:44 -0700496 caseblock_list '}'
Russ Coxd6a98172009-05-30 21:18:15 -0700497 {
498 $$ = $3;
Russ Coxd6a98172009-05-30 21:18:15 -0700499 popdcl();
500 }
501
502caseblock:
Russ Coxe52e9ca2009-07-17 01:00:44 -0700503 case stmt_list
Russ Coxd6a98172009-05-30 21:18:15 -0700504 {
505 $$ = $1;
506 $$->nbody = $2;
507 }
508
Russ Coxe52e9ca2009-07-17 01:00:44 -0700509caseblock_list:
Russ Coxd6a98172009-05-30 21:18:15 -0700510 {
Russ Coxe52e9ca2009-07-17 01:00:44 -0700511 $$ = nil;
512 }
513| caseblock_list caseblock
514 {
515 $$ = list($1, $2);
Russ Coxd6a98172009-05-30 21:18:15 -0700516 }
517
Russ Cox8f4af6d2009-06-06 12:46:38 -0700518loop_body:
519 LBODY
520 {
521 markdcl();
522 }
Russ Coxe52e9ca2009-07-17 01:00:44 -0700523 stmt_list '}'
Russ Cox8f4af6d2009-06-06 12:46:38 -0700524 {
525 $$ = $3;
Russ Cox8f4af6d2009-06-06 12:46:38 -0700526 popdcl();
527 }
528
Russ Cox3ec46752009-01-28 15:41:50 -0800529range_stmt:
Russ Cox8f4af6d2009-06-06 12:46:38 -0700530 expr_list '=' LRANGE expr
Rob Pike0cafb9e2008-06-04 14:37:38 -0700531 {
Russ Coxe52e9ca2009-07-17 01:00:44 -0700532 $$ = nod(ORANGE, N, $4);
533 $$->list = $1;
Ken Thompsonb79272d2008-12-06 13:40:30 -0800534 $$->etype = 0; // := flag
535 }
Russ Cox8f4af6d2009-06-06 12:46:38 -0700536| expr_list LCOLAS LRANGE expr
Ken Thompsonb79272d2008-12-06 13:40:30 -0800537 {
Russ Coxe52e9ca2009-07-17 01:00:44 -0700538 $$ = nod(ORANGE, N, $4);
539 $$->list = $1;
Russ Cox26097312009-08-05 02:33:30 -0700540 $$->colas = 1;
541 colasdefn($1, $$);
Ken Thompsonb79272d2008-12-06 13:40:30 -0800542 }
Ken Thompsonb79272d2008-12-06 13:40:30 -0800543
544for_header:
Russ Cox3ec46752009-01-28 15:41:50 -0800545 osimple_stmt ';' osimple_stmt ';' osimple_stmt
Ken Thompsonb79272d2008-12-06 13:40:30 -0800546 {
Rob Pike0cafb9e2008-06-04 14:37:38 -0700547 // init ; test ; incr
Ken Thompsonae5a4752008-12-15 13:44:27 -0800548 if($5 != N && $5->colas != 0)
549 yyerror("cannot declare in the for-increment");
Rob Pike0cafb9e2008-06-04 14:37:38 -0700550 $$ = nod(OFOR, N, N);
Russ Coxe52e9ca2009-07-17 01:00:44 -0700551 if($1 != N)
552 $$->ninit = list1($1);
Rob Pike0cafb9e2008-06-04 14:37:38 -0700553 $$->ntest = $3;
554 $$->nincr = $5;
555 }
Russ Cox8f4af6d2009-06-06 12:46:38 -0700556| osimple_stmt
Rob Pike0cafb9e2008-06-04 14:37:38 -0700557 {
Ken Thompsonb79272d2008-12-06 13:40:30 -0800558 // normal test
Rob Pike0cafb9e2008-06-04 14:37:38 -0700559 $$ = nod(OFOR, N, N);
Rob Pike0cafb9e2008-06-04 14:37:38 -0700560 $$->ntest = $1;
Rob Pike0cafb9e2008-06-04 14:37:38 -0700561 }
Russ Cox3ec46752009-01-28 15:41:50 -0800562| range_stmt
Rob Pike0cafb9e2008-06-04 14:37:38 -0700563
564for_body:
Russ Cox8f4af6d2009-06-06 12:46:38 -0700565 for_header loop_body
Rob Pike0cafb9e2008-06-04 14:37:38 -0700566 {
567 $$ = $1;
Russ Coxe52e9ca2009-07-17 01:00:44 -0700568 $$->nbody = concat($$->nbody, $2);
Rob Pike0cafb9e2008-06-04 14:37:38 -0700569 }
570
571for_stmt:
Russ Coxd6a98172009-05-30 21:18:15 -0700572 LFOR
Rob Pike0cafb9e2008-06-04 14:37:38 -0700573 {
Ken Thompson417a9712008-07-05 12:49:25 -0700574 markdcl();
Russ Coxd6a98172009-05-30 21:18:15 -0700575 }
576 for_body
Rob Pike0cafb9e2008-06-04 14:37:38 -0700577 {
Russ Coxd6a98172009-05-30 21:18:15 -0700578 $$ = $3;
579 popdcl();
Rob Pike0cafb9e2008-06-04 14:37:38 -0700580 }
581
582if_header:
Russ Cox8f4af6d2009-06-06 12:46:38 -0700583 osimple_stmt
Rob Pike0cafb9e2008-06-04 14:37:38 -0700584 {
585 // test
586 $$ = nod(OIF, N, N);
Rob Pike0cafb9e2008-06-04 14:37:38 -0700587 $$->ntest = $1;
588 }
Russ Cox8f4af6d2009-06-06 12:46:38 -0700589| osimple_stmt ';' osimple_stmt
Rob Pike0cafb9e2008-06-04 14:37:38 -0700590 {
591 // init ; test
592 $$ = nod(OIF, N, N);
Russ Coxe52e9ca2009-07-17 01:00:44 -0700593 if($1 != N)
594 $$->ninit = list1($1);
Rob Pike0cafb9e2008-06-04 14:37:38 -0700595 $$->ntest = $3;
596 }
597
Russ Coxd6a98172009-05-30 21:18:15 -0700598if_stmt:
599 LIF
600 {
601 markdcl();
602 }
Russ Cox8f4af6d2009-06-06 12:46:38 -0700603 if_header loop_body
Russ Coxd6a98172009-05-30 21:18:15 -0700604 {
605 $$ = $3;
606 $$->nbody = $4;
607 // no popdcl; maybe there's an LELSE
608 }
609
610switch_stmt:
611 LSWITCH
612 {
613 markdcl();
614 }
Ken Thompsona4a10ed2009-03-06 17:50:43 -0800615 if_header
616 {
617 Node *n;
Russ Coxd6a98172009-05-30 21:18:15 -0700618 n = $3->ntest;
Russ Cox5d16d232009-09-09 00:18:16 -0700619 if(n != N && n->op != OTYPESW)
Ken Thompsona4a10ed2009-03-06 17:50:43 -0800620 n = N;
Russ Cox5d16d232009-09-09 00:18:16 -0700621 typesw = nod(OXXX, typesw, n);
Rob Pike0cafb9e2008-06-04 14:37:38 -0700622 }
Russ Coxd6a98172009-05-30 21:18:15 -0700623 switch_body
Rob Pike0cafb9e2008-06-04 14:37:38 -0700624 {
Russ Coxd6a98172009-05-30 21:18:15 -0700625 $$ = $3;
626 $$->op = OSWITCH;
Russ Coxe52e9ca2009-07-17 01:00:44 -0700627 $$->list = $5;
Russ Cox5d16d232009-09-09 00:18:16 -0700628 typesw = typesw->left;
Russ Coxd6a98172009-05-30 21:18:15 -0700629 popdcl();
Rob Pike0cafb9e2008-06-04 14:37:38 -0700630 }
631
Ken Thompsonb78676a2008-07-20 20:13:07 -0700632select_stmt:
Russ Coxd6a98172009-05-30 21:18:15 -0700633 LSELECT
Ken Thompsonb78676a2008-07-20 20:13:07 -0700634 {
635 markdcl();
636 }
Russ Coxd6a98172009-05-30 21:18:15 -0700637 switch_body
Ken Thompsonb78676a2008-07-20 20:13:07 -0700638 {
Russ Coxe52e9ca2009-07-17 01:00:44 -0700639 $$ = nod(OSELECT, N, N);
640 $$->list = $3;
Russ Coxd6a98172009-05-30 21:18:15 -0700641 popdcl();
Ken Thompsonb78676a2008-07-20 20:13:07 -0700642 }
643
Rob Pike0cafb9e2008-06-04 14:37:38 -0700644/*
645 * expressions
646 */
647expr:
648 uexpr
649| expr LOROR expr
650 {
651 $$ = nod(OOROR, $1, $3);
652 }
653| expr LANDAND expr
654 {
655 $$ = nod(OANDAND, $1, $3);
656 }
657| expr LEQ expr
658 {
659 $$ = nod(OEQ, $1, $3);
660 }
661| expr LNE expr
662 {
663 $$ = nod(ONE, $1, $3);
664 }
665| expr LLT expr
666 {
667 $$ = nod(OLT, $1, $3);
668 }
669| expr LLE expr
670 {
671 $$ = nod(OLE, $1, $3);
672 }
673| expr LGE expr
674 {
675 $$ = nod(OGE, $1, $3);
676 }
677| expr LGT expr
678 {
679 $$ = nod(OGT, $1, $3);
680 }
681| expr '+' expr
682 {
683 $$ = nod(OADD, $1, $3);
684 }
685| expr '-' expr
686 {
687 $$ = nod(OSUB, $1, $3);
688 }
689| expr '|' expr
690 {
691 $$ = nod(OOR, $1, $3);
692 }
693| expr '^' expr
694 {
695 $$ = nod(OXOR, $1, $3);
696 }
697| expr '*' expr
698 {
699 $$ = nod(OMUL, $1, $3);
700 }
701| expr '/' expr
702 {
703 $$ = nod(ODIV, $1, $3);
704 }
705| expr '%' expr
706 {
707 $$ = nod(OMOD, $1, $3);
708 }
709| expr '&' expr
710 {
711 $$ = nod(OAND, $1, $3);
712 }
Ken Thompsonbb02e482009-03-11 19:59:35 -0700713| expr LANDNOT expr
714 {
715 $$ = nod(OANDNOT, $1, $3);
716 }
Rob Pike0cafb9e2008-06-04 14:37:38 -0700717| expr LLSH expr
718 {
719 $$ = nod(OLSH, $1, $3);
720 }
721| expr LRSH expr
722 {
723 $$ = nod(ORSH, $1, $3);
724 }
Rob Pike47919792008-09-16 19:14:33 -0700725| expr LCOMM expr
Ken Thompsonac048ce2008-07-15 21:07:59 -0700726 {
727 $$ = nod(OSEND, $1, $3);
728 }
Rob Pike0cafb9e2008-06-04 14:37:38 -0700729
730uexpr:
731 pexpr
732| '*' uexpr
733 {
734 $$ = nod(OIND, $2, N);
735 }
736| '&' uexpr
737 {
738 $$ = nod(OADDR, $2, N);
739 }
740| '+' uexpr
741 {
742 $$ = nod(OPLUS, $2, N);
743 }
744| '-' uexpr
745 {
746 $$ = nod(OMINUS, $2, N);
747 }
748| '!' uexpr
749 {
750 $$ = nod(ONOT, $2, N);
751 }
752| '~' uexpr
753 {
754 yyerror("the OCOM operator is ^");
755 $$ = nod(OCOM, $2, N);
756 }
757| '^' uexpr
758 {
759 $$ = nod(OCOM, $2, N);
760 }
Rob Pike47919792008-09-16 19:14:33 -0700761| LCOMM uexpr
Rob Pike0cafb9e2008-06-04 14:37:38 -0700762 {
763 $$ = nod(ORECV, $2, N);
764 }
Rob Pike0cafb9e2008-06-04 14:37:38 -0700765
Ken Thompson7a983152009-04-28 17:20:18 -0700766/*
767 * call-like statements that
Russ Coxe52e9ca2009-07-17 01:00:44 -0700768 * can be preceded by 'defer' and 'go'
Ken Thompson7a983152009-04-28 17:20:18 -0700769 */
770pseudocall:
Russ Cox39974952009-12-11 15:59:41 -0800771 pexpr '(' oexpr_or_type_list_ocomma ')'
Ken Thompson7a983152009-04-28 17:20:18 -0700772 {
Russ Coxe52e9ca2009-07-17 01:00:44 -0700773 $$ = nod(OCALL, $1, N);
774 $$->list = $3;
Ken Thompson7a983152009-04-28 17:20:18 -0700775 }
776
Rob Pike0cafb9e2008-06-04 14:37:38 -0700777pexpr:
778 LLITERAL
779 {
Russ Cox8f194bf2009-03-12 19:04:38 -0700780 $$ = nodlit($1);
781 }
Russ Cox35e59062009-07-17 14:42:14 -0700782| name
Russ Cox8f4af6d2009-06-06 12:46:38 -0700783| pexpr '.' sym
Russ Cox8f194bf2009-03-12 19:04:38 -0700784 {
Russ Cox8f4af6d2009-06-06 12:46:38 -0700785 if($1->op == OPACK) {
786 Sym *s;
Russ Coxbe16caf2009-07-13 23:38:39 -0700787 s = restrictlookup($3->name, $1->sym->name);
Russ Cox73e52ae2009-09-17 16:42:10 -0700788 $1->used = 1;
Russ Cox8f4af6d2009-06-06 12:46:38 -0700789 $$ = oldname(s);
790 break;
791 }
Russ Cox26097312009-08-05 02:33:30 -0700792 $$ = nod(OXDOT, $1, newname($3));
Rob Pike0cafb9e2008-06-04 14:37:38 -0700793 }
Russ Cox8f4af6d2009-06-06 12:46:38 -0700794| '(' expr_or_type ')'
795 {
796 $$ = $2;
797 }
798| pexpr '.' '(' expr_or_type ')'
Rob Pike0cafb9e2008-06-04 14:37:38 -0700799 {
Russ Coxbe16caf2009-07-13 23:38:39 -0700800 $$ = nod(ODOTTYPE, $1, $4);
Rob Pike0cafb9e2008-06-04 14:37:38 -0700801 }
Ken Thompsona4a10ed2009-03-06 17:50:43 -0800802| pexpr '.' '(' LTYPE ')'
803 {
Russ Cox5d16d232009-09-09 00:18:16 -0700804 $$ = nod(OTYPESW, N, $1);
Ken Thompsona4a10ed2009-03-06 17:50:43 -0800805 }
Rob Pike0cafb9e2008-06-04 14:37:38 -0700806| pexpr '[' expr ']'
807 {
808 $$ = nod(OINDEX, $1, $3);
809 }
Russ Cox652f5562009-11-20 09:11:46 -0800810| pexpr '[' expr ':' ']'
Rob Pike0cafb9e2008-06-04 14:37:38 -0700811 {
Russ Cox652f5562009-11-20 09:11:46 -0800812 $$ = nod(OSLICE, $1, nod(OKEY, $3, N));
813 }
814| pexpr '[' expr ':' expr ']'
815 {
816 $$ = nod(OSLICE, $1, nod(OKEY, $3, $5));
Rob Pike0cafb9e2008-06-04 14:37:38 -0700817 }
Ken Thompson7a983152009-04-28 17:20:18 -0700818| pseudocall
Russ Cox49cc6492009-03-03 08:41:02 -0800819| convtype '(' expr ')'
Ken Thompson0194aaf2008-09-05 19:50:34 -0700820 {
Russ Cox49cc6492009-03-03 08:41:02 -0800821 // conversion
Russ Coxe52e9ca2009-07-17 01:00:44 -0700822 $$ = nod(OCALL, $1, N);
823 $$->list = list1($3);
Ken Thompson0194aaf2008-09-05 19:50:34 -0700824 }
Russ Coxe52e9ca2009-07-17 01:00:44 -0700825| convtype lbrace braced_keyval_list '}'
Ken Thompson0194aaf2008-09-05 19:50:34 -0700826 {
Russ Cox49cc6492009-03-03 08:41:02 -0800827 // composite expression
Russ Cox9dc22b62009-08-03 11:58:52 -0700828 $$ = nod(OCOMPLIT, N, $1);
Russ Coxe52e9ca2009-07-17 01:00:44 -0700829 $$->list = $3;
Russ Cox8f4af6d2009-06-06 12:46:38 -0700830
831 // If the opening brace was an LBODY,
832 // set up for another one now that we're done.
833 // See comment in lex.c about loophack.
834 if($2 == LBODY)
835 loophack = 1;
836 }
Russ Cox6f169872009-09-29 21:21:14 -0700837| pexpr '{' braced_keyval_list '}'
Russ Cox8f4af6d2009-06-06 12:46:38 -0700838 {
839 // composite expression
Russ Cox9dc22b62009-08-03 11:58:52 -0700840 $$ = nod(OCOMPLIT, N, $1);
Russ Coxe52e9ca2009-07-17 01:00:44 -0700841 $$->list = $3;
Ken Thompson0194aaf2008-09-05 19:50:34 -0700842 }
843| fnliteral
Rob Pike0cafb9e2008-06-04 14:37:38 -0700844
Russ Cox8f4af6d2009-06-06 12:46:38 -0700845expr_or_type:
846 expr
Russ Cox35e59062009-07-17 14:42:14 -0700847| non_expr_type %prec PreferToRightParen
Rob Pike0cafb9e2008-06-04 14:37:38 -0700848
Russ Cox8f4af6d2009-06-06 12:46:38 -0700849name_or_type:
Russ Cox35e59062009-07-17 14:42:14 -0700850 ntype
Russ Cox8f4af6d2009-06-06 12:46:38 -0700851
852lbrace:
853 LBODY
854 {
855 $$ = LBODY;
856 }
857| '{'
858 {
859 $$ = '{';
Rob Pike0cafb9e2008-06-04 14:37:38 -0700860 }
861
862/*
863 * names and types
864 * newname is used before declared
865 * oldname is used after declared
866 */
Rob Pike0cafb9e2008-06-04 14:37:38 -0700867new_name:
Russ Cox8f4af6d2009-06-06 12:46:38 -0700868 sym
Rob Pike0cafb9e2008-06-04 14:37:38 -0700869 {
870 $$ = newname($1);
871 }
872
Russ Coxdb508ccbf2009-07-17 13:38:16 -0700873dcl_name:
874 sym
875 {
876 $$ = dclname($1);
877 }
878
Ken Thompson33ee5272008-08-29 20:30:19 -0700879onew_name:
880 {
881 $$ = N;
882 }
883| new_name
884
Rob Pike0cafb9e2008-06-04 14:37:38 -0700885sym:
Russ Cox8f4af6d2009-06-06 12:46:38 -0700886 LNAME
Ken Thompsone8278bc2008-10-26 14:04:09 -0700887
Rob Pike0cafb9e2008-06-04 14:37:38 -0700888name:
Russ Cox35e59062009-07-17 14:42:14 -0700889 sym
Russ Cox63985b42009-03-05 15:57:03 -0800890 {
891 $$ = oldname($1);
Russ Cox73e52ae2009-09-17 16:42:10 -0700892 if($$->pack != N)
893 $$->pack->used = 1;
Russ Cox63985b42009-03-05 15:57:03 -0800894 }
895
896labelname:
Russ Coxb6487162009-08-07 12:50:26 -0700897 new_name
Rob Pike0cafb9e2008-06-04 14:37:38 -0700898
Ken Thompson0194aaf2008-09-05 19:50:34 -0700899convtype:
Russ Coxbe16caf2009-07-13 23:38:39 -0700900 '[' oexpr ']' ntype
Ken Thompson8200a0b2008-06-08 12:48:37 -0700901 {
Ken Thompson4539ced2008-09-03 14:09:29 -0700902 // array literal
Russ Coxbe16caf2009-07-13 23:38:39 -0700903 $$ = nod(OTARRAY, $2, $4);
Ken Thompson8200a0b2008-06-08 12:48:37 -0700904 }
Russ Coxbe16caf2009-07-13 23:38:39 -0700905| '[' dotdotdot ']' ntype
Ken Thompsonb0f627a2009-01-06 17:31:24 -0800906 {
907 // array literal of nelem
Russ Coxbe16caf2009-07-13 23:38:39 -0700908 $$ = nod(OTARRAY, $2, $4);
Ken Thompsonb0f627a2009-01-06 17:31:24 -0800909 }
Russ Coxbe16caf2009-07-13 23:38:39 -0700910| LMAP '[' ntype ']' ntype
Ken Thompson8200a0b2008-06-08 12:48:37 -0700911 {
Ken Thompson4539ced2008-09-03 14:09:29 -0700912 // map literal
Russ Coxbe16caf2009-07-13 23:38:39 -0700913 $$ = nod(OTMAP, $3, $5);
Ken Thompson8200a0b2008-06-08 12:48:37 -0700914 }
Ken Thompson0194aaf2008-09-05 19:50:34 -0700915| structtype
Ken Thompson8200a0b2008-06-08 12:48:37 -0700916
Russ Coxd364d282008-10-07 12:36:30 -0700917/*
918 * to avoid parsing conflicts, type is split into
Russ Coxd364d282008-10-07 12:36:30 -0700919 * channel types
920 * function types
Russ Cox8abcdee2009-06-06 19:27:48 -0700921 * parenthesized types
Russ Coxd364d282008-10-07 12:36:30 -0700922 * any other type
Russ Coxd364d282008-10-07 12:36:30 -0700923 * the type system makes additional restrictions,
924 * but those are not implemented in the grammar.
925 */
Ken Thompsonc21d9a12008-10-29 12:46:44 -0700926dotdotdot:
927 LDDD
928 {
Russ Coxbe16caf2009-07-13 23:38:39 -0700929 $$ = typenod(typ(TDDD));
Ken Thompsonc21d9a12008-10-29 12:46:44 -0700930 }
Russ Coxd364d282008-10-07 12:36:30 -0700931
Russ Coxbe16caf2009-07-13 23:38:39 -0700932ntype:
Russ Cox8abcdee2009-06-06 19:27:48 -0700933 chantype
Russ Coxdb508ccbf2009-07-17 13:38:16 -0700934| fntype
Russ Cox8abcdee2009-06-06 19:27:48 -0700935| othertype
Russ Cox35e59062009-07-17 14:42:14 -0700936| ptrtype
937| dotname
Russ Coxbe16caf2009-07-13 23:38:39 -0700938| '(' ntype ')'
Russ Coxebc10db2009-02-18 10:07:46 -0800939 {
940 $$ = $2;
941 }
Russ Coxd364d282008-10-07 12:36:30 -0700942
Russ Cox35e59062009-07-17 14:42:14 -0700943non_expr_type:
944 chantype
945| fntype
946| othertype
947| '*' non_expr_type
948 {
949 $$ = nod(OIND, $2, N);
950 }
951| '(' non_expr_type ')'
952 {
953 $$ = $2;
954 }
955
Russ Cox8abcdee2009-06-06 19:27:48 -0700956non_chan_type:
Russ Coxdb508ccbf2009-07-17 13:38:16 -0700957 fntype
Russ Cox8abcdee2009-06-06 19:27:48 -0700958| othertype
Russ Cox35e59062009-07-17 14:42:14 -0700959| ptrtype
960| dotname
Russ Coxbe16caf2009-07-13 23:38:39 -0700961| '(' ntype ')'
Russ Cox4d571c92008-09-30 12:53:11 -0700962 {
Russ Cox8abcdee2009-06-06 19:27:48 -0700963 $$ = $2;
Russ Cox4d571c92008-09-30 12:53:11 -0700964 }
Russ Cox4d571c92008-09-30 12:53:11 -0700965
Russ Cox8abcdee2009-06-06 19:27:48 -0700966non_fn_type:
967 chantype
968| othertype
Russ Cox35e59062009-07-17 14:42:14 -0700969| ptrtype
970| dotname
Russ Cox8abcdee2009-06-06 19:27:48 -0700971
Russ Cox8f4af6d2009-06-06 12:46:38 -0700972dotname:
Russ Cox35e59062009-07-17 14:42:14 -0700973 name
Russ Cox8f4af6d2009-06-06 12:46:38 -0700974| name '.' sym
975 {
976 if($1->op == OPACK) {
977 Sym *s;
Russ Coxbe16caf2009-07-13 23:38:39 -0700978 s = restrictlookup($3->name, $1->sym->name);
Russ Cox73e52ae2009-09-17 16:42:10 -0700979 $1->used = 1;
Russ Cox8f4af6d2009-06-06 12:46:38 -0700980 $$ = oldname(s);
981 break;
982 }
Russ Cox26097312009-08-05 02:33:30 -0700983 $$ = nod(OXDOT, $1, newname($3));
Russ Cox8f4af6d2009-06-06 12:46:38 -0700984 }
Russ Coxd364d282008-10-07 12:36:30 -0700985
Russ Cox8abcdee2009-06-06 19:27:48 -0700986othertype:
Russ Cox35e59062009-07-17 14:42:14 -0700987 '[' oexpr ']' ntype
Russ Coxd364d282008-10-07 12:36:30 -0700988 {
Russ Cox35e59062009-07-17 14:42:14 -0700989 $$ = nod(OTARRAY, $2, $4);
Russ Coxd364d282008-10-07 12:36:30 -0700990 }
Russ Cox6f169872009-09-29 21:21:14 -0700991| '[' dotdotdot ']' ntype
992 {
993 // array literal of nelem
994 $$ = nod(OTARRAY, $2, $4);
995 }
Russ Coxbe16caf2009-07-13 23:38:39 -0700996| LCOMM LCHAN ntype
Russ Coxd364d282008-10-07 12:36:30 -0700997 {
Russ Coxbe16caf2009-07-13 23:38:39 -0700998 $$ = nod(OTCHAN, $3, N);
999 $$->etype = Crecv;
Russ Coxd364d282008-10-07 12:36:30 -07001000 }
Russ Cox8abcdee2009-06-06 19:27:48 -07001001| LCHAN LCOMM non_chan_type
Russ Coxd364d282008-10-07 12:36:30 -07001002 {
Russ Coxbe16caf2009-07-13 23:38:39 -07001003 $$ = nod(OTCHAN, $3, N);
1004 $$->etype = Csend;
Russ Coxd364d282008-10-07 12:36:30 -07001005 }
Russ Coxbe16caf2009-07-13 23:38:39 -07001006| LMAP '[' ntype ']' ntype
Russ Coxd364d282008-10-07 12:36:30 -07001007 {
Russ Coxbe16caf2009-07-13 23:38:39 -07001008 $$ = nod(OTMAP, $3, $5);
Russ Coxd364d282008-10-07 12:36:30 -07001009 }
Russ Cox35e59062009-07-17 14:42:14 -07001010| structtype
1011| interfacetype
1012
1013ptrtype:
1014 '*' ntype
Russ Coxd364d282008-10-07 12:36:30 -07001015 {
Russ Coxbe16caf2009-07-13 23:38:39 -07001016 $$ = nod(OIND, $2, N);
Russ Coxd364d282008-10-07 12:36:30 -07001017 }
Rob Pike0cafb9e2008-06-04 14:37:38 -07001018
Russ Cox8abcdee2009-06-06 19:27:48 -07001019chantype:
Russ Coxbe16caf2009-07-13 23:38:39 -07001020 LCHAN ntype
Russ Coxd364d282008-10-07 12:36:30 -07001021 {
Russ Coxbe16caf2009-07-13 23:38:39 -07001022 $$ = nod(OTCHAN, $2, N);
1023 $$->etype = Cboth;
Russ Coxd364d282008-10-07 12:36:30 -07001024 }
Ken Thompson0194aaf2008-09-05 19:50:34 -07001025
1026structtype:
Russ Coxe52e9ca2009-07-17 01:00:44 -07001027 LSTRUCT '{' structdcl_list osemi '}'
Ken Thompson0194aaf2008-09-05 19:50:34 -07001028 {
Russ Coxe52e9ca2009-07-17 01:00:44 -07001029 $$ = nod(OTSTRUCT, N, N);
1030 $$->list = $3;
Ken Thompson0194aaf2008-09-05 19:50:34 -07001031 }
1032| LSTRUCT '{' '}'
1033 {
Russ Coxbe16caf2009-07-13 23:38:39 -07001034 $$ = nod(OTSTRUCT, N, N);
Ken Thompson0194aaf2008-09-05 19:50:34 -07001035 }
1036
1037interfacetype:
Russ Coxe52e9ca2009-07-17 01:00:44 -07001038 LINTERFACE '{' interfacedcl_list osemi '}'
Ken Thompson0194aaf2008-09-05 19:50:34 -07001039 {
Russ Coxe52e9ca2009-07-17 01:00:44 -07001040 $$ = nod(OTINTER, N, N);
1041 $$->list = $3;
Ken Thompson0194aaf2008-09-05 19:50:34 -07001042 }
1043| LINTERFACE '{' '}'
1044 {
Russ Coxbe16caf2009-07-13 23:38:39 -07001045 $$ = nod(OTINTER, N, N);
Ken Thompson0194aaf2008-09-05 19:50:34 -07001046 }
1047
Rob Pike0cafb9e2008-06-04 14:37:38 -07001048keyval:
1049 expr ':' expr
1050 {
Ken Thompson182f91f2008-09-03 14:40:22 -07001051 $$ = nod(OKEY, $1, $3);
Rob Pike0cafb9e2008-06-04 14:37:38 -07001052 }
Russ Coxc2fa45b2009-05-21 16:31:10 -07001053
Rob Pike0cafb9e2008-06-04 14:37:38 -07001054
1055/*
1056 * function stuff
1057 * all in one place to show how crappy it all is
1058 */
1059xfndcl:
Russ Coxb6487162009-08-07 12:50:26 -07001060 LFUNC fndcl fnbody
Rob Pike0cafb9e2008-06-04 14:37:38 -07001061 {
Russ Coxb6487162009-08-07 12:50:26 -07001062 $$ = $2;
Russ Coxa3382312009-11-15 12:57:09 -08001063 if($$ == N)
1064 break;
Russ Coxb6487162009-08-07 12:50:26 -07001065 $$->nbody = $3;
Rob Pike0cafb9e2008-06-04 14:37:38 -07001066 funcbody($$);
1067 }
1068
1069fndcl:
Russ Cox39974952009-12-11 15:59:41 -08001070 dcl_name '(' oarg_type_list_ocomma ')' fnres
Rob Pike0cafb9e2008-06-04 14:37:38 -07001071 {
Russ Cox35e59062009-07-17 14:42:14 -07001072 Node *n;
1073
Rob Pike0cafb9e2008-06-04 14:37:38 -07001074 $$ = nod(ODCLFUNC, N, N);
1075 $$->nname = $1;
Russ Coxe52e9ca2009-07-17 01:00:44 -07001076 if($3 == nil && $5 == nil)
Ken Thompsonf24f8ff2008-07-19 18:39:12 -07001077 $$->nname = renameinit($1);
Russ Cox35e59062009-07-17 14:42:14 -07001078 n = nod(OTFUNC, N, N);
1079 n->list = $3;
1080 n->rlist = $5;
Russ Coxb6487162009-08-07 12:50:26 -07001081 // TODO: check if nname already has an ntype
1082 $$->nname->ntype = n;
Rob Pike0cafb9e2008-06-04 14:37:38 -07001083 funchdr($$);
1084 }
Russ Cox39974952009-12-11 15:59:41 -08001085| '(' oarg_type_list_ocomma ')' new_name '(' oarg_type_list_ocomma ')' fnres
Rob Pike0cafb9e2008-06-04 14:37:38 -07001086 {
Russ Coxb6487162009-08-07 12:50:26 -07001087 Node *rcvr, *t;
Russ Coxe52e9ca2009-07-17 01:00:44 -07001088
Russ Coxa3382312009-11-15 12:57:09 -08001089 $$ = N;
1090 if($2 == nil) {
1091 yyerror("method has no receiver");
1092 break;
1093 }
1094 if($2->next != nil) {
1095 yyerror("method has multiple receivers");
1096 break;
1097 }
Russ Coxe52e9ca2009-07-17 01:00:44 -07001098 rcvr = $2->n;
Russ Coxa3382312009-11-15 12:57:09 -08001099 if(rcvr->op != ODCLFIELD) {
Russ Coxe52e9ca2009-07-17 01:00:44 -07001100 yyerror("bad receiver in method");
Russ Coxa3382312009-11-15 12:57:09 -08001101 break;
Russ Coxe52e9ca2009-07-17 01:00:44 -07001102 }
1103
Rob Pike0cafb9e2008-06-04 14:37:38 -07001104 $$ = nod(ODCLFUNC, N, N);
Russ Coxb6487162009-08-07 12:50:26 -07001105 $$->nname = methodname1($4, rcvr->right);
1106 t = nod(OTFUNC, rcvr, N);
1107 t->list = $6;
1108 t->rlist = $8;
1109 $$->nname->ntype = t;
1110 $$->shortname = $4;
Russ Coxe52e9ca2009-07-17 01:00:44 -07001111 funchdr($$);
Rob Pike0cafb9e2008-06-04 14:37:38 -07001112 }
1113
Rob Pike0cafb9e2008-06-04 14:37:38 -07001114fntype:
Russ Cox39974952009-12-11 15:59:41 -08001115 LFUNC '(' oarg_type_list_ocomma ')' fnres
Ken Thompson0194aaf2008-09-05 19:50:34 -07001116 {
Russ Coxdb508ccbf2009-07-17 13:38:16 -07001117 $$ = nod(OTFUNC, N, N);
1118 $$->list = $3;
1119 $$->rlist = $5;
Rob Pike0cafb9e2008-06-04 14:37:38 -07001120 }
1121
Rob Pike0cafb9e2008-06-04 14:37:38 -07001122fnbody:
Russ Coxe52e9ca2009-07-17 01:00:44 -07001123 {
1124 $$ = nil;
1125 }
1126| '{' stmt_list '}'
Rob Pike0cafb9e2008-06-04 14:37:38 -07001127 {
Ken Thompson417a9712008-07-05 12:49:25 -07001128 $$ = $2;
Russ Coxe52e9ca2009-07-17 01:00:44 -07001129 if($$ == nil)
Russ Cox0b2683d2009-07-27 14:36:32 -07001130 $$ = list1(nod(OEMPTY, N, N));
Rob Pike0cafb9e2008-06-04 14:37:38 -07001131 }
Ken Thompson417a9712008-07-05 12:49:25 -07001132
Rob Pike0cafb9e2008-06-04 14:37:38 -07001133fnres:
Russ Cox63985b42009-03-05 15:57:03 -08001134 %prec NotParen
Russ Coxd364d282008-10-07 12:36:30 -07001135 {
Russ Coxe52e9ca2009-07-17 01:00:44 -07001136 $$ = nil;
Russ Coxd364d282008-10-07 12:36:30 -07001137 }
Russ Cox8abcdee2009-06-06 19:27:48 -07001138| non_fn_type
Rob Pike0cafb9e2008-06-04 14:37:38 -07001139 {
Russ Coxe52e9ca2009-07-17 01:00:44 -07001140 $$ = list1(nod(ODCLFIELD, N, $1));
Rob Pike0cafb9e2008-06-04 14:37:38 -07001141 }
Russ Cox39974952009-12-11 15:59:41 -08001142| '(' oarg_type_list_ocomma ')'
Rob Pike0cafb9e2008-06-04 14:37:38 -07001143 {
1144 $$ = $2;
1145 }
1146
Russ Coxb6487162009-08-07 12:50:26 -07001147fnlitdcl:
1148 fntype
1149 {
1150 closurehdr($1);
1151 }
1152
1153fnliteral:
1154 fnlitdcl '{' stmt_list '}'
1155 {
1156 $$ = closurebody($3);
1157 }
1158
1159
Rob Pike0cafb9e2008-06-04 14:37:38 -07001160/*
1161 * lists of things
1162 * note that they are left recursive
1163 * to conserve yacc stack. they need to
1164 * be reversed to interpret correctly
1165 */
Russ Coxe52e9ca2009-07-17 01:00:44 -07001166xdcl_list:
Rob Pike0cafb9e2008-06-04 14:37:38 -07001167 {
Russ Coxe52e9ca2009-07-17 01:00:44 -07001168 $$ = nil;
1169 }
Russ Cox39974952009-12-11 15:59:41 -08001170| xdcl_list xdcl ';'
Russ Coxe52e9ca2009-07-17 01:00:44 -07001171 {
1172 $$ = concat($1, $2);
Russ Cox23724082009-10-12 11:03:48 -07001173 if(nsyntaxerrors == 0)
1174 testdclstack();
Rob Pike0cafb9e2008-06-04 14:37:38 -07001175 }
1176
Russ Coxe52e9ca2009-07-17 01:00:44 -07001177vardcl_list:
Rob Pike0cafb9e2008-06-04 14:37:38 -07001178 vardcl
Russ Coxe52e9ca2009-07-17 01:00:44 -07001179| vardcl_list ';' vardcl
Rob Pike0cafb9e2008-06-04 14:37:38 -07001180 {
Russ Coxe52e9ca2009-07-17 01:00:44 -07001181 $$ = concat($1, $3);
Rob Pike0cafb9e2008-06-04 14:37:38 -07001182 }
1183
Russ Coxe52e9ca2009-07-17 01:00:44 -07001184constdcl_list:
Ken Thompson9dbaab52008-09-04 12:21:10 -07001185 constdcl1
Russ Coxe52e9ca2009-07-17 01:00:44 -07001186| constdcl_list ';' constdcl1
Russ Coxdb508ccbf2009-07-17 13:38:16 -07001187 {
1188 $$ = concat($1, $3);
1189 }
Rob Pike0cafb9e2008-06-04 14:37:38 -07001190
Russ Coxe52e9ca2009-07-17 01:00:44 -07001191typedcl_list:
Rob Pike0cafb9e2008-06-04 14:37:38 -07001192 typedcl
Russ Coxdb508ccbf2009-07-17 13:38:16 -07001193 {
1194 $$ = list1($1);
1195 }
Russ Coxe52e9ca2009-07-17 01:00:44 -07001196| typedcl_list ';' typedcl
Russ Coxdb508ccbf2009-07-17 13:38:16 -07001197 {
1198 $$ = list($1, $3);
1199 }
Rob Pike0cafb9e2008-06-04 14:37:38 -07001200
Russ Coxe52e9ca2009-07-17 01:00:44 -07001201structdcl_list:
Rob Pike0cafb9e2008-06-04 14:37:38 -07001202 structdcl
Russ Coxe52e9ca2009-07-17 01:00:44 -07001203| structdcl_list ';' structdcl
Rob Pike0cafb9e2008-06-04 14:37:38 -07001204 {
Russ Coxe52e9ca2009-07-17 01:00:44 -07001205 $$ = concat($1, $3);
Rob Pike0cafb9e2008-06-04 14:37:38 -07001206 }
1207
Russ Coxe52e9ca2009-07-17 01:00:44 -07001208interfacedcl_list:
Rob Pike0cafb9e2008-06-04 14:37:38 -07001209 interfacedcl
Russ Cox7743ffe2009-09-28 14:05:34 -07001210 {
1211 $$ = list1($1);
1212 }
Russ Coxe52e9ca2009-07-17 01:00:44 -07001213| interfacedcl_list ';' interfacedcl
Rob Pike0cafb9e2008-06-04 14:37:38 -07001214 {
Russ Cox7743ffe2009-09-28 14:05:34 -07001215 $$ = list($1, $3);
Rob Pike0cafb9e2008-06-04 14:37:38 -07001216 }
1217
1218structdcl:
Russ Coxdb508ccbf2009-07-17 13:38:16 -07001219 new_name_list ntype oliteral
Rob Pike0cafb9e2008-06-04 14:37:38 -07001220 {
Russ Coxe52e9ca2009-07-17 01:00:44 -07001221 NodeList *l;
1222
1223 for(l=$1; l; l=l->next) {
1224 l->n = nod(ODCLFIELD, l->n, $2);
1225 l->n->val = $3;
1226 }
Rob Pike0cafb9e2008-06-04 14:37:38 -07001227 }
Russ Coxf2b153632008-10-30 15:29:55 -07001228| embed oliteral
1229 {
Russ Coxe52e9ca2009-07-17 01:00:44 -07001230 $1->val = $2;
1231 $$ = list1($1);
Russ Coxf2b153632008-10-30 15:29:55 -07001232 }
1233| '*' embed oliteral
Ken Thompson9f3d6002008-09-26 21:27:26 -07001234 {
Russ Coxe52e9ca2009-07-17 01:00:44 -07001235 $2->right = nod(OIND, $2->right, N);
1236 $2->val = $3;
1237 $$ = list1($2);
Ken Thompson0347e952008-10-21 15:04:10 -07001238 }
1239
Russ Cox8f4af6d2009-06-06 12:46:38 -07001240packname:
1241 LNAME
Russ Cox73e52ae2009-09-17 16:42:10 -07001242 {
1243 Node *n;
1244
1245 $$ = $1;
1246 n = oldname($1);
1247 if(n->pack != N)
1248 n->pack->used = 1;
1249 }
Russ Cox8f4af6d2009-06-06 12:46:38 -07001250| LNAME '.' sym
1251 {
1252 char *pkg;
1253
1254 if($1->def == N || $1->def->op != OPACK) {
1255 yyerror("%S is not a package", $1);
1256 pkg = $1->name;
Russ Cox73e52ae2009-09-17 16:42:10 -07001257 } else {
1258 $1->def->used = 1;
Russ Cox8f4af6d2009-06-06 12:46:38 -07001259 pkg = $1->def->sym->name;
Russ Cox73e52ae2009-09-17 16:42:10 -07001260 }
Russ Coxbe16caf2009-07-13 23:38:39 -07001261 $$ = restrictlookup($3->name, pkg);
Russ Cox8f4af6d2009-06-06 12:46:38 -07001262 }
1263
Ken Thompson14c63912008-10-21 20:55:40 -07001264embed:
Russ Cox8f4af6d2009-06-06 12:46:38 -07001265 packname
Ken Thompson0347e952008-10-21 15:04:10 -07001266 {
Ken Thompson14c63912008-10-21 20:55:40 -07001267 $$ = embedded($1);
Ken Thompson61361af2008-10-19 20:13:37 -07001268 }
Rob Pike0cafb9e2008-06-04 14:37:38 -07001269
Russ Coxb4af09a2009-02-16 16:36:18 -08001270interfacedcl:
Russ Cox7743ffe2009-09-28 14:05:34 -07001271 new_name indcl
Russ Coxe52e9ca2009-07-17 01:00:44 -07001272 {
Russ Cox7743ffe2009-09-28 14:05:34 -07001273 $$ = nod(ODCLFIELD, $1, $2);
Russ Coxe52e9ca2009-07-17 01:00:44 -07001274 }
Russ Cox8f4af6d2009-06-06 12:46:38 -07001275| packname
Russ Coxb4af09a2009-02-16 16:36:18 -08001276 {
Russ Cox7743ffe2009-09-28 14:05:34 -07001277 $$ = nod(ODCLFIELD, N, oldname($1));
Russ Coxb4af09a2009-02-16 16:36:18 -08001278 }
1279
Ken Thompson0194aaf2008-09-05 19:50:34 -07001280indcl:
Russ Cox39974952009-12-11 15:59:41 -08001281 '(' oarg_type_list_ocomma ')' fnres
Rob Pike0cafb9e2008-06-04 14:37:38 -07001282 {
1283 // without func keyword
Russ Cox35e59062009-07-17 14:42:14 -07001284 $$ = nod(OTFUNC, fakethis(), N);
1285 $$->list = $2;
1286 $$->rlist = $4;
Rob Pike0cafb9e2008-06-04 14:37:38 -07001287 }
Rob Pike0cafb9e2008-06-04 14:37:38 -07001288
Russ Cox4d571c92008-09-30 12:53:11 -07001289/*
1290 * function arguments.
Russ Cox4d571c92008-09-30 12:53:11 -07001291 */
Russ Cox8f4af6d2009-06-06 12:46:38 -07001292arg_type:
1293 name_or_type
1294| sym name_or_type
Rob Pike0cafb9e2008-06-04 14:37:38 -07001295 {
Russ Cox5d16d232009-09-09 00:18:16 -07001296 $$ = nod(ONONAME, N, N);
1297 $$->sym = $1;
Russ Cox8f4af6d2009-06-06 12:46:38 -07001298 $$ = nod(OKEY, $$, $2);
Rob Pike0cafb9e2008-06-04 14:37:38 -07001299 }
Russ Cox8f4af6d2009-06-06 12:46:38 -07001300| sym dotdotdot
Ken Thompsonc21d9a12008-10-29 12:46:44 -07001301 {
Russ Cox5d16d232009-09-09 00:18:16 -07001302 $$ = nod(ONONAME, N, N);
1303 $$->sym = $1;
Russ Coxbe16caf2009-07-13 23:38:39 -07001304 $$ = nod(OKEY, $$, $2);
Ken Thompsonc21d9a12008-10-29 12:46:44 -07001305 }
Russ Cox8f4af6d2009-06-06 12:46:38 -07001306| dotdotdot
Rob Pike0cafb9e2008-06-04 14:37:38 -07001307
Russ Coxe52e9ca2009-07-17 01:00:44 -07001308arg_type_list:
Russ Cox8f4af6d2009-06-06 12:46:38 -07001309 arg_type
Russ Cox4d571c92008-09-30 12:53:11 -07001310 {
Russ Coxe52e9ca2009-07-17 01:00:44 -07001311 $$ = list1($1);
1312 }
1313| arg_type_list ',' arg_type
1314 {
1315 $$ = list($1, $3);
Russ Cox4d571c92008-09-30 12:53:11 -07001316 }
1317
Russ Cox39974952009-12-11 15:59:41 -08001318oarg_type_list_ocomma:
Russ Cox4d571c92008-09-30 12:53:11 -07001319 {
Russ Coxe52e9ca2009-07-17 01:00:44 -07001320 $$ = nil;
1321 }
Russ Cox39974952009-12-11 15:59:41 -08001322| arg_type_list ocomma
Russ Coxe52e9ca2009-07-17 01:00:44 -07001323 {
1324 $$ = checkarglist($1);
Rob Pike0cafb9e2008-06-04 14:37:38 -07001325 }
1326
Ken Thompson36bfd2a2008-06-08 16:11:14 -07001327/*
Russ Cox8abcdee2009-06-06 19:27:48 -07001328 * statement
Ken Thompson36bfd2a2008-06-08 16:11:14 -07001329 */
Russ Cox8abcdee2009-06-06 19:27:48 -07001330stmt:
Ken Thompson610644a2008-06-08 17:21:46 -07001331 {
1332 $$ = N;
1333 }
Russ Coxd364d282008-10-07 12:36:30 -07001334| simple_stmt
Russ Cox8abcdee2009-06-06 19:27:48 -07001335| compound_stmt
1336| common_dcl
Russ Coxe52e9ca2009-07-17 01:00:44 -07001337 {
1338 $$ = liststmt($1);
1339 }
Russ Cox8abcdee2009-06-06 19:27:48 -07001340| for_stmt
1341| switch_stmt
1342| select_stmt
1343| if_stmt
Rob Pike0cafb9e2008-06-04 14:37:38 -07001344 {
Russ Cox8abcdee2009-06-06 19:27:48 -07001345 popdcl();
1346 $$ = $1;
Rob Pike0cafb9e2008-06-04 14:37:38 -07001347 }
Russ Cox8abcdee2009-06-06 19:27:48 -07001348| if_stmt LELSE stmt
Ken Thompson8200a0b2008-06-08 12:48:37 -07001349 {
Russ Cox8abcdee2009-06-06 19:27:48 -07001350 popdcl();
1351 $$ = $1;
Russ Coxe52e9ca2009-07-17 01:00:44 -07001352 $$->nelse = list1($3);
Russ Cox8abcdee2009-06-06 19:27:48 -07001353 }
1354| error
1355 {
1356 $$ = N;
1357 }
1358| labelname ':' stmt
1359 {
Russ Coxe52e9ca2009-07-17 01:00:44 -07001360 NodeList *l;
1361
Russ Cox62c48182009-10-19 20:39:18 -07001362 l = list1(nod(OLABEL, $1, $3));
Russ Coxe52e9ca2009-07-17 01:00:44 -07001363 if($3)
1364 l = list(l, $3);
1365 $$ = liststmt(l);
Russ Cox8abcdee2009-06-06 19:27:48 -07001366 }
1367| LFALL
1368 {
1369 // will be converted to OFALL
1370 $$ = nod(OXFALL, N, N);
1371 }
1372| LBREAK onew_name
1373 {
1374 $$ = nod(OBREAK, $2, N);
1375 }
1376| LCONTINUE onew_name
1377 {
1378 $$ = nod(OCONTINUE, $2, N);
1379 }
1380| LGO pseudocall
1381 {
1382 $$ = nod(OPROC, $2, N);
1383 }
1384| LDEFER pseudocall
1385 {
1386 $$ = nod(ODEFER, $2, N);
1387 }
1388| LGOTO new_name
1389 {
1390 $$ = nod(OGOTO, $2, N);
1391 }
1392| LRETURN oexpr_list
1393 {
Russ Coxe52e9ca2009-07-17 01:00:44 -07001394 $$ = nod(ORETURN, N, N);
1395 $$->list = $2;
Ken Thompson8200a0b2008-06-08 12:48:37 -07001396 }
Ken Thompson8200a0b2008-06-08 12:48:37 -07001397
Russ Coxe52e9ca2009-07-17 01:00:44 -07001398stmt_list:
Russ Cox8abcdee2009-06-06 19:27:48 -07001399 stmt
Russ Coxe52e9ca2009-07-17 01:00:44 -07001400 {
1401 $$ = nil;
1402 if($1 != N)
1403 $$ = list1($1);
1404 }
1405| stmt_list ';' stmt
1406 {
1407 $$ = $1;
1408 if($3 != N)
1409 $$ = list($$, $3);
1410 }
1411
Russ Coxdb508ccbf2009-07-17 13:38:16 -07001412new_name_list:
1413 new_name
Russ Coxe52e9ca2009-07-17 01:00:44 -07001414 {
Russ Coxdb508ccbf2009-07-17 13:38:16 -07001415 $$ = list1($1);
Russ Coxe52e9ca2009-07-17 01:00:44 -07001416 }
Russ Coxdb508ccbf2009-07-17 13:38:16 -07001417| new_name_list ',' new_name
Russ Coxe52e9ca2009-07-17 01:00:44 -07001418 {
Russ Coxdb508ccbf2009-07-17 13:38:16 -07001419 $$ = list($1, $3);
1420 }
1421
1422dcl_name_list:
1423 dcl_name
1424 {
1425 $$ = list1($1);
1426 }
1427| dcl_name_list ',' dcl_name
1428 {
1429 $$ = list($1, $3);
Russ Coxe52e9ca2009-07-17 01:00:44 -07001430 }
1431
1432expr_list:
1433 expr
1434 {
1435 $$ = list1($1);
1436 }
1437| expr_list ',' expr
Russ Cox8abcdee2009-06-06 19:27:48 -07001438 {
1439 $$ = list($1, $3);
1440 }
Rob Pike0cafb9e2008-06-04 14:37:38 -07001441
Russ Coxe52e9ca2009-07-17 01:00:44 -07001442expr_or_type_list:
Russ Cox8f4af6d2009-06-06 12:46:38 -07001443 expr_or_type
Ken Thompsone8278bc2008-10-26 14:04:09 -07001444 {
Russ Coxe52e9ca2009-07-17 01:00:44 -07001445 $$ = list1($1);
Ken Thompsone8278bc2008-10-26 14:04:09 -07001446 }
Russ Coxe52e9ca2009-07-17 01:00:44 -07001447| expr_or_type_list ',' expr_or_type
Rob Pike0cafb9e2008-06-04 14:37:38 -07001448 {
Russ Coxe52e9ca2009-07-17 01:00:44 -07001449 $$ = list($1, $3);
Rob Pike0cafb9e2008-06-04 14:37:38 -07001450 }
1451
Ken Thompsona0160812009-05-21 13:46:07 -07001452/*
1453 * list of combo of keyval and val
1454 */
Russ Coxe52e9ca2009-07-17 01:00:44 -07001455keyval_list:
Rob Pike0cafb9e2008-06-04 14:37:38 -07001456 keyval
Russ Coxe52e9ca2009-07-17 01:00:44 -07001457 {
1458 $$ = list1($1);
1459 }
Ken Thompsona0160812009-05-21 13:46:07 -07001460| expr
Rob Pike0cafb9e2008-06-04 14:37:38 -07001461 {
Russ Coxe52e9ca2009-07-17 01:00:44 -07001462 $$ = list1($1);
Rob Pike0cafb9e2008-06-04 14:37:38 -07001463 }
Russ Coxe52e9ca2009-07-17 01:00:44 -07001464| keyval_list ',' keyval
Ken Thompsona0160812009-05-21 13:46:07 -07001465 {
Russ Coxe52e9ca2009-07-17 01:00:44 -07001466 $$ = list($1, $3);
1467 }
1468| keyval_list ',' expr
1469 {
1470 $$ = list($1, $3);
Ken Thompsona0160812009-05-21 13:46:07 -07001471 }
Rob Pike0cafb9e2008-06-04 14:37:38 -07001472
Russ Coxe52e9ca2009-07-17 01:00:44 -07001473braced_keyval_list:
Russ Cox82e41cc2008-10-14 17:10:39 -07001474 {
Russ Coxe52e9ca2009-07-17 01:00:44 -07001475 $$ = nil;
Russ Cox82e41cc2008-10-14 17:10:39 -07001476 }
Russ Coxe52e9ca2009-07-17 01:00:44 -07001477| keyval_list ocomma
Russ Cox82e41cc2008-10-14 17:10:39 -07001478 {
Russ Coxe52e9ca2009-07-17 01:00:44 -07001479 $$ = $1;
Russ Cox82e41cc2008-10-14 17:10:39 -07001480 }
Russ Cox82e41cc2008-10-14 17:10:39 -07001481
Rob Pike0cafb9e2008-06-04 14:37:38 -07001482/*
1483 * optional things
1484 */
1485osemi:
1486| ';'
1487
1488ocomma:
1489| ','
1490
1491oexpr:
1492 {
1493 $$ = N;
1494 }
1495| expr
1496
1497oexpr_list:
1498 {
Russ Coxe52e9ca2009-07-17 01:00:44 -07001499 $$ = nil;
Rob Pike0cafb9e2008-06-04 14:37:38 -07001500 }
1501| expr_list
1502
Russ Cox39974952009-12-11 15:59:41 -08001503oexpr_or_type_list_ocomma:
Russ Cox8f4af6d2009-06-06 12:46:38 -07001504 {
Russ Coxe52e9ca2009-07-17 01:00:44 -07001505 $$ = nil;
Russ Cox8f4af6d2009-06-06 12:46:38 -07001506 }
Russ Cox39974952009-12-11 15:59:41 -08001507| expr_or_type_list ocomma
Russ Cox8f4af6d2009-06-06 12:46:38 -07001508
Rob Pike0cafb9e2008-06-04 14:37:38 -07001509osimple_stmt:
1510 {
1511 $$ = N;
1512 }
1513| simple_stmt
1514
Russ Coxb8babed2008-10-03 16:15:55 -07001515ohidden_funarg_list:
1516 {
Russ Coxe52e9ca2009-07-17 01:00:44 -07001517 $$ = nil;
Russ Coxb8babed2008-10-03 16:15:55 -07001518 }
1519| hidden_funarg_list
1520
1521ohidden_structdcl_list:
1522 {
Russ Coxe52e9ca2009-07-17 01:00:44 -07001523 $$ = nil;
Russ Coxb8babed2008-10-03 16:15:55 -07001524 }
1525| hidden_structdcl_list
1526
1527ohidden_interfacedcl_list:
1528 {
Russ Coxe52e9ca2009-07-17 01:00:44 -07001529 $$ = nil;
Russ Coxb8babed2008-10-03 16:15:55 -07001530 }
1531| hidden_interfacedcl_list
1532
Russ Coxf27aaf42008-10-30 15:13:09 -07001533oliteral:
1534 {
1535 $$.ctype = CTxxx;
1536 }
1537| LLITERAL
1538
Rob Pike0cafb9e2008-06-04 14:37:38 -07001539/*
1540 * import syntax from header of
1541 * an output package
1542 */
1543hidden_import:
Russ Cox39974952009-12-11 15:59:41 -08001544 LPACKAGE sym ';'
Rob Pike0cafb9e2008-06-04 14:37:38 -07001545 /* variables */
Russ Cox39974952009-12-11 15:59:41 -08001546| LVAR hidden_pkg_importsym hidden_type ';'
Rob Pike0cafb9e2008-06-04 14:37:38 -07001547 {
Russ Cox4a431982009-01-30 14:39:42 -08001548 importvar($2, $3, PEXTERN);
Russ Coxb8babed2008-10-03 16:15:55 -07001549 }
Russ Cox39974952009-12-11 15:59:41 -08001550| LCONST hidden_pkg_importsym '=' hidden_constant ';'
Russ Coxb8babed2008-10-03 16:15:55 -07001551 {
Russ Cox8f194bf2009-03-12 19:04:38 -07001552 importconst($2, types[TIDEAL], $4);
Russ Coxb8babed2008-10-03 16:15:55 -07001553 }
Russ Cox39974952009-12-11 15:59:41 -08001554| LCONST hidden_pkg_importsym hidden_type '=' hidden_constant ';'
Russ Coxb8babed2008-10-03 16:15:55 -07001555 {
Russ Cox8f194bf2009-03-12 19:04:38 -07001556 importconst($2, $3, $5);
Russ Coxb8babed2008-10-03 16:15:55 -07001557 }
Russ Cox39974952009-12-11 15:59:41 -08001558| LTYPE hidden_pkgtype hidden_type ';'
Russ Coxb8babed2008-10-03 16:15:55 -07001559 {
Russ Cox0183baa2009-01-20 14:40:00 -08001560 importtype($2, $3);
Russ Coxb8babed2008-10-03 16:15:55 -07001561 }
Russ Cox39974952009-12-11 15:59:41 -08001562| LFUNC hidden_pkg_importsym '(' ohidden_funarg_list ')' ohidden_funres ';'
Russ Coxb8babed2008-10-03 16:15:55 -07001563 {
Russ Cox4a431982009-01-30 14:39:42 -08001564 importvar($2, functype(N, $4, $6), PFUNC);
Russ Coxb8babed2008-10-03 16:15:55 -07001565 }
Russ Cox39974952009-12-11 15:59:41 -08001566| LFUNC '(' hidden_funarg_list ')' sym '(' ohidden_funarg_list ')' ohidden_funres ';'
Russ Coxb8babed2008-10-03 16:15:55 -07001567 {
Russ Coxe52e9ca2009-07-17 01:00:44 -07001568 if($3->next != nil || $3->n->op != ODCLFIELD) {
Russ Coxb8babed2008-10-03 16:15:55 -07001569 yyerror("bad receiver in method");
1570 YYERROR;
1571 }
Russ Coxe52e9ca2009-07-17 01:00:44 -07001572 importmethod($5, functype($3->n, $7, $9));
Rob Pike0cafb9e2008-06-04 14:37:38 -07001573 }
1574
Russ Coxb6487162009-08-07 12:50:26 -07001575hidden_pkgtype:
1576 hidden_pkg_importsym
1577 {
1578 $$ = pkgtype($1);
1579 importsym($1, OTYPE);
1580 }
1581
Russ Coxb8babed2008-10-03 16:15:55 -07001582hidden_type:
Russ Coxe7337662009-12-03 00:10:32 -08001583 hidden_type_misc
1584| hidden_type_chan
1585| hidden_type_func
Russ Coxb8babed2008-10-03 16:15:55 -07001586
Russ Coxe7337662009-12-03 00:10:32 -08001587hidden_type_non_chan:
1588 hidden_type_misc
1589| hidden_type_func
1590
1591hidden_type_non_func:
1592 hidden_type_misc
1593| hidden_type_chan
1594
1595hidden_type_misc:
Russ Coxb8babed2008-10-03 16:15:55 -07001596 hidden_importsym
Rob Pike0cafb9e2008-06-04 14:37:38 -07001597 {
Russ Cox8f4af6d2009-06-06 12:46:38 -07001598 $$ = pkgtype($1);
Rob Pike0cafb9e2008-06-04 14:37:38 -07001599 }
Russ Cox8f4af6d2009-06-06 12:46:38 -07001600| LNAME
Rob Pike0cafb9e2008-06-04 14:37:38 -07001601 {
Russ Coxa1214102009-08-04 22:59:23 -07001602 // predefined name like uint8
Russ Coxe780fa82009-09-09 01:01:39 -07001603 $1 = pkglookup($1->name, "/builtin/");
Russ Coxa1214102009-08-04 22:59:23 -07001604 if($1->def == N || $1->def->op != OTYPE) {
Russ Coxe780fa82009-09-09 01:01:39 -07001605 yyerror("%s is not a type", $1->name);
Russ Coxa1214102009-08-04 22:59:23 -07001606 $$ = T;
1607 } else
1608 $$ = $1->def->type;
Russ Coxb8babed2008-10-03 16:15:55 -07001609 }
1610| '[' ']' hidden_type
1611 {
1612 $$ = aindex(N, $3);
1613 }
1614| '[' LLITERAL ']' hidden_type
1615 {
Russ Cox8f194bf2009-03-12 19:04:38 -07001616 $$ = aindex(nodlit($2), $4);
Russ Coxb8babed2008-10-03 16:15:55 -07001617 }
1618| LMAP '[' hidden_type ']' hidden_type
1619 {
Russ Cox98b34e52009-03-04 17:38:37 -08001620 $$ = maptype($3, $5);
Russ Coxb8babed2008-10-03 16:15:55 -07001621 }
1622| LSTRUCT '{' ohidden_structdcl_list '}'
1623 {
1624 $$ = dostruct($3, TSTRUCT);
1625 }
1626| LINTERFACE '{' ohidden_interfacedcl_list '}'
1627 {
1628 $$ = dostruct($3, TINTER);
1629 $$ = sortinter($$);
1630 }
1631| '*' hidden_type
1632 {
Russ Coxb8babed2008-10-03 16:15:55 -07001633 $$ = ptrto($2);
1634 }
1635| LCOMM LCHAN hidden_type
1636 {
1637 $$ = typ(TCHAN);
1638 $$->type = $3;
1639 $$->chan = Crecv;
1640 }
Russ Coxe7337662009-12-03 00:10:32 -08001641| LCHAN LCOMM hidden_type_non_chan
Russ Coxb8babed2008-10-03 16:15:55 -07001642 {
1643 $$ = typ(TCHAN);
1644 $$->type = $3;
1645 $$->chan = Csend;
Rob Pike0cafb9e2008-06-04 14:37:38 -07001646 }
Russ Coxe7337662009-12-03 00:10:32 -08001647| LCHAN LCOMM '(' hidden_type_chan ')'
1648 {
1649 $$ = typ(TCHAN);
1650 $$->type = $4;
1651 $$->chan = Csend;
1652 }
Ken Thompson2fef4c72008-11-01 16:52:12 -07001653| LDDD
1654 {
1655 $$ = typ(TDDD);
1656 }
Rob Pike0cafb9e2008-06-04 14:37:38 -07001657
Russ Coxe7337662009-12-03 00:10:32 -08001658hidden_type_chan:
Russ Coxb8babed2008-10-03 16:15:55 -07001659 LCHAN hidden_type
Rob Pike0cafb9e2008-06-04 14:37:38 -07001660 {
Russ Coxb8babed2008-10-03 16:15:55 -07001661 $$ = typ(TCHAN);
1662 $$->type = $2;
1663 $$->chan = Cboth;
Rob Pike0cafb9e2008-06-04 14:37:38 -07001664 }
Russ Coxe7337662009-12-03 00:10:32 -08001665
1666hidden_type_func:
1667 LFUNC '(' ohidden_funarg_list ')' ohidden_funres
Rob Pike0cafb9e2008-06-04 14:37:38 -07001668 {
Russ Coxe52e9ca2009-07-17 01:00:44 -07001669 $$ = functype(nil, $3, $5);
Rob Pike0cafb9e2008-06-04 14:37:38 -07001670 }
Russ Coxb8babed2008-10-03 16:15:55 -07001671
1672hidden_dcl:
Russ Cox8f4af6d2009-06-06 12:46:38 -07001673 sym hidden_type
Ken Thompson66a603c2008-08-27 17:28:30 -07001674 {
Russ Coxb6487162009-08-07 12:50:26 -07001675 $$ = nod(ODCLFIELD, newname($1), typenod($2));
Ken Thompson66a603c2008-08-27 17:28:30 -07001676 }
Russ Coxb8babed2008-10-03 16:15:55 -07001677| '?' hidden_type
Rob Pike0cafb9e2008-06-04 14:37:38 -07001678 {
Russ Coxb6487162009-08-07 12:50:26 -07001679 $$ = nod(ODCLFIELD, N, typenod($2));
Rob Pike0cafb9e2008-06-04 14:37:38 -07001680 }
Russ Coxb8babed2008-10-03 16:15:55 -07001681
Russ Cox21617252008-10-22 13:22:56 -07001682hidden_structdcl:
Russ Cox8f4af6d2009-06-06 12:46:38 -07001683 sym hidden_type oliteral
Russ Cox21617252008-10-22 13:22:56 -07001684 {
Russ Coxbe16caf2009-07-13 23:38:39 -07001685 $$ = nod(ODCLFIELD, newname($1), typenod($2));
Russ Cox1850b292008-10-30 15:25:26 -07001686 $$->val = $3;
Russ Cox21617252008-10-22 13:22:56 -07001687 }
Russ Coxf2b153632008-10-30 15:29:55 -07001688| '?' hidden_type oliteral
Russ Cox21617252008-10-22 13:22:56 -07001689 {
Russ Coxe780fa82009-09-09 01:01:39 -07001690 Sym *s;
1691
1692 s = $2->sym;
1693 if(s == S && isptr[$2->etype])
1694 s = $2->type->sym;
1695 if(s && strcmp(s->package, "/builtin/") == 0)
1696 s = lookup(s->name);
1697 $$ = embedded(s);
1698 $$->right = typenod($2);
Russ Coxf2b153632008-10-30 15:29:55 -07001699 $$->val = $3;
Russ Cox21617252008-10-22 13:22:56 -07001700 }
1701
Russ Coxb8babed2008-10-03 16:15:55 -07001702hidden_interfacedcl:
Russ Cox8f4af6d2009-06-06 12:46:38 -07001703 sym '(' ohidden_funarg_list ')' ohidden_funres
Rob Pike0cafb9e2008-06-04 14:37:38 -07001704 {
Russ Coxbe16caf2009-07-13 23:38:39 -07001705 $$ = nod(ODCLFIELD, newname($1), typenod(functype(fakethis(), $3, $5)));
Rob Pike0cafb9e2008-06-04 14:37:38 -07001706 }
Russ Coxb8babed2008-10-03 16:15:55 -07001707
1708ohidden_funres:
Rob Pike0cafb9e2008-06-04 14:37:38 -07001709 {
Russ Coxe52e9ca2009-07-17 01:00:44 -07001710 $$ = nil;
Rob Pike0cafb9e2008-06-04 14:37:38 -07001711 }
Russ Coxb8babed2008-10-03 16:15:55 -07001712| hidden_funres
1713
1714hidden_funres:
1715 '(' ohidden_funarg_list ')'
Rob Pike0cafb9e2008-06-04 14:37:38 -07001716 {
Russ Coxb8babed2008-10-03 16:15:55 -07001717 $$ = $2;
Rob Pike0cafb9e2008-06-04 14:37:38 -07001718 }
Russ Coxe7337662009-12-03 00:10:32 -08001719| hidden_type_non_func
Rob Pike0cafb9e2008-06-04 14:37:38 -07001720 {
Russ Coxb6487162009-08-07 12:50:26 -07001721 $$ = list1(nod(ODCLFIELD, N, typenod($1)));
Ken Thompson21192942008-09-14 16:57:55 -07001722 }
Rob Pike0cafb9e2008-06-04 14:37:38 -07001723
Russ Coxc3d841f2008-09-26 11:44:20 -07001724hidden_constant:
1725 LLITERAL
Russ Cox8f194bf2009-03-12 19:04:38 -07001726 {
1727 $$ = nodlit($1);
1728 }
Russ Coxc3d841f2008-09-26 11:44:20 -07001729| '-' LLITERAL
1730 {
Russ Cox8f194bf2009-03-12 19:04:38 -07001731 $$ = nodlit($2);
1732 switch($$->val.ctype){
Russ Coxc3d841f2008-09-26 11:44:20 -07001733 case CTINT:
Russ Cox8f194bf2009-03-12 19:04:38 -07001734 mpnegfix($$->val.u.xval);
Russ Coxc3d841f2008-09-26 11:44:20 -07001735 break;
1736 case CTFLT:
Russ Cox8f194bf2009-03-12 19:04:38 -07001737 mpnegflt($$->val.u.fval);
Russ Coxc3d841f2008-09-26 11:44:20 -07001738 break;
1739 default:
1740 yyerror("bad negated constant");
1741 }
1742 }
Russ Coxe780fa82009-09-09 01:01:39 -07001743| sym
Russ Coxdec12d32009-01-16 10:45:28 -08001744 {
Russ Coxe780fa82009-09-09 01:01:39 -07001745 $$ = oldname(pkglookup($1->name, "/builtin/"));
Russ Cox8f4af6d2009-06-06 12:46:38 -07001746 if($$->op != OLITERAL)
1747 yyerror("bad constant %S", $$->sym);
Russ Coxdec12d32009-01-16 10:45:28 -08001748 }
Russ Coxc3d841f2008-09-26 11:44:20 -07001749
Russ Coxb8babed2008-10-03 16:15:55 -07001750hidden_importsym:
Russ Cox8f4af6d2009-06-06 12:46:38 -07001751 sym '.' sym
Rob Pike0cafb9e2008-06-04 14:37:38 -07001752 {
Russ Cox8f4af6d2009-06-06 12:46:38 -07001753 $$ = pkglookup($3->name, $1->name);
Rob Pike0cafb9e2008-06-04 14:37:38 -07001754 }
Russ Cox13f31492008-09-18 13:32:14 -07001755
Russ Cox4efad582009-01-26 16:57:24 -08001756hidden_pkg_importsym:
1757 hidden_importsym
1758 {
1759 $$ = $1;
Russ Cox8f4af6d2009-06-06 12:46:38 -07001760 structpkg = $$->package;
Russ Cox4efad582009-01-26 16:57:24 -08001761 }
1762
Russ Coxe52e9ca2009-07-17 01:00:44 -07001763hidden_import_list:
1764| hidden_import_list hidden_import
Russ Cox4efad582009-01-26 16:57:24 -08001765
Russ Coxe52e9ca2009-07-17 01:00:44 -07001766hidden_funarg_list:
1767 hidden_dcl
1768 {
1769 $$ = list1($1);
1770 }
1771| hidden_funarg_list ',' hidden_dcl
1772 {
1773 $$ = list($1, $3);
1774 }
1775
1776hidden_structdcl_list:
1777 hidden_structdcl
1778 {
1779 $$ = list1($1);
1780 }
1781| hidden_structdcl_list ';' hidden_structdcl
1782 {
1783 $$ = list($1, $3);
1784 }
1785
1786hidden_interfacedcl_list:
1787 hidden_interfacedcl
1788 {
1789 $$ = list1($1);
1790 }
1791| hidden_interfacedcl_list ';' hidden_interfacedcl
1792 {
1793 $$ = list($1, $3);
1794 }