summaryrefslogtreecommitdiff
path: root/perly.y
blob: c0c09092c5e9305af5638535effebf18ea62cfe3 (plain)
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
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
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
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
/*    perly.y
 *
 *    Copyright (c) 1991-2002, 2003, 2004, 2005, 2006 Larry Wall
 *    Copyright (c) 2007, 2008, 2009, 2010, 2011 by Larry Wall and others
 *
 *    You may distribute under the terms of either the GNU General Public
 *    License or the Artistic License, as specified in the README file.
 *
 */

/*
 * 'I see,' laughed Strider.  'I look foul and feel fair.  Is that it?
 *  All that is gold does not glitter, not all those who wander are lost.'
 *
 *     [p.171 of _The Lord of the Rings_, I/x: "Strider"]
 */

/*
 * This file holds the grammar for the Perl language. If edited, you need
 * to run regen_perly.pl, which re-creates the files perly.h, perly.tab
 * and perly.act which are derived from this.
 *
 * The main job of this grammar is to call the various newFOO()
 * functions in op.c to build a syntax tree of OP structs.
 * It relies on the lexer in toke.c to do the tokenizing.
 *
 * Note: due to the way that the cleanup code works WRT to freeing ops on
 * the parse stack, it is dangerous to assign to the $n variables within
 * an action.
 */

/*  Make the parser re-entrant. */

%define api.pure

%start grammar

%union {
    I32	ival; /* __DEFAULT__ (marker for regen_perly.pl;
				must always be 1st union member) */
    void *pval;
    OP *opval;
    GV *gvval;
}

%token <ival> GRAMPROG GRAMEXPR GRAMBLOCK GRAMBARESTMT GRAMFULLSTMT GRAMSTMTSEQ GRAMSUBSIGNATURE

/* Tokens emitted by toke.c for simple punctiation characters - &, {, }, etc... */
%token <ival> PERLY_AMPERSAND
%token <ival> PERLY_BRACE_OPEN
%token <ival> PERLY_BRACE_CLOSE
%token <ival> PERLY_BRACKET_OPEN
%token <ival> PERLY_BRACKET_CLOSE
%token <ival> PERLY_COMMA
%token <ival> PERLY_DOLLAR
%token <ival> PERLY_DOT
%token <ival> PERLY_EQUAL_SIGN
%token <ival> PERLY_MINUS
%token <ival> PERLY_PERCENT_SIGN
%token <ival> PERLY_PLUS
%token <ival> PERLY_SEMICOLON
%token <ival> PERLY_SLASH
%token <ival> PERLY_SNAIL
%token <ival> PERLY_STAR

/* Tokens emitted by toke.c on simple keywords */
%token <ival> KW_FORMAT KW_PACKAGE KW_CLASS
%token <ival> KW_LOCAL KW_MY KW_FIELD
%token <ival> KW_IF KW_ELSE KW_ELSIF KW_UNLESS
%token <ival> KW_FOR KW_UNTIL KW_WHILE KW_CONTINUE
%token <ival> KW_GIVEN KW_WHEN KW_DEFAULT
%token <ival> KW_TRY KW_CATCH KW_FINALLY KW_DEFER
%token <ival> KW_REQUIRE KW_DO

/* The 'use' and 'no' keywords both emit this */
%token <ival> KW_USE_or_NO

/* The 'sub' keyword is a bit special; four different tokens depending on
 *   named-vs-anon, and whether signatures are in effect */
%token <ival> KW_SUB_named KW_SUB_named_sig KW_SUB_anon KW_SUB_anon_sig
%token <ival> KW_METHOD_named KW_METHOD_anon

/* Tokens emitted in other situations */
%token <opval> BAREWORD METHCALL0 METHCALL THING PMFUNC PRIVATEREF QWLIST
%token <opval> FUNC0OP FUNC0SUB UNIOPSUB LSTOPSUB
%token <opval> PLUGEXPR PLUGSTMT
%token <opval> LABEL
%token <ival> LOOPEX DOTDOT YADAYADA
%token <ival> FUNC0 FUNC1 FUNC UNIOP LSTOP
%token <ival> POWOP MULOP ADDOP
%token <ival> DOLSHARP HASHBRACK NOAMP
%token <ival> COLONATTR FORMLBRACK FORMRBRACK
%token <ival> SUBLEXSTART SUBLEXEND
%token <ival> PHASER

%type <ival> grammar remember mremember
%type <ival>  startsub startanonsub startanonmethod startformsub

%type <ival> mintro

%type <ival>  sigsub_or_method_named
%type <opval> stmtseq fullstmt labfullstmt barestmt block mblock else finally
%type <opval> expr term subscripted scalar ary hsh arylen star amper sideff
%type <opval> condition
%type <opval> catch_paren
%type <opval> empty
%type <opval> sliceme kvslice gelem
%type <opval> listexpr nexpr texpr iexpr mexpr mnexpr
%type <opval> optlistexpr optexpr optrepl indirob listop methodname
%type <opval> formname subname proto cont my_scalar my_var
%type <opval> list_of_scalars my_list_of_scalars refgen_topic formblock
%type <opval> subattrlist myattrlist myattrterm myterm
%type <pval>  fieldvar /* pval is PADNAME */
%type <opval> optfieldattrlist fielddecl
%type <opval> termbinop termunop anonymous termdo
%type <opval> termrelop relopchain termeqop eqopchain
%type <ival>  sigslurpsigil
%type <opval> sigvarname sigdefault sigscalarelem sigslurpelem
%type <opval> sigelem siglist optsiglist subsigguts subsignature optsubsignature
%type <opval> subbody optsubbody sigsubbody optsigsubbody
%type <opval> formstmtseq formline formarg

%nonassoc <ival> PREC_LOW
%nonassoc LOOPEX

%nonassoc <pval> PLUGIN_LOW_OP
%left <ival> OROP <pval> PLUGIN_LOGICAL_OR_LOW_OP
%left <ival> ANDOP <pval> PLUGIN_LOGICAL_AND_LOW_OP
%right <ival> NOTOP
%nonassoc LSTOP LSTOPSUB
%left PERLY_COMMA
%right <ival> ASSIGNOP <pval> PLUGIN_ASSIGN_OP
%right <ival> PERLY_QUESTION_MARK PERLY_COLON
%nonassoc DOTDOT
%left <ival> OROR DORDOR <pval> PLUGIN_LOGICAL_OR_OP
%left <ival> ANDAND <pval> PLUGIN_LOGICAL_AND_OP
%left <ival> BITOROP
%left <ival> BITANDOP
%left <ival> CHEQOP NCEQOP
%left <ival> CHRELOP NCRELOP
%nonassoc <pval> PLUGIN_REL_OP
%nonassoc UNIOP UNIOPSUB
%nonassoc KW_REQUIRE
%left <ival> SHIFTOP
%left ADDOP <pval> PLUGIN_ADD_OP
%left MULOP <pval> PLUGIN_MUL_OP
%left <ival> MATCHOP
%right <ival> PERLY_EXCLAMATION_MARK PERLY_TILDE UMINUS REFGEN
%right POWOP <pval> PLUGIN_POW_OP
%nonassoc <ival> PREINC PREDEC POSTINC POSTDEC POSTJOIN
%nonassoc <pval> PLUGIN_HIGH_OP
%left <ival> ARROW
%nonassoc <ival> PERLY_PAREN_CLOSE
%left <ival> PERLY_PAREN_OPEN
%left PERLY_BRACKET_OPEN PERLY_BRACE_OPEN

%% /* RULES */

/* Top-level choice of what kind of thing yyparse was called to parse */
grammar	:	GRAMPROG
			{
			  parser->expect = XSTATE;
                          $<ival>$ = 0;
			}
		remember stmtseq
			{
			  newPROG(block_end($remember,$stmtseq));
			  PL_compiling.cop_seq = 0;
			  $$ = 0;
			}
	|	GRAMEXPR
			{
			  parser->expect = XTERM;
                          $<ival>$ = 0;
			}
		optexpr
			{
			  PL_eval_root = $optexpr;
			  $$ = 0;
			}
	|	GRAMBLOCK
			{
			  parser->expect = XBLOCK;
                          $<ival>$ = 0;
			}
		block
			{
			  PL_pad_reset_pending = TRUE;
			  PL_eval_root = $block;
			  $$ = 0;
			  yyunlex();
			  parser->yychar = yytoken = YYEOF;
			}
	|	GRAMBARESTMT
			{
			  parser->expect = XSTATE;
                          $<ival>$ = 0;
			}
		barestmt
			{
			  PL_pad_reset_pending = TRUE;
			  PL_eval_root = $barestmt;
			  $$ = 0;
			  yyunlex();
			  parser->yychar = yytoken = YYEOF;
			}
	|	GRAMFULLSTMT
			{
			  parser->expect = XSTATE;
                          $<ival>$ = 0;
			}
		fullstmt
			{
			  PL_pad_reset_pending = TRUE;
			  PL_eval_root = $fullstmt;
			  $$ = 0;
			  yyunlex();
			  parser->yychar = yytoken = YYEOF;
			}
	|	GRAMSTMTSEQ
			{
			  parser->expect = XSTATE;
                          $<ival>$ = 0;
			}
		stmtseq
			{
			  PL_eval_root = $stmtseq;
			  $$ = 0;
			}
	|	GRAMSUBSIGNATURE
			{
			  parser->expect = XSTATE;
			  $<ival>$ = 0;
			}
		subsigguts
			{
			  PL_eval_root = $subsigguts;
			  $$ = 0;
			}
	;

