PageRenderTime 95ms CodeModel.GetById 16ms app.highlight 69ms RepoModel.GetById 1ms app.codeStats 0ms

/iparser/igo_parser.y

https://github.com/zsaleeba/indigo
Happy | 2242 lines | 2091 code | 151 blank | 0 comment | 0 complexity | 3b3383b98dd0b5c283ad9f981ac6406f MD5 | raw file
   1// Copyright 2009 The Go Authors and the Indigo authors.
   2// All rights reserved.
   3// Use of this source code is governed by a BSD-style
   4// license that can be found in the LICENSE file.
   5
   6/*
   7 * Go language grammar.
   8 *
   9 * The Go semicolon rules are:
  10 *
  11 *  1. all statements and declarations are terminated by semicolons.
  12 *  2. semicolons can be omitted before a closing ) or }.
  13 *  3. semicolons are inserted by the lexer before a newline
  14 *      following a specific list of tokens.
  15 *
  16 * 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.
  19 */
  20
  21%{
  22package parser
  23
  24import (
  25//    "bufio"
  26//    "fmt"
  27//    "math"
  28//    "os"
  29    "github.com/zsaleeba/indigo/ast"
  30)
  31%}
  32%union	{
  33	node ast.Node
  34	list *ast.NodeList
  35	typ ast.Type
  36	sym *ast.Sym
  37	val ast.Val
  38	i int
  39}
  40
  41// |sed 's/.*	//' |9 fmt -l1 |sort |9 fmt -l50 | sed 's/^/%xxx		/'
  42
  43%token	<val>	LLITERAL
  44%token	<sym>	LBREAK LCASE LCHAN LCONST LCONTINUE LDDD
  45%token	<sym>	LDEFAULT LDEFER LELSE LFALL LFOR LFUNC LGO LGOTO
  46%token	<sym>	LIF LIMPORT LINTERFACE LMAP LNAME
  47%token	<sym>	LPACKAGE LRANGE LRETURN LSELECT LSTRUCT LSWITCH
  48%token	<sym>	LTYPE LVAR
  49
  50%token		LANDAND LANDNOT LBODY LCOMM LDEC LEQ LGE LGT
  51%token		LIGNORE LINC LLE LLSH LLT LNE LOROR LRSH
  52%token      LADDAS LSUBAS LMULAS LDIVAS LANDNOTAS LANDAS LORAS
  53%token      LLSHAS LRSHAS LDECLAS
  54
  55%type	<i>	lbrace import_here
  56%type	<sym>	sym packname
  57%type	<val>	oliteral
  58
  59%type	<node>	stmt ntype
  60%type	<node>	arg_type
  61%type	<node>	case caseblock
  62%type	<node>	compound_stmt dotname embed expr complitexpr bare_complitexpr
  63%type	<node>	expr_or_type
  64%type	<node>	fndcl hidden_fndcl fnliteral
  65%type	<node>	for_body for_header for_stmt if_header if_stmt non_dcl_stmt
  66%type	<node>	interfacedcl keyval labelname name
  67%type	<node>	name_or_type non_expr_type
  68%type	<node>	new_name dcl_name oexpr typedclname
  69%type	<node>	onew_name
  70%type	<node>	osimple_stmt pexpr pexpr_no_paren
  71%type	<node>	pseudocall range_stmt select_stmt
  72%type	<node>	simple_stmt
  73%type	<node>	switch_stmt uexpr
  74%type	<node>	xfndcl typedcl start_complit
  75
  76%type	<list>	xdcl fnbody fnres loop_body dcl_name_list
  77%type	<list>	new_name_list expr_list keyval_list braced_keyval_list expr_or_type_list xdcl_list
  78%type	<list>	oexpr_list caseblock_list elseif elseif_list else stmt_list oarg_type_list_ocomma arg_type_list
  79%type	<list>	interfacedcl_list vardcl vardcl_list structdcl structdcl_list
  80%type	<list>	common_dcl constdcl constdcl1 constdcl_list typedcl_list
  81
  82%type	<node>	convtype comptype dotdotdot
  83%type	<node>	indcl interfacetype structtype ptrtype
  84%type	<node>	recvchantype non_recvchantype othertype fnret_type fntype
  85
  86%type	<sym>	hidden_importsym hidden_pkg_importsym
  87
  88%type	<node>	hidden_constant hidden_literal hidden_funarg
  89%type	<node>	hidden_interfacedcl hidden_structdcl
  90
  91%type	<list>	hidden_funres
  92%type	<list>	ohidden_funres
  93%type	<list>	hidden_funarg_list ohidden_funarg_list
  94%type	<list>	hidden_interfacedcl_list ohidden_interfacedcl_list
  95%type	<list>	hidden_structdcl_list ohidden_structdcl_list
  96
  97%type	<typ>	hidden_type hidden_type_misc hidden_pkgtype
  98%type	<typ>	hidden_type_func
  99%type	<typ>	hidden_type_recv_chan hidden_type_non_recv_chan
 100
 101%left		LCOMM	/* outside the usual hierarchy; here for good error messages */
 102
 103%left		LOROR
 104%left		LANDAND
 105%left		LEQ LNE LLE LGE LLT LGT
 106%left		'+' '-' '|' '^'
 107%left		'*' '/' '%' '&' LLSH LRSH LANDNOT
 108
 109/*
 110 * manual override of shift/reduce conflicts.
 111 * the general form is that we assign a precedence
 112 * to the token being shifted and then introduce
 113 * NotToken with lower precedence or PreferToToken with higher
 114 * and annotate the reducing rule accordingly.
 115 */
 116%left		NotPackage
 117%left		LPACKAGE
 118
 119%left		NotParen
 120%left		'('
 121
 122%left		')'
 123%left		PreferToRightParen
 124
 125%%
 126file:
 127	loadsys
 128	package
 129	imports
 130	xdcl_list
 131	{
 132//		xtop = concat(xtop, $4);
 133	}
 134
 135package:
 136	%prec NotPackage
 137	{
 138//		prevlineno = lineno;
 139//		yyerror("package statement must be first");
 140//		errorexit();
 141	}
 142|	LPACKAGE sym ';'
 143	{
 144//		mkpackage($2.name);
 145	}
 146
 147/*
 148 * this loads the definitions for the low-level runtime functions,
 149 * so that the compiler can generate calls to them,
 150 * but does not make the name "runtime" visible as a package.
 151 */
 152loadsys:
 153	{
 154//		importpkg = runtimepkg;
 155//
 156//		if(debug['A'])
 157//			cannedimports("runtime.builtin", "package runtime\n\n$$\n\n");
 158//		else
 159//			cannedimports("runtime.builtin", runtimeimport);
 160//		curio.importsafe = 1;
 161	}
 162	import_package
 163	import_there
 164	{
 165//		importpkg = nil;
 166	}
 167
 168imports:
 169|	imports import ';'
 170
 171import:
 172	LIMPORT import_stmt
 173|	LIMPORT '(' import_stmt_list osemi ')'
 174|	LIMPORT '(' ')'
 175
 176import_stmt:
 177	import_here import_package import_there
 178	{
 179//		Pkg *ipkg;
 180//		Sym *my;
 181//		Node *pack;
 182//		
 183//		ipkg = importpkg;
 184//		my = importmyname;
 185//		importpkg = nil;
 186//		importmyname = S;
 187//
 188//		if(my == nil)
 189//			my = lookup(ipkg->name);
 190//
 191//		pack = nod(OPACK, N, N);
 192//		pack->sym = my;
 193//		pack->pkg = ipkg;
 194//		pack->lineno = $1;
 195//
 196//		if(my->name[0] == '.') {
 197//			importdot(ipkg, pack);
 198//			break;
 199//		}
 200//		if(strcmp(my->name, "init") == 0) {
 201//			yyerror("cannot import package as init - init must be a func");
 202//			break;
 203//		}
 204//		if(my->name[0] == '_' && my->name[1] == '\0')
 205//			break;
 206//		if(my->def) {
 207//			lineno = $1;
 208//			redeclare(my, "as imported package name");
 209//		}
 210//		my->def = pack;
 211//		my->lastlineno = $1;
 212//		my->block = 1;	// at top level
 213	}
 214|	import_here import_there
 215	{
 216		// When an invalid import path is passed to importfile,
 217		// it calls yyerror and then sets up a fake import with
 218		// no package statement. This allows us to test more
 219		// than one invalid import statement in a single file.
 220//		if(nerrors == 0)
 221//			fatal("phase error in import");
 222	}
 223
 224import_stmt_list:
 225	import_stmt
 226|	import_stmt_list ';' import_stmt
 227
 228import_here:
 229	LLITERAL
 230	{
 231//		// import with original name
 232//		$$ = parserline();
 233//		importmyname = S;
 234//		importfile(&$1, $$);
 235	}
 236|	sym LLITERAL
 237	{
 238//		// import with given name
 239//		$$ = parserline();
 240//		importmyname = $1;
 241//		importfile(&$2, $$);
 242	}
 243|	'.' LLITERAL
 244	{
 245//		// import into my name space
 246//		$$ = parserline();
 247//		importmyname = lookup(".");
 248//		importfile(&$2, $$);
 249	}
 250
 251import_package:
 252	LPACKAGE LNAME import_safety ';'
 253	{
 254//		if(importpkg->name == nil) {
 255//			importpkg->name = $2->name;
 256//			pkglookup($2->name, nil)->npkg++;
 257//		} else if(strcmp(importpkg->name, $2->name) != 0)
 258//			yyerror("conflicting names %s and %s for package \"%Z\"", importpkg->name, $2->name, importpkg->path);
 259//		importpkg->direct = 1;
 260//		importpkg->safe = curio.importsafe;
 261//
 262//		if(safemode && !curio.importsafe)
 263//			yyerror("cannot import unsafe package \"%Z\"", importpkg->path);
 264	}
 265
 266import_safety:
 267|	LNAME
 268	{
 269//		if(strcmp($1->name, "safe") == 0)
 270//			curio.importsafe = 1;
 271	}
 272
 273import_there:
 274	{
 275//		defercheckwidth();
 276	}
 277	hidden_import_list '$' '$'
 278	{
 279//		resumecheckwidth();
 280//		unimportfile();
 281	}
 282
 283/*
 284 * declarations
 285 */
 286xdcl:
 287	{
 288//		yyerror("empty top-level declaration");
 289//		$$ = nil;
 290	}
 291|	common_dcl
 292|	xfndcl
 293	{
 294//		$$ = list1($1);
 295	}
 296|	non_dcl_stmt
 297	{
 298//		yyerror("non-declaration statement outside function body");
 299//		$$ = nil;
 300	}
 301|	error
 302	{
 303//		$$ = nil;
 304	}
 305
 306common_dcl:
 307	LVAR vardcl
 308	{
 309//		$$ = $2;
 310	}
 311|	LVAR '(' vardcl_list osemi ')'
 312	{
 313//		$$ = $3;
 314	}
 315|	LVAR '(' ')'
 316	{
 317//		$$ = nil;
 318	}
 319|	lconst constdcl
 320	{
 321//		$$ = $2;
 322//		iota = -100000;
 323//		lastconst = nil;
 324	}
 325|	lconst '(' constdcl osemi ')'
 326	{
 327//		$$ = $3;
 328//		iota = -100000;
 329//		lastconst = nil;
 330	}
 331|	lconst '(' constdcl ';' constdcl_list osemi ')'
 332	{
 333//		$$ = concat($3, $5);
 334//		iota = -100000;
 335//		lastconst = nil;
 336	}
 337|	lconst '(' ')'
 338	{
 339//		$$ = nil;
 340//		iota = -100000;
 341	}
 342|	LTYPE typedcl
 343	{
 344//		$$ = list1($2);
 345	}
 346|	LTYPE '(' typedcl_list osemi ')'
 347	{
 348//		$$ = $3;
 349	}
 350|	LTYPE '(' ')'
 351	{
 352//		$$ = nil;
 353	}
 354
 355lconst:
 356	LCONST
 357	{
 358//		iota = 0;
 359	}
 360
 361vardcl:
 362	dcl_name_list ntype
 363	{
 364//		$$ = variter($1, $2, nil);
 365	}
 366|	dcl_name_list ntype '=' expr_list
 367	{
 368//		$$ = variter($1, $2, $4);
 369	}
 370|	dcl_name_list '=' expr_list
 371	{
 372//		$$ = variter($1, nil, $3);
 373	}
 374
 375constdcl:
 376	dcl_name_list ntype '=' expr_list
 377	{
 378//		$$ = constiter($1, $2, $4);
 379	}
 380|	dcl_name_list '=' expr_list
 381	{
 382//		$$ = constiter($1, N, $3);
 383	}
 384
 385constdcl1:
 386	constdcl
 387|	dcl_name_list ntype
 388	{
 389//		$$ = constiter($1, $2, nil);
 390	}
 391|	dcl_name_list
 392	{
 393//		$$ = constiter($1, N, nil);
 394	}
 395
 396typedclname:
 397	sym
 398	{
 399//		// different from dclname because the name
 400//		// becomes visible right here, not at the end
 401//		// of the declaration.
 402//		$$ = typedcl0($1);
 403	}
 404
 405typedcl:
 406	typedclname ntype
 407	{
 408//		$$ = typedcl1($1, $2, 1);
 409	}
 410
 411simple_stmt:
 412	expr
 413	{
 414//		$$ = $1;
 415//
 416//		// These nodes do not carry line numbers.
 417//		// Since a bare name used as an expression is an error,
 418//		// introduce a wrapper node to give the correct line.
 419//		switch($$->op) {
 420//		case ONAME:
 421//		case ONONAME:
 422//		case OTYPE:
 423//		case OPACK:
 424//		case OLITERAL:
 425//			$$ = nod(OPAREN, $$, N);
 426//			$$->implicit = 1;
 427//			break;
 428//		}
 429	}
 430|	expr LADDAS expr
 431	{
 432//		$$ = nod(OASOP, $1, $3);
 433//		$$->etype = $2;			// rathole to pass opcode
 434	}
 435|	expr LSUBAS expr
 436	{
 437	}
 438|	expr LMULAS expr
 439	{
 440	}
 441|	expr LDIVAS expr
 442	{
 443	}
 444|	expr LANDNOTAS expr
 445	{
 446	}
 447|	expr LANDAS expr
 448	{
 449	}
 450|	expr LORAS expr
 451	{
 452	}
 453|	expr LLSHAS expr
 454	{
 455	}
 456|	expr LRSHAS expr
 457	{
 458	}
 459|	expr_list '=' expr_list
 460	{
 461//		if($1->next == nil && $3->next == nil) {
 462//			// simple
 463//			$$ = nod(OAS, $1->n, $3->n);
 464//			break;
 465//		}
 466//		// multiple
 467//		$$ = nod(OAS2, N, N);
 468//		$$->list = $1;
 469//		$$->rlist = $3;
 470	}
 471|	expr_list LDECLAS expr_list
 472	{
 473//		if($3->n->op == OTYPESW) {
 474//			$$ = nod(OTYPESW, N, $3->n->right);
 475//			if($3->next != nil)
 476//				yyerror("expr.(type) must be alone in list");
 477//			if($1->next != nil)
 478//				yyerror("argument count mismatch: %d = %d", count($1), 1);
 479//			else if(($1->n->op != ONAME && $1->n->op != OTYPE && $1->n->op != ONONAME) || isblank($1->n))
 480//				yyerror("invalid variable name %N in type switch", $1->n);
 481//			else
 482//				$$->left = dclname($1->n->sym);  // it's a colas, so must not re-use an oldname.
 483//			break;
 484//		}
 485//		$$ = colas($1, $3, $2);
 486	}
 487|	expr LINC
 488	{
 489//		$$ = nod(OASOP, $1, nodintconst(1));
 490//		$$->etype = OADD;
 491	}
 492|	expr LDEC
 493	{
 494//		$$ = nod(OASOP, $1, nodintconst(1));
 495//		$$->etype = OSUB;
 496	}
 497
 498case:
 499	LCASE expr_or_type_list ':'
 500	{
 501//		Node *n, *nn;
 502//
 503//		// will be converted to OCASE
 504//		// right will point to next case
 505//		// done in casebody()
 506//		markdcl();
 507//		$$ = nod(OXCASE, N, N);
 508//		$$->list = $2;
 509//		if(typesw != N && typesw->right != N && (n=typesw->right->left) != N) {
 510//			// type switch - declare variable
 511//			nn = newname(n->sym);
 512//			declare(nn, dclcontext);
 513//			$$->nname = nn;
 514//
 515//			// keep track of the instances for reporting unused
 516//			nn->defn = typesw->right;
 517//		}
 518	}
 519|	LCASE expr_or_type_list '=' expr ':'
 520	{
 521//		Node *n;
 522//
 523//		// will be converted to OCASE
 524//		// right will point to next case
 525//		// done in casebody()
 526//		markdcl();
 527//		$$ = nod(OXCASE, N, N);
 528//		if($2->next == nil)
 529//			n = nod(OAS, $2->n, $4);
 530//		else {
 531//			n = nod(OAS2, N, N);
 532//			n->list = $2;
 533//			n->rlist = list1($4);
 534//		}
 535//		$$->list = list1(n);
 536	}
 537|	LCASE expr_or_type_list LDECLAS expr ':'
 538	{
 539//		// will be converted to OCASE
 540//		// right will point to next case
 541//		// done in casebody()
 542//		markdcl();
 543//		$$ = nod(OXCASE, N, N);
 544//		$$->list = list1(colas($2, list1($4), $3));
 545	}
 546|	LDEFAULT ':'
 547	{
 548//		Node *n, *nn;
 549//
 550//		markdcl();
 551//		$$ = nod(OXCASE, N, N);
 552//		if(typesw != N && typesw->right != N && (n=typesw->right->left) != N) {
 553//			// type switch - declare variable
 554//			nn = newname(n->sym);
 555//			declare(nn, dclcontext);
 556//			$$->nname = nn;
 557//
 558//			// keep track of the instances for reporting unused
 559//			nn->defn = typesw->right;
 560//		}
 561	}
 562
 563compound_stmt:
 564	'{'
 565	{
 566//		markdcl();
 567	}
 568	stmt_list '}'
 569	{
 570//		if($3 == nil)
 571//			$$ = nod(OEMPTY, N, N);
 572//		else
 573//			$$ = liststmt($3);
 574//		popdcl();
 575	}
 576
 577caseblock:
 578	case
 579	{
 580//		// If the last token read by the lexer was consumed
 581//		// as part of the case, clear it (parser has cleared yychar).
 582//		// If the last token read by the lexer was the lookahead
 583//		// leave it alone (parser has it cached in yychar).
 584//		// This is so that the stmt_list action doesn't look at
 585//		// the case tokens if the stmt_list is empty.
 586//		yylast = yychar;
 587//		$1->xoffset = block;
 588	}
 589	stmt_list
 590	{
 591//		int last;
 592//
 593//		// This is the only place in the language where a statement
 594//		// list is not allowed to drop the final semicolon, because
 595//		// it's the only place where a statement list is not followed 
 596//		// by a closing brace.  Handle the error for pedantry.
 597//
 598//		// Find the final token of the statement list.
 599//		// yylast is lookahead; yyprev is last of stmt_list
 600//		last = yyprev;
 601//
 602//		if(last > 0 && last != ';' && yychar != '}')
 603//			yyerror("missing statement after label");
 604//		$$ = $1;
 605//		$$->nbody = $3;
 606//		popdcl();
 607	}
 608
 609caseblock_list:
 610	{
 611//		$$ = nil;
 612	}
 613|	caseblock_list caseblock
 614	{
 615//		$$ = list($1, $2);
 616	}
 617
 618loop_body:
 619	LBODY
 620	{
 621//		markdcl();
 622	}
 623	stmt_list '}'
 624	{
 625//		$$ = $3;
 626//		popdcl();
 627	}
 628
 629range_stmt:
 630	expr_list '=' LRANGE expr
 631	{
 632//		$$ = nod(ORANGE, N, $4);
 633//		$$->list = $1;
 634//		$$->etype = 0;	// := flag
 635	}
 636|	expr_list LDECLAS LRANGE expr
 637	{
 638//		$$ = nod(ORANGE, N, $4);
 639//		$$->list = $1;
 640//		$$->colas = 1;
 641//		colasdefn($1, $$);
 642	}
 643
 644for_header:
 645	osimple_stmt ';' osimple_stmt ';' osimple_stmt
 646	{
 647//		// init ; test ; incr
 648//		if($5 != N && $5->colas != 0)
 649//			yyerror("cannot declare in the for-increment");
 650//		$$ = nod(OFOR, N, N);
 651//		if($1 != N)
 652//			$$->ninit = list1($1);
 653//		$$->ntest = $3;
 654//		$$->nincr = $5;
 655	}
 656|	osimple_stmt
 657	{
 658//		// normal test
 659//		$$ = nod(OFOR, N, N);
 660//		$$->ntest = $1;
 661	}
 662|	range_stmt
 663
 664for_body:
 665	for_header loop_body
 666	{
 667//		$$ = $1;
 668//		$$->nbody = concat($$->nbody, $2);
 669	}
 670
 671for_stmt:
 672	LFOR
 673	{
 674//		markdcl();
 675	}
 676	for_body
 677	{
 678//		$$ = $3;
 679//		popdcl();
 680	}
 681
 682if_header:
 683	osimple_stmt
 684	{
 685//		// test
 686//		$$ = nod(OIF, N, N);
 687//		$$->ntest = $1;
 688	}
 689|	osimple_stmt ';' osimple_stmt
 690	{
 691//		// init ; test
 692//		$$ = nod(OIF, N, N);
 693//		if($1 != N)
 694//			$$->ninit = list1($1);
 695//		$$->ntest = $3;
 696	}
 697
 698/* IF cond body (ELSE IF cond body)* (ELSE block)? */
 699if_stmt:
 700	LIF
 701	{
 702//		markdcl();
 703	}
 704	if_header
 705	{
 706//		if($3->ntest == N)
 707//			yyerror("missing condition in if statement");
 708	}
 709	loop_body
 710	{
 711//		$3->nbody = $5;
 712	}
 713	elseif_list else
 714	{
 715//		Node *n;
 716//		NodeList *nn;
 717//
 718//		$$ = $3;
 719//		n = $3;
 720//		popdcl();
 721//		for(nn = concat($7, $8); nn; nn = nn->next) {
 722//			if(nn->n->op == OIF)
 723//				popdcl();
 724//			n->nelse = list1(nn->n);
 725//			n = nn->n;
 726//		}
 727	}
 728
 729elseif:
 730	LELSE LIF 
 731	{
 732//		markdcl();
 733	}
 734	if_header loop_body
 735	{
 736//		if($4->ntest == N)
 737//			yyerror("missing condition in if statement");
 738//		$4->nbody = $5;
 739//		$$ = list1($4);
 740	}
 741
 742elseif_list:
 743	{
 744//		$$ = nil;
 745	}
 746|	elseif_list elseif
 747	{
 748//		$$ = concat($1, $2);
 749	}
 750
 751else:
 752	{
 753//		$$ = nil;
 754	}
 755|	LELSE compound_stmt
 756	{
 757//		NodeList *node;
 758//		
 759//		node = mal(sizeof *node);
 760//		node->n = $2;
 761//		node->end = node;
 762//		$$ = node;
 763	}
 764
 765switch_stmt:
 766	LSWITCH
 767	{
 768//		markdcl();
 769	}
 770	if_header
 771	{
 772//		Node *n;
 773//		n = $3->ntest;
 774//		if(n != N && n->op != OTYPESW)
 775//			n = N;
 776//		typesw = nod(OXXX, typesw, n);
 777	}
 778	LBODY caseblock_list '}'
 779	{
 780//		$$ = $3;
 781//		$$->op = OSWITCH;
 782//		$$->list = $6;
 783//		typesw = typesw->left;
 784//		popdcl();
 785	}
 786
 787select_stmt:
 788	LSELECT
 789	{
 790//		typesw = nod(OXXX, typesw, N);
 791	}
 792	LBODY caseblock_list '}'
 793	{
 794//		$$ = nod(OSELECT, N, N);
 795//		$$->lineno = typesw->lineno;
 796//		$$->list = $4;
 797//		typesw = typesw->left;
 798	}
 799
 800/*
 801 * expressions
 802 */
 803expr:
 804	uexpr
 805|	expr LOROR expr
 806	{
 807//		$$ = nod(OOROR, $1, $3);
 808	}
 809|	expr LANDAND expr
 810	{
 811//		$$ = nod(OANDAND, $1, $3);
 812	}
 813|	expr LEQ expr
 814	{
 815//		$$ = nod(OEQ, $1, $3);
 816	}
 817|	expr LNE expr
 818	{
 819//		$$ = nod(ONE, $1, $3);
 820	}
 821|	expr LLT expr
 822	{
 823//		$$ = nod(OLT, $1, $3);
 824	}
 825|	expr LLE expr
 826	{
 827//		$$ = nod(OLE, $1, $3);
 828	}
 829|	expr LGE expr
 830	{
 831//		$$ = nod(OGE, $1, $3);
 832	}
 833|	expr LGT expr
 834	{
 835//		$$ = nod(OGT, $1, $3);
 836	}
 837|	expr '+' expr
 838	{
 839//		$$ = nod(OADD, $1, $3);
 840	}
 841|	expr '-' expr
 842	{
 843//		$$ = nod(OSUB, $1, $3);
 844	}
 845|	expr '|' expr
 846	{
 847//		$$ = nod(OOR, $1, $3);
 848	}
 849|	expr '^' expr
 850	{
 851//		$$ = nod(OXOR, $1, $3);
 852	}
 853|	expr '*' expr
 854	{
 855//		$$ = nod(OMUL, $1, $3);
 856	}
 857|	expr '/' expr
 858	{
 859//		$$ = nod(ODIV, $1, $3);
 860	}
 861|	expr '%' expr
 862	{
 863//		$$ = nod(OMOD, $1, $3);
 864	}
 865|	expr '&' expr
 866	{
 867//		$$ = nod(OAND, $1, $3);
 868	}
 869|	expr LANDNOT expr
 870	{
 871//		$$ = nod(OANDNOT, $1, $3);
 872	}
 873|	expr LLSH expr
 874	{
 875//		$$ = nod(OLSH, $1, $3);
 876	}
 877|	expr LRSH expr
 878	{
 879//		$$ = nod(ORSH, $1, $3);
 880	}
 881	/* not an expression anymore, but left in so we can give a good error */
 882|	expr LCOMM expr
 883	{
 884//		$$ = nod(OSEND, $1, $3);
 885	}
 886
 887uexpr:
 888	pexpr
 889|	'*' uexpr
 890	{
 891//		$$ = nod(OIND, $2, N);
 892	}
 893|	'&' uexpr
 894	{
 895//		if($2->op == OCOMPLIT) {
 896//			// Special case for &T{...}: turn into (*T){...}.
 897//			$$ = $2;
 898//			$$->right = nod(OIND, $$->right, N);
 899//			$$->right->implicit = 1;
 900//		} else {
 901//			$$ = nod(OADDR, $2, N);
 902//		}
 903	}
 904|	'+' uexpr
 905	{
 906//		$$ = nod(OPLUS, $2, N);
 907	}
 908|	'-' uexpr
 909	{
 910//		$$ = nod(OMINUS, $2, N);
 911	}
 912|	'!' uexpr
 913	{
 914//		$$ = nod(ONOT, $2, N);
 915	}
 916|	'~' uexpr
 917	{
 918//		yyerror("the bitwise complement operator is ^");
 919//		$$ = nod(OCOM, $2, N);
 920	}
 921|	'^' uexpr
 922	{
 923//		$$ = nod(OCOM, $2, N);
 924	}
 925|	LCOMM uexpr
 926	{
 927//		$$ = nod(ORECV, $2, N);
 928	}
 929
 930/*
 931 * call-like statements that
 932 * can be preceded by 'defer' and 'go'
 933 */
 934pseudocall:
 935	pexpr '(' ')'
 936	{
 937//		$$ = nod(OCALL, $1, N);
 938	}
 939|	pexpr '(' expr_or_type_list ocomma ')'
 940	{
 941//		$$ = nod(OCALL, $1, N);
 942//		$$->list = $3;
 943	}
 944|	pexpr '(' expr_or_type_list LDDD ocomma ')'
 945	{
 946//		$$ = nod(OCALL, $1, N);
 947//		$$->list = $3;
 948//		$$->isddd = 1;
 949	}
 950
 951pexpr_no_paren:
 952	LLITERAL
 953	{
 954//		$$ = nodlit($1);
 955	}
 956|	name
 957|	pexpr '.' sym
 958	{
 959//		if($1->op == OPACK) {
 960//			Sym *s;
 961//			s = restrictlookup($3->name, $1->pkg);
 962//			$1->used = 1;
 963//			$$ = oldname(s);
 964//			break;
 965//		}
 966//		$$ = nod(OXDOT, $1, newname($3));
 967	}
 968|	pexpr '.' '(' expr_or_type ')'
 969	{
 970//		$$ = nod(ODOTTYPE, $1, $4);
 971	}
 972|	pexpr '.' '(' LTYPE ')'
 973	{
 974//		$$ = nod(OTYPESW, N, $1);
 975	}
 976|	pexpr '[' expr ']'
 977	{
 978//		$$ = nod(OINDEX, $1, $3);
 979	}
 980|	pexpr '[' oexpr ':' oexpr ']'
 981	{
 982//		$$ = nod(OSLICE, $1, nod(OKEY, $3, $5));
 983	}
 984|	pexpr '[' oexpr ':' oexpr ':' oexpr ']'
 985	{
 986//		if($5 == N)
 987//			yyerror("middle index required in 3-index slice");
 988//		if($7 == N)
 989//			yyerror("final index required in 3-index slice");
 990//		$$ = nod(OSLICE3, $1, nod(OKEY, $3, nod(OKEY, $5, $7)));
 991	}
 992|	pseudocall
 993|	convtype '(' expr ocomma ')'
 994	{
 995//		// conversion
 996//		$$ = nod(OCALL, $1, N);
 997//		$$->list = list1($3);
 998	}
 999|	comptype lbrace start_complit braced_keyval_list '}'
