File: parser2.y

package info (click to toggle)
covered 0.7.10-7
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 9,040 kB
  • sloc: ansic: 48,809; yacc: 11,650; xml: 8,838; tcl: 7,698; sh: 3,925; lex: 2,240; makefile: 362; perl: 329
file content (5068 lines) | stat: -rw-r--r-- 109,683 bytes parent folder | download | duplicates (7)
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

%{
/*
 Copyright (c) 2006-2010 Trevor Williams

 This program is free software; you can redistribute it and/or modify
 it under the terms of the GNU General Public License as published by the Free Software
 Foundation; either version 2 of the License, or (at your option) any later version.

 This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
 without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 See the GNU General Public License for more details.

 You should have received a copy of the GNU General Public License along with this program;
 if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/

/*!
 \file     parser.c
 \author   Trevor Williams  (phase1geo@gmail.com)
 \date     12/14/2001
*/

#ifdef HAVE_CONFIG_H
#include "config.h"
#endif

#include <stdio.h>
#include <assert.h>
#include <stdlib.h>
#ifdef HAVE_STRING_H
#include <string.h>
#endif

#include "db.h"
#include "defines.h"
#include "expr.h"
#include "func_unit.h"
#include "gen_item.h"
#include "link.h"
#include "obfuscate.h"
#include "parser_misc.h"
#include "statement.h"
#include "static.h"
#include "util.h"
#include "vector.h"
#include "vsignal.h"

#define YYERROR_VERBOSE 1

/* Uncomment these lines to turn debugging on */
/*
#define YYDEBUG 1
int yydebug = 1;
*/

/* Recent version of bison expect that the user supply a
   YYLLOC_DEFAULT macro that makes up a yylloc value from existing
   values. I need to supply an explicit version to account for the
   text field, that otherwise won't be copied. */

#define YYRHSLOC(Rhs, K) ((Rhs)[K])
#define YYLLOC_DEFAULT(Current, Rhs, N)                                \
    do                                                                  \
      if (N)                                                            \
        {                                                               \
          (Current).first_line   = YYRHSLOC(Rhs, 1).first_line;         \
          (Current).first_column = YYRHSLOC(Rhs, 1).first_column;       \
          (Current).last_line    = YYRHSLOC(Rhs, N).last_line;          \
          (Current).last_column  = YYRHSLOC(Rhs, N).last_column;        \
          (Current).text         = YYRHSLOC(Rhs, 1).text;               \
        }                                                               \
      else                                                              \
        {                                                               \
          (Current).first_line   = (Current).last_line   =              \
            YYRHSLOC(Rhs, 0).last_line;                                 \
          (Current).first_column = (Current).last_column =              \
            YYRHSLOC(Rhs, 0).last_column;                               \
          (Current).text         = YYRHSLOC(Rhs, 0).text;               \
        }                                                               \
    while (0)

%}

%union {
  bool            logical;
  char*           text;
  int             integer;
  vector*         num;
  double          realtime;
  vsignal*        sig;
  expression*     expr;
  statement*      state;
  static_expr*    statexp;
  str_link*       strlink;
  exp_link*       explink;
  case_statement* case_stmt;
  attr_param*     attr_parm;
  exp_bind*       expbind;
  port_info*      portinfo;
  gen_item*       gitem;
  case_gitem*     case_gi;
  typedef_item*   typdef;
  func_unit*      funit;
};

%token <text>     IDENTIFIER SYSTEM_IDENTIFIER C_IDENTIFIER SIMPLE_IDENTIFIER ESCAPED_IDENTIFIER
%token <typdef>   TYPEDEF_IDENTIFIER
%token <text>     PATHPULSE_IDENTIFIER
%token <num>      NUMBER
%token <realtime> REALTIME
%token <num>      STRING
%token IGNORE
%token UNUSED_IDENTIFIER UNUSED_C_IDENTIFIER UNUSED_SIMPLE_IDENTIFIER UNUSED_ESCAPED_IDENTIFIER
%token UNUSED_PATHPULSE_IDENTIFIER
%token UNUSED_NUMBER
%token UNUSED_REALTIME
%token UNUSED_STRING UNUSED_SYSTEM_IDENTIFIER
%token K_LE K_GE K_EG K_EQ K_NE K_CEQ K_CNE K_LS K_RS K_SG K_PP K_PS K_PEQ K_PNE K_RSS K_LSS
%token K_ADD_A K_SUB_A K_MLT_A K_DIV_A K_MOD_A K_AND_A K_OR_A K_XOR_A K_LS_A K_RS_A K_ALS_A K_ARS_A K_INC K_DEC K_POW
%token K_PO_POS K_PO_NEG K_STARP K_PSTAR
%token K_LOR K_LAND K_NAND K_NOR K_NXOR K_TRIGGER
%token K_TU_S K_TU_MS K_TU_US K_TU_NS K_TU_PS K_TU_FS K_TU_STEP
%token K_INCDIR
%token K_always K_and K_assign K_begin K_buf K_bufif0 K_bufif1 K_case
%token K_casex K_casez K_cmos K_deassign K_default K_defparam K_disable
%token K_edge K_else K_end K_endcase K_endfunction K_endmodule I_endmodule
%token K_endprimitive K_endspecify K_endtable K_endtask K_event K_for
%token K_force K_forever K_fork K_function K_highz0 K_highz1 K_if
%token K_generate K_endgenerate K_genvar
%token K_initial K_inout K_input K_integer K_join K_large K_localparam
%token K_macromodule
%token K_medium K_module K_nand K_negedge K_nmos K_nor K_not K_notif0
%token K_notif1 K_or K_output K_parameter K_pmos K_posedge K_primitive
%token K_pull0 K_pull1 K_pulldown K_pullup K_rcmos K_shortreal K_real K_realtime
%token K_reg K_release K_repeat
%token K_rnmos K_rpmos K_rtran K_rtranif0 K_rtranif1
%token K_signed K_small K_specify
%token K_specparam K_strong0 K_strong1 K_supply0 K_supply1 K_table K_task
%token K_time K_tran K_tranif0 K_tranif1 K_tri K_tri0 K_tri1 K_triand
%token K_trior K_trireg K_vectored K_wait K_wand K_weak0 K_weak1
%token K_while K_wire
%token K_wor K_xnor K_xor
%token K_Shold K_Speriod K_Srecovery K_Ssetup K_Swidth K_Ssetuphold K_Sremoval K_Srecrem K_Sskew K_Stimeskew K_Sfullskew K_Snochange
%token K_automatic K_cell K_use K_library K_config K_endconfig K_design K_liblist K_instance
%token K_showcancelled K_noshowcancelled K_pulsestyle_onevent K_pulsestyle_ondetect

%token K_bit K_byte K_logic K_shortint K_int K_longint K_unsigned
%token K_unique K_priority K_do
%token K_always_comb K_always_latch K_always_ff
%token K_typedef K_type K_enum K_union K_struct K_packed
%token K_assert K_assume K_property K_endproperty K_cover K_sequence K_endsequence K_expect
%token K_program K_endprogram K_final K_void K_return K_continue K_break K_extern K_interface K_endinterface
%token K_class K_endclass K_extends K_package K_endpackage K_timeunit K_timeprecision K_ref K_bind K_const
%token K_new K_static K_protected K_local K_rand K_randc K_randcase K_constraint K_import K_export K_scalared K_chandle
%token K_context K_pure K_modport K_clocking K_iff K_intersect K_first_match K_throughout K_with K_within
%token K_dist K_covergroup K_endgroup K_coverpoint K_optionDOT K_type_optionDOT K_wildcard
%token K_bins K_illegal_bins K_ignore_bins K_cross K_binsof K_alias K_join_any K_join_none K_matches
%token K_tagged K_foreach K_randsequence K_ifnone K_randomize K_null K_inside K_super K_this K_wait_order
%token K_include K_Sroot K_Sunit K_endclocking K_virtual K_before K_forkjoin K_solve
%token K_DPI

%token K_TAND
%right '?' ':'
%left K_LOR
%left K_LAND
%left '|'
%left '^' K_NXOR K_NOR
%left '&' K_NAND
%left K_EQ K_NE K_CEQ K_CNE
%left K_GE K_LE '<' '>'
%left K_LS K_RS K_RSS K_LSS
%left '+' '-'
%left '*' '/' '%'
%left UNARY_PREC

/* to resolve dangling else ambiguity: */
%nonassoc K_else

%%

  /* SOURCE TEXT */
main
  : source_text
  | library_text
  |
  ;

  /* Library source text - CURRENTLY NOT SUPPORTED - TBD */

library_text
  : library_descriptions
  ;

library_description
  : library_declaration
  | include_statement
  | config_declaration
  ;

library_descriptions
  : library_description
  | library_descriptions library_description
  ;

library_declaration
  : K_library identifier file_path_specs { lex_start_library_options(); } incdir_opt { lex_end_library_options(); }
  ;

file_path_spec
  : STRING        { free_safe( $1 ); }
  | UNUSED_STRING
  ;

file_path_specs
  : file_path_spec
  | file_path_specs ',' file_path_spec
  ;

include_statement
  : K_include file_path_spec ; 
  ;

incdir_opt
  : K_INCDIR file_path_specs
  |
  ;

  /* Configuration source text - CURRENTLY NOT SUPPORTED - TBD */

config_declaration
  : K_config identifier ';' design_statement config_rule_statements_opt K_endconfig postfix_identifier_opt
  ;

design_statement
  : K_design inst_names_opt ';'
  ;

config_rule_statement
  : default_clause liblist_clause
  | inst_clause liblist_clause
  | inst_clause use_clause
  | cell_clause liblist_clause
  | cell_clause use_clause
  ;

config_rule_statements
  : config_rule_statement
  | config_rule_statements config_rule_statement
  ;

config_rule_statements_opt
  : config_rule_statements
  |
  ;

default_clause
  : K_default
  ;

inst_clause
  : K_instance inst_name
  ;

inst_name
  : identifier instance_identifiers_opt
  ;

inst_names
  : inst_name
  | inst_names inst_name
  ;

inst_names_opt
  : inst_names
  |
  ;

instance_identifiers
  : '.' identifier
  | instance_identifiers '.' identifier
  ;

instance_identifiers_opt
  : instance_identifiers
  |
  ;

cell_clause
  : K_cell inst_name
  ;

liblist_clause
  : K_liblist identifiers_opt
  ;

use_clause
  : K_use inst_name
  | K_use inst_name ':' K_config
  ;

  /* Configuration source text */

source_text
  : timeunits_declaration descriptions
  | descriptions
  ;

description
  : module_declaration
  | udp_declaration
  | interface_declaration
  | program_declaration
  | package_declaration
  | attribute_instances_opt package_item
  | attribute_instances_opt bind_directive
  ;

descriptions
  : description
  | descriptions description
  ;

module_nonansi_header
  : attribute_instances_opt module_keyword lifetime_opt identifier parameter_port_list_opt list_of_ports ';'
  ;

module_ansi_header
  : attribute_instances_opt module_keyword lifetime_opt identifier parameter_port_list_opt list_of_port_declarations_opt ';'
  ;

module_declaration
  : module_nonansi_header timeunits_declaration_opt module_items_opt K_endmodule postfix_identifier_opt
  | module_ansi_header timeunits_declaration_opt non_port_module_items_opt K_endmodule postfix_identifier_opt
  | attribute_instances_opt module_keyword lifetime_opt identifier '(' K_PS ')' ';' timeunits_declaration_opt module_items_opt K_endmodule postfix_identifier_opt
  | K_extern module_nonansi_header
  | K_extern module_ansi_header
  ;

module_keyword
  : K_module
  | K_macromodule
  ;

interface_nonansi_header
  : attribute_instances_opt K_interface lifetime_opt identifier parameter_port_list_opt list_of_ports ';'
  ;

interface_ansi_header
  : attribute_instances_opt K_interface lifetime_opt identifier parameter_port_list_opt list_of_port_declarations_opt ';' 
  ;

interface_declaration
  : interface_nonansi_header timeunits_declaration_opt interface_items_opt K_endinterface postfix_identifier_opt
  | interface_ansi_header timeunits_declaration_opt non_port_interface_items_opt K_endinterface postfix_identifier_opt
  | attribute_instances_opt K_interface identifier '(' K_PS ')' ';' timeunits_declaration_opt interface_items_opt K_endinterface postfix_identifier_opt
  | K_extern interface_nonansi_header
  | K_extern interface_ansi_header
  ;

program_nonansi_header
  : attribute_instances_opt K_program lifetime_opt identifier parameter_port_list_opt list_of_ports ';'
  ;

program_ansi_header
  : attribute_instances_opt K_program lifetime_opt identifier parameter_port_list_opt list_of_port_declarations_opt ';'
  ;

program_declaration
  : program_nonansi_header timeunits_declaration_opt program_items_opt K_endprogram postfix_identifier_opt
  | program_ansi_header timeunits_declaration_opt non_port_program_items_opt K_endprogram postfix_identifier_opt
  | attribute_instances_opt K_program identifier '(' K_PS ')' ';' timeunits_declaration_opt program_items_opt K_endprogram postfix_identifier_opt
  | K_extern program_nonansi_header
  | K_extern program_ansi_header
  ;

class_declaration
  : K_class lifetime_opt identifier parameter_port_list_opt class_extension_opt ';' class_items_opt K_endclass postfix_identifier_opt
  | K_virtual K_class lifetime_opt identifier parameter_port_list_opt class_extension_opt ';' class_items_opt K_endclass postfix_identifier_opt
  ;

class_extension_opt
  : K_extends class_type list_of_arguments_opt
  |
  ;

package_declaration
  : attribute_instances_opt K_package identifier ';' timeunits_declaration_opt package_attrib_items_opt K_endpackage postfix_identifier_opt
  ;

package_attrib_item
  : attribute_instances_opt package_item
  ;

package_attrib_items
  : package_attrib_item
  | package_attrib_items package_attrib_items
  ;

package_attrib_items_opt
  : package_attrib_items
  |
  ;

timeunits_declaration
  : K_timeunit time_literal ';'
  | K_timeprecision time_literal ';'
  | K_timeunit time_literal ';' K_timeprecision time_literal ';'
  | K_timeprecision time_literal ';' K_timeunit time_literal ';'
  ;

timeunits_declaration_opt
  : timeunits_declaration
  |
  ;

  /* Module parameters and ports */
parameter_port_list
  : '#' '(' list_of_param_assignments parameter_port_list_declarations_opt ')'
  | '#' '(' parameter_port_declaration parameter_port_list_declarations_opt ')'

parameter_port_list_opt
  : parameter_port_list
  |
  ;

parameter_port_declaration
  : parameter_declaration
  | data_type list_of_param_assignments
  | K_type list_of_type_assignments
  ;

parameter_port_list_declaration
  : ',' parameter_port_declaration
  ;

parameter_port_list_declarations
  : parameter_port_list_declaration
  | parameter_port_list_declarations parameter_port_list_declaration
  ;

parameter_port_list_declarations_opt
  : parameter_port_list_declarations
  |
  ;

list_of_ports
  : '(' port port_lists_opt ')'
  ;

port_list
  : ',' port
  ;

port_lists
  : port_list
  | port_lists port_list
  ;

port_lists_opt
  : port_lists
  |
  ;

