go.y 29.5 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14
// Copyright 2009 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

%{
#include "go.h"
%}
%union	{
	Node*		node;
	Type*		type;
	Sym*		sym;
	struct	Val	val;
	int		lint;
}
Ken Thompson's avatar
Ken Thompson committed
15 16
%token	<val>		LLITERAL
%token	<lint>		LASOP
Ken Thompson's avatar
Ken Thompson committed
17
%token	<sym>		LNAME LBASETYPE LATYPE LPACK LACONST
18
%token	<sym>		LPACKAGE LIMPORT LDEFER LCLOSE LCLOSED
Ken Thompson's avatar
Ken Thompson committed
19
%token	<sym>		LMAP LCHAN LINTERFACE LFUNC LSTRUCT
Ken Thompson's avatar
Ken Thompson committed
20
%token	<sym>		LCOLAS LFALL LRETURN LDDD
Ken Thompson's avatar
Ken Thompson committed
21
%token	<sym>		LLEN LCAP LPANIC LPANICN LPRINT LPRINTN
Ken Thompson's avatar
Ken Thompson committed
22
%token	<sym>		LVAR LTYPE LCONST LCONVERT LSELECT LMAKE LNEW
Ken Thompson's avatar
Ken Thompson committed
23 24 25 26
%token	<sym>		LFOR LIF LELSE LSWITCH LCASE LDEFAULT
%token	<sym>		LBREAK LCONTINUE LGO LGOTO LRANGE
%token	<sym>		LNIL LTRUE LFALSE LIOTA

27
%token			LOROR LANDAND LEQ LNE LLE LLT LGE LGT
28
%token			LLSH LRSH LINC LDEC LCOMM LANDNOT
Ken Thompson's avatar
Ken Thompson committed
29
%token			LIGNORE
30

Russ Cox's avatar
Russ Cox committed
31 32 33 34 35 36 37 38 39 40 41 42 43 44
/*
 * the go semicolon rules are:
 *
 *  1. all statements and declarations are terminated by semicolons
 *  2. semicolons can be omitted at top level.
 *  3. semicolons can be omitted before and after the closing ) or }
 *	on a list of statements or declarations.
 *
 * thus the grammar must distinguish productions that
 * can omit the semicolon terminator and those that can't.
 * names like Astmt, Avardcl, etc. can drop the semicolon.
 * names like Bstmt, Bvardcl, etc. can't.
 */

Ken Thompson's avatar
Ken Thompson committed
45
%type	<sym>		sym sym1 sym2 sym3 keyword laconst lname latype lpackatype
46 47
%type	<node>		xdcl xdcl_list_r oxdcl_list
%type	<node>		common_dcl Acommon_dcl Bcommon_dcl
48
%type	<node>		oarg_type_list arg_type_list_r arg_chunk arg_chunk_list_r arg_type_list
Russ Cox's avatar
Russ Cox committed
49
%type	<node>		Aelse_stmt Belse_stmt
Ken Thompson's avatar
Ken Thompson committed
50 51
%type	<node>		complex_stmt compound_stmt ostmt_list
%type	<node>		stmt_list_r Astmt_list_r Bstmt_list_r
Russ Cox's avatar
Russ Cox committed
52
%type	<node>		Astmt Bstmt
53
%type	<node>		for_stmt for_body for_header
54
%type	<node>		if_stmt if_body if_header select_stmt condition
Russ Cox's avatar
Russ Cox committed
55
%type	<node>		simple_stmt osimple_stmt range_stmt semi_stmt
56
%type	<node>		expr uexpr pexpr expr_list oexpr oexpr_list expr_list_r
Ken Thompson's avatar
Ken Thompson committed
57
%type	<node>		exprsym3_list_r exprsym3
Russ Cox's avatar
Russ Cox committed
58
%type	<node>		name labelname onew_name new_name new_name_list_r new_field
59
%type	<node>		vardcl_list_r vardcl Avardcl Bvardcl
60
%type	<node>		interfacedcl_list_r interfacedcl interfacedcl1
Ken Thompson's avatar
Ken Thompson committed
61
%type	<node>		structdcl_list_r structdcl embed
Ken Thompson's avatar
Ken Thompson committed
62
%type	<node>		fnres Afnres Bfnres fnliteral xfndcl fndcl fnbody
Russ Cox's avatar
Russ Cox committed
63
%type	<node>		braced_keyexpr_list keyval_list_r keyval
64

Russ Cox's avatar
Russ Cox committed
65 66 67 68 69 70 71 72
%type	<type>		typedclname new_type
%type	<type>		type Atype Btype
%type	<type>		othertype Aothertype Bothertype
%type	<type>		chantype Achantype Bchantype
%type	<type>		fntype Afntype Bfntype
%type	<type>		nametype structtype interfacetype convtype
%type	<type>		non_name_type Anon_fn_type Bnon_fn_type
%type	<type>		Anon_chan_type Bnon_chan_type
Ken Thompson's avatar
Ken Thompson committed
73
%type	<type>		indcl fnlitdcl dotdotdot
74
%type	<val>		oliteral
75

76
%type	<node>		hidden_constant
Russ Cox's avatar
Russ Cox committed
77
%type	<node>		hidden_dcl hidden_structdcl
Russ Cox's avatar
Russ Cox committed
78 79 80 81 82
%type	<type>		hidden_type hidden_type1 hidden_type2
%type	<node>		hidden_structdcl_list ohidden_structdcl_list hidden_structdcl_list_r
%type	<node>		hidden_interfacedcl_list ohidden_interfacedcl_list hidden_interfacedcl_list_r
%type	<node>		hidden_interfacedcl
%type	<node>		hidden_funarg_list ohidden_funarg_list hidden_funarg_list_r
Russ Cox's avatar
Russ Cox committed
83
%type	<node>		hidden_funres ohidden_funres hidden_importsym hidden_pkg_importsym
84

85 86
%left			LOROR
%left			LANDAND
Rob Pike's avatar
Rob Pike committed
87
%left			LCOMM
88 89
%left			LEQ LNE LLE LGE LLT LGT
%left			'+' '-' '|' '^'
90
%left			'*' '/' '%' '&' LLSH LRSH LANDNOT
Russ Cox's avatar
Russ Cox committed
91

92 93 94 95 96 97
/*
 * resolve { vs condition in favor of condition
 */
%left			'{'
%left			Condition

Russ Cox's avatar
Russ Cox committed
98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114
/*
 * resolve LPACKAGE vs not in favor of LPACKAGE
 */
%left			NotPackage
%left			LPACKAGE

/*
 * resolve '.' vs not in favor of '.'
 */
%left			NotDot
%left			'.'

/*
 * resolve '(' vs not in favor of '('
 */
%left			NotParen
%left			'('
115

116 117 118 119 120 121
%%
file:
	package import_there imports oxdcl_list
	{
		if(debug['f'])
			frame(1);
Ken Thompson's avatar
Ken Thompson committed
122
		fninit($4);
123 124 125 126
		testdclstack();
	}

package:
Russ Cox's avatar
Russ Cox committed
127
	%prec NotPackage
128 129 130
	{
		yyerror("package statement must be first");
		mkpackage("main");
Ken Thompson's avatar
Ken Thompson committed
131
		cannedimports("sys.6", sysimport);
132 133 134 135
	}
|	LPACKAGE sym
	{
		mkpackage($2->name);
Ken Thompson's avatar
Ken Thompson committed
136
		cannedimports("sys.6", sysimport);
137 138 139 140 141 142 143 144
	}

imports:
|	imports import

import:
	LIMPORT import_stmt
|	LIMPORT '(' import_stmt_list_r osemi ')'
145
|	LIMPORT '(' ')'
146 147

import_stmt:
Ken Thompson's avatar
Ken Thompson committed
148
	import_here import_package import_there
149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170

import_here:
	LLITERAL
	{
		// import with original name
		pkgmyname = S;
		importfile(&$1);
	}
|	sym LLITERAL
	{
		// import with given name
		pkgmyname = $1;
		pkgmyname->lexical = LPACK;
		importfile(&$2);
	}
|	'.' LLITERAL
	{
		// import with my name
		pkgmyname = lookup(package);
		importfile(&$2);
	}

Ken Thompson's avatar
Ken Thompson committed
171 172 173 174 175 176 177 178 179 180 181
import_package:
	LPACKAGE sym
	{
		pkgimportname = $2;

		// if we are not remapping the package name
		// then the imported package name is LPACK
		if(pkgmyname == S)
			pkgimportname->lexical = LPACK;
	}

182
import_there:
183
	hidden_import_list '$' '$'
184
	{
Ken Thompson's avatar
Ken Thompson committed
185
		checkimports();
186
		unimportfile();
187
		pkgimportname = S;
188
	}
189
|	LIMPORT '$' '$' hidden_import_list '$' '$'
Ken Thompson's avatar
Ken Thompson committed
190 191 192
	{
		checkimports();
	}
193

194 195 196 197 198 199 200 201 202
hidden_import_list:
	{
		defercheckwidth();
	}
	hidden_import_list_r
	{
		resumecheckwidth();
	}

203 204 205 206
/*
 * declarations
 */
xdcl:
207 208 209 210 211
	{ stksize = initstksize; } common_dcl
	{
		$$ = $2;
		initstksize = stksize;
	}