/* Either a signatured 'sub' or 'method' keyword */
sigsub_or_method_named
	:	KW_SUB_named_sig
			{ $$ = KW_SUB_named_sig; }
	|	KW_METHOD_named
			{ $$ = KW_METHOD_named; }
	;

/* An ordinary block */
block	:	PERLY_BRACE_OPEN remember stmtseq PERLY_BRACE_CLOSE
			{ if (parser->copline > (line_t)$PERLY_BRACE_OPEN)
			      parser->copline = (line_t)$PERLY_BRACE_OPEN;
			  $$ = block_end($remember, $stmtseq);
			}
	;

empty
	:	%empty          { $$ = NULL; }
	;

/* format body */
formblock:	PERLY_EQUAL_SIGN remember PERLY_SEMICOLON FORMRBRACK formstmtseq PERLY_SEMICOLON PERLY_DOT
			{ if (parser->copline > (line_t)$PERLY_EQUAL_SIGN)
			      parser->copline = (line_t)$PERLY_EQUAL_SIGN;
			  $$ = block_end($remember, $formstmtseq);
			}
	;

remember:	%empty	/* start a full lexical scope */
			{ $$ = block_start(TRUE);
			  parser->parsed_sub = 0; }
	;

mblock	:	PERLY_BRACE_OPEN mremember stmtseq PERLY_BRACE_CLOSE
			{ if (parser->copline > (line_t)$PERLY_BRACE_OPEN)
			      parser->copline = (line_t)$PERLY_BRACE_OPEN;
			  $$ = block_end($mremember, $stmtseq);
			}
	;

mremember:	%empty	/* start a partial lexical scope */
			{ $$ = block_start(FALSE);
			  parser->parsed_sub = 0; }
	;

/* The parenthesized variable of a catch block */
catch_paren:	empty
			/* not really valid grammar but we detect it in the
			 * action block to throw a nicer error message */
	|	PERLY_PAREN_OPEN
			{ parser->in_my = 1; }
		scalar
			{ parser->in_my = 0; intro_my(); }
		PERLY_PAREN_CLOSE
			{ $$ = $scalar; }
	;

/* A sequence of statements in the program */
stmtseq
	:	empty
	|	stmtseq[list] fullstmt
			{   $$ = op_append_list(OP_LINESEQ, $list, $fullstmt);
			    PL_pad_reset_pending = TRUE;
			    if ($list && $fullstmt)
				PL_hints |= HINT_BLOCK_SCOPE;
			}
	;

/* A sequence of format lines */
formstmtseq
	:	empty
	|	formstmtseq[list] formline
			{   $$ = op_append_list(OP_LINESEQ, $list, $formline);
			    PL_pad_reset_pending = TRUE;
			    if ($list && $formline)
				PL_hints |= HINT_BLOCK_SCOPE;
			}
	;

/* A statement in the program, including optional labels */
fullstmt:	barestmt
			{
			  $$ = $barestmt ? newSTATEOP(0, NULL, $barestmt) : NULL;
			}
	|	labfullstmt
			{ $$ = $labfullstmt; }
	;

labfullstmt:	LABEL barestmt
			{
                          SV *label = cSVOPx_sv($LABEL);
			  $$ = newSTATEOP(SvFLAGS(label) & SVf_UTF8,
                                            savepv(SvPVX_const(label)), $barestmt);
                          op_free($LABEL);
			}
	|	LABEL labfullstmt[list]
			{
                          SV *label = cSVOPx_sv($LABEL);
			  $$ = newSTATEOP(SvFLAGS(label) & SVf_UTF8,
                                            savepv(SvPVX_const(label)), $list);
                          op_free($LABEL);
			}
	;

