/
go.y
2312 lines (2096 loc) · 38.1 KB
/
go.y
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
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
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
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
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// 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.
/*
* Go language grammar.
*
* The Go semicolon rules are:
*
* 1. all statements and declarations are terminated by semicolons.
* 2. semicolons can be omitted before a closing ) or }.
* 3. semicolons are inserted by the lexer before a newline
* following a specific list of tokens.
*
* Rules #1 and #2 are accomplished by writing the lists as
* semicolon-separated lists with an optional trailing semicolon.
* Rule #3 is implemented in yylex.
*/
%{
package gc
import (
"fmt"
"strings"
)
%}
%union {
node *Node
list *NodeList
typ *Type
sym *Sym
val Val
i int
}
// |sed 's/.* //' |9 fmt -l1 |sort |9 fmt -l50 | sed 's/^/%xxx /'
%token <val> LLITERAL
%token <i> LASOP LCOLAS
%token <sym> LBREAK LCASE LCHAN LCONST LCONTINUE LDDD
%token <sym> LDEFAULT LDEFER LELSE LFALL LFOR LFUNC LGO LGOTO
%token <sym> LIF LIMPORT LINTERFACE LMAP LNAME
%token <sym> LPACKAGE LRANGE LRETURN LSELECT LSTRUCT LSWITCH
%token <sym> LTYPE LVAR
%token LANDAND LANDNOT LBODY LCOMM LDEC LEQ LGE LGT
%token LIGNORE LINC LLE LLSH LLT LNE LOROR LRSH
%type <i> lbrace import_here
%type <sym> sym packname
%type <val> oliteral
%type <node> stmt ntype
%type <node> arg_type
%type <node> case caseblock
%type <node> compound_stmt dotname embed expr complitexpr bare_complitexpr
%type <node> expr_or_type
%type <node> fndcl hidden_fndcl fnliteral
%type <node> for_body for_header for_stmt if_header if_stmt non_dcl_stmt
%type <node> interfacedcl keyval labelname name
%type <node> name_or_type non_expr_type
%type <node> new_name dcl_name oexpr typedclname
%type <node> onew_name
%type <node> osimple_stmt pexpr pexpr_no_paren
%type <node> pseudocall range_stmt select_stmt
%type <node> simple_stmt
%type <node> switch_stmt uexpr
%type <node> xfndcl typedcl start_complit
%type <list> xdcl fnbody fnres loop_body dcl_name_list
%type <list> new_name_list expr_list keyval_list braced_keyval_list expr_or_type_list xdcl_list
%type <list> oexpr_list caseblock_list elseif elseif_list else stmt_list oarg_type_list_ocomma arg_type_list
%type <list> interfacedcl_list vardcl vardcl_list structdcl structdcl_list
%type <list> common_dcl constdcl constdcl1 constdcl_list typedcl_list
%type <node> convtype comptype dotdotdot
%type <node> indcl interfacetype structtype ptrtype
%type <node> recvchantype non_recvchantype othertype fnret_type fntype
%type <sym> hidden_importsym hidden_pkg_importsym
%type <node> hidden_constant hidden_literal hidden_funarg
%type <node> hidden_interfacedcl hidden_structdcl
%type <list> hidden_funres
%type <list> ohidden_funres
%type <list> hidden_funarg_list ohidden_funarg_list
%type <list> hidden_interfacedcl_list ohidden_interfacedcl_list
%type <list> hidden_structdcl_list ohidden_structdcl_list
%type <typ> hidden_type hidden_type_misc hidden_pkgtype
%type <typ> hidden_type_func
%type <typ> hidden_type_recv_chan hidden_type_non_recv_chan
%left LCOMM /* outside the usual hierarchy; here for good error messages */
%left LOROR
%left LANDAND
%left LEQ LNE LLE LGE LLT LGT
%left '+' '-' '|' '^'
%left '*' '/' '%' '&' LLSH LRSH LANDNOT
/*
* manual override of shift/reduce conflicts.
* the general form is that we assign a precedence
* to the token being shifted and then introduce
* NotToken with lower precedence or PreferToToken with higher
* and annotate the reducing rule accordingly.
*/
%left NotPackage
%left LPACKAGE
%left NotParen
%left '('
%left ')'
%left PreferToRightParen
%error loadsys package LIMPORT '(' LLITERAL import_package import_there ',':
"unexpected comma during import block"
%error loadsys package LIMPORT LNAME ';':
"missing import path; require quoted string"
%error loadsys package imports LFUNC LNAME '(' ')' '{' LIF if_header ';':
"missing { after if clause"
%error loadsys package imports LFUNC LNAME '(' ')' '{' LSWITCH if_header ';':
"missing { after switch clause"
%error loadsys package imports LFUNC LNAME '(' ')' '{' LFOR for_header ';':
"missing { after for clause"
%error loadsys package imports LFUNC LNAME '(' ')' '{' LFOR ';' LBODY:
"missing { after for clause"
%error loadsys package imports LFUNC LNAME '(' ')' ';' '{':
"unexpected semicolon or newline before {"
%error loadsys package imports LTYPE LNAME ';':
"unexpected semicolon or newline in type declaration"
%error loadsys package imports LCHAN '}':
"unexpected } in channel type"
%error loadsys package imports LCHAN ')':
"unexpected ) in channel type"
%error loadsys package imports LCHAN ',':
"unexpected comma in channel type"
%error loadsys package imports LFUNC LNAME '(' ')' '{' if_stmt ';' LELSE:
"unexpected semicolon or newline before else"
%error loadsys package imports LTYPE LNAME LINTERFACE '{' LNAME ',' LNAME:
"name list not allowed in interface type"
%error loadsys package imports LFUNC LNAME '(' ')' '{' LFOR LVAR LNAME '=' LNAME:
"var declaration not allowed in for initializer"
%error loadsys package imports LVAR LNAME '[' ']' LNAME '{':
"unexpected { at end of statement"
%error loadsys package imports LFUNC LNAME '(' ')' '{' LVAR LNAME '[' ']' LNAME '{':
"unexpected { at end of statement"
%error loadsys package imports LFUNC LNAME '(' ')' '{' LDEFER LNAME ';':
"argument to go/defer must be function call"
%error loadsys package imports LVAR LNAME '=' LNAME '{' LNAME ';':
"need trailing comma before newline in composite literal"
%error loadsys package imports LVAR LNAME '=' comptype '{' LNAME ';':
"need trailing comma before newline in composite literal"
%error loadsys package imports LFUNC LNAME '(' ')' '{' LFUNC LNAME:
"nested func not allowed"
%error loadsys package imports LFUNC LNAME '(' ')' '{' LIF if_header loop_body LELSE ';':
"else must be followed by if or statement block"
%%
file:
loadsys
package
imports
xdcl_list
{
xtop = concat(xtop, $4);
}
package:
%prec NotPackage
{
prevlineno = lineno;
Yyerror("package statement must be first");
errorexit();
}
| LPACKAGE sym ';'
{
mkpackage($2.Name);
}
/*
* this loads the definitions for the low-level runtime functions,
* so that the compiler can generate calls to them,
* but does not make the name "runtime" visible as a package.
*/
loadsys:
{
importpkg = Runtimepkg;
if Debug['A'] != 0 {
cannedimports("runtime.Builtin", "package runtime\n\n$$\n\n");
} else {
cannedimports("runtime.Builtin", runtimeimport);
}
curio.importsafe = true
}
import_package
import_there
{
importpkg = nil;
}
imports:
| imports import ';'
import:
LIMPORT import_stmt
| LIMPORT '(' import_stmt_list osemi ')'
| LIMPORT '(' ')'
import_stmt:
import_here import_package import_there
{
ipkg := importpkg;
my := importmyname;
importpkg = nil;
importmyname = nil;
if my == nil {
my = Lookup(ipkg.Name);
}
pack := Nod(OPACK, nil, nil);
pack.Sym = my;
pack.Name.Pkg = ipkg;
pack.Lineno = int32($1);
if strings.HasPrefix(my.Name, ".") {
importdot(ipkg, pack);
break;
}
if my.Name == "init" {
Yyerror("cannot import package as init - init must be a func");
break;
}
if my.Name == "_" {
break;
}
if my.Def != nil {
lineno = int32($1);
redeclare(my, "as imported package name");
}
my.Def = pack;
my.Lastlineno = int32($1);
my.Block = 1; // at top level
}
| import_here import_there
{
// When an invalid import path is passed to importfile,
// it calls Yyerror and then sets up a fake import with
// no package statement. This allows us to test more
// than one invalid import statement in a single file.
if nerrors == 0 {
Fatal("phase error in import");
}
}
import_stmt_list:
import_stmt
| import_stmt_list ';' import_stmt
import_here:
LLITERAL
{
// import with original name
$$ = parserline();
importmyname = nil;
importfile(&$1, $$);
}
| sym LLITERAL
{
// import with given name
$$ = parserline();
importmyname = $1;
importfile(&$2, $$);
}
| '.' LLITERAL
{
// import into my name space
$$ = parserline();
importmyname = Lookup(".");
importfile(&$2, $$);
}
import_package:
LPACKAGE LNAME import_safety ';'
{
if importpkg.Name == "" {
importpkg.Name = $2.Name;
numImport[$2.Name]++
} else if importpkg.Name != $2.Name {
Yyerror("conflicting names %s and %s for package %q", importpkg.Name, $2.Name, importpkg.Path);
}
importpkg.Direct = 1;
importpkg.Safe = curio.importsafe
if safemode != 0 && !curio.importsafe {
Yyerror("cannot import unsafe package %q", importpkg.Path);
}
}
import_safety:
| LNAME
{
if $1.Name == "safe" {
curio.importsafe = true
}
}
import_there:
{
defercheckwidth();
}
hidden_import_list '$' '$'
{
resumecheckwidth();
unimportfile();
}
/*
* declarations
*/
xdcl:
{
Yyerror("empty top-level declaration");
$$ = nil;
}
| common_dcl
| xfndcl
{
$$ = list1($1);
}
| non_dcl_stmt
{
Yyerror("non-declaration statement outside function body");
$$ = nil;
}
| error
{
$$ = nil;
}
common_dcl:
LVAR vardcl
{
$$ = $2;
}
| LVAR '(' vardcl_list osemi ')'
{
$$ = $3;
}
| LVAR '(' ')'
{
$$ = nil;
}
| lconst constdcl
{
$$ = $2;
iota_ = -100000;
lastconst = nil;
}
| lconst '(' constdcl osemi ')'
{
$$ = $3;
iota_ = -100000;
lastconst = nil;
}
| lconst '(' constdcl ';' constdcl_list osemi ')'
{
$$ = concat($3, $5);
iota_ = -100000;
lastconst = nil;
}
| lconst '(' ')'
{
$$ = nil;
iota_ = -100000;
}
| LTYPE typedcl
{
$$ = list1($2);
}
| LTYPE '(' typedcl_list osemi ')'
{
$$ = $3;
}
| LTYPE '(' ')'
{
$$ = nil;
}
lconst:
LCONST
{
iota_ = 0;
}
vardcl:
dcl_name_list ntype
{
$$ = variter($1, $2, nil);
}
| dcl_name_list ntype '=' expr_list
{
$$ = variter($1, $2, $4);
}
| dcl_name_list '=' expr_list
{
$$ = variter($1, nil, $3);
}
constdcl:
dcl_name_list ntype '=' expr_list
{
$$ = constiter($1, $2, $4);
}
| dcl_name_list '=' expr_list
{
$$ = constiter($1, nil, $3);
}
constdcl1:
constdcl
| dcl_name_list ntype
{
$$ = constiter($1, $2, nil);
}
| dcl_name_list
{
$$ = constiter($1, nil, nil);
}
typedclname:
sym
{
// different from dclname because the name
// becomes visible right here, not at the end
// of the declaration.
$$ = typedcl0($1);
}
typedcl:
typedclname ntype
{
$$ = typedcl1($1, $2, true);
}
simple_stmt:
expr
{
$$ = $1;
// These nodes do not carry line numbers.
// Since a bare name used as an expression is an error,
// introduce a wrapper node to give the correct line.
switch($$.Op) {
case ONAME, ONONAME, OTYPE, OPACK, OLITERAL:
$$ = Nod(OPAREN, $$, nil);
$$.Implicit = true;
break;
}
}
| expr LASOP expr
{
$$ = Nod(OASOP, $1, $3);
$$.Etype = uint8($2); // rathole to pass opcode
}
| expr_list '=' expr_list
{
if $1.Next == nil && $3.Next == nil {
// simple
$$ = Nod(OAS, $1.N, $3.N);
break;
}
// multiple
$$ = Nod(OAS2, nil, nil);
$$.List = $1;
$$.Rlist = $3;
}
| expr_list LCOLAS expr_list
{
if $3.N.Op == OTYPESW {
$$ = Nod(OTYPESW, nil, $3.N.Right);
if $3.Next != nil {
Yyerror("expr.(type) must be alone in list");
}
if $1.Next != nil {
Yyerror("argument count mismatch: %d = %d", count($1), 1);
} else if ($1.N.Op != ONAME && $1.N.Op != OTYPE && $1.N.Op != ONONAME) || isblank($1.N) {
Yyerror("invalid variable name %s in type switch", $1.N);
} else {
$$.Left = dclname($1.N.Sym);
} // it's a colas, so must not re-use an oldname.
break;
}
$$ = colas($1, $3, int32($2));
}
| expr LINC
{
$$ = Nod(OASOP, $1, Nodintconst(1));
$$.Implicit = true;
$$.Etype = OADD;
}
| expr LDEC
{
$$ = Nod(OASOP, $1, Nodintconst(1));
$$.Implicit = true;
$$.Etype = OSUB;
}
case:
LCASE expr_or_type_list ':'
{
var n, nn *Node
// will be converted to OCASE
// right will point to next case
// done in casebody()
markdcl();
$$ = Nod(OXCASE, nil, nil);
$$.List = $2;
if typesw != nil && typesw.Right != nil {
n = typesw.Right.Left
if n != nil {
// type switch - declare variable
nn = newname(n.Sym);
declare(nn, dclcontext);
$$.Rlist = list1(nn);
// keep track of the instances for reporting unused
nn.Name.Defn = typesw.Right;
}
}
}
| LCASE expr_or_type_list '=' expr ':'
{
var n *Node
// will be converted to OCASE
// right will point to next case
// done in casebody()
markdcl();
$$ = Nod(OXCASE, nil, nil);
if $2.Next == nil {
n = Nod(OAS, $2.N, $4);
} else {
n = Nod(OAS2, nil, nil);
n.List = $2;
n.Rlist = list1($4);
}
$$.List = list1(n);
}
| LCASE expr_or_type_list LCOLAS expr ':'
{
// will be converted to OCASE
// right will point to next case
// done in casebody()
markdcl();
$$ = Nod(OXCASE, nil, nil);
$$.List = list1(colas($2, list1($4), int32($3)));
}
| LDEFAULT ':'
{
var n, nn *Node
markdcl();
$$ = Nod(OXCASE, nil, nil);
if typesw != nil && typesw.Right != nil {
n = typesw.Right.Left
if n != nil {
// type switch - declare variable
nn = newname(n.Sym);
declare(nn, dclcontext);
$$.Rlist = list1(nn);
// keep track of the instances for reporting unused
nn.Name.Defn = typesw.Right;
}
}
}
compound_stmt:
'{'
{
markdcl();
}
stmt_list '}'
{
if $3 == nil {
$$ = Nod(OEMPTY, nil, nil);
} else {
$$ = liststmt($3);
}
popdcl();
}
caseblock:
case
{
// If the last token read by the lexer was consumed
// as part of the case, clear it (parser has cleared yychar).
// If the last token read by the lexer was the lookahead
// leave it alone (parser has it cached in yychar).
// This is so that the stmt_list action doesn't look at
// the case tokens if the stmt_list is empty.
yylast = yychar;
$1.Xoffset = int64(block);
}
stmt_list
{
// This is the only place in the language where a statement
// list is not allowed to drop the final semicolon, because
// it's the only place where a statement list is not followed
// by a closing brace. Handle the error for pedantry.
// Find the final token of the statement list.
// yylast is lookahead; yyprev is last of stmt_list
last := yyprev;
if last > 0 && last != ';' && yychar != '}' {
Yyerror("missing statement after label");
}
$$ = $1;
$$.Nbody = $3;
popdcl();
}
caseblock_list:
{
$$ = nil;
}
| caseblock_list caseblock
{
$$ = list($1, $2);
}
loop_body:
LBODY
{
markdcl();
}
stmt_list '}'
{
$$ = $3;
popdcl();
}
range_stmt:
expr_list '=' LRANGE expr
{
$$ = Nod(ORANGE, nil, $4);
$$.List = $1;
$$.Etype = 0; // := flag
}
| expr_list LCOLAS LRANGE expr
{
$$ = Nod(ORANGE, nil, $4);
$$.List = $1;
$$.Colas = true;
colasdefn($1, $$);
}
| LRANGE expr
{
$$ = Nod(ORANGE, nil, $2);
$$.Etype = 0; // := flag
}
for_header:
osimple_stmt ';' osimple_stmt ';' osimple_stmt
{
// init ; test ; incr
if $5 != nil && $5.Colas {
Yyerror("cannot declare in the for-increment");
}
$$ = Nod(OFOR, nil, nil);
if $1 != nil {
$$.Ninit = list1($1);
}
$$.Left = $3;
$$.Right = $5;
}
| osimple_stmt
{
// normal test
$$ = Nod(OFOR, nil, nil);
$$.Left = $1;
}
| range_stmt
for_body:
for_header loop_body
{
$$ = $1;
$$.Nbody = concat($$.Nbody, $2);
}
for_stmt:
LFOR
{
markdcl();
}
for_body
{
$$ = $3;
popdcl();
}
if_header:
osimple_stmt
{
// test
$$ = Nod(OIF, nil, nil);
$$.Left = $1;
}
| osimple_stmt ';' osimple_stmt
{
// init ; test
$$ = Nod(OIF, nil, nil);
if $1 != nil {
$$.Ninit = list1($1);
}
$$.Left = $3;
}
/* IF cond body (ELSE IF cond body)* (ELSE block)? */
if_stmt:
LIF
{
markdcl();
}
if_header
{
if $3.Left == nil {
Yyerror("missing condition in if statement");
}
}
loop_body
{
$3.Nbody = $5;
}
elseif_list else
{
var n *Node
var nn *NodeList
$$ = $3;
n = $3;
popdcl();
for nn = concat($7, $8); nn != nil; nn = nn.Next {
if nn.N.Op == OIF {
popdcl();
}
n.Rlist = list1(nn.N);
n = nn.N;
}
}
elseif:
LELSE LIF
{
markdcl();
}
if_header loop_body
{
if $4.Left == nil {
Yyerror("missing condition in if statement");
}
$4.Nbody = $5;
$$ = list1($4);
}
elseif_list:
{
$$ = nil;
}
| elseif_list elseif
{
$$ = concat($1, $2);
}
else:
{
$$ = nil;
}
| LELSE compound_stmt
{
l := &NodeList{N: $2}
l.End = l
$$ = l;
}
switch_stmt:
LSWITCH
{
markdcl();
}
if_header
{
var n *Node
n = $3.Left;
if n != nil && n.Op != OTYPESW {
n = nil;
}
typesw = Nod(OXXX, typesw, n);
}
LBODY caseblock_list '}'
{
$$ = $3;
$$.Op = OSWITCH;
$$.List = $6;
typesw = typesw.Left;
popdcl();
}
select_stmt:
LSELECT
{
typesw = Nod(OXXX, typesw, nil);
}
LBODY caseblock_list '}'
{
$$ = Nod(OSELECT, nil, nil);
$$.Lineno = typesw.Lineno;
$$.List = $4;
typesw = typesw.Left;
}
/*
* 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);
}
| expr LANDNOT expr
{
$$ = Nod(OANDNOT, $1, $3);
}
| expr LLSH expr
{
$$ = Nod(OLSH, $1, $3);
}
| expr LRSH expr
{
$$ = Nod(ORSH, $1, $3);
}
/* not an expression anymore, but left in so we can give a good error */
| expr LCOMM expr
{
$$ = Nod(OSEND, $1, $3);
}
uexpr:
pexpr
| '*' uexpr
{
$$ = Nod(OIND, $2, nil);
}
| '&' uexpr
{
if $2.Op == OCOMPLIT {
// Special case for &T{...}: turn into (*T){...}.
$$ = $2;
$$.Right = Nod(OIND, $$.Right, nil);
$$.Right.Implicit = true;
} else {
$$ = Nod(OADDR, $2, nil);
}
}
| '+' uexpr
{
$$ = Nod(OPLUS, $2, nil);
}
| '-' uexpr
{
$$ = Nod(OMINUS, $2, nil);
}
| '!' uexpr
{
$$ = Nod(ONOT, $2, nil);
}
| '~' uexpr
{
Yyerror("the bitwise complement operator is ^");
$$ = Nod(OCOM, $2, nil);
}
| '^' uexpr
{
$$ = Nod(OCOM, $2, nil);
}
| LCOMM uexpr
{
$$ = Nod(ORECV, $2, nil);
}
/*
* call-like statements that
* can be preceded by 'defer' and 'go'
*/
pseudocall:
pexpr '(' ')'
{
$$ = Nod(OCALL, $1, nil);
}
| pexpr '(' expr_or_type_list ocomma ')'
{
$$ = Nod(OCALL, $1, nil);
$$.List = $3;
}
| pexpr '(' expr_or_type_list LDDD ocomma ')'
{
$$ = Nod(OCALL, $1, nil);
$$.List = $3;
$$.Isddd = true;