Ken Thompson's avatar
Ken Thompson committed
212
|	xfndcl
213
	{
Russ Cox's avatar
Russ Cox committed
214 215
		if($1 != N && $1->nname != N && $1->type->thistuple == 0)
			autoexport($1->nname->sym);
Ken Thompson's avatar
Ken Thompson committed
216
		$$ = N;
217
	}
218
|	LPACKAGE { warn("package is gone"); } xfndcl
219
	{
220 221
		if($3 != N && $3->nname != N)
			packagesym($3->nname->sym);
222 223
		$$ = N;
	}
224 225 226 227
|	';'
	{
		$$ = N;
	}
Ken Thompson's avatar
Ken Thompson committed
228
|	error xdcl
229
	{
Ken Thompson's avatar
Ken Thompson committed
230
		$$ = $2;
231
	}
232 233

common_dcl:
234 235 236 237 238
	Acommon_dcl
|	Bcommon_dcl

Acommon_dcl:
	LVAR Avardcl
239 240 241 242 243 244 245
	{
		$$ = $2;
	}
|	LVAR '(' vardcl_list_r osemi ')'
	{
		$$ = rev($3);
	}
246 247 248 249
|	LVAR '(' ')'
	{
		$$ = N;
	}
Ken Thompson's avatar
Ken Thompson committed
250 251 252 253 254 255 256
|	LCONST '(' constdcl osemi ')'
	{
		iota = 0;
		lastconst = N;
		$$ = N;
	}
|	LCONST '(' constdcl ';' constdcl_list_r osemi ')'
257 258
	{
		iota = 0;
Ken Thompson's avatar
Ken Thompson committed
259
		lastconst = N;
Ken Thompson's avatar
Ken Thompson committed
260
		$$ = N;
261
	}
262 263 264 265
|	LCONST '(' ')'
	{
		$$ = N;
	}
266
|	LTYPE Atypedcl
267 268 269
	{
		$$ = N;
	}
270
|	LTYPE '(' typedcl_list_r osemi ')'
271 272 273
	{
		$$ = N;
	}
274 275 276 277
|	LTYPE '(' ')'
	{
		$$ = N;
	}
278 279 280 281 282 283 284 285 286 287

Bcommon_dcl:
	LVAR Bvardcl
	{
		$$ = $2;
	}
|	LCONST constdcl
	{
		$$ = N;
		iota = 0;
Ken Thompson's avatar
Ken Thompson committed
288
		lastconst = N;
289 290
	}
|	LTYPE Btypedcl
291 292 293 294 295
	{
		$$ = N;
	}

vardcl:
296 297 298 299
	Avardcl
|	Bvardcl

Avardcl:
Russ Cox's avatar
Russ Cox committed
300
	new_name_list_r Atype
301 302 303 304 305
	{
		$$ = rev($1);
		dodclvar($$, $2);

		$$ = nod(OAS, $$, N);
306
		addtotop($$);
307 308 309
	}

Bvardcl:
Russ Cox's avatar
Russ Cox committed
310
	new_name_list_r Btype
311 312 313 314 315
	{
		$$ = rev($1);
		dodclvar($$, $2);

		$$ = nod(OAS, $$, N);
316
		addtotop($$);
317
	}
Ken Thompson's avatar
Ken Thompson committed
318
|	new_name_list_r type '=' expr_list
319
	{
320 321 322
		if(addtop != N)
			fatal("new_name_list_r type '=' expr_list");

323
		$$ = variter($1, $2, $4);
Ken Thompson's avatar
Ken Thompson committed
324
		addtotop($$);
325
	}
326
|	new_name_list_r '=' expr_list
327
	{
328 329 330 331 332
		if(addtop != N)
			fatal("new_name_list_r '=' expr_list");

		$$ = variter($1, T, $3);
		addtotop($$);
333 334 335
	}

constdcl:
336
	new_name_list_r type '=' expr_list
Ken Thompson's avatar
Ken Thompson committed
337
	{
338
		constiter($1, $2, $4);
Ken Thompson's avatar
Ken Thompson committed
339
	}
340
|	new_name_list_r '=' expr_list
341
	{
342
		constiter($1, T, $3);
Ken Thompson's avatar
Ken Thompson committed
343 344
	}

Ken Thompson's avatar
Ken Thompson committed
345 346
constdcl1:
	constdcl
347
|	new_name_list_r type
Ken Thompson's avatar
Ken Thompson committed
348
	{
349
		constiter($1, $2, N);
350
	}
351
|	new_name_list_r
352
	{
353
		constiter($1, T, N);
354 355
	}

356 357 358 359 360 361 362
typedclname:
	new_type
	{
		$$ = dodcltype($1);
		defercheckwidth();
	}

Russ Cox's avatar
Russ Cox committed
363 364 365 366
typedcl:
	Atypedcl
|	Btypedcl

367
Atypedcl:
Russ Cox's avatar
Russ Cox committed
368 369 370 371 372 373 374 375
	typedclname Atype
	{
		updatetype($1, $2);
		resumecheckwidth();
	}

Btypedcl:
	typedclname Btype
376 377 378 379 380
	{
		updatetype($1, $2);
		resumecheckwidth();
	}
|	typedclname LSTRUCT
381
	{
382 383
		updatetype($1, typ(TFORWSTRUCT));
		resumecheckwidth();
384
	}
385 386 387 388 389
|	typedclname LINTERFACE
	{
		updatetype($1, typ(TFORWINTER));
		resumecheckwidth();
	}
390

Russ Cox's avatar
Russ Cox committed
391
Aelse_stmt:
Ken Thompson's avatar
Ken Thompson committed
392
	complex_stmt
393 394
|	compound_stmt

Russ Cox's avatar
Russ Cox committed
395
Belse_stmt:
Ken Thompson's avatar
Ken Thompson committed
396 397 398
	simple_stmt
|	semi_stmt
|	';'
399
	{
Ken Thompson's avatar
Ken Thompson committed
400
		$$ = N;
401 402 403 404 405 406 407 408 409 410
	}

simple_stmt:
	expr
	{
		$$ = $1;
	}
|	expr LASOP expr
	{
		$$ = nod(OASOP, $1, $3);
Ken Thompson's avatar
Ken Thompson committed
411
		$$->etype = $2;			// rathole to pass opcode
412
	}
Ken Thompson's avatar
Ken Thompson committed
413
|	exprsym3_list_r '=' expr_list
414
	{
Ken Thompson's avatar
Ken Thompson committed
415 416
		$$ = rev($1);
		$$ = nod(OAS, $$, $3);
417
	}
Ken Thompson's avatar
Ken Thompson committed
418
|	exprsym3_list_r LCOLAS expr_list
419
	{
420 421
		if(addtop != N)
			fatal("exprsym3_list_r LCOLAS expr_list");
Ken Thompson's avatar
Ken Thompson committed
422 423 424 425
		if($3->op == OTYPESW) {
			$$ = nod(OTYPESW, $1, $3->left);
			break;
		}
Ken Thompson's avatar
Ken Thompson committed
426 427 428
		$$ = rev($1);
		$$ = colas($$, $3);
		$$ = nod(OAS, $$, $3);
429
		$$->colas = 1;
Ken Thompson's avatar
Ken Thompson committed
430
		addtotop($$);
431
	}
432 433 434 435
|	LPRINT '(' oexpr_list ')'
	{
		$$ = nod(OPRINT, $3, N);
	}
Ken Thompson's avatar
Ken Thompson committed
436 437 438 439
|	LPRINTN '(' oexpr_list ')'
	{
		$$ = nod(OPRINTN, $3, N);
	}
440 441 442 443
|	LPANIC '(' oexpr_list ')'
	{
		$$ = nod(OPANIC, $3, N);
	}
Ken Thompson's avatar
Ken Thompson committed
444 445 446 447
|	LPANICN '(' oexpr_list ')'
	{
		$$ = nod(OPANICN, $3, N);
	}
Russ Cox's avatar
Russ Cox committed
448
|	expr LINC
Ken Thompson's avatar
Ken Thompson committed
449
	{
450
		$$ = nod(OASOP, $1, nodintconst(1));
Ken Thompson's avatar
Ken Thompson committed
451 452 453 454
		$$->etype = OADD;
	}
|	expr LDEC
	{
455
		$$ = nod(OASOP, $1, nodintconst(1));
Ken Thompson's avatar
Ken Thompson committed
456 457 458
		$$->etype = OSUB;
	}

459 460 461
complex_stmt:
	LFOR for_stmt
	{
Ken Thompson's avatar
Ken Thompson committed
462
		popdcl();
463 464 465 466
		$$ = $2;
	}
|	LSWITCH if_stmt
	{
Ken Thompson's avatar
Ken Thompson committed
467
		popdcl();
468 469 470 471 472
		$$ = $2;
		$$->op = OSWITCH;
	}
|	LIF if_stmt
	{
Ken Thompson's avatar
Ken Thompson committed
473
		popdcl();
474 475
		$$ = $2;
	}
Russ Cox's avatar
Russ Cox committed
476
|	LIF if_stmt LELSE Aelse_stmt
477
	{
Ken Thompson's avatar
Ken Thompson committed
478
		popdcl();
479 480 481
		$$ = $2;
		$$->nelse = $4;
	}
Ken Thompson's avatar
Ken Thompson committed
482 483 484 485 486
|	LSELECT select_stmt
	{
		popdcl();
		$$ = $2;
	}