/* A bare statement, lacking label and other aspects of state op */
barestmt:	PLUGSTMT
			{ $$ = $PLUGSTMT; }
	|	KW_FORMAT startformsub formname formblock
			{
			  CV *fmtcv = PL_compcv;
			  newFORM($startformsub, $formname, $formblock);
			  $$ = NULL;
			  if (CvOUTSIDE(fmtcv) && !CvEVAL(CvOUTSIDE(fmtcv))) {
			      pad_add_weakref(fmtcv);
			  }
			  parser->parsed_sub = 1;
			}
	|	KW_SUB_named subname startsub
                    /* sub declaration or definition not within scope
                       of 'use feature "signatures"'*/
			{
                          init_named_cv(PL_compcv, $subname);
			  parser->in_my = 0;
			  parser->in_my_stash = NULL;
			}
                    proto subattrlist optsubbody
			{
			  SvREFCNT_inc_simple_void(PL_compcv);
			  $subname->op_type == OP_CONST
			      ? newATTRSUB($startsub, $subname, $proto, $subattrlist, $optsubbody)
			      : newMYSUB($startsub, $subname, $proto, $subattrlist, $optsubbody)
			  ;
			  $$ = NULL;
			  intro_my();
			  parser->parsed_sub = 1;
			}
	|	sigsub_or_method_named subname startsub
                    /* sub declaration or definition under 'use feature
                     * "signatures"'. (Note that a signature isn't
                     * allowed in a declaration)
                     */
			{
                          init_named_cv(PL_compcv, $subname);
			  if($sigsub_or_method_named == KW_METHOD_named) {
			      croak_kw_unless_class("method");
			      class_prepare_method_parse(PL_compcv);
			  }
			  parser->in_my = 0;
			  parser->in_my_stash = NULL;
			}
                    subattrlist optsigsubbody
			{
			  OP *body = $optsigsubbody;

			  SvREFCNT_inc_simple_void(PL_compcv);
			  $subname->op_type == OP_CONST
			      ? newATTRSUB($startsub, $subname, NULL, $subattrlist, body)
			      : newMYSUB(  $startsub, $subname, NULL, $subattrlist, body)
			  ;
			  $$ = NULL;
			  intro_my();
			  parser->parsed_sub = 1;
			}
	|	PHASER startsub
			{
			  switch($PHASER) {
			      case KEY_ADJUST:
			         croak_kw_unless_class("ADJUST");
			         class_prepare_method_parse(PL_compcv);
			         break;
			      default:
			         NOT_REACHED;
			  }
			}
		    optsubbody
			{
			  OP *body = $optsubbody;
			  SvREFCNT_inc_simple_void(PL_compcv);

			  CV *cv;

			  switch($PHASER) {
			      case KEY_ADJUST:
			          cv = newATTRSUB($startsub, NULL, NULL, NULL, body);
			          class_add_ADJUST(PL_curstash, cv);
			          break;
			  }
			  $$ = NULL;
			}
	|	KW_PACKAGE BAREWORD[version] BAREWORD[package] PERLY_SEMICOLON
		    /* version and package appear in the reverse order to what may be
		     * expected, because toke.c has already pushed both of them to a stack
		     * by calling force_next() from within force_version().
		     * When the parser pops them back out again they appear swapped */
			{
			  package($package);
			  if ($version)
			      package_version($version);
			  $$ = NULL;
			}
	|	KW_CLASS BAREWORD[version] BAREWORD[package] subattrlist PERLY_SEMICOLON
			{
			  package($package);
			  if ($version)
			      package_version($version);
			  $$ = NULL;
			  class_setup_stash(PL_curstash);
			  if ($subattrlist) {
			      class_apply_attributes(PL_curstash, $subattrlist);
			  }
			}
	|	KW_USE_or_NO startsub
			{ CvSPECIAL_on(PL_compcv); /* It's a BEGIN {} */ }
		BAREWORD[version] BAREWORD[module] optlistexpr PERLY_SEMICOLON
		    /* version and package appear in reverse order for the same reason as
		     * KW_PACKAGE; see comment above */
			{
			  SvREFCNT_inc_simple_void(PL_compcv);
			  utilize($KW_USE_or_NO, $startsub, $version, $module, $optlistexpr);
			  parser->parsed_sub = 1;
			  $$ = NULL;
			}
	|	KW_IF PERLY_PAREN_OPEN remember mexpr PERLY_PAREN_CLOSE mblock else
			{
			  $$ = block_end($remember,
			      newCONDOP(0, $mexpr, op_scope($mblock), $else));
			  parser->copline = (line_t)$KW_IF;
			}
	|	KW_UNLESS PERLY_PAREN_OPEN remember mexpr PERLY_PAREN_CLOSE mblock else
			{
			  $$ = block_end($remember,
                              newCONDOP(0, $mexpr, $else, op_scope($mblock)));
			  parser->copline = (line_t)$KW_UNLESS;
			}
	|	KW_GIVEN PERLY_PAREN_OPEN remember mexpr PERLY_PAREN_CLOSE mblock
			{
			  $$ = block_end($remember, newGIVENOP($mexpr, op_scope($mblock), 0));
			  parser->copline = (line_t)$KW_GIVEN;
			}
	|	KW_WHEN PERLY_PAREN_OPEN remember mexpr PERLY_PAREN_CLOSE mblock
			{ $$ = block_end($remember, newWHENOP($mexpr, op_scope($mblock))); }
	|	KW_DEFAULT block
			{ $$ = newWHENOP(0, op_scope($block)); }
	|	KW_WHILE PERLY_PAREN_OPEN remember texpr PERLY_PAREN_CLOSE mintro mblock cont
			{
			  $$ = block_end($remember,
				  newWHILEOP(0, 1, NULL,
				      $texpr, $mblock, $cont, $mintro));
			  parser->copline = (line_t)$KW_WHILE;
			}
	|	KW_UNTIL PERLY_PAREN_OPEN remember iexpr PERLY_PAREN_CLOSE mintro mblock cont
			{
			  $$ = block_end($remember,
				  newWHILEOP(0, 1, NULL,
				      $iexpr, $mblock, $cont, $mintro));
			  parser->copline = (line_t)$KW_UNTIL;
			}
	|	KW_FOR PERLY_PAREN_OPEN remember mnexpr[init_mnexpr] PERLY_SEMICOLON
			{ parser->expect = XTERM; }
		texpr PERLY_SEMICOLON
			{ parser->expect = XTERM; }
		mintro mnexpr[iterate_mnexpr] PERLY_PAREN_CLOSE
		mblock
			{
			  OP *initop = $init_mnexpr;
			  OP *forop = newWHILEOP(0, 1, NULL,
				      scalar($texpr), $mblock, $iterate_mnexpr, $mintro);
			  if (initop) {
			      forop = op_prepend_elem(OP_LINESEQ, initop,
				  op_append_elem(OP_LINESEQ,
				      newOP(OP_UNSTACK, OPf_SPECIAL),
				      forop));
			  }
			  PL_hints |= HINT_BLOCK_SCOPE;
			  $$ = block_end($remember, forop);
			  parser->copline = (line_t)$KW_FOR;
			}
	|	KW_FOR KW_MY remember my_scalar PERLY_PAREN_OPEN mexpr PERLY_PAREN_CLOSE mblock cont
			{
			  $$ = block_end($remember, newFOROP(0, $my_scalar, $mexpr, $mblock, $cont));
			  parser->copline = (line_t)$KW_FOR;
			}
	|	KW_FOR KW_MY remember PERLY_PAREN_OPEN my_list_of_scalars PERLY_PAREN_CLOSE PERLY_PAREN_OPEN mexpr PERLY_PAREN_CLOSE mblock cont
			{
                          if ($my_list_of_scalars->op_type == OP_PADSV)
                            /* degenerate case of 1 var: for my ($x) ....
                               Flag it so it can be special-cased in newFOROP */
                                $my_list_of_scalars->op_flags |= OPf_PARENS;
			  $$ = block_end($remember, newFOROP(0, $my_list_of_scalars, $mexpr, $mblock, $cont));
			  parser->copline = (line_t)$KW_FOR;
			}
	|	KW_FOR scalar PERLY_PAREN_OPEN remember mexpr PERLY_PAREN_CLOSE mblock cont
			{
			  $$ = block_end($remember, newFOROP(0,
				      op_lvalue($scalar, OP_ENTERLOOP), $mexpr, $mblock, $cont));
			  parser->copline = (line_t)$KW_FOR;
			}
	|	KW_FOR my_refgen remember my_var
			{ parser->in_my = 0; $<opval>$ = my($my_var); }[variable]
		PERLY_PAREN_OPEN mexpr PERLY_PAREN_CLOSE mblock cont
			{
			  $$ = block_end(
				$remember,
				newFOROP(0,
					 op_lvalue(
					    newUNOP(OP_REFGEN, 0,
						    $<opval>variable),
					    OP_ENTERLOOP),
					 $mexpr, $mblock, $cont)
			  );
			  parser->copline = (line_t)$KW_FOR;
			}
	|	KW_FOR REFGEN refgen_topic PERLY_PAREN_OPEN remember mexpr PERLY_PAREN_CLOSE mblock cont
			{
			  $$ = block_end($remember, newFOROP(
				0, op_lvalue(newUNOP(OP_REFGEN, 0,
						     $refgen_topic),
					     OP_ENTERLOOP), $mexpr, $mblock, $cont));
			  parser->copline = (line_t)$KW_FOR;
			}
	|	KW_FOR PERLY_PAREN_OPEN remember mexpr PERLY_PAREN_CLOSE mblock cont
			{
			  $$ = block_end($remember,
				  newFOROP(0, NULL, $mexpr, $mblock, $cont));
			  parser->copline = (line_t)$KW_FOR;
			}
	|       KW_TRY mblock[try] KW_CATCH remember catch_paren[scalar]
			{
			  if(!$scalar) {
			      yyerror("catch block requires a (VAR)");
			      YYERROR;
			  }
			}
		mblock[catch] finally
			{
			  $$ = newTRYCATCHOP(0,
				  $try, $scalar, block_end($remember, op_scope($catch)));
			  if($finally)
			      $$ = op_wrap_finally($$, $finally);
			  parser->copline = (line_t)$KW_TRY;
			}
	|	block cont
			{
			  /* a block is a loop that happens once */
			  $$ = newWHILEOP(0, 1, NULL,
				  NULL, $block, $cont, 0);
			}
	|	KW_PACKAGE BAREWORD[version] BAREWORD[package] PERLY_BRACE_OPEN remember
			{
			  package($package);
			  if ($version) {
			      package_version($version);
			  }
			}
		stmtseq PERLY_BRACE_CLOSE
			{
			  /* a block is a loop that happens once */
			  $$ = newWHILEOP(0, 1, NULL,
				  NULL, block_end($remember, $stmtseq), NULL, 0);
			  if (parser->copline > (line_t)$PERLY_BRACE_OPEN)
			      parser->copline = (line_t)$PERLY_BRACE_OPEN;
			}
	|	KW_CLASS BAREWORD[version] BAREWORD[package] subattrlist PERLY_BRACE_OPEN remember
			{
			  package($package);

			  if ($version) {
			      package_version($version);
			  }
			  class_setup_stash(PL_curstash);
			  if ($subattrlist) {
			      class_apply_attributes(PL_curstash, $subattrlist);
			  }
			}
		stmtseq PERLY_BRACE_CLOSE
			{
			  /* a block is a loop that happens once */
			  $$ = newWHILEOP(0, 1, NULL,
				  NULL, block_end($remember, $stmtseq), NULL, 0);
			  if (parser->copline > (line_t)$PERLY_BRACE_OPEN)
			      parser->copline = (line_t)$PERLY_BRACE_OPEN;
			}
	|	fielddecl PERLY_SEMICOLON
			{
			  $$ = $fielddecl;
			}
	|	sideff PERLY_SEMICOLON
			{
			  $$ = $sideff;
			}
	|	KW_DEFER mblock
			{
			  $$ = newDEFEROP(0, op_scope($2));
			}
	|	YADAYADA PERLY_SEMICOLON
			{
                          /* diag_listed_as: Unimplemented */
			  $$ = newLISTOP(OP_DIE, 0, newOP(OP_PUSHMARK, 0),
				newSVOP(OP_CONST, 0, newSVpvs("Unimplemented")));
			}
	|	PERLY_SEMICOLON
			{
			  $$ = NULL;
			  parser->copline = NOLINE;
			}
	;

/* Format line */
formline:	THING formarg
			{ OP *list;
			  if ($formarg) {
			      OP *term = $formarg;
			      list = op_append_elem(OP_LIST, $THING, term);
			  }
			  else {
			      list = $THING;
			  }
			  if (parser->copline == NOLINE)
			       parser->copline = CopLINE(PL_curcop)-1;
			  else parser->copline--;
			  $$ = newSTATEOP(0, NULL,
					  op_convert_list(OP_FORMLINE, 0, list));
			}
	;

formarg
	:	empty
	|	FORMLBRACK stmtseq FORMRBRACK
			{ $$ = op_unscope($stmtseq); }
	;

condition: expr
;