list_of_port_declarations
  : '(' port_declarations_opt ')'
  ;

list_of_port_declarations_opt
  : list_of_port_declarations
  |
  ;

port_declarations_opt
  : attribute_instances_opt ansi_port_declaration ansi_port_declarations_opt
  |
  ;

port_declaration
  : attribute_instances_opt inout_declaration
  | attribute_instances_opt input_declaration
  | attribute_instances_opt output_declaration
  | attribute_instances_opt ref_declaration
  | attribute_instances_opt interface_port_declaration
  ;

port
  : port_expression_opt
  | '.' identifier '(' port_expression_opt ')'

port_expression
  : port_reference
  | '{' port_reference port_reference_list_opt '}'
  ;

port_expression_opt
  : port_expression
  |
  ;

port_reference
  : identifier constant_select
  ;

port_reference_list
  : ',' port_reference
  | port_reference_list ',' port_reference
  ;

port_reference_list_opt
  : port_reference_list
  |
  ;

port_direction
  : K_input
  | K_output
  | K_inout
  | K_ref
  ;

port_direction_opt
  : port_direction
  |
  ;

net_port_header
  : port_direction_opt port_type
  ;

variable_port_header
  : port_direction_opt data_type
  ;

interface_port_header
  : identifier
  | identifier '.' identifier
  | K_interface
  | K_interface '.' identifier
  ;

ansi_port_declaration
  : identifier unpacked_dimensions_opt
  | net_port_header identifier unpacked_dimensions_opt
  | interface_port_header identifier unpacked_dimensions_opt
  | identifier variable_dimension
  | variable_port_header identifier variable_dimension
  | identifier variable_dimension '=' constant_expression
  | variable_port_header identifier variable_dimension '=' constant_expression
  | '.' identifier '(' expression_opt ')'
  | net_port_header '.' identifier '(' expression_opt ')'
  | variable_port_header '.' identifier '(' expression_opt ')'
  ;

ansi_port_declarations
  : ansi_port_declaration
  | ansi_port_declarations ansi_port_declaration
  ;

ansi_port_declarations_opt
  : ansi_port_declarations
  |
  ;

  /* Module items */
module_common_item
  : module_or_generate_item_declaration
  | interface_or_program_or_module_instantiation
  | concurrent_assertion_item
  | bind_directive
  | continuous_assign
  | net_alias
  | initial_construct
  | final_construct
  | always_construct
  ;

module_item
  : port_declaration ';'
  | non_port_module_item
  ;

module_items
  : module_item
  | module_items module_item
  ;

module_items_opt
  : module_items
  |
  ;

module_or_generate_item
  : attribute_instances_opt parameter_override
  | attribute_instances_opt gate_instantiation
  | attribute_instances_opt udp_instantiation
  | attribute_instances_opt module_common_item
  ;

module_or_generate_item_declaration
  : package_or_generate_item_declaration
  | genvar_declaration
  | clocking_declaration
  | K_default K_clocking identifier ';'
  ;

non_port_module_item
  : generated_module_instantiation
  | module_or_generate_item
  | specify_block
  | attribute_instances_opt specparam_declaration
  | program_declaration
  | module_declaration
  | timeunits_declaration 
  ;

non_port_module_items
  : non_port_module_item
  | non_port_module_items non_port_module_item
  ;

non_port_module_items_opt
  : non_port_module_items
  |
  ;

parameter_override
  : K_defparam list_of_defparam_assignments ';'
  ;

bind_directive
  : K_bind hierarchical_identifier constant_select bind_instantiation ';'
  ;

bind_instantiation
  : interface_or_program_or_module_instantiation 
  ;

  /* Interface items */
interface_or_generate_item
  : attribute_instances_opt module_common_item
  | attribute_instances_opt modport_declaration
  | attribute_instances_opt extern_tf_declaration
  ;

extern_tf_declaration
  : K_extern method_prototype ';'
  | K_extern K_forkjoin task_prototype ';'
  ;

interface_item
  : port_declaration ';'
  | non_port_interface_item
  ;

interface_items
  : interface_item
  | interface_items interface_item
  ;

interface_items_opt
  : interface_items
  |
  ;

non_port_interface_item
  : generated_interface_instantiation
  | attribute_instances_opt specparam_declaration
  | interface_or_generate_item
  | program_declaration
  | interface_declaration
  | timeunits_declaration 
  ;

non_port_interface_items
  : non_port_interface_item
  | non_port_interface_items non_port_interface_item
  ;

non_port_interface_items_opt
  : non_port_interface_items
  |
  ;

  /* Program items */
program_item
  : port_declaration ';'
  | non_port_program_item
  ;

program_items
  : program_item
  | program_items program_item
  ;

program_items_opt
  : program_items
  |
  ;

non_port_program_item
  : attribute_instances_opt continuous_assign
  | attribute_instances_opt module_or_generate_item_declaration
  | attribute_instances_opt specparam_declaration
  | attribute_instances_opt initial_construct
  | attribute_instances_opt concurrent_assertion_item
  | attribute_instances_opt timeunits_declaration 
  ;

non_port_program_items
  : non_port_program_item
  | non_port_program_items non_port_program_item
  ;

non_port_program_items_opt
  : non_port_program_items
  |
  ;

  /* Class items */
class_item
  : attribute_instances_opt class_property
  | attribute_instances_opt class_method
  | attribute_instances_opt class_constraint
  | attribute_instances_opt type_declaration
  | attribute_instances_opt class_declaration
  | attribute_instances_opt timeunits_declaration
  ;

class_items
  : class_item
  | class_items class_item
  ;

class_items_opt
  : class_items
  |
  ;

class_property
  : property_qualifiers_opt data_declaration
  | K_const class_item_qualifiers_opt data_type identifier ';'
  | K_const class_item_qualifiers_opt data_type identifier '=' constant_expression ';'
  ;

class_method
  : method_qualifiers_opt task_declaration
  | method_qualifiers_opt function_declaration
  | K_extern method_qualifiers_opt method_prototype ';'
  | method_qualifier_opt class_constructor_declaration
  | K_extern method_qualifiers_opt class_constructor_prototype
  ;

class_constructor_prototype
  : K_function K_new '(' tf_port_list_opt ')' ';'
  ;

class_constraint
  : constraint_prototype
  | constraint_declaration
  ;

class_item_qualifier
  : K_static
  | K_protected
  | K_local
  ;

class_item_qualifiers
  : class_item_qualifier
  | class_item_qualifiers class_item_qualifier
  ;

class_item_qualifiers_opt
  : class_item_qualifiers
  |
  ;

property_qualifier
  : K_rand
  | K_randc
  | class_item_qualifier
  ;

property_qualifiers
  : property_qualifier
  | property_qualifiers property_qualifier
  ;

property_qualifiers_opt
  : property_qualifiers
  |
  ;

method_qualifier
  : K_virtual
  | class_item_qualifier 
  ;

method_qualifier_opt
  : method_qualifier
  ;

method_qualifiers
  : method_qualifier
  | method_qualifiers method_qualifier
  ;

method_qualifiers_opt
  : method_qualifiers
  |
  ;

method_prototype
  : task_prototype ';'
  | function_prototype ';'
  ;

class_constructor_declaration
  : K_function class_scope_opt K_new tf_port_list_opt ';' block_item_declarations_opt
    function_statement_or_nulls_opt K_endfunction postfix_new_opt
  | K_function class_scope_opt K_new tf_port_list_opt ';' block_item_declarations_opt K_super '.' K_new list_of_arguments_opt ';'
    function_statement_or_nulls_opt K_endfunction postfix_new_opt
  ;

  /* Constraints */
constraint_declaration
  : K_static K_constraint identifier constraint_block
  | K_constraint identifier constraint_block
  ;

constraint_block
  : '{' constraint_block_items_opt '}'
  ;

constraint_block_item
  : K_solve identifier_list K_before identifier_list ';'
  | constraint_expression
  ;

constraint_block_items
  : constraint_block_item
  | constraint_block_items constraint_block_item
  ;

constraint_block_items_opt
  : constraint_block_items
  |
  ;

constraint_expression
  : expression_or_dist ';'
  | expression K_TRIGGER constraint_set
  | K_if '(' expression ')' constraint_set
  | K_if '(' expression ')' constraint_set K_else constraint_set
  | K_foreach '(' identifier loop_variables_opt ')' constraint_set
  ;

constraint_expressions
  : constraint_expression
  | constraint_expressions constraint_expression
  ;

constraint_expressions_opt
  : constraint_expressions
  |
  ;

constraint_set
  : constraint_expression
  | '{' constraint_expressions_opt '}'
  ;

dist_list
  : dist_item dist_items_opt
  ;

dist_item
  : value_range dist_weight_opt
  ;

dist_items
  : ',' dist_item
  | dist_items ',' dist_item
  ;

dist_items_opt
  : dist_items
  |
  ;

dist_weight
  : ':' '=' expression
  | ':' '/' expression
  ;

dist_weight_opt
  : dist_weight
  |
  ;

constraint_prototype
  : K_static K_constraint identifier ';'
  | K_constraint identifier ;
  ;

extern_constraint_declaration
  : K_static K_constraint class_scope identifier constraint_block
  | K_constraint class_scope identifier constraint_block
  ;

identifier_list
  : identifier identifiers_opt
  ;

  /* Package items */

package_item
  : package_or_generate_item_declaration
  | specparam_declaration
  | anonymous_program
  | timeunits_declaration
  ;

package_or_generate_item_declaration
  : net_declaration
  | data_declaration
  | task_declaration
  | function_declaration
  | dpi_import_export
  | extern_constraint_declaration
  | class_declaration
  | class_constructor_declaration
  | parameter_declaration ';'
  | local_parameter_declaration
  | covergroup_declaration
  | overload_declaration
  | concurrent_assertion_item_declaration
  |
  ;

anonymous_program
  : K_program ';' anonymous_program_items_opt K_endprogram
  ;

anonymous_program_item
  : task_declaration
  | function_declaration
  | class_declaration
  | covergroup_declaration
  | class_constructor_declaration
  ; 

anonymous_program_items
  : anonymous_program_item
  | anonymous_program_items anonymous_program_item
  ;

anonymous_program_items_opt
  : anonymous_program_items
  |
  ;

  /* DECLARATIONS */

  /* Declaration Types */

  /* Module parameter declarations */
local_parameter_declaration
  : K_localparam data_type_or_implicit list_of_param_assignments ';'
  ;

parameter_declaration
  : K_parameter data_type_or_implicit list_of_param_assignments
  | K_parameter K_type list_of_type_assignments
  ;

specparam_declaration
  : K_specparam packed_dimension_opt list_of_specparam_assignments ';'
  ;

  /* Port declarations */
inout_declaration
  : K_inout port_type list_of_port_identifiers
  ;

input_declaration
  : K_input port_type list_of_port_identifiers
  | K_input data_type list_of_variable_identifiers
  ;

output_declaration
  : K_output port_type list_of_port_identifiers
  | K_output data_type list_of_variable_port_identifiers
  ;

interface_port_declaration
  : identifier list_of_interface_identifiers
  | identifier '.' identifier list_of_interface_identifiers
  ;

ref_declaration
  : K_ref data_type list_of_port_identifiers
  ;

  /* Type declarations */

data_declaration
  : K_const lifetime_opt variable_declaration
  | variable_declaration
  | lifetime variable_declaration
  | type_declaration
  | package_import_declaration
  | virtual_interface_declaration
  ;

data_declarations
  : data_declaration
  | data_declarations data_declaration
  ;

data_declarations_opt
  : data_declarations
  |
  ;

package_import_declaration
  : K_import package_import_item package_import_items_opt ';'

package_import_item
  : identifier ':' ':' identifier
  | identifier ':' ':' '*'
  ;

package_import_items
  : ',' package_import_item
  | package_import_items ',' package_import_item
  ;

package_import_items_opt
  : package_import_items
  |
  ;

genvar_declaration
  : K_genvar list_of_genvar_identifiers ';'
  ;

net_declaration
  : net_type_or_trireg drive_or_charge_strength_opt vectored_or_scalared_opt signing_opt packed_dimensions_opt delay3_opt list_of_net_decl_assignments ';'
  ;

drive_or_charge_strength_opt
  : drive_strength
  | charge_strength
  |
  ;

vectored_or_scalared_opt
  : K_vectored
  | K_scalared
  |
  ;

type_declaration
  : K_typedef data_type identifier variable_dimension ';'
  | K_typedef identifier '.' identifier identifier ';'
  | K_typedef esuc_opt identifier ';'
  ;

esuc_opt
  : K_enum
  | K_struct
  | K_union
  | K_class
  |
  ;

variable_declaration
  : data_type list_of_variable_decl_assignments ';'
  ;

lifetime
  : K_static
  | K_automatic
  ;

lifetime_opt
  : lifetime
  |
  ;

  /* Declaration data types */

  /* Net and variable types */

casting_type
  : simple_type
  | NUMBER
  | UNUSED_NUMBER
  | signing 
  ;

data_type
  : integer_vector_type signing_opt packed_dimensions_opt
  | integer_atom_type signing_opt
  | non_integer_type
  | struct_union packed_opt '{' struct_union_member struct_union_members_opt '}' packed_dimensions_opt
  | K_enum enum_base_type_opt '{' enum_name_declaration enum_name_declarations_opt '}'
  | STRING
  | UNUSED_STRING
  | K_chandle
  | K_virtual K_interface identifier
  | K_virtual identifier
  | identifier packed_dimensions_opt
  | class_scope identifier packed_dimensions_opt
  | package_scope identifier packed_dimensions_opt
  | class_type
  | K_event
  | ps_identifier
  ;

data_type_list
  : ',' data_type
  | data_type_list ',' data_type
  ;

data_type_list_opt
  : data_type_list
  |
  ;

packed_opt
  : K_packed signing_opt
  |
  ;

data_type_or_implicit
  : data_type
  | signing_opt packed_dimensions_opt
  ;

enum_base_type
  : integer_atom_type signing_opt
  | integer_vector_type signing_opt packed_dimension_opt
  | identifier packed_dimension_opt
  ;

enum_base_type_opt
  : enum_base_type
  |
  ;

enum_name_declaration
  : identifier
  | identifier '[' NUMBER ']'
  | identifier '[' UNUSED_NUMBER ']'
  | identifier '[' NUMBER ':' NUMBER ']'
  | identifier '[' UNUSED_NUMBER ':' UNUSED_NUMBER ']'
  | identifier '=' constant_expression
  | identifier '[' NUMBER ']' '=' constant_expression
  | identifier '[' UNUSED_NUMBER ']' '=' constant_expression
  | identifier '[' NUMBER ':' NUMBER ']' '=' constant_expression
  | identifier '[' UNUSED_NUMBER ':' UNUSED_NUMBER ']' '=' constant_expression
  ;

enum_name_declarations
  : ',' enum_name_declaration
  | enum_name_declarations ',' enum_name_declaration
  ;

enum_name_declarations_opt
  : enum_name_declarations
  |
  ;

class_scope
  : class_type ':' ':'

class_scope_opt
  : class_scope
  |
  ;

class_type
  : ps_identifier parameter_value_assignment_opt class_identifier_and_param_value_assignments_opt
  ;