1000	{
1001//		$$ = $3;
1002//		$$->right = $1;
1003//		$$->list = $4;
1004//		fixlbrace($2);
1005	}
1006|	pexpr_no_paren '{' start_complit braced_keyval_list '}'
1007	{
1008//		$$ = $3;
1009//		$$->right = $1;
1010//		$$->list = $4;
1011	}
1012|	'(' expr_or_type ')' '{' start_complit braced_keyval_list '}'
1013	{
1014//		yyerror("cannot parenthesize type in composite literal");
1015//		$$ = $5;
1016//		$$->right = $2;
1017//		$$->list = $6;
1018	}
1019|	fnliteral
1020
1021start_complit:
1022	{
1023//		// composite expression.
1024//		// make node early so we get the right line number.
1025//		$$ = nod(OCOMPLIT, N, N);
1026	}
1027
1028keyval:
1029	expr ':' complitexpr
1030	{
1031//		$$ = nod(OKEY, $1, $3);
1032	}
1033
1034bare_complitexpr:
1035	expr
1036	{
1037//		// These nodes do not carry line numbers.
1038//		// Since a composite literal commonly spans several lines,
1039//		// the line number on errors may be misleading.
1040//		// Introduce a wrapper node to give the correct line.
1041//		$$ = $1;
1042//		switch($$->op) {
1043//		case ONAME:
1044//		case ONONAME:
1045//		case OTYPE:
1046//		case OPACK:
1047//		case OLITERAL:
1048//			$$ = nod(OPAREN, $$, N);
1049//			$$->implicit = 1;
1050//		}
1051	}
1052|	'{' start_complit braced_keyval_list '}'
1053	{
1054//		$$ = $2;
1055//		$$->list = $3;
1056	}
1057
1058complitexpr:
1059	expr
1060|	'{' start_complit braced_keyval_list '}'
1061	{
1062//		$$ = $2;
1063//		$$->list = $3;
1064	}
1065
1066pexpr:
1067	pexpr_no_paren
1068|	'(' expr_or_type ')'
1069	{
1070//		$$ = $2;
1071//		
1072//		// Need to know on lhs of := whether there are ( ).
1073//		// Don't bother with the OPAREN in other cases:
1074//		// it's just a waste of memory and time.
1075//		switch($$->op) {
1076//		case ONAME:
1077//		case ONONAME:
1078//		case OPACK:
1079//		case OTYPE:
1080//		case OLITERAL:
1081//		case OTYPESW:
1082//			$$ = nod(OPAREN, $$, N);
1083//		}
1084	}
1085
1086expr_or_type:
1087	expr
1088|	non_expr_type	%prec PreferToRightParen
1089
1090name_or_type:
1091	ntype
1092
1093lbrace:
1094	LBODY
1095	{
1096//		$$ = LBODY;
1097	}
1098|	'{'
1099	{
1100//		$$ = '{';
1101	}
1102
1103/*
1104 * names and types
1105 *	newname is used before declared
1106 *	oldname is used after declared
1107 */
1108new_name:
1109	sym
1110	{
1111//		if($1 == S)
1112//			$$ = N;
1113//		else
1114//			$$ = newname($1);
1115	}
1116
1117dcl_name:
1118	sym
1119	{
1120//		$$ = dclname($1);
1121	}
1122
1123onew_name:
1124	{
1125//		$$ = N;
1126	}
1127|	new_name
1128
1129sym:
1130	LNAME
1131	{
1132//		$$ = $1;
1133//		// during imports, unqualified non-exported identifiers are from builtinpkg
1134//		if(importpkg != nil && !exportname($1->name))
1135//			$$ = pkglookup($1->name, builtinpkg);
1136	}
1137|	hidden_importsym
1138|	'?'
1139	{
1140//		$$ = S;
1141	}
1142
1143hidden_importsym:
1144	'@' LLITERAL '.' LNAME
1145	{
1146//		Pkg *p;
1147//
1148//		if($2.u.sval->len == 0)
1149//			p = importpkg;
1150//		else {
1151//			if(isbadimport($2.u.sval))
1152//				errorexit();
1153//			p = mkpkg($2.u.sval);
1154//		}
1155//		$$ = pkglookup($4->name, p);
1156	}
1157|	'@' LLITERAL '.' '?'
1158	{
1159//		Pkg *p;
1160//
1161//		if($2.u.sval->len == 0)
1162//			p = importpkg;
1163//		else {
1164//			if(isbadimport($2.u.sval))
1165//				errorexit();
1166//			p = mkpkg($2.u.sval);
1167//		}
1168//		$$ = pkglookup("?", p);
1169	}
1170
1171name:
1172	sym	%prec NotParen
1173	{
1174//		$$ = oldname($1);
1175//		if($$->pack != N)
1176//			$$->pack->used = 1;
1177	}
1178
1179labelname:
1180	new_name
1181
1182/*
1183 * to avoid parsing conflicts, type is split into
1184 *	channel types
1185 *	function types
1186 *	parenthesized types
1187 *	any other type
1188 * the type system makes additional restrictions,
1189 * but those are not implemented in the grammar.
1190 */
1191dotdotdot:
1192	LDDD
1193	{
1194//		yyerror("final argument in variadic function missing type");
1195//		$$ = nod(ODDD, typenod(typ(TINTER)), N);
1196	}
1197|	LDDD ntype
1198	{
1199//		$$ = nod(ODDD, $2, N);
1200	}
1201
1202ntype:
1203	recvchantype
1204|	fntype
1205|	othertype
1206|	ptrtype
1207|	dotname
1208|	'(' ntype ')'
1209	{
1210//		$$ = nod(OTPAREN, $2, N);
1211	}
1212
1213non_expr_type:
1214	recvchantype
1215|	fntype
1216|	othertype
1217|	'*' non_expr_type
1218	{
1219//		$$ = nod(OIND, $2, N);
1220	}
1221
1222non_recvchantype:
1223	fntype
1224|	othertype
1225|	ptrtype
1226|	dotname
1227|	'(' ntype ')'
1228	{
1229//		$$ = nod(OTPAREN, $2, N);
1230	}
1231
1232convtype:
1233	fntype
1234|	othertype
1235
1236comptype:
1237	othertype
1238
1239fnret_type:
1240	recvchantype
1241|	fntype
1242|	othertype
1243|	ptrtype
1244|	dotname
1245
1246dotname:
1247	name
1248|	name '.' sym
1249	{
1250//		if($1->op == OPACK) {
1251//			Sym *s;
1252//			s = restrictlookup($3->name, $1->pkg);
1253//			$1->used = 1;
1254//			$$ = oldname(s);
1255//			break;
1256//		}
1257//		$$ = nod(OXDOT, $1, newname($3));
1258	}
1259
1260othertype:
1261	'[' oexpr ']' ntype
1262	{
1263//		$$ = nod(OTARRAY, $2, $4);
1264	}
1265|	'[' LDDD ']' ntype
1266	{
1267//		// array literal of nelem
1268//		$$ = nod(OTARRAY, nod(ODDD, N, N), $4);
1269	}
1270|	LCHAN non_recvchantype
1271	{
1272//		$$ = nod(OTCHAN, $2, N);
1273//		$$->etype = Cboth;
1274	}
1275|	LCHAN LCOMM ntype
1276	{
1277//		$$ = nod(OTCHAN, $3, N);
1278//		$$->etype = Csend;
1279	}
1280|	LMAP '[' ntype ']' ntype
1281	{
1282//		$$ = nod(OTMAP, $3, $5);
1283	}
1284|	structtype
1285|	interfacetype
1286
1287ptrtype:
1288	'*' ntype
1289	{
1290//		$$ = nod(OIND, $2, N);
1291	}
1292
1293recvchantype:
1294	LCOMM LCHAN ntype
1295	{
1296//		$$ = nod(OTCHAN, $3, N);
1297//		$$->etype = Crecv;
1298	}
1299
1300structtype:
1301	LSTRUCT lbrace structdcl_list osemi '}'
1302	{
1303//		$$ = nod(OTSTRUCT, N, N);
1304//		$$->list = $3;
1305//		fixlbrace($2);
1306	}
1307|	LSTRUCT lbrace '}'
1308	{
1309//		$$ = nod(OTSTRUCT, N, N);
1310//		fixlbrace($2);
1311	}
1312
1313interfacetype:
1314	LINTERFACE lbrace interfacedcl_list osemi '}'
1315	{
1316//		$$ = nod(OTINTER, N, N);
1317//		$$->list = $3;
1318//		fixlbrace($2);
1319	}
1320|	LINTERFACE lbrace '}'
1321	{
1322//		$$ = nod(OTINTER, N, N);
1323//		fixlbrace($2);
1324	}
1325
1326/*
1327 * function stuff
1328 * all in one place to show how crappy it all is
1329 */
1330xfndcl:
1331	LFUNC fndcl fnbody
1332	{
1333//		$$ = $2;
1334//		if($$ == N)
1335//			break;
1336//		if(noescape && $3 != nil)
1337//			yyerror("can only use //go:noescape with external func implementations");
1338//		$$->nbody = $3;
1339//		$$->endlineno = lineno;
1340//		$$->noescape = noescape;
1341//		funcbody($$);
1342	}
1343
1344fndcl:
1345	sym '(' oarg_type_list_ocomma ')' fnres
1346	{
1347//		Node *t;
1348//
1349//		$$ = N;
1350//		$3 = checkarglist($3, 1);
1351//
1352//		if(strcmp($1->name, "init") == 0) {
1353//			$1 = renameinit();
1354//			if($3 != nil || $5 != nil)
1355//				yyerror("func init must have no arguments and no return values");
1356//		}
1357//		if(strcmp(localpkg->name, "main") == 0 && strcmp($1->name, "main") == 0) {
1358//			if($3 != nil || $5 != nil)
1359//				yyerror("func main must have no arguments and no return values");
1360//		}
1361//
1362//		t = nod(OTFUNC, N, N);
1363//		t->list = $3;
1364//		t->rlist = $5;
1365//
1366//		$$ = nod(ODCLFUNC, N, N);
1367//		$$->nname = newname($1);
1368//		$$->nname->defn = $$;
1369//		$$->nname->ntype = t;		// TODO: check if nname already has an ntype
1370//		declare($$->nname, PFUNC);
1371//
1372//		funchdr($$);
1373	}
1374|	'(' oarg_type_list_ocomma ')' sym '(' oarg_type_list_ocomma ')' fnres
1375	{
1376//		Node *rcvr, *t;
1377//
1378//		$$ = N;
1379//		$2 = checkarglist($2, 0);
1380//		$6 = checkarglist($6, 1);
1381//
1382//		if($2 == nil) {
1383//			yyerror("method has no receiver");
1384//			break;
1385//		}
1386//		if($2->next != nil) {
1387//			yyerror("method has multiple receivers");
1388//			break;
1389//		}
1390//		rcvr = $2->n;
1391//		if(rcvr->op != ODCLFIELD) {
1392//			yyerror("bad receiver in method");
1393//			break;
1394//		}
1395//		if(rcvr->right->op == OTPAREN || (rcvr->right->op == OIND && rcvr->right->left->op == OTPAREN))
1396//			yyerror("cannot parenthesize receiver type");
1397//
1398//		t = nod(OTFUNC, rcvr, N);
1399//		t->list = $6;
1400//		t->rlist = $8;
1401//
1402//		$$ = nod(ODCLFUNC, N, N);
1403//		$$->shortname = newname($4);
1404//		$$->nname = methodname1($$->shortname, rcvr->right);
1405//		$$->nname->defn = $$;
1406//		$$->nname->ntype = t;
1407//		$$->nname->nointerface = nointerface;
1408//		declare($$->nname, PFUNC);
1409//
1410//		funchdr($$);
1411	}
1412
1413hidden_fndcl:
1414	hidden_pkg_importsym '(' ohidden_funarg_list ')' ohidden_funres
1415	{
1416//		Sym *s;
1417//		Type *t;
1418//
1419//		$$ = N;
1420//
1421//		s = $1;
1422//		t = functype(N, $3, $5);
1423//
1424//		importsym(s, ONAME);
1425//		if(s->def != N && s->def->op == ONAME) {
1426//			if(eqtype(t, s->def->type)) {
1427//				dclcontext = PDISCARD;  // since we skip funchdr below
1428//				break;
1429//			}
1430//			yyerror("inconsistent definition for func %S during import\n\t%T\n\t%T", s, s->def->type, t);
1431//		}
1432//
1433//		$$ = newname(s);
1434//		$$->type = t;
1435//		declare($$, PFUNC);
1436//
1437//		funchdr($$);
1438	}
1439|	'(' hidden_funarg_list ')' sym '(' ohidden_funarg_list ')' ohidden_funres
1440	{
1441//		$$ = methodname1(newname($4), $2->n->right); 
1442//		$$->type = functype($2->n, $6, $8);
1443//
1444//		checkwidth($$->type);
1445//		addmethod($4, $$->type, 0, nointerface);
1446//		nointerface = 0;
1447//		funchdr($$);
1448//		
1449//		// inl.c's inlnode in on a dotmeth node expects to find the inlineable body as
1450//		// (dotmeth's type)->nname->inl, and dotmeth's type has been pulled
1451//		// out by typecheck's lookdot as this $$->ttype.  So by providing
1452//		// this back link here we avoid special casing there.
1453//		$$->type->nname = $$;
1454	}
1455
1456fntype:
1457	LFUNC '(' oarg_type_list_ocomma ')' fnres
1458	{
1459//		$3 = checkarglist($3, 1);
1460//		$$ = nod(OTFUNC, N, N);
1461//		$$->list = $3;
1462//		$$->rlist = $5;
1463	}
1464
1465fnbody:
1466	{
1467//		$$ = nil;
1468	}
1469|	'{' stmt_list '}'
1470	{
1471//		$$ = $2;
1472//		if($$ == nil)
1473//			$$ = list1(nod(OEMPTY, N, N));
1474	}
1475
1476fnres:
1477	%prec NotParen
1478	{
1479//		$$ = nil;
1480	}
1481|	fnret_type
1482	{
1483//		$$ = list1(nod(ODCLFIELD, N, $1));
1484	}
1485|	'(' oarg_type_list_ocomma ')'
1486	{
1487//		$2 = checkarglist($2, 0);
1488//		$$ = $2;
1489	}
1490
1491fnlitdcl:
1492	fntype
1493	{
1494//		closurehdr($1);
1495	}
1496
1497fnliteral:
1498	fnlitdcl lbrace stmt_list '}'
1499	{
1500//		$$ = closurebody($3);
1501//		fixlbrace($2);
1502	}
1503|	fnlitdcl error
1504	{
1505//		$$ = closurebody(nil);
1506	}
1507
1508/*
1509 * lists of things
1510 * note that they are left recursive
1511 * to conserve yacc stack. they need to
1512 * be reversed to interpret correctly
1513 */
1514xdcl_list:
1515	{
1516//		$$ = nil;
1517	}
1518|	xdcl_list xdcl ';'
1519	{
1520//		$$ = concat($1, $2);
1521//		if(nsyntaxerrors == 0)
1522//			testdclstack();
1523//		nointerface = 0;
1524//		noescape = 0;
1525	}
1526
1527vardcl_list:
1528	vardcl
1529|	vardcl_list ';' vardcl
1530	{
1531//		$$ = concat($1, $3);
1532	}
1533
1534constdcl_list:
1535	constdcl1
1536|	constdcl_list ';' constdcl1
1537	{
1538//		$$ = concat($1, $3);
1539	}
1540
1541typedcl_list:
1542	typedcl
1543	{
1544//		$$ = list1($1);
1545	}
1546|	typedcl_list ';' typedcl
1547	{
1548//		$$ = list($1, $3);
1549	}
1550
1551structdcl_list:
1552	structdcl
1553|	structdcl_list ';' structdcl
1554	{
1555//		$$ = concat($1, $3);
1556	}
1557
1558interfacedcl_list:
1559	interfacedcl
1560	{
1561//		$$ = list1($1);
1562	}
1563|	interfacedcl_list ';' interfacedcl
1564	{
1565//		$$ = list($1, $3);
1566	}
1567
1568structdcl:
1569	new_name_list ntype oliteral
1570	{
1571//		NodeList *l;
1572//
1573//		Node *n;
1574//		l = $1;
1575//		if(l == nil) {
1576//			// ? symbol, during import (list1(N) == nil)
1577//			n = $2;
1578//			if(n->op == OIND)
1579//				n = n->left;
1580//			n = embedded(n->sym, importpkg);
1581//			n->right = $2;
1582//			n->val = $3;
1583//			$$ = list1(n);
1584//			break;
1585//		}
1586//
1587//		for(l=$1; l; l=l->next) {
1588//			l->n = nod(ODCLFIELD, l->n, $2);
1589//			l->n->val = $3;
1590//		}
1591	}
1592|	embed oliteral
1593	{
1594//		$1->val = $2;
1595//		$$ = list1($1);
1596	}
1597|	'(' embed ')' oliteral
1598	{
1599//		$2->val = $4;
1600//		$$ = list1($2);
1601//		yyerror("cannot parenthesize embedded type");
1602	}
1603|	'*' embed oliteral
1604	{
1605//		$2->right = nod(OIND, $2->right, N);
1606//		$2->val = $3;
1607//		$$ = list1($2);
1608	}
1609|	'(' '*' embed ')' oliteral
1610	{
1611//		$3->right = nod(OIND, $3->right, N);
1612//		$3->val = $5;
1613//		$$ = list1($3);
1614//		yyerror("cannot parenthesize embedded type");
1615	}
1616|	'*' '(' embed ')' oliteral
1617	{
1618//		$3->right = nod(OIND, $3->right, N);
1619//		$3->val = $5;
1620//		$$ = list1($3);
1621//		yyerror("cannot parenthesize embedded type");
1622	}
1623
1624packname:
1625	LNAME
1626	{
1627//		Node *n;
1628//
1629//		$$ = $1;
1630//		n = oldname($1);
1631//		if(n->pack != N)
1632//			n->pack->used = 1;
1633	}
1634|	LNAME '.' sym
1635	{
1636//		Pkg *pkg;
1637//
1638//		if($1->def == N || $1->def->op != OPACK) {
1639//			yyerror("%S is not a package", $1);
1640//			pkg = localpkg;
1641//		} else {
1642//			$1->def->used = 1;
1643//			pkg = $1->def->pkg;
1644//		}
1645//		$$ = restrictlookup($3->name, pkg);
1646	}
1647
1648embed:
1649	packname
1650	{
1651//		$$ = embedded($1, localpkg);
1652	}
1653
1654interfacedcl:
1655	new_name indcl
1656	{
1657//		$$ = nod(ODCLFIELD, $1, $2);
1658//		ifacedcl($$);
1659	}
1660|	packname
1661	{
1662//		$$ = nod(ODCLFIELD, N, oldname($1));
1663	}
1664|	'(' packname ')'
1665	{
1666//		$$ = nod(ODCLFIELD, N, oldname($2));
1667//		yyerror("cannot parenthesize embedded type");
1668	}
1669
1670indcl:
1671	'(' oarg_type_list_ocomma ')' fnres
1672	{
1673//		// without func keyword
1674//		$2 = checkarglist($2, 1);
1675//		$$ = nod(OTFUNC, fakethis(), N);
1676//		$$->list = $2;
1677//		$$->rlist = $4;
1678	}
1679
1680/*
1681 * function arguments.
1682 */
1683arg_type:
1684	name_or_type
1685|	sym name_or_type
1686	{
1687//		$$ = nod(ONONAME, N, N);
1688//		$$->sym = $1;
1689//		$$ = nod(OKEY, $$, $2);
1690	}
1691|	sym dotdotdot
1692	{
1693//		$$ = nod(ONONAME, N, N);
1694//		$$->sym = $1;
1695//		$$ = nod(OKEY, $$, $2);
1696	}
1697|	dotdotdot
1698
1699arg_type_list:
1700	arg_type
1701	{
1702//		$$ = list1($1);
1703	}
1704|	arg_type_list ',' arg_type
1705	{
1706//		$$ = list($1, $3);
1707	}
1708
1709oarg_type_list_ocomma:
1710	{
1711//		$$ = nil;
1712	}
1713|	arg_type_list ocomma
1714	{
1715//		$$ = $1;
1716	}
1717
1718/*
1719 * statement
1720 */
1721stmt:
1722	{
1723//		$$ = N;
1724	}
1725|	compound_stmt
1726|	common_dcl
1727	{
1728//		$$ = liststmt($1);
1729	}
1730|	non_dcl_stmt
1731|	error
1732	{
1733//		$$ = N;
1734	}
1735
1736non_dcl_stmt:
1737	simple_stmt
1738|	for_stmt
1739|	switch_stmt
1740|	select_stmt
1741|	if_stmt
1742|	labelname ':'
1743	{
1744//		$1 = nod(OLABEL, $1, N);
1745//		$1->sym = dclstack;  // context, for goto restrictions
1746	}
1747	stmt
1748	{
1749//		NodeList *l;
1750//
1751//		$1->defn = $4;
1752//		l = list1($1);
1753//		if($4)
1754//			l = list(l, $4);
1755//		$$ = liststmt(l);
1756	}
1757|	LFALL
1758	{
1759//		// will be converted to OFALL
1760//		$$ = nod(OXFALL, N, N);
1761//		$$->xoffset = block;
1762	}
1763|	LBREAK onew_name
1764	{
1765//		$$ = nod(OBREAK, $2, N);
1766	}
1767|	LCONTINUE onew_name
1768	{
1769//		$$ = nod(OCONTINUE, $2, N);
1770	}
1771|	LGO pseudocall
1772	{
1773//		$$ = nod(OPROC, $2, N);
1774	}
1775|	LDEFER pseudocall
1776	{
1777//		$$ = nod(ODEFER, $2, N);
1778	}
1779|	LGOTO new_name
1780	{
1781//		$$ = nod(OGOTO, $2, N);
1782//		$$->sym = dclstack;  // context, for goto restrictions
1783	}
1784|	LRETURN oexpr_list
1785	{
1786//		$$ = nod(ORETURN, N, N);
1787//		$$->list = $2;
1788//		if($$->list == nil && curfn != N) {
1789//			NodeList *l;
1790//
1791//			for(l=curfn->dcl; l; l=l->next) {
1792//				if(l->n->class == PPARAM)
1793//					continue;
1794//				if(l->n->class != PPARAMOUT)
1795//					break;
1796//				if(l->n->sym->def != l->n)
1797//					yyerror("%s is shadowed during return", l->n->sym->name);
1798//			}
1799//		}
1800	}
1801
1802stmt_list:
1803	stmt
1804	{
1805//		$$ = nil;
1806//		if($1 != N)
1807//			$$ = list1($1);
1808	}
1809|	stmt_list ';' stmt
1810	{
1811//		$$ = $1;
1812//		if($3 != N)
1813//			$$ = list($$, $3);
1814	}
1815
1816new_name_list:
1817	new_name
1818	{
1819//		$$ = list1($1);
1820	}
1821|	new_name_list ',' new_name
1822	{
1823//		$$ = list($1, $3);
1824	}
1825
1826dcl_name_list:
1827	dcl_name
1828	{
1829//		$$ = list1($1);
1830	}
1831|	dcl_name_list ',' dcl_name
1832	{
1833//		$$ = list($1, $3);
1834	}
1835
1836expr_list:
1837	expr
1838	{
1839//		$$ = list1($1);
1840	}
1841|	expr_list ',' expr
1842	{
1843//		$$ = list($1, $3);
1844	}
1845
1846expr_or_type_list:
1847	expr_or_type
1848	{
1849//		$$ = list1($1);
1850	}
1851|	expr_or_type_list ',' expr_or_type
1852	{
1853//		$$ = list($1, $3);
1854	}
1855
1856/*
1857 * list of combo of keyval and val
1858 */
1859keyval_list:
1860	keyval
1861	{
1862//		$$ = list1($1);
1863	}
1864|	bare_complitexpr
1865	{
1866//		$$ = list1($1);
1867	}
1868|	keyval_list ',' keyval
1869	{
1870//		$$ = list($1, $3);
1871	}
1872|	keyval_list ',' bare_complitexpr
1873	{
1874//		$$ = list($1, $3);
1875	}
1876
1877braced_keyval_list:
1878	{
1879//		$$ = nil;
1880	}
1881|	keyval_list ocomma
1882	{
1883//		$$ = $1;
1884	}
1885
1886/*
1887 * optional things
1888 */
1889osemi:
1890|	';'
1891
1892ocomma:
1893|	','
1894
1895oexpr:
1896	{
1897//		$$ = N;
1898	}
1899|	expr
1900
1901oexpr_list:
1902	{
1903//		$$ = nil;
1904	}
1905|	expr_list
1906
1907osimple_stmt:
1908	{
1909//		$$ = N;
1910	}
1911|	simple_stmt
1912
1913ohidden_funarg_list:
1914	{
1915//		$$ = nil;
1916	}
1917|	hidden_funarg_list
1918
1919ohidden_structdcl_list:
1920	{
1921//		$$ = nil;
1922	}
1923|	hidden_structdcl_list
1924
1925ohidden_interfacedcl_list:
1926	{
1927//		$$ = nil;
1928	}
1929|	hidden_interfacedcl_list
1930
1931oliteral:
1932	{
1933//		$$.ctype = CTxxx;
1934	}
1935|	LLITERAL
1936
1937/*
1938 * import syntax from package header
1939 */
1940hidden_import:
1941	LIMPORT LNAME LLITERAL ';'
1942	{
1943//		importimport($2, $3.u.sval);
1944	}
1945|	LVAR hidden_pkg_importsym hidden_type ';'
1946	{
1947//		importvar($2, $3);
1948	}
1949|	LCONST hidden_pkg_importsym '=' hidden_constant ';'
1950	{
1951//		importconst($2, types[TIDEAL], $4);
1952	}
1953|	LCONST hidden_pkg_importsym hidden_type '=' hidden_constant ';'
1954	{
1955//		importconst($2, $3, $5);
1956	}
1957|	LTYPE hidden_pkgtype hidden_type ';'
1958	{
1959//		importtype($2, $3);
1960	}
1961|	LFUNC hidden_fndcl fnbody ';'
1962	{
1963//		if($2 == N) {
1964//			dclcontext = PEXTERN;  // since we skip the funcbody below
1965//			break;
1966//		}
1967//
1968//		$2->inl = $3;
1969//
1970//		funcbody($2);
1971//		importlist = list(importlist, $2);
1972//
1973//		if(debug['E']) {
1974//			print("import [%Z] func %lN \n", importpkg->path, $2);
1975//			if(debug['m'] > 2 && $2->inl)
1976//				print("inl body:%+H\n", $2->inl);
1977//		}
1978	}
1979
1980hidden_pkg_importsym:
1981	hidden_importsym
1982	{
1983//		$$ = $1;
1984//		structpkg = $$->pkg;
1985	}
1986
1987hidden_pkgtype:
1988	hidden_pkg_importsym
1989	{
1990//		$$ = pkgtype($1);
1991//		importsym($1, OTYPE);
1992	}
1993
1994/*
1995 *  importing types
1996 */
1997
1998hidden_type:
1999	hidden_type_misc
2000|	hidden_type_recv_chan
2001|	hidden_type_func
2002
2003hidden_type_non_recv_chan:
2004	hidden_type_misc
2005|	hidden_type_func
2006
2007hidden_type_misc:
2008	hidden_importsym
2009	{
2010//		$$ = pkgtype($1);
2011	}
2012|	LNAME
2013	{
2014//		// predefined name like uint8
2015//		$1 = pkglookup($1->name, builtinpkg);
2016//		if($1->def == N || $1->def->op != OTYPE) {
2017//			yyerror("%s is not a type", $1->name);
2018//			$$ = T;
2019//		} else
2020//			$$ = $1->def->type;
2021	}
2022|	'[' ']' hidden_type
2023	{
2024//		$$ = aindex(N, $3);
2025	}
2026|	'[' LLITERAL ']' hidden_type
2027	{
2028//		$$ = aindex(nodlit($2), $4);
2029	}
2030|	LMAP '[' hidden_type ']' hidden_type
2031	{
2032//		$$ = maptype($3, $5);
2033	}
2034|	LSTRUCT '{' ohidden_structdcl_list '}'
2035	{
2036//		$$ = tostruct($3);
2037	}
2038|	LINTERFACE '{' ohidden_interfacedcl_list '}'
2039	{
2040//		$$ = tointerface($3);
2041	}
2042|	'*' hidden_type
2043	{
2044//		$$ = ptrto($2);
2045	}
2046|	LCHAN hidden_type_non_recv_chan
2047	{
2048//		$$ = typ(TCHAN);
2049//		$$->type = $2;
2050//		$$->chan = Cboth;
2051	}
2052|	LCHAN '(' hidden_type_recv_chan ')'
2053	{
2054//		$$ = typ(TCHAN);
2055//		$$->type = $3;
2056//		$$->chan = Cboth;
2057	}
2058|	LCHAN LCOMM hidden_type
2059	{
2060//		$$ = typ(TCHAN);
2061//		$$->type = $3;
2062//		$$->chan = Csend;
2063	}
2064
2065hidden_type_recv_chan:
2066	LCOMM LCHAN hidden_type
2067	{
2068//		$$ = typ(TCHAN);
2069//		$$->type = $3;
2070//		$$->chan = Crecv;
2071	}
2072
2073hidden_type_func:
2074	LFUNC '(' ohidden_funarg_list ')' ohidden_funres
2075	{
2076//		$$ = functype(nil, $3, $5);
2077	}
2078
2079hidden_funarg:
2080	sym hidden_type oliteral
2081	{
2082//		$$ = nod(ODCLFIELD, N, typenod($2));
2083//		if($1)
2084//			$$->left = newname($1);
2085//		$$->val = $3;
2086	}
2087|	sym LDDD hidden_type oliteral
2088	{
2089//		Type *t;
2090//	
2091//		t = typ(TARRAY);
2092//		t->bound = -1;
2093//		t->type = $3;
2094//
2095//		$$ = nod(ODCLFIELD, N, typenod(t));
2096//		if($1)
2097//			$$->left = newname($1);
2098//		$$->isddd = 1;
2099//		$$->val = $4;
2100	}
2101
2102hidden_structdcl:
2103	sym hidden_type oliteral
2104	{
2105//		Sym *s;
2106//		Pkg *p;
2107//
2108//		if($1 != S && strcmp($1->name, "?") != 0) {
2109//			$$ = nod(ODCLFIELD, newname($1), typenod($2));
2110//			$$->val = $3;
2111//		} else {
2112//			s = $2->sym;
2113//			if(s == S && isptr[$2->etype])
2114//				s = $2->type->sym;
2115//			p = importpkg;
2116//			if($1 != S)
2117//				p = $1->pkg;
2118//			$$ = embedded(s, p);
2119//			$$->right = typenod($2);
2120//			$$->val = $3;
2121//		}
2122	}
2123
2124hidden_interfacedcl:
2125	sym '(' ohidden_funarg_list ')' ohidden_funres
2126	{
2127//		$$ = nod(ODCLFIELD, newname($1), typenod(functype(fakethis(), $3, $5)));
2128	}
2129|	hidden_type
2130	{
2131//		$$ = nod(ODCLFIELD, N, typenod($1));
2132	}
2133
2134ohidden_funres:
2135	{
2136//		$$ = nil;
2137	}
2138|	hidden_funres
2139
2140hidden_funres:
2141	'(' ohidden_funarg_list ')'
2142	{
2143//		$$ = $2;
2144	}
2145|	hidden_type
2146	{
2147//		$$ = list1(nod(ODCLFIELD, N, typenod($1)));
2148	}
2149
2150/*
2151 *  importing constants
2152 */
2153
2154hidden_literal:
2155	LLITERAL
2156	{
2157//		$$ = nodlit($1);
2158	}
2159|	'-' LLITERAL
2160	{
2161//		$$ = nodlit($2);
2162//		switch($$->val.ctype){
2163//		case CTINT:
2164//		case CTRUNE:
2165//			mpnegfix($$->val.u.xval);
2166//			break;
2167//		case CTFLT:
2168//			mpnegflt($$->val.u.fval);
2169//			break;
2170//		case CTCPLX:
2171//			mpnegflt(&$$->val.u.cval->real);
2172//			mpnegflt(&$$->val.u.cval->imag);
2173//			break;
2174//		default:
2175//			yyerror("bad negated constant");
2176//		}
2177	}
2178|	sym
2179	{
2180//		$$ = oldname(pkglookup($1->name, builtinpkg));
2181//		if($$->op != OLITERAL)
2182//			yyerror("bad constant %S", $$->sym);
2183	}
2184
2185hidden_constant:
2186	hidden_literal
2187|	'(' hidden_literal '+' hidden_literal ')'
2188	{
2189//		if($2->val.ctype == CTRUNE && $4->val.ctype == CTINT) {
2190//			$$ = $2;
2191//			mpaddfixfix($2->val.u.xval, $4->val.u.xval, 0);
2192//			break;
2193//		}
2194//		$4->val.u.cval->real = $4->val.u.cval->imag;
2195//		mpmovecflt(&$4->val.u.cval->imag, 0.0);
2196//		$$ = nodcplxlit($2->val, $4->val);
2197	}
2198
2199hidden_import_list:
2200|	hidden_import_list hidden_import
2201
2202hidden_funarg_list:
2203	hidden_funarg
2204	{
2205//		$$ = list1($1);
2206	}
2207|	hidden_funarg_list ',' hidden_funarg
2208	{
2209//		$$ = list($1, $3);
2210	}
2211
2212hidden_structdcl_list:
2213	hidden_structdcl
2214	{
2215//		$$ = list1($1);
2216	}
2217|	hidden_structdcl_list ';' hidden_structdcl
2218	{
2219//		$$ = list($1, $3);
2220	}
2221
2222hidden_interfacedcl_list:
2223	hidden_interfacedcl
2224	{
2225//		$$ = list1($1);
2226	}
2227|	hidden_interfacedcl_list ';' hidden_interfacedcl
2228	{
2229//		$$ = list($1, $3);
2230	}
2231
2232%%
2233
2234func fixlbrace(lbr int) {
2235	// If the opening brace was an LBODY,
2236	// set up for another one now that we're done.
2237	// See comment in lex.c about loophack.
2238//	if lbr == LBODY {
2239//		loophack = 1
2240//	}
2241}
2242