/* An expression which may have a side-effect */
sideff	:	error
			{ $$ = NULL; }
	|	expr[body]
			{ $$ = $body; }
	|	expr[body] KW_IF condition
			{ $$ = newLOGOP(OP_AND, 0, $condition, $body); }
	|	expr[body] KW_UNLESS condition
			{ $$ = newLOGOP(OP_OR, 0, $condition, $body); }
	|	expr[body] KW_WHILE condition
			{ $$ = newLOOPOP(OPf_PARENS, 1, scalar($condition), $body); }
	|	expr[body] KW_UNTIL iexpr
			{ $$ = newLOOPOP(OPf_PARENS, 1, $iexpr, $body); }
	|	expr[body] KW_FOR condition
			{ $$ = newFOROP(0, NULL, $condition, $body, NULL);
			  parser->copline = (line_t)$KW_FOR; }
	|	expr[body] KW_WHEN condition
			{ $$ = newWHENOP($condition, op_scope($body)); }
	;

/* else and elsif blocks */
else
	:	empty
	|	KW_ELSE mblock
			{
			  ($mblock)->op_flags |= OPf_PARENS;
			  $$ = op_scope($mblock);
			}
	|	KW_ELSIF PERLY_PAREN_OPEN mexpr PERLY_PAREN_CLOSE mblock else[else.recurse]
			{ parser->copline = (line_t)$KW_ELSIF;
			    $$ = newCONDOP(0,
				newSTATEOP(OPf_SPECIAL,NULL,$mexpr),
				op_scope($mblock), $[else.recurse]);
			  PL_hints |= HINT_BLOCK_SCOPE;
			}
	;

/* Continue blocks */
cont
	:	empty
	|	KW_CONTINUE block
			{ $$ = op_scope($block); }
	;

/* Finally blocks */
finally	:	%empty
			{ $$ = NULL; }
	|	KW_FINALLY block
			{ $$ = op_scope($block); }
	;

/* determine whether there are any new my declarations */
mintro	:	%empty
			{ $$ = (PL_min_intro_pending &&
			    PL_max_intro_pending >=  PL_min_intro_pending);
			  intro_my(); }

/* Normal expression */
nexpr
	:	empty
	|	sideff
	;

/* Boolean expression */
texpr	:	%empty /* NULL means true */
			{ YYSTYPE tmplval;
			  (void)scan_num("1", &tmplval);
			  $$ = tmplval.opval; }
	|	expr
	;

/* Inverted boolean expression */
iexpr	:	expr
			{ $$ = invert(scalar($expr)); }
	;

/* Expression with its own lexical scope */
mexpr	:	expr
			{ $$ = $expr; intro_my(); }
	;

mnexpr	:	nexpr
			{ $$ = $nexpr; intro_my(); }
	;

formname:	BAREWORD	{ $$ = $BAREWORD; }
	|	empty
	;

startsub:	%empty	/* start a regular subroutine scope */
			{ $$ = start_subparse(FALSE, 0);
			    SAVEFREESV(PL_compcv); }

	;

startanonsub:	%empty	/* start an anonymous subroutine scope */
			{ $$ = start_subparse(FALSE, CVf_ANON);
			    SAVEFREESV(PL_compcv); }
	;

startanonmethod:	%empty	/* start an anonymous method scope */
			{ $$ = start_subparse(FALSE, CVf_ANON|CVf_IsMETHOD);
			    SAVEFREESV(PL_compcv); }
	;

startformsub:	%empty	/* start a format subroutine scope */
			{ $$ = start_subparse(TRUE, 0);
			    SAVEFREESV(PL_compcv); }
	;

/* Name of a subroutine - must be a bareword, could be special */
subname	:	BAREWORD
	|	PRIVATEREF
	;

/* Subroutine prototype */
proto
	:	empty
	|	THING
	;

/* Optional list of subroutine attributes */
subattrlist
	:	empty
	|	COLONATTR THING
			{
			  OP *attrlist = $THING;
			  if(attrlist && !PL_parser->sig_seen)
			      attrlist = apply_builtin_cv_attributes(PL_compcv, attrlist);
			  $$ = attrlist;
			}
	|	COLONATTR
			{ $$ = NULL; }
	;

/* List of attributes for a "my" variable declaration */
myattrlist:	COLONATTR THING
			{ $$ = $THING; }
	|	COLONATTR
			{ $$ = NULL; }
	;



/* --------------------------------------
 * subroutine signature parsing
 */

/* the '' or 'foo' part of a '$' or '@foo' etc signature variable  */
sigvarname:     %empty
			{ parser->in_my = 0; $$ = NULL; }
        |       PRIVATEREF
                        { parser->in_my = 0; $$ = $PRIVATEREF; }
	;

sigslurpsigil:
                PERLY_SNAIL
                        { $$ = '@'; }
        |       PERLY_PERCENT_SIGN
                        { $$ = '%'; }

/* @, %, @foo, %foo */
sigslurpelem: sigslurpsigil sigvarname sigdefault/* def only to catch errors */ 
                        {
                            I32 sigil = $sigslurpsigil;
                            OP *var   = $sigvarname;
                            OP *defop = $sigdefault;

                            if (parser->sig_slurpy)
                                yyerror("Multiple slurpy parameters not allowed");
                            parser->sig_slurpy = (char)sigil;

                            if (defop)
                                yyerror("A slurpy parameter may not have "
                                        "a default value");

                            $$ = var ? newSTATEOP(0, NULL, var) : NULL;
                        }
	;

/* default part of sub signature scalar element: i.e. '= default_expr' */
sigdefault
	:	empty
        |       ASSIGNOP
                        { $$ = newARGDEFELEMOP(0, newOP(OP_NULL, 0), parser->sig_elems); }
        |       ASSIGNOP term
                        {
                            I32 flags = 0;
                            if ($ASSIGNOP == OP_DORASSIGN)
                                flags |= OPpARG_IF_UNDEF << 8;
                            if ($ASSIGNOP == OP_ORASSIGN)
                                flags |= OPpARG_IF_FALSE << 8;
                            $$ = newARGDEFELEMOP(flags, $term, parser->sig_elems);
                        }


/* subroutine signature scalar element: e.g. '$x', '$=', '$x = $default' */
sigscalarelem:
                PERLY_DOLLAR sigvarname sigdefault
                        {
                            OP *var   = $sigvarname;
                            OP *defop = $sigdefault;

                            if (parser->sig_slurpy)
                                yyerror("Slurpy parameter not last");

                            parser->sig_elems++;

                            if (defop) {
                                parser->sig_optelems++;

                                OP *defexpr = cLOGOPx(defop)->op_first;

                                if (   defexpr->op_type == OP_NULL
                                    && !(defexpr->op_flags & OPf_KIDS))
                                {
                                    /* handle '$=' special case */
                                    if (var)
                                        yyerror("Optional parameter "
                                                    "lacks default expression");
                                    op_free(defop);
                                }
                                else { 
                                    /* a normal '=default' expression */ 
                                    if (var) {
                                        var->op_flags |= OPf_STACKED;
                                        (void)op_sibling_splice(var,
                                                        NULL, 0, defop);
                                        scalar(defop);
                                    }
                                    else
                                        var = newUNOP(OP_NULL, 0, defop);

                                    LINKLIST(var);
                                    /* NB: normally the first child of a
                                     * logop is executed before the logop,
                                     * and it pushes a boolean result
                                     * ready for the logop. For ARGDEFELEM,
                                     * the op itself does the boolean
                                     * calculation, so set the first op to
                                     * it instead.
                                     */
                                    var->op_next = defop;
                                    defexpr->op_next = var;
                                }
                            }
                            else {
                                if (parser->sig_optelems)
                                    yyerror("Mandatory parameter "
                                            "follows optional parameter");
                            }

                            $$ = var ? newSTATEOP(0, NULL, var) : NULL;
                        }
	;


/* subroutine signature element: e.g. '$x = $default' or '%h' */
sigelem:        sigscalarelem
                        { parser->in_my = KEY_sigvar; $$ = $sigscalarelem; }
        |       sigslurpelem
                        { parser->in_my = KEY_sigvar; $$ = $sigslurpelem; }
	;

/* list of subroutine signature elements */
siglist:
	 	siglist[list] PERLY_COMMA
			{ $$ = $list; }
	|	siglist[list] PERLY_COMMA sigelem[element]
			{
			  $$ = op_append_list(OP_LINESEQ, $list, $element);
			}
        |	sigelem[element]  %prec PREC_LOW
			{ $$ = $element; }
	;

/* () or (....) */
optsiglist
	:	empty
	|	siglist
	;

/* optional subroutine signature */
optsubsignature
	:	empty
	|	subsignature
	;

/* Subroutine signature */
subsignature:	PERLY_PAREN_OPEN subsigguts PERLY_PAREN_CLOSE
			{ $$ = $subsigguts; }