class_identifier_and_param_value_assignments
  : ':' ':' identifier parameter_value_assignment_opt
  | class_identifier_and_param_value_assignments ':' ':' identifier parameter_value_assignment_opt
  ;

class_identifier_and_param_value_assignments_opt
  : class_identifier_and_param_value_assignments
  |
  ;

integer_type
  : integer_vector_type
  | integer_atom_type
  ;

integer_atom_type
  : K_byte
  | K_shortint
  | K_int
  | K_longint
  | K_integer
  | K_time
  ;

integer_vector_type
  : K_bit
  | K_logic
  | K_reg
  ;

non_integer_type
  : K_shortreal
  | K_real
  | K_realtime
  ;

net_type
  : K_supply0
  | K_supply1
  | K_tri
  | K_triand
  | K_trior
  | K_tri0
  | K_tri1
  | K_wire
  | K_wand
  | K_wor
  ;

port_type
  : net_type_or_trireg_opt signing_opt packed_dimensions_opt
  ;

net_type_or_trireg
  : net_type
  | K_trireg
  ;

net_type_or_trireg_opt
  : net_type_or_trireg
  |
  ;

signing
  : K_signed
  | K_unsigned
  ;

signing_opt
  : signing
  |
  ;

simple_type
  : integer_type
  | non_integer_type
  | ps_identifier
  ;

struct_union_member
  : attribute_instances_opt data_type_or_void list_of_variable_identifiers ';'
  ;

struct_union_members
  : struct_union_member
  | struct_union_members struct_union_member
  ;

struct_union_members_opt
  : struct_union_members
  |
  ;

data_type_or_void
  : data_type
  | K_void
  ;

struct_union
  : K_struct
  | K_union
  | K_union K_tagged
  ;

  /* Strengths */

drive_strength
  : '(' strength0 ',' strength1 ')'
  | '(' strength1 ',' strength0 ')'
  | '(' strength0 ',' K_highz1 ')'
  | '(' strength1 ',' K_highz0 ')'
  | '(' K_highz0 ',' strength1 ')'
  | '(' K_highz1 ',' strength0 ')'
  ;

drive_strength_opt
  : drive_strength
  |
  ;

strength0
  : K_supply0
  | K_strong0
  | K_pull0
  | K_weak0
  ;

strength1
  : K_supply1
  | K_strong1
  | K_pull1
  | K_weak1
  ;

charge_strength
  : '(' K_small ')'
  | '(' K_medium ')'
  | '(' K_large ')'
  ;

  /* Delays */

delay3
  : '#' delay_value
  | '#' '(' mintypmax_expression ')'
  | '#' '(' mintypmax_expression ',' mintypmax_expression ')'
  | '#' '(' mintypmax_expression ',' mintypmax_expression ',' mintypmax_expression ')'
  ;

delay3_opt
  : delay3
  |
  ;

delay2
  : '#' delay_value
  | '#' '(' mintypmax_expression ')'
  | '#' '(' mintypmax_expression ',' mintypmax_expression ')'
  ;

delay2_opt
  : delay2
  |
  ;

delay_value
  : NUMBER
  | UNUSED_NUMBER
  | REALTIME
  | UNUSED_REALTIME
  | ps_identifier
  | time_literal
  ;

  /* Declaration lists */

list_of_defparam_assignments
  : defparam_assignment defparam_assignments_list_opt
  ;

defparam_assignments_list
  : ',' defparam_assignment
  | defparam_assignments_list ',' defparam_assignment
  ;

defparam_assignments_list_opt
  : defparam_assignments_list
  |
  ;

list_of_genvar_identifiers
  : identifier genvar_identifier_list_opt
  ;

genvar_identifier_list
  : ',' identifier
  | genvar_identifier_list ',' identifier
  ;

genvar_identifier_list_opt
  : genvar_identifier_list
  |
  ;

list_of_interface_identifiers
  : identifier unpacked_dimensions_opt interface_identifiers_list_opt
  ;

interface_identifiers_list
  : ',' identifier unpacked_dimensions_opt
  | interface_identifiers_list ',' identifier unpacked_dimensions_opt
  ;

interface_identifiers_list_opt
  : interface_identifiers_list
  |
  ;

list_of_net_decl_assignments
  : net_decl_assignment net_decl_assignment_list_opt
  ;

net_decl_assignment_list
  : ',' net_decl_assignment
  | net_decl_assignment_list ',' net_decl_assignment
  ;

net_decl_assignment_list_opt
  : net_decl_assignment_list
  |
  ;

list_of_param_assignments
  : param_assignment param_assignment_list_opt
  ;

param_assignment_list
  : ',' param_assignment
  | param_assignment_list ',' param_assignment
  ;

param_assignment_list_opt
  : param_assignment_list
  |
  ;

list_of_port_identifiers
  : identifier unpacked_dimensions_opt port_identifiers_list_opt
  ;

port_identifiers_list
  : ',' identifier unpacked_dimensions_opt
  | port_identifiers_list ',' identifier unpacked_dimensions_opt
  ;

port_identifiers_list_opt
  : port_identifiers_list
  |
  ;

list_of_udp_port_identifiers
  : identifier udp_port_identifiers_list_opt
  ;

udp_port_identifiers_list
  : ',' identifier
  | udp_port_identifiers_list ',' identifier
  ;

udp_port_identifiers_list_opt
  : udp_port_identifiers_list
  |
  ;

list_of_specparam_assignments
  : specparam_assignment specparam_assignments_list_opt
  ;

specparam_assignments_list
  : ',' specparam_assignment
  | specparam_assignments_list ',' specparam_assignment
  ;

specparam_assignments_list_opt
  : specparam_assignments_list
  |
  ;

list_of_tf_variable_identifiers
  : identifier variable_dimension tf_variable_identifiers_list_opt
  | identifier variable_dimension '=' expression tf_variable_identifiers_list_opt
  ;

tf_variable_identifiers_list
  : ',' identifier variable_dimension
  | ',' identifier variable_dimension '=' expression
  | tf_variable_identifiers_list ',' identifier variable_dimension
  | tf_variable_identifiers_list ',' identifier variable_dimension '=' expression
  ;

tf_variable_identifiers_list_opt
  : tf_variable_identifiers_list
  |
  ;

list_of_type_assignments
  : type_assignment type_assignments_list_opt

type_assignments_list
  : ',' type_assignment
  | type_assignments_list ',' type_assignment
  ;

type_assignments_list_opt
  : type_assignments_list
  |
  ;

list_of_variable_decl_assignments
  : variable_decl_assignment variable_decl_assignments_list_opt
  ;

variable_decl_assignments_list
  : ',' variable_decl_assignment
  | variable_decl_assignments_list ',' variable_decl_assignment
  ;

variable_decl_assignments_list_opt
  : variable_decl_assignments_list
  |
  ;

list_of_variable_identifiers
  : identifier variable_dimension variable_identifiers_list_opt
  ;

variable_identifiers_list
  : ',' identifier variable_dimension
  | variable_identifiers_list ',' identifier variable_dimension
  ;

variable_identifiers_list_opt
  : variable_identifiers_list
  |
  ;

list_of_variable_port_identifiers
  : identifier variable_dimension variable_port_identifiers_list_opt
  | identifier variable_dimension '=' constant_expression variable_port_identifiers_list_opt
  ;

variable_port_identifiers_list
  : ',' identifier variable_dimension
  | ',' identifier variable_dimension '=' constant_expression
  | variable_port_identifiers_list ',' identifier variable_dimension
  | variable_port_identifiers_list ',' identifier variable_dimension '=' constant_expression
  ;

variable_port_identifiers_list_opt
  : variable_port_identifiers_list
  |
  ;

list_of_virtual_interface_decl
  : identifier virtual_interface_decl_list_opt
  | identifier '=' identifier virtual_interface_decl_list_opt
  ;

virtual_interface_decl_list
  : ',' identifier
  | ',' identifier '=' identifier
  | virtual_interface_decl_list ',' identifier
  | virtual_interface_decl_list ',' identifier '=' identifier
  ;

virtual_interface_decl_list_opt
  : virtual_interface_decl_list
  |
  ;

  /* Declaration assignments */

defparam_assignment
  : hierarchical_identifier '=' constant_mintypmax_expression
  ;

net_decl_assignment
  : identifier unpacked_dimensions_opt
  | identifier unpacked_dimensions_opt '=' expression
  ;

param_assignment
  : identifier unpacked_dimensions_opt '=' constant_param_expression
  ;

specparam_assignment
  : identifier '=' constant_mintypmax_expression
  | pulse_control_specparam
  ;

type_assignment
  : identifier '=' data_type 
  ;

pulse_control_specparam
  : PATHPULSE_IDENTIFIER '=' '(' reject_limit_value ')' ';'
  | UNUSED_PATHPULSE_IDENTIFIER '=' '(' reject_limit_value ')' ';'
  | PATHPULSE_IDENTIFIER '=' '(' reject_limit_value ',' error_limit_value ')' ';'
  | UNUSED_PATHPULSE_IDENTIFIER '=' '(' reject_limit_value ',' error_limit_value ')' ';'
  | PATHPULSE_IDENTIFIER specify_input_terminal_descriptor '$' specify_output_terminal_descriptor '=' '(' reject_limit_value ')' ';'
  | UNUSED_PATHPULSE_IDENTIFIER specify_input_terminal_descriptor '$' specify_output_terminal_descriptor '=' '(' reject_limit_value ')' ';'
  | PATHPULSE_IDENTIFIER specify_input_terminal_descriptor '$' specify_output_terminal_descriptor '=' '(' reject_limit_value ',' error_limit_value ')' ';'
  | UNUSED_PATHPULSE_IDENTIFIER specify_input_terminal_descriptor '$' specify_output_terminal_descriptor '=' '(' reject_limit_value ',' error_limit_value ')' ';'
  ;

error_limit_value
  : limit_value
  ;

reject_limit_value
  : limit_value
  ;

limit_value
  : constant_mintypmax_expression
  ;

variable_decl_assignment
  : identifier variable_dimension
  | identifier variable_dimension '=' expression
  | identifier '[' ']'
  | identifier '[' ']' '=' dynamic_array_new
  | identifier
  | identifier '=' class_new
  | '=' K_new list_of_arguments_opt
  | identifier '=' K_new list_of_arguments_opt
  ;

class_new
  : K_new list_of_arguments_opt
  | K_new expression
  ;

dynamic_array_new
  : K_new '[' expression ']'
  | K_new '[' expression ']' '(' expression ')'
  ;

  /* Declaration ranges */
unpacked_dimension
  : '[' constant_range ']'
  | '[' constant_expression ']'
  ;

unpacked_dimensions
  : unpacked_dimension
  | unpacked_dimensions unpacked_dimension
  ;

unpacked_dimensions_opt
  : unpacked_dimensions
  |
  ;

packed_dimension
  : '[' constant_range ']'
  | unsized_dimension
  ;

packed_dimension_opt
  : packed_dimension
  |
  ;

packed_dimensions
  : packed_dimension
  | packed_dimensions packed_dimension
  ;

packed_dimensions_opt
  : packed_dimensions
  |
  ;

associative_dimension
  : '[' data_type ']'
  | '[' '*' ']'
  ;

variable_dimension
  : sized_or_unsized_dimensions_opt
  | associative_dimension
  | queue_dimension
  ;

queue_dimension
  : '[' '$' ']'
  | '[' '$' ':' constant_expression ']'
  ;

unsized_dimension
  : '[' ']'
  ;

sized_or_unsized_dimension
  : unpacked_dimension
  | unsized_dimension
  ;

sized_or_unsized_dimensions
  : sized_or_unsized_dimension
  | sized_or_unsized_dimensions sized_or_unsized_dimension
  ;

sized_or_unsized_dimensions_opt
  : sized_or_unsized_dimensions
  |
  ;

  /* Function declarations */
function_data_type
  : data_type
  | K_void
  ;

function_data_type_opt
  : function_data_type
  |
  ;

function_data_type_or_implicit
  : function_data_type
  | signing_opt packed_dimensions_opt
  ;

function_declaration
  : K_function lifetime_opt function_body_declaration
  ;

function_body_declaration
  : function_data_type_or_implicit identifier ';' tf_item_declarations_opt function_statement_or_nulls_opt K_endfunction postfix_identifier_opt
  | function_data_type_or_implicit identifier '.' identifier ';' tf_item_declarations_opt function_statement_or_nulls_opt K_endfunction postfix_identifier_opt
  | function_data_type_or_implicit class_scope identifier ';' tf_item_declarations_opt function_statement_or_nulls_opt K_endfunction postfix_identifier_opt
  | function_data_type_or_implicit identifier '(' tf_port_list_opt ')' ';' block_item_declarations_opt function_statement_or_nulls_opt K_endfunction postfix_identifier_opt
  | function_data_type_or_implicit identifier '.' identifier '(' tf_port_list_opt ')' ';' block_item_declarations_opt function_statement_or_nulls_opt K_endfunction postfix_identifier_opt
  | function_data_type_or_implicit class_scope identifier '(' tf_port_list_opt ')' ';' block_item_declarations_opt function_statement_or_nulls_opt K_endfunction postfix_identifier_opt
  ;

function_prototype
  : K_function function_data_type identifier '(' tf_port_list_opt ')'
  ;

dpi_import_export
  : K_import lex_start_import_export K_DPI lex_end_import_export dpi_function_import_property_opt dpi_function_proto ';'
  | K_import lex_start_import_export K_DPI lex_end_import_export dpi_function_import_property_opt c_identifier '=' dpi_function_proto ';'
  | K_import lex_start_import_export K_DPI lex_end_import_export dpi_task_import_property dpi_task_proto ';'
  | K_import lex_start_import_export K_DPI lex_end_import_export dpi_task_import_property c_identifier '=' dpi_task_proto ';'
  | K_export lex_start_import_export K_DPI lex_end_import_export K_function identifier ';'
  | K_export lex_start_import_export K_DPI lex_end_import_export c_identifier '=' K_function identifier ';'
  | K_export lex_start_import_export K_DPI lex_end_import_export K_task identifier ';'
  | K_export lex_start_import_export K_DPI lex_end_import_export c_identifier '=' K_task identifier ';'
  ;

dpi_function_import_property
  : K_context
  | K_pure
  ;

dpi_function_import_property_opt
  : dpi_function_import_property
  |
  ;

dpi_task_import_property
  : K_context
  ;

dpi_function_proto
  : function_prototype
  ;

dpi_task_proto
  : task_prototype
  ;

  /* Task declarations */
task_declaration
  : K_task lifetime_opt task_body_declaration
  ;

task_body_declaration
  : identifier ';' tf_item_declarations_opt statement_or_nulls_opt K_endtask postfix_identifier_opt
  | identifier '.' identifier ';' tf_item_declarations_opt statement_or_nulls_opt K_endtask postfix_identifier_opt
  | class_scope identifier ';' tf_item_declarations_opt statement_or_nulls_opt K_endtask postfix_identifier_opt
  | identifier '(' tf_port_list_opt ')' ';' block_item_declarations_opt statement_or_nulls_opt K_endtask postfix_identifier_opt
  | identifier '.' identifier '(' tf_port_list_opt ')' ';' block_item_declarations_opt statement_or_nulls_opt K_endtask postfix_identifier_opt
  | class_scope identifier '(' tf_port_list_opt ')' ';' block_item_declarations_opt statement_or_nulls_opt K_endtask postfix_identifier_opt
  ;