487 488 489 490 491 492 493 494
|	LCASE expr_list ':'
	{
		// will be converted to OCASE
		// right will point to next case
		// done in casebody()
		poptodcl();
		$$ = nod(OXCASE, $2, N);
	}
Rob Pike's avatar
Rob Pike committed
495 496 497 498 499 500 501 502 503 504 505 506 507 508 509
|	LCASE name '=' expr ':'
	{
		// will be converted to OCASE
		// right will point to next case
		// done in casebody()
		poptodcl();
		$$ = nod(OAS, $2, $4);
		$$ = nod(OXCASE, $$, N);
	}
|	LCASE name LCOLAS expr ':'
	{
		// will be converted to OCASE
		// right will point to next case
		// done in casebody()
		poptodcl();
Ken Thompson's avatar
Ken Thompson committed
510
		$$ = nod(OAS, selectas($2,$4), $4);
Rob Pike's avatar
Rob Pike committed
511
		$$ = nod(OXCASE, $$, N);
512
		addtotop($$);
Rob Pike's avatar
Rob Pike committed
513
	}
Ken Thompson's avatar
Ken Thompson committed
514 515 516 517 518 519 520 521 522 523 524 525
|	LCASE type ':'
	{
		poptodcl();
		if(typeswvar == N || typeswvar->right == N) {
			yyerror("type case not in a type switch");
			$$ = N;
		} else
			$$ = old2new(typeswvar->right, $2);
		$$ = nod(OTYPESW, $$, N);
		$$ = nod(OXCASE, $$, N);
		addtotop($$);
	}
526 527 528 529 530
|	LDEFAULT ':'
	{
		poptodcl();
		$$ = nod(OXCASE, N, N);
	}
Ken Thompson's avatar
Ken Thompson committed
531 532 533

semi_stmt:
	LFALL
534 535 536 537
	{
		// will be converted to OFALL
		$$ = nod(OXFALL, N, N);
	}
538
|	LBREAK onew_name
539 540 541
	{
		$$ = nod(OBREAK, $2, N);
	}
542
|	LCONTINUE onew_name
543 544 545
	{
		$$ = nod(OCONTINUE, $2, N);
	}
Ken Thompson's avatar
Ken Thompson committed
546
|	LGO pexpr '(' oexpr_list ')'
547
	{
Ken Thompson's avatar
Ken Thompson committed
548 549
		$$ = nod(OCALL, $2, $4);
		$$ = nod(OPROC, $$, N);
550
	}
Ken Thompson's avatar
defer  
Ken Thompson committed
551 552 553 554 555
|	LDEFER pexpr '(' oexpr_list ')'
	{
		$$ = nod(OCALL, $2, $4);
		$$ = nod(ODEFER, $$, N);
	}
Ken Thompson's avatar
Ken Thompson committed
556
|	LGOTO new_name
557 558 559
	{
		$$ = nod(OGOTO, $2, N);
	}
Ken Thompson's avatar
Ken Thompson committed
560
|	LRETURN oexpr_list
561
	{
Ken Thompson's avatar
Ken Thompson committed
562 563
		$$ = nod(ORETURN, $2, N);
	}
Russ Cox's avatar
Russ Cox committed
564
|	LIF if_stmt LELSE Belse_stmt
Ken Thompson's avatar
Ken Thompson committed
565
	{
Ken Thompson's avatar
Ken Thompson committed
566
		popdcl();
Ken Thompson's avatar
Ken Thompson committed
567 568
		$$ = $2;
		$$->nelse = $4;
569 570 571 572 573
	}

compound_stmt:
	'{'
	{
Ken Thompson's avatar
Ken Thompson committed
574
		markdcl();
575 576 577 578 579
	} ostmt_list '}'
	{
		$$ = $3;
		if($$ == N)
			$$ = nod(OEMPTY, N, N);
Ken Thompson's avatar
Ken Thompson committed
580
		popdcl();
581 582
	}

Russ Cox's avatar
Russ Cox committed
583 584
range_stmt:
	exprsym3_list_r '=' LRANGE expr
Ken Thompson's avatar
Ken Thompson committed
585 586 587 588
	{
		$$ = nod(ORANGE, $1, $4);
		$$->etype = 0;	// := flag
	}
589
|	exprsym3_list_r LCOLAS LRANGE expr
Ken Thompson's avatar
Ken Thompson committed
590 591 592 593 594 595
	{
		$$ = nod(ORANGE, $1, $4);
		$$->etype = 1;
	}

for_header:
Russ Cox's avatar
Russ Cox committed
596 597
	osimple_stmt ';' osimple_stmt ';' osimple_stmt
	{
598
		// init ; test ; incr
599 600
		if($5 != N && $5->colas != 0)
			yyerror("cannot declare in the for-increment");
601 602 603 604 605
		$$ = nod(OFOR, N, N);
		$$->ninit = $1;
		$$->ntest = $3;
		$$->nincr = $5;
	}
606
|	condition
607
	{
Ken Thompson's avatar
Ken Thompson committed
608
		// normal test
609 610 611 612 613
		$$ = nod(OFOR, N, N);
		$$->ninit = N;
		$$->ntest = $1;
		$$->nincr = N;
	}
Russ Cox's avatar
Russ Cox committed
614 615 616 617 618
|	range_stmt
	{
		$$ = dorange($1);
		addtotop($$);
	}
619 620 621 622 623

for_body:
	for_header compound_stmt
	{
		$$ = $1;
Ken Thompson's avatar
Ken Thompson committed
624
		$$->nbody = list($$->nbody, $2);
625 626 627 628
	}

for_stmt:
	{
Ken Thompson's avatar
Ken Thompson committed
629
		markdcl();
630 631 632 633 634
	} for_body
	{
		$$ = $2;
	}

635 636 637 638 639 640 641 642 643 644 645 646 647 648 649
/*
 * using cond instead of osimple_stmt creates
 * a shift/reduce conflict on an input like
 *
 *	if x == []int { true } { true }
 *
 * at the first {, giving us an opportunity
 * to resolve it by reduce, which implements
 * the rule about { } inside if conditions
 * needing parens.
 */
condition:
	osimple_stmt	%prec Condition


650
if_header:
651
	condition
652 653 654 655 656 657
	{
		// test
		$$ = nod(OIF, N, N);
		$$->ninit = N;
		$$->ntest = $1;
	}
658
|	osimple_stmt ';' condition
659 660 661 662 663 664 665 666
	{
		// init ; test
		$$ = nod(OIF, N, N);
		$$->ninit = $1;
		$$->ntest = $3;
	}

if_body:
Ken Thompson's avatar
Ken Thompson committed
667 668 669 670 671 672 673 674 675 676
	if_header
	{
		Node *n;
		n = $1->ntest;
		if(n != N && n->op == OTYPESW)
			n = n->left;
		else
			n = N;
		typeswvar = nod(OLIST, typeswvar, n);
	} compound_stmt
677 678
	{
		$$ = $1;
Ken Thompson's avatar
Ken Thompson committed
679 680
		$$->nbody = $3;
		typeswvar = typeswvar->left;
681 682 683 684
	}

if_stmt:
	{
Ken Thompson's avatar
Ken Thompson committed
685
		markdcl();
686 687 688 689 690
	} if_body
	{
		$$ = $2;
	}

Ken Thompson's avatar
Ken Thompson committed
691 692 693 694 695 696 697 698 699
select_stmt:
	{
		markdcl();
	}
	compound_stmt
	{
		$$ = nod(OSELECT, $2, N);
	}

700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768
/*
 * expressions
 */
expr:
	uexpr
|	expr LOROR expr
	{
		$$ = nod(OOROR, $1, $3);
	}
|	expr LANDAND expr
	{
		$$ = nod(OANDAND, $1, $3);
	}
|	expr LEQ expr
	{
		$$ = nod(OEQ, $1, $3);
	}
|	expr LNE expr
	{
		$$ = nod(ONE, $1, $3);
	}
|	expr LLT expr
	{
		$$ = nod(OLT, $1, $3);
	}
|	expr LLE expr
	{
		$$ = nod(OLE, $1, $3);
	}
|	expr LGE expr
	{
		$$ = nod(OGE, $1, $3);
	}
|	expr LGT expr
	{
		$$ = nod(OGT, $1, $3);
	}
|	expr '+' expr
	{
		$$ = nod(OADD, $1, $3);
	}
|	expr '-' expr
	{
		$$ = nod(OSUB, $1, $3);
	}
|	expr '|' expr
	{
		$$ = nod(OOR, $1, $3);
	}
|	expr '^' expr
	{
		$$ = nod(OXOR, $1, $3);
	}
|	expr '*' expr
	{
		$$ = nod(OMUL, $1, $3);
	}
|	expr '/' expr
	{
		$$ = nod(ODIV, $1, $3);
	}
|	expr '%' expr
	{
		$$ = nod(OMOD, $1, $3);
	}
|	expr '&' expr
	{
		$$ = nod(OAND, $1, $3);
	}
769 770 771 772
|	expr LANDNOT expr
	{
		$$ = nod(OANDNOT, $1, $3);
	}
773 774 775 776 777 778 779 780
|	expr LLSH expr
	{
		$$ = nod(OLSH, $1, $3);
	}