subsigguts:
                        {
                            ENTER;
                            SAVEIV(parser->sig_elems);
                            SAVEIV(parser->sig_optelems);
                            SAVEI8(parser->sig_slurpy);
                            parser->sig_elems    = 0;
                            parser->sig_optelems = 0;
                            parser->sig_slurpy   = 0;
                            parser->in_my        = KEY_sigvar;
                        }
                optsiglist
			{
                            OP            *sigops = $optsiglist;
                            struct op_argcheck_aux *aux;
                            OP            *check;

			    if (!FEATURE_SIGNATURES_IS_ENABLED && !CvIsMETHOD(PL_compcv))
			        Perl_croak(aTHX_ "Experimental "
                                    "subroutine signatures not enabled");

                            /* We shouldn't get here otherwise */
                            aux = (struct op_argcheck_aux*)
                                    PerlMemShared_malloc(
                                        sizeof(struct op_argcheck_aux));
                            aux->params     = parser->sig_elems;
                            aux->opt_params = parser->sig_optelems;
                            aux->slurpy     = parser->sig_slurpy;
                            check = newUNOP_AUX(OP_ARGCHECK, 0, NULL,
                                            (UNOP_AUX_item *)aux);
                            sigops = op_prepend_elem(OP_LINESEQ, check, sigops);
                            sigops = op_prepend_elem(OP_LINESEQ,
                                                newSTATEOP(0, NULL, NULL),
                                                sigops);
                            /* a nextstate at the end handles context
                             * correctly for an empty sub body */
                            sigops = op_append_elem(OP_LINESEQ,
                                                sigops,
                                                newSTATEOP(0, NULL, NULL));
                            /* wrap the list of arg ops in a NULL aux op.
                              This serves two purposes. First, it makes
                              the arg list a separate subtree from the
                              body of the sub, and secondly the null op
                              may in future be upgraded to an OP_SIGNATURE
                              when implemented. For now leave it as
                              ex-argcheck */
                            $$ = newUNOP_AUX(OP_ARGCHECK, 0, sigops, NULL);
                            op_null($$);

			    CvSIGNATURE_on(PL_compcv);

                            parser->in_my = 0;
                            /* tell the toker that attrributes can follow
                             * this sig, but only so that the toker
                             * can skip through any (illegal) trailing
                             * attribute text then give a useful error
                             * message about "attributes before sig",
                             * rather than falling over ina mess at
                             * unrecognised syntax.
                             */
                            parser->expect = XATTRBLOCK;
                            parser->sig_seen = TRUE;
                            LEAVE;
			}
	;

/* Optional subroutine body (for named subroutine declaration) */
optsubbody
	:	subbody
	|	PERLY_SEMICOLON	{ $$ = NULL; }
	;


/* Subroutine body (without signature) */
subbody:	remember  PERLY_BRACE_OPEN stmtseq PERLY_BRACE_CLOSE
			{
			  if (parser->copline > (line_t)$PERLY_BRACE_OPEN)
			      parser->copline = (line_t)$PERLY_BRACE_OPEN;
			  $$ = block_end($remember, $stmtseq);
			}
	;


/* optional [ Subroutine body with optional signature ] (for named
 * subroutine declaration) */
optsigsubbody
	:	sigsubbody
	|	PERLY_SEMICOLON	   { $$ = NULL; }
	;

/* Subroutine body with optional signature */
sigsubbody:	remember optsubsignature PERLY_BRACE_OPEN stmtseq PERLY_BRACE_CLOSE
			{
			  if (parser->copline > (line_t)$PERLY_BRACE_OPEN)
			      parser->copline = (line_t)$PERLY_BRACE_OPEN;
			  $$ = block_end($remember,
				op_append_list(OP_LINESEQ, $optsubsignature, $stmtseq));
 			}
 	;


/* Ordinary expressions; logical combinations */
expr	:	expr[lhs] ANDOP expr[rhs]
			{ $$ = newLOGOP(OP_AND, 0, $lhs, $rhs); }
	|	expr[lhs] PLUGIN_LOGICAL_AND_LOW_OP[op] expr[rhs]
			{ $$ = build_infix_plugin($lhs, $rhs, $op); }
	|	expr[lhs] OROP[operator] expr[rhs]
			{ $$ = newLOGOP($operator, 0, $lhs, $rhs); }
	|	expr[lhs] PLUGIN_LOGICAL_OR_LOW_OP[op] expr[rhs]
			{ $$ = build_infix_plugin($lhs, $rhs, $op); }
	|	listexpr %prec PREC_LOW
	;

/* Expressions are a list of terms joined by commas */
listexpr:	listexpr[list] PERLY_COMMA
			{ $$ = $list; }
	|	listexpr[list] PERLY_COMMA term
			{
			  OP* term = $term;
			  $$ = op_append_elem(OP_LIST, $list, term);
			}
	|	term %prec PREC_LOW
	;

/* List operators */
listop	:	LSTOP indirob listexpr /* map {...} @args or print $fh @args */
			{ $$ = op_convert_list($LSTOP, OPf_STACKED,
				op_prepend_elem(OP_LIST, newGVREF($LSTOP,$indirob), $listexpr) );
			}
	|	FUNC PERLY_PAREN_OPEN indirob expr PERLY_PAREN_CLOSE      /* print ($fh @args */
			{ $$ = op_convert_list($FUNC, OPf_STACKED,
				op_prepend_elem(OP_LIST, newGVREF($FUNC,$indirob), $expr) );
			}
	|	term ARROW methodname PERLY_PAREN_OPEN optexpr PERLY_PAREN_CLOSE /* $foo->bar(list) */
			{ $$ = op_convert_list(OP_ENTERSUB, OPf_STACKED,
				op_append_elem(OP_LIST,
				    op_prepend_elem(OP_LIST, scalar($term), $optexpr),
				    newMETHOP(OP_METHOD, 0, $methodname)));
			}
	|	term ARROW methodname                     /* $foo->bar */
			{ $$ = op_convert_list(OP_ENTERSUB, OPf_STACKED,
				op_append_elem(OP_LIST, scalar($term),
				    newMETHOP(OP_METHOD, 0, $methodname)));
			}
	|	METHCALL0 indirob optlistexpr           /* new Class @args */
			{ $$ = op_convert_list(OP_ENTERSUB, OPf_STACKED,
				op_append_elem(OP_LIST,
				    op_prepend_elem(OP_LIST, $indirob, $optlistexpr),
				    newMETHOP(OP_METHOD, 0, $METHCALL0)));
			}
	|	METHCALL indirob PERLY_PAREN_OPEN optexpr PERLY_PAREN_CLOSE    /* method $object (@args) */
			{ $$ = op_convert_list(OP_ENTERSUB, OPf_STACKED,
				op_append_elem(OP_LIST,
				    op_prepend_elem(OP_LIST, $indirob, $optexpr),
				    newMETHOP(OP_METHOD, 0, $METHCALL)));
			}
	|	LSTOP optlistexpr                    /* print @args */
			{ $$ = op_convert_list($LSTOP, 0, $optlistexpr); }
	|	FUNC PERLY_PAREN_OPEN optexpr PERLY_PAREN_CLOSE                 /* print (@args) */
			{ $$ = op_convert_list($FUNC, 0, $optexpr); }
	|	FUNC SUBLEXSTART optexpr SUBLEXEND          /* uc($arg) from "\U..." */
			{ $$ = op_convert_list($FUNC, 0, $optexpr); }
	|	LSTOPSUB startanonsub block /* sub f(&@);   f { foo } ... */
			{ SvREFCNT_inc_simple_void(PL_compcv);
			  $<opval>$ = newANONATTRSUB($startanonsub, 0, NULL, $block); }[anonattrsub]
		    optlistexpr		%prec LSTOP  /* ... @bar */
			{ $$ = newUNOP(OP_ENTERSUB, OPf_STACKED,
				 op_append_elem(OP_LIST,
				   op_prepend_elem(OP_LIST, $<opval>anonattrsub, $optlistexpr), $LSTOPSUB));
			}
	;

/* Names of methods. May use $object->$methodname */
methodname:	METHCALL0
	|	scalar
	;