tf_item_declaration
  : block_item_declaration
  | tf_port_declaration
  ;

tf_item_declarations
  : tf_item_declaration
  | tf_item_declarations tf_item_declaration
  ;

tf_item_declarations_opt
  : tf_item_declarations
  |
  ;

tf_port_list
  : tf_port_item tf_port_items_opt
  ;

tf_port_list_opt
  : tf_port_list
  |
  ;

tf_port_item
  : attribute_instances_opt tf_port_direction_opt data_type_or_implicit identifier variable_dimension
  | attribute_instances_opt tf_port_direction_opt data_type_or_implicit identifier variable_dimension '=' expression
  ;

tf_port_items
  : tf_port_item
  | tf_port_items tf_port_item
  ;

tf_port_items_opt
  : tf_port_items
  |
  ;

tf_port_direction
  : port_direction
  | K_const K_ref
  ;

tf_port_direction_opt
  : tf_port_direction
  |
  ;

tf_port_declaration
  : attribute_instances_opt tf_port_direction data_type_or_implicit list_of_tf_variable_identifiers ';'
  ;

task_prototype
  : K_task identifier '(' tf_port_list_opt ')'
  ;

  /* Block item declarations */
block_item_declaration
  : attribute_instances_opt data_declaration
  | attribute_instances_opt local_parameter_declaration
  | attribute_instances_opt parameter_declaration ';'
  | attribute_instances_opt overload_declaration
  ;

block_item_declarations
  : block_item_declaration
  | block_item_declarations block_item_declaration
  ;

block_item_declarations_opt
  : block_item_declarations
  |
  ;

overload_declaration
  : K_bind overload_operator K_function data_type identifier '(' overload_proto_formals ')' ';'
  ;

overload_operator
  : '+'
  | K_INC
  | '-'
  | K_DEC
  | '*'
  | K_POW
  | '/'
  | '%'
  | K_EQ
  | K_NE
  | '<'
  | K_LE
  | '>'
  | K_GE
  | '='
  ;

overload_proto_formals
  : data_type data_type_list_opt
  ;

  /* Interface declarations */
virtual_interface_declaration
  : K_virtual identifier list_of_virtual_interface_decl ';'
  | K_virtual K_interface identifier list_of_virtual_interface_decl ';'
  ;

modport_declaration
  : K_modport modport_item modport_item_list_opt ';'
  ;

modport_item
  : identifier '(' modport_ports_declaration modport_ports_declaration_list_opt ')'
  ;

modport_item_list
  : ',' modport_item
  | modport_item_list ',' modport_item
  ;

modport_item_list_opt
  : modport_item_list
  |
  ;

modport_ports_declaration
  : attribute_instances_opt modport_simple_ports_declaration
  | attribute_instances_opt modport_hierarchical_ports_declaration
  | attribute_instances_opt modport_tf_ports_declaration
  | attribute_instances_opt modport_clocking_declaration
  ;

modport_ports_declaration_list
  : ',' modport_ports_declaration
  | modport_ports_declaration_list ',' modport_ports_declaration
  ;

modport_ports_declaration_list_opt
  : modport_ports_declaration_list
  |
  ;

modport_clocking_declaration
  : K_clocking identifier
  ;

modport_simple_ports_declaration
  : port_direction modport_simple_port modport_simple_port_list_opt
  ;

modport_simple_port
  : identifier
  | '.' identifier '(' expression_opt ')'
  ;

modport_simple_port_list
  : ',' modport_simple_port
  | modport_simple_port_list ',' modport_simple_port
  ;

modport_simple_port_list_opt
  : modport_simple_port_list
  |
  ;

modport_hierarchical_ports_declaration
  : identifier '.' identifier
  | identifier '[' constant_expression ']' '.' identifier
  ;

modport_tf_ports_declaration
  : import_export modport_tf_port modport_tf_port_list_opt
  ;

modport_tf_port
  : method_prototype
  | identifier
  ;

modport_tf_port_list
  : ',' modport_tf_port
  | modport_tf_port_list ',' modport_tf_port
  ;

modport_tf_port_list_opt
  : modport_tf_port_list
  |
  ;

import_export
  : K_import
  | K_export
  ;

  /* Assertion declarations */

concurrent_assertion_item
  : concurrent_assertion_statement
  | identifier ':' concurrent_assertion_statement
  ;

concurrent_assertion_statement
  : assert_property_statement
  | assume_property_statement
  | cover_property_statement
  ;

assert_property_statement
  : K_assert K_property '(' property_spec ')' action_block
  ;

assume_property_statement
  : K_assume K_property '(' property_spec ')' ';'
  ;

cover_property_statement
  : K_cover K_property '(' property_spec ')' statement_or_null
  ;

expect_property_statement
  : K_expect '(' property_spec ')' action_block
  ;

property_instance
  : ps_identifier actual_arg_lister_opt
  ;

concurrent_assertion_item_declaration
  : property_declaration
  | sequence_declaration
  ;

property_declaration
  : K_property identifier list_of_formals_opt ';' assertion_variable_declarations_opt property_spec ';' K_endproperty postfix_identifier_opt
  ;

property_spec
  : clocking_event_opt property_expr
  | clocking_event_opt K_disable K_iff '(' expression_or_dist ')' property_expr
  ;

property_expr
  : sequence_expr
  | '(' property_expr ')'
  | K_not property_expr
  | property_expr K_or property_expr
  | property_expr K_and property_expr
  | sequence_expr '|' K_TRIGGER property_expr
  | sequence_expr '|' K_EG property_expr
  | K_if '(' expression_or_dist ')' property_expr
  | K_if '(' expression_or_dist ')' property_expr K_else property_expr
  | property_instance
  | clocking_event property_expr
  ;

sequence_declaration
  : K_sequence identifier list_of_formals_opt ';' assertion_variable_declarations_opt sequence_expr ';' K_endsequence postfix_identifier_opt
  ;

sequence_expr
  : cycle_delay_range sequence_expr cycle_delay_range_sequence_exprs_opt
  | sequence_expr cycle_delay_range sequence_expr cycle_delay_range_sequence_exprs_opt
  | expression_or_dist boolean_abbrev_opt
  | '(' expression_or_dist sequence_match_item_list_opt ')' boolean_abbrev_opt
  | sequence_instance sequence_abbrev_opt
  | '(' sequence_expr sequence_match_item_list_opt ')' sequence_abbrev_opt
  | sequence_expr K_and sequence_expr
  | sequence_expr K_intersect sequence_expr
  | sequence_expr K_or sequence_expr
  | K_first_match '(' sequence_expr sequence_match_item_list_opt ')'
  | expression_or_dist K_throughout sequence_expr
  | sequence_expr K_within sequence_expr
  | clocking_event sequence_expr
  ;

cycle_delay_range_sequence_exprs
  : cycle_delay_range sequence_expr
  | cycle_delay_range_sequence_exprs cycle_delay_range sequence_expr
  ;

cycle_delay_range_sequence_exprs_opt
  : cycle_delay_range_sequence_exprs
  |
  ;

cycle_delay_range
  : K_PP NUMBER
  | K_PP UNUSED_NUMBER
  | K_PP identifier
  | K_PP '(' constant_expression ')'
  | K_PP '[' cycle_delay_const_range_expression ']'
  ;

sequence_method_call
  : sequence_instance '.' identifier
  ;

sequence_match_item
  : operator_assignment
  | inc_or_dec_expression
  | subroutine_call
  ;

sequence_match_item_list
  : ',' sequence_match_item
  | sequence_match_item_list ',' sequence_match_item
  ;

sequence_match_item_list_opt
  : sequence_match_item_list
  |
  ;

sequence_instance
  : ps_identifier actual_arg_lister_opt
  ;

formal_list_item
  : identifier
  | identifier '=' actual_arg_expr
  ;

formal_list_item_list
  : ',' formal_list_item
  | formal_list_item_list ',' formal_list_item
  ;

formal_list_item_list_opt
  : formal_list_item_list
  |
  ;

list_of_formals
  : formal_list_item formal_list_item_list_opt
  ;

actual_arg_list
  : actual_arg_expr actual_arg_expr_list_opt
  | '.' identifier '(' actual_arg_expr ')' identifier_actual_arg_expr_list_opt
  ;

actual_arg_expr
  : event_expression
  | '$'
  ;

actual_arg_expr_list
  : ',' actual_arg_expr
  | actual_arg_expr_list ',' actual_arg_expr
  ;

actual_arg_expr_list_opt
  : actual_arg_expr_list
  |
  ;

identifier_actual_arg_expr_list
  : ',' '.' identifier '(' actual_arg_expr ')'
  | identifier_actual_arg_expr_list ',' '.' identifier '(' actual_arg_expr ')'
  ;

identifier_actual_arg_expr_list_opt
  : identifier_actual_arg_expr_list
  |
  ;

boolean_abbrev
  : consecutive_repetition
  | non_consecutive_repetition
  | goto_repetition
  ;

boolean_abbrev_opt
  : boolean_abbrev
  |
  ;

sequence_abbrev
  : consecutive_repetition
  ;

sequence_abbrev_opt
  : sequence_abbrev
  |
  ;

consecutive_repetition
  : '[' '*' const_or_range_expression ']'
  ;

non_consecutive_repetition
  : '[' '=' const_or_range_expression ']'
  ;

goto_repetition
  : '[' K_TRIGGER const_or_range_expression ']'
  ;

const_or_range_expression
  : constant_expression
  | cycle_delay_const_range_expression
  ;

cycle_delay_const_range_expression
  : constant_expression ':' constant_expression
  | constant_expression ':' '$'
  ;

expression_or_dist
  : expression
  | expression K_dist '{' dist_list '}'
  ;

assertion_variable_declaration
  : data_type list_of_variable_identifiers ';'
  ;

assertion_variable_declarations
  : assertion_variable_declaration
  | assertion_variable_declarations assertion_variable_declaration
  ;

assertion_variable_declarations_opt
  : assertion_variable_declarations
  |
  ;

  /* Covergroup declarations */

covergroup_declaration
  : K_covergroup identifier tf_port_list_opt coverage_event_opt ';' coverage_spec_or_options_opt K_endgroup postfix_identifier_opt
  ;

coverage_spec_or_option
  : attribute_instances_opt coverage_spec
  | attribute_instances_opt coverage_option ';'
  ;

coverage_spec_or_options
  : coverage_spec_or_option ';'
  | coverage_spec_or_options coverage_spec_or_option ';'
  ;

coverage_spec_or_options_opt
  : coverage_spec_or_options
  |
  ;

coverage_option
  : K_optionDOT identifier '=' expression
  | K_type_optionDOT identifier '=' expression
  ;

coverage_spec
  : cover_point
  | cover_cross
  ;

coverage_event
  : clocking_event
  | '@' '@' '(' block_event_expression ')'
  ;

coverage_event_opt
  : coverage_event
  |
  ;

block_event_expression
  : block_event_expression K_or block_event_expression
  | K_begin hierarchical_btf_identifier
  | K_end hierarchical_btf_identifier
  ;

hierarchical_btf_identifier
  : hierarchical_identifier
  | hierarchical_identifier class_scope_opt identifier
  ;

cover_point
  : identifier_opt K_coverpoint expression iff_expression_opt bins_or_empty
  ;

iff_expression_opt
  : K_iff '(' expression ')'
  |
  ;

bins_or_empty
  : '{' attribute_instances_opt bins_or_options_list_opt '}'
  |
  ;

bins_or_options
  : coverage_option
  | bins_keyword identifier '=' '{' range_list '}' iff_expression_opt
  | bins_keyword identifier '[' expression_opt ']' '=' '{' range_list '}' iff_expression_opt
  | bins_keyword identifier '=' trans_list iff_expression_opt
  | bins_keyword identifier '[' ']' '=' trans_list iff_expression_opt
  | K_wildcard bins_keyword identifier '=' '{' range_list '}' iff_expression_opt
  | K_wildcard bins_keyword identifier '[' expression_opt ']' '=' '{' range_list '}' iff_expression_opt
  | K_wildcard bins_keyword identifier '=' trans_list iff_expression_opt
  | K_wildcard bins_keyword identifier '[' ']' '=' trans_list iff_expression_opt
  | bins_keyword identifier '=' K_default iff_expression_opt
  | bins_keyword identifier '[' expression_opt ']' '=' K_default iff_expression_opt
  | bins_keyword identifier '=' K_default K_sequence iff_expression_opt
  ;

bins_or_options_list
  : bins_or_options ';'
  | bins_or_options_list bins_or_options ';'
  ;

bins_or_options_list_opt
  : bins_or_options_list
  |
  ;

bins_keyword
  : K_bins
  | K_illegal_bins
  | K_ignore_bins
  ;

range_list
  : value_range value_range_list_opt

value_range_list
  : ',' value_range
  | value_range_list ',' value_range
  ;

value_range_list_opt
  : value_range_list
  |
  ;

trans_list
  : '(' trans_set ')' trans_set_list_opt
  ;

trans_set_list
  : ',' '(' trans_set ')'
  | trans_set_list ',' '(' trans_set ')'
  ;

trans_set_list_opt
  : trans_set_list
  |
  ;

trans_set
  : trans_range_list K_EG trans_range_list trans_range_lists_opt
  ;

trans_range_lists
  : K_EG trans_range_list
  | trans_range_lists K_EG trans_range_list
  ;

trans_range_lists_opt
  : trans_range_lists
  |
  ;

trans_range_list
  : trans_item
  | trans_item '[' '*' repeat_range ']'
  | trans_item '[' K_TRIGGER repeat_range ']'
  | trans_item '[' '=' repeat_range ']'
  ;

trans_item
  : range_list
  ;

repeat_range
  : expression
  | expression ':' expression
  ;

cover_cross
  : identifier_opt K_cross list_of_coverpoints iff_expression_opt select_bins_or_empty
  ;

list_of_coverpoints
  : cross_item ',' cross_item cross_item_list_opt
  ;

cross_item
  : identifier
  ;

cross_item_list
  : ',' cross_item
  | cross_item_list ',' cross_item
  ;

cross_item_list_opt
  : cross_item_list
  |
  ;

select_bins_or_empty
  : '{' bins_selection_or_option_list_opt '}'
  |
  ;

bins_selection_or_option
  : attribute_instances_opt coverage_option
  | attribute_instances_opt bins_selection
  ;

bins_selection_or_option_list
  : bins_selection_or_option ';'
  | bins_selection_or_option_list bins_selection_or_option ';'
  ;

bins_selection_or_option_list_opt
  : bins_selection_or_option_list
  |
  ;

bins_selection
  : bins_keyword identifier '=' select_expression iff_expression_opt
  ;

select_expression
  : select_condition
  | '!' select_condition
  | select_expression K_LAND select_expression
  | select_expression K_LOR select_expression
  | '(' select_expression ')' 
  ;

select_condition
  : K_binsof '(' bins_expression ')'
  | K_binsof '(' bins_expression ')' K_intersect open_range_lists_opt
  ;

bins_expression
  : identifier
  | identifier '.' identifier
  ;

open_range_list
  : open_value_range open_value_range_list_opt
  ;

open_range_lists
  : ',' open_range_list
  | open_range_lists ',' open_range_list
  ;