|	expr LRSH expr
	{
		$$ = nod(ORSH, $1, $3);
	}
Rob Pike's avatar
Rob Pike committed
781
|	expr LCOMM expr
Ken Thompson's avatar
Ken Thompson committed
782 783 784
	{
		$$ = nod(OSEND, $1, $3);
	}
785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816

uexpr:
	pexpr
|	'*' uexpr
	{
		$$ = nod(OIND, $2, N);
	}
|	'&' uexpr
	{
		$$ = nod(OADDR, $2, N);
	}
|	'+' uexpr
	{
		$$ = nod(OPLUS, $2, N);
	}
|	'-' uexpr
	{
		$$ = nod(OMINUS, $2, N);
	}
|	'!' uexpr
	{
		$$ = nod(ONOT, $2, N);
	}
|	'~' uexpr
	{
		yyerror("the OCOM operator is ^");
		$$ = nod(OCOM, $2, N);
	}
|	'^' uexpr
	{
		$$ = nod(OCOM, $2, N);
	}
Rob Pike's avatar
Rob Pike committed
817
|	LCOMM uexpr
818 819 820 821 822 823 824
	{
		$$ = nod(ORECV, $2, N);
	}

pexpr:
	LLITERAL
	{
825
		$$ = nodlit($1);
826 827 828
	}
|	LNIL
	{
829 830 831 832
		Val v;

		v.ctype = CTNIL;
		$$ = nodlit(v);
833 834 835
	}
|	LTRUE
	{
836
		$$ = nodbool(1);
837 838 839
	}
|	LFALSE
	{
840 841 842 843 844 845 846
		$$ = nodbool(0);
	}
|	laconst
	{
		$$ = nod(OLITERAL, N, N);
		$$->val = $1->oconst->val;
		$$->type = $1->oconst->type;
847 848 849
	}
|	LIOTA
	{
850
		$$ = nodintconst(iota);
Ken Thompson's avatar
Ken Thompson committed
851
		$$->iota = 1;	// flag to reevaluate on copy
852 853 854 855 856 857
	}
|	name
|	'(' expr ')'
	{
		$$ = $2;
	}
Ken Thompson's avatar
Ken Thompson committed
858
|	pexpr '.' sym2
859 860
	{
		$$ = nod(ODOT, $1, newname($3));
Ken Thompson's avatar
Ken Thompson committed
861
		$$ = adddot($$);
862 863 864
	}
|	pexpr '.' '(' type ')'
	{
865
		$$ = nod(ODOTTYPE, $1, N);
866 867
		$$->type = $4;
	}
Ken Thompson's avatar
Ken Thompson committed
868 869 870 871
|	pexpr '.' '(' LTYPE ')'
	{
		$$ = nod(OTYPESW, $1, N);
	}
872 873 874 875 876 877 878 879 880 881
|	pexpr '[' expr ']'
	{
		$$ = nod(OINDEX, $1, $3);
	}
|	pexpr '[' keyval ']'
	{
		$$ = nod(OSLICE, $1, $3);
	}
|	pexpr '(' oexpr_list ')'
	{
882 883 884
		$$ = unsafenmagic($1, $3);
		if($$ == N)
			$$ = nod(OCALL, $1, $3);
885
	}
Ken Thompson's avatar
Ken Thompson committed
886
|	LLEN '(' expr ')'
887 888 889
	{
		$$ = nod(OLEN, $3, N);
	}
890 891 892 893 894 895 896 897
|	LCLOSE '(' expr ')'
	{
		$$ = nod(OCLOSE, $3, N);
	}
|	LCLOSED '(' expr ')'
	{
		$$ = nod(OCLOSED, $3, N);
	}
Ken Thompson's avatar
Ken Thompson committed
898 899 900 901
|	LCAP '(' expr ')'
	{
		$$ = nod(OCAP, $3, N);
	}
902 903 904
|	LNEW '(' type ')'
	{
		$$ = nod(ONEW, N, N);
Ken Thompson's avatar
Ken Thompson committed
905
		$$->type = $3;
906
	}
Ken Thompson's avatar
Ken Thompson committed
907 908 909
|	LNEW '(' type ',' expr_list ')'
	{
		$$ = nod(ONEW, $5, N);
Ken Thompson's avatar
Ken Thompson committed
910
		$$->type = $3;
Ken Thompson's avatar
Ken Thompson committed
911
	}
Ken Thompson's avatar
Ken Thompson committed
912 913 914 915 916 917 918 919 920 921
|	LMAKE '(' type ')'
	{
		$$ = nod(OMAKE, N, N);
		$$->type = $3;
	}
|	LMAKE '(' type ',' expr_list ')'
	{
		$$ = nod(OMAKE, $5, N);
		$$->type = $3;
	}
922
|	convtype '(' expr ')'
Ken Thompson's avatar
Ken Thompson committed
923
	{
924
		// conversion
Russ Cox's avatar
Russ Cox committed
925 926 927
		$$ = rev($3);
		if($$ == N)
			$$ = nod(OEMPTY, N, N);
928
		$$ = nod(OCONV, $$, N);
Russ Cox's avatar
Russ Cox committed
929
		$$->type = $1;
Ken Thompson's avatar
Ken Thompson committed
930
	}
931
|	convtype '{' braced_keyexpr_list '}'
Ken Thompson's avatar
Ken Thompson committed
932
	{
933
		// composite expression
Ken Thompson's avatar
Ken Thompson committed
934 935 936
		$$ = rev($3);
		if($$ == N)
			$$ = nod(OEMPTY, N, N);
937
		$$ = nod(OCOMPOS, $$, N);
Ken Thompson's avatar
Ken Thompson committed
938 939 940
		$$->type = $1;
	}
|	fnliteral
941 942 943 944 945 946

/*
 * lexical symbols that can be
 * from other packages
 */
lpack:
Ken Thompson's avatar
Ken Thompson committed
947
	LPACK
948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969
	{
		context = $1->name;
	}

laconst:
	LACONST
|	lpack '.' LACONST
	{
		$$ = $3;
		context = nil;
	}

lname:
	LNAME
|	lpack '.' LNAME
	{
		$$ = $3;
		context = nil;
	}

latype:
	LATYPE
970 971 972 973
|	lpackatype

lpackatype:
	lpack '.' LATYPE
974 975 976 977 978 979 980 981 982 983 984
	{
		$$ = $3;
		context = nil;
	}

/*
 * names and types
 *	newname is used before declared
 *	oldname is used after declared
 */
new_name:
Ken Thompson's avatar
Ken Thompson committed
985
	sym1
986 987 988 989
	{
		$$ = newname($1);
	}

990 991 992 993 994 995
new_field:
	sym2
	{
		$$ = newname($1);
	}

996
new_type:
Ken Thompson's avatar
Ken Thompson committed
997
	sym1
998 999 1000 1001
	{
		$$ = newtype($1);
	}

1002 1003 1004 1005 1006 1007
onew_name:
	{
		$$ = N;
	}
|	new_name

1008 1009 1010 1011 1012 1013
sym:
	LATYPE
|	LNAME
|	LACONST
|	LPACK

Ken Thompson's avatar
Ken Thompson committed
1014 1015
sym1:
	sym
Ken Thompson's avatar
Ken Thompson committed
1016
|	keyword
Ken Thompson's avatar
Ken Thompson committed
1017

1018 1019 1020 1021 1022
/*
 * keywords that can be field names
 * pretty much any name can be allowed
 * limited only by good taste
 */
Ken Thompson's avatar
Ken Thompson committed
1023
sym2:
Russ Cox's avatar
Russ Cox committed
1024
	sym1
Ken Thompson's avatar
Ken Thompson committed
1025 1026

/*
Ken Thompson's avatar
Ken Thompson committed
1027 1028
 * keywords that can be variables
 * but are not already legal expressions
Ken Thompson's avatar
Ken Thompson committed
1029
 */
Ken Thompson's avatar
Ken Thompson committed
1030 1031
sym3:
	LLEN
Ken Thompson's avatar
Ken Thompson committed
1032
|	LCAP
1033 1034
|	LCLOSE
|	LCLOSED
Ken Thompson's avatar
Ken Thompson committed
1035
|	LPANIC
Ken Thompson's avatar
Ken Thompson committed
1036
|	LPANICN
Ken Thompson's avatar
Ken Thompson committed
1037
|	LPRINT
Ken Thompson's avatar
Ken Thompson committed
1038
|	LPRINTN
Ken Thompson's avatar
Ken Thompson committed
1039
|	LNEW
Ken Thompson's avatar
Ken Thompson committed
1040
|	LMAKE
Ken Thompson's avatar
Ken Thompson committed
1041
|	LBASETYPE
Ken Thompson's avatar
Ken Thompson committed
1042

Ken Thompson's avatar
Ken Thompson committed
1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053
/*
 * keywords that we can
 * use as variable/type names
 */
keyword:
	sym3
|	LNIL
|	LTRUE
|	LFALSE
|	LIOTA

1054 1055 1056 1057 1058
name:
	lname
	{
		$$ = oldname($1);
	}
Russ Cox's avatar
Russ Cox committed
1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077
	/*
	 * this rule introduces 1 reduce/reduce conflict
	 * with the rule lpack: LPACK above.
	 * the reduce/reduce conflict is only with
	 * lookahead '.', in which case the correct
	 * resolution is the lpack rule.  (and it wins
	 * because it is above.)
	 */