/* Some kind of subscripted expression */
subscripted:    gelem PERLY_BRACE_OPEN expr PERLY_SEMICOLON PERLY_BRACE_CLOSE        /* *main::{something} */
                        /* In this and all the hash accessors, PERLY_SEMICOLON is
                         * provided by the tokeniser */
			{ $$ = newBINOP(OP_GELEM, 0, $gelem, scalar($expr)); }
	|	scalar[array] PERLY_BRACKET_OPEN expr PERLY_BRACKET_CLOSE          /* $array[$element] */
			{ $$ = newBINOP(OP_AELEM, 0, oopsAV($array), scalar($expr));
			}
	|	term[array_reference] ARROW PERLY_BRACKET_OPEN expr PERLY_BRACKET_CLOSE      /* somearef->[$element] */
			{ $$ = newBINOP(OP_AELEM, 0,
					ref(newAVREF($array_reference),OP_RV2AV),
					scalar($expr));
			}
	|	subscripted[array_reference] PERLY_BRACKET_OPEN expr PERLY_BRACKET_CLOSE    /* $foo->[$bar]->[$baz] */
			{ $$ = newBINOP(OP_AELEM, 0,
					ref(newAVREF($array_reference),OP_RV2AV),
					scalar($expr));
			}
	|	scalar[hash] PERLY_BRACE_OPEN expr PERLY_SEMICOLON PERLY_BRACE_CLOSE    /* $foo{bar();} */
			{ $$ = newBINOP(OP_HELEM, 0, oopsHV($hash), jmaybe($expr));
			}
	|	term[hash_reference] ARROW PERLY_BRACE_OPEN expr PERLY_SEMICOLON PERLY_BRACE_CLOSE /* somehref->{bar();} */
			{ $$ = newBINOP(OP_HELEM, 0,
					ref(newHVREF($hash_reference),OP_RV2HV),
					jmaybe($expr)); }
	|	subscripted[hash_reference] PERLY_BRACE_OPEN expr PERLY_SEMICOLON PERLY_BRACE_CLOSE /* $foo->[bar]->{baz;} */
			{ $$ = newBINOP(OP_HELEM, 0,
					ref(newHVREF($hash_reference),OP_RV2HV),
					jmaybe($expr)); }
	|	term[code_reference] ARROW PERLY_PAREN_OPEN PERLY_PAREN_CLOSE          /* $subref->() */
			{ $$ = newUNOP(OP_ENTERSUB, OPf_STACKED,
				   newCVREF(0, scalar($code_reference)));
			  if (parser->expect == XBLOCK)
			      parser->expect = XOPERATOR;
			}
	|	term[code_reference] ARROW PERLY_PAREN_OPEN expr PERLY_PAREN_CLOSE     /* $subref->(@args) */
			{ $$ = newUNOP(OP_ENTERSUB, OPf_STACKED,
				   op_append_elem(OP_LIST, $expr,
				       newCVREF(0, scalar($code_reference))));
			  if (parser->expect == XBLOCK)
			      parser->expect = XOPERATOR;
			}

	|	subscripted[code_reference] PERLY_PAREN_OPEN expr PERLY_PAREN_CLOSE   /* $foo->{bar}->(@args) */
			{ $$ = newUNOP(OP_ENTERSUB, OPf_STACKED,
				   op_append_elem(OP_LIST, $expr,
					       newCVREF(0, scalar($code_reference))));
			  if (parser->expect == XBLOCK)
			      parser->expect = XOPERATOR;
			}
	|	subscripted[code_reference] PERLY_PAREN_OPEN PERLY_PAREN_CLOSE        /* $foo->{bar}->() */
			{ $$ = newUNOP(OP_ENTERSUB, OPf_STACKED,
				   newCVREF(0, scalar($code_reference)));
			  if (parser->expect == XBLOCK)
			      parser->expect = XOPERATOR;
			}
	|	PERLY_PAREN_OPEN expr[list] PERLY_PAREN_CLOSE PERLY_BRACKET_OPEN expr[slice] PERLY_BRACKET_CLOSE            /* list slice */
			{ $$ = newSLICEOP(0, $slice, $list); }
	|	QWLIST PERLY_BRACKET_OPEN expr PERLY_BRACKET_CLOSE            /* list literal slice */
			{ $$ = newSLICEOP(0, $expr, $QWLIST); }
	|	PERLY_PAREN_OPEN PERLY_PAREN_CLOSE PERLY_BRACKET_OPEN expr PERLY_BRACKET_CLOSE                 /* empty list slice! */
			{ $$ = newSLICEOP(0, $expr, NULL); }
    ;

/* Binary operators between terms */
termbinop:	term[lhs] PLUGIN_HIGH_OP[op] term[rhs]
			{ $$ = build_infix_plugin($lhs, $rhs, $op); }
	|	term[lhs] ASSIGNOP term[rhs]                     /* $x = $y, $x += $y */
			{ $$ = newASSIGNOP(OPf_STACKED, $lhs, $ASSIGNOP, $rhs); }
	|	term[lhs] PLUGIN_ASSIGN_OP[op] term[rhs]
			{ $$ = build_infix_plugin($lhs, $rhs, $op); }
	|	term[lhs] POWOP term[rhs]                        /* $x ** $y */
			{ $$ = newBINOP($POWOP, 0, scalar($lhs), scalar($rhs)); }
	|	term[lhs] PLUGIN_POW_OP[op] term[rhs]
			{ $$ = build_infix_plugin($lhs, $rhs, $op); }
	|	term[lhs] MULOP term[rhs]                        /* $x * $y, $x x $y */
			{   if ($MULOP != OP_REPEAT)
				scalar($lhs);
			    $$ = newBINOP($MULOP, 0, $lhs, scalar($rhs));
			}
	|	term[lhs] PLUGIN_MUL_OP[op] term[rhs]
			{ $$ = build_infix_plugin($lhs, $rhs, $op); }
	|	term[lhs] ADDOP term[rhs]                        /* $x + $y */
			{ $$ = newBINOP($ADDOP, 0, scalar($lhs), scalar($rhs)); }
	|	term[lhs] PLUGIN_ADD_OP[op] term[rhs]
			{ $$ = build_infix_plugin($lhs, $rhs, $op); }
	|	term[lhs] SHIFTOP term[rhs]                      /* $x >> $y, $x << $y */
			{ $$ = newBINOP($SHIFTOP, 0, scalar($lhs), scalar($rhs)); }
	|	termrelop %prec PREC_LOW               /* $x > $y, etc. */
			{ $$ = $termrelop; }
	|	termeqop %prec PREC_LOW                /* $x == $y, $x cmp $y */
			{ $$ = $termeqop; }
	|	term[lhs] BITANDOP term[rhs]                     /* $x & $y */
			{ $$ = newBINOP($BITANDOP, 0, scalar($lhs), scalar($rhs)); }
	|	term[lhs] BITOROP term[rhs]                      /* $x | $y */
			{ $$ = newBINOP($BITOROP, 0, scalar($lhs), scalar($rhs)); }
	|	term[lhs] DOTDOT term[rhs]                       /* $x..$y, $x...$y */
			{ $$ = newRANGE($DOTDOT, scalar($lhs), scalar($rhs)); }
	|	term[lhs] ANDAND term[rhs]                       /* $x && $y */
			{ $$ = newLOGOP(OP_AND, 0, $lhs, $rhs); }
	|	term[lhs] PLUGIN_LOGICAL_AND_OP[op] term[rhs]
			{ $$ = build_infix_plugin($lhs, $rhs, $op); }
	|	term[lhs] OROR term[rhs]                         /* $x || $y */
			{ $$ = newLOGOP(OP_OR, 0, $lhs, $rhs); }
	|	term[lhs] PLUGIN_LOGICAL_OR_OP[op] term[rhs]
			{ $$ = build_infix_plugin($lhs, $rhs, $op); }
	|	term[lhs] DORDOR term[rhs]                       /* $x // $y */
			{ $$ = newLOGOP(OP_DOR, 0, $lhs, $rhs); }
	|	term[lhs] MATCHOP term[rhs]                      /* $x =~ /$y/ */
			{ $$ = bind_match($MATCHOP, $lhs, $rhs); }
	|	term[lhs] PLUGIN_LOW_OP[op] term[rhs]
			{ $$ = build_infix_plugin($lhs, $rhs, $op); }
    ;

termrelop:	relopchain %prec PREC_LOW
			{ $$ = cmpchain_finish($relopchain); }
	|	term[lhs] NCRELOP term[rhs]
			{ $$ = newBINOP($NCRELOP, 0, scalar($lhs), scalar($rhs)); }
	|	termrelop NCRELOP
			{ yyerror("syntax error"); YYERROR; }
	|	termrelop CHRELOP
			{ yyerror("syntax error"); YYERROR; }
	|	term[lhs] PLUGIN_REL_OP[op] term[rhs]
			{ $$ = build_infix_plugin($lhs, $rhs, $op); }
	;

relopchain:	term[lhs] CHRELOP term[rhs]
			{ $$ = cmpchain_start($CHRELOP, $lhs, $rhs); }
	|	relopchain[lhs] CHRELOP term[rhs]
			{ $$ = cmpchain_extend($CHRELOP, $lhs, $rhs); }
	;

termeqop:	eqopchain %prec PREC_LOW
			{ $$ = cmpchain_finish($eqopchain); }
	|	term[lhs] NCEQOP term[rhs]
			{ $$ = newBINOP($NCEQOP, 0, scalar($lhs), scalar($rhs)); }
	|	termeqop NCEQOP
			{ yyerror("syntax error"); YYERROR; }
	|	termeqop CHEQOP
			{ yyerror("syntax error"); YYERROR; }
	;

eqopchain:	term[lhs] CHEQOP term[rhs]
			{ $$ = cmpchain_start($CHEQOP, $lhs, $rhs); }
	|	eqopchain[lhs] CHEQOP term[rhs]
			{ $$ = cmpchain_extend($CHEQOP, $lhs, $rhs); }
	;