open_range_lists_opt
  : open_range_lists
  |
  ;

open_value_range
  : value_range
  ;

open_value_range_list
  : ',' open_value_range
  | open_value_range_list ',' open_value_range
  ;

open_value_range_list_opt
  : open_value_range_list
  |
  ;

  /* Primitive instances */

  /* Primitive instantiation and instances */

gate_instantiation
  : cmos_switchtype delay3_opt cmos_switch_instance cmos_switch_instance_list_opt ';'
  | enable_gatetype drive_strength_opt delay3_opt enable_gate_instance enable_gate_instance_list_opt ';'
  | mos_switchtype delay3_opt mos_switch_instance mos_switch_instance_list_opt ';'
  | n_input_gatetype drive_strength_opt delay2_opt n_input_gate_instance n_input_gate_instance_list_opt ';'
  | n_output_gatetype drive_strength_opt delay2_opt n_output_gate_instance n_output_gate_instance_list_opt ';'
  | pass_en_switchtype delay2_opt pass_enable_switch_instance pass_enable_switch_instance_list_opt ';'
  | pass_switchtype pass_switch_instance pass_switch_instance_list_opt ';'
  | K_pulldown pulldown_strength_opt pull_gate_instance pull_gate_instance_list_opt ';'
  | K_pullup pullup_strength_opt pull_gate_instance pull_gate_instance_list_opt ';'
  ;

cmos_switch_instance
  : name_of_instance_opt '(' output_terminal ',' input_terminal ',' ncontrol_terminal ',' pcontrol_terminal ')'
  ;

cmos_switch_instance_list
  : ',' cmos_switch_instance
  | cmos_switch_instance_list ',' cmos_switch_instance
  ;

cmos_switch_instance_list_opt
  : cmos_switch_instance_list
  |
  ;

enable_gate_instance
  : name_of_instance_opt '(' output_terminal ',' input_terminal ',' enable_terminal ')'
  ;

enable_gate_instance_list
  : ',' enable_gate_instance
  | enable_gate_instance_list ',' enable_gate_instance
  ;

enable_gate_instance_list_opt
  : enable_gate_instance_list
  |
  ;

mos_switch_instance
  : name_of_instance_opt '(' output_terminal ',' input_terminal ',' enable_terminal ')'
  ;

mos_switch_instance_list
  : ',' mos_switch_instance
  | mos_switch_instance_list ',' mos_switch_instance
  ;

mos_switch_instance_list_opt
  : mos_switch_instance_list
  |
  ;

n_input_gate_instance
  : name_of_instance_opt '(' output_terminal ',' input_terminal input_terminal_list_opt ')'
  ;

n_input_gate_instance_list
  : ',' n_input_gate_instance
  | n_input_gate_instance_list ',' n_input_gate_instance
  ;

n_input_gate_instance_list_opt
  : n_input_gate_instance_list
  |
  ;

n_output_gate_instance
  : name_of_instance_opt '(' output_terminal output_terminal_list_opt ',' input_terminal ')'
  ;

n_output_gate_instance_list
  : ',' n_output_gate_instance
  | n_output_gate_instance_list ',' n_output_gate_instance
  ;

n_output_gate_instance_list_opt
  : n_output_gate_instance_list
  |
  ;

pass_switch_instance
  : name_of_instance_opt '(' inout_terminal ',' inout_terminal ')'
  ;

pass_switch_instance_list
  : ',' pass_switch_instance
  | pass_switch_instance_list ',' pass_switch_instance
  ;

pass_switch_instance_list_opt
  : pass_switch_instance_list
  |
  ;

pass_enable_switch_instance
  : name_of_instance_opt '(' inout_terminal ',' inout_terminal ',' enable_terminal ')'
  ;

pass_enable_switch_instance_list
  : ',' pass_enable_switch_instance
  | pass_enable_switch_instance_list ',' pass_enable_switch_instance
  ;

pass_enable_switch_instance_list_opt
  : pass_enable_switch_instance_list
  |
  ;

pull_gate_instance
  : name_of_instance_opt '(' output_terminal ')'
  ;

pull_gate_instance_list
  : ',' pull_gate_instance
  | pull_gate_instance_list ',' pull_gate_instance
  ;

pull_gate_instance_list_opt
  : pull_gate_instance_list
  |
  ;

  /* Primitive strengths */

pulldown_strength
  : '(' strength0 ',' strength1 ')'
  | '(' strength1 ',' strength0 ')'
  | '(' strength0 ')'
  ;

pulldown_strength_opt
  : pulldown_strength
  |
  ;

pullup_strength
  : '(' strength0 ',' strength1 ')'
  | '(' strength1 ',' strength0 ')'
  | '(' strength1 ')'
  ;

pullup_strength_opt
  : pullup_strength
  |
  ;

  /* Primitive terminals */

enable_terminal
  : expression
  ;

inout_terminal
  : net_lvalue
  ;

input_terminal
  : expression
  ;

input_terminal_list
  : ',' input_terminal
  | input_terminal_list ',' input_terminal
  ;

input_terminal_list_opt
  : input_terminal_list
  |
  ;

ncontrol_terminal
  : expression
  ;

output_terminal
  : net_lvalue
  ;

output_terminal_list
  : ',' output_terminal
  | output_terminal_list ',' output_terminal
  ;

output_terminal_list_opt
  : output_terminal_list
  |
  ;

pcontrol_terminal
  : expression
  ;

  /* Primitive gate and switch types */

cmos_switchtype
  : K_cmos
  | K_rcmos
  ;

enable_gatetype
  : K_bufif0
  | K_bufif1
  | K_notif0
  | K_notif1
  ;

mos_switchtype
  : K_nmos
  | K_pmos
  | K_rnmos
  | K_rpmos
  ;

n_input_gatetype
  : K_and
  | K_nand
  | K_or
  | K_nor
  | K_xor
  | K_xnor
  ;

n_output_gatetype
  : K_buf
  | K_not
  ;

pass_en_switchtype
  : K_tranif0
  | K_tranif1
  | K_rtranif1
  | K_rtranif0
  ;

pass_switchtype
  : K_tran
  | K_rtran
  ;

  /* Module, interface and generated instantiation */

  /* Instantiation */

  /* Module instantiation */

parameter_value_assignment
  : '#' '(' list_of_parameter_assignments ')'
  ;

parameter_value_assignment_opt
  : parameter_value_assignment
  |
  ;

list_of_parameter_assignments
  : ordered_parameter_assignment ordered_parameter_assignment_list_opt
  | named_parameter_assignment named_parameter_assignment_list_opt
  ;

ordered_parameter_assignment
  : param_expression
  ;

ordered_parameter_assignment_list
  : ',' ordered_parameter_assignment
  | ordered_parameter_assignment_list ',' ordered_parameter_assignment
  ;

ordered_parameter_assignment_list_opt
  : ordered_parameter_assignment_list
  |
  ;

named_parameter_assignment
  : '.' identifier '(' param_expression_opt ')'
  ;

named_parameter_assignment_list
  : ',' named_parameter_assignment
  | named_parameter_assignment_list ',' named_parameter_assignment
  ;

named_parameter_assignment_list_opt
  : named_parameter_assignment_list
  |
  ;

hierarchical_instance
  : name_of_instance '(' list_of_port_connections_opt ')'
  ;

hierarchical_instance_list
  : ',' hierarchical_instance
  | hierarchical_instance_list ',' hierarchical_instance
  ;

hierarchical_instance_list_opt
  : hierarchical_instance_list
  |
  ;

name_of_instance
  : identifier unpacked_dimensions_opt
  ;

name_of_instance_opt
  : name_of_instance
  |
  ;

list_of_port_connections
  : ordered_port_connection ordered_port_connection_list_opt
  | named_port_connection named_port_connection_list_opt
  ;

list_of_port_connections_opt
  : list_of_port_connections
  |
  ;

ordered_port_connection
  : attribute_instances_opt expression_opt
  ;

ordered_port_connection_list
  : ',' ordered_port_connection
  | ordered_port_connection_list ',' ordered_port_connection
  ;

ordered_port_connection_list_opt
  : ordered_port_connection_list
  |
  ;

named_port_connection
  : attribute_instances_opt '.' identifier
  : attribute_instances_opt '.' identifier '(' expression_opt ')'
  | attribute_instances_opt K_PS
  ;

named_port_connection_list
  : ',' named_port_connection
  | named_port_connection_list ',' named_port_connection
  ;

named_port_connection_list_opt
  : named_port_connection_list
  |
  ;

  /* Interface/Program/Module instantiation */

interface_or_program_or_module_instantiation
  : identifier parameter_value_assignment_opt hierarchical_instance hierarchical_instance_list_opt ';'
  ;

  /* Generated instantiation */

  /* Generated module instantiation */

generated_module_instantiation
  : K_generate generate_module_items_opt K_endgenerate
  ;

generate_module_item
  : generate_module_conditional_statement
  | generate_module_case_statement
  | generate_module_loop_statement
  | generate_module_block
  | identifier ':' generate_module_block
  | module_or_generate_item
  ;

generate_module_items
  : generate_module_item
  | generate_module_items generate_module_item
  ;

generate_module_items_opt
  : generate_module_items
  |
  ;

generate_module_conditional_statement
  : K_if '(' constant_expression ')' generate_module_item
  | K_if '(' constant_expression ')' generate_module_item K_else generate_module_item
  ;

generate_module_case_statement
  : K_case '(' constant_expression ')' genvar_module_case_item genvar_module_case_items_opt K_endcase
  ;

genvar_module_case_item
  : constant_expression constant_expression_list_opt ':' generate_module_item
  | K_default generate_module_item
  | K_default ':' generate_module_item
  ;

genvar_module_case_items
  : genvar_module_case_item
  | genvar_module_case_items genvar_module_case_item
  ;

genvar_module_case_items_opt
  : genvar_module_case_items
  |
  ;

generate_module_loop_statement
  : K_for '(' genvar_decl_assignment ';' constant_expression ';' genvar_assignment ')' generate_module_named_block
  ;

genvar_assignment
  : identifier assignment_operator constant_expression
  | inc_or_dec_operator identifier
  | identifier inc_or_dec_operator
  ;

genvar_decl_assignment
  : identifier '=' constant_expression
  | K_genvar identifier '=' constant_expression
  ;

generate_module_named_block
  : K_begin ':' identifier generate_module_items_opt K_end postfix_identifier_opt
  | identifier ':' generate_module_block
  ;

generate_module_block
  : K_begin generate_module_items_opt K_end postfix_identifier_opt
  | K_begin ':' identifier generate_module_items_opt K_end postfix_identifier_opt
  ;

  /* Generated interface instantiation */

generated_interface_instantiation
  : K_generate generate_interface_items_opt K_endgenerate 
  ;

generate_interface_item
  : generate_interface_conditional_statement
  | generate_interface_case_statement
  | generate_interface_loop_statement
  | generate_interface_block
  | identifier ':' generate_interface_block
  | interface_or_generate_item
  ;

generate_interface_items
  : generate_interface_item
  | generate_interface_items generate_interface_item
  ;

generate_interface_items_opt
  : generate_interface_items
  |
  ;

generate_interface_conditional_statement
  : K_if '(' constant_expression ')' generate_interface_item 
  | K_if '(' constant_expression ')' generate_interface_item K_else generate_interface_item
  ;

generate_interface_case_statement
  : K_case '(' constant_expression ')' genvar_interface_case_item genvar_interface_case_items_opt K_endcase
  ;

genvar_interface_case_item
  : constant_expression constant_expression_list_opt ':' generate_interface_item
  | K_default generate_interface_item
  | K_default ':' generate_interface_item
  ;

genvar_interface_case_items
  : genvar_interface_case_item
  | genvar_interface_case_items genvar_interface_case_item
  ;

genvar_interface_case_items_opt
  : genvar_interface_case_items
  |
  ;

generate_interface_loop_statement
  : K_for '(' genvar_decl_assignment ';' constant_expression ';' genvar_assignment ')' generate_interface_named_block
  ;

generate_interface_named_block
  : K_begin ':' identifier generate_interface_items_opt K_end postfix_identifier_opt
  | identifier ':' generate_interface_block
  ;

generate_interface_block 
  : K_begin generate_interface_items_opt K_end postfix_identifier_opt
  | K_begin ':' identifier generate_interface_items_opt K_end postfix_identifier_opt
  ;

  /* UDP declaration and instantiation */
 
  /* UDP declaration */

udp_nonansi_declaration
  : attribute_instances_opt K_primitive identifier '(' udp_port_list ')' ';'
  ;

udp_ansi_declaration
  : attribute_instances_opt K_primitive identifier '(' udp_declaration_port_list ')' ';' 
  ;

udp_declaration
  : udp_nonansi_declaration udp_port_declaration udp_port_declarations_opt udp_body K_endprimitive postfix_identifier_opt
  | udp_ansi_declaration udp_body K_endprimitive postfix_identifier_opt
  | K_extern udp_nonansi_declaration
  | K_extern udp_ansi_declaration
  | attribute_instances_opt K_primitive identifier '(' K_PS ')' ';' udp_port_declarations_opt udp_body K_endprimitive postfix_identifier_opt
  ;

  /* UDP ports */

udp_port_list
  : identifier ',' identifier identifier_opt_list
  ;

udp_declaration_port_list
  : udp_output_declaration ',' udp_input_declaration udp_input_declaration_list_opt
  ;

udp_port_declaration
  : udp_output_declaration ';'
  | udp_input_declaration ';'
  | udp_reg_declaration ';'
  ;

udp_port_declarations
  : udp_port_declaration
  | udp_port_declarations udp_port_declaration
  ;

udp_port_declarations_opt
  : udp_port_declarations
  |
  ;

udp_output_declaration
  : attribute_instances_opt K_output identifier
  | attribute_instances_opt K_output K_reg identifier
  | attribute_instances_opt K_output K_reg identifier '=' constant_expression
  ;

udp_input_declaration
  : attribute_instances_opt K_input list_of_udp_port_identifiers
  ;

udp_input_declaration_list
  : ',' udp_input_declaration
  | udp_input_declaration_list ',' udp_input_declaration
  ;

udp_input_declaration_list_opt
  : udp_input_declaration_list
  |
  ;

udp_reg_declaration
  : attribute_instances_opt K_reg identifier
  ;

  /* UDP body */

udp_body
  : combinational_body
  | sequential_body
  ;

combinational_body
  : K_table { lex_start_udp_table(); } combinational_entry combinational_entries_opt { lex_end_udp_table(); } K_endtable

combinational_entry
  : level_input_list ':' output_symbol ';'
  ;

combinational_entries
  : combinational_entry
  | combinational_entries combinational_entry
  ;

combinational_entries_opt
  : combinational_entries
  |
  ;

sequential_body
  : K_table { lex_start_udp_table(); } sequential_entry sequential_entries_opt { lex_end_udp_table(); } K_endtable
  | udp_initial_statement K_table { lex_start_udp_table(); } sequential_entry sequential_entries_opt { lex_end_udp_table(); } K_endtable
  ;

udp_initial_statement
  : K_initial identifier '=' init_val ';'
  ;

init_val
  : NUMBER
  | UNUSED_NUMBER
  ;

sequential_entry
  : seq_input_list ':' current_state ':' next_state ';'
  ;

