Welcome to mirror list, hosted at ThFree Co, Russian Federation.

cs-parser.jay « gmcs « mcs - github.com/mono/mono.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 05c5aa9765441ed2854ccc98b05612f712f677c6 (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
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880
2881
2882
2883
2884
2885
2886
2887
2888
2889
2890
2891
2892
2893
2894
2895
2896
2897
2898
2899
2900
2901
2902
2903
2904
2905
2906
2907
2908
2909
2910
2911
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
2923
2924
2925
2926
2927
2928
2929
2930
2931
2932
2933
2934
2935
2936
2937
2938
2939
2940
2941
2942
2943
2944
2945
2946
2947
2948
2949
2950
2951
2952
2953
2954
2955
2956
2957
2958
2959
2960
2961
2962
2963
2964
2965
2966
2967
2968
2969
2970
2971
2972
2973
2974
2975
2976
2977
2978
2979
2980
2981
2982
2983
2984
2985
2986
2987
2988
2989
2990
2991
2992
2993
2994
2995
2996
2997
2998
2999
3000
3001
3002
3003
3004
3005
3006
3007
3008
3009
3010
3011
3012
3013
3014
3015
3016
3017
3018
3019
3020
3021
3022
3023
3024
3025
3026
3027
3028
3029
3030
3031
3032
3033
3034
3035
3036
3037
3038
3039
3040
3041
3042
3043
3044
3045
3046
3047
3048
3049
3050
3051
3052
3053
3054
3055
3056
3057
3058
3059
3060
3061
3062
3063
3064
3065
3066
3067
3068
3069
3070
3071
3072
3073
3074
3075
3076
3077
3078
3079
3080
3081
3082
3083
3084
3085
3086
3087
3088
3089
3090
3091
3092
3093
3094
3095
3096
3097
3098
3099
3100
3101
3102
3103
3104
3105
3106
3107
3108
3109
3110
3111
3112
3113
3114
3115
3116
3117
3118
3119
3120
3121
3122
3123
3124
3125
3126
3127
3128
3129
3130
3131
3132
3133
3134
3135
3136
3137
3138
3139
3140
3141
3142
3143
3144
3145
3146
3147
3148
3149
3150
3151
3152
3153
3154
3155
3156
3157
3158
3159
3160
3161
3162
3163
3164
3165
3166
3167
3168
3169
3170
3171
3172
3173
3174
3175
3176
3177
3178
3179
3180
3181
3182
3183
3184
3185
3186
3187
3188
3189
3190
3191
3192
3193
3194
3195
3196
3197
3198
3199
3200
3201
3202
3203
3204
3205
3206
3207
3208
3209
3210
3211
3212
3213
3214
3215
3216
3217
3218
3219
3220
3221
3222
3223
3224
3225
3226
3227
3228
3229
3230
3231
3232
3233
3234
3235
3236
3237
3238
3239
3240
3241
3242
3243
3244
3245
3246
3247
3248
3249
3250
3251
3252
3253
3254
3255
3256
3257
3258
3259
3260
3261
3262
3263
3264
3265
3266
3267
3268
3269
3270
3271
3272
3273
3274
3275
3276
3277
3278
3279
3280
3281
3282
3283
3284
3285
3286
3287
3288
3289
3290
3291
3292
3293
3294
3295
3296
3297
3298
3299
3300
3301
3302
3303
3304
3305
3306
3307
3308
3309
3310
3311
3312
3313
3314
3315
3316
3317
3318
3319
3320
3321
3322
3323
3324
3325
3326
3327
3328
3329
3330
3331
3332
3333
3334
3335
3336
3337
3338
3339
3340
3341
3342
3343
3344
3345
3346
3347
3348
3349
3350
3351
3352
3353
3354
3355
3356
3357
3358
3359
3360
3361
3362
3363
3364
3365
3366
3367
3368
3369
3370
3371
3372
3373
3374
3375
3376
3377
3378
3379
3380
3381
3382
3383
3384
3385
3386
3387
3388
3389
3390
3391
3392
3393
3394
3395
3396
3397
3398
3399
3400
3401
3402
3403
3404
3405
3406
3407
3408
3409
3410
3411
3412
3413
3414
3415
3416
3417
3418
3419
3420
3421
3422
3423
3424
3425
3426
3427
3428
3429
3430
3431
3432
3433
3434
3435
3436
3437
3438
3439
3440
3441
3442
3443
3444
3445
3446
3447
3448
3449
3450
3451
3452
3453
3454
3455
3456
3457
3458
3459
3460
3461
3462
3463
3464
3465
3466
3467
3468
3469
3470
3471
3472
3473
3474
3475
3476
3477
3478
3479
3480
3481
3482
3483
3484
3485
3486
3487
3488
3489
3490
3491
3492
3493
3494
3495
3496
3497
3498
3499
3500
3501
3502
3503
3504
3505
3506
3507
3508
3509
3510
3511
3512
3513
3514
3515
3516
3517
3518
3519
3520
3521
3522
3523
3524
3525
3526
3527
3528
3529
3530
3531
3532
3533
3534
3535
3536
3537
3538
3539
3540
3541
3542
3543
3544
3545
3546
3547
3548
3549
3550
3551
3552
3553
3554
3555
3556
3557
3558
3559
3560
3561
3562
3563
3564
3565
3566
3567
3568
3569
3570
3571
3572
3573
3574
3575
3576
3577
3578
3579
3580
3581
3582
3583
3584
3585
3586
3587
3588
3589
3590
3591
3592
3593
3594
3595
3596
3597
3598
3599
3600
3601
3602
3603
3604
3605
3606
3607
3608
3609
3610
3611
3612
3613
3614
3615
3616
3617
3618
3619
3620
3621
3622
3623
3624
3625
3626
3627
3628
3629
3630
3631
3632
3633
3634
3635
3636
3637
3638
3639
3640
3641
3642
3643
3644
3645
3646
3647
3648
3649
3650
3651
3652
3653
3654
3655
3656
3657
3658
3659
3660
3661
3662
3663
3664
3665
3666
3667
3668
3669
3670
3671
3672
3673
3674
3675
3676
3677
3678
3679
3680
3681
3682
3683
3684
3685
3686
3687
3688
3689
3690
3691
3692
3693
3694
3695
3696
3697
3698
3699
3700
3701
3702
3703
3704
3705
3706
3707
3708
3709
3710
3711
3712
3713
3714
3715
3716
3717
3718
3719
3720
3721
3722
3723
3724
3725
3726
3727
3728
3729
3730
3731
3732
3733
3734
3735
3736
3737
3738
3739
3740
3741
3742
3743
3744
3745
3746
3747
3748
3749
3750
3751
3752
3753
3754
3755
3756
3757
3758
3759
3760
3761
3762
3763
3764
3765
3766
3767
3768
3769
3770
3771
3772
3773
3774
3775
3776
3777
3778
3779
3780
3781
3782
3783
3784
3785
3786
3787
3788
3789
3790
3791
3792
3793
3794
3795
3796
3797
3798
3799
3800
3801
3802
3803
3804
3805
3806
3807
3808
3809
3810
3811
3812
3813
3814
3815
3816
3817
3818
3819
3820
3821
3822
3823
3824
3825
3826
3827
3828
3829
3830
3831
3832
3833
3834
3835
3836
3837
3838
3839
3840
3841
3842
3843
3844
3845
3846
3847
3848
3849
3850
3851
3852
3853
3854
3855
3856
3857
3858
3859
3860
3861
3862
3863
3864
3865
3866
3867
3868
3869
3870
3871
3872
3873
3874
3875
3876
3877
3878
3879
3880
3881
3882
3883
3884
3885
3886
3887
3888
3889
3890
3891
3892
3893
3894
3895
3896
3897
3898
3899
3900
3901
3902
3903
3904
3905
3906
3907
3908
3909
3910
3911
3912
3913
3914
3915
3916
3917
3918
3919
3920
3921
3922
3923
3924
3925
3926
3927
3928
3929
3930
3931
3932
3933
3934
3935
3936
3937
3938
3939
3940
3941
3942
3943
3944
3945
3946
3947
3948
3949
3950
3951
3952
3953
3954
3955
3956
3957
3958
3959
3960
3961
3962
3963
3964
3965
3966
3967
3968
3969
3970
3971
3972
3973
3974
3975
3976
3977
3978
3979
3980
3981
3982
3983
3984
3985
3986
3987
3988
3989
3990
3991
3992
3993
3994
3995
3996
3997
3998
3999
4000
4001
4002
4003
4004
4005
4006
4007
4008
4009
4010
4011
4012
4013
4014
4015
4016
4017
4018
4019
4020
4021
4022
4023
4024
4025
4026
4027
4028
4029
4030
4031
4032
4033
4034
4035
4036
4037
4038
4039
4040
4041
4042
4043
4044
4045
4046
4047
4048
4049
4050
4051
4052
4053
4054
4055
4056
4057
4058
4059
4060
4061
4062
4063
4064
4065
4066
4067
4068
4069
4070
4071
4072
4073
4074
4075
4076
4077
4078
4079
4080
4081
4082
4083
4084
4085
4086
4087
4088
4089
4090
4091
4092
4093
4094
4095
4096
4097
4098
4099
4100
4101
4102
4103
4104
4105
4106
4107
4108
4109
4110
4111
4112
4113
4114
4115
4116
4117
4118
4119
4120
4121
4122
4123
4124
4125
4126
4127
4128
4129
4130
4131
4132
4133
4134
4135
4136
4137
4138
4139
4140
4141
4142
4143
4144
4145
4146
4147
4148
4149
4150
4151
4152
4153
4154
4155
4156
4157
4158
4159
4160
4161
4162
4163
4164
4165
4166
4167
4168
4169
4170
4171
4172
4173
4174
4175
4176
4177
4178
4179
4180
4181
4182
4183
4184
4185
4186
4187
4188
4189
4190
4191
4192
4193
4194
4195
4196
4197
4198
4199
4200
4201
4202
4203
4204
4205
4206
4207
4208
4209
4210
4211
4212
4213
4214
4215
4216
4217
4218
4219
4220
4221
4222
4223
4224
4225
4226
4227
4228
4229
4230
4231
4232
4233
4234
4235
4236
4237
4238
4239
4240
4241
4242
4243
4244
4245
4246
4247
4248
4249
4250
4251
4252
4253
4254
4255
4256
4257
4258
4259
4260
4261
4262
4263
4264
4265
4266
4267
4268
4269
4270
4271
4272
4273
4274
4275
4276
4277
4278
4279
4280
4281
4282
4283
4284
4285
4286
4287
4288
4289
4290
4291
4292
4293
4294
4295
4296
4297
4298
4299
4300
4301
4302
4303
4304
4305
4306
4307
4308
4309
4310
4311
4312
4313
4314
4315
4316
4317
4318
4319
4320
4321
4322
4323
4324
4325
4326
4327
4328
4329
4330
4331
4332
4333
4334
4335
4336
4337
4338
4339
4340
4341
4342
4343
4344
4345
4346
4347
4348
4349
4350
4351
4352
4353
4354
4355
4356
4357
4358
4359
4360
4361
4362
4363
4364
4365
4366
4367
4368
4369
4370
4371
4372
4373
4374
4375
4376
4377
4378
4379
4380
4381
4382
4383
4384
4385
4386
4387
4388
4389
4390
4391
4392
4393
4394
4395
4396
4397
4398
4399
4400
4401
4402
4403
4404
4405
4406
4407
4408
4409
4410
4411
4412
4413
4414
4415
4416
4417
4418
4419
4420
4421
4422
4423
4424
4425
4426
4427
4428
4429
4430
4431
4432
4433
4434
4435
4436
4437
4438
4439
4440
4441
4442
4443
4444
4445
4446
4447
4448
4449
4450
4451
4452
4453
4454
4455
4456
4457
4458
4459
4460
4461
4462
4463
4464
4465
4466
4467
4468
4469
4470
4471
4472
4473
4474
4475
4476
4477
4478
4479
4480
4481
4482
4483
4484
4485
4486
4487
4488
4489
4490
4491
4492
4493
4494
4495
4496
4497
4498
4499
4500
4501
4502
4503
4504
4505
4506
4507
4508
4509
4510
4511
4512
4513
4514
4515
4516
4517
4518
4519
4520
4521
4522
4523
4524
4525
4526
4527
4528
4529
4530
4531
4532
4533
4534
4535
4536
4537
4538
4539
4540
4541
4542
4543
4544
4545
4546
4547
4548
4549
4550
4551
4552
4553
4554
4555
4556
4557
4558
4559
4560
4561
4562
4563
4564
4565
4566
4567
4568
4569
4570
4571
4572
4573
4574
4575
4576
4577
4578
4579
4580
4581
4582
4583
4584
4585
4586
4587
4588
4589
4590
4591
4592
4593
4594
4595
4596
4597
4598
4599
4600
4601
4602
4603
4604
4605
4606
4607
4608
4609
4610
4611
4612
4613
4614
4615
4616
4617
4618
4619
4620
4621
4622
4623
4624
4625
4626
4627
4628
4629
4630
4631
4632
4633
4634
4635
4636
4637
4638
4639
4640
4641
4642
4643
4644
4645
4646
4647
4648
4649
4650
4651
4652
4653
4654
4655
4656
4657
4658
4659
4660
4661
4662
4663
4664
4665
4666
4667
4668
4669
4670
4671
4672
4673
4674
4675
4676
4677
4678
4679
4680
4681
4682
4683
4684
4685
4686
4687
4688
4689
4690
4691
4692
4693
4694
4695
4696
4697
4698
4699
4700
4701
4702
4703
4704
4705
4706
4707
4708
4709
4710
4711
4712
4713
4714
4715
4716
4717
4718
4719
4720
4721
4722
4723
4724
4725
4726
4727
4728
4729
4730
4731
4732
4733
4734
4735
4736
4737
4738
4739
4740
4741
4742
4743
4744
4745
4746
4747
4748
4749
4750
4751
4752
4753
4754
4755
4756
4757
4758
4759
4760
4761
4762
4763
4764
4765
4766
4767
4768
4769
4770
4771
4772
4773
4774
4775
4776
4777
4778
4779
4780
4781
4782
4783
4784
4785
4786
4787
4788
4789
4790
4791
4792
4793
4794
4795
4796
4797
4798
4799
4800
4801
4802
4803
4804
4805
4806
4807
4808
4809
4810
4811
4812
4813
4814
4815
4816
4817
4818
4819
4820
4821
4822
4823
4824
4825
4826
4827
4828
4829
4830
4831
4832
4833
4834
4835
4836
4837
4838
4839
4840
4841
4842
4843
4844
4845
4846
4847
4848
4849
4850
4851
4852
4853
4854
4855
4856
4857
4858
4859
4860
4861
4862
4863
4864
4865
4866
4867
4868
4869
4870
4871
4872
4873
4874
4875
4876
4877
4878
4879
4880
4881
4882
4883
4884
4885
4886
4887
4888
4889
4890
4891
4892
4893
4894
4895
4896
4897
4898
4899
4900
4901
4902
4903
4904
4905
4906
4907
4908
4909
4910
4911
4912
4913
4914
4915
4916
4917
4918
4919
4920
4921
4922
4923
4924
4925
4926
4927
4928
4929
4930
4931
4932
4933
4934
4935
4936
4937
4938
4939
4940
4941
4942
4943
4944
4945
4946
4947
4948
4949
4950
4951
4952
4953
4954
4955
4956
4957
4958
4959
4960
4961
4962
4963
4964
4965
4966
4967
4968
4969
4970
4971
4972
4973
4974
4975
4976
4977
4978
4979
4980
4981
4982
4983
4984
4985
4986
4987
4988
4989
4990
4991
4992
4993
4994
4995
4996
4997
4998
4999
5000
5001
5002
5003
5004
5005
5006
5007
5008
5009
5010
5011
5012
5013
5014
5015
5016
5017
5018
5019
5020
5021
5022
5023
5024
5025
5026
5027
5028
5029
5030
5031
5032
5033
5034
5035
5036
5037
5038
5039
5040
5041
5042
5043
5044
5045
5046
5047
5048
5049
5050
5051
5052
5053
5054
5055
5056
5057
5058
5059
5060
5061
5062
5063
5064
5065
5066
5067
5068
5069
5070
5071
5072
5073
5074
5075
5076
5077
5078
5079
5080
5081
5082
5083
5084
5085
5086
5087
5088
5089
5090
5091
5092
5093
5094
5095
5096
5097
5098
5099
5100
5101
5102
5103
5104
5105
5106
5107
5108
5109
5110
5111
5112
5113
5114
5115
5116
5117
5118
5119
5120
5121
5122
5123
5124
5125
5126
5127
5128
5129
5130
5131
5132
5133
5134
5135
5136
5137
5138
5139
5140
5141
5142
5143
5144
5145
5146
5147
5148
5149
5150
5151
5152
5153
5154
5155
5156
5157
5158
5159
5160
5161
5162
5163
5164
5165
5166
5167
5168
5169
5170
5171
5172
5173
5174
5175
5176
5177
5178
5179
5180
5181
5182
5183
5184
5185
5186
5187
5188
5189
5190
5191
5192
5193
5194
5195
5196
5197
5198
5199
5200
5201
5202
5203
5204
5205
5206
5207
5208
5209
5210
5211
5212
5213
5214
5215
5216
5217
5218
5219
5220
5221
5222
5223
5224
5225
5226
5227
5228
5229
5230
5231
5232
5233
5234
5235
5236
5237
5238
5239
5240
5241
5242
5243
5244
5245
5246
5247
5248
5249
5250
5251
5252
5253
5254
5255
5256
5257
5258
5259
5260
5261
5262
5263
5264
5265
5266
5267
5268
5269
5270
5271
5272
5273
5274
5275
5276
5277
5278
5279
5280
5281
5282
5283
5284
5285
5286
5287
5288
5289
5290
5291
5292
5293
5294
5295
5296
5297
5298
5299
5300
5301
5302
5303
5304
5305
5306
5307
5308
5309
5310
5311
5312
5313
5314
5315
5316
5317
5318
5319
5320
5321
5322
5323
5324
5325
5326
5327
5328
5329
5330
5331
5332
5333
5334
5335
5336
5337
5338
5339
5340
5341
%{
//
// cs-parser.jay: The Parser for the C# compiler
//
// Authors: Miguel de Icaza (miguel@gnu.org)
//          Ravi Pratap     (ravi@ximian.com)
//
// Licensed under the terms of the GNU GPL
//
// (C) 2001 Ximian, Inc (http://www.ximian.com)
// (C) 2004 Novell, Inc
//
// TODO:
//   (1) Figure out why error productions dont work.  `type-declaration' is a
//       great spot to put an `error' because you can reproduce it with this input:
//	 "public X { }"
//
// Possible optimization:
//   Run memory profiler with parsing only, and consider dropping 
//   arraylists where not needed.   Some pieces can use linked lists.
//
using System.Text;
using System.IO;
using System;

namespace Mono.CSharp
{
	using System.Collections;

	/// <summary>
	///    The C# Parser
	/// </summary>
	public class CSharpParser {
		NamespaceEntry  current_namespace;
		TypeContainer   current_container;
		TypeContainer	current_class;
	
		IIteratorContainer iterator_container;

		/// <summary>
		///   Current block is used to add statements as we find
		///   them.  
		/// </summary>
		Block      current_block, top_current_block;

		Delegate   current_delegate;

		/// <summary>
		///   This is used by the unary_expression code to resolve
		///   a name against a parameter.  
		/// </summary>
		Parameters current_local_parameters;

		/// <summary>
		///   Using during property parsing to describe the implicit
		///   value parameter that is passed to the "set" and "get"accesor
		///   methods (properties and indexers).
		/// </summary>
		Expression implicit_value_parameter_type;
		Parameters indexer_parameters;

		/// <summary>
		///   Hack to help create non-typed array initializer
		/// </summary>
		public static Expression current_array_type;

		/// <summary>
		///   Used to determine if we are parsing the get/set pair
		///   of an indexer or a property
		/// </summmary>
		bool  parsing_indexer;

		///
		/// An out-of-band stack.
		///
		Stack oob_stack;

		///
		/// Switch stack.
		///
		Stack switch_stack;

		static public int yacc_verbose_flag;

		// Name of the file we are parsing
		public string name;

		///
		/// The current file.
		///
		SourceFile file;

		///
		/// Temporary Xml documentation cache.
		/// For enum types, we need one more temporary store.
		///
		string tmpComment;
		string enumTypeComment;
	       		
		/// Current attribute target
		string current_attr_target;
		
		/// assembly and module attribute definitions are enabled
		bool global_attrs_enabled = true;
		bool has_get, has_set;

%}

%token EOF
%token NONE   /* This token is never returned by our lexer */
%token ERROR		// This is used not by the parser, but by the tokenizer.
			// do not remove.

/*
 *These are the C# keywords
 */
%token FIRST_KEYWORD
%token ABSTRACT	
%token AS
%token ADD
%token ASSEMBLY
%token BASE	
%token BOOL	
%token BREAK	
%token BYTE	
%token CASE	
%token CATCH	
%token CHAR	
%token CHECKED	
%token CLASS	
%token CONST	
%token CONTINUE	
%token DECIMAL	
%token DEFAULT	
%token DELEGATE	
%token DO	
%token DOUBLE	
%token ELSE	
%token ENUM	
%token EVENT	
%token EXPLICIT	
%token EXTERN	
%token FALSE	
%token FINALLY	
%token FIXED	
%token FLOAT	
%token FOR	
%token FOREACH	
%token GOTO	
%token IF	
%token IMPLICIT	
%token IN	
%token INT	
%token INTERFACE
%token INTERNAL	
%token IS	
%token LOCK	
%token LONG	
%token NAMESPACE
%token NEW	
%token NULL	
%token OBJECT	
%token OPERATOR	
%token OUT	
%token OVERRIDE	
%token PARAMS	
%token PRIVATE	
%token PROTECTED
%token PUBLIC	
%token READONLY	
%token REF	
%token RETURN	
%token REMOVE
%token SBYTE	
%token SEALED	
%token SHORT	
%token SIZEOF	
%token STACKALLOC
%token STATIC	
%token STRING	
%token STRUCT	
%token SWITCH	
%token THIS	
%token THROW	
%token TRUE	
%token TRY	
%token TYPEOF	
%token UINT	
%token ULONG	
%token UNCHECKED
%token UNSAFE	
%token USHORT	
%token USING	
%token VIRTUAL	
%token VOID	
%token VOLATILE
%token WHERE
%token WHILE	
%token ARGLIST
%token PARTIAL

/* C# keywords which are not really keywords */
%token GET           "get"
%token SET           "set"

%left LAST_KEYWORD

/* C# single character operators/punctuation. */
%token OPEN_BRACE    "{"
%token CLOSE_BRACE   "}"
%token OPEN_BRACKET  "["
%token CLOSE_BRACKET "]"
%token OPEN_PARENS   "("
%token CLOSE_PARENS  ")"
%token DOT           "."
%token COMMA         ","
%token COLON         ":"
%token SEMICOLON     ";"
%token TILDE         "~"

%token PLUS           "+"
%token MINUS          "-"
%token BANG           "!"
%token ASSIGN         "="
%token OP_LT          "<"
%token OP_GENERICS_LT "<"
%token OP_GT          ">"
%token OP_GENERICS_GT ">"
%token BITWISE_AND    "&"
%token BITWISE_OR     "|"
%token STAR           "*"
%token PERCENT        "%"
%token DIV            "/"
%token CARRET         "^"
%token INTERR         "?"

/* C# multi-character operators. */
%token DOUBLE_COLON	      "::"
%token OP_INC                 "++"
%token OP_DEC                 "--"
%token OP_SHIFT_LEFT          "<<"
%token OP_SHIFT_RIGHT         ">>"
%token OP_LE                  "<="
%token OP_GE                  ">="
%token OP_EQ                  "=="
%token OP_NE                  "!="
%token OP_AND                 "&&"
%token OP_OR                  "||"
%token OP_MULT_ASSIGN         "*="
%token OP_DIV_ASSIGN          "/="
%token OP_MOD_ASSIGN          "%="
%token OP_ADD_ASSIGN          "+="
%token OP_SUB_ASSIGN          "-="
%token OP_SHIFT_LEFT_ASSIGN   "<<="
%token OP_SHIFT_RIGHT_ASSIGN  ">>="
%token OP_AND_ASSIGN          "&="
%token OP_XOR_ASSIGN          "^="
%token OP_OR_ASSIGN           "|="
%token OP_PTR                 "->"

/* Numbers */
%token LITERAL_INTEGER           "int literal"
%token LITERAL_FLOAT             "float literal"
%token LITERAL_DOUBLE            "double literal"
%token LITERAL_DECIMAL           "decimal literal"
%token LITERAL_CHARACTER         "character literal"
%token LITERAL_STRING            "string literal"

%token IDENTIFIER
%token CLOSE_PARENS_CAST
%token CLOSE_PARENS_NO_CAST
%token CLOSE_PARENS_OPEN_PARENS
%token CLOSE_PARENS_MINUS
%token DEFAULT_OPEN_PARENS
%token GENERIC_DIMENSION

/* Add precedence rules to solve dangling else s/r conflict */
%nonassoc LOWPREC
%nonassoc IF
%nonassoc ELSE
%right ASSIGN
%left OP_OR
%left OP_AND
%left BITWISE_OR
%left BITWISE_AND
%left OP_SHIFT_LEFT OP_SHIFT_RIGHT
%left PLUS MINUS
%left STAR DIV PERCENT
%right BANG CARRET UMINUS
%nonassoc OP_INC OP_DEC
%left OPEN_PARENS
%left OPEN_BRACKET OPEN_BRACE
%left DOT
%nonassoc HIGHPREC

%start compilation_unit
%%

compilation_unit
        : outer_declarations opt_EOF
        | outer_declarations global_attributes opt_EOF
        | global_attributes opt_EOF
	| opt_EOF /* allow empty files */
        ;
	
opt_EOF
	: /* empty */
	  {
		Lexer.check_incorrect_doc_comment ();
	  }
	| EOF
	  {
		Lexer.check_incorrect_doc_comment ();
	  }
	;

outer_declarations
        : outer_declaration
        | outer_declarations outer_declaration
        ;
 
outer_declaration
	: extern_alias_directive
        | using_directive 
        | namespace_member_declaration
        ;

extern_alias_directives
	: extern_alias_directive
	| extern_alias_directives extern_alias_directive;

extern_alias_directive
	: EXTERN IDENTIFIER IDENTIFIER SEMICOLON
	  {
		LocatedToken lt = (LocatedToken) $2;
		string s = lt.Value;
		if (s != "alias"){
			Report.Error (1003, lt.Location, "'alias' expected");
		} else if (RootContext.Version == LanguageVersion.ISO_1) {
			Report.FeatureIsNotStandardized (lt.Location, "external alias");
		} else {
			lt = (LocatedToken) $3; 
			current_namespace.UsingExternalAlias (lt.Value, lt.Location);
		}
	  }
	;
 
using_directives
	: using_directive 
	| using_directives using_directive
	;

using_directive
	: using_alias_directive
	  {
		if (RootContext.Documentation != null)
			Lexer.doc_state = XmlCommentState.Allowed;
	  }
	| using_namespace_directive
	  {
		if (RootContext.Documentation != null)
			Lexer.doc_state = XmlCommentState.Allowed;
	  }
	;

using_alias_directive
	: USING IDENTIFIER ASSIGN 
	  namespace_or_type_name SEMICOLON
	  {
		LocatedToken lt = (LocatedToken) $2;
		current_namespace.UsingAlias (lt.Value, (MemberName) $4, (Location) $1);
	  }
	| USING error {
		CheckIdentifierToken (yyToken, GetLocation ($2));
	  }
	;

using_namespace_directive
	: USING namespace_name SEMICOLON 
	  {
		current_namespace.Using ((MemberName) $2, (Location) $1);
          }
	;

//
// Strictly speaking, namespaces don't have attributes but
// we parse global attributes along with namespace declarations and then
// detach them
// 
namespace_declaration
	: opt_attributes NAMESPACE namespace_or_type_name
	  {
		MemberName name = (MemberName) $3;

		if ($1 != null) {
			Report.Error(1671, name.Location, "A namespace declaration cannot have modifiers or attributes");
		}

		if (name.TypeArguments != null)
			syntax_error (lexer.Location, "namespace name expected");

		current_namespace = new NamespaceEntry (
			current_namespace, file, name.GetName (), name.Location);
	  } 
	  namespace_body opt_semicolon
	  { 
		current_namespace = current_namespace.Parent;
	  }
	;

opt_semicolon
	: /* empty */
	| SEMICOLON
	;

opt_comma
	: /* empty */
	| COMMA
	;

namespace_name
	: namespace_or_type_name {
		MemberName name = (MemberName) $1;

		if (name.TypeArguments != null)
			syntax_error (lexer.Location, "namespace name expected");

		$$ = name;
	  }
	;

namespace_body
	: OPEN_BRACE
	  {
		if (RootContext.Documentation != null)
			Lexer.doc_state = XmlCommentState.Allowed;
	  }
	  opt_extern_alias_directives
	  opt_using_directives
	  opt_namespace_member_declarations
	  CLOSE_BRACE
	;

opt_using_directives
	: /* empty */
	| using_directives
	;

opt_extern_alias_directives
	: /* empty */
	| extern_alias_directives
	;

opt_namespace_member_declarations
	: /* empty */
	| namespace_member_declarations
	;

namespace_member_declarations
	: namespace_member_declaration
	| namespace_member_declarations namespace_member_declaration
	;

namespace_member_declaration
	: type_declaration
	  {
		if ($1 != null) {
			DeclSpace ds = (DeclSpace)$1;

			if ((ds.ModFlags & (Modifiers.PRIVATE|Modifiers.PROTECTED)) != 0){
				Report.Error (1527, ds.Location, 
				"Namespace elements cannot be explicitly declared as private, protected or protected internal");
			}
		}
		current_namespace.DeclarationFound = true;
	  }
	| namespace_declaration {
		current_namespace.DeclarationFound = true;
	  }

	| field_declaration {
		Report.Error (116, ((MemberCore) $1).Location, "A namespace can only contain types and namespace declarations");
	  }
	| method_declaration {
		Report.Error (116, ((MemberCore) $1).Location, "A namespace can only contain types and namespace declarations");
	  }
	;

type_declaration
	: class_declaration		
	| struct_declaration		
	| interface_declaration		
	| enum_declaration		
	| delegate_declaration
//
// Enable this when we have handled all errors, because this acts as a generic fallback
//
//	| error {
//		Console.WriteLine ("Token=" + yyToken);
//		Report.Error (1518, GetLocation ($1), "Expected class, struct, interface, enum or delegate");
//	  }
	;

//
// Attributes 17.2
//

global_attributes
	: attribute_sections
{
	if ($1 != null)
		CodeGen.Assembly.AddAttributes (((Attributes)$1).Attrs);

	$$ = $1;
}

opt_attributes
	: /* empty */ 
	  {
		global_attrs_enabled = false;
		$$ = null;
      }
	| attribute_sections
	  { 
		global_attrs_enabled = false;
		$$ = $1;
	  }
    ;
 

attribute_sections
	: attribute_section
          {
		ArrayList sect = (ArrayList) $1;

		if (global_attrs_enabled) {
			if (current_attr_target == "module") {
				CodeGen.Module.AddAttributes (sect);
				$$ = null;
			} else if (current_attr_target != null && current_attr_target.Length > 0) {
				CodeGen.Assembly.AddAttributes (sect);
				$$ = null;
			} else {
				$$ = new Attributes (sect);
			}
			if ($$ == null) {
				if (RootContext.Documentation != null) {
					Lexer.check_incorrect_doc_comment ();
					Lexer.doc_state =
						XmlCommentState.Allowed;
				}
			}
		} else {
			$$ = new Attributes (sect);
		}		
		current_attr_target = null;
      }
	| attribute_sections attribute_section
	  {
		Attributes attrs = $1 as Attributes;
		ArrayList sect = (ArrayList) $2;

		if (global_attrs_enabled) {
			if (current_attr_target == "module") {
				CodeGen.Module.AddAttributes (sect);
				$$ = null;
			} else if (current_attr_target == "assembly") {
				CodeGen.Assembly.AddAttributes (sect);
				$$ = null;
			} else {
				if (attrs == null)
					attrs = new Attributes (sect);
				else
					attrs.AddAttributes (sect);			
			}
		} else {
			if (attrs == null)
				attrs = new Attributes (sect);
			else
				attrs.AddAttributes (sect);
		}		
		$$ = attrs;
		current_attr_target = null;
	  }
	;

attribute_section
	: OPEN_BRACKET attribute_target_specifier attribute_list opt_comma CLOSE_BRACKET
	  {
		$$ = $3;
 	  }
        | OPEN_BRACKET attribute_list opt_comma CLOSE_BRACKET
	  {
		$$ = $2;
	  }
	;
 
attribute_target_specifier
	: attribute_target COLON
	  {
		current_attr_target = (string)$1;
		$$ = $1;
	  }
	;

attribute_target
	: IDENTIFIER
	  {
		LocatedToken lt = (LocatedToken) $1;
		CheckAttributeTarget (lt.Value, lt.Location);
		$$ = lt.Value; // Location won't be required anymore.
	  }
        | EVENT  { $$ = "event"; }	  
        | RETURN { $$ = "return"; }
	;

attribute_list
	: attribute
	  {
		ArrayList attrs = new ArrayList (4);
		attrs.Add ($1);

		$$ = attrs;
	       
	  }
	| attribute_list COMMA attribute
	  {
		ArrayList attrs = (ArrayList) $1;
		attrs.Add ($3);

		$$ = attrs;
	  }
	;

attribute
	: attribute_name opt_attribute_arguments
	  {
		MemberName mname = (MemberName) $1;
		if (mname.IsGeneric) {
			Report.Error (404, lexer.Location,
				      "'<' unexpected: attributes cannot be generic");
		}

		ArrayList arguments = (ArrayList) $2;
		MemberName left = mname.Left;
		string identifier = mname.Name;

		Expression left_expr = left == null ? null : left.GetTypeExpression ();

		if (current_attr_target == "assembly" || current_attr_target == "module")
			// FIXME: supply "nameEscaped" parameter here.
			$$ = new GlobalAttribute (current_namespace, current_attr_target,
						  left_expr, identifier, arguments, mname.Location, lexer.IsEscapedIdentifier (mname.Location));
		else
			$$ = new Attribute (current_attr_target, left_expr, identifier, arguments, mname.Location, lexer.IsEscapedIdentifier (mname.Location));
	  }
	;

attribute_name
	: namespace_or_type_name  { /* reserved attribute name or identifier: 17.4 */ }
	;

opt_attribute_arguments
	: /* empty */   { $$ = null; }
	| OPEN_PARENS attribute_arguments CLOSE_PARENS
	  {
		$$ = $2;
	  }
	;


attribute_arguments
	: opt_positional_argument_list
	  {
		if ($1 == null)
			$$ = null;
		else {
			ArrayList args = new ArrayList (4);
			args.Add ($1);
		
			$$ = args;
		}
	  }
        | positional_argument_list COMMA named_argument_list
	  {
		ArrayList args = new ArrayList (4);
		args.Add ($1);
		args.Add ($3);

		$$ = args;
	  }
        | named_argument_list
	  {
		ArrayList args = new ArrayList (4);
		args.Add (null);
		args.Add ($1);
		
		$$ = args;
	  }
        ;


opt_positional_argument_list
	: /* empty */ 		{ $$ = null; } 
	| positional_argument_list
	;

positional_argument_list
	: expression
	  {
		ArrayList args = new ArrayList (4);
		args.Add (new Argument ((Expression) $1, Argument.AType.Expression));

		$$ = args;
	  }
        | positional_argument_list COMMA expression
	 {
		ArrayList args = (ArrayList) $1;
		args.Add (new Argument ((Expression) $3, Argument.AType.Expression));

		$$ = args;
	 }
        ;

named_argument_list
	: named_argument
	  {
		ArrayList args = new ArrayList (4);
		args.Add ($1);

		$$ = args;
	  }
        | named_argument_list COMMA named_argument
	  {	  
		ArrayList args = (ArrayList) $1;
		args.Add ($3);

		$$ = args;
	  }
	  | named_argument_list COMMA expression
	    {
		  Report.Error (1016, ((Expression) $3).Location, "Named attribute argument expected");
		  $$ = null;
		}
        ;

named_argument
	: IDENTIFIER ASSIGN expression
	  {
		// FIXME: keep location
		$$ = new DictionaryEntry (
			((LocatedToken) $1).Value, 
			new Argument ((Expression) $3, Argument.AType.Expression));
	  }
	;

		  
class_body
	:  OPEN_BRACE opt_class_member_declarations CLOSE_BRACE
	;

opt_class_member_declarations
	: /* empty */
	| class_member_declarations
	;

class_member_declarations
	: class_member_declaration
	| class_member_declarations 
	  class_member_declaration
	;

class_member_declaration
	: constant_declaration			// done
	| field_declaration			// done
	| method_declaration			// done
	| property_declaration			// done
	| event_declaration			// done
	| indexer_declaration			// done
	| operator_declaration			// done
	| constructor_declaration		// done
	| destructor_declaration		// done
	| type_declaration
	;

struct_declaration
	: opt_attributes
	  opt_modifiers
	  opt_partial
	  STRUCT
	  {
		lexer.ConstraintsParsing = true;
	  }
	  member_name
	  { 
		MemberName name = MakeName ((MemberName) $6);
		if ($3 != null) {
			ClassPart part = PartialContainer.CreatePart (
				current_namespace, current_class, name, (int) $2,
				(Attributes) $1, Kind.Struct, (Location) $3);

			current_container = part.PartialContainer;
			current_class = part;
		} else {
			current_class = new Struct (
				current_namespace, current_class, name, (int) $2,
				(Attributes) $1);

			current_container.AddClassOrStruct (current_class);
			current_container = current_class;
			RootContext.Tree.RecordDecl (current_namespace.NS, name, current_class);
		}
	  }
	  opt_class_base
	  opt_type_parameter_constraints_clauses
	  {
		lexer.ConstraintsParsing = false;

		if ($8 != null)
			current_class.Bases = (ArrayList) $8;

		current_class.SetParameterInfo ((ArrayList) $9);

		if (RootContext.Documentation != null)
			current_class.DocComment = Lexer.consume_doc_comment ();
	  }
	  struct_body
	  {
		if (RootContext.Documentation != null)
			Lexer.doc_state = XmlCommentState.Allowed;
	  }
	  opt_semicolon
	  {
		$$ = pop_current_class ();
	  }
	| opt_attributes opt_modifiers opt_partial STRUCT error {
		CheckIdentifierToken (yyToken, GetLocation ($5));
	  }
	;

struct_body
	: OPEN_BRACE
	  {
		if (RootContext.Documentation != null)
			Lexer.doc_state = XmlCommentState.Allowed;
	  }
	  opt_struct_member_declarations CLOSE_BRACE
	;

opt_struct_member_declarations
	: /* empty */
	| struct_member_declarations
	;

struct_member_declarations
	: struct_member_declaration
	| struct_member_declarations struct_member_declaration
	;

struct_member_declaration
	: constant_declaration
	| field_declaration
	| method_declaration
	| property_declaration
	| event_declaration
	| indexer_declaration
	| operator_declaration
	| constructor_declaration
	| type_declaration

	/*
	 * This is only included so we can flag error 575: 
	 * destructors only allowed on class types
	 */
	| destructor_declaration 
	;

constant_declaration
	: opt_attributes 
	  opt_modifiers
	  CONST
	  type
	  constant_declarators
	  SEMICOLON
	  {
		int modflags = (int) $2;
		foreach (VariableDeclaration constant in (ArrayList) $5){
			Location l = constant.Location;
			if ((modflags & Modifiers.STATIC) != 0) {
				Report.Error (504, l, "The constant `{0}' cannot be marked static", current_container.GetSignatureForError () + '.' + (string) constant.identifier);
				continue;
			}

			Const c = new Const (
				current_class, (Expression) $4, (string) constant.identifier, 
				(Expression) constant.expression_or_array_initializer, modflags, 
				(Attributes) $1, l);

			if (RootContext.Documentation != null) {
				c.DocComment = Lexer.consume_doc_comment ();
				Lexer.doc_state = XmlCommentState.Allowed;
			}
			current_container.AddConstant (c);
		}
	  }
	;

constant_declarators
	: constant_declarator 
	  {
		ArrayList constants = new ArrayList (4);
		if ($1 != null)
			constants.Add ($1);
		$$ = constants;
	  }
	| constant_declarators COMMA constant_declarator
	  {
		if ($3 != null) {
			ArrayList constants = (ArrayList) $1;
			constants.Add ($3);
		}
	  }
	;

constant_declarator
	: IDENTIFIER ASSIGN constant_expression
	  {
		$$ = new VariableDeclaration ((LocatedToken) $1, $3);
	  }
	| IDENTIFIER
	  {
		// A const field requires a value to be provided
		Report.Error (145, ((LocatedToken) $1).Location, "A const field requires a value to be provided");
		$$ = null;
	  }
	;

field_declaration
	: opt_attributes
	  opt_modifiers
	  type 
	  variable_declarators
	  SEMICOLON
	  { 
		Expression type = (Expression) $3;
		int mod = (int) $2;

		current_array_type = null;

		foreach (VariableDeclaration var in (ArrayList) $4){
			Field field = new Field (current_class, type, mod, var.identifier, 
						 (Attributes) $1, var.Location);

			field.Initializer = var.expression_or_array_initializer;

			if (RootContext.Documentation != null) {
				field.DocComment = Lexer.consume_doc_comment ();
				Lexer.doc_state = XmlCommentState.Allowed;
			}
			current_container.AddField (field);
			$$ = field; // FIXME: might be better if it points to the top item
		}
	  }
	| opt_attributes
	  opt_modifiers
	  FIXED
	  type 
	  fixed_variable_declarators
	  SEMICOLON
	  { 
			Expression type = (Expression) $4;
			int mod = (int) $2;

			current_array_type = null;

			foreach (VariableDeclaration var in (ArrayList) $5) {
				FixedField field = new FixedField (current_class, type, mod, var.identifier,
					(Expression)var.expression_or_array_initializer, (Attributes) $1, var.Location);

				if (RootContext.Documentation != null) {
					field.DocComment = Lexer.consume_doc_comment ();
					Lexer.doc_state = XmlCommentState.Allowed;
				}
				current_container.AddField (field);
				$$ = field; // FIXME: might be better if it points to the top item
			}
	  }
	| opt_attributes
	  opt_modifiers
	  VOID  
	  variable_declarators
	  SEMICOLON {
		current_array_type = null;
		Report.Error (670, (Location) $3, "Fields cannot have void type");
	  }
	;

fixed_variable_declarators
	: fixed_variable_declarator
	  {
		ArrayList decl = new ArrayList (2);
		decl.Add ($1);
		$$ = decl;
  	  }
	| fixed_variable_declarators COMMA fixed_variable_declarator
	  {
		ArrayList decls = (ArrayList) $1;
		decls.Add ($3);
		$$ = $1;
	  }
	;

fixed_variable_declarator
	: IDENTIFIER OPEN_BRACKET expression CLOSE_BRACKET
	  {
		$$ = new VariableDeclaration ((LocatedToken) $1, $3);
	  }
	| IDENTIFIER OPEN_BRACKET CLOSE_BRACKET
	  {
		Report.Error (443, lexer.Location, "Value or constant expected");
		$$ = new VariableDeclaration ((LocatedToken) $1, null);
	  }
	;

variable_declarators
	: variable_declarator 
	  {
		ArrayList decl = new ArrayList (4);
		if ($1 != null)
			decl.Add ($1);
		$$ = decl;
	  }
	| variable_declarators COMMA variable_declarator
	  {
		ArrayList decls = (ArrayList) $1;
		decls.Add ($3);
		$$ = $1;
	  }
	;

variable_declarator
	: IDENTIFIER ASSIGN variable_initializer
	  {
		$$ = new VariableDeclaration ((LocatedToken) $1, $3);
	  }
	| IDENTIFIER
	  {
		$$ = new VariableDeclaration ((LocatedToken) $1, null);
	  }
	| IDENTIFIER OPEN_BRACKET opt_expression CLOSE_BRACKET
	  {
		Report.Error (650, ((LocatedToken) $1).Location, "Syntax error, bad array declarator. To declare a managed array the rank specifier precedes the variable's identifier. " +
			"To declare a fixed size buffer field, use the fixed keyword before the field type");
		$$ = null;
	  }
	;

variable_initializer
	: expression
	  {
		$$ = $1;
	  }
	| array_initializer
	  {
		$$ = $1;
	  }
	| STACKALLOC type OPEN_BRACKET expression CLOSE_BRACKET
	  {
		$$ = new StackAlloc ((Expression) $2, (Expression) $4, (Location) $1);
	  }
	| STACKALLOC type
	  {
		Report.Error (1575, (Location) $1, "A stackalloc expression requires [] after type");
                $$ = null;
	  }
	;

method_declaration
	: method_header {
		iterator_container = (IIteratorContainer) $1;
		if (RootContext.Documentation != null)
			Lexer.doc_state = XmlCommentState.NotAllowed;
	  }
	  method_body
	  {
		Method method = (Method) $1;
		method.Block = (ToplevelBlock) $3;
		current_container.AddMethod (method);

		current_local_parameters = null;
		iterator_container = null;

		if (RootContext.Documentation != null)
			Lexer.doc_state = XmlCommentState.Allowed;
	  }
	;

opt_error_modifier
	: /* empty */
	| modifiers 
	  {
		int m = (int) $1;
		int i = 1;

		while (m != 0){
			if ((i & m) != 0){
				Report.Error (1585, lexer.Location,
					"Member modifier `{0}' must precede the member type and name",
					Modifiers.Name (i));
			}
			m &= ~i;
			i = i << 1;
		}
	  }
	;

method_header
	: opt_attributes
	  opt_modifiers
	  type namespace_or_type_name
	  OPEN_PARENS opt_formal_parameter_list CLOSE_PARENS 
	  {
		lexer.ConstraintsParsing = true;
	  }
	  opt_type_parameter_constraints_clauses
	  {
		lexer.ConstraintsParsing = false;

		MemberName name = (MemberName) $4;

		if ($9 != null && name.TypeArguments == null)
			Report.Error (80, lexer.Location,
				      "Constraints are not allowed on non-generic declarations");

		Method method;

		GenericMethod generic = null;
		if (name.TypeArguments != null) {
			generic = new GenericMethod (current_namespace, current_class, name,
						     (Expression) $3, (Parameters) $6);

			generic.SetParameterInfo ((ArrayList) $9);
		}

		method = new Method (current_class, generic, (Expression) $3, (int) $2, false,
				     name, (Parameters) $6, (Attributes) $1);

		current_local_parameters = (Parameters) $6;

		if (RootContext.Documentation != null)
			method.DocComment = Lexer.consume_doc_comment ();

		$$ = method;
	  }
	| opt_attributes
	  opt_modifiers
	  VOID namespace_or_type_name
	  OPEN_PARENS opt_formal_parameter_list CLOSE_PARENS 
	  {
		lexer.ConstraintsParsing = true;
	  }
	  opt_type_parameter_constraints_clauses
	  {
		lexer.ConstraintsParsing = false;

		MemberName name = (MemberName) $4;

		if ($9 != null && name.TypeArguments == null)
			Report.Error (80, lexer.Location,
				      "Constraints are not allowed on non-generic declarations");

		Method method;
		GenericMethod generic = null;
		if (name.TypeArguments != null) {
			generic = new GenericMethod (current_namespace, current_class, name,
						     TypeManager.system_void_expr, (Parameters) $6);

			generic.SetParameterInfo ((ArrayList) $9);
		}

		method = new Method (current_class, generic, TypeManager.system_void_expr,
				     (int) $2, false, name, (Parameters) $6, (Attributes) $1);

		current_local_parameters = (Parameters) $6;

		if (RootContext.Documentation != null)
			method.DocComment = Lexer.consume_doc_comment ();

		$$ = method;
	  }
	| opt_attributes
	  opt_modifiers
	  type 
	  modifiers namespace_or_type_name OPEN_PARENS opt_formal_parameter_list CLOSE_PARENS
	  {
		MemberName name = (MemberName) $5;
		Report.Error (1585, name.Location, 
			"Member modifier `{0}' must precede the member type and name", Modifiers.Name ((int) $4));

		Method method = new Method (current_class, null, TypeManager.system_void_expr,
					    0, false, name, (Parameters) $6, (Attributes) $1);

		current_local_parameters = (Parameters) $6;

		if (RootContext.Documentation != null)
			method.DocComment = Lexer.consume_doc_comment ();

		$$ = null;
	  }
	;

method_body
	: block
	| SEMICOLON		{ $$ = null; }
	;

opt_formal_parameter_list
	: /* empty */			{ $$ = Parameters.EmptyReadOnlyParameters; }
	| formal_parameter_list
	;

formal_parameter_list
	: fixed_parameters		
	  { 
		ArrayList pars_list = (ArrayList) $1;

		Parameter [] pars = new Parameter [pars_list.Count];
		pars_list.CopyTo (pars);

	  	$$ = new Parameters (pars); 
	  } 
	| fixed_parameters COMMA parameter_array
	  {
		ArrayList pars_list = (ArrayList) $1;
		pars_list.Add ($3);

		Parameter [] pars = new Parameter [pars_list.Count];
		pars_list.CopyTo (pars);

		$$ = new Parameters (pars); 
	  }
	| fixed_parameters COMMA ARGLIST
	  {
		ArrayList pars_list = (ArrayList) $1;
		//pars_list.Add (new ArglistParameter (GetLocation ($3)));

		Parameter [] pars = new Parameter [pars_list.Count];
		pars_list.CopyTo (pars);

		$$ = new Parameters (pars, true);
	  }
	| parameter_array COMMA error
	  {
		if ($1 != null)
			Report.Error (231, ((Parameter) $1).Location, "A params parameter must be the last parameter in a formal parameter list");
		$$ = null;
	  }
	| ARGLIST COMMA error
	  {
		Report.Error (257, (Location) $1, "An __arglist parameter must be the last parameter in a formal parameter list");
		$$ = null;
	  }
	| parameter_array 
	  {
		$$ = new Parameters (new Parameter[] { (Parameter) $1 } );
	  }
	| ARGLIST
	  {
		$$ = new Parameters (new Parameter[0], true);
	  }
	;

fixed_parameters
	: fixed_parameter	
	  {
		ArrayList pars = new ArrayList (4);

		pars.Add ($1);
		$$ = pars;
	  }
	| fixed_parameters COMMA fixed_parameter
	  {
		ArrayList pars = (ArrayList) $1;

		pars.Add ($3);
		$$ = $1;
	  }
	;

fixed_parameter
	: opt_attributes
	  opt_parameter_modifier
	  type
	  IDENTIFIER
	  {
		LocatedToken lt = (LocatedToken) $4;
		$$ = new Parameter ((Expression) $3, lt.Value, (Parameter.Modifier) $2, (Attributes) $1, lt.Location);
	  }
	| opt_attributes
	  opt_parameter_modifier
	  type
	  IDENTIFIER OPEN_BRACKET CLOSE_BRACKET
	  {
		LocatedToken lt = (LocatedToken) $4;
		Report.Error (1552, lt.Location, "Array type specifier, [], must appear before parameter name");
		$$ = null;
	  }
	| opt_attributes
	  opt_parameter_modifier
	  type
	  {
		Report.Error (1001, GetLocation ($3), "Identifier expected");
		$$ = null;
	  }
	| opt_attributes
	  opt_parameter_modifier
	  type
	  error {
		CheckIdentifierToken (yyToken, GetLocation ($4));
		$$ = null;
	  }
	| opt_attributes
	  opt_parameter_modifier
	  type
	  IDENTIFIER
	  ASSIGN
	  constant_expression
	   {
		LocatedToken lt = (LocatedToken) $4;
		Report.Error (241, lt.Location, "Default parameter specifiers are not permitted");
		 $$ = null;
	   }
	;

opt_parameter_modifier
	: /* empty */		{ $$ = Parameter.Modifier.NONE; }
	| parameter_modifier
	;

parameter_modifier
	: REF			{ $$ = Parameter.Modifier.REF; }
	| OUT			{ $$ = Parameter.Modifier.OUT; }
	;

parameter_array
	: opt_attributes PARAMS type IDENTIFIER
	  { 
		LocatedToken lt = (LocatedToken) $4;
		$$ = new ParamsParameter ((Expression) $3, lt.Value, (Attributes) $1, lt.Location);
		note ("type must be a single-dimension array type"); 
	  }
	| opt_attributes PARAMS parameter_modifier type IDENTIFIER 
	  {
		Report.Error (1611, (Location) $2, "The params parameter cannot be declared as ref or out");
                $$ = null;
	  }
	| opt_attributes PARAMS type error {
		CheckIdentifierToken (yyToken, GetLocation ($4));
		$$ = null;
	  }
	;

property_declaration
	: opt_attributes
	  opt_modifiers
	  type
	  namespace_or_type_name
	  {
		if (RootContext.Documentation != null)
			tmpComment = Lexer.consume_doc_comment ();
	  }
	  OPEN_BRACE 
	  {
		implicit_value_parameter_type = (Expression) $3;

		lexer.PropertyParsing = true;
	  }
	  accessor_declarations 
	  {
		lexer.PropertyParsing = false;
		has_get = has_set = false;
	  }
	  CLOSE_BRACE
	  { 
		if ($8 == null)
			break;

		Property prop;
		Pair pair = (Pair) $8;
		Accessor get_block = (Accessor) pair.First;
		Accessor set_block = (Accessor) pair.Second;

		MemberName name = (MemberName) $4;

		if (name.TypeArguments != null)
			syntax_error (lexer.Location, "a property can't have type arguments");

		prop = new Property (current_class, (Expression) $3, (int) $2, false,
				     name, (Attributes) $1, get_block, set_block);
		
		current_container.AddProperty (prop);
		implicit_value_parameter_type = null;

		if (RootContext.Documentation != null)
			prop.DocComment = ConsumeStoredComment ();

	  }
	;

accessor_declarations
	: get_accessor_declaration
	 {
		$$ = new Pair ($1, null);
	 }
	| get_accessor_declaration accessor_declarations
	 { 
		Pair pair = (Pair) $2;
		pair.First = $1;
		$$ = pair;
	 }
	| set_accessor_declaration
	 {
		$$ = new Pair (null, $1);
	 }
	| set_accessor_declaration accessor_declarations
	 { 
		Pair pair = (Pair) $2;
		pair.Second = $1;
		$$ = pair;
	 }
	| error
	  {
		Report.Error (1014, GetLocation ($1), "A get or set accessor expected");
		$$ = null;
	  }
	;

get_accessor_declaration
	: opt_attributes opt_modifiers GET
	  {
		// If this is not the case, then current_local_parameters has already
		// been set in indexer_declaration
		if (parsing_indexer == false)
			current_local_parameters = null;
		else 
			current_local_parameters = indexer_parameters;
		lexer.PropertyParsing = false;

		iterator_container = SimpleIteratorContainer.GetSimple ();
	  }
          accessor_body
	  {
		if (has_get) {
			Report.Error (1007, (Location) $3, "Property accessor already defined");
			break;
		}
		Accessor accessor = new Accessor ((ToplevelBlock) $5, (int) $2, (Attributes) $1, (Location) $3);
		has_get = true;
		current_local_parameters = null;
		lexer.PropertyParsing = true;

		if (SimpleIteratorContainer.Simple.Yields)
			accessor.SetYields ();

		iterator_container = null;

		if (RootContext.Documentation != null)
			if (Lexer.doc_state == XmlCommentState.Error)
				Lexer.doc_state = XmlCommentState.NotAllowed;

		$$ = accessor;
	  }
	;

set_accessor_declaration
	: opt_attributes opt_modifiers SET 
	  {
		Parameter [] args;
		Parameter implicit_value_parameter = new Parameter (
			implicit_value_parameter_type, "value", 
			Parameter.Modifier.NONE, null, (Location) $3);

		if (parsing_indexer == false) {
			args  = new Parameter [1];
			args [0] = implicit_value_parameter;
			current_local_parameters = new Parameters (args);
		} else {
			Parameter [] fpars = indexer_parameters.FixedParameters;

			if (fpars != null){
				int count = fpars.Length;

				args = new Parameter [count + 1];
				fpars.CopyTo (args, 0);
				args [count] = implicit_value_parameter;
			} else 
				args = null;
			current_local_parameters = new Parameters (
				args);
		}
		
		lexer.PropertyParsing = false;

		iterator_container = SimpleIteratorContainer.GetSimple ();
	  }
	  accessor_body
	  {
		if (has_set) {
			Report.Error (1007, ((LocatedToken) $3).Location, "Property accessor already defined");
			break;
		}
		Accessor accessor = new Accessor ((ToplevelBlock) $5, (int) $2, (Attributes) $1, (Location) $3);
		has_set = true;
		current_local_parameters = null;
		lexer.PropertyParsing = true;

		if (SimpleIteratorContainer.Simple.Yields)
			accessor.SetYields ();

		iterator_container = null;

		if (RootContext.Documentation != null
			&& Lexer.doc_state == XmlCommentState.Error)
			Lexer.doc_state = XmlCommentState.NotAllowed;

		$$ = accessor;
	  }
	;

accessor_body
	: block 
	| SEMICOLON		{ $$ = null; }
	;

interface_declaration
	: opt_attributes
	  opt_modifiers
	  opt_partial
	  INTERFACE
	  {
		lexer.ConstraintsParsing = true;
	  }
	  member_name
	  {
		MemberName name = MakeName ((MemberName) $6);

		if ($3 != null) {
			ClassPart part = PartialContainer.CreatePart (
				current_namespace, current_class, name, (int) $2,
				(Attributes) $1, Kind.Interface, (Location) $3);

			current_container = part.PartialContainer;
			current_class = part;
		} else {
			current_class = new Interface (
				current_namespace, current_class, name, (int) $2,
				(Attributes) $1);

			current_container.AddInterface (current_class);
			current_container = current_class;
			RootContext.Tree.RecordDecl (current_namespace.NS, name, current_class);
		}
	  }
	  opt_class_base
	  opt_type_parameter_constraints_clauses
	  {
		lexer.ConstraintsParsing = false;

		if ($8 != null)
			current_class.Bases = (ArrayList) $8;

		current_class.SetParameterInfo ((ArrayList) $9);

		if (RootContext.Documentation != null) {
			current_class.DocComment = Lexer.consume_doc_comment ();
			Lexer.doc_state = XmlCommentState.Allowed;
		}
	  }
	  interface_body
	  { 
		if (RootContext.Documentation != null)
			Lexer.doc_state = XmlCommentState.Allowed;
	  }
	  opt_semicolon 
	  {
		$$ = pop_current_class ();
	  }
	| opt_attributes opt_modifiers opt_partial INTERFACE error {
		CheckIdentifierToken (yyToken, GetLocation ($5));
	  }
	;

interface_body
	: OPEN_BRACE
	  opt_interface_member_declarations
	  CLOSE_BRACE
	;

opt_interface_member_declarations
	: /* empty */
	| interface_member_declarations
	;

interface_member_declarations
	: interface_member_declaration
	| interface_member_declarations interface_member_declaration
	;

interface_member_declaration
	: interface_method_declaration		
	  { 
		if ($1 == null)
			break;

		Method m = (Method) $1;

		if (m.IsExplicitImpl)
		        Report.Error (541, m.Location, "`{0}': explicit interface declaration can only be declared in a class or struct",
				m.GetSignatureForError ());

		current_container.AddMethod (m);

		if (RootContext.Documentation != null)
			Lexer.doc_state = XmlCommentState.Allowed;
	  }
	| interface_property_declaration	
	  { 
		if ($1 == null)
			break;

		Property p = (Property) $1;

		if (p.IsExplicitImpl)
		        Report.Error (541, p.Location, "`{0}': explicit interface declaration can only be declared in a class or struct",
				p.GetSignatureForError ());

		current_container.AddProperty (p);

		if (RootContext.Documentation != null)
			Lexer.doc_state = XmlCommentState.Allowed;
	  }
	| interface_event_declaration 
          { 
		if ($1 != null){
			Event e = (Event) $1;

			if (e.IsExplicitImpl)
		        Report.Error (541, e.Location, "`{0}': explicit interface declaration can only be declared in a class or struct",
				e.GetSignatureForError ());
			
			current_container.AddEvent (e);
		}

		if (RootContext.Documentation != null)
			Lexer.doc_state = XmlCommentState.Allowed;
	  }
	| interface_indexer_declaration
	  { 
		if ($1 == null)
			break;

		Indexer i = (Indexer) $1;

		if (i.IsExplicitImpl)
		        Report.Error (541, i.Location, "`{0}': explicit interface declaration can only be declared in a class or struct",
				i.GetSignatureForError ());

		current_container.AddIndexer (i);

		if (RootContext.Documentation != null)
			Lexer.doc_state = XmlCommentState.Allowed;
	  }
	| delegate_declaration
	  {
		if ($1 != null) {
			Report.Error (524, GetLocation ($1), "`{0}': Interfaces cannot declare classes, structs, interfaces, delegates, enumerations or constants",
				((MemberCore)$1).GetSignatureForError ());
		}
	  }
	| class_declaration
	  {
		if ($1 != null) {
			Report.Error (524, GetLocation ($1), "`{0}': Interfaces cannot declare classes, structs, interfaces, delegates, enumerations or constants",
				((MemberCore)$1).GetSignatureForError ());
		}
	  }
	| struct_declaration
	  {
		if ($1 != null) {
			Report.Error (524, GetLocation ($1), "`{0}': Interfaces cannot declare classes, structs, interfaces, delegates, enumerations or constants",
				((MemberCore)$1).GetSignatureForError ());
		}
	  }
	| enum_declaration 
	  {
		if ($1 != null) {
			Report.Error (524, GetLocation ($1), "`{0}': Interfaces cannot declare classes, structs, interfaces, delegates, enumerations or constants",
				((MemberCore)$1).GetSignatureForError ());
		}
	  }
	| interface_declaration 
	  {
		if ($1 != null) {
			Report.Error (524, GetLocation ($1), "`{0}': Interfaces cannot declare classes, structs, interfaces, delegates, enumerations or constants",
				((MemberCore)$1).GetSignatureForError ());
		}
	  } 
	| constant_declaration
	  {
		Report.Error (525, GetLocation ($1), "Interfaces cannot contain fields or constants");
	  }
	;

opt_new
	: opt_modifiers 
	  {
		int val = (int) $1;
		val = Modifiers.Check (Modifiers.NEW | Modifiers.UNSAFE, val, 0, GetLocation ($1));
		$$ = val;
	  }
	;

interface_method_declaration_body
	: OPEN_BRACE
	  {
		lexer.ConstraintsParsing = false;
	  }
	  opt_statement_list CLOSE_BRACE
	  {
		Report.Error (531, lexer.Location,
			      "'{0}': interface members cannot have a definition", ((MemberName) $-1).ToString ());
		$$ = null;
	  }
	| SEMICOLON
	;

interface_method_declaration
	: opt_attributes opt_new type namespace_or_type_name
	  OPEN_PARENS opt_formal_parameter_list CLOSE_PARENS
	  {
		lexer.ConstraintsParsing = true;
	  }
	  opt_type_parameter_constraints_clauses
	  {
		// Refer to the name as $-1 in interface_method_declaration_body	  
		$$ = $4;
	  }
	  interface_method_declaration_body
	  {
		lexer.ConstraintsParsing = false;

		MemberName name = (MemberName) $4;

		if ($9 != null && name.TypeArguments == null)
			Report.Error (80, lexer.Location,
				      "Constraints are not allowed on non-generic declarations");

		GenericMethod generic = null;
		if (name.TypeArguments != null) {
			generic = new GenericMethod (current_namespace, current_class, name,
						     (Expression) $3, (Parameters) $6);

			generic.SetParameterInfo ((ArrayList) $9);
		}

		$$ = new Method (current_class, generic, (Expression) $3, (int) $2, true, name,
				 (Parameters) $6, (Attributes) $1);
		if (RootContext.Documentation != null)
			((Method) $$).DocComment = Lexer.consume_doc_comment ();
	  }
	| opt_attributes opt_new VOID namespace_or_type_name
	  OPEN_PARENS opt_formal_parameter_list CLOSE_PARENS
	  {
		lexer.ConstraintsParsing = true;
	  }
	  opt_type_parameter_constraints_clauses
	  {
		$$ = $4;
	  }
	  interface_method_declaration_body
	  {
		lexer.ConstraintsParsing = false;

		MemberName name = (MemberName) $4;

		if ($9 != null && name.TypeArguments == null)
			Report.Error (80, lexer.Location,
				      "Constraints are not allowed on non-generic declarations");

		GenericMethod generic = null;
		if (name.TypeArguments != null) {
			generic = new GenericMethod (current_namespace, current_class, name,
						     TypeManager.system_void_expr, (Parameters) $6);

			generic.SetParameterInfo ((ArrayList) $9);
		}

		$$ = new Method (current_class, generic, TypeManager.system_void_expr, (int) $2,
				 true, name, (Parameters) $6, (Attributes) $1);
		if (RootContext.Documentation != null)
			((Method) $$).DocComment = Lexer.consume_doc_comment ();
	  }
	;

interface_property_declaration
	: opt_attributes
	  opt_new
	  type IDENTIFIER 
	  OPEN_BRACE 
	  { lexer.PropertyParsing = true; }
	  accessor_declarations 
	  {
		has_get = has_set = false; 
		lexer.PropertyParsing = false;
	  }
	  CLOSE_BRACE
	  {
		LocatedToken lt = (LocatedToken) $4;
		MemberName name = new MemberName (lt.Value, lt.Location);

		if ($3 == TypeManager.system_void_expr) {
			Report.Error (547, lt.Location, "`{0}': property or indexer cannot have void type", lt.Value);
			break;
		}

		Property p = null;
		if ($7 == null) {
			p = new Property (current_class, (Expression) $3, (int) $2, true,
				   name, (Attributes) $1,
				   null, null);

			Report.Error (548, p.Location, "`{0}': property or indexer must have at least one accessor", p.GetSignatureForError ());
			break;
		}

		Pair pair = (Pair) $7;
		p = new Property (current_class, (Expression) $3, (int) $2, true,
				   name, (Attributes) $1,
				   (Accessor)pair.First, (Accessor)pair.Second);

		if (pair.First != null && ((Accessor)(pair.First)).Block != null) {
			Report.Error (531, p.Location, "`{0}.get': interface members cannot have a definition", p.GetSignatureForError ());
			$$ = null;
			break;
		}

		if (pair.Second != null && ((Accessor)(pair.Second)).Block != null) {
			Report.Error (531, p.Location, "`{0}.set': interface members cannot have a definition", p.GetSignatureForError ());
			$$ = null;
			break;
		}

		if (RootContext.Documentation != null)
			p.DocComment = Lexer.consume_doc_comment ();

		$$ = p;
	  }
	| opt_attributes
	  opt_new
	  type error {
		CheckIdentifierToken (yyToken, GetLocation ($4));
		$$ = null;
	  }
	;


interface_event_declaration
	: opt_attributes opt_new EVENT type IDENTIFIER SEMICOLON
	  {
		LocatedToken lt = (LocatedToken) $5;
		$$ = new EventField (current_class, (Expression) $4, (int) $2, true,
				     new MemberName (lt.Value, lt.Location),
				     (Attributes) $1);
		if (RootContext.Documentation != null)
			((EventField) $$).DocComment = Lexer.consume_doc_comment ();
	  }
	| opt_attributes opt_new EVENT type error {
		CheckIdentifierToken (yyToken, GetLocation ($5));
		$$ = null;
	  }
	| opt_attributes opt_new EVENT type IDENTIFIER ASSIGN  {
		LocatedToken lt = (LocatedToken) $5;
		Report.Error (68, lt.Location, "`{0}.{1}': event in interface cannot have initializer", current_container.Name, lt.Value);
		$$ = null;
	  }
	| opt_attributes opt_new EVENT type IDENTIFIER OPEN_BRACE
	  {
		lexer.EventParsing = true;
	  }
	  event_accessor_declarations
	  {
		lexer.EventParsing = false;
	  }
	  CLOSE_BRACE {
		Report.Error (69, (Location) $3, "Event in interface cannot have add or remove accessors");
 		$$ = null;
 	  }
	;

interface_indexer_declaration 
	: opt_attributes opt_new type THIS 
	  OPEN_BRACKET formal_parameter_list CLOSE_BRACKET
	  OPEN_BRACE 
	  { lexer.PropertyParsing = true; }
	  accessor_declarations 
	  { 
		has_get = has_set = false;
 		lexer.PropertyParsing = false;
	  }
	  CLOSE_BRACE
	  {
		Indexer i = null;
		if ($10 == null) {
			i = new Indexer (current_class, (Expression) $3,
				  new MemberName (TypeContainer.DefaultIndexerName, (Location) $4),
				  (int) $2, true, (Parameters) $6, (Attributes) $1,
				  null, null);

			Report.Error (548, i.Location, "`{0}': property or indexer must have at least one accessor", i.GetSignatureForError ());
			break;
		}

		Pair pair = (Pair) $10;
		i = new Indexer (current_class, (Expression) $3,
				  new MemberName (TypeContainer.DefaultIndexerName, (Location) $4),
				  (int) $2, true, (Parameters) $6, (Attributes) $1,
				   (Accessor)pair.First, (Accessor)pair.Second);

		if (pair.First != null && ((Accessor)(pair.First)).Block != null) {
			Report.Error (531, i.Location, "`{0}.get': interface members cannot have a definition", i.GetSignatureForError ());
			$$ = null;
			break;
		}

		if (pair.Second != null && ((Accessor)(pair.Second)).Block != null) {
			Report.Error (531, i.Location, "`{0}.set': interface members cannot have a definition", i.GetSignatureForError ());
			$$ = null;
			break;
		}

		if (RootContext.Documentation != null)
			i.DocComment = ConsumeStoredComment ();

		$$ = i;
	  }
	;

operator_declaration
	: opt_attributes opt_modifiers operator_declarator 
	  {
		iterator_container = SimpleIteratorContainer.GetSimple ();
	  }
	  operator_body
	  {
		if ($3 == null)
			break;

		OperatorDeclaration decl = (OperatorDeclaration) $3;
		
		Parameter [] param_list = new Parameter [decl.arg2type != null ? 2 : 1];

		param_list[0] = new Parameter (decl.arg1type, decl.arg1name, Parameter.Modifier.NONE, null, decl.location);
		if (decl.arg2type != null)
			param_list[1] = new Parameter (decl.arg2type, decl.arg2name, Parameter.Modifier.NONE, null, decl.location);

		Operator op = new Operator (
			current_class, decl.optype, decl.ret_type, (int) $2, 
			new Parameters (param_list),
			(ToplevelBlock) $5, (Attributes) $1, decl.location);

		if (RootContext.Documentation != null) {
			op.DocComment = tmpComment;
			Lexer.doc_state = XmlCommentState.Allowed;
		}

		if (SimpleIteratorContainer.Simple.Yields)
			op.SetYields ();

		// Note again, checking is done in semantic analysis
		current_container.AddOperator (op);

		current_local_parameters = null;
		iterator_container = null;
	  }
	;

operator_body 
	: block
	| SEMICOLON { $$ = null; }
	; 
operator_declarator
	: type OPERATOR overloadable_operator 
	  OPEN_PARENS type IDENTIFIER CLOSE_PARENS
	  {
		LocatedToken lt = (LocatedToken) $6;
		Operator.OpType op = (Operator.OpType) $3;
		CheckUnaryOperator (op, lt.Location);

		if (op == Operator.OpType.Addition)
			op = Operator.OpType.UnaryPlus;

		if (op == Operator.OpType.Subtraction)
			op = Operator.OpType.UnaryNegation;

		Parameter [] pars = new Parameter [1];
		Expression type = (Expression) $5;

		pars [0] = new Parameter (type, lt.Value, Parameter.Modifier.NONE, null, lt.Location);

		current_local_parameters = new Parameters (pars);

		if (RootContext.Documentation != null) {
			tmpComment = Lexer.consume_doc_comment ();
			Lexer.doc_state = XmlCommentState.NotAllowed;
		}

		$$ = new OperatorDeclaration (op, (Expression) $1, type, lt.Value,
					      null, null, (Location) $2);
	  }
	| type OPERATOR overloadable_operator
	  OPEN_PARENS 
		type IDENTIFIER COMMA
	  	type IDENTIFIER 
	  CLOSE_PARENS
          {
		LocatedToken ltParam1 = (LocatedToken) $6;
		LocatedToken ltParam2 = (LocatedToken) $9;
		CheckBinaryOperator ((Operator.OpType) $3, (Location) $2);

		Parameter [] pars = new Parameter [2];

		Expression typeL = (Expression) $5;
		Expression typeR = (Expression) $8;

	       pars [0] = new Parameter (typeL, ltParam1.Value, Parameter.Modifier.NONE, null, ltParam1.Location);
	       pars [1] = new Parameter (typeR, ltParam2.Value, Parameter.Modifier.NONE, null, ltParam2.Location);

	       current_local_parameters = new Parameters (pars);

		if (RootContext.Documentation != null) {
			tmpComment = Lexer.consume_doc_comment ();
			Lexer.doc_state = XmlCommentState.NotAllowed;
		}
	       
	       $$ = new OperatorDeclaration ((Operator.OpType) $3, (Expression) $1, 
					     typeL, ltParam1.Value,
					     typeR, ltParam2.Value, (Location) $2);
          }
	| conversion_operator_declarator
	| type OPERATOR overloadable_operator
	  OPEN_PARENS 
		type IDENTIFIER COMMA
	  	type IDENTIFIER COMMA
		type IDENTIFIER
	  CLOSE_PARENS
	  {
		Report.Error (1534, (Location) $2, "Overloaded binary operator `{0}' takes two parameters",
			Operator.GetName ((Operator.OpType) $3));
		$$ = null;
	  }
	| type OPERATOR overloadable_operator 
	  OPEN_PARENS CLOSE_PARENS
	  {
		Report.Error (1535, (Location) $2, "Overloaded unary operator `{0}' takes one parameter",
			Operator.GetName ((Operator.OpType) $3));
		$$ = null;
	  }
	;

overloadable_operator
// Unary operators:
	: BANG   { $$ = Operator.OpType.LogicalNot; }
        | TILDE  { $$ = Operator.OpType.OnesComplement; }  
        | OP_INC { $$ = Operator.OpType.Increment; }
        | OP_DEC { $$ = Operator.OpType.Decrement; }
        | TRUE   { $$ = Operator.OpType.True; }
        | FALSE  { $$ = Operator.OpType.False; }
// Unary and binary:
        | PLUS { $$ = Operator.OpType.Addition; }
        | MINUS { $$ = Operator.OpType.Subtraction; }
// Binary:
        | STAR { $$ = Operator.OpType.Multiply; }
        | DIV {  $$ = Operator.OpType.Division; }
        | PERCENT { $$ = Operator.OpType.Modulus; }
        | BITWISE_AND { $$ = Operator.OpType.BitwiseAnd; }
        | BITWISE_OR { $$ = Operator.OpType.BitwiseOr; }
        | CARRET { $$ = Operator.OpType.ExclusiveOr; }
        | OP_SHIFT_LEFT { $$ = Operator.OpType.LeftShift; }
        | OP_SHIFT_RIGHT { $$ = Operator.OpType.RightShift; }
        | OP_EQ { $$ = Operator.OpType.Equality; }
        | OP_NE { $$ = Operator.OpType.Inequality; }
        | OP_GT { $$ = Operator.OpType.GreaterThan; }
        | OP_LT { $$ = Operator.OpType.LessThan; }
        | OP_GE { $$ = Operator.OpType.GreaterThanOrEqual; }
        | OP_LE { $$ = Operator.OpType.LessThanOrEqual; }
	;

conversion_operator_declarator
	: IMPLICIT OPERATOR type OPEN_PARENS type IDENTIFIER CLOSE_PARENS
	  {
		LocatedToken lt = (LocatedToken) $6;
		Parameter [] pars = new Parameter [1];

		pars [0] = new Parameter ((Expression) $5, lt.Value, Parameter.Modifier.NONE, null, lt.Location);

		current_local_parameters = new Parameters (pars);  
		  
		if (RootContext.Documentation != null) {
			tmpComment = Lexer.consume_doc_comment ();
			Lexer.doc_state = XmlCommentState.NotAllowed;
		}

		$$ = new OperatorDeclaration (Operator.OpType.Implicit, (Expression) $3, (Expression) $5, lt.Value,
					      null, null, (Location) $2);
	  }
	| EXPLICIT OPERATOR type OPEN_PARENS type IDENTIFIER CLOSE_PARENS
	  {
		LocatedToken lt = (LocatedToken) $6;
		Parameter [] pars = new Parameter [1];

		pars [0] = new Parameter ((Expression) $5, lt.Value, Parameter.Modifier.NONE, null, lt.Location);

		current_local_parameters = new Parameters (pars);  
		  
		if (RootContext.Documentation != null) {
			tmpComment = Lexer.consume_doc_comment ();
			Lexer.doc_state = XmlCommentState.NotAllowed;
		}

		$$ = new OperatorDeclaration (Operator.OpType.Explicit, (Expression) $3, (Expression) $5, lt.Value,
					      null, null, (Location) $2);
	  }
	| IMPLICIT error 
	  {
		syntax_error ((Location) $1, "'operator' expected");
	  }
	| EXPLICIT error 
	  {
		syntax_error ((Location) $1, "'operator' expected");
	  }
	;

constructor_declaration
	: opt_attributes
	  opt_modifiers
	  constructor_declarator
	  constructor_body
	  { 
		Constructor c = (Constructor) $3;
		c.Block = (ToplevelBlock) $4;
		c.OptAttributes = (Attributes) $1;
		c.ModFlags = (int) $2;
	
		if (RootContext.Documentation != null)
			c.DocComment = ConsumeStoredComment ();

		if (c.Name == current_container.Basename){
			if ((c.ModFlags & Modifiers.STATIC) != 0){
				if ((c.ModFlags & Modifiers.Accessibility) != 0){
					Report.Error (515, c.Location,
						"`{0}': access modifiers are not allowed on static constructors",
						c.GetSignatureForError ());
				}
	
				c.ModFlags = Modifiers.Check (Constructor.AllowedModifiers, (int) $2, Modifiers.PRIVATE, c.Location);	
	
				if (c.Initializer != null){
					Report.Error (514, c.Location,
						"`{0}': static constructor cannot have an explicit `this' or `base' constructor call",
						c.GetSignatureForError ());
				}
	
				if (!c.Parameters.Empty){
					Report.Error (132, c.Location,
						"`{0}': The static constructor must be parameterless", c.GetSignatureForError ());
				}
			} else {
				c.ModFlags = Modifiers.Check (Constructor.AllowedModifiers, (int) $2, Modifiers.PRIVATE, c.Location);
			}
		} else {
			// We let another layer check the validity of the constructor.
			//Console.WriteLine ("{0} and {1}", c.Name, current_container.Basename);
		}

		current_container.AddConstructor (c);

		current_local_parameters = null;
		if (RootContext.Documentation != null)
			Lexer.doc_state = XmlCommentState.Allowed;
	  }
	;

constructor_declarator
	: IDENTIFIER
	  {
		if (RootContext.Documentation != null) {
			tmpComment = Lexer.consume_doc_comment ();
			Lexer.doc_state = XmlCommentState.Allowed;
		}
	  }
	  OPEN_PARENS opt_formal_parameter_list CLOSE_PARENS
	  {
		current_local_parameters = (Parameters) $4;
	  }
	  opt_constructor_initializer
	  {
		LocatedToken lt = (LocatedToken) $1;
		$$ = new Constructor (current_class, lt.Value, 0, (Parameters) $4,
				      (ConstructorInitializer) $7, lt.Location);
	  }
	;

constructor_body
	: block
	| SEMICOLON 		{ $$ = null; }
	;

opt_constructor_initializer
	: /* empty */			{ $$ = null; }
	| constructor_initializer
	;

constructor_initializer
	: COLON BASE OPEN_PARENS opt_argument_list CLOSE_PARENS
	  {
		$$ = new ConstructorBaseInitializer ((ArrayList) $4, (Location) $2);
	  }
	| COLON THIS OPEN_PARENS opt_argument_list CLOSE_PARENS
	  {
		$$ = new ConstructorThisInitializer ((ArrayList) $4, (Location) $2);
	  }
	| COLON error {
		Report.Error (1018, (Location) $1, "Keyword this or base expected");
		$$ = null;
	  }
	;

opt_finalizer
        : /* EMPTY */           { $$ = 0; }
        | UNSAFE		{ $$ = Modifiers.UNSAFE; }
	| EXTERN		{ $$ = Modifiers.EXTERN; }
        ;
        
destructor_declaration
	: opt_attributes opt_finalizer TILDE 
	  {
		if (RootContext.Documentation != null) {
			tmpComment = Lexer.consume_doc_comment ();
			Lexer.doc_state = XmlCommentState.NotAllowed;
		}
	  }
	  IDENTIFIER OPEN_PARENS CLOSE_PARENS block
	  {
		LocatedToken lt = (LocatedToken) $5;
		if (lt.Value != current_container.MemberName.Name){
			Report.Error (574, lt.Location, "Name of destructor must match name of class");
		} else if (current_container.Kind != Kind.Class){
			Report.Error (575, lt.Location, "Only class types can contain destructor");
		} else {
			Location l = lt.Location;

			int m = (int) $2;
			if (!RootContext.StdLib && current_container.Name == "System.Object")
				m |= Modifiers.PROTECTED | Modifiers.VIRTUAL;
			else
				m |= Modifiers.PROTECTED | Modifiers.OVERRIDE;
                        
			Method d = new Destructor (
				current_class, TypeManager.system_void_expr, m, "Finalize", 
				Parameters.EmptyReadOnlyParameters, (Attributes) $1, l);
			if (RootContext.Documentation != null)
				d.DocComment = ConsumeStoredComment ();
		  
			d.Block = (ToplevelBlock) $8;
			current_container.AddMethod (d);
		}
	  }
	;

event_declaration
	: opt_attributes
	  opt_modifiers
	  EVENT type variable_declarators SEMICOLON
	  {
		current_array_type = null;
		foreach (VariableDeclaration var in (ArrayList) $5) {

			MemberName name = new MemberName (var.identifier,
				var.Location);

			EventField e = new EventField (
				current_class, (Expression) $4, (int) $2, false, name,
				(Attributes) $1);

			e.Initializer = var.expression_or_array_initializer;

			current_container.AddEvent (e);

			if (RootContext.Documentation != null) {
				e.DocComment = Lexer.consume_doc_comment ();
				Lexer.doc_state = XmlCommentState.Allowed;
			}
		}
	  }
	| opt_attributes
	  opt_modifiers
	  EVENT type namespace_or_type_name
	  OPEN_BRACE
	  {
		implicit_value_parameter_type = (Expression) $4;  
		lexer.EventParsing = true;
	  }
	  event_accessor_declarations
	  {
		lexer.EventParsing = false;  
	  }
	  CLOSE_BRACE
	  {
		MemberName name = (MemberName) $5;

		if ($8 == null){
			Report.Error (65, (Location) $3, "`{0}.{1}': event property must have both add and remove accessors",
				current_container.Name, name.ToString ());
			$$ = null;
		} else {
			Pair pair = (Pair) $8;
			
			if (name.TypeArguments != null)
				syntax_error (lexer.Location, "an event can't have type arguments");

			if (pair.First == null || pair.Second == null)
				// CS0073 is already reported, so no CS0065 here.
				$$ = null;
			else {
				Event e = new EventProperty (
					current_class, (Expression) $4, (int) $2, false, name,
					(Attributes) $1, (Accessor) pair.First, (Accessor) pair.Second);
				if (RootContext.Documentation != null) {
					e.DocComment = Lexer.consume_doc_comment ();
					Lexer.doc_state = XmlCommentState.Allowed;
				}

				current_container.AddEvent (e);
				implicit_value_parameter_type = null;
			}
		}
	  }
	| opt_attributes opt_modifiers EVENT type namespace_or_type_name error {
		MemberName mn = (MemberName) $5;

		if (mn.Left != null)
			Report.Error (71, mn.Location, "An explicit interface implementation of an event must use property syntax");
		else 
			Report.Error (71, mn.Location, "Event declaration should use property syntax");

		if (RootContext.Documentation != null)
			Lexer.doc_state = XmlCommentState.Allowed;
	  }
	;

event_accessor_declarations
	: add_accessor_declaration remove_accessor_declaration
	  {
		$$ = new Pair ($1, $2);
	  }
	| remove_accessor_declaration add_accessor_declaration
	  {
		$$ = new Pair ($2, $1);
	  }	
	| add_accessor_declaration  { $$ = null; } 
	| remove_accessor_declaration { $$ = null; } 
	| error
	  { 
		Report.Error (1055, GetLocation ($1), "An add or remove accessor expected");
		$$ = null;
	  }
	| { $$ = null; }
	;

add_accessor_declaration
	: opt_attributes ADD
	  {
		Parameter [] args = new Parameter [1];
		Parameter implicit_value_parameter = new Parameter (
			implicit_value_parameter_type, "value", 
			Parameter.Modifier.NONE, null, (Location) $2);

		args [0] = implicit_value_parameter;
		
		current_local_parameters = new Parameters (args);  
		lexer.EventParsing = false;
	  }
          block
	  {
		$$ = new Accessor ((ToplevelBlock) $4, 0, (Attributes) $1, (Location) $2);
		lexer.EventParsing = true;
	  }
	| opt_attributes ADD error {
		Report.Error (73, (Location) $2, "An add or remove accessor must have a body");
		$$ = null;
	  }
	| opt_attributes modifiers ADD {
		Report.Error (1609, (Location) $3, "Modifiers cannot be placed on event accessor declarations");
		$$ = null;
	  }
	;

remove_accessor_declaration
	: opt_attributes REMOVE
	  {
		Parameter [] args = new Parameter [1];
		Parameter implicit_value_parameter = new Parameter (
			implicit_value_parameter_type, "value", 
			Parameter.Modifier.NONE, null, (Location) $2);

		args [0] = implicit_value_parameter;
		
		current_local_parameters = new Parameters (args);  
		lexer.EventParsing = false;
	  }
          block
	  {
		$$ = new Accessor ((ToplevelBlock) $4, 0, (Attributes) $1, (Location) $2);
		lexer.EventParsing = true;
	  }
	| opt_attributes REMOVE error {
		Report.Error (73, (Location) $2, "An add or remove accessor must have a body");
		$$ = null;
	  }
	| opt_attributes modifiers REMOVE {
		Report.Error (1609, (Location) $3, "Modifiers cannot be placed on event accessor declarations");
		$$ = null;
	  }
	;

indexer_declaration
	: opt_attributes opt_modifiers indexer_declarator 
	  OPEN_BRACE
	  {
		IndexerDeclaration decl = (IndexerDeclaration) $3;

		implicit_value_parameter_type = decl.type;
		
		lexer.PropertyParsing = true;
		parsing_indexer  = true;
		
		indexer_parameters = decl.param_list;
		iterator_container = SimpleIteratorContainer.GetSimple ();
	  }
          accessor_declarations 
	  {
		  lexer.PropertyParsing = false;
		  has_get = has_set = false;
		  parsing_indexer  = false;
	  }
	  CLOSE_BRACE
	  { 
		if ($6 == null)
			break;

		// The signature is computed from the signature of the indexer.  Look
	 	// at section 3.6 on the spec
		Indexer indexer;
		IndexerDeclaration decl = (IndexerDeclaration) $3;
		Pair pair = (Pair) $6;
		Accessor get_block = (Accessor) pair.First;
		Accessor set_block = (Accessor) pair.Second;

		MemberName name;
		if (decl.interface_type != null)
			name = new MemberName (
				decl.interface_type, TypeContainer.DefaultIndexerName, decl.location);
		else
			name = new MemberName (TypeContainer.DefaultIndexerName, decl.location);

		indexer = new Indexer (current_class, decl.type, name,
				       (int) $2, false, decl.param_list, (Attributes) $1,
				       get_block, set_block);

		if (RootContext.Documentation != null)
			indexer.DocComment = ConsumeStoredComment ();

		current_container.AddIndexer (indexer);
		
		current_local_parameters = null;
		implicit_value_parameter_type = null;
		indexer_parameters = null;
	  }
	;

indexer_declarator
	: type THIS OPEN_BRACKET opt_formal_parameter_list CLOSE_BRACKET
	  {
		Parameters pars = (Parameters) $4;
		if (pars.HasArglist) {
			// "__arglist is not valid in this context"
			Report.Error (1669, (Location) $2, "__arglist is not valid in this context");
		} else if (pars.Empty){
			Report.Error (1551, (Location) $2, "Indexers must have at least one parameter");
		}
		if (RootContext.Documentation != null) {
			tmpComment = Lexer.consume_doc_comment ();
			Lexer.doc_state = XmlCommentState.Allowed;
		}

		$$ = new IndexerDeclaration ((Expression) $1, null, pars, (Location) $2);
	  }
	| type namespace_or_type_name DOT THIS OPEN_BRACKET opt_formal_parameter_list CLOSE_BRACKET
	  {
		Parameters pars = (Parameters) $6;

		if (pars.HasArglist) {
			// "__arglist is not valid in this context"
			Report.Error (1669, (Location) $4, "__arglist is not valid in this context");
		} else if (pars.Empty){
			Report.Error (1551, (Location) $4, "Indexers must have at least one parameter");
		}

		MemberName name = (MemberName) $2;
		$$ = new IndexerDeclaration ((Expression) $1, name, pars, (Location) $4);

		if (RootContext.Documentation != null) {
			tmpComment = Lexer.consume_doc_comment ();
			Lexer.doc_state = XmlCommentState.Allowed;
		}
	  }
	;

enum_declaration
	: opt_attributes
	  opt_modifiers
	  opt_partial
	  ENUM IDENTIFIER 
	  opt_enum_base {
		if (RootContext.Documentation != null)
			enumTypeComment = Lexer.consume_doc_comment ();
	  }
	  enum_body
	  opt_semicolon
	  {
		LocatedToken lt = (LocatedToken) $5;
		Location enum_location = lt.Location;

		if ($3 != null) {
			Report.Error (267, lt.Location, "The partial modifier can only appear immediately before `class', `struct' or `interface'");
			break;	// assumes that the parser put us in a switch
		}

		MemberName name = MakeName (new MemberName (lt.Value, enum_location));
		Enum e = new Enum (current_namespace, current_class, (Expression) $6, (int) $2,
				   name, (Attributes) $1);
		
		if (RootContext.Documentation != null)
			e.DocComment = enumTypeComment;


		EnumMember em = null;
		foreach (VariableDeclaration ev in (ArrayList) $8) {
			em = new EnumMember (e, em, (Expression) ev.expression_or_array_initializer,
				new MemberName (ev.identifier, ev.Location), ev.OptAttributes);

//			if (RootContext.Documentation != null)
				em.DocComment = ev.DocComment;

			e.AddEnumMember (em);
		}

		current_container.AddEnum (e);
		RootContext.Tree.RecordDecl (current_namespace.NS, name, e);
		$$ = e;

	  }
	;

opt_enum_base
	: /* empty */		{ $$ = TypeManager.system_int32_expr; }
	| COLON type		{ $$ = $2;   }
	;

enum_body
	: OPEN_BRACE
	  {
		if (RootContext.Documentation != null)
			Lexer.doc_state = XmlCommentState.Allowed;
	  }
	  opt_enum_member_declarations
	  {
	  	// here will be evaluated after CLOSE_BLACE is consumed.
		if (RootContext.Documentation != null)
			Lexer.doc_state = XmlCommentState.Allowed;
	  }
	  CLOSE_BRACE
	  {
		$$ = $3;
	  }
	;

opt_enum_member_declarations
	: /* empty */			{ $$ = new ArrayList (4); }
	| enum_member_declarations opt_comma { $$ = $1; }
	;

enum_member_declarations
	: enum_member_declaration 
	  {
		ArrayList l = new ArrayList (4);

		l.Add ($1);
		$$ = l;
	  }
	| enum_member_declarations COMMA enum_member_declaration
	  {
		ArrayList l = (ArrayList) $1;

		l.Add ($3);

		$$ = l;
	  }
	;

enum_member_declaration
	: opt_attributes IDENTIFIER 
	  {
		VariableDeclaration vd = new VariableDeclaration (
			(LocatedToken) $2, null, (Attributes) $1);

		if (RootContext.Documentation != null) {
			vd.DocComment = Lexer.consume_doc_comment ();
			Lexer.doc_state = XmlCommentState.Allowed;
		}

		$$ = vd;
	  }
	| opt_attributes IDENTIFIER
	  {
		if (RootContext.Documentation != null) {
			tmpComment = Lexer.consume_doc_comment ();
			Lexer.doc_state = XmlCommentState.NotAllowed;
		}
	  }
          ASSIGN expression
	  { 
		VariableDeclaration vd = new VariableDeclaration (
			(LocatedToken) $2, $5, (Attributes) $1);

		if (RootContext.Documentation != null)
			vd.DocComment = ConsumeStoredComment ();

		$$ = vd;
	  }
	;

delegate_declaration
	: opt_attributes
	  opt_modifiers
	  DELEGATE
	  {
		lexer.ConstraintsParsing = true;
	  }
	  type member_name
	  OPEN_PARENS opt_formal_parameter_list CLOSE_PARENS
	  {
		MemberName name = MakeName ((MemberName) $6);
		Delegate del = new Delegate (current_namespace, current_class, (Expression) $5,
					     (int) $2, name, (Parameters) $8, (Attributes) $1);

		if (RootContext.Documentation != null) {
			del.DocComment = Lexer.consume_doc_comment ();
			Lexer.doc_state = XmlCommentState.Allowed;
		}

		current_container.AddDelegate (del);
		RootContext.Tree.RecordDecl (current_namespace.NS, name, del);

		current_delegate = del;
	  }
	  opt_type_parameter_constraints_clauses
	  {
		lexer.ConstraintsParsing = false;
	  }
	  SEMICOLON
	  {
		current_delegate.SetParameterInfo ((ArrayList) $11);
		$$ = current_delegate;

		current_delegate = null;
	  }
	;

opt_nullable
	: /* empty */
	  {
		lexer.CheckNullable (false);
		$$ = false;
	  }
	| INTERR
	  {
		lexer.CheckNullable (true);
		$$ = true;
	  }
	;

namespace_or_type_name
	: member_name
	| IDENTIFIER DOUBLE_COLON IDENTIFIER {
		LocatedToken lt1 = (LocatedToken) $1;
		LocatedToken lt2 = (LocatedToken) $3;
		$$ = new MemberName (lt1.Value, lt2.Value, lt2.Location);
	  }
	| namespace_or_type_name DOT IDENTIFIER opt_type_argument_list {
		LocatedToken lt = (LocatedToken) $3;
		$$ = new MemberName ((MemberName) $1, lt.Value, (TypeArguments) $4, lt.Location);
	  }
	;

member_name
	: IDENTIFIER opt_type_argument_list {
		LocatedToken lt = (LocatedToken) $1;
		$$ = new MemberName (lt.Value, (TypeArguments) $2, lt.Location);
	  }
	;

opt_type_argument_list
	: /* empty */ 		     { $$ = null; } 
	| OP_GENERICS_LT type_arguments OP_GENERICS_GT
	  {
		$$ = $2;
		if (RootContext.Version == LanguageVersion.ISO_1)
			Report.FeatureIsNotStandardized (lexer.Location, "generics");
	  }
	| GENERIC_DIMENSION
	  {
		$$ = new TypeArguments ((int) $1, lexer.Location);
		if (RootContext.Version == LanguageVersion.ISO_1)
			Report.FeatureIsNotStandardized (lexer.Location, "generics");
	  }
	;

type_arguments
	: opt_attributes type {
		TypeArguments type_args = new TypeArguments (lexer.Location);
		if ($1 != null) {
			SimpleName sn = $2 as SimpleName;
			if (sn == null)
				Report.Error (1031, lexer.Location, "Type expected");
			else
				$2 = new TypeParameterName (sn.Name, (Attributes) $1, lexer.Location);
		}
		type_args.Add ((Expression) $2);
		$$ = type_args;
  	  }
	| type_arguments COMMA opt_attributes type {
		TypeArguments type_args = (TypeArguments) $1;
		if ($3 != null) {
			SimpleName sn = $4 as SimpleName;
			if (sn == null)
				Report.Error (1031, lexer.Location, "Type expected");
			else
				$4 = new TypeParameterName (sn.Name, (Attributes) $3, lexer.Location);
		}
		type_args.Add ((Expression) $4);
		$$ = type_args;
	  }
	;

	
/* 
 * Before you think of adding a return_type, notice that we have been
 * using two rules in the places where it matters (one rule using type
 * and another identical one that uses VOID as the return type).  This
 * gets rid of a shift/reduce couple
 */
type
	: namespace_or_type_name opt_nullable
	  {
		MemberName name = (MemberName) $1;
		$$ = name.GetTypeExpression ();

		if ((bool) $2)
			$$ = new ComposedCast ((Expression) $$, "?", lexer.Location);
	  }
	| builtin_types opt_nullable
	  {
		if ((bool) $2)
			$$ = new ComposedCast ((Expression) $1, "?", lexer.Location);
	  }
	| array_type
	| pointer_type
	;

pointer_type
	: type STAR
	  {
		//
		// Note that here only unmanaged types are allowed but we
		// can't perform checks during this phase - we do it during
		// semantic analysis.
		//
		$$ = new ComposedCast ((Expression) $1, "*", Lexer.Location);
	  }
	| VOID STAR
	  {
		$$ = new ComposedCast (TypeManager.system_void_expr, "*", (Location) $1);
	  }
	;

non_expression_type
	: builtin_types opt_nullable
	  {
		if ((bool) $2)
			$$ = new ComposedCast ((Expression) $1, "?", lexer.Location);
	  }
	| non_expression_type rank_specifier
	  {
		Location loc = GetLocation ($1);
		if (loc.IsNull)
			loc = lexer.Location;
		$$ = new ComposedCast ((Expression) $1, (string) $2, loc);
	  }
	| non_expression_type STAR
	  {
		Location loc = GetLocation ($1);
		if (loc.IsNull)
			loc = lexer.Location;
		$$ = new ComposedCast ((Expression) $1, "*", loc);
	  }
	| expression rank_specifiers 
	  {
		$$ = new ComposedCast ((Expression) $1, (string) $2);
	  }
	| expression STAR 
	  {
		$$ = new ComposedCast ((Expression) $1, "*");
	  }
	
	//
	// We need this because the parser will happily go and reduce IDENTIFIER STAR
	// through this different path
	//
	| multiplicative_expression STAR 
	  {
		$$ = new ComposedCast ((Expression) $1, "*");
	  }
	;

type_list
	: type
	  {
		ArrayList types = new ArrayList (4);

		types.Add ($1);
		$$ = types;
	  }
	| type_list COMMA type
	  {
		ArrayList types = (ArrayList) $1;

		types.Add ($3);
		$$ = types;
	  }
	;

/*
 * replaces all the productions for isolating the various
 * simple types, but we need this to reuse it easily in local_variable_type
 */
builtin_types
	: OBJECT	{ $$ = TypeManager.system_object_expr; }
	| STRING	{ $$ = TypeManager.system_string_expr; }
	| BOOL		{ $$ = TypeManager.system_boolean_expr; }
	| DECIMAL	{ $$ = TypeManager.system_decimal_expr; }
	| FLOAT		{ $$ = TypeManager.system_single_expr; }
	| DOUBLE	{ $$ = TypeManager.system_double_expr; }
	| integral_type
	;

integral_type
	: SBYTE		{ $$ = TypeManager.system_sbyte_expr; }
	| BYTE		{ $$ = TypeManager.system_byte_expr; }
	| SHORT		{ $$ = TypeManager.system_int16_expr; }
	| USHORT	{ $$ = TypeManager.system_uint16_expr; }
	| INT		{ $$ = TypeManager.system_int32_expr; }
	| UINT		{ $$ = TypeManager.system_uint32_expr; }
	| LONG		{ $$ = TypeManager.system_int64_expr; }
	| ULONG		{ $$ = TypeManager.system_uint64_expr; }
	| CHAR		{ $$ = TypeManager.system_char_expr; }
	| VOID		{ $$ = TypeManager.system_void_expr; }
	;

array_type
	: type rank_specifiers opt_nullable
	  {
		string rank_specifiers = (string) $2;
		if ((bool) $3)
			rank_specifiers += "?";

		$$ = current_array_type = new ComposedCast ((Expression) $1, rank_specifiers);
	  }
	;

//
// Expressions, section 7.5
//
primary_expression
	: literal
	  {
		// 7.5.1: Literals
	  }
 	| member_name
	  {
		MemberName mn = (MemberName) $1;
		$$ = mn.GetTypeExpression ();
	  }
	| IDENTIFIER DOUBLE_COLON IDENTIFIER
	  {
		LocatedToken lt1 = (LocatedToken) $1;
		LocatedToken lt2 = (LocatedToken) $3;
		$$ = new QualifiedAliasMember (lt1.Value, lt2.Value, lt2.Location);
	  }
	| parenthesized_expression
	| default_value_expression
	| member_access
	| invocation_expression
	| element_access
	| this_access
	| base_access
	| post_increment_expression
	| post_decrement_expression
	| new_expression
	| typeof_expression
	| sizeof_expression
	| checked_expression
	| unchecked_expression
	| pointer_member_access
	| anonymous_method_expression
	;

literal
	: boolean_literal
	| integer_literal
	| real_literal
	| LITERAL_CHARACTER     { $$ = new CharLiteral ((char) lexer.Value, lexer.Location); }
	| LITERAL_STRING        { $$ = new StringLiteral ((string) lexer.Value, lexer.Location); } 
	| NULL			{ $$ = new NullLiteral (lexer.Location); }
	;

real_literal
	: LITERAL_FLOAT         { $$ = new FloatLiteral ((float) lexer.Value, lexer.Location); }
	| LITERAL_DOUBLE        { $$ = new DoubleLiteral ((double) lexer.Value, lexer.Location); }
	| LITERAL_DECIMAL       { $$ = new DecimalLiteral ((decimal) lexer.Value, lexer.Location); }
	;

integer_literal
	: LITERAL_INTEGER       { 
		object v = lexer.Value;

		if (v is int){
			$$ = new IntLiteral ((int) v, lexer.Location);
		} else if (v is uint)
			$$ = new UIntLiteral ((UInt32) v, lexer.Location);
		else if (v is long)
			$$ = new LongLiteral ((Int64) v, lexer.Location);
		else if (v is ulong)
			$$ = new ULongLiteral ((UInt64) v, lexer.Location);
		else
			Console.WriteLine ("OOPS.  Unexpected result from scanner");
	  }
	;

boolean_literal
	: TRUE			{ $$ = new BoolLiteral (true, lexer.Location); }
	| FALSE			{ $$ = new BoolLiteral (false, lexer.Location); }
	;

parenthesized_expression_0
	: OPEN_PARENS expression CLOSE_PARENS
	  {
		$$ = $2;
		lexer.Deambiguate_CloseParens ();
		// After this, the next token returned is one of
		// CLOSE_PARENS_CAST, CLOSE_PARENS_NO_CAST, CLOSE_PARENS_OPEN_PARENS
		// or CLOSE_PARENS_MINUS.
	  }
	| OPEN_PARENS expression error { CheckToken (1026, yyToken, "Expecting ')'", lexer.Location); }
	;

parenthesized_expression
	: parenthesized_expression_0 CLOSE_PARENS_NO_CAST
	  {
		$$ = $1;
	  }
	| parenthesized_expression_0 CLOSE_PARENS_MINUS
	  {
		// If a parenthesized expression is followed by a minus, we need to wrap
		// the expression inside a ParenthesizedExpression for the CS0075 check
		// in Binary.DoResolve().
		$$ = new ParenthesizedExpression ((Expression) $1);
	  }
	;

member_access
	: primary_expression DOT IDENTIFIER opt_type_argument_list
	  {
		LocatedToken lt = (LocatedToken) $3;
		$$ = new MemberAccess ((Expression) $1, lt.Value,
				       (TypeArguments) $4, lt.Location);
	  }
	| predefined_type DOT IDENTIFIER opt_type_argument_list
	  {
		LocatedToken lt = (LocatedToken) $3;
		$$ = new MemberAccess ((Expression) $1, lt.Value,
				       (TypeArguments) $4, lt.Location);
	  }
	;

predefined_type
	: builtin_types
	;

invocation_expression
	: primary_expression OPEN_PARENS opt_argument_list CLOSE_PARENS
	  {
		if ($1 == null)
			Report.Error (1, (Location) $2, "Parse error");
	        else
			$$ = new Invocation ((Expression) $1, (ArrayList) $3);
	  }
	| parenthesized_expression_0 CLOSE_PARENS_OPEN_PARENS OPEN_PARENS CLOSE_PARENS
	  {
		$$ = new Invocation ((Expression) $1, new ArrayList ());
	  }
	| parenthesized_expression_0 CLOSE_PARENS_OPEN_PARENS primary_expression
	  {
		$$ = new InvocationOrCast ((Expression) $1, (Expression) $3);
	  }
	| parenthesized_expression_0 CLOSE_PARENS_OPEN_PARENS OPEN_PARENS non_simple_argument CLOSE_PARENS
	  {
		ArrayList args = new ArrayList (1);
		args.Add ($4);
		$$ = new Invocation ((Expression) $1, args);
	  }
	| parenthesized_expression_0 CLOSE_PARENS_OPEN_PARENS OPEN_PARENS argument_list COMMA argument CLOSE_PARENS
	  {
		ArrayList args = ((ArrayList) $4);
		args.Add ($6);
		$$ = new Invocation ((Expression) $1, args);
	  }
	;

opt_argument_list
	: /* empty */		{ $$ = null; }
	| argument_list
	;

argument_list
	: argument		
	  { 
		ArrayList list = new ArrayList (4);
		list.Add ($1);
		$$ = list;
	  }
	| argument_list COMMA argument
	  {
		ArrayList list = (ArrayList) $1;
		list.Add ($3);
		$$ = list;
	  }
	| argument_list error {
		CheckToken (1026, yyToken, "Expected `,' or `)'", GetLocation ($2));
		$$ = null;
	  }
	;

argument
	: expression
	  {
		$$ = new Argument ((Expression) $1, Argument.AType.Expression);
	  }
	| non_simple_argument
	  {
		$$ = $1;
	  }
	;

non_simple_argument
	: REF variable_reference 
	  { 
		$$ = new Argument ((Expression) $2, Argument.AType.Ref);
	  }
	| OUT variable_reference 
	  { 
		$$ = new Argument ((Expression) $2, Argument.AType.Out);
	  }
	| ARGLIST OPEN_PARENS argument_list CLOSE_PARENS
	  {
		ArrayList list = (ArrayList) $3;
		Argument[] args = new Argument [list.Count];
		list.CopyTo (args, 0);

		Expression expr = new Arglist (args, (Location) $1);
		$$ = new Argument (expr, Argument.AType.Expression);
	  }
	| ARGLIST
	  {
		$$ = new Argument (new ArglistAccess ((Location) $1), Argument.AType.ArgList);
	  }
	;

variable_reference
	: expression { note ("section 5.4"); $$ = $1; }
	;

element_access
	: primary_expression OPEN_BRACKET expression_list CLOSE_BRACKET	
	  {
		$$ = new ElementAccess ((Expression) $1, (ArrayList) $3);
	  }
	| primary_expression rank_specifiers
	  {
		// So the super-trick is that primary_expression
		// can only be either a SimpleName or a MemberAccess. 
		// The MemberAccess case arises when you have a fully qualified type-name like :
		// Foo.Bar.Blah i;
		// SimpleName is when you have
		// Blah i;
		  
		Expression expr = (Expression) $1;  
		if (expr is ComposedCast){
			$$ = new ComposedCast (expr, (string) $2);
		} else if (!(expr is SimpleName || expr is MemberAccess || expr is ConstructedType || expr is QualifiedAliasMember)){
			Error_ExpectingTypeName (expr);
			$$ = TypeManager.system_object_expr;
		} else {
			//
			// So we extract the string corresponding to the SimpleName
			// or MemberAccess
			// 
			$$ = new ComposedCast (expr, (string) $2);
		}
		current_array_type = (Expression)$$;
	  }
	;

expression_list
	: expression
	  {
		ArrayList list = new ArrayList (4);
		list.Add ($1);
		$$ = list;
	  }
	| expression_list COMMA expression
	  {
		ArrayList list = (ArrayList) $1;
		list.Add ($3);
		$$ = list;
	  }
	;

this_access
	: THIS
	  {
		$$ = new This (current_block, (Location) $1);
	  }
	;

base_access
	: BASE DOT IDENTIFIER
	  {
		LocatedToken lt = (LocatedToken) $3;
		$$ = new BaseAccess (lt.Value, lt.Location);
	  }
	| BASE OPEN_BRACKET expression_list CLOSE_BRACKET
	  {
		$$ = new BaseIndexerAccess ((ArrayList) $3, (Location) $1);
	  }
	| BASE error {
		Report.Error (175, (Location) $1, "Use of keyword `base' is not valid in this context");
		$$ = null;
	  }
	;

post_increment_expression
	: primary_expression OP_INC
	  {
		$$ = new UnaryMutator (UnaryMutator.Mode.PostIncrement,
				       (Expression) $1, (Location) $2);
	  }
	;

post_decrement_expression
	: primary_expression OP_DEC
	  {
		$$ = new UnaryMutator (UnaryMutator.Mode.PostDecrement,
				       (Expression) $1, (Location) $2);
	  }
	;

new_expression
	: object_or_delegate_creation_expression
	| array_creation_expression
	;

object_or_delegate_creation_expression
	: NEW type OPEN_PARENS opt_argument_list CLOSE_PARENS
	  {
		$$ = new New ((Expression) $2, (ArrayList) $4, (Location) $1);
	  }
	;

array_creation_expression
	: NEW type OPEN_BRACKET expression_list CLOSE_BRACKET 
	  opt_rank_specifier
	  opt_array_initializer
	  {
		$$ = new ArrayCreation ((Expression) $2, (ArrayList) $4, (string) $6, (ArrayList) $7, (Location) $1);
	  }
	| NEW type rank_specifiers array_initializer
	  {
		$$ = new ArrayCreation ((Expression) $2, (string) $3, (ArrayList) $4, (Location) $1);
	  }
	| NEW error
	  {
		Report.Error (1031, (Location) $1, "Type expected");
                $$ = null;
	  }          
	| NEW type error 
	  {
		Report.Error (1526, (Location) $1, "A new expression requires () or [] after type");
		$$ = null;
	  }
	;

opt_rank_specifier
	: /* empty */
	  {
		  $$ = "";
	  }
	| rank_specifiers
	  {
			$$ = $1;
	  }
	;

opt_rank_specifier_or_nullable
	: /* empty */
	  {
		$$ = "";
	  }
	| INTERR
	  {
		$$ = "?";
	  }
	| opt_nullable rank_specifiers
	  {
		if ((bool) $1)
			$$ = "?" + $2;
		else
			$$ = $2;
	  }
	| opt_nullable rank_specifiers INTERR
	  {
		if ((bool) $1)
			$$ = "?" + $2 + "?";
		else
			$$ = $2 + "?";
	  }
	;

rank_specifiers
	: rank_specifier opt_rank_specifier
	  {
		  $$ = (string) $2 + (string) $1;
	  }
        ;

rank_specifier
	: OPEN_BRACKET opt_dim_separators CLOSE_BRACKET
	  {
		$$ = "[" + (string) $2 + "]";
	  }
	;

opt_dim_separators
	: /* empty */
	  {
		$$ = "";
	  }
	| dim_separators
	  {
		  $$ = $1;
	  }		  
	;

dim_separators
	: COMMA
	  {
		$$ = ",";
	  }
	| dim_separators COMMA
	  {
		$$ = (string) $1 + ",";
	  }
	;

opt_array_initializer
	: /* empty */
	  {
		$$ = null;
	  }
        | array_initializer
	  {
		$$ = $1;
	  }
	;

array_initializer
	: OPEN_BRACE CLOSE_BRACE
	  {
		ArrayList list = new ArrayList (4);
		$$ = list;
	  }
	| OPEN_BRACE variable_initializer_list opt_comma CLOSE_BRACE
	  {
		$$ = (ArrayList) $2;
	  }
	;

variable_initializer_list
	: variable_initializer
	  {
		ArrayList list = new ArrayList (4);
		list.Add ($1);
		$$ = list;
	  }
	| variable_initializer_list COMMA variable_initializer
	  {
		ArrayList list = (ArrayList) $1;
		list.Add ($3);
		$$ = list;
	  }
	;

void_pointer_expression
	: void_pointer_expression STAR
	  {
		$$ = new ComposedCast ((Expression) $1, "*", lexer.Location);
	  }
	| VOID STAR
	  {
		$$ = new ComposedCast (TypeManager.system_void_expr, "*", lexer.Location);;
	  }
	;

typeof_expression
	: TYPEOF OPEN_PARENS VOID CLOSE_PARENS
	  {
		$$ = new TypeOfVoid ((Location) $1);
	  }
	| TYPEOF OPEN_PARENS void_pointer_expression CLOSE_PARENS
	  {
		$$ = new TypeOf ((Expression) $3, (Location) $1);
	  }
	| TYPEOF OPEN_PARENS
	  {
		lexer.TypeOfParsing = true;
	  }
	  type CLOSE_PARENS
	  {
		lexer.TypeOfParsing = false;
		$$ = new TypeOf ((Expression) $4, lexer.Location);
	  }
	;

sizeof_expression
	: SIZEOF OPEN_PARENS type CLOSE_PARENS { 
		$$ = new SizeOf ((Expression) $3, (Location) $1);
	  }
	;

checked_expression
	: CHECKED OPEN_PARENS expression CLOSE_PARENS
	  {
		$$ = new CheckedExpr ((Expression) $3, (Location) $1);
	  }
	;

unchecked_expression
	: UNCHECKED OPEN_PARENS expression CLOSE_PARENS
	  {
		$$ = new UnCheckedExpr ((Expression) $3, (Location) $1);
	  }
	;

pointer_member_access 
	: primary_expression OP_PTR IDENTIFIER
	  {
		Expression deref;
		LocatedToken lt = (LocatedToken) $3;

		deref = new Unary (Unary.Operator.Indirection, (Expression) $1, lt.Location);
		$$ = new MemberAccess (deref, lt.Value, lt.Location);
	  }
	;

anonymous_method_expression
	: DELEGATE opt_anonymous_method_signature
	  {
		oob_stack.Push (current_local_parameters);
		current_local_parameters = (Parameters)$2;

		// Force the next block to be created as a ToplevelBlock
		oob_stack.Push (current_block);
		oob_stack.Push (top_current_block);
		current_block = null;
	  } 
	  block
	  {
		Location loc = (Location) $1;
		top_current_block = (Block) oob_stack.Pop ();
		current_block = (Block) oob_stack.Pop ();
		if (RootContext.Version == LanguageVersion.ISO_1){
			Report.FeatureIsNotStandardized (loc, "anonymous methods");
			$$ = null;
		} else  {
			ToplevelBlock anon_block = (ToplevelBlock) $4;

			anon_block.Parent = current_block;
			$$ = new AnonymousMethod ((Parameters) $2, (ToplevelBlock) top_current_block, 
				anon_block, loc);
		}
			current_local_parameters = (Parameters) oob_stack.Pop ();
		}
	;

opt_anonymous_method_signature
	: /* empty */			{ $$ = null; } 
	| anonymous_method_signature
	;

anonymous_method_signature
	: OPEN_PARENS opt_anonymous_method_parameter_list CLOSE_PARENS 
	  {
		if ($2 == null)
			$$ = Parameters.EmptyReadOnlyParameters;
		else {
			ArrayList par_list = (ArrayList) $2;
			Parameter [] pars = new Parameter [par_list.Count];
			par_list.CopyTo (pars);
			$$ = new Parameters (pars);
		}
	  }
	;

opt_anonymous_method_parameter_list
	: /* empty */	{ $$ = null; } 
	| anonymous_method_parameter_list  { $$ = $1; }
	;

anonymous_method_parameter_list
	: anonymous_method_parameter 
	  {
		ArrayList a = new ArrayList (4);
		a.Add ($1);
		$$ = a;
	  }
	| anonymous_method_parameter_list COMMA anonymous_method_parameter 
	  {
		ArrayList a = (ArrayList) $1;
		a.Add ($3);
		$$ = a;
	  }
	; 

anonymous_method_parameter
	: opt_parameter_modifier type IDENTIFIER {
		LocatedToken lt = (LocatedToken) $3;
		$$ = new Parameter ((Expression) $2, lt.Value, (Parameter.Modifier) $1, null, lt.Location);
	  }
	| PARAMS type IDENTIFIER {
		Report.Error (1670, ((LocatedToken) $3).Location, "The `params' modifier is not allowed in anonymous method declaration");
		$$ = null;
	  }
	;

default_value_expression
	: DEFAULT_OPEN_PARENS type CLOSE_PARENS
	  {
		$$ = new DefaultValueExpression ((Expression) $2, lexer.Location);
	  }
	;

unary_expression
	: primary_expression
	| BANG prefixed_unary_expression
	  {
		$$ = new Unary (Unary.Operator.LogicalNot, (Expression) $2, (Location) $1);
	  }
	| TILDE prefixed_unary_expression
	  {
		$$ = new Unary (Unary.Operator.OnesComplement, (Expression) $2, (Location) $1);
	  }
	| cast_expression
	;

cast_list
	: parenthesized_expression_0 CLOSE_PARENS_CAST unary_expression
	  {
		$$ = new Cast ((Expression) $1, (Expression) $3);
	  }
	| parenthesized_expression_0 CLOSE_PARENS_OPEN_PARENS cast_expression
	  {
		$$ = new Cast ((Expression) $1, (Expression) $3);
	  }	
	;

cast_expression
	: cast_list
	| OPEN_PARENS non_expression_type CLOSE_PARENS prefixed_unary_expression
	  {
		// TODO: wrong location
		$$ = new Cast ((Expression) $2, (Expression) $4, lexer.Location);
	  }
	;

	//
	// The idea to split this out is from Rhys' grammar
	// to solve the problem with casts.
	//
prefixed_unary_expression
	: unary_expression
	| PLUS prefixed_unary_expression
	  { 
	  	$$ = new Unary (Unary.Operator.UnaryPlus, (Expression) $2, (Location) $1);
	  } 
	| MINUS prefixed_unary_expression 
	  { 
		$$ = new Unary (Unary.Operator.UnaryNegation, (Expression) $2, (Location) $1);
	  }
	| OP_INC prefixed_unary_expression 
	  {
		$$ = new UnaryMutator (UnaryMutator.Mode.PreIncrement,
				       (Expression) $2, (Location) $1);
	  }
	| OP_DEC prefixed_unary_expression 
	  {
		$$ = new UnaryMutator (UnaryMutator.Mode.PreDecrement,
				       (Expression) $2, (Location) $1);
	  }
	| STAR prefixed_unary_expression
	  {
		$$ = new Unary (Unary.Operator.Indirection, (Expression) $2, (Location) $1);
	  }
	| BITWISE_AND prefixed_unary_expression
	  {
		$$ = new Unary (Unary.Operator.AddressOf, (Expression) $2, (Location) $1);
	  }
	;

pre_increment_expression
	: OP_INC prefixed_unary_expression 
	  {
		$$ = new UnaryMutator (UnaryMutator.Mode.PreIncrement,
				       (Expression) $2, (Location) $1);
	  }
	;

pre_decrement_expression
	: OP_DEC prefixed_unary_expression 
	  {
		$$ = new UnaryMutator (UnaryMutator.Mode.PreDecrement,
				       (Expression) $2, (Location) $1);
	  }
	;

multiplicative_expression
	: prefixed_unary_expression
	| multiplicative_expression STAR prefixed_unary_expression
	  {
		$$ = new Binary (Binary.Operator.Multiply, 
			         (Expression) $1, (Expression) $3);
	  }
	| multiplicative_expression DIV prefixed_unary_expression
	  {
		$$ = new Binary (Binary.Operator.Division, 
			         (Expression) $1, (Expression) $3);
	  }
	| multiplicative_expression PERCENT prefixed_unary_expression 
	  {
		$$ = new Binary (Binary.Operator.Modulus, 
			         (Expression) $1, (Expression) $3);
	  }
	;

additive_expression
	: multiplicative_expression
	| additive_expression PLUS multiplicative_expression 
	  {
		$$ = new Binary (Binary.Operator.Addition, 
			         (Expression) $1, (Expression) $3);
	  }
	| additive_expression MINUS multiplicative_expression
	  {
		$$ = new Binary (Binary.Operator.Subtraction, 
			         (Expression) $1, (Expression) $3);
	  }
	;

shift_expression
	: additive_expression
	| shift_expression OP_SHIFT_LEFT additive_expression
	  {
		$$ = new Binary (Binary.Operator.LeftShift, 
			         (Expression) $1, (Expression) $3);
	  }
	| shift_expression OP_SHIFT_RIGHT additive_expression
	  {
		$$ = new Binary (Binary.Operator.RightShift, 
			         (Expression) $1, (Expression) $3);
	  }
	; 

opt_error
	: /* empty */
	  {
		$$ = false;
	  }
	| error
	  {
		lexer.PutbackNullable ();
		$$ = true;
	  }
	;

nullable_type_or_conditional
	: type opt_error
	  {
		if (((bool) $2) && ($1 is ComposedCast))
			$$ = ((ComposedCast) $1).RemoveNullable ();
		else
			$$ = $1;
	  }
	;

relational_expression
	: shift_expression
	| relational_expression OP_LT shift_expression
	  {
		$$ = new Binary (Binary.Operator.LessThan, 
			         (Expression) $1, (Expression) $3);
	  }
	| relational_expression OP_GT shift_expression
	  {
		$$ = new Binary (Binary.Operator.GreaterThan, 
			         (Expression) $1, (Expression) $3);
	  }
	| relational_expression OP_LE shift_expression
	  {
		$$ = new Binary (Binary.Operator.LessThanOrEqual, 
			         (Expression) $1, (Expression) $3);
	  }
	| relational_expression OP_GE shift_expression
	  {
		$$ = new Binary (Binary.Operator.GreaterThanOrEqual, 
			         (Expression) $1, (Expression) $3);
	  }
	| relational_expression IS
	  {
		yyErrorFlag = 3;
	  } nullable_type_or_conditional
	  {
		$$ = new Is ((Expression) $1, (Expression) $4, (Location) $2);
	  }
	| relational_expression AS
	  {
		yyErrorFlag = 3;
	  } nullable_type_or_conditional
	  {
		$$ = new As ((Expression) $1, (Expression) $4, (Location) $2);
	  }
	;

equality_expression
	: relational_expression
	| equality_expression OP_EQ relational_expression
	  {
		$$ = new Binary (Binary.Operator.Equality, 
			         (Expression) $1, (Expression) $3);
	  }
	| equality_expression OP_NE relational_expression
	  {
		$$ = new Binary (Binary.Operator.Inequality, 
			         (Expression) $1, (Expression) $3);
	  }
	; 

and_expression
	: equality_expression
	| and_expression BITWISE_AND equality_expression
	  {
		$$ = new Binary (Binary.Operator.BitwiseAnd, 
			         (Expression) $1, (Expression) $3);
	  }
	;

exclusive_or_expression
	: and_expression
	| exclusive_or_expression CARRET and_expression
	  {
		$$ = new Binary (Binary.Operator.ExclusiveOr, 
			         (Expression) $1, (Expression) $3);
	  }
	;

inclusive_or_expression
	: exclusive_or_expression
	| inclusive_or_expression BITWISE_OR exclusive_or_expression
	  {
		$$ = new Binary (Binary.Operator.BitwiseOr, 
			         (Expression) $1, (Expression) $3);
	  }
	;

conditional_and_expression
	: inclusive_or_expression
	| conditional_and_expression OP_AND inclusive_or_expression
	  {
		$$ = new Binary (Binary.Operator.LogicalAnd, 
			         (Expression) $1, (Expression) $3);
	  }
	;

conditional_or_expression
	: conditional_and_expression
	| conditional_or_expression OP_OR conditional_and_expression
	  {
		$$ = new Binary (Binary.Operator.LogicalOr, 
			         (Expression) $1, (Expression) $3);
	  }
	;

conditional_expression
	: conditional_or_expression
	| conditional_or_expression INTERR expression COLON expression 
	  {
		$$ = new Conditional ((Expression) $1, (Expression) $3, (Expression) $5);
	  }
	| conditional_or_expression INTERR INTERR expression
	  {
		$$ = new Nullable.NullCoalescingOperator ((Expression) $1, (Expression) $4, lexer.Location);
	  }
	// We'll be resolved into a `parenthesized_expression_0' later on.
	| conditional_or_expression INTERR CLOSE_PARENS
	  {
		$$ = new ComposedCast ((Expression) $1, "?", lexer.Location);
		lexer.PutbackCloseParens ();
	  }
	;

assignment_expression
	: prefixed_unary_expression ASSIGN expression
	  {
		$$ = new Assign ((Expression) $1, (Expression) $3);
	  }
	| prefixed_unary_expression OP_MULT_ASSIGN expression
	  {
		$$ = new CompoundAssign (
			Binary.Operator.Multiply, (Expression) $1, (Expression) $3);
	  }
	| prefixed_unary_expression OP_DIV_ASSIGN expression
	  {
		$$ = new CompoundAssign (
			Binary.Operator.Division, (Expression) $1, (Expression) $3);
	  }
	| prefixed_unary_expression OP_MOD_ASSIGN expression
	  {
		$$ = new CompoundAssign (
			Binary.Operator.Modulus, (Expression) $1, (Expression) $3);
	  }
	| prefixed_unary_expression OP_ADD_ASSIGN expression
	  {
		$$ = new CompoundAssign (
			Binary.Operator.Addition, (Expression) $1, (Expression) $3);
	  }
	| prefixed_unary_expression OP_SUB_ASSIGN expression
	  {
		$$ = new CompoundAssign (
			Binary.Operator.Subtraction, (Expression) $1, (Expression) $3);
	  }
	| prefixed_unary_expression OP_SHIFT_LEFT_ASSIGN expression
	  {
		$$ = new CompoundAssign (
			Binary.Operator.LeftShift, (Expression) $1, (Expression) $3);
	  }
	| prefixed_unary_expression OP_SHIFT_RIGHT_ASSIGN expression
	  {
		$$ = new CompoundAssign (
			Binary.Operator.RightShift, (Expression) $1, (Expression) $3);
	  }
	| prefixed_unary_expression OP_AND_ASSIGN expression
	  {
		$$ = new CompoundAssign (
			Binary.Operator.BitwiseAnd, (Expression) $1, (Expression) $3);
	  }
	| prefixed_unary_expression OP_OR_ASSIGN expression
	  {
		$$ = new CompoundAssign (
			Binary.Operator.BitwiseOr, (Expression) $1, (Expression) $3);
	  }
	| prefixed_unary_expression OP_XOR_ASSIGN expression
	  {
		$$ = new CompoundAssign (
			Binary.Operator.ExclusiveOr, (Expression) $1, (Expression) $3);
	  }
	;

expression
	: conditional_expression
	| assignment_expression
	;

constant_expression
	: expression
	;

boolean_expression
	: expression
	;

//
// 10 classes
//
class_declaration
	: opt_attributes
	  opt_modifiers
	  opt_partial
	  CLASS
	  {
		lexer.ConstraintsParsing = true;
	  }
	  member_name
	  {
		MemberName name = MakeName ((MemberName) $6);
		int mod_flags = (int) $2;

		if ($3 != null) {
			ClassPart part = PartialContainer.CreatePart (
				current_namespace, current_class, name, mod_flags,
				(Attributes) $1, Kind.Class, (Location) $3);

			current_container = part.PartialContainer;
			current_class = part;
		} else {
			if ((mod_flags & Modifiers.STATIC) != 0) {
				current_class = new StaticClass (
					current_namespace, current_class, name,
					mod_flags, (Attributes) $1);
			} else {
				current_class = new Class (
					current_namespace, current_class, name,
					mod_flags, (Attributes) $1);
			}

			current_container.AddClassOrStruct (current_class);
			current_container = current_class;
			RootContext.Tree.RecordDecl (current_namespace.NS, name, current_class);
		}
	  }
	  opt_class_base
	  opt_type_parameter_constraints_clauses
	  {
		lexer.ConstraintsParsing = false;

		if ($8 != null) {
			if (current_class.Name == "System.Object") {
				Report.Error (537, current_class.Location,
					      "The class System.Object cannot have a base " +
					      "class or implement an interface.");
			}
			current_class.Bases = (ArrayList) $8;
		}

		current_class.SetParameterInfo ((ArrayList) $9);

		if (RootContext.Documentation != null) {
			current_class.DocComment = Lexer.consume_doc_comment ();
			Lexer.doc_state = XmlCommentState.Allowed;
		}
	  }
	  class_body
	  {
		if (RootContext.Documentation != null)
			Lexer.doc_state = XmlCommentState.Allowed;
	  }
	  opt_semicolon 
	  {
		$$ = pop_current_class ();
	  }
	;	

opt_partial
	: /* empty */
	  { $$ = null; }
	| PARTIAL
	  { $$ = $1; } // location
	;

opt_modifiers
	: /* empty */		{ $$ = (int) 0; }
	| modifiers
	;

modifiers
	: modifier
	| modifiers modifier
	  { 
		int m1 = (int) $1;
		int m2 = (int) $2;

		if ((m1 & m2) != 0) {
			Location l = lexer.Location;
			Report.Error (1004, l, "Duplicate `{0}' modifier", Modifiers.Name (m2));
		}
		$$ = (int) (m1 | m2);
	  }
        ;

modifier
	: NEW			{ $$ = Modifiers.NEW; }
	| PUBLIC		{ $$ = Modifiers.PUBLIC; }
	| PROTECTED		{ $$ = Modifiers.PROTECTED; }
	| INTERNAL		{ $$ = Modifiers.INTERNAL; }
	| PRIVATE		{ $$ = Modifiers.PRIVATE; }
	| ABSTRACT		{ $$ = Modifiers.ABSTRACT; }
	| SEALED		{ $$ = Modifiers.SEALED; }
	| STATIC		{ $$ = Modifiers.STATIC; }
	| READONLY		{ $$ = Modifiers.READONLY; }
	| VIRTUAL		{ $$ = Modifiers.VIRTUAL; }
	| OVERRIDE 		{ $$ = Modifiers.OVERRIDE; }
	| EXTERN		{ $$ = Modifiers.EXTERN; }
	| VOLATILE		{ $$ = Modifiers.VOLATILE; }
	| UNSAFE		{ $$ = Modifiers.UNSAFE; }
	;

opt_class_base
	: /* empty */		{ $$ = null; }
	| class_base		{ $$ = $1;   }
	;

class_base
	: COLON type_list { $$ = $2; }
	;

opt_type_parameter_constraints_clauses
	: /* empty */		{ $$ = null; }
	| type_parameter_constraints_clauses 
	  { $$ = $1; }
	;

type_parameter_constraints_clauses
	: type_parameter_constraints_clause {
		ArrayList constraints = new ArrayList (1);
		constraints.Add ($1);
		$$ = constraints;
	  }
	| type_parameter_constraints_clauses type_parameter_constraints_clause {
		ArrayList constraints = (ArrayList) $1;

		constraints.Add ($2);
		$$ = constraints;
	  }
	; 

type_parameter_constraints_clause
	: WHERE IDENTIFIER COLON type_parameter_constraints {
		LocatedToken lt = (LocatedToken) $2;
		$$ = new Constraints (lt.Value, (ArrayList) $4, lt.Location);
	  }
	; 

type_parameter_constraints
	: type_parameter_constraint {
		ArrayList constraints = new ArrayList (1);
		constraints.Add ($1);
		$$ = constraints;
	  }
	| type_parameter_constraints COMMA type_parameter_constraint {
		ArrayList constraints = (ArrayList) $1;

		constraints.Add ($3);
		$$ = constraints;
	  }
	;

type_parameter_constraint
	: type
	| NEW OPEN_PARENS CLOSE_PARENS {
		$$ = SpecialConstraint.Constructor;
	  }
	| CLASS {
		$$ = SpecialConstraint.ReferenceType;
	  }
	| STRUCT {
		$$ = SpecialConstraint.ValueType;
	  }
	;

//
// Statements (8.2)
//

//
// A block is "contained" on the following places:
//	method_body
//	property_declaration as part of the accessor body (get/set)
//      operator_declaration
//	constructor_declaration
//	destructor_declaration
//	event_declaration as part of add_accessor_declaration or remove_accessor_declaration
//      
block
	: OPEN_BRACE 
	  {
		if (current_block == null){
			current_block = new ToplevelBlock ((ToplevelBlock) top_current_block, current_local_parameters, (Location) $1);
			top_current_block = current_block;
		} else {
			current_block = new Block (current_block, (Location) $1, Location.Null);
		}
	  } 
	  opt_statement_list CLOSE_BRACE 
	  { 
		while (current_block.Implicit)
			current_block = current_block.Parent;
		$$ = current_block;
		current_block.SetEndLocation ((Location) $4);
		current_block = current_block.Parent;
		if (current_block == null)
			top_current_block = null;
	  }
	;

opt_statement_list
	: /* empty */
	| statement_list 
	;

statement_list
	: statement
	| statement_list statement
	;

statement
	: declaration_statement
	  {
		if ($1 != null && (Block) $1 != current_block){
			current_block.AddStatement ((Statement) $1);
			current_block = (Block) $1;
		}
	  }
	| valid_declaration_statement
	  {
		current_block.AddStatement ((Statement) $1);
	  }
	| labeled_statement
	;

valid_declaration_statement
	: block
	| empty_statement
        | expression_statement
	| selection_statement
	| iteration_statement
	| jump_statement		  
	| try_statement
	| checked_statement
	| unchecked_statement
	| lock_statement
	| using_statement
	| unsafe_statement
	| fixed_statement
	;

embedded_statement
	: valid_declaration_statement
	| declaration_statement
	  {
		  Report.Error (1023, GetLocation ($1), "An embedded statement may not be a declaration or labeled statement");
		  $$ = null;
	  }
	| labeled_statement
	  {
		  Report.Error (1023, GetLocation ($1), "An embedded statement may not be a declaration or labeled statement");
		  $$ = null;
	  }
	;

empty_statement
	: SEMICOLON
	  {
		  $$ = EmptyStatement.Value;
	  }
	;

labeled_statement
	: IDENTIFIER COLON 
	  {
		LocatedToken lt = (LocatedToken) $1;
		LabeledStatement labeled = new LabeledStatement (lt.Value, lt.Location);

		if (current_block.AddLabel (lt.Value, labeled, lt.Location))
			current_block.AddStatement (labeled);
	  }
	  statement
	;

declaration_statement
	: local_variable_declaration SEMICOLON
	  {
		current_array_type = null;
		if ($1 != null){
			DictionaryEntry de = (DictionaryEntry) $1;
			Expression e = (Expression) de.Key;

			$$ = declare_local_variables (e, (ArrayList) de.Value, e.Location);
		}
	  }

	| local_constant_declaration SEMICOLON
	  {
		current_array_type = null;
		if ($1 != null){
			DictionaryEntry de = (DictionaryEntry) $1;

			$$ = declare_local_constants ((Expression) de.Key, (ArrayList) de.Value);
		}
	  }
	;

/* 
 * The following is from Rhys' grammar:
 * > Types in local variable declarations must be recognized as 
 * > expressions to prevent reduce/reduce errors in the grammar.
 * > The expressions are converted into types during semantic analysis.
 */
local_variable_type
	: primary_expression opt_rank_specifier_or_nullable
	  { 
		// FIXME: Do something smart here regarding the composition of the type.

		// Ok, the above "primary_expression" is there to get rid of
		// both reduce/reduce and shift/reduces in the grammar, it should
		// really just be "type_name".  If you use type_name, a reduce/reduce
		// creeps up.  If you use namespace_or_type_name (which is all we need
		// really) two shift/reduces appear.
		// 

		// So the super-trick is that primary_expression
		// can only be either a SimpleName or a MemberAccess. 
		// The MemberAccess case arises when you have a fully qualified type-name like :
		// Foo.Bar.Blah i;
		// SimpleName is when you have
		// Blah i;
		  
		Expression expr = (Expression) $1;  
		if (!(expr is SimpleName || expr is MemberAccess || expr is ComposedCast || expr is ConstructedType || expr is QualifiedAliasMember)) {
			Error_ExpectingTypeName (expr);
			$$ = null;
		} else {
			//
			// So we extract the string corresponding to the SimpleName
			// or MemberAccess
			// 

			if ((string) $2 == "")
				$$ = $1;
			else
				$$ = new ComposedCast ((Expression) $1, (string) $2);
		}
	  }
	| builtin_types opt_rank_specifier_or_nullable
	  {
		if ((string) $2 == "")
			$$ = $1;
		else
			$$ = current_array_type = new ComposedCast ((Expression) $1, (string) $2, lexer.Location);
	  }
        ;

local_variable_pointer_type
	: primary_expression STAR
	  {
		Expression expr = (Expression) $1;  

		if (!(expr is SimpleName || expr is MemberAccess || expr is ComposedCast || expr is ConstructedType || expr is QualifiedAliasMember)) {
			Error_ExpectingTypeName (expr);

			$$ = null;
		} else 
			$$ = new ComposedCast ((Expression) $1, "*");
	  }
        | builtin_types STAR
	  {
		$$ = new ComposedCast ((Expression) $1, "*", lexer.Location);
	  }
        | VOID STAR
	  {
		$$ = new ComposedCast (TypeManager.system_void_expr, "*", (Location) $1);
	  }
	| local_variable_pointer_type STAR
          {
		$$ = new ComposedCast ((Expression) $1, "*");
	  }
        ;

local_variable_declaration
	: local_variable_type variable_declarators
	  {
		if ($1 != null)
			$$ = new DictionaryEntry ($1, $2);
		else
			$$ = null;
	  }
        | local_variable_pointer_type opt_rank_specifier_or_nullable variable_declarators
	  {
		if ($1 != null){
			Expression t;

			if ((string) $2 == "")
				t = (Expression) $1;
			else
				t = new ComposedCast ((Expression) $1, (string) $2);
			$$ = new DictionaryEntry (t, $3);
		} else 
			$$ = null;
	  }
 	;

local_constant_declaration
	: CONST local_variable_type constant_declarators
	  {
		if ($2 != null)
			$$ = new DictionaryEntry ($2, $3);
		else
			$$ = null;
	  }
	;

expression_statement
	: statement_expression SEMICOLON { $$ = $1; }
	;

	//
	// We have to do the wrapping here and not in the case above,
	// because statement_expression is used for example in for_statement
	//
statement_expression
	: expression
	  {
		Expression expr = (Expression) $1;
		ExpressionStatement s = expr as ExpressionStatement;
		if (s == null) {
			Report.Error (201, expr.Location, "Only assignment, call, increment, decrement, and new object expressions can be used as a statement");
			$$ = null;
		}
		$$ = new StatementExpression (s);
	  }
	| error
	  {
		Report.Error (1002, GetLocation ($1), "Expecting `;'");
		$$ = null;
	  }
	;

object_creation_expression
	: object_or_delegate_creation_expression
	  { note ("complain if this is a delegate maybe?"); } 
	;

selection_statement
	: if_statement
	| switch_statement
	; 

if_statement
	: IF OPEN_PARENS boolean_expression CLOSE_PARENS 
	  embedded_statement
	  { 
		Location l = (Location) $1;

		$$ = new If ((Expression) $3, (Statement) $5, l);

		// FIXME: location for warning should be loc property of $5.
		if ($5 == EmptyStatement.Value)
			Report.Warning (642, 3, l, "Possible mistaken empty statement");

	  }
	| IF OPEN_PARENS boolean_expression CLOSE_PARENS
	  embedded_statement ELSE embedded_statement
	  {
		Location l = (Location) $1;

		$$ = new If ((Expression) $3, (Statement) $5, (Statement) $7, l);

		// FIXME: location for warning should be loc property of $5 and $7.
		if ($5 == EmptyStatement.Value)
			Report.Warning (642, 3, l, "Possible mistaken empty statement");
		if ($7 == EmptyStatement.Value)
			Report.Warning (642, 3, l, "Possible mistaken empty statement");
	  }
	;

switch_statement
	: SWITCH OPEN_PARENS
	  { 
		switch_stack.Push (current_block);
	  }
	  expression CLOSE_PARENS 
	  switch_block
	  {
		$$ = new Switch ((Expression) $4, (ArrayList) $6, (Location) $1);
		current_block = (Block) switch_stack.Pop ();
	  }
	;

switch_block
	: OPEN_BRACE
	  opt_switch_sections
	  CLOSE_BRACE
	  {
		$$ = $2;
	  }
	;

opt_switch_sections
	: /* empty */ 		
          {
	  	Report.Error (1522, lexer.Location, "Empty switch block"); 
	  }
	| switch_sections
	;

switch_sections
	: switch_section 
	  {
		ArrayList sections = new ArrayList (4);

		sections.Add ($1);
		$$ = sections;
	  }
	| switch_sections switch_section
	  {
		ArrayList sections = (ArrayList) $1;

		sections.Add ($2);
		$$ = sections;
	  }
	;

switch_section
	: switch_labels
	  {
		current_block = current_block.CreateSwitchBlock (lexer.Location);
	  }
 	  statement_list 
	  {
		Block topmost = current_block;

		while (topmost.Implicit)
			topmost = topmost.Parent;
		$$ = new SwitchSection ((ArrayList) $1, topmost);
	  }
	;

switch_labels
	: switch_label 
	  {
		ArrayList labels = new ArrayList (4);

		labels.Add ($1);
		$$ = labels;
	  }
	| switch_labels switch_label 
	  {
		ArrayList labels = (ArrayList) ($1);
		labels.Add ($2);

		$$ = labels;
	  }
	;

switch_label
	: CASE constant_expression COLON 	{ $$ = new SwitchLabel ((Expression) $2, (Location) $1); }
	| DEFAULT COLON				{ $$ = new SwitchLabel (null, (Location) $2); }
	| error {
		Report.Error (
			1523, GetLocation ($1), 
			"The keyword case or default must precede code in switch block");
	  }
	;

iteration_statement
	: while_statement
	| do_statement
	| for_statement
	| foreach_statement
	;

while_statement
	: WHILE OPEN_PARENS boolean_expression CLOSE_PARENS embedded_statement
	  {
		Location l = (Location) $1;
		$$ = new While ((Expression) $3, (Statement) $5, l);
	  }
	;

do_statement
	: DO embedded_statement 
	  WHILE OPEN_PARENS boolean_expression CLOSE_PARENS SEMICOLON
	  {
		Location l = (Location) $1;

		$$ = new Do ((Statement) $2, (Expression) $5, l);
	  }
	;

for_statement
	: FOR OPEN_PARENS 
	  opt_for_initializer SEMICOLON
	  {
		Block assign_block = new Block (current_block);
		current_block = assign_block;

		if ($3 is DictionaryEntry){
			DictionaryEntry de = (DictionaryEntry) $3;
			
			Expression type = (Expression) de.Key;
			ArrayList var_declarators = (ArrayList) de.Value;

			foreach (VariableDeclaration decl in var_declarators){

				LocalInfo vi;

				vi = current_block.AddVariable (type, decl.identifier, decl.Location);
				if (vi == null)
					continue;

				Location l = lexer.Location;
				Expression expr = decl.expression_or_array_initializer;
					
				LocalVariableReference var;
				var = new LocalVariableReference (assign_block, decl.identifier, l);

				if (expr != null) {
					Assign a = new Assign (var, expr, decl.Location);
					
					assign_block.AddStatement (new StatementExpression (a));
				}
			}
			
			// Note: the $$ below refers to the value of this code block, not of the LHS non-terminal.
			// This can be referred to as $5 below.
			$$ = null;
		} else {
			$$ = $3;
		}
	  } 
	  opt_for_condition SEMICOLON
	  opt_for_iterator CLOSE_PARENS 
	  embedded_statement
	  {
		Location l = (Location) $1;

		For f = new For ((Statement) $5, (Expression) $6, (Statement) $8, (Statement) $10, l);

		current_block.AddStatement (f);
		while (current_block.Implicit)
			current_block = current_block.Parent;
		$$ = current_block;
		current_block = current_block.Parent;
	  }
	;

opt_for_initializer
	: /* empty */		{ $$ = EmptyStatement.Value; }
	| for_initializer	
	;

for_initializer
	: local_variable_declaration
	| statement_expression_list
	;

opt_for_condition
	: /* empty */		{ $$ = null; }
	| boolean_expression
	;

opt_for_iterator
	: /* empty */		{ $$ = EmptyStatement.Value; }
	| for_iterator
	;

for_iterator
	: statement_expression_list
	;

statement_expression_list
	: statement_expression	
	  {
		// CHANGE: was `null'
		Statement s = (Statement) $1;
		Block b = new Block (current_block, Block.Flags.Implicit, s.loc, lexer.Location);   

		b.AddStatement (s);
		$$ = b;
	  }
	| statement_expression_list COMMA statement_expression
	  {
		Block b = (Block) $1;

		b.AddStatement ((Statement) $3);
		$$ = $1;
	  }
	;

foreach_statement
	: FOREACH OPEN_PARENS type IN expression CLOSE_PARENS
	  {
		Report.Error (230, (Location) $1, "Type and identifier are both required in a foreach statement");
		$$ = null;
	  }
	| FOREACH OPEN_PARENS type IDENTIFIER IN
	  expression CLOSE_PARENS 
	  {
		Block foreach_block = new Block (current_block);
		current_block = foreach_block;

		LocatedToken lt = (LocatedToken) $4;
		Location l = lt.Location;
		LocalInfo vi;

		vi = foreach_block.AddVariable ((Expression) $3, lt.Value, l);
		if (vi != null) {
			vi.SetReadOnlyContext (LocalInfo.ReadOnlyContext.Foreach);

			// Get a writable reference to this read-only variable.
			//
			// Note that the $$ here refers to the value of _this_ code block,
			// not the value of the LHS non-terminal.  This can be referred to as $8 below.
			$$ = new LocalVariableReference (foreach_block, lt.Value, l, vi, false);
		} else {
			$$ = null;
		}
	  } 
	  embedded_statement 
	  {
		LocalVariableReference v = (LocalVariableReference) $8;
		Location l = (Location) $1;

		if (v != null) {
			Foreach f = new Foreach ((Expression) $3, v, (Expression) $6, (Statement) $9, l);
			current_block.AddStatement (f);
		}

		while (current_block.Implicit)
			  current_block = current_block.Parent;
		$$ = current_block;
		current_block = current_block.Parent;
	  }
	;

jump_statement
	: break_statement
	| continue_statement
	| goto_statement
	| return_statement
	| throw_statement
	| yield_statement
	;

break_statement
	: BREAK SEMICOLON
	  {
		$$ = new Break ((Location) $1);
	  }
	;

continue_statement
	: CONTINUE SEMICOLON
	  {
		$$ = new Continue ((Location) $1);
	  }
	;

goto_statement
	: GOTO IDENTIFIER SEMICOLON 
	  {
		LocatedToken lt = (LocatedToken) $2;
		$$ = new Goto (lt.Value, lt.Location);
	  }
	| GOTO CASE constant_expression SEMICOLON
	  {
		$$ = new GotoCase ((Expression) $3, (Location) $1);
	  }
	| GOTO DEFAULT SEMICOLON 
	  {
		$$ = new GotoDefault ((Location) $1);
	  }
	; 

return_statement
	: RETURN opt_expression SEMICOLON
	  {
		$$ = new Return ((Expression) $2, (Location) $1);
	  }
	;

throw_statement
	: THROW opt_expression SEMICOLON
	  {
		$$ = new Throw ((Expression) $2, (Location) $1);
	  }
	;

yield_statement 
	: IDENTIFIER RETURN expression SEMICOLON
	  {
		LocatedToken lt = (LocatedToken) $1;
		string s = lt.Value;
		if (s != "yield"){
			Report.Error (1003, lt.Location, "; expected");
			$$ = null;
		}
		if (RootContext.Version == LanguageVersion.ISO_1){
			Report.FeatureIsNotStandardized (lt.Location, "yield statement");
			$$ = null;
		}
		if (iterator_container == null){
			Report.Error (204, lt.Location, "yield statement can only be used within a method, operator or property");
			$$ = null;
		} else {
			iterator_container.SetYields ();
			$$ = new Yield ((Expression) $3, lt.Location); 
		}
	  }
	| IDENTIFIER RETURN SEMICOLON
	  {
		Report.Error (1627, (Location) $2, "Expression expected after yield return");
		$$ = null;
	  }
	| IDENTIFIER BREAK SEMICOLON
	  {
		LocatedToken lt = (LocatedToken) $1;
		string s = lt.Value;
		if (s != "yield"){
			Report.Error (1003, lt.Location, "; expected");
			$$ = null;
		}
		if (RootContext.Version == LanguageVersion.ISO_1){
			Report.FeatureIsNotStandardized (lt.Location, "yield statement");
			$$ = null;
		}
		if (iterator_container == null){
			Report.Error (204, lt.Location, "yield statement can only be used within a method, operator or property");
			$$ = null;
		} else {
			iterator_container.SetYields ();
			$$ = new YieldBreak (lt.Location);
		}
	  }
	;

opt_expression
	: /* empty */
	| expression
	;

try_statement
	: TRY block catch_clauses 
	  {
		Catch g = null;
		
		ArrayList c = (ArrayList)$3;
		for (int i = 0; i < c.Count; ++i) {
			Catch cc = (Catch) c [i];
			if (cc.IsGeneral) {
				if (i != c.Count - 1)
					Report.Error (1017, cc.loc, "Try statement already has an empty catch block");
				g = cc;
				c.RemoveAt (i);
				i--;
			}
		}

		// Now s contains the list of specific catch clauses
		// and g contains the general one.
		
		$$ = new Try ((Block) $2, c, g, null, ((Block) $2).loc);
	  }
	| TRY block opt_catch_clauses FINALLY block
	  {
		Catch g = null;
		ArrayList s = new ArrayList (4);
		ArrayList catch_list = (ArrayList) $3;

		if (catch_list != null){
			foreach (Catch cc in catch_list) {
				if (cc.IsGeneral)
					g = cc;
				else
					s.Add (cc);
			}
		}

		$$ = new Try ((Block) $2, s, g, (Block) $5, ((Block) $2).loc);
	  }
	| TRY block error 
	  {
		Report.Error (1524, (Location) $1, "Expected catch or finally");
		$$ = null;
	  }
	;

opt_catch_clauses
	: /* empty */  { $$ = null; }
        | catch_clauses
	;

catch_clauses
	: catch_clause 
	  {
		ArrayList l = new ArrayList (4);

		l.Add ($1);
		$$ = l;
	  }
	| catch_clauses catch_clause
	  {
		ArrayList l = (ArrayList) $1;

		l.Add ($2);
		$$ = l;
	  }
	;

opt_identifier
	: /* empty */	{ $$ = null; }
	| IDENTIFIER
	;

catch_clause 
	: CATCH opt_catch_args 
	  {
		Expression type = null;
		
		if ($2 != null) {
			DictionaryEntry cc = (DictionaryEntry) $2;
			type = (Expression) cc.Key;
			LocatedToken lt = (LocatedToken) cc.Value;

			if (lt != null){
				ArrayList one = new ArrayList (4);

				one.Add (new VariableDeclaration (lt, null));

				current_block = new Block (current_block);
				Block b = declare_local_variables (type, one, lt.Location);
				current_block = b;
			}
		}
	  } block {
		Expression type = null;
		string id = null;
		Block var_block = null;

		if ($2 != null){
			DictionaryEntry cc = (DictionaryEntry) $2;
			type = (Expression) cc.Key;
			LocatedToken lt = (LocatedToken) cc.Value;

			if (lt != null){
				id = lt.Value;
				while (current_block.Implicit)
					current_block = current_block.Parent;
				var_block = current_block;
				current_block = current_block.Parent;
			}
		}

		$$ = new Catch (type, id, (Block) $4, var_block, ((Block) $4).loc);
	  }
        ;

opt_catch_args
	: /* empty */ { $$ = null; }
        | catch_args
	;	  

catch_args 
        : OPEN_PARENS type opt_identifier CLOSE_PARENS 
          {
		$$ = new DictionaryEntry ($2, $3);
	  }
        ;


checked_statement
	: CHECKED block
	  {
		$$ = new Checked ((Block) $2);
	  }
	;

unchecked_statement
	: UNCHECKED block
	  {
		$$ = new Unchecked ((Block) $2);
	  }
	;

unsafe_statement
	: UNSAFE 
	  {
		RootContext.CheckUnsafeOption ((Location) $1);
	  } block {
		$$ = new Unsafe ((Block) $3);
	  }
	;

fixed_statement
	: FIXED OPEN_PARENS 
	  type fixed_pointer_declarators 
	  CLOSE_PARENS
	  {
		ArrayList list = (ArrayList) $4;
		Expression type = (Expression) $3;
		Location l = (Location) $1;
		int top = list.Count;

		Block assign_block = new Block (current_block);
		current_block = assign_block;

		for (int i = 0; i < top; i++){
			Pair p = (Pair) list [i];
			LocalInfo v;

			v = current_block.AddVariable (type, (string) p.First, l);
			if (v == null)
				continue;

			v.SetReadOnlyContext (LocalInfo.ReadOnlyContext.Fixed);
			v.Pinned = true;
			p.First = v;
			list [i] = p;
		}
	  }
	  embedded_statement 
	  {
		Location l = (Location) $1;

		Fixed f = new Fixed ((Expression) $3, (ArrayList) $4, (Statement) $7, l);

		current_block.AddStatement (f);
		while (current_block.Implicit)
			current_block = current_block.Parent;
		$$ = current_block;
		current_block = current_block.Parent;
	  }
	;

fixed_pointer_declarators
	: fixed_pointer_declarator	{ 
	   	ArrayList declarators = new ArrayList (4);
	   	if ($1 != null)
			declarators.Add ($1);
		$$ = declarators;
	  }
	| fixed_pointer_declarators COMMA fixed_pointer_declarator
	  {
		ArrayList declarators = (ArrayList) $1;
		if ($3 != null)
			declarators.Add ($3);
		$$ = declarators;
	  }
	;

fixed_pointer_declarator
	: IDENTIFIER ASSIGN expression
	  {
		LocatedToken lt = (LocatedToken) $1;
		// FIXME: keep location
		$$ = new Pair (lt.Value, $3);
	  }
	| IDENTIFIER
	  {
		Report.Error (210, ((LocatedToken) $1).Location, "You must provide an initializer in a fixed or using statement declaration");
		$$ = null;
	  }
	;

lock_statement
	: LOCK OPEN_PARENS expression CLOSE_PARENS 
	  {
		//
 	  } 
	  embedded_statement
	  {
		$$ = new Lock ((Expression) $3, (Statement) $6, (Location) $1);
	  }
	;

using_statement
	: USING OPEN_PARENS resource_acquisition CLOSE_PARENS
	  {
		Block assign_block = new Block (current_block);
		current_block = assign_block;

		if ($3 is DictionaryEntry){
			DictionaryEntry de = (DictionaryEntry) $3;
			Location l = (Location) $1;

			Expression type = (Expression) de.Key;
			ArrayList var_declarators = (ArrayList) de.Value;

			ArrayList vars = new ArrayList (4);

			foreach (VariableDeclaration decl in var_declarators){

				LocalInfo vi = current_block.AddVariable (type, decl.identifier, decl.Location);
				if (vi == null)
					continue;
				vi.SetReadOnlyContext (LocalInfo.ReadOnlyContext.Using);

				Expression expr = decl.expression_or_array_initializer;
				if (expr == null) {
					Report.Error (210, l, "You must provide an initializer in a fixed or using statement declaration");
				}

				LocalVariableReference var;

				// Get a writable reference to this read-only variable.
				var = new LocalVariableReference (assign_block, decl.identifier, l, vi, false);

				// This is so that it is not a warning on using variables
				vi.Used = true;

				vars.Add (new DictionaryEntry (var, expr));				

				// Assign a = new Assign (var, expr, decl.Location);
				// assign_block.AddStatement (new StatementExpression (a));
			}

			// Note: the $$ here refers to the value of this code block and not of the LHS non-terminal.
			// It can be referred to as $5 below.
			$$ = new DictionaryEntry (type, vars);
		 } else {
			$$ = $3;
		 }
	  } 
	  embedded_statement
	  {
		Using u = new Using ($5, (Statement) $6, (Location) $1);
		current_block.AddStatement (u);
		while (current_block.Implicit)
			current_block = current_block.Parent;
		$$ = current_block;
		current_block = current_block.Parent;
	  }
	; 

resource_acquisition
	: local_variable_declaration
	| expression
	;

%%

// <summary>
//   A class used to pass around variable declarations and constants
// </summary>
public class VariableDeclaration {
	public string identifier;
	public Expression expression_or_array_initializer;
	public Location Location;
	public Attributes OptAttributes;
	public string DocComment;

	public VariableDeclaration (LocatedToken lt, object eoai, Attributes opt_attrs)
	{
		this.identifier = lt.Value;
		if (eoai is ArrayList) {
			if (CSharpParser.current_array_type == null)
				Report.Error (622, lt.Location,
					"Can only use array initializer expressions to assign to array types. Try using a new expression instead.");
			this.expression_or_array_initializer = new ArrayCreation (CSharpParser.current_array_type, "", (ArrayList)eoai, lt.Location);
		} else {
			this.expression_or_array_initializer = (Expression)eoai;
		}
		this.Location = lt.Location;
		this.OptAttributes = opt_attrs;
	}

	public VariableDeclaration (LocatedToken lt, object eoai) : this (lt, eoai, null)
	{
	}
}

// <summary>
//   A class used to hold info about an indexer declarator
// </summary>
public class IndexerDeclaration {
	public Expression type;
	public MemberName interface_type;
	public Parameters param_list;
	public Location location;

	public IndexerDeclaration (Expression type, MemberName interface_type,
				   Parameters param_list, Location loc)
	{
		this.type = type;
		this.interface_type = interface_type;
		this.param_list = param_list;
		this.location = loc;
	}
}

//
// We use this when we do not have an object in advance that is an IIteratorContainer
//
public class SimpleIteratorContainer : IIteratorContainer {
	public bool Yields;

	public static SimpleIteratorContainer Simple = new SimpleIteratorContainer ();

	//
	// Reset and return
	//
	public static SimpleIteratorContainer GetSimple () { 
		Simple.Yields = false;
		return Simple;
	}

	public void SetYields () { Yields = true; } 
}

// <summary>
//  A class used to hold info about an operator declarator
// </summary>
public class OperatorDeclaration {
	public Operator.OpType optype;
	public Expression ret_type, arg1type, arg2type;
	public string arg1name, arg2name;
	public Location location;

	public OperatorDeclaration (Operator.OpType op, Expression ret_type, 
				    Expression arg1type, string arg1name,
				    Expression arg2type, string arg2name, Location location)
	{
		optype = op;
		this.ret_type = ret_type;
		this.arg1type = arg1type;
		this.arg1name = arg1name;
		this.arg2type = arg2type;
		this.arg2name = arg2name;
		this.location = location;
	}

}

void Error_ExpectingTypeName (Expression expr)
{
	if (expr is Invocation){
		Report.Error (1002, expr.Location, "Expecting `;'");
	} else {
		Report.Error (201, expr.Location, "Only assignment, call, increment, decrement, and new object expressions can be used as a statement");
	}
}

TypeContainer pop_current_class ()
{
	TypeContainer retval = current_class;

	current_class = (TypeContainer) current_class.Parent;
	current_container = (TypeContainer) current_container.Parent;

	if (current_class != current_container) {
		if (((ClassPart) current_class).PartialContainer != current_container)
			throw new InternalErrorException ("current_container and current_class are out of sync");
	} else if (current_container is ClassPart)
		current_container = ((ClassPart) current_class).PartialContainer;

	return retval;
}

// <summary>
//   Given the @class_name name, it creates a fully qualified name
//   based on the containing declaration space
// </summary>
MemberName
MakeName (MemberName class_name)
{
	Namespace ns = current_namespace.NS;

	if (current_container.Name == ""){
		if (ns.Name != "")
			return new MemberName (ns.MemberName, class_name);
		else
			return class_name;
	} else {
		return new MemberName (current_container.MemberName, class_name);
	}
}

Block declare_local_variables (Expression type, ArrayList variable_declarators, Location loc)
{
	Block implicit_block;
	ArrayList inits = null;

	//
	// We use the `Used' property to check whether statements
	// have been added to the current block.  If so, we need
	// to create another block to contain the new declaration
	// otherwise, as an optimization, we use the same block to
	// add the declaration.
	//
	// FIXME: A further optimization is to check if the statements
	// that were added were added as part of the initialization
	// below.  In which case, no other statements have been executed
	// and we might be able to reduce the number of blocks for
	// situations like this:
	//
	// int j = 1;  int k = j + 1;
	//
	if (current_block.Used)
		implicit_block = new Block (current_block, Block.Flags.Implicit, loc, Location.Null);
	else
		implicit_block = current_block;

	foreach (VariableDeclaration decl in variable_declarators){

		if (implicit_block.AddVariable (type, decl.identifier, decl.Location) != null) {
			if (decl.expression_or_array_initializer != null){
				if (inits == null)
					inits = new ArrayList (4);
				inits.Add (decl);
			}
		}
	}

	if (inits == null)
		return implicit_block;

	foreach (VariableDeclaration decl in inits){
		Assign assign;
		Expression expr = decl.expression_or_array_initializer;
		
		LocalVariableReference var;
		var = new LocalVariableReference (implicit_block, decl.identifier, loc);

		assign = new Assign (var, expr, decl.Location);

		implicit_block.AddStatement (new StatementExpression (assign));
	}
	
	return implicit_block;
}

Block declare_local_constants (Expression type, ArrayList declarators)
{
	Block implicit_block;

	if (current_block.Used)
		implicit_block = new Block (current_block, Block.Flags.Implicit);
	else
		implicit_block = current_block;

	foreach (VariableDeclaration decl in declarators){
		implicit_block.AddConstant (type, decl.identifier, (Expression) decl.expression_or_array_initializer, decl.Location);
	}
	
	return implicit_block;
}

void CheckAttributeTarget (string a, Location l)
{
	switch (a) {

	case "assembly" : case "module" : case "field" : case "method" : case "param" : case "property" : case "type" :
		return;
		
	default :
		Report.Error (658, l, "`" + a + "' is an invalid attribute target");
		break;
	}

}

void CheckUnaryOperator (Operator.OpType op, Location l)
{
	switch (op) {
		
	case Operator.OpType.LogicalNot: 
	case Operator.OpType.OnesComplement: 
	case Operator.OpType.Increment:
	case Operator.OpType.Decrement:
	case Operator.OpType.True: 
	case Operator.OpType.False: 
	case Operator.OpType.Addition: 
	case Operator.OpType.Subtraction:
		
		break;
		
	default :
		Report.Error (1019, l, "Overloadable unary operator expected"); 
		break;
		
	}
}

void CheckBinaryOperator (Operator.OpType op, Location l)
{
	switch (op) {
		
	case Operator.OpType.Addition: 
	case Operator.OpType.Subtraction: 
	case Operator.OpType.Multiply:
	case Operator.OpType.Division:
	case Operator.OpType.Modulus: 
	case Operator.OpType.BitwiseAnd: 
	case Operator.OpType.BitwiseOr:
	case Operator.OpType.ExclusiveOr: 
	case Operator.OpType.LeftShift: 
	case Operator.OpType.RightShift:
	case Operator.OpType.Equality: 
	case Operator.OpType.Inequality:
	case Operator.OpType.GreaterThan: 
	case Operator.OpType.LessThan: 
	case Operator.OpType.GreaterThanOrEqual:
	case Operator.OpType.LessThanOrEqual:
		break;
		
	default :
		Report.Error (1020, l, "Overloadable binary operator expected");
		break;
	}
	
}

void syntax_error (Location l, string msg)
{
	Report.Error (1003, l, "Syntax error, " + msg);
}

void note (string s)
{
	// Used to put annotations
}

Tokenizer lexer;

public Tokenizer Lexer {
	get {
		return lexer;
	}
}		   

public CSharpParser (SeekableStreamReader reader, SourceFile file, ArrayList defines)
{
	current_namespace = new NamespaceEntry (null, file, null, Location.Null);
	this.name = file.Name;
	this.file = file;
	current_container = RootContext.Tree.Types;
	// TODO: Make RootContext.Tree.Types a PartialContainer.
	current_class = current_container;
	current_container.NamespaceEntry = current_namespace;
	oob_stack = new Stack ();
	switch_stack = new Stack ();

	lexer = new Tokenizer (reader, file, defines);
}

public void parse ()
{
	int errors = Report.Errors;
	try {
		if (yacc_verbose_flag > 1)
			yyparse (lexer, new yydebug.yyDebugSimple ());
		else
			yyparse (lexer);
		Tokenizer tokenizer = lexer as Tokenizer;
		tokenizer.cleanup ();
	} catch (Exception e){
		//
		// Removed for production use, use parser verbose to get the output.
		//
		// Console.WriteLine (e);
		if (Report.Errors == errors)
			Report.Error (-25, lexer.Location, "Parsing error");
		if (yacc_verbose_flag > 0)
			Console.WriteLine (e);
	}

	RootContext.Tree.Types.NamespaceEntry = null;
}

void CheckToken (int error, int yyToken, string msg, Location loc)
{
	if (yyToken >= Token.FIRST_KEYWORD && yyToken <= Token.LAST_KEYWORD)
		Report.Error (error, loc, "{0}: `{1}' is a keyword", msg, yyNames [yyToken].ToLower ());
	else
		Report.Error (error, loc, msg);
}

void CheckIdentifierToken (int yyToken, Location loc)
{
	CheckToken (1041, yyToken, "Identifier expected", loc);
}

string ConsumeStoredComment ()
{
	string s = tmpComment;
	tmpComment = null;
	Lexer.doc_state = XmlCommentState.Allowed;
	return s;
}

Location GetLocation (object obj)
{
	if (obj is MemberCore)
		return ((MemberCore) obj).Location;
	if (obj is MemberName)
		return ((MemberName) obj).Location;
	if (obj is LocatedToken)
		return ((LocatedToken) obj).Location;
	if (obj is Location)
		return (Location) obj;
	return lexer.Location;
}

/* end end end */
}