/* Unary operators and terms */
termunop : PERLY_MINUS term %prec UMINUS                       /* -$x */
			{ $$ = newUNOP(OP_NEGATE, 0, scalar($term)); }
	|	PERLY_PLUS term %prec UMINUS                  /* +$x */
			{ $$ = $term; }

	|	PERLY_EXCLAMATION_MARK term                               /* !$x */
			{ $$ = newUNOP(OP_NOT, 0, scalar($term)); }
	|	PERLY_TILDE term                               /* ~$x */
			{ $$ = newUNOP($PERLY_TILDE, 0, scalar($term)); }
	|	term POSTINC                           /* $x++ */
			{ $$ = newUNOP(OP_POSTINC, 0,
					op_lvalue(scalar($term), OP_POSTINC)); }
	|	term POSTDEC                           /* $x-- */
			{ $$ = newUNOP(OP_POSTDEC, 0,
					op_lvalue(scalar($term), OP_POSTDEC));}
	|	term POSTJOIN    /* implicit join after interpolated ->@ */
			{ $$ = op_convert_list(OP_JOIN, 0,
				       op_append_elem(
					OP_LIST,
					newSVREF(scalar(
					    newSVOP(OP_CONST,0,
						    newSVpvs("\""))
					)),
					$term
				       ));
			}
	|	PREINC term                            /* ++$x */
			{ $$ = newUNOP(OP_PREINC, 0,
					op_lvalue(scalar($term), OP_PREINC)); }
	|	PREDEC term                            /* --$x */
			{ $$ = newUNOP(OP_PREDEC, 0,
					op_lvalue(scalar($term), OP_PREDEC)); }

    ;

/* Constructors for anonymous data */
anonymous
	:	PERLY_BRACKET_OPEN optexpr PERLY_BRACKET_CLOSE
			{ $$ = newANONLIST($optexpr); }
	|	HASHBRACK optexpr PERLY_SEMICOLON PERLY_BRACE_CLOSE	%prec PERLY_PAREN_OPEN /* { foo => "Bar" } */
			{ $$ = newANONHASH($optexpr); }
	|	KW_SUB_anon     startanonsub proto subattrlist subbody    %prec PERLY_PAREN_OPEN
			{ SvREFCNT_inc_simple_void(PL_compcv);
			  $$ = newANONATTRSUB($startanonsub, $proto, $subattrlist, $subbody); }
	|	KW_SUB_anon_sig startanonsub subattrlist sigsubbody %prec PERLY_PAREN_OPEN
			{ SvREFCNT_inc_simple_void(PL_compcv);
			  $$ = newANONATTRSUB($startanonsub, NULL, $subattrlist, $sigsubbody); }
	|	KW_METHOD_anon startanonmethod subattrlist sigsubbody %prec PERLY_PAREN_OPEN
			{
			  SvREFCNT_inc_simple_void(PL_compcv);
			  $$ = newANONATTRSUB($startanonmethod, NULL, $subattrlist, $sigsubbody);
			}
    ;

/* Things called with "do" */
termdo	:       KW_DO term	%prec UNIOP                     /* do $filename */
			{ $$ = dofile($term, $KW_DO);}
	|	KW_DO block	%prec PERLY_PAREN_OPEN               /* do { code */
			{ $$ = newUNOP(OP_NULL, OPf_SPECIAL, op_scope($block));}
        ;

term[product]	:	termbinop
	|	termunop
	|	anonymous
	|	termdo
	|	term[condition] PERLY_QUESTION_MARK term[then] PERLY_COLON term[else]
			{ $$ = newCONDOP(0, $condition, $then, $else); }
	|	REFGEN term[operand]                          /* \$x, \@y, \%z */
			{ $$ = newUNOP(OP_REFGEN, 0, $operand); }
	|	myattrterm	%prec UNIOP
			{ $$ = $myattrterm; }
	|	KW_LOCAL term[operand]	%prec UNIOP
			{ $$ = localize($operand,0); }
	|	PERLY_PAREN_OPEN expr PERLY_PAREN_CLOSE
			{ $$ = sawparens($expr); }
	|	QWLIST
			{ $$ = $QWLIST; }
	|	PERLY_PAREN_OPEN PERLY_PAREN_CLOSE
			{ $$ = sawparens(newNULLLIST()); }
	|	scalar	%prec PERLY_PAREN_OPEN
			{ $$ = $scalar; }
	|	star	%prec PERLY_PAREN_OPEN
			{ $$ = $star; }
	|	hsh 	%prec PERLY_PAREN_OPEN
			{ $$ = $hsh; }
	|	ary 	%prec PERLY_PAREN_OPEN
			{ $$ = $ary; }
	|	arylen 	%prec PERLY_PAREN_OPEN                    /* $#x, $#{ something } */
			{ $$ = newUNOP(OP_AV2ARYLEN, 0, ref($arylen, OP_AV2ARYLEN));}
	|       subscripted
			{ $$ = $subscripted; }
	|	sliceme PERLY_BRACKET_OPEN expr PERLY_BRACKET_CLOSE                     /* array slice */
			{ $$ = op_prepend_elem(OP_ASLICE,
				newOP(OP_PUSHMARK, 0),
				    newLISTOP(OP_ASLICE, 0,
					list($expr),
					ref($sliceme, OP_ASLICE)));
			  if ($$ && $sliceme)
			      $$->op_private |=
				  $sliceme->op_private & OPpSLICEWARNING;
			}
	|	kvslice PERLY_BRACKET_OPEN expr PERLY_BRACKET_CLOSE                 /* array key/value slice */
			{ $$ = op_prepend_elem(OP_KVASLICE,
				newOP(OP_PUSHMARK, 0),
				    newLISTOP(OP_KVASLICE, 0,
					list($expr),
					ref(oopsAV($kvslice), OP_KVASLICE)));
			  if ($$ && $kvslice)
			      $$->op_private |=
				  $kvslice->op_private & OPpSLICEWARNING;
			}
	|	sliceme PERLY_BRACE_OPEN expr PERLY_SEMICOLON PERLY_BRACE_CLOSE                 /* @hash{@keys} */
			{ $$ = op_prepend_elem(OP_HSLICE,
				newOP(OP_PUSHMARK, 0),
				    newLISTOP(OP_HSLICE, 0,
					list($expr),
					ref(oopsHV($sliceme), OP_HSLICE)));
			  if ($$ && $sliceme)
			      $$->op_private |=
				  $sliceme->op_private & OPpSLICEWARNING;
			}
	|	kvslice PERLY_BRACE_OPEN expr PERLY_SEMICOLON PERLY_BRACE_CLOSE                 /* %hash{@keys} */
			{ $$ = op_prepend_elem(OP_KVHSLICE,
				newOP(OP_PUSHMARK, 0),
				    newLISTOP(OP_KVHSLICE, 0,
					list($expr),
					ref($kvslice, OP_KVHSLICE)));
			  if ($$ && $kvslice)
			      $$->op_private |=
				  $kvslice->op_private & OPpSLICEWARNING;
			}
	|	THING	%prec PERLY_PAREN_OPEN
			{ $$ = $THING; }
	|	amper                                /* &foo; */
			{ $$ = newUNOP(OP_ENTERSUB, 0, scalar($amper)); }
	|	amper PERLY_PAREN_OPEN PERLY_PAREN_CLOSE                 /* &foo() or foo() */
			{ $$ = newUNOP(OP_ENTERSUB, OPf_STACKED, scalar($amper));
			}
	|	amper PERLY_PAREN_OPEN expr PERLY_PAREN_CLOSE          /* &foo(@args) or foo(@args) */
			{
			  $$ = newUNOP(OP_ENTERSUB, OPf_STACKED,
				op_append_elem(OP_LIST, $expr, scalar($amper)));
			}
	|	NOAMP subname optlistexpr       /* foo @args (no parens) */
			{ $$ = newUNOP(OP_ENTERSUB, OPf_STACKED,
			    op_append_elem(OP_LIST, $optlistexpr, scalar($subname)));
			}
	|	term[operand] ARROW PERLY_DOLLAR PERLY_STAR
			{ $$ = newSVREF($operand); }
	|	term[operand] ARROW PERLY_SNAIL PERLY_STAR
			{ $$ = newAVREF($operand); }
	|	term[operand] ARROW PERLY_PERCENT_SIGN PERLY_STAR
			{ $$ = newHVREF($operand); }
	|	term[operand] ARROW PERLY_AMPERSAND PERLY_STAR
			{ $$ = newUNOP(OP_ENTERSUB, 0,
				       scalar(newCVREF($PERLY_AMPERSAND,$operand))); }
	|	term[operand] ARROW PERLY_STAR PERLY_STAR	%prec PERLY_PAREN_OPEN
			{ $$ = newGVREF(0,$operand); }
	|	LOOPEX  /* loop exiting command (goto, last, dump, etc) */
			{ $$ = newOP($LOOPEX, OPf_SPECIAL);
			    PL_hints |= HINT_BLOCK_SCOPE; }
	|	LOOPEX term[operand]
			{ $$ = newLOOPEX($LOOPEX,$operand); }
	|	NOTOP listexpr                       /* not $foo */
			{ $$ = newUNOP(OP_NOT, 0, scalar($listexpr)); }
	|	UNIOP                                /* Unary op, $_ implied */
			{ $$ = newOP($UNIOP, 0); }
	|	UNIOP block                          /* eval { foo }* */
			{ $$ = newUNOP($UNIOP, 0, $block); }
	|	UNIOP term[operand]                           /* Unary op */
			{ $$ = newUNOP($UNIOP, 0, $operand); }
	|	KW_REQUIRE                              /* require, $_ implied */
			{ $$ = newOP(OP_REQUIRE, $KW_REQUIRE ? OPf_SPECIAL : 0); }
	|	KW_REQUIRE term[operand]                         /* require Foo */
			{ $$ = newUNOP(OP_REQUIRE, $KW_REQUIRE ? OPf_SPECIAL : 0, $operand); }
	|	UNIOPSUB
			{ $$ = newUNOP(OP_ENTERSUB, OPf_STACKED, scalar($UNIOPSUB)); }
	|	UNIOPSUB term[operand]                        /* Sub treated as unop */
			{ $$ = newUNOP(OP_ENTERSUB, OPf_STACKED,
			    op_append_elem(OP_LIST, $operand, scalar($UNIOPSUB))); }
	|	FUNC0                                /* Nullary operator */
			{ $$ = newOP($FUNC0, 0); }
	|	FUNC0 PERLY_PAREN_OPEN PERLY_PAREN_CLOSE
			{ $$ = newOP($FUNC0, 0);}
	|	FUNC0OP       /* Same as above, but op created in toke.c */
			{ $$ = $FUNC0OP; }
	|	FUNC0OP PERLY_PAREN_OPEN PERLY_PAREN_CLOSE
			{ $$ = $FUNC0OP; }
	|	FUNC0SUB                             /* Sub treated as nullop */
			{ $$ = newUNOP(OP_ENTERSUB, OPf_STACKED, scalar($FUNC0SUB)); }
	|	FUNC1 PERLY_PAREN_OPEN PERLY_PAREN_CLOSE                        /* not () */
			{ $$ = ($FUNC1 == OP_NOT)
                          ? newUNOP($FUNC1, 0, newSVOP(OP_CONST, 0, newSViv(0)))
                          : newOP($FUNC1, OPf_SPECIAL); }
	|	FUNC1 PERLY_PAREN_OPEN expr PERLY_PAREN_CLOSE                   /* not($foo) */
			{ $$ = newUNOP($FUNC1, 0, $expr); }
	|	PMFUNC /* m//, s///, qr//, tr/// */
			{
			    if (   $PMFUNC->op_type != OP_TRANS
			        && $PMFUNC->op_type != OP_TRANSR
				&& (((PMOP*)$PMFUNC)->op_pmflags & PMf_HAS_CV))
			    {
				$<ival>$ = start_subparse(FALSE, CVf_ANON);
				SAVEFREESV(PL_compcv);
			    } else
				$<ival>$ = 0;
			}
		    SUBLEXSTART listexpr optrepl SUBLEXEND
			{ $$ = pmruntime($PMFUNC, $listexpr, $optrepl, 1, $<ival>2); }
	|	BAREWORD
	|	listop
	|	PLUGEXPR
	;