sequential_entries
  : sequential_entry
  | sequential_entries sequential_entry
  ;

sequential_entries_opt
  : sequential_entries
  |
  ;

seq_input_list
  : level_input_list 
  | edge_input_list
  ;

level_input_list
  : level_symbol level_symbols_opt
  ;

edge_input_list
  : level_symbols_opt edge_indicator level_symbols_opt
  ;

edge_indicator
  : '(' level_symbol level_symbol ')' 
  | edge_symbol
  ;

current_state
  : level_symbol
  ;

next_state
  : output_symbol 
  | '-'
  ;

output_symbol
  : '0'
  | '1'
  | 'x'
  ;

level_symbol
  : '0'
  | '1'
  | 'x'
  | '?'
  | 'b'
  ;

level_symbols
  : level_symbol
  | level_symbols level_symbol
  ;

level_symbols_opt
  : level_symbols
  |
  ;

edge_symbol
  : 'r'
  | 'f'
  | 'p'
  | 'n'
  | '*'
  ;

  /* UDP instantiation */

udp_instantiation
  : identifier drive_strength_opt delay2_opt udp_instance udp_instance_list_opt ';'
  ;

udp_instance
  : name_of_instance_opt '(' output_terminal ',' input_terminal input_terminal_list_opt ')'
  ;

udp_instance_list
  : ',' udp_instance
  | udp_instance_list ',' udp_instance
  ;

udp_instance_list_opt
  : udp_instance_list
  |
  ;

  /* Behavioral statements */

  /* Continuous assignment and net alias statements */

continuous_assign
  : K_assign drive_strength_opt delay3_opt list_of_net_assignments ';'
  | K_assign delay_control_opt list_of_variable_assignments ';'
  ;

list_of_net_assignments
  : net_assignment net_assignment_list_opt
  ;

net_assignment_list
  : ',' net_assignment
  | net_assignment_list ',' net_assignment
  ;

net_assignment_list_opt
  : net_assignment_list
  |
  ;

list_of_variable_assignments
  : variable_assignment variable_assignment_list_opt

net_alias
  : K_alias net_lvalue '=' net_lvalue net_lvalue_assign_list_opt ';'
  ;

net_assignment
  : net_lvalue '=' expression
  ;

  /* Procedural blocks and assignments */

initial_construct
  : K_initial statement_or_null
  ;

final_construct
  : K_final function_statement
  ;

always_construct
  : always_keyword statement
  ;

always_keyword
  : K_always
  | K_always_comb
  | K_always_latch
  | K_always_ff  
  ;

blocking_assignment
  : variable_lvalue '=' delay_or_event_control expression
  | hierarchical_identifier '=' dynamic_array_new
  | hierarchical_identifier select '=' class_new
  | implicit_class_handle_dot hierarchical_identifier select '=' class_new
  | class_scope hierarchical_identifier select '=' class_new
  | package_scope hierarchical_identifier select '=' class_new
  | operator_assignment
  ;

operator_assignment
  : variable_lvalue assignment_operator expression
  ;

assignment_operator
  : '='
  | K_ADD_A
  | K_SUB_A
  | K_MLT_A
  | K_DIV_A
  | K_MOD_A
  | K_AND_A
  | K_OR_A
  | K_XOR_A
  | K_LS_A
  | K_RS_A
  | K_ALS_A
  | K_ARS_A
  ;

nonblocking_assignment
  : variable_lvalue K_LE delay_or_event_control_opt expression
  ;

procedural_continuous_assignment
  : K_assign variable_assignment
  | K_deassign variable_lvalue
  | K_force variable_assignment
  | K_force net_assignment
  | K_release variable_lvalue
  | K_release net_lvalue
  ;

variable_assignment
  : variable_lvalue '=' expression
  ;

variable_assignment_list
  : ',' variable_assignment
  | variable_assignment_list ',' variable_assignment
  ;

variable_assignment_list_opt
  : variable_assignment_list
  |
  ;

  /* Parallel and sequential blocks */

action_block
  : statement_or_null
  | K_else statement_or_null
  | statement K_else statement_or_null
  ;

seq_block
  : K_begin block_item_declarations_opt statement_or_nulls_opt K_end postfix_identifier_opt
  | K_begin ':' identifier block_item_declarations_opt statement_or_nulls_opt K_end postfix_identifier_opt

par_block
  : K_fork block_item_declarations_opt statement_or_nulls_opt join_keyword postfix_identifier_opt
  | K_fork ':' identifier block_item_declarations_opt statement_or_nulls_opt join_keyword postfix_identifier_opt
  ;

join_keyword
  : K_join
  | K_join_any
  | K_join_none
  ;

  /* Statements */

statement_or_null
  : statement
  | attribute_instances_opt ';'
  ;

statement_or_nulls
  : statement_or_null
  | statement_or_nulls statement_or_null
  ;

statement_or_nulls_opt
  : statement_or_nulls
  |
  ;

statement
  : attribute_instances_opt statement_item 
  | identifier ':' attribute_instances_opt statement_item 
  ;

statement_item
  : blocking_assignment ';'
  | nonblocking_assignment ';'
  | procedural_continuous_assignment ';'
  | case_statement
  | conditional_statement
  | inc_or_dec_expression ';'
  | subroutine_call_statement
  | disable_statement
  | event_trigger
  | loop_statement
  | jump_statement
  | par_block
  | procedural_timing_control_statement
  | seq_block
  | wait_statement
  | procedural_assertion_statement
  | clocking_drive ';'
  | randsequence_statement
  | randcase_statement
  | expect_property_statement
  ;

function_statement
  : statement
  ;

function_statement_or_null
  : function_statement
  | attribute_instances_opt ';'
  ;

function_statement_or_nulls
  : function_statement_or_null
  | function_statement_or_nulls function_statement_or_null
  ;

function_statement_or_nulls_opt
  : function_statement_or_nulls
  |
  ;

variable_identifier_list
  : identifier identifiers_opt
  ;

  /* Timing control statements */

procedural_timing_control_statement
  : procedural_timing_control statement_or_null
  ;

delay_or_event_control
  : delay_control
  | event_control
  | K_repeat '(' expression ')' event_control
  ;

delay_or_event_control_opt
  : delay_or_event_control
  |
  ;

delay_control
  : '#' delay_value
  | '#' '(' mintypmax_expression ')' 
  ;

delay_control_opt
  : delay_control
  |
  ;

event_control
  : '@' hierarchical_identifier
  | '@' '(' event_expression ')'
  | '@' '*'
  | '@' sequence_instance
  ;

event_expression
  : edge_identifier_opt expression
  | edge_identifier_opt expression K_iff expression
  | sequence_instance
  | sequence_instance K_iff expression
  | event_expression K_or event_expression
  | event_expression ',' event_expression
  ;

procedural_timing_control
  : delay_control
  | event_control
  | cycle_delay
  ;

jump_statement
  : K_return expression_opt ';'
  | K_break ';'
  | K_continue ';'
  ;

wait_statement
  : K_wait '(' expression ')' statement_or_null
  | K_wait K_fork ';'
  | K_wait_order '(' hierarchical_identifier hierarchical_identifier_list_opt ')' action_block
  ;

event_trigger
  : K_TRIGGER hierarchical_identifier ';'
  | K_TRIGGER '>' delay_or_event_control_opt hierarchical_identifier ';'

disable_statement
  : K_disable hierarchical_identifier ';'
  | K_disable K_fork ';'

  /* Conditional statements */

conditional_statement
  : K_if '(' cond_predicate ')' statement_or_null
  | K_if '(' cond_predicate ')' statement_or_null K_else statement_or_null
  | unique_priority_if_statement
  ;

unique_priority_if_statement
  : unique_priority_opt K_if '(' cond_predicate ')' statement_or_null else_if_list_opt
  | unique_priority_opt K_if '(' cond_predicate ')' statement_or_null else_if_list_opt K_else statement_or_null
  ;

else_if_list
  : K_else K_if '(' cond_predicate ')' statement_or_null
  | else_if_list K_else K_if '(' cond_predicate ')' statement_or_null
  ;

else_if_list_opt
  : else_if_list
  |
  ;

unique_priority
  : K_unique
  | K_priority
  ;

unique_priority_opt
  : unique_priority
  |
  ;

cond_predicate
  : expression_or_cond_pattern expression_or_cond_pattern_tand_list_opt
  ;

expression_or_cond_pattern
  : expression
  | cond_pattern
  ;

expression_or_cond_pattern_tand_list
  : K_TAND expression_or_cond_pattern
  | expression_or_cond_pattern_tand_list K_TAND expression_or_cond_pattern
  ;

expression_or_cond_pattern_tand_list_opt
  : expression_or_cond_pattern_tand_list
  |
  ;

cond_pattern
  : expression K_matches pattern
  ;

  /* Case statements */

case_statement
  : unique_priority_opt case_keyword '(' expression ')' case_item case_items_opt K_endcase
  | unique_priority_opt case_keyword '(' expression ')' K_matches case_pattern_item case_pattern_items_opt K_endcase
  ;

case_keyword
  : K_case
  | K_casez
  | K_casex
  ;

case_item
  : expression expression_list_opt ':' statement_or_null
  | K_default statement_or_null
  | K_default ':' statement_or_null
  ;

case_items
  : case_item
  | case_items case_item
  ;

case_items_opt
  :  case_items
  |
  ;

case_pattern_item 
  : pattern ':' statement_or_null
  | pattern K_TAND expression ':' statement_or_null
  | K_default statement_or_null
  | K_default ':' statement_or_null
  ;

case_pattern_items
  : case_pattern_item
  | case_pattern_items case_pattern_item
  ;

case_pattern_items_opt
  : case_pattern_items
  |
  ;

randcase_statement
  : K_randcase randcase_item randcase_items_opt K_endcase
  ;

randcase_item
  : expression ':' statement_or_null
  ;

randcase_items
  : randcase_item
  | randcase_items randcase_item
  ;

randcase_items_opt
  : randcase_items
  |
  ;

  /* Patterns */

pattern
  : '.' identifier
  | K_PS
  | constant_expression
  | K_tagged identifier pattern_opt
  | '{' pattern pattern_list_opt '}'
  | '{' identifier ':' pattern member_identifier_pattern_list_opt '}'
  ;

pattern_opt
  : pattern
  |
  ;

pattern_list
  : ',' pattern
  | pattern_list ',' pattern
  ;

pattern_list_opt
  : pattern_list
  |
  ;

member_identifier_pattern_list
  : ',' identifier ':' pattern
  | member_identifier_pattern_list ',' identifier ':' pattern
  ;

member_identifier_pattern_list_opt
  : member_identifier_pattern_list
  |
  ;

  /* Looping statements */

loop_statement
  : K_forever statement_or_null
  | K_repeat '(' expression ')' statement_or_null
  | K_while '(' expression ')' statement_or_null
  | K_for '(' for_initialization ';' expression ';' for_step ')' statement_or_null
  | K_do statement_or_null K_while '(' expression ')' ';'
  | K_foreach '(' identifier loop_variables_opt ')' statement
  ;

for_initialization
  : list_of_variable_assignments
  | for_variable_declaration for_variable_declaration_list_opt
  ;

for_variable_declaration
  : data_type identifier '=' expression variable_expression_assign_list_opt
  ;

for_variable_declaration_list
  : ',' for_variable_declaration
  | for_variable_declaration_list ',' for_variable_declaration
  ;

for_variable_declaration_list_opt
  : for_variable_declaration_list
  |
  ;

variable_expression_assign_list
  : ',' identifier '=' expression
  | variable_expression_assign_list ',' identifier '=' expression
  ;

variable_expression_assign_list_opt
  : variable_expression_assign_list
  |
  ;

for_step
  : for_step_assignment for_step_assignment_list_opt

for_step_assignment
  : operator_assignment
  | inc_or_dec_expression
  ;

for_step_assignment_list
  : ',' for_step_assignment
  | for_step_assignment_list ',' for_step_assignment
  ;

for_step_assignment_list_opt
  : for_step_assignment_list
  |
  ;

loop_variables
  : identifier_opt identifier_opt_list_opt
  ;

loop_variables_opt
  : loop_variables
  |
  ;

  /* Subroutine call statements */

subroutine_call_statement
  : subroutine_call ';'
  | K_void '\'' '(' function_subroutine_call ')' ';'
  ;

  /* Assertion statements */

procedural_assertion_statement
  : concurrent_assertion_statement
  | immediate_assert_statement
  ;

immediate_assert_statement
  : K_assert '(' expression ')' action_block
  ;

  /* Clocking block */

clocking_declaration
  : K_clocking identifier_opt clocking_event ';'
  | K_default K_clocking identifier_opt clocking_event ';' clocking_items_opt K_endclocking postfix_identifier_opt
  ;

clocking_event
  : '@' identifier
  | '@' '(' event_expression ')'
  ;

clocking_event_opt
  : clocking_event
  |
  ;

clocking_item
  : K_default default_skew ';'
  | clocking_direction list_of_clocking_decl_assign ';'
  | attribute_instances_opt concurrent_assertion_item_declaration
  ;

clocking_items
  : clocking_item
  | clocking_items clocking_item
  ;

clocking_items_opt
  : clocking_items
  |
  ;

default_skew
  : K_input clocking_skew
  | K_output clocking_skew
  | K_input clocking_skew K_output clocking_skew
  ;

clocking_direction
  : K_input clocking_skew_opt
  | K_output clocking_skew_opt
  | K_input clocking_skew_opt K_output clocking_skew_opt
  | K_inout
  ;

list_of_clocking_decl_assign
  : clocking_decl_assign clocking_decl_assign_list_opt
  ;

clocking_decl_assign
  : identifier
  | identifier '=' hierarchical_identifier
  ;

clocking_decl_assign_list
  : ',' clocking_decl_assign
  | clocking_decl_assign_list ',' clocking_decl_assign
  ;

clocking_decl_assign_list_opt
  : clocking_decl_assign_list
  |
  ;

clocking_skew
  : edge_identifier delay_control_opt
  | delay_control 
  ;

clocking_skew_opt
  : clocking_skew
  |
  ;

clocking_drive
  : clockvar_expression K_LE cycle_delay_opt expression
  | cycle_delay clockvar_expression K_LE expression
  ;

cycle_delay
  : K_PP NUMBER
  | K_PP UNUSED_NUMBER
  | K_PP identifier
  | K_PP '(' expression ')'
  ;

cycle_delay_opt
  : cycle_delay
  |
  ;

clockvar
  : hierarchical_identifier
  ;

clockvar_expression
  : clockvar select
  ;

  /* Randsequence */

randsequence_statement
  : K_randsequence '(' identifier_opt ')' production productions_opt K_endsequence
  ;

production
  : function_data_type_opt identifier tf_port_lister_opt ':' rs_rule rs_rule_list_opt ';'
  ;

productions
  : production
  | productions production
  ;

productions_opt
  : productions
  |
  ;

rs_rule
  : rs_production_list
  | rs_production_list ':' '=' expression rs_code_block_opt
  ;

rs_rule_list
  : '|' rs_rule
  | rs_rule_list '|' rs_rule
  ;

rs_rule_list_opt
  : rs_rule_list
  |
  ;

rs_production_list
  : rs_prod rs_prods_opt
  | K_rand K_join production_item production_item production_items_opt
  | K_rand K_join '(' expression ')' production_item production_item production_items_opt