|	LPACK	%prec NotDot
	{
		$$ = oldname($1);
	}

labelname:
	name
|	keyword
	{
		$$ = oldname($1);
	}
1078

Ken Thompson's avatar
Ken Thompson committed
1079
convtype:
Ken Thompson's avatar
Ken Thompson committed
1080 1081 1082 1083
	latype
	{
		$$ = oldtype($1);
	}
Ken Thompson's avatar
Ken Thompson committed
1084
|	'[' oexpr ']' type
Ken Thompson's avatar
Ken Thompson committed
1085
	{
Ken Thompson's avatar
Ken Thompson committed
1086 1087
		// array literal
		$$ = aindex($2, $4);
Ken Thompson's avatar
Ken Thompson committed
1088
	}
Ken Thompson's avatar
Ken Thompson committed
1089 1090 1091 1092 1093 1094
|	'[' LDDD ']' type
	{
		// array literal of nelem
		$$ = aindex(N, $4);
		$$->bound = -100;
	}
Ken Thompson's avatar
Ken Thompson committed
1095
|	LMAP '[' type ']' type
Ken Thompson's avatar
Ken Thompson committed
1096
	{
Ken Thompson's avatar
Ken Thompson committed
1097
		// map literal
1098
		$$ = maptype($3, $5);
Ken Thompson's avatar
Ken Thompson committed
1099
	}
Ken Thompson's avatar
Ken Thompson committed
1100
|	structtype
1101 1102 1103 1104
|	'(' type ')'
	{
		$$ = $2;
	}
Ken Thompson's avatar
Ken Thompson committed
1105

Russ Cox's avatar
Russ Cox committed
1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117
/*
 * to avoid parsing conflicts, type is split into
 *	named types
 *	channel types
 *	function types
 *	any other type
 *
 * (and also into A/B as described above).
 *
 * the type system makes additional restrictions,
 * but those are not implemented in the grammar.
 */
1118
type:
Russ Cox's avatar
Russ Cox committed
1119 1120
	Atype
|	Btype
1121

Russ Cox's avatar
Russ Cox committed
1122 1123
Atype:
	Achantype
1124
|	Afntype
Russ Cox's avatar
Russ Cox committed
1125
|	Aothertype
1126

Russ Cox's avatar
Russ Cox committed
1127 1128 1129 1130 1131
Btype:
	nametype
|	Bchantype
|	Bfntype
|	Bothertype
1132 1133 1134 1135
|	'(' type ')'
	{
		$$ = $2;
	}
Russ Cox's avatar
Russ Cox committed
1136 1137 1138 1139 1140

non_name_type:
	chantype
|	fntype
|	othertype
Ken Thompson's avatar
Ken Thompson committed
1141 1142 1143 1144 1145 1146 1147
|	dotdotdot

dotdotdot:
	LDDD
	{
		$$ = typ(TDDD);
	}
Russ Cox's avatar
Russ Cox committed
1148 1149 1150 1151 1152 1153 1154 1155 1156

Anon_chan_type:
	Afntype
|	Aothertype

Bnon_chan_type:
	nametype
|	Bfntype
|	Bothertype
1157 1158 1159 1160
|	'(' Btype ')'
	{
		$$ = $2;
	}
Russ Cox's avatar
Russ Cox committed
1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171

Anon_fn_type:
	Achantype
|	Aothertype

Bnon_fn_type:
	nametype
|	Bchantype
|	Bothertype

nametype:
1172 1173
	LATYPE
	{
Ken Thompson's avatar
Ken Thompson committed
1174
		if($1->otype != T && $1->otype->etype == TANY)
Ken Thompson's avatar
Ken Thompson committed
1175
		if(strcmp(package, "PACKAGE") != 0)
Ken Thompson's avatar
Ken Thompson committed
1176
			yyerror("the any type is restricted");
1177 1178 1179
		$$ = oldtype($1);
	}

Russ Cox's avatar
Russ Cox committed
1180 1181 1182 1183 1184 1185
othertype:
	Aothertype
|	Bothertype

Aothertype:
	'[' oexpr ']' Atype
1186 1187 1188
	{
		$$ = aindex($2, $4);
	}
Russ Cox's avatar
Russ Cox committed
1189
|	LCOMM LCHAN Atype
1190 1191 1192
	{
		$$ = typ(TCHAN);
		$$->type = $3;
Rob Pike's avatar
Rob Pike committed
1193 1194
		$$->chan = Crecv;
	}
Russ Cox's avatar
Russ Cox committed
1195
|	LCHAN LCOMM Anon_chan_type
Rob Pike's avatar
Rob Pike committed
1196 1197 1198 1199
	{
		$$ = typ(TCHAN);
		$$->type = $3;
		$$->chan = Csend;
1200
	}
Russ Cox's avatar
Russ Cox committed
1201
|	LMAP '[' type ']' Atype
1202
	{
1203
		$$ = maptype($3, $5);
1204
	}
Russ Cox's avatar
Russ Cox committed
1205
|	'*' Atype
1206 1207 1208
	{
		$$ = ptrto($2);
	}
Russ Cox's avatar
Russ Cox committed
1209 1210
|	structtype
|	interfacetype
1211

Russ Cox's avatar
Russ Cox committed
1212 1213
Bothertype:
	lpackatype
Rob Pike's avatar
Rob Pike committed
1214
	{
Russ Cox's avatar
Russ Cox committed
1215
		$$ = oldtype($1);
Rob Pike's avatar
Rob Pike committed
1216
	}
Russ Cox's avatar
Russ Cox committed
1217
|	'[' oexpr ']' Btype
1218 1219 1220
	{
		$$ = aindex($2, $4);
	}
Russ Cox's avatar
Russ Cox committed
1221
|	LCOMM LCHAN Btype
1222 1223 1224
	{
		$$ = typ(TCHAN);
		$$->type = $3;
Rob Pike's avatar
Rob Pike committed
1225 1226
		$$->chan = Crecv;
	}
Russ Cox's avatar
Russ Cox committed
1227
|	LCHAN LCOMM Bnon_chan_type
Rob Pike's avatar
Rob Pike committed
1228 1229 1230 1231
	{
		$$ = typ(TCHAN);
		$$->type = $3;
		$$->chan = Csend;
1232
	}
Russ Cox's avatar
Russ Cox committed
1233
|	LMAP '[' type ']' Btype
1234
	{
1235
		$$ = maptype($3, $5);
1236
	}
Russ Cox's avatar
Russ Cox committed
1237
|	'*' Btype
1238 1239 1240
	{
		$$ = ptrto($2);
	}
1241

Russ Cox's avatar
Russ Cox committed
1242 1243 1244 1245 1246 1247 1248 1249 1250 1251
chantype:
	Achantype
|	Bchantype

Achantype:
	LCHAN Atype
	{
		$$ = typ(TCHAN);
		$$->type = $2;
		$$->chan = Cboth;
1252 1253
	}

Rob Pike's avatar
Rob Pike committed
1254
Bchantype:
Russ Cox's avatar
Russ Cox committed
1255
	LCHAN Btype
Rob Pike's avatar
Rob Pike committed
1256 1257 1258 1259 1260 1261
	{
		$$ = typ(TCHAN);
		$$->type = $2;
		$$->chan = Cboth;
	}

Ken Thompson's avatar
Ken Thompson committed
1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282
structtype:
	LSTRUCT '{' structdcl_list_r osemi '}'
	{
		$$ = dostruct(rev($3), TSTRUCT);
	}
|	LSTRUCT '{' '}'
	{
		$$ = dostruct(N, TSTRUCT);
	}

interfacetype:
	LINTERFACE '{' interfacedcl_list_r osemi '}'
	{
		$$ = dostruct(rev($3), TINTER);
		$$ = sortinter($$);
	}
|	LINTERFACE '{' '}'
	{
		$$ = dostruct(N, TINTER);
	}

1283 1284 1285
keyval:
	expr ':' expr
	{
Ken Thompson's avatar
Ken Thompson committed
1286
		$$ = nod(OKEY, $1, $3);
1287 1288 1289 1290 1291 1292 1293
	}

/*
 * function stuff
 * all in one place to show how crappy it all is
 */
xfndcl:
Ken Thompson's avatar
Ken Thompson committed
1294
	LFUNC
1295
	{
Ken Thompson's avatar
Ken Thompson committed
1296 1297 1298 1299 1300 1301
		maxarg = 0;
		stksize = 0;
	} fndcl fnbody
	{
		$$ = $3;
		$$->nbody = $4;
1302 1303 1304 1305 1306 1307 1308 1309 1310
		funcbody($$);
	}

fndcl:
	new_name '(' oarg_type_list ')' fnres
	{
		b0stack = dclstack;	// mark base for fn literals
		$$ = nod(ODCLFUNC, N, N);
		$$->nname = $1;
Ken Thompson's avatar
init  
Ken Thompson committed
1311 1312
		if($3 == N && $5 == N)
			$$->nname = renameinit($1);
1313 1314 1315 1316 1317 1318 1319
		$$->type = functype(N, $3, $5);
		funchdr($$);
	}