/* "my" declarations, with optional attributes */
myattrterm
	:	KW_MY myterm myattrlist
			{ $$ = my_attrs($myterm,$myattrlist); }
	|	KW_MY myterm
			{ $$ = localize($myterm,1); }
	|	KW_MY REFGEN myterm myattrlist
			{ $$ = newUNOP(OP_REFGEN, 0, my_attrs($myterm,$myattrlist)); }
	|	KW_MY REFGEN term[operand]
			{ $$ = newUNOP(OP_REFGEN, 0, localize($operand,1)); }
	;

/* Things that can be "my"'d */
myterm	:	PERLY_PAREN_OPEN expr PERLY_PAREN_CLOSE
			{ $$ = sawparens($expr); }
	|	PERLY_PAREN_OPEN PERLY_PAREN_CLOSE
			{ $$ = sawparens(newNULLLIST()); }

	|	scalar	%prec PERLY_PAREN_OPEN
			{ $$ = $scalar; }
	|	hsh 	%prec PERLY_PAREN_OPEN
			{ $$ = $hsh; }
	|	ary 	%prec PERLY_PAREN_OPEN
			{ $$ = $ary; }
	;

/* "field" declarations */
fieldvar:	scalar	%prec PERLY_PAREN_OPEN
			{
			  $$ = PadnamelistARRAY(PL_comppad_name)[$scalar->op_targ];
			  op_free($scalar);
			}
	|	hsh 	%prec PERLY_PAREN_OPEN
			{
			  $$ = PadnamelistARRAY(PL_comppad_name)[$hsh->op_targ];
			  op_free($hsh);
			}
	|	ary 	%prec PERLY_PAREN_OPEN
			{
			  $$ = PadnamelistARRAY(PL_comppad_name)[$ary->op_targ];
			  op_free($ary);
			}
	;

optfieldattrlist:
		COLONATTR THING
			{ $$ = $THING; }
	|	COLONATTR
			{ $$ = NULL; }
	|	empty
	;

fielddecl
	:	KW_FIELD fieldvar optfieldattrlist
			{
			  parser->in_my = 0;
			  if($optfieldattrlist)
			    class_apply_field_attributes((PADNAME *)$fieldvar, $optfieldattrlist);
			  $$ = newOP(OP_NULL, 0);
			}
	|	KW_FIELD fieldvar optfieldattrlist ASSIGNOP
			{
			  parser->in_my = 0;
			  if($optfieldattrlist)
			    class_apply_field_attributes((PADNAME *)$fieldvar, $optfieldattrlist);
			  ENTER;
			  class_prepare_initfield_parse();
			}
		term
			{
			  class_set_field_defop((PADNAME *)$fieldvar, $ASSIGNOP, $term);
			  LEAVE;
			  $$ = newOP(OP_NULL, 0);
			}
	;

/* Basic list expressions */
optlistexpr
	:	empty                   %prec PREC_LOW
	|	listexpr                %prec PREC_LOW
	;

optexpr
	:	empty
	|	expr
	;

optrepl
	:	empty
	|	PERLY_SLASH expr        { $$ = $expr; }
	;

/* A little bit of trickery to make "for my $foo (@bar)" actually be
   lexical */
my_scalar:	scalar
			{ parser->in_my = 0; $$ = my($scalar); }
	;

/* A list of scalars for "for my ($foo, $bar) (@baz)"  */
list_of_scalars:	list_of_scalars[list] PERLY_COMMA
			{ $$ = $list; }
	|		list_of_scalars[list] PERLY_COMMA scalar
			{
			  $$ = op_append_elem(OP_LIST, $list, $scalar);
			}
	|		scalar %prec PREC_LOW
	;

my_list_of_scalars:	list_of_scalars
			{ parser->in_my = 0; $$ = $list_of_scalars; }
	;

my_var	:	scalar
	|	ary
	|	hsh
	;

refgen_topic:	my_var
	|	amper
	;

my_refgen:	KW_MY REFGEN
	|	REFGEN KW_MY
	;

amper	:	PERLY_AMPERSAND indirob
			{ $$ = newCVREF($PERLY_AMPERSAND,$indirob); }
	;

scalar	:	PERLY_DOLLAR indirob
			{ $$ = newSVREF($indirob); }
	;

ary	:	PERLY_SNAIL indirob
			{ $$ = newAVREF($indirob);
			  if ($$) $$->op_private |= $PERLY_SNAIL;
			}
	;

hsh	:	PERLY_PERCENT_SIGN indirob
			{ $$ = newHVREF($indirob);
			  if ($$) $$->op_private |= $PERLY_PERCENT_SIGN;
			}
	;

arylen	:	DOLSHARP indirob
			{ $$ = newAVREF($indirob); }
	|	term ARROW DOLSHARP PERLY_STAR
			{ $$ = newAVREF($term); }
	;

star	:	PERLY_STAR indirob
			{ $$ = newGVREF(0,$indirob); }
	;

sliceme	:	ary
	|	term ARROW PERLY_SNAIL
			{ $$ = newAVREF($term); }
	;

kvslice	:	hsh
	|	term ARROW PERLY_PERCENT_SIGN
			{ $$ = newHVREF($term); }
	;

gelem	:	star
	|	term ARROW PERLY_STAR
			{ $$ = newGVREF(0,$term); }
	;

/* Indirect objects */
indirob	:	BAREWORD
			{ $$ = scalar($BAREWORD); }
	|	scalar %prec PREC_LOW
			{ $$ = scalar($scalar); }
	|	block
			{ $$ = op_scope($block); }

	|	PRIVATEREF
			{ $$ = $PRIVATEREF; }
	;