rs_code_block
  : '{' data_declarations_opt statement_or_nulls_opt '}'

rs_code_block_opt
  : rs_code_block
  |
  ;

rs_prod
  : production_item
  | rs_code_block
  | rs_if_else
  | rs_repeat
  | rs_case
  ;

rs_prods
  : rs_prod
  | rs_prods rs_prod
  ;

rs_prods_opt
  : rs_prods
  |
  ;

production_item
  : identifier list_of_arguments_opt
  ;

production_items
  : production_item
  | production_items production_item
  ;

production_items_opt
  : production_items
  |
  ;

rs_if_else
  : K_if '(' expression ')' production_item 
  | K_if '(' expression ')' production_item K_else production_item
  ;

rs_repeat
  : K_repeat '(' expression ')' production_item
  ;

rs_case
  : K_case '(' expression ')' rs_case_item rs_case_items_opt K_endcase
  ;

rs_case_item
  : expression expression_list_opt ':' production_item ';'
  | K_default production_item ';'
  | K_default ':' production_item ';'
  ;

rs_case_items
  : rs_case_item
  | rs_case_items rs_case_item
  ;

rs_case_items_opt
  : rs_case_items
  |
  ;

  /* Specify section */

  /* Specify block declaration */

specify_block
  : K_specify specify_items_opt K_endspecify
  ;

specify_item
  : specparam_declaration
  | pulsestyle_declaration
  | showcancelled_declaration
  | path_declaration
  | system_timing_check
  ;

specify_items
  : specify_item
  | specify_items specify_item
  ;

specify_items_opt
  : specify_items
  |
  ;

pulsestyle_declaration
  : K_pulsestyle_onevent list_of_path_outputs ';'
  | K_pulsestyle_ondetect list_of_path_outputs ';'
  ;

showcancelled_declaration
  : K_showcancelled list_of_path_outputs ';'
  | K_noshowcancelled list_of_path_outputs ';'
  ;

  /* Specify path declarations */

path_declaration
  : simple_path_declaration ';'
  | edge_sensitive_path_declaration ';'
  | state_dependent_path_declaration ';'
  ;

simple_path_declaration
  : parallel_path_description '=' path_delay_value
  | full_path_description '=' path_delay_value
  ;

parallel_path_description
  : '(' specify_input_terminal_descriptor polarity_operator_opt K_EG specify_output_terminal_descriptor ')'
  ;

full_path_description
  : '(' list_of_path_inputs polarity_operator_opt K_SG list_of_path_outputs ')'
  ;

list_of_path_inputs
  : specify_input_terminal_descriptor specify_input_terminal_descriptor_list_opt
  ;

list_of_path_outputs
  : specify_output_terminal_descriptor specify_output_terminal_descriptor_list_opt
  ;

  /* Specify block terminals */

specify_input_terminal_descriptor
  : input_identifier
  | input_identifier '[' constant_range_expression ']'
  ;

specify_input_terminal_descriptor_list
  : ',' specify_input_terminal_descriptor
  | specify_input_terminal_descriptor_list ',' specify_input_terminal_descriptor
  ;

specify_input_terminal_descriptor_list_opt
  : specify_input_terminal_descriptor_list
  |
  ;

specify_output_terminal_descriptor
  : output_identifier
  | output_identifier '[' constant_range_expression ']'
  ;

specify_output_terminal_descriptor_list
  : ',' specify_output_terminal_descriptor
  | specify_output_terminal_descriptor_list ',' specify_output_terminal_descriptor
  ;

specify_output_terminal_descriptor_list_opt
  : specify_output_terminal_descriptor_list
  |
  ;

input_identifier
  : identifier
  | identifier '.' identifier
  ;

output_identifier
  : identifier
  | identifier '.' identifier
  ;

  /* Specify path delays */

path_delay_value
  : list_of_path_delay_expressions
  | '(' list_of_path_delay_expressions ')'
  ;

list_of_path_delay_expressions
  : path_delay_expression
  | path_delay_expression ',' path_delay_expression
  | path_delay_expression ',' path_delay_expression ',' path_delay_expression
  | path_delay_expression ',' path_delay_expression ',' path_delay_expression ',' path_delay_expression ',' path_delay_expression ',' path_delay_expression
  | path_delay_expression ',' path_delay_expression ',' path_delay_expression ',' path_delay_expression ',' path_delay_expression ',' path_delay_expression ',' path_delay_expression ',' path_delay_expression ',' path_delay_expression ',' path_delay_expression ',' path_delay_expression ',' path_delay_expression
  ;

path_delay_expression
  : constant_mintypmax_expression
  ;

edge_sensitive_path_declaration
  : parallel_edge_sensitive_path_description '=' path_delay_value
  | full_edge_sensitive_path_description '=' path_delay_value
  ;

parallel_edge_sensitive_path_description
  : '(' edge_identifier_opt specify_input_terminal_descriptor K_EG '(' specify_output_terminal_descriptor polarity_operator_opt ':' data_source_expression ')' ')'
  ;

full_edge_sensitive_path_description
  : '(' edge_identifier_opt list_of_path_inputs K_SG '(' list_of_path_outputs polarity_operator_opt ':' data_source_expression ')' ')'
  ;

data_source_expression
  : expression
  ;

edge_identifier
  : K_posedge
  | K_negedge
  ;

edge_identifier_opt
  : edge_identifier
  |
  ;

state_dependent_path_declaration
  : K_if '(' module_path_expression ')' simple_path_declaration
  | K_if '(' module_path_expression ')' edge_sensitive_path_declaration
  | K_ifnone simple_path_declaration
  ;

polarity_operator
  : '+'
  | '-'
  ;

polarity_operator_opt
  : polarity_operator
  |
  ;

  /* System timing checks */

  /* System timing check commands */

system_timing_check
  : Ssetup_timing_check
  | Shold_timing_check
  | Ssetuphold_timing_check
  | Srecovery_timing_check
  | Sremoval_timing_check
  | Srecrem_timing_check
  | Sskew_timing_check
  | Stimeskew_timing_check
  | Sfullskew_timing_check
  | Speriod_timing_check
  | Swidth_timing_check
  | Snochange_timing_check
  ;

Ssetup_timing_check
  : K_Ssetup '(' data_event ',' reference_event ',' timing_check_limit ')' ';'
  | K_Ssetup '(' data_event ',' reference_event ',' timing_check_limit ',' notifier_opt ')' ';'
  ;

Shold_timing_check
  : K_Shold '(' reference_event ',' data_event ',' timing_check_limit ')' ';'
  | K_Shold '(' reference_event ',' data_event ',' timing_check_limit ',' notifier_opt ')' ';'
  ;

Ssetuphold_timing_check
  : K_Ssetuphold '(' reference_event ',' data_event ',' timing_check_limit ',' timing_check_limit ')' ';'
  | K_Ssetuphold '(' reference_event ',' data_event ',' timing_check_limit ',' timing_check_limit ',' notifier_opt ')' ';'
  | K_Ssetuphold '(' reference_event ',' data_event ',' timing_check_limit ',' timing_check_limit ',' notifier_opt ',' stamptime_condition_opt ')' ';'
  | K_Ssetuphold '(' reference_event ',' data_event ',' timing_check_limit ',' timing_check_limit ',' notifier_opt ',' stamptime_condition_opt ',' checktime_condition_opt ')' ';'
  | K_Ssetuphold '(' reference_event ',' data_event ',' timing_check_limit ',' timing_check_limit ',' notifier_opt ',' stamptime_condition_opt ',' checktime_condition_opt ',' delayed_reference_opt ')' ';'
  | K_Ssetuphold '(' reference_event ',' data_event ',' timing_check_limit ',' timing_check_limit ',' notifier_opt ',' stamptime_condition_opt ',' checktime_condition_opt ',' delayed_reference_opt ',' delayed_data_opt ')' ';'
  ;

Srecovery_timing_check
  : K_Srecovery '(' reference_event ',' data_event ',' timing_check_limit ')' ';'
  | K_Srecovery '(' reference_event ',' data_event ',' timing_check_limit ',' notifier_opt ')' ';'
  ;

Sremoval_timing_check
  : K_Sremoval '(' reference_event ',' data_event ',' timing_check_limit ')' ';'
  | K_Sremoval '(' reference_event ',' data_event ',' timing_check_limit ',' notifier_opt ')' ';'
  ;

Srecrem_timing_check
  : K_Srecrem '(' reference_event ',' data_event ',' timing_check_limit ',' timing_check_limit ')' ';'
  | K_Srecrem '(' reference_event ',' data_event ',' timing_check_limit ',' timing_check_limit ',' notifier_opt ')' ';'
  | K_Srecrem '(' reference_event ',' data_event ',' timing_check_limit ',' timing_check_limit ',' notifier_opt ',' stamptime_condition_opt ')' ';'
  | K_Srecrem '(' reference_event ',' data_event ',' timing_check_limit ',' timing_check_limit ',' notifier_opt ',' stamptime_condition_opt ',' checktime_condition_opt ')' ';'
  | K_Srecrem '(' reference_event ',' data_event ',' timing_check_limit ',' timing_check_limit ',' notifier_opt ',' stamptime_condition_opt ',' checktime_condition_opt ',' delayed_reference_opt ')' ';'
  | K_Srecrem '(' reference_event ',' data_event ',' timing_check_limit ',' timing_check_limit ',' notifier_opt ',' stamptime_condition_opt ',' checktime_condition_opt ',' delayed_reference_opt ',' delayed_data_opt ')' ';'
  ;

Sskew_timing_check
  : K_Sskew '(' reference_event ',' data_event ',' timing_check_limit ')' ';'
  | K_Sskew '(' reference_event ',' data_event ',' timing_check_limit ',' notifier_opt ')' ';'
  ;

Stimeskew_timing_check 
  : K_Stimeskew '(' reference_event ',' data_event ',' timing_check_limit ')' ';' 
  | K_Stimeskew '(' reference_event ',' data_event ',' timing_check_limit ',' notifier_opt ')' ';' 
  | K_Stimeskew '(' reference_event ',' data_event ',' timing_check_limit ',' notifier_opt ',' event_based_flag_opt ')' ';' 
  | K_Stimeskew '(' reference_event ',' data_event ',' timing_check_limit ',' notifier_opt ',' event_based_flag_opt ',' remain_active_flag_opt ')' ';' 
  ;

Sfullskew_timing_check
  : K_Sfullskew '(' reference_event ',' data_event ',' timing_check_limit ',' timing_check_limit ')' ';'
  | K_Sfullskew '(' reference_event ',' data_event ',' timing_check_limit ',' timing_check_limit ',' notifier_opt ')' ';'
  | K_Sfullskew '(' reference_event ',' data_event ',' timing_check_limit ',' timing_check_limit ',' notifier_opt ',' event_based_flag_opt ')' ';'
  | K_Sfullskew '(' reference_event ',' data_event ',' timing_check_limit ',' timing_check_limit ',' notifier_opt ',' event_based_flag_opt ',' remain_active_flag_opt ')' ';'
  ;

Speriod_timing_check
  : K_Speriod '(' controlled_reference_event ',' timing_check_limit ')' ';'
  | K_Speriod '(' controlled_reference_event ',' timing_check_limit ',' notifier_opt ')' ';'
  ;

Swidth_timing_check
  : K_Swidth '(' controlled_reference_event ',' timing_check_limit ',' threshold ')' ';'
  | K_Swidth '(' controlled_reference_event ',' timing_check_limit ',' threshold ',' notifier_opt ')' ';'
  ;

Snochange_timing_check
  : K_Snochange '(' reference_event ',' data_event ',' start_edge_offset ',' end_edge_offset ')' ';'
  | K_Snochange '(' reference_event ',' data_event ',' start_edge_offset ',' end_edge_offset ',' notifier_opt ')' ';'
  ;

  /* System timing check command arguments */

checktime_condition
  : mintypmax_expression
  ;

checktime_condition_opt
  : checktime_condition
  |
  ;

controlled_reference_event
  : controlled_timing_check_event
  ;

data_event
  : timing_check_event
  ;

delayed_data
  : identifier
  | identifier '[' constant_mintypmax_expression ']'
  ;

delayed_data_opt
  : delayed_data
  |
  ;

delayed_reference
  : identifier
  | identifier '[' constant_mintypmax_expression ']'
  ;

delayed_reference_opt
  : delayed_reference
  |
  ;

end_edge_offset
  : mintypmax_expression
  ;

event_based_flag
  : constant_expression
  ;

event_based_flag_opt
  : event_based_flag
  |
  ;

notifier
  : identifier
  ;

notifier_opt
  : notifier
  |
  ;

reference_event
  : timing_check_event
  ;

remain_active_flag
  : constant_mintypmax_expression
  ;

remain_active_flag_opt
  : remain_active_flag
  |
  ;

stamptime_condition
  : mintypmax_expression
  ;

stamptime_condition_opt
  : stamptime_condition
  |
  ;

start_edge_offset
  : mintypmax_expression
  ;

threshold
  : constant_expression
  ;

timing_check_limit
  : expression
  ;

  /* System timing check event definitions */

timing_check_event
  : timing_check_event_control_opt specify_terminal_descriptor
  | timing_check_event_control_opt specify_terminal_descriptor K_TAND timing_check_condition
  ;

controlled_timing_check_event
  : timing_check_event_control specify_terminal_descriptor
  | timing_check_event_control specify_terminal_descriptor K_TAND timing_check_condition
  ;

timing_check_event_control
  : K_posedge
  | K_negedge
  | edge_control_specifier
  ;

timing_check_event_control_opt
  : timing_check_event_control
  |
  ;

specify_terminal_descriptor
  : specify_input_terminal_descriptor
  | specify_output_terminal_descriptor
  ;

edge_control_specifier
  : K_edge
  | K_edge { lex_start_udp_table(); } edge_descriptor { lex_end_udp_table(); } edge_descriptor_list_opt
  ;

edge_descriptor
  : '0' '1'
  | '1' '0'
  | z_or_x zero_or_one
  | zero_or_one z_or_x
  ;

edge_descriptor_list
  : ',' edge_descriptor
  | edge_descriptor_list ',' edge_descriptor
  ;

edge_descriptor_list_opt
  : edge_descriptor_list
  |
  ;

zero_or_one
  : '0'
  | '1'
  ;

z_or_x
  : 'x'
  | 'z'
  ;

timing_check_condition
  : scalar_timing_check_condition
  | '(' scalar_timing_check_condition ')'
  ;

scalar_timing_check_condition
  : expression
  | '~' expression
  | expression K_EQ scalar_constant
  | expression K_CEQ scalar_constant
  | expression K_NE scalar_constant
  | expression K_CNE scalar_constant
  ;

scalar_constant
  : NUMBER
  | UNUSED_NUMBER
  ;

  /* Expressions */

  /* Concatenations */

concatenation
  : '{' expression expression_list_opt '}'
  | '{' struct_or_array_member_label ':' expression struct_or_array_member_label_expression_list_opt '}'
  ;

struct_or_array_member_label_expression_list
  : ',' struct_or_array_member_label ':' expression
  | struct_or_array_member_label_expression_list ',' struct_or_array_member_label ':' expression
  ;

struct_or_array_member_label_expression_list_opt
  : struct_or_array_member_label_expression_list
  |
  ;