|	'(' oarg_type_list ')' new_name '(' oarg_type_list ')' fnres
	{
		b0stack = dclstack;	// mark base for fn literals
		$$ = nod(ODCLFUNC, N, N);
Ken Thompson's avatar
Ken Thompson committed
1320
		if(listcount($2) == 1) {
1321
			$$->nname = $4;
1322
			$$->nname = methodname($4, $2->type);
Ken Thompson's avatar
Ken Thompson committed
1323 1324 1325 1326 1327 1328 1329 1330 1331 1332
			$$->type = functype($2, $6, $8);
			funchdr($$);
			addmethod($4, $$->type, 1);
		} else {
			/* declare it as a function */
			yyerror("unknown method receiver");
			$$->nname = $4;
			$$->type = functype(N, $6, $8);
			funchdr($$);
		}
Ken Thompson's avatar
Ken Thompson committed
1333

1334 1335
	}

Ken Thompson's avatar
Ken Thompson committed
1336 1337 1338
fntype:
	Afntype
|	Bfntype
1339

Ken Thompson's avatar
Ken Thompson committed
1340
Afntype:
Russ Cox's avatar
Russ Cox committed
1341
	LFUNC '(' oarg_type_list ')' Afnres
1342
	{
Russ Cox's avatar
Russ Cox committed
1343
		$$ = functype(N, $3, $5);
1344 1345
	}

Ken Thompson's avatar
Ken Thompson committed
1346
Bfntype:
Russ Cox's avatar
Russ Cox committed
1347
	LFUNC '(' oarg_type_list ')' Bfnres
1348
	{
Russ Cox's avatar
Russ Cox committed
1349
		$$ = functype(N, $3, $5);
1350 1351 1352 1353 1354
	}

fnlitdcl:
	fntype
	{
Russ Cox's avatar
Russ Cox committed
1355
		markdcl();
1356
		$$ = $1;
Russ Cox's avatar
Russ Cox committed
1357
		funclit0($$);
1358 1359 1360
	}

fnliteral:
Russ Cox's avatar
Russ Cox committed
1361
	fnlitdcl '{' ostmt_list '}'
1362
	{
Russ Cox's avatar
Russ Cox committed
1363
		$$ = funclit1($1, $3);
1364 1365 1366
	}

fnbody:
Ken Thompson's avatar
Ken Thompson committed
1367
	'{' ostmt_list '}'
1368
	{
Ken Thompson's avatar
Ken Thompson committed
1369 1370
		$$ = $2;
		if($$ == N)
1371 1372
			$$ = nod(ORETURN, N, N);
	}
Russ Cox's avatar
Russ Cox committed
1373
|	{
1374 1375
		$$ = N;
	}
Ken Thompson's avatar
Ken Thompson committed
1376

1377
fnres:
1378 1379 1380 1381
	Afnres
|	Bfnres

Afnres:
Russ Cox's avatar
Russ Cox committed
1382
	Anon_fn_type
1383 1384 1385 1386 1387 1388
	{
		$$ = nod(ODCLFIELD, N, N);
		$$->type = $1;
		$$ = cleanidlist($$);
	}

1389
Bfnres:
Russ Cox's avatar
Russ Cox committed
1390
	%prec NotParen
1391 1392 1393
	{
		$$ = N;
	}
Russ Cox's avatar
Russ Cox committed
1394
|	Bnon_fn_type
1395 1396 1397 1398 1399
	{
		$$ = nod(ODCLFIELD, N, N);
		$$->type = $1;
		$$ = cleanidlist($$);
	}
Russ Cox's avatar
Russ Cox committed
1400 1401 1402 1403
|	'(' oarg_type_list ')'
	{
		$$ = $2;
	}
1404

1405 1406 1407 1408 1409 1410 1411 1412 1413 1414
/*
 * lists of things
 * note that they are left recursive
 * to conserve yacc stack. they need to
 * be reversed to interpret correctly
 */
xdcl_list_r:
	xdcl
|	xdcl_list_r xdcl
	{
Ken Thompson's avatar
Ken Thompson committed
1415
		$$ = list($1, $2);
1416 1417 1418 1419 1420 1421 1422 1423 1424 1425
	}

vardcl_list_r:
	vardcl
|	vardcl_list_r ';' vardcl
	{
		$$ = nod(OLIST, $1, $3);
	}

constdcl_list_r:
Ken Thompson's avatar
Ken Thompson committed
1426 1427
	constdcl1
|	constdcl_list_r ';' constdcl1
1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455

typedcl_list_r:
	typedcl
|	typedcl_list_r ';' typedcl

structdcl_list_r:
	structdcl
	{
		$$ = cleanidlist($1);
	}
|	structdcl_list_r ';' structdcl
	{
		$$ = cleanidlist($3);
		$$ = nod(OLIST, $1, $$);
	}

interfacedcl_list_r:
	interfacedcl
	{
		$$ = cleanidlist($1);
	}
|	interfacedcl_list_r ';' interfacedcl
	{
		$$ = cleanidlist($3);
		$$ = nod(OLIST, $1, $$);
	}

structdcl:
1456
	new_field ',' structdcl
1457 1458 1459 1460
	{
		$$ = nod(ODCLFIELD, $1, N);
		$$ = nod(OLIST, $$, $3);
	}
1461
|	new_field type oliteral
1462 1463 1464
	{
		$$ = nod(ODCLFIELD, $1, N);
		$$->type = $2;
1465
		$$->val = $3;
1466
	}
Russ Cox's avatar
Russ Cox committed
1467 1468 1469 1470 1471 1472
|	embed oliteral
	{
		$$ = $1;
		$$->val = $2;
	}
|	'*' embed oliteral
Ken Thompson's avatar
Ken Thompson committed
1473
	{
Ken Thompson's avatar
Ken Thompson committed
1474 1475
		$$ = $2;
		$$->type = ptrto($$->type);
Russ Cox's avatar
Russ Cox committed
1476
		$$->val = $3;
Ken Thompson's avatar
Ken Thompson committed
1477 1478
	}

Ken Thompson's avatar
Ken Thompson committed
1479
embed:
Ken Thompson's avatar
Ken Thompson committed
1480 1481
	LATYPE
	{
Ken Thompson's avatar
Ken Thompson committed
1482
		$$ = embedded($1);
1483 1484 1485
	}
|	lpack '.' LATYPE
	{
Ken Thompson's avatar
Ken Thompson committed
1486
		$$ = embedded($3);
1487
		context = nil;
Ken Thompson's avatar
Ken Thompson committed
1488
	}
1489

1490 1491
interfacedcl1:
	new_name ',' interfacedcl1
1492 1493 1494 1495
	{
		$$ = nod(ODCLFIELD, $1, N);
		$$ = nod(OLIST, $$, $3);
	}
Ken Thompson's avatar
Ken Thompson committed
1496
|	new_name indcl
1497 1498 1499 1500 1501
	{
		$$ = nod(ODCLFIELD, $1, N);
		$$->type = $2;
	}

1502 1503 1504 1505 1506 1507 1508 1509
interfacedcl:
	interfacedcl1
|	latype
	{
		$$ = nod(ODCLFIELD, N, N);
		$$->type = oldtype($1);
	}

Ken Thompson's avatar
Ken Thompson committed
1510
indcl:
1511 1512 1513 1514 1515 1516
	'(' oarg_type_list ')' fnres
	{
		// without func keyword
		$$ = functype(fakethis(), $2, $4);
	}

1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531
/*
 * function arguments.
 *
 * the hard part is that when we're reading a list of names,
 * we don't know if they are going to be the names of
 * parameters (like "a,b,c int") or the types of anonymous
 * parameters (like "int, string, bool").
 *
 * an arg_chunk is a comma-separated list of arguments
 * that ends in an obvious type, either "a, b, c x" or "a, b, c, *x".
 * in the first case, a, b, c are parameters of type x.
 * in the second case, a, b, c, and *x are types of anonymous parameters.
 */
arg_chunk:
	new_name_list_r type
1532
	{
1533
		$$ = nametodcl($1, $2);
1534
	}
Ken Thompson's avatar
Ken Thompson committed
1535 1536 1537 1538
|	new_name_list_r dotdotdot
	{
		$$ = nametodcl($1, $2);
	}
1539
|	non_name_type
1540
	{
1541
		$$ = anondcl($1);
1542
	}
1543
|	new_name_list_r ',' non_name_type
1544
	{
1545 1546 1547 1548 1549 1550 1551 1552 1553
		$1 = nametoanondcl($1);
		$$ = appendr($1, anondcl($3));
	}

arg_chunk_list_r:
	arg_chunk
|	arg_chunk_list_r ',' arg_chunk
	{
		$$ = appendr($1, $3);
1554 1555
	}

1556 1557 1558 1559 1560
/*
 * an arg type list is a sequence of arg chunks,
 * possibly ending in a list of names (plain "a,b,c"),
 * which must be the types of anonymous parameters.
 */
1561
arg_type_list_r:
1562 1563
	arg_chunk_list_r
|	arg_chunk_list_r ',' new_name_list_r
1564
	{
1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577
		$3 = nametoanondcl($3);
		$$ = appendr($1, $3);
	}
|	new_name_list_r
	{
		$$ = nametoanondcl($1);
	}

arg_type_list:
	arg_type_list_r
	{
		$$ = rev($1);
		checkarglist($$);
1578 1579
	}

Ken Thompson's avatar
Ken Thompson committed
1580
/*
Russ Cox's avatar
Russ Cox committed
1581
 * statement that doesn't need semicolon terminator
Ken Thompson's avatar
Ken Thompson committed
1582
 */
Ken Thompson's avatar
Ken Thompson committed
1583 1584
Astmt:
	complex_stmt
Ken Thompson's avatar
Ken Thompson committed
1585
|	compound_stmt
1586
|	Acommon_dcl
Ken Thompson's avatar
asdf  
Ken Thompson committed
1587 1588 1589 1590
|	';'
	{
		$$ = N;
	}
Ken Thompson's avatar
Ken Thompson committed
1591
|	error Astmt
1592 1593 1594
	{
		$$ = N;
	}
Russ Cox's avatar
Russ Cox committed
1595
|	labelname ':'
Russ Cox's avatar
Russ Cox committed
1596 1597 1598 1599
	{
		$$ = nod(OLABEL, $1, N);
	}
|	Bstmt ';'
Ken Thompson's avatar
Ken Thompson committed
1600

Ken Thompson's avatar
Ken Thompson committed
1601
/*
Russ Cox's avatar
Russ Cox committed
1602
 * statement that does
Ken Thompson's avatar
Ken Thompson committed
1603
 */
Ken Thompson's avatar
Ken Thompson committed
1604 1605
Bstmt:
	semi_stmt
1606
|	Bcommon_dcl
Russ Cox's avatar
Russ Cox committed
1607
|	simple_stmt
Ken Thompson's avatar
Ken Thompson committed
1608 1609

/*
Russ Cox's avatar
Russ Cox committed
1610
 * statement list that doesn't need semicolon terminator
Ken Thompson's avatar
Ken Thompson committed
1611
 */
Ken Thompson's avatar
Ken Thompson committed
1612 1613 1614
Astmt_list_r:
	Astmt
|	Astmt_list_r Astmt
1615
	{
Ken Thompson's avatar
Ken Thompson committed
1616
		$$ = list($1, $2);
Ken Thompson's avatar
Ken Thompson committed
1617 1618
	}

Ken Thompson's avatar
Ken Thompson committed
1619
/*
Russ Cox's avatar
Russ Cox committed
1620
 * statement list that needs semicolon terminator
Ken Thompson's avatar
Ken Thompson committed
1621
 */
Ken Thompson's avatar
Ken Thompson committed
1622 1623
Bstmt_list_r:
	Bstmt
Ken Thompson's avatar
Ken Thompson committed
1624
|	Astmt_list_r Bstmt
1625
	{
Ken Thompson's avatar
Ken Thompson committed
1626
		$$ = list($1, $2);
1627
	}
Ken Thompson's avatar
Ken Thompson committed
1628 1629 1630 1631

stmt_list_r:
	Astmt_list_r
|	Bstmt_list_r
1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646

expr_list_r:
	expr
|	expr_list_r ',' expr
	{
		$$ = nod(OLIST, $1, $3);
	}

new_name_list_r:
	new_name
|	new_name_list_r ',' new_name
	{
		$$ = nod(OLIST, $1, $3);
	}

Ken Thompson's avatar
Ken Thompson committed
1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660
exprsym3:
	expr
|	sym3
	{
		$$ = newname($1);
	}

exprsym3_list_r:
	exprsym3
|	exprsym3_list_r ',' exprsym3
	{
		$$ = nod(OLIST, $1, $3);
	}

1661 1662 1663 1664 1665 1666 1667
import_stmt_list_r:
	import_stmt
|	import_stmt_list_r osemi import_stmt

hidden_import_list_r:
|	hidden_import_list_r hidden_import

Russ Cox's avatar
Russ Cox committed
1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681
hidden_funarg_list_r:
	hidden_dcl
|	hidden_funarg_list_r ',' hidden_dcl
	{
		$$ = nod(OLIST, $1, $3);
	}

hidden_funarg_list:
	hidden_funarg_list_r
	{
		$$ = rev($1);
	}

hidden_structdcl_list_r:
Russ Cox's avatar
Russ Cox committed
1682 1683
	hidden_structdcl
|	hidden_structdcl_list_r ';' hidden_structdcl
Russ Cox's avatar
Russ Cox committed
1684 1685 1686 1687 1688 1689
	{
		$$ = nod(OLIST, $1, $3);
	}

hidden_structdcl_list:
	hidden_structdcl_list_r
1690
	{
Russ Cox's avatar
Russ Cox committed
1691
		$$ = rev($1);
1692 1693
	}

Russ Cox's avatar
Russ Cox committed
1694 1695 1696
hidden_interfacedcl_list_r:
	hidden_interfacedcl
|	hidden_interfacedcl_list_r ';' hidden_interfacedcl
1697
	{
Russ Cox's avatar
Russ Cox committed
1698 1699 1700 1701 1702 1703 1704
		$$ = nod(OLIST, $1, $3);
	}

hidden_interfacedcl_list:
	hidden_interfacedcl_list_r
	{
		$$ = rev($1);
1705 1706 1707 1708 1709 1710 1711 1712 1713
	}

keyval_list_r:
	keyval
|	keyval_list_r ',' keyval
	{
		$$ = nod(OLIST, $1, $3);
	}

1714 1715 1716 1717 1718 1719 1720
/*
 * have to spell this out using _r lists to avoid yacc conflict
 */
braced_keyexpr_list:
	{
		$$ = N;
	}
1721
|	keyval_list_r ocomma
1722 1723 1724
	{
		$$ = rev($1);
	}
1725
|	expr_list_r ocomma
1726 1727 1728 1729
	{
		$$ = rev($1);
	}

Ken Thompson's avatar
Ken Thompson committed
1730

1731 1732 1733 1734 1735 1736 1737 1738 1739 1740
/*
 * the one compromise of a
 * non-reversed list
 */
expr_list:
	expr_list_r
	{
		$$ = rev($1);
	}

1741

1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786
/*
 * optional things
 */
osemi:
|	';'

ocomma:
|	','

oexpr:
	{
		$$ = N;
	}
|	expr

oexpr_list:
	{
		$$ = N;
	}
|	expr_list

osimple_stmt:
	{
		$$ = N;
	}
|	simple_stmt

ostmt_list:
	{
		$$ = N;
	}
|	stmt_list_r
	{
		$$ = rev($1);
	}

oxdcl_list:
	{
		$$ = N;
	}
|	xdcl_list_r
	{
		$$ = rev($1);
	}

Russ Cox's avatar
Russ Cox committed
1787
oarg_type_list:
1788 1789 1790
	{
		$$ = N;
	}
Russ Cox's avatar
Russ Cox committed
1791 1792 1793
|	arg_type_list

ohidden_funarg_list:
1794
	{
Russ Cox's avatar
Russ Cox committed
1795
		$$ = N;
1796
	}
Russ Cox's avatar
Russ Cox committed
1797
|	hidden_funarg_list
1798

Russ Cox's avatar
Russ Cox committed
1799
ohidden_structdcl_list:
1800 1801 1802
	{
		$$ = N;
	}
Russ Cox's avatar
Russ Cox committed
1803 1804 1805
|	hidden_structdcl_list

ohidden_interfacedcl_list:
1806
	{
Russ Cox's avatar
Russ Cox committed
1807
		$$ = N;
1808
	}
Russ Cox's avatar
Russ Cox committed
1809
|	hidden_interfacedcl_list
1810

1811 1812 1813 1814 1815 1816
oliteral:
	{
		$$.ctype = CTxxx;
	}
|	LLITERAL

1817 1818 1819 1820 1821
/*
 * import syntax from header of
 * an output package
 */
hidden_import:
Russ Cox's avatar
Russ Cox committed
1822
	LPACKAGE sym1
1823
	/* variables */
Russ Cox's avatar
Russ Cox committed
1824
|	LVAR hidden_pkg_importsym hidden_type
Russ Cox's avatar
Russ Cox committed
1825
	{
Russ Cox's avatar
Russ Cox committed
1826
		importvar($2, $3, PEXTERN);
Russ Cox's avatar
Russ Cox committed
1827
	}
Russ Cox's avatar
Russ Cox committed
1828
|	LCONST hidden_pkg_importsym '=' hidden_constant
Russ Cox's avatar
Russ Cox committed
1829
	{
1830
		importconst($2, types[TIDEAL], $4);
Russ Cox's avatar
Russ Cox committed
1831
	}
Russ Cox's avatar
Russ Cox committed
1832
|	LCONST hidden_pkg_importsym hidden_type '=' hidden_constant
Russ Cox's avatar
Russ Cox committed
1833
	{
1834
		importconst($2, $3, $5);
Russ Cox's avatar
Russ Cox committed
1835
	}
Russ Cox's avatar
Russ Cox committed
1836
|	LTYPE hidden_pkg_importsym hidden_type
Russ Cox's avatar
Russ Cox committed
1837
	{
Russ Cox's avatar
Russ Cox committed
1838
		importtype($2, $3);
Russ Cox's avatar
Russ Cox committed
1839
	}
Russ Cox's avatar
Russ Cox committed
1840
|	LFUNC hidden_pkg_importsym '(' ohidden_funarg_list ')' ohidden_funres
1841
	{
Russ Cox's avatar
Russ Cox committed
1842
		importvar($2, functype(N, $4, $6), PFUNC);
1843
	}