constant_concatenation
  : '{' constant_expression constant_expression_list_opt '}'
  | '{' struct_or_array_member_label ':' constant_expression struct_or_array_member_label_constant_expression_list_opt '}'
  ;

struct_or_array_member_label
  : K_default
  | constant_expression { /* identifier only valid for structs */ }
  ;

struct_or_array_member_label_constant_expression_list
  : ',' struct_or_array_member_label ':' constant_expression
  | struct_or_array_member_label_constant_expression_list ',' struct_or_array_member_label ':' constant_expression
  ;

struct_or_array_member_label_constant_expression_list_opt
  : struct_or_array_member_label_constant_expression_list
  |
  ;

constant_multiple_concatenation
  : '{' constant_expression constant_concatenation '}'
  ;

module_path_concatenation
  : '{' module_path_expression module_path_expression_list_opt '}'
  ;

module_path_multiple_concatenation
  : '{' constant_expression module_path_concatenation '}'
  ;

multiple_concatenation
  : '{' expression concatenation '}'
  ;

streaming_expression
  : '{' stream_operator slice_size stream_concatenation '}'
  | '{' stream_operator stream_concatenation '}'
  ;

stream_operator
  : K_LS
  | K_RS
  ;

slice_size
  : ps_identifier
  | constant_expression
  ;

stream_concatenation
  : '{' stream_expression stream_expression_list_opt '}'
  ;

stream_expression
  : expression
  | expression K_with array_range_expression_opt
  ;

stream_expression_list
  : ',' stream_expression
  | stream_expression_list ',' stream_expression
  ;

stream_expression_list_opt
  : stream_expression_list
  |
  ;

array_range_expression
  : expression
  | expression ':' expression
  | expression K_PO_POS expression
  | expression K_PO_NEG expression
  ;

array_range_expression_opt
  : array_range_expression
  |
  ;

empty_queue
  : '{' '}'
  ;

  /* Subroutine calls */

constant_function_call
  : function_subroutine_call
  ;

tf_call
  : ps_or_hierarchical_identifier attribute_instances_opt list_of_arguments_opt
  ;

system_tf_call
  : system_tf_identifier list_of_arguments_opt
  ;

subroutine_call
  : tf_call
  | system_tf_call
  | method_call
  | randomize_call
  ;

function_subroutine_call
  : subroutine_call
  ;

list_of_arguments
  : expression_opt expression_opt_list_opt identifier_expression_opt_list_opt
  | '.' identifier '(' expression_opt ')' identifier_expression_opt_list_opt
  ;

expression_opt_list
  : ',' expression_opt
  | expression_opt_list ',' expression_opt
  ;

expression_opt_list_opt
  : expression_opt_list
  |
  ;

identifier_expression_opt_list
  : ',' '.' identifier '(' expression_opt ')'
  | identifier_expression_opt_list ',' '.' identifier '(' expression_opt ')'
  ;

identifier_expression_opt_list_opt
  : identifier_expression_opt_list
  |
  ;

method_call
  : method_call_root_dot method_call_body
  ;

method_call_body
  : identifier attribute_instances_opt list_of_arguments_opt
  | built_in_method_call
  ;

built_in_method_call
  : array_manipulation_call
  | randomize_call
  ;

array_manipulation_call
  : array_method_name attribute_instances_opt list_of_arguments_opt
  | array_method_name attribute_instances_opt list_of_arguments_opt K_with '(' expression ')'
  ;

randomize_call
  : K_randomize attribute_instances_opt
  | K_randomize attribute_instances_opt '(' ')'
  | K_randomize attribute_instances_opt '(' variable_identifier_list ')'
  | K_randomize attribute_instances_opt '(' K_null ')'
  | K_randomize attribute_instances_opt K_with constraint_block
  | K_randomize attribute_instances_opt '(' ')' K_with constraint_block
  | K_randomize attribute_instances_opt '(' variable_identifier_list ')' K_with constraint_block
  | K_randomize attribute_instances_opt '(' K_null ')' K_with constraint_block
  ;

method_call_root_dot
  : expression '.'
  | implicit_class_handle_dot
  ;

array_method_name
  : identifier
  | K_unique
  | K_and
  | K_or
  | K_xor
  ;

  /* Expressions */

inc_or_dec_expression
  : inc_or_dec_operator attribute_instances_opt variable_lvalue
  | variable_lvalue attribute_instances_opt inc_or_dec_operator 
  ;

conditional_expression
  : cond_predicate '?' attribute_instances_opt expression ':' expression
  ;

constant_expression
  : constant_primary
  | unary_operator attribute_instances_opt constant_primary
  | constant_expression binary_operator attribute_instances_opt constant_expression
  | constant_expression '?' attribute_instances_opt constant_expression ':' constant_expression
  ;

constant_expression_list
  : ',' constant_expression
  | constant_expression_list ',' constant_expression
  ;

constant_expression_list_opt
  : constant_expression_list
  |
  ;

constant_mintypmax_expression
  : constant_expression
  | constant_expression ':' constant_expression ':' constant_expression
  ;

constant_param_expression
  : constant_mintypmax_expression
  | data_type
  | '$'
  ;

param_expression
  : mintypmax_expression
  | data_type
  ;

param_expression_opt
  : param_expression
  |
  ;

constant_range_expression
  : constant_expression
  | constant_part_select_range
  ;

constant_part_select_range
  : constant_range
  | constant_indexed_range
  ;

constant_range
  : constant_expression ':' constant_expression
  ;

constant_indexed_range
  : constant_expression K_PO_POS constant_expression
  | constant_expression K_PO_NEG constant_expression
  ;

expression
  : primary
  | unary_operator attribute_instances_opt primary
  | inc_or_dec_expression
  | '(' operator_assignment ')'
  | expression binary_operator attribute_instances_opt expression
  | conditional_expression
  | inside_expression
  | tagged_union_expression
  ;

expression_opt
  : expression
  |
  ;

expression_list
  : ',' expression
  | expression_list ',' expression
  ;

expression_list_opt
  : expression_list
  |
  ;

tagged_union_expression
  : K_tagged identifier expression_opt
  ;

inside_expression
  : expression K_inside open_range_lists_opt
  ;

value_range
  : expression
  | '[' expression ':' expression ']'
  ;

mintypmax_expression
  : expression
  | expression ':' expression ':' expression
  ;

module_path_conditional_expression
  : module_path_expression '?' attribute_instances_opt module_path_expression ':' module_path_expression
  ;

module_path_expression
  : module_path_primary
  | unary_module_path_operator attribute_instances_opt module_path_primary
  | module_path_expression binary_module_path_operator attribute_instances_opt module_path_expression
  | module_path_conditional_expression
  ;

module_path_expression_list
  : ',' module_path_expression
  | module_path_expression_list ',' module_path_expression
  ;

module_path_expression_list_opt
  : module_path_expression_list
  |
  ;

module_path_mintypmax_expression
  : module_path_expression
  | module_path_expression ':' module_path_expression ':' module_path_expression
  ;

part_select_range
  : constant_range
  | indexed_range
  ;

indexed_range
  : expression K_PO_POS constant_expression
  | expression K_PO_NEG constant_expression
  ;

  /* Primaries */

constant_primary
  : primary_literal
  | ps_identifier
  | identifier
  | package_scope identifier
  | class_scope identifier
  | constant_concatenation
  | constant_multiple_concatenation
  | constant_function_call
  | '(' constant_mintypmax_expression ')'
  | constant_cast
  ;

module_path_primary
  : number
  | identifier
  | module_path_concatenation
  | module_path_multiple_concatenation
  | function_subroutine_call
  | '(' module_path_mintypmax_expression ')'
  ;

primary
  : primary_literal
  | hierarchical_identifier select
  | implicit_class_handle_dot hierarchical_identifier select
  | class_scope hierarchical_identifier select
  | package_scope hierarchical_identifier select
  | empty_queue
  | concatenation
  | multiple_concatenation
  | function_subroutine_call
  | '(' mintypmax_expression ')'
  | cast
  | streaming_expression
  | sequence_method_call
  | '$'
  | K_null
  ;

time_literal
  : NUMBER { lex_start_time_unit(); } time_unit { lex_end_time_unit(); }
  | UNUSED_NUMBER { lex_start_time_unit(); } time_unit { lex_end_time_unit(); }
  | NUMBER '.' NUMBER { lex_start_time_unit(); } time_unit { lex_end_time_unit(); }
  | UNUSED_NUMBER '.' UNUSED_NUMBER { lex_start_time_unit(); } time_unit { lex_end_time_unit(); }
  ;

time_unit
  : K_TU_S
  | K_TU_MS
  | K_TU_US
  | K_TU_NS
  | K_TU_PS
  | K_TU_FS
  | K_TU_STEP
  ;

implicit_class_handle_dot
  : K_this '.'
  | K_super '.'
  | K_this '.' K_super '.'
  ;

select
  : select_expression_list_opt
  | select_expression_list_opt '[' part_select_range ']'
  ;

select_expression_list
  : '[' expression ']'
  | select_expression_list '[' expression ']'
  ;

select_expression_list_opt
  : select_expression_list
  |
  ;

constant_select
  : select_constant_expression_list_opt
  | select_constant_expression_list_opt '[' constant_part_select_range ']'
  ;

select_constant_expression_list
  : '[' constant_expression ']'
  | select_constant_expression_list '[' constant_expression ']'
  ;

select_constant_expression_list_opt
  : select_constant_expression_list
  |
  ;

primary_literal
  : number
  | time_literal
  | string_literal
  ;

constant_cast
  : casting_type '\'' '(' constant_expression ')'
  | casting_type '\'' constant_concatenation
  | casting_type '\'' constant_multiple_concatenation
  ;

cast
  : casting_type '\'' '(' expression ')'
  | casting_type '\'' concatenation
  | casting_type '\'' multiple_concatenation
  ;

  /* Expression left-side values */

net_lvalue
  : ps_or_hierarchical_identifier constant_select
  | '{' net_lvalue net_lvalue_list_opt '}'
  ;

net_lvalue_list
  : ',' net_lvalue
  | net_lvalue_list ',' net_lvalue
  ;

net_lvalue_list_opt
  : net_lvalue_list
  |
  ;

variable_lvalue
  : hierarchical_identifier select
  | implicit_class_handle_dot hierarchical_identifier select
  | package_scope hierarchical_identifier select
  | '{' variable_lvalue variable_lvalue_list_opt '}'
  ;

variable_lvalue_list
  : ',' variable_lvalue
  | variable_lvalue_list ',' variable_lvalue
  ;

variable_lvalue_list_opt
  : variable_lvalue_list
  |
  ;

  /* Operators */

unary_operator
  : '+'
  | '-'
  | '!'
  | '~'
  | '&'
  | K_NAND
  | '|'
  | K_NOR
  | '^'
  | K_NXOR
  ;

binary_operator
  : '+'
  | '-'
  | '*'
  | '/'
  | '%'
  | K_EQ
  | K_NE
  | K_CEQ
  | K_CNE
  | K_PEQ
  | K_PNE
  | K_LAND
  | K_LOR
  | K_POW
  | '<'
  | K_LE
  | '>'
  | K_GE
  | '&'
  | '|'
  | '^'
  | K_NXOR
  | K_LS
  | K_RS
  | K_LSS
  | K_RSS
  ;

inc_or_dec_operator
  : K_INC
  | K_DEC
  ;

unary_module_path_operator
  : '!'
  | '~'
  | '&'
  | K_NAND
  | '|'
  | K_NOR
  | '^'
  | K_NXOR
  ;

binary_module_path_operator
  : K_EQ
  | K_NE
  | K_LAND
  | K_LOR
  | '&'
  | '|'
  | '^'
  | K_NXOR
  ;

  /* Numbers */

number
  : NUMBER
  | UNUSED_NUMBER
  | REALTIME
  | UNUSED_REALTIME
  ;

  /* Strings */

string_literal
  : STRING
  | UNUSED_STRING
  ;

  /* General */

  /* Attributes */

attribute_instance
  : K_PSTAR attr_spec attr_spec_list_opt K_STARP

attribute_instances
  : attribute_instance
  | attribute_instances attribute_instance
  ;

attribute_instances_opt
  : attribute_instances
  |
  ;

attr_spec
  : identifier
  | identifier '=' constant_expression
  ;

attr_spec_list
  : ',' attr_spec
  | attr_spec_list ',' attr_spec
  ;

attr_spec_list_opt
  : attr_spec_list
  |
  ;

  /* Identifiers */

c_identifier
  : C_IDENTIFIER
  | UNUSED_C_IDENTIFIER
  ; /* ::= [ a - zA - Z_ ] { [ a - zA - Z0 - 9_ ] } */

escaped_identifier
  : ESCAPED_IDENTIFIER
  | UNUSED_ESCAPED_IDENTIFIER
  ; /* '\' {any_ASCII_character_except_white_space} white_space */

hierarchical_identifier
  : hierarchical_identifier_tail
  | K_Sroot '.' hierarchical_identifier_tail
  ;

hierarchical_identifier_tail
  : identifier
  | identifier select_constant_expression_list_opt '.' hierarchical_identifier_list
  ;

hierarchical_identifier_list
  : ',' hierarchical_identifier
  | hierarchical_identifier_list ',' hierarchical_identifier
  ;

hierarchical_identifier_list_opt
  : hierarchical_identifier_list
  |
  ;

identifier
  : simple_identifier
  | escaped_identifier
  ;

identifier_opt
  : identifier
  |
  ;

identifier_opt_list
  : ',' identifier_opt
  | identifier_opt_list ',' identifier_opt
  ;

identifier_opt_list_opt
  : identifier_opt_list
  |
  ;

package_scope
  : identifier ':' ':'
  | K_Sunit ':' ':'
  ;

ps_identifier
  : identifier
  | package_scope identifier
  ;

ps_or_hierarchical_identifier
  : ps_identifier
  | hierarchical_identifier
  ;

simple_identifier
  : SIMPLE_IDENTIFIER
  | UNUSED_SIMPLE_IDENTIFIER
  ; /* ::= [ a - zA - Z_ ] { [ a - zA - Z0 - 9_$ ] } */

system_tf_identifier
  : SYSTEM_IDENTIFIER
  | UNUSED_SYSTEM_IDENTIFIER
  ;

  /* Miscellaneous rules not found specifically in the spec */

postfix_identifier_opt
  : ':' identifier
  |
  ;

postfix_new_opt
  : ':' K_new
  |
  ;

net_lvalue_assign_list
  : '=' net_lvalue
  | net_lvalue_assign_list '=' net_lvalue
  ;

net_lvalue_assign_list_opt
  : net_lvalue_assign_list
  |
  ;

list_of_arguments_opt
  : '(' list_of_arguments ')'
  |
  ;

list_of_formals_opt
  : '(' list_of_formals ')'
  |
  ;

tf_port_lister_opt
  : '(' tf_port_list_opt ')'
  |
  ;

actual_arg_lister_opt
  : '(' actual_arg_list ')'
  |
  ;

identifiers
  : identifier
  | identifiers identifier
  ;

identifiers_opt
  : identifiers
  |
  ;

lex_start_import_export
  : { lex_start_import_export(); }
  ;

lex_end_import_export
  : { lex_end_import_export(); }
  ;