Russ Cox's avatar
Russ Cox committed
1844
|	LFUNC '(' hidden_funarg_list ')' sym1 '(' ohidden_funarg_list ')' ohidden_funres
Russ Cox's avatar
Russ Cox committed
1845
	{
Russ Cox's avatar
Russ Cox committed
1846
		if($3->op != ODCLFIELD) {
Russ Cox's avatar
Russ Cox committed
1847 1848 1849
			yyerror("bad receiver in method");
			YYERROR;
		}
Russ Cox's avatar
Russ Cox committed
1850
		importmethod($5, functype($3, $7, $9));
Russ Cox's avatar
Russ Cox committed
1851 1852 1853 1854 1855
	}

hidden_type:
	hidden_type1
|	hidden_type2
1856

Russ Cox's avatar
Russ Cox committed
1857 1858
hidden_type1:
	hidden_importsym
1859
	{
Russ Cox's avatar
Russ Cox committed
1860
		$$ = pkgtype($1->sym->name, $1->psym->name);
1861
	}
Russ Cox's avatar
Russ Cox committed
1862
|	LATYPE
1863
	{
Russ Cox's avatar
Russ Cox committed
1864
		$$ = oldtype($1);
1865
	}
Russ Cox's avatar
Russ Cox committed
1866 1867 1868 1869 1870 1871
|	'[' ']' hidden_type
	{
		$$ = aindex(N, $3);
	}
|	'[' LLITERAL ']' hidden_type
	{
1872
		$$ = aindex(nodlit($2), $4);
Russ Cox's avatar
Russ Cox committed
1873 1874 1875
	}
|	LMAP '[' hidden_type ']' hidden_type
	{
1876
		$$ = maptype($3, $5);
Russ Cox's avatar
Russ Cox committed
1877 1878
	}
|	LSTRUCT '{' ohidden_structdcl_list '}'
1879
	{
Russ Cox's avatar
Russ Cox committed
1880
		$$ = dostruct($3, TSTRUCT);
1881
	}
Russ Cox's avatar
Russ Cox committed
1882
|	LINTERFACE '{' ohidden_interfacedcl_list '}'
1883
	{
Russ Cox's avatar
Russ Cox committed
1884 1885
		$$ = dostruct($3, TINTER);
		$$ = sortinter($$);
1886
	}
Russ Cox's avatar
Russ Cox committed
1887
|	'*' hidden_type
Ken Thompson's avatar
Ken Thompson committed
1888
	{
1889
		checkwidth($2);
Russ Cox's avatar
Russ Cox committed
1890
		$$ = ptrto($2);
Ken Thompson's avatar
Ken Thompson committed
1891
	}
Russ Cox's avatar
Russ Cox committed
1892
|	LCOMM LCHAN hidden_type
1893
	{
Russ Cox's avatar
Russ Cox committed
1894 1895 1896
		$$ = typ(TCHAN);
		$$->type = $3;
		$$->chan = Crecv;
1897
	}
Russ Cox's avatar
Russ Cox committed
1898
|	LCHAN LCOMM hidden_type1
1899
	{
Russ Cox's avatar
Russ Cox committed
1900 1901 1902
		$$ = typ(TCHAN);
		$$->type = $3;
		$$->chan = Csend;
1903
	}
Ken Thompson's avatar
Ken Thompson committed
1904 1905 1906 1907
|	LDDD
	{
		$$ = typ(TDDD);
	}
Russ Cox's avatar
Russ Cox committed
1908 1909 1910

hidden_type2:
	LCHAN hidden_type
1911
	{
Russ Cox's avatar
Russ Cox committed
1912 1913 1914
		$$ = typ(TCHAN);
		$$->type = $2;
		$$->chan = Cboth;
1915
	}
Russ Cox's avatar
Russ Cox committed
1916
|	LFUNC '(' ohidden_funarg_list ')' ohidden_funres
1917
	{
Russ Cox's avatar
Russ Cox committed
1918
		$$ = functype(N, $3, $5);
1919
	}
Russ Cox's avatar
Russ Cox committed
1920 1921 1922

hidden_dcl:
	sym1 hidden_type
1923
	{
Russ Cox's avatar
Russ Cox committed
1924 1925
		$$ = nod(ODCLFIELD, newname($1), N);
		$$->type = $2;
1926
	}
Russ Cox's avatar
Russ Cox committed
1927
|	'?' hidden_type
Ken Thompson's avatar
Ken Thompson committed
1928
	{
Russ Cox's avatar
Russ Cox committed
1929 1930
		$$ = nod(ODCLFIELD, N, N);
		$$->type = $2;
Ken Thompson's avatar
Ken Thompson committed
1931
	}
Russ Cox's avatar
Russ Cox committed
1932

Russ Cox's avatar
Russ Cox committed
1933
hidden_structdcl:
Russ Cox's avatar
Russ Cox committed
1934
	sym1 hidden_type oliteral
Russ Cox's avatar
Russ Cox committed
1935 1936 1937
	{
		$$ = nod(ODCLFIELD, newname($1), N);
		$$->type = $2;
Russ Cox's avatar
Russ Cox committed
1938
		$$->val = $3;
Russ Cox's avatar
Russ Cox committed
1939
	}
Russ Cox's avatar
Russ Cox committed
1940
|	'?' hidden_type oliteral
Russ Cox's avatar
Russ Cox committed
1941
	{
Ken Thompson's avatar
Ken Thompson committed
1942 1943 1944 1945 1946
		if(isptr[$2->etype]) {
			$$ = embedded($2->type->sym);
			$$->type = ptrto($$->type);
		} else
			$$ = embedded($2->sym);
Russ Cox's avatar
Russ Cox committed
1947
		$$->val = $3;
Russ Cox's avatar
Russ Cox committed
1948 1949
	}

Russ Cox's avatar
Russ Cox committed
1950 1951
hidden_interfacedcl:
	sym1 '(' ohidden_funarg_list ')' ohidden_funres
Ken Thompson's avatar
Ken Thompson committed
1952
	{
Russ Cox's avatar
Russ Cox committed
1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971
		$$ = nod(ODCLFIELD, newname($1), N);
		$$->type = functype(fakethis(), $3, $5);
	}

ohidden_funres:
	{
		$$ = N;
	}
|	hidden_funres

hidden_funres:
	'(' ohidden_funarg_list ')'
	{
		$$ = $2;
	}
|	hidden_type1
	{
		$$ = nod(ODCLFIELD, N, N);
		$$->type = $1;
Ken Thompson's avatar
Ken Thompson committed
1972
	}
1973

1974 1975
hidden_constant:
	LLITERAL
1976 1977 1978
	{
		$$ = nodlit($1);
	}
1979 1980
|	'-' LLITERAL
	{
1981 1982
		$$ = nodlit($2);
		switch($$->val.ctype){
1983
		case CTINT:
1984
			mpnegfix($$->val.u.xval);
1985 1986
			break;
		case CTFLT:
1987
			mpnegflt($$->val.u.fval);
1988 1989 1990 1991 1992
			break;
		default:
			yyerror("bad negated constant");
		}
	}
Russ Cox's avatar
Russ Cox committed
1993 1994
|	LTRUE
	{
1995
		$$ = nodbool(1);
Russ Cox's avatar
Russ Cox committed
1996 1997 1998
	}
|	LFALSE
	{
1999
		$$ = nodbool(0);
Russ Cox's avatar
Russ Cox committed
2000
	}
2001

Russ Cox's avatar
Russ Cox committed
2002
hidden_importsym:
2003
	sym1 '.' sym2
2004 2005 2006 2007 2008 2009
	{
		$$ = nod(OIMPORT, N, N);
		$$->osym = $1;
		$$->psym = $1;
		$$->sym = $3;
	}
2010

Russ Cox's avatar
Russ Cox committed
2011 2012 2013 2014 2015 2016 2017 2018
hidden_pkg_importsym:
	hidden_importsym
	{
		$$ = $1;
		pkgcontext = $$->psym->name;
	}


2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030
/*
 * helpful error messages.
 * THIS SECTION MUST BE AT THE END OF THE FILE.
 *
 * these rules trigger reduce/reduce conflicts in the grammar.
 * they are safe because reduce/reduce conflicts are resolved
 * in favor of rules appearing earlier in the grammar, and these
 * are at the end of the file.
 *
 * to check whether the rest of the grammar is free of
 * reduce/reduce conflicts, comment this section out by
 * removing the slash on the next line.
2031
 */
2032 2033 2034 2035 2036 2037 2038 2039
lpack:
	LATYPE
	{
		yyerror("%s is type, not package", $1->name);
		YYERROR;
	}

laconst:
Russ Cox's avatar
Russ Cox committed
2040
	LATYPE
2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058
	{
		yyerror("%s is type, not var", $1->name);
		YYERROR;
	}

latype:
	LACONST
	{
		yyerror("%s is const, not type", $1->name);
		YYERROR;
	}
|	LPACK
	{
		yyerror("%s is package, not type", $1->name);
		YYERROR;
	}
|	LNAME
	{
Russ Cox's avatar
Russ Cox committed
2059 2060 2061
		yyerror("no type %s", $1->name);
		YYERROR;
	}
2062

Russ Cox's avatar
Russ Cox committed
2063 2064 2065 2066 2067 2068 2069
nametype:
	LNAME
	{
		yyerror("no type %s", $1->name);
		YYERROR;
	}

2070 2071
/**/