1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 2221 2222 2223 2224 2225 2226 2227 2228 2229 2230 2231 2232 2233 2234 2235 2236 2237 2238 2239 2240 2241 2242 2243 2244 2245 2246 2247 2248 2249 2250 2251 2252 2253 2254 2255 2256 2257 2258 2259 2260 2261 2262 2263 2264 2265 2266 2267 2268 2269 2270 2271 2272 2273 2274 2275 2276 2277 2278 2279 2280 2281 2282 2283 2284 2285 2286 2287 2288 2289 2290 2291 2292 2293 2294 2295 2296 2297 2298 2299 2300 2301 2302 2303 2304 2305 2306 2307 2308 2309 2310 2311 2312 2313 2314 2315 2316 2317 2318 2319 2320 2321 2322 2323 2324 2325 2326 2327 2328 2329 2330 2331 2332 2333 2334 2335 2336 2337 2338 2339 2340 2341 2342 2343 2344 2345 2346 2347 2348 2349 2350 2351 2352 2353 2354 2355 2356 2357 2358 2359 2360 2361 2362 2363 2364 2365 2366 2367 2368 2369 2370 2371 2372 2373 2374 2375 2376 2377 2378 2379 2380 2381 2382 2383 2384 2385 2386 2387 2388 2389 2390 2391 2392 2393 2394 2395 2396 2397 2398 2399 2400 2401 2402 2403 2404 2405 2406 2407 2408 2409 2410 2411 2412 2413 2414 2415 2416 2417 2418 2419 2420 2421 2422 2423 2424 2425 2426 2427 2428 2429 2430 2431 2432 2433 2434 2435 2436 2437 2438 2439 2440 2441 2442 2443 2444 2445 2446 2447 2448 2449 2450 2451 2452 2453 2454 2455 2456 2457 2458 2459 2460 2461 2462 2463 2464 2465 2466 2467 2468 2469 2470 2471 2472 2473 2474 2475 2476 2477 2478 2479 2480 2481 2482 2483 2484 2485 2486 2487 2488 2489 2490 2491 2492 2493 2494 2495 2496 2497 2498 2499 2500 2501 2502 2503 2504 2505 2506 2507 2508 2509 2510 2511 2512 2513 2514 2515 2516 2517 2518 2519 2520 2521 2522 2523 2524 2525 2526 2527 2528 2529 2530 2531 2532 2533 2534 2535 2536 2537 2538 2539 2540 2541 2542 2543 2544 2545 2546 2547 2548 2549 2550 2551 2552 2553 2554 2555 2556 2557 2558 2559 2560 2561 2562 2563 2564 2565 2566 2567 2568 2569 2570 2571 2572 2573 2574 2575 2576 2577 2578 2579 2580 2581 2582 2583 2584 2585 2586 2587 2588 2589 2590 2591 2592 2593 2594 2595 2596 2597 2598 2599 2600 2601 2602 2603 2604 2605 2606 2607 2608 2609 2610 2611 2612 2613 2614 2615 2616 2617 2618 2619 2620 2621 2622 2623 2624 2625 2626 2627 2628 2629 2630 2631 2632 2633 2634 2635 2636 2637 2638 2639 2640 2641 2642 2643 2644 2645 2646 2647 2648 2649 2650 2651 2652 2653 2654 2655 2656 2657 2658 2659 2660 2661 2662 2663 2664 2665 2666 2667 2668 2669 2670 2671 2672 2673 2674 2675 2676 2677 2678 2679 2680 2681 2682 2683 2684 2685 2686 2687 2688 2689 2690 2691 2692 2693 2694 2695 2696 2697 2698 2699 2700 2701 2702 2703 2704 2705 2706 2707 2708 2709 2710 2711 2712 2713 2714 2715 2716 2717 2718 2719 2720 2721 2722 2723 2724 2725 2726 2727 2728 2729 2730 2731 2732 2733 2734 2735 2736 2737 2738 2739 2740 2741 2742 2743 2744 2745 2746 2747 2748 2749 2750 2751 2752 2753 2754 2755 2756 2757 2758 2759 2760 2761 2762 2763 2764 2765 2766 2767 2768 2769 2770 2771 2772 2773 2774 2775 2776 2777 2778 2779 2780 2781 2782 2783 2784 2785 2786 2787 2788 2789 2790 2791 2792 2793 2794 2795 2796 2797 2798 2799 2800 2801 2802 2803 2804 2805 2806 2807 2808 2809 2810 2811 2812 2813 2814 2815 2816 2817 2818 2819 2820 2821 2822 2823 2824 2825 2826 2827 2828 2829 2830 2831 2832 2833 2834 2835 2836 2837 2838 2839 2840 2841 2842 2843 2844 2845 2846 2847 2848 2849 2850 2851 2852 2853 2854 2855 2856 2857 2858 2859 2860 2861 2862 2863 2864 2865 2866 2867 2868 2869 2870 2871 2872 2873 2874 2875 2876 2877 2878 2879 2880 2881 2882 2883 2884 2885 2886 2887 2888 2889 2890 2891 2892 2893 2894 2895 2896 2897 2898 2899 2900 2901 2902 2903 2904 2905 2906 2907 2908 2909 2910 2911 2912 2913 2914 2915 2916 2917 2918 2919 2920 2921 2922 2923 2924 2925 2926 2927 2928 2929 2930 2931 2932 2933 2934 2935 2936 2937 2938 2939 2940 2941 2942 2943 2944 2945 2946 2947 2948 2949 2950 2951 2952 2953 2954 2955 2956 2957 2958 2959 2960 2961 2962 2963 2964 2965 2966 2967 2968 2969 2970 2971 2972 2973 2974 2975 2976 2977 2978 2979 2980 2981 2982 2983 2984 2985 2986 2987 2988 2989 2990 2991 2992 2993 2994 2995 2996 2997 2998 2999 3000 3001 3002 3003 3004 3005 3006 3007 3008 3009 3010 3011 3012 3013 3014 3015 3016 3017 3018 3019 3020 3021 3022 3023 3024 3025 3026 3027 3028 3029 3030 3031 3032 3033 3034 3035 3036 3037 3038 3039 3040 3041 3042 3043 3044 3045 3046 3047 3048 3049 3050 3051 3052 3053 3054 3055 3056 3057 3058 3059 3060 3061 3062 3063 3064 3065 3066 3067 3068 3069 3070 3071 3072 3073 3074 3075 3076 3077 3078 3079 3080 3081 3082 3083 3084 3085 3086 3087 3088 3089 3090 3091 3092 3093 3094 3095 3096 3097 3098 3099 3100 3101 3102 3103 3104 3105 3106 3107 3108 3109 3110 3111 3112 3113 3114 3115 3116 3117 3118 3119 3120 3121 3122 3123 3124 3125 3126 3127 3128 3129 3130 3131 3132 3133 3134 3135 3136 3137 3138 3139 3140 3141 3142 3143 3144 3145 3146 3147 3148 3149 3150 3151 3152 3153 3154 3155 3156 3157 3158 3159 3160 3161 3162 3163 3164 3165 3166 3167 3168 3169 3170 3171 3172 3173 3174 3175 3176 3177 3178 3179 3180 3181 3182 3183 3184 3185 3186 3187 3188 3189 3190 3191 3192 3193 3194 3195 3196 3197 3198 3199 3200 3201 3202 3203 3204 3205 3206 3207 3208 3209 3210 3211 3212 3213 3214 3215 3216 3217 3218 3219 3220 3221 3222 3223 3224 3225 3226 3227 3228 3229 3230 3231 3232 3233 3234 3235 3236 3237 3238 3239 3240 3241 3242 3243 3244 3245 3246 3247 3248 3249 3250 3251 3252 3253 3254 3255 3256 3257 3258 3259 3260 3261 3262 3263 3264 3265 3266 3267 3268 3269 3270 3271 3272 3273 3274 3275 3276 3277 3278 3279 3280 3281 3282 3283 3284 3285 3286 3287 3288 3289 3290 3291 3292 3293 3294 3295 3296 3297 3298 3299 3300 3301 3302 3303 3304 3305 3306 3307 3308 3309 3310 3311 3312 3313 3314 3315 3316 3317 3318 3319 3320 3321 3322 3323 3324 3325 3326 3327 3328 3329 3330 3331 3332 3333 3334 3335 3336 3337 3338 3339 3340 3341 3342 3343 3344 3345 3346 3347 3348 3349 3350 3351 3352 3353 3354 3355 3356 3357 3358 3359 3360 3361 3362 3363 3364 3365 3366 3367 3368 3369 3370 3371 3372 3373 3374 3375 3376 3377 3378 3379 3380 3381 3382 3383 3384 3385 3386 3387 3388 3389 3390 3391 3392 3393 3394 3395 3396 3397 3398 3399 3400 3401 3402 3403 3404 3405 3406 3407 3408 3409 3410 3411 3412 3413 3414 3415 3416 3417 3418 3419 3420 3421 3422 3423 3424 3425 3426 3427 3428 3429 3430 3431 3432 3433 3434 3435 3436 3437 3438 3439 3440 3441 3442 3443 3444 3445 3446 3447 3448 3449 3450 3451 3452 3453 3454 3455 3456 3457 3458 3459 3460 3461 3462 3463 3464 3465 3466 3467 3468 3469 3470 3471 3472 3473 3474 3475 3476 3477 3478 3479 3480 3481 3482 3483 3484 3485 3486 3487 3488 3489 3490 3491 3492 3493 3494 3495 3496 3497 3498 3499 3500 3501 3502 3503 3504 3505 3506 3507 3508 3509 3510 3511 3512 3513 3514 3515 3516 3517 3518 3519 3520 3521 3522 3523 3524 3525 3526 3527 3528 3529 3530 3531 3532 3533 3534 3535 3536 3537 3538 3539 3540 3541 3542 3543 3544 3545 3546 3547 3548 3549 3550 3551 3552 3553 3554 3555 3556 3557 3558 3559 3560 3561 3562 3563 3564 3565 3566 3567 3568 3569 3570 3571 3572 3573 3574 3575 3576 3577 3578 3579 3580 3581 3582 3583 3584 3585 3586 3587 3588 3589 3590 3591 3592 3593 3594 3595 3596 3597 3598 3599 3600 3601 3602 3603 3604 3605 3606 3607 3608 3609 3610 3611 3612 3613 3614 3615 3616 3617 3618 3619 3620 3621 3622 3623 3624 3625 3626 3627 3628 3629 3630 3631 3632 3633 3634 3635 3636 3637 3638 3639 3640 3641 3642 3643 3644 3645 3646 3647 3648 3649 3650 3651 3652 3653 3654 3655 3656 3657 3658 3659 3660 3661 3662 3663 3664 3665 3666 3667 3668 3669 3670 3671 3672 3673 3674 3675 3676 3677 3678 3679 3680 3681 3682 3683 3684 3685 3686 3687 3688 3689 3690 3691 3692 3693 3694 3695 3696 3697 3698 3699 3700 3701 3702 3703 3704 3705 3706 3707 3708 3709 3710 3711 3712 3713 3714 3715 3716 3717 3718 3719 3720 3721 3722 3723 3724 3725 3726 3727 3728 3729 3730 3731 3732 3733 3734 3735 3736 3737 3738 3739 3740 3741 3742 3743 3744 3745 3746 3747 3748 3749 3750 3751 3752 3753 3754 3755 3756 3757 3758 3759 3760 3761 3762 3763 3764 3765 3766 3767 3768 3769 3770 3771 3772 3773 3774 3775 3776 3777 3778 3779 3780 3781 3782 3783 3784 3785 3786 3787 3788 3789 3790 3791 3792 3793 3794 3795 3796 3797 3798 3799 3800 3801 3802 3803 3804 3805 3806 3807 3808 3809 3810 3811 3812 3813 3814 3815 3816 3817 3818 3819 3820 3821 3822 3823 3824 3825 3826 3827 3828 3829 3830 3831 3832 3833 3834 3835 3836 3837 3838 3839 3840 3841 3842 3843 3844 3845 3846 3847 3848 3849 3850 3851 3852 3853 3854 3855 3856 3857 3858 3859 3860 3861 3862 3863 3864 3865 3866 3867 3868 3869 3870 3871 3872 3873 3874 3875 3876 3877 3878 3879 3880 3881 3882 3883 3884 3885 3886 3887 3888 3889 3890 3891 3892 3893 3894 3895 3896 3897 3898 3899 3900 3901 3902 3903 3904 3905 3906 3907 3908 3909 3910 3911 3912 3913 3914 3915 3916 3917 3918 3919 3920 3921 3922 3923 3924 3925 3926 3927 3928 3929 3930 3931 3932 3933 3934 3935 3936 3937 3938 3939 3940 3941 3942 3943 3944 3945 3946 3947 3948 3949 3950 3951 3952 3953 3954 3955 3956 3957 3958 3959 3960 3961 3962 3963 3964 3965 3966 3967 3968 3969 3970 3971 3972 3973 3974 3975 3976 3977 3978 3979 3980 3981 3982 3983 3984 3985 3986 3987 3988 3989 3990 3991 3992 3993 3994 3995 3996 3997 3998 3999 4000 4001 4002 4003 4004 4005 4006 4007 4008 4009 4010 4011 4012 4013 4014 4015 4016 4017 4018 4019 4020 4021 4022 4023 4024 4025 4026 4027 4028 4029 4030 4031 4032 4033 4034 4035 4036 4037 4038 4039 4040 4041 4042 4043 4044 4045 4046 4047 4048 4049 4050 4051 4052 4053 4054 4055 4056 4057 4058 4059 4060 4061 4062 4063 4064 4065 4066 4067 4068 4069 4070 4071 4072 4073 4074 4075 4076 4077 4078 4079 4080 4081 4082 4083 4084 4085 4086 4087 4088 4089 4090 4091 4092 4093 4094 4095 4096 4097 4098 4099 4100 4101 4102 4103 4104 4105 4106 4107 4108 4109 4110 4111 4112 4113 4114 4115 4116 4117 4118 4119 4120 4121 4122 4123 4124 4125 4126 4127 4128 4129 4130 4131 4132 4133 4134 4135 4136 4137 4138 4139 4140 4141 4142 4143 4144 4145 4146 4147 4148 4149 4150 4151 4152 4153 4154 4155 4156 4157 4158 4159 4160 4161 4162 4163 4164 4165 4166 4167 4168 4169 4170 4171 4172 4173 4174 4175 4176 4177 4178 4179 4180 4181 4182 4183 4184 4185 4186 4187 4188 4189 4190 4191 4192 4193 4194 4195 4196 4197 4198 4199 4200 4201 4202 4203 4204 4205 4206 4207 4208 4209 4210 4211 4212 4213 4214 4215 4216 4217 4218 4219 4220 4221 4222 4223 4224 4225 4226 4227 4228 4229 4230 4231 4232 4233 4234 4235 4236 4237 4238 4239 4240 4241 4242 4243 4244 4245 4246 4247 4248 4249 4250 4251 4252 4253 4254 4255 4256 4257 4258 4259 4260 4261 4262 4263 4264 4265 4266 4267 4268 4269 4270 4271 4272 4273 4274 4275 4276 4277 4278 4279 4280 4281 4282 4283 4284 4285 4286 4287 4288 4289 4290 4291 4292 4293 4294 4295 4296 4297 4298 4299 4300 4301 4302 4303 4304 4305 4306 4307 4308 4309 4310 4311 4312 4313 4314 4315 4316 4317 4318 4319 4320 4321 4322 4323 4324 4325 4326 4327 4328 4329 4330 4331 4332 4333 4334 4335 4336 4337 4338 4339 4340 4341 4342 4343 4344 4345 4346 4347 4348 4349 4350 4351 4352 4353 4354 4355 4356 4357 4358 4359 4360 4361 4362 4363 4364 4365 4366 4367 4368 4369 4370 4371 4372 4373 4374 4375 4376 4377 4378 4379 4380 4381 4382 4383 4384 4385 4386 4387 4388 4389 4390 4391 4392 4393 4394 4395 4396 4397 4398 4399 4400 4401 4402 4403 4404 4405 4406 4407 4408 4409 4410 4411 4412 4413 4414 4415 4416 4417 4418 4419 4420 4421 4422 4423 4424 4425 4426 4427 4428 4429 4430 4431 4432 4433 4434 4435 4436 4437 4438 4439 4440 4441 4442 4443 4444 4445 4446 4447 4448 4449 4450 4451 4452 4453 4454 4455 4456 4457 4458 4459 4460 4461 4462 4463 4464 4465 4466 4467 4468 4469 4470 4471 4472 4473 4474 4475 4476 4477 4478 4479 4480 4481 4482 4483 4484 4485 4486 4487 4488 4489 4490 4491 4492 4493 4494 4495 4496 4497 4498 4499 4500 4501 4502 4503 4504 4505 4506 4507 4508 4509 4510 4511 4512 4513 4514 4515 4516 4517 4518 4519 4520 4521 4522 4523 4524 4525 4526 4527 4528 4529 4530 4531 4532 4533 4534 4535 4536 4537 4538 4539 4540 4541 4542 4543 4544 4545 4546 4547 4548 4549 4550 4551 4552 4553 4554 4555 4556 4557 4558 4559 4560 4561 4562 4563 4564 4565 4566 4567 4568 4569 4570 4571 4572 4573 4574 4575 4576 4577 4578 4579 4580 4581 4582 4583 4584 4585 4586 4587 4588 4589 4590 4591 4592 4593 4594 4595 4596 4597 4598 4599 4600 4601 4602 4603 4604 4605 4606 4607 4608 4609 4610 4611 4612 4613 4614 4615 4616 4617 4618 4619 4620 4621 4622 4623 4624 4625 4626 4627 4628 4629 4630 4631 4632 4633 4634 4635 4636 4637 4638 4639 4640 4641 4642 4643 4644 4645 4646 4647 4648 4649 4650 4651 4652 4653 4654 4655 4656 4657 4658 4659 4660 4661 4662 4663 4664 4665 4666 4667 4668 4669 4670 4671 4672 4673 4674 4675 4676 4677 4678 4679 4680 4681 4682 4683 4684 4685 4686 4687 4688 4689 4690 4691 4692 4693 4694 4695 4696 4697 4698 4699 4700 4701 4702 4703 4704 4705 4706 4707 4708 4709 4710 4711 4712 4713 4714 4715 4716 4717 4718 4719 4720 4721 4722 4723 4724 4725 4726 4727 4728 4729 4730 4731 4732 4733 4734 4735 4736 4737 4738 4739 4740 4741 4742 4743 4744 4745 4746 4747 4748 4749 4750 4751 4752 4753 4754 4755 4756 4757 4758 4759 4760 4761 4762 4763 4764 4765 4766 4767 4768 4769 4770 4771 4772 4773 4774 4775 4776 4777 4778 4779 4780 4781 4782 4783 4784 4785 4786 4787 4788 4789 4790 4791 4792 4793 4794 4795 4796 4797 4798 4799 4800 4801 4802 4803 4804 4805 4806 4807 4808 4809 4810 4811 4812 4813 4814 4815 4816 4817 4818 4819 4820 4821 4822 4823 4824 4825 4826 4827 4828 4829 4830 4831 4832 4833 4834 4835 4836 4837 4838 4839 4840 4841 4842 4843 4844 4845 4846 4847 4848 4849 4850 4851 4852 4853 4854 4855 4856 4857 4858 4859 4860 4861 4862 4863 4864 4865 4866 4867 4868 4869 4870 4871 4872 4873 4874 4875 4876 4877 4878 4879 4880 4881 4882 4883 4884 4885 4886 4887 4888 4889 4890 4891 4892 4893 4894 4895 4896 4897 4898 4899 4900 4901 4902 4903 4904 4905 4906 4907 4908 4909 4910 4911 4912 4913 4914 4915 4916 4917 4918 4919 4920 4921 4922 4923 4924 4925 4926 4927 4928 4929 4930 4931 4932 4933 4934 4935 4936 4937 4938 4939 4940 4941 4942 4943 4944 4945 4946 4947 4948 4949 4950 4951 4952 4953 4954 4955 4956 4957 4958 4959 4960 4961 4962 4963 4964 4965 4966 4967 4968 4969 4970 4971 4972 4973 4974 4975 4976 4977 4978 4979 4980 4981 4982 4983 4984 4985 4986 4987 4988 4989 4990 4991 4992 4993 4994 4995 4996 4997 4998 4999 5000 5001 5002 5003 5004 5005 5006 5007 5008 5009 5010 5011 5012 5013 5014 5015 5016 5017 5018 5019 5020 5021 5022 5023 5024 5025 5026 5027 5028 5029 5030 5031 5032 5033 5034 5035 5036 5037 5038 5039 5040 5041 5042 5043 5044 5045 5046 5047 5048 5049 5050 5051 5052 5053 5054 5055 5056 5057 5058 5059 5060 5061 5062 5063 5064 5065 5066 5067 5068 5069 5070 5071 5072 5073 5074 5075 5076 5077 5078 5079 5080 5081 5082 5083 5084 5085 5086 5087 5088 5089 5090 5091 5092 5093 5094 5095 5096 5097 5098 5099 5100 5101 5102 5103 5104 5105 5106 5107 5108 5109 5110 5111 5112 5113 5114 5115 5116 5117 5118 5119 5120 5121 5122 5123 5124 5125 5126 5127 5128 5129 5130 5131 5132 5133 5134 5135 5136 5137 5138 5139 5140 5141 5142 5143 5144 5145 5146 5147 5148 5149 5150 5151 5152 5153 5154 5155 5156 5157 5158 5159 5160 5161 5162 5163 5164 5165 5166 5167 5168 5169 5170 5171 5172 5173 5174 5175 5176 5177 5178 5179 5180 5181 5182 5183 5184 5185 5186 5187 5188 5189 5190 5191 5192 5193 5194 5195 5196 5197 5198 5199 5200 5201 5202 5203 5204 5205 5206 5207 5208 5209 5210 5211 5212 5213 5214 5215 5216 5217 5218 5219 5220 5221 5222 5223 5224 5225 5226 5227 5228 5229 5230 5231 5232 5233 5234 5235 5236 5237 5238 5239 5240 5241 5242 5243 5244 5245 5246 5247 5248 5249 5250 5251 5252 5253 5254 5255 5256 5257 5258 5259 5260 5261 5262 5263 5264 5265 5266 5267 5268 5269 5270 5271 5272 5273 5274 5275 5276 5277 5278 5279 5280 5281 5282 5283 5284 5285 5286 5287 5288 5289 5290 5291 5292 5293 5294 5295 5296 5297 5298 5299 5300 5301 5302 5303 5304 5305 5306 5307 5308 5309 5310 5311 5312 5313 5314 5315 5316 5317 5318 5319 5320 5321 5322 5323 5324 5325 5326 5327 5328 5329 5330 5331 5332 5333 5334 5335 5336 5337 5338 5339 5340 5341 5342 5343 5344 5345 5346 5347 5348 5349 5350 5351 5352 5353 5354 5355 5356 5357 5358 5359 5360 5361 5362 5363 5364 5365 5366 5367 5368 5369 5370 5371 5372 5373 5374 5375 5376 5377 5378 5379 5380 5381 5382 5383 5384 5385 5386 5387 5388 5389 5390 5391 5392 5393 5394 5395 5396 5397 5398 5399 5400 5401 5402 5403 5404 5405 5406 5407 5408 5409 5410 5411 5412 5413 5414 5415 5416 5417 5418 5419 5420 5421 5422 5423 5424 5425 5426 5427 5428 5429 5430 5431 5432 5433 5434 5435 5436 5437 5438 5439 5440 5441 5442 5443 5444 5445 5446 5447 5448 5449 5450 5451 5452 5453 5454 5455 5456 5457 5458 5459 5460 5461 5462 5463 5464 5465 5466 5467 5468 5469 5470 5471 5472 5473 5474 5475 5476 5477 5478 5479 5480 5481 5482 5483 5484 5485 5486 5487 5488 5489 5490 5491 5492 5493 5494 5495 5496 5497 5498 5499 5500 5501 5502 5503 5504 5505 5506 5507 5508 5509 5510 5511 5512 5513 5514 5515 5516 5517 5518 5519 5520 5521 5522 5523 5524 5525 5526 5527 5528 5529 5530 5531 5532 5533 5534 5535 5536 5537 5538 5539 5540 5541 5542 5543 5544 5545 5546 5547 5548 5549 5550 5551 5552 5553 5554 5555 5556 5557 5558 5559 5560 5561 5562 5563 5564 5565 5566 5567 5568 5569 5570 5571 5572 5573 5574 5575 5576 5577 5578 5579 5580 5581 5582 5583 5584 5585 5586 5587 5588 5589 5590 5591 5592 5593 5594 5595 5596 5597 5598 5599 5600 5601 5602 5603 5604 5605 5606 5607 5608 5609 5610 5611 5612 5613 5614 5615 5616 5617 5618 5619 5620 5621 5622 5623 5624 5625 5626 5627 5628 5629 5630 5631 5632 5633 5634 5635 5636 5637 5638 5639 5640 5641 5642 5643 5644 5645 5646 5647 5648 5649 5650 5651 5652 5653 5654 5655 5656 5657 5658 5659 5660 5661 5662 5663 5664 5665 5666 5667 5668 5669 5670 5671 5672 5673 5674 5675 5676 5677 5678 5679 5680 5681 5682 5683 5684 5685 5686 5687 5688 5689 5690 5691 5692 5693 5694 5695 5696 5697 5698 5699 5700 5701 5702 5703 5704 5705 5706 5707 5708 5709 5710 5711 5712 5713 5714 5715 5716 5717 5718 5719 5720 5721 5722 5723 5724 5725 5726 5727 5728 5729 5730 5731 5732 5733 5734 5735 5736 5737 5738 5739 5740 5741 5742 5743 5744 5745 5746 5747 5748 5749 5750 5751 5752 5753 5754 5755 5756 5757 5758 5759 5760 5761 5762 5763 5764 5765 5766 5767 5768 5769 5770 5771 5772 5773 5774 5775 5776 5777 5778 5779 5780 5781 5782 5783 5784 5785 5786 5787 5788 5789 5790 5791 5792 5793 5794 5795 5796 5797 5798 5799 5800 5801 5802 5803 5804 5805 5806 5807 5808 5809 5810 5811 5812 5813 5814 5815 5816 5817 5818 5819 5820 5821 5822 5823 5824 5825 5826 5827 5828 5829 5830 5831 5832 5833 5834 5835 5836 5837 5838 5839 5840 5841 5842 5843 5844 5845 5846 5847 5848 5849 5850 5851 5852 5853 5854 5855 5856 5857 5858 5859 5860 5861 5862 5863 5864 5865 5866 5867 5868 5869 5870 5871 5872 5873 5874 5875 5876 5877 5878 5879 5880 5881 5882 5883 5884 5885 5886 5887 5888 5889 5890 5891 5892 5893 5894 5895 5896 5897 5898 5899 5900 5901 5902 5903 5904 5905 5906 5907 5908 5909 5910 5911 5912 5913 5914 5915 5916 5917 5918 5919 5920 5921 5922 5923 5924 5925 5926 5927 5928 5929 5930 5931 5932 5933 5934 5935 5936 5937 5938 5939 5940 5941 5942 5943 5944 5945 5946 5947 5948 5949 5950 5951 5952 5953 5954 5955 5956 5957 5958 5959 5960 5961 5962 5963 5964 5965 5966 5967 5968 5969 5970 5971 5972 5973 5974 5975 5976 5977 5978 5979 5980 5981 5982 5983 5984 5985 5986 5987 5988 5989 5990 5991 5992 5993 5994 5995 5996 5997 5998 5999 6000 6001 6002 6003 6004 6005 6006 6007 6008 6009 6010 6011 6012 6013 6014 6015 6016 6017 6018 6019 6020 6021 6022 6023 6024 6025 6026 6027 6028 6029 6030 6031 6032 6033 6034 6035 6036 6037 6038 6039 6040 6041 6042 6043 6044 6045 6046 6047 6048 6049 6050 6051 6052 6053 6054 6055 6056 6057 6058 6059 6060 6061 6062 6063 6064 6065 6066 6067 6068 6069 6070 6071 6072 6073 6074 6075 6076 6077 6078 6079 6080 6081 6082 6083 6084 6085 6086 6087 6088 6089 6090 6091 6092 6093 6094 6095 6096 6097 6098 6099 6100 6101 6102 6103 6104 6105 6106 6107 6108 6109 6110 6111 6112 6113 6114 6115 6116 6117 6118 6119 6120 6121 6122 6123 6124 6125 6126 6127 6128 6129 6130 6131 6132 6133 6134 6135 6136 6137 6138 6139 6140 6141 6142 6143 6144 6145 6146 6147 6148 6149 6150 6151 6152 6153 6154 6155 6156 6157 6158 6159 6160 6161 6162 6163 6164 6165 6166 6167 6168 6169 6170 6171 6172 6173 6174 6175 6176 6177 6178 6179 6180 6181 6182 6183 6184 6185 6186 6187 6188 6189 6190 6191 6192 6193 6194 6195 6196 6197 6198 6199 6200 6201 6202 6203 6204 6205 6206 6207 6208 6209 6210 6211 6212 6213 6214 6215 6216 6217 6218 6219 6220 6221 6222 6223 6224 6225 6226 6227 6228 6229 6230 6231 6232 6233 6234 6235 6236 6237 6238 6239 6240 6241 6242 6243 6244 6245 6246 6247 6248 6249 6250 6251 6252 6253 6254 6255 6256 6257 6258 6259 6260 6261 6262 6263 6264 6265 6266 6267 6268 6269 6270 6271 6272 6273 6274 6275 6276 6277 6278 6279 6280 6281 6282 6283 6284 6285 6286 6287 6288 6289 6290 6291 6292 6293 6294 6295 6296 6297 6298 6299 6300 6301 6302 6303 6304 6305 6306 6307 6308 6309 6310 6311 6312 6313 6314 6315 6316 6317 6318 6319 6320 6321 6322 6323 6324 6325 6326 6327 6328 6329 6330 6331 6332 6333 6334 6335 6336 6337 6338 6339 6340 6341 6342 6343 6344 6345 6346 6347 6348 6349 6350 6351 6352 6353 6354 6355 6356 6357 6358 6359 6360 6361 6362 6363 6364 6365 6366 6367 6368 6369 6370 6371 6372 6373 6374 6375 6376 6377 6378 6379 6380 6381 6382 6383 6384 6385 6386 6387 6388 6389 6390 6391 6392 6393 6394 6395 6396 6397 6398 6399 6400 6401 6402 6403 6404 6405 6406 6407 6408 6409 6410 6411 6412 6413 6414 6415 6416 6417 6418 6419 6420 6421 6422 6423 6424 6425 6426 6427 6428 6429 6430 6431 6432 6433 6434 6435 6436 6437 6438 6439 6440 6441 6442 6443 6444 6445 6446 6447 6448 6449 6450 6451 6452 6453 6454 6455 6456 6457 6458 6459 6460 6461 6462 6463 6464 6465 6466 6467 6468 6469 6470 6471 6472 6473 6474 6475 6476 6477 6478 6479 6480 6481 6482 6483 6484 6485 6486 6487 6488 6489 6490 6491 6492 6493 6494 6495 6496 6497 6498 6499 6500 6501 6502 6503 6504 6505 6506 6507 6508 6509 6510 6511 6512 6513 6514 6515 6516 6517 6518 6519 6520 6521 6522 6523 6524 6525 6526 6527 6528 6529 6530 6531 6532 6533 6534 6535 6536 6537 6538 6539 6540 6541 6542 6543 6544 6545 6546 6547 6548 6549 6550 6551 6552 6553 6554 6555 6556 6557 6558 6559 6560 6561 6562 6563 6564 6565 6566 6567 6568 6569 6570 6571 6572 6573 6574 6575 6576 6577 6578 6579 6580 6581 6582 6583 6584 6585 6586 6587 6588 6589 6590 6591 6592 6593 6594 6595 6596 6597 6598 6599 6600 6601 6602 6603 6604 6605 6606 6607 6608 6609 6610 6611 6612 6613 6614 6615 6616 6617 6618 6619 6620 6621 6622 6623 6624 6625 6626 6627 6628 6629 6630 6631 6632 6633 6634 6635 6636 6637 6638 6639 6640 6641 6642 6643 6644 6645 6646 6647 6648 6649 6650 6651 6652 6653 6654 6655 6656 6657 6658 6659 6660 6661 6662 6663 6664 6665 6666 6667 6668 6669 6670 6671 6672 6673 6674 6675 6676 6677 6678 6679 6680 6681 6682 6683 6684 6685 6686 6687 6688 6689 6690 6691 6692 6693 6694 6695 6696 6697 6698 6699 6700 6701 6702 6703 6704 6705 6706 6707 6708 6709 6710 6711 6712 6713 6714 6715 6716 6717 6718 6719 6720 6721 6722 6723 6724 6725 6726 6727 6728 6729 6730 6731 6732 6733 6734 6735 6736 6737 6738 6739 6740 6741 6742 6743 6744 6745 6746 6747 6748 6749 6750 6751 6752 6753 6754 6755 6756 6757 6758 6759 6760 6761 6762 6763 6764 6765 6766 6767 6768 6769 6770 6771 6772 6773 6774 6775 6776 6777 6778 6779 6780 6781 6782 6783 6784 6785 6786 6787 6788 6789 6790 6791 6792 6793 6794 6795 6796 6797 6798 6799 6800 6801 6802 6803 6804 6805 6806 6807 6808 6809 6810 6811 6812 6813 6814 6815 6816 6817 6818 6819 6820 6821 6822 6823 6824 6825 6826 6827 6828 6829 6830 6831 6832 6833 6834 6835 6836 6837 6838 6839 6840 6841 6842 6843 6844 6845 6846 6847 6848 6849 6850 6851 6852 6853 6854 6855 6856 6857 6858 6859 6860 6861 6862 6863 6864 6865 6866 6867 6868 6869 6870 6871 6872 6873 6874 6875 6876 6877 6878 6879 6880 6881 6882 6883 6884 6885 6886 6887 6888 6889 6890 6891 6892 6893 6894 6895 6896 6897 6898 6899 6900 6901 6902 6903 6904 6905 6906 6907 6908 6909 6910 6911 6912 6913 6914 6915 6916 6917 6918 6919 6920 6921 6922 6923 6924 6925 6926 6927 6928 6929 6930 6931 6932 6933 6934 6935 6936 6937 6938 6939 6940 6941 6942 6943 6944 6945 6946 6947 6948 6949 6950 6951 6952 6953 6954 6955 6956 6957 6958 6959 6960 6961 6962 6963 6964 6965 6966 6967 6968 6969 6970 6971 6972 6973 6974 6975 6976 6977 6978 6979 6980 6981 6982 6983 6984 6985 6986 6987 6988 6989 6990 6991 6992 6993 6994 6995 6996 6997 6998 6999 7000 7001 7002 7003 7004 7005 7006 7007 7008 7009 7010 7011 7012 7013 7014 7015 7016 7017 7018 7019 7020 7021 7022 7023 7024 7025 7026 7027 7028 7029 7030 7031 7032 7033 7034 7035 7036 7037 7038 7039 7040 7041 7042 7043 7044 7045 7046 7047 7048 7049 7050 7051 7052 7053 7054 7055 7056 7057 7058 7059 7060 7061 7062 7063 7064 7065 7066 7067 7068 7069 7070 7071 7072 7073 7074 7075 7076 7077 7078 7079 7080 7081 7082 7083 7084 7085 7086 7087 7088 7089 7090 7091 7092 7093 7094 7095 7096 7097 7098 7099 7100 7101 7102 7103 7104 7105 7106 7107 7108 7109 7110 7111 7112 7113 7114 7115 7116 7117 7118 7119 7120 7121 7122 7123 7124 7125 7126 7127 7128 7129 7130 7131 7132 7133 7134 7135 7136 7137 7138 7139 7140 7141 7142 7143 7144 7145 7146 7147 7148 7149 7150 7151 7152 7153 7154 7155 7156 7157 7158 7159 7160 7161 7162 7163 7164 7165 7166 7167 7168 7169 7170 7171 7172 7173 7174 7175 7176 7177 7178 7179 7180 7181 7182 7183 7184 7185 7186 7187 7188 7189 7190 7191 7192 7193 7194 7195 7196 7197 7198 7199 7200 7201 7202 7203 7204 7205 7206 7207 7208 7209 7210 7211 7212 7213 7214 7215 7216 7217 7218 7219 7220 7221 7222 7223 7224 7225 7226 7227 7228 7229 7230 7231 7232 7233 7234 7235 7236 7237 7238 7239 7240 7241 7242 7243 7244 7245 7246 7247 7248 7249 7250 7251 7252 7253 7254 7255 7256 7257 7258 7259 7260 7261 7262 7263 7264 7265 7266 7267 7268 7269 7270 7271 7272 7273 7274 7275 7276 7277 7278 7279 7280 7281 7282 7283 7284 7285 7286 7287 7288 7289 7290 7291 7292 7293 7294 7295 7296 7297 7298 7299 7300 7301 7302 7303 7304 7305 7306 7307 7308 7309 7310 7311 7312 7313 7314 7315 7316 7317 7318 7319 7320 7321 7322 7323 7324 7325 7326 7327 7328 7329 7330 7331 7332 7333 7334 7335 7336 7337 7338 7339 7340 7341 7342 7343 7344 7345 7346 7347 7348 7349 7350 7351 7352 7353 7354 7355 7356 7357 7358 7359 7360 7361 7362 7363 7364 7365 7366 7367 7368 7369 7370 7371 7372 7373 7374 7375 7376 7377 7378 7379 7380 7381 7382 7383 7384 7385 7386 7387 7388 7389 7390 7391 7392 7393 7394 7395 7396 7397 7398 7399 7400 7401 7402 7403 7404 7405 7406 7407 7408 7409 7410 7411 7412 7413 7414 7415 7416 7417 7418 7419 7420 7421 7422 7423 7424 7425 7426 7427 7428 7429 7430 7431 7432 7433 7434 7435 7436 7437 7438 7439 7440 7441 7442 7443 7444 7445 7446 7447 7448 7449 7450 7451 7452 7453 7454 7455 7456 7457 7458 7459 7460 7461 7462 7463 7464 7465 7466 7467 7468 7469 7470 7471 7472 7473 7474 7475 7476 7477 7478 7479 7480 7481 7482 7483 7484 7485 7486 7487 7488 7489 7490 7491 7492 7493 7494 7495 7496 7497 7498 7499 7500 7501 7502 7503 7504 7505 7506 7507 7508 7509 7510 7511 7512 7513 7514 7515 7516 7517 7518 7519 7520 7521 7522 7523 7524 7525 7526 7527 7528 7529 7530 7531 7532 7533 7534 7535 7536 7537 7538 7539 7540 7541 7542 7543 7544 7545 7546 7547 7548 7549 7550 7551 7552 7553 7554 7555 7556 7557 7558 7559 7560 7561 7562 7563 7564 7565 7566 7567 7568 7569 7570 7571 7572 7573 7574 7575 7576 7577 7578 7579 7580 7581 7582 7583 7584 7585 7586 7587 7588 7589 7590 7591 7592 7593 7594 7595 7596 7597 7598 7599 7600 7601 7602 7603 7604 7605 7606 7607 7608 7609 7610 7611 7612 7613 7614 7615 7616 7617 7618 7619 7620 7621 7622 7623 7624 7625 7626 7627 7628 7629 7630 7631 7632 7633 7634 7635 7636 7637 7638 7639 7640 7641 7642 7643 7644 7645 7646 7647 7648 7649 7650 7651 7652 7653 7654 7655 7656 7657 7658 7659 7660 7661 7662 7663 7664 7665 7666 7667 7668 7669 7670 7671 7672 7673 7674 7675 7676 7677 7678 7679 7680 7681 7682 7683 7684 7685 7686 7687 7688 7689 7690 7691 7692 7693 7694 7695 7696 7697 7698 7699 7700 7701 7702 7703 7704 7705 7706 7707 7708 7709 7710 7711 7712 7713 7714 7715 7716 7717 7718 7719 7720 7721 7722 7723 7724 7725 7726 7727 7728 7729 7730 7731 7732 7733 7734 7735 7736 7737 7738 7739 7740 7741 7742 7743 7744 7745 7746 7747 7748 7749 7750 7751 7752 7753 7754 7755 7756 7757 7758 7759 7760 7761 7762 7763 7764 7765 7766 7767 7768 7769 7770 7771 7772 7773 7774 7775 7776 7777 7778 7779 7780 7781 7782 7783 7784 7785 7786 7787 7788 7789 7790 7791 7792 7793 7794 7795 7796 7797 7798 7799 7800 7801 7802 7803 7804 7805 7806 7807 7808 7809 7810 7811 7812 7813 7814 7815 7816 7817 7818 7819 7820 7821 7822 7823 7824 7825 7826 7827 7828 7829 7830 7831 7832 7833 7834 7835 7836 7837 7838 7839 7840 7841 7842 7843 7844 7845 7846 7847 7848 7849 7850 7851 7852 7853 7854 7855 7856 7857 7858 7859 7860 7861 7862 7863 7864 7865 7866 7867 7868 7869 7870 7871 7872 7873 7874 7875 7876 7877 7878 7879 7880 7881 7882 7883 7884 7885 7886 7887 7888 7889 7890 7891 7892 7893 7894 7895 7896 7897 7898 7899 7900 7901 7902 7903 7904 7905 7906 7907 7908 7909 7910 7911 7912 7913 7914 7915 7916 7917 7918 7919 7920 7921 7922 7923 7924 7925 7926 7927 7928 7929 7930 7931 7932 7933 7934 7935 7936 7937 7938 7939 7940 7941 7942 7943 7944 7945 7946 7947 7948 7949 7950 7951 7952 7953 7954 7955 7956 7957 7958 7959 7960 7961 7962 7963 7964 7965 7966 7967 7968 7969 7970 7971 7972 7973 7974 7975 7976 7977 7978 7979 7980 7981 7982 7983 7984 7985 7986 7987 7988 7989 7990 7991 7992 7993 7994 7995 7996 7997 7998 7999 8000 8001 8002 8003 8004 8005 8006 8007 8008 8009 8010 8011 8012 8013 8014 8015 8016 8017 8018 8019 8020 8021 8022 8023 8024 8025 8026 8027 8028 8029 8030 8031 8032 8033 8034 8035 8036 8037 8038 8039 8040 8041 8042 8043 8044 8045 8046 8047 8048 8049 8050 8051 8052 8053 8054 8055 8056 8057 8058 8059 8060 8061 8062 8063 8064 8065 8066 8067 8068 8069 8070 8071 8072 8073 8074 8075 8076 8077 8078 8079 8080 8081 8082 8083 8084 8085 8086 8087 8088 8089 8090 8091 8092 8093 8094 8095 8096 8097 8098 8099 8100 8101 8102 8103 8104 8105 8106 8107 8108 8109 8110 8111 8112 8113 8114 8115 8116 8117 8118 8119 8120 8121 8122 8123 8124 8125 8126 8127 8128 8129 8130 8131 8132 8133 8134 8135 8136 8137 8138 8139 8140 8141 8142 8143 8144 8145 8146 8147 8148 8149 8150 8151 8152 8153 8154 8155 8156 8157 8158 8159 8160 8161 8162 8163 8164 8165 8166 8167 8168 8169 8170 8171 8172 8173 8174 8175 8176 8177 8178 8179 8180 8181 8182 8183 8184 8185 8186 8187 8188 8189 8190 8191 8192 8193 8194 8195 8196 8197 8198 8199 8200 8201 8202 8203 8204 8205 8206 8207 8208 8209 8210 8211 8212 8213 8214 8215 8216 8217 8218 8219 8220 8221 8222 8223 8224 8225 8226 8227 8228 8229 8230 8231 8232 8233 8234 8235 8236 8237 8238 8239 8240 8241 8242 8243 8244 8245 8246 8247 8248 8249 8250 8251 8252 8253 8254 8255 8256 8257 8258 8259 8260 8261 8262 8263 8264 8265 8266 8267 8268 8269 8270 8271 8272 8273 8274 8275 8276 8277 8278 8279 8280 8281 8282 8283 8284 8285 8286 8287 8288 8289 8290 8291 8292 8293 8294 8295 8296 8297 8298 8299 8300 8301 8302 8303 8304 8305 8306 8307 8308 8309 8310 8311 8312 8313 8314 8315 8316 8317 8318 8319 8320 8321 8322 8323 8324 8325 8326 8327 8328 8329 8330 8331 8332 8333 8334 8335 8336 8337 8338 8339 8340 8341 8342 8343 8344 8345 8346 8347 8348 8349 8350 8351 8352 8353 8354 8355 8356 8357 8358 8359 8360 8361 8362 8363 8364 8365 8366 8367 8368 8369 8370 8371 8372 8373 8374 8375 8376 8377 8378 8379 8380 8381 8382 8383 8384 8385 8386 8387 8388 8389 8390 8391 8392 8393 8394 8395 8396 8397 8398 8399 8400 8401 8402 8403 8404 8405 8406 8407 8408 8409 8410 8411 8412 8413 8414 8415 8416 8417 8418 8419 8420 8421 8422 8423 8424 8425 8426 8427 8428 8429 8430 8431 8432 8433 8434 8435 8436 8437 8438 8439 8440 8441 8442 8443 8444 8445 8446 8447 8448 8449 8450 8451 8452 8453 8454 8455 8456 8457 8458 8459 8460 8461 8462 8463 8464 8465 8466 8467 8468 8469 8470 8471 8472 8473 8474 8475 8476 8477 8478 8479 8480 8481 8482 8483 8484 8485 8486 8487 8488 8489 8490 8491 8492 8493 8494 8495 8496 8497 8498 8499 8500 8501 8502 8503 8504 8505 8506 8507 8508 8509 8510 8511 8512 8513 8514 8515 8516 8517 8518 8519 8520 8521 8522 8523 8524 8525 8526 8527 8528 8529 8530 8531 8532 8533 8534 8535 8536 8537 8538 8539 8540 8541 8542 8543 8544 8545 8546 8547 8548 8549 8550 8551 8552 8553 8554 8555 8556 8557 8558 8559 8560 8561 8562 8563 8564 8565 8566 8567 8568 8569 8570 8571 8572 8573 8574 8575 8576 8577 8578 8579 8580 8581 8582 8583 8584 8585 8586 8587 8588 8589 8590 8591 8592 8593 8594 8595 8596 8597 8598 8599 8600 8601 8602 8603 8604 8605 8606 8607 8608 8609 8610 8611 8612 8613 8614 8615 8616 8617 8618 8619 8620 8621 8622 8623 8624 8625 8626 8627 8628 8629 8630 8631 8632 8633 8634 8635 8636 8637 8638 8639 8640 8641 8642 8643 8644 8645 8646 8647 8648 8649 8650 8651 8652 8653 8654 8655 8656 8657 8658 8659 8660 8661 8662 8663 8664 8665 8666 8667 8668 8669 8670 8671 8672 8673 8674 8675 8676 8677 8678 8679 8680 8681 8682 8683 8684 8685 8686 8687 8688 8689 8690 8691 8692 8693 8694 8695 8696 8697 8698 8699 8700 8701 8702 8703 8704 8705 8706 8707 8708 8709 8710 8711 8712 8713 8714 8715 8716 8717 8718 8719 8720 8721 8722 8723 8724 8725 8726 8727 8728 8729 8730 8731 8732 8733 8734 8735 8736 8737 8738 8739 8740 8741 8742 8743 8744 8745 8746 8747 8748 8749 8750 8751 8752 8753 8754 8755 8756 8757 8758 8759 8760 8761 8762 8763 8764 8765 8766 8767 8768 8769 8770 8771 8772 8773 8774 8775 8776 8777 8778 8779 8780 8781 8782 8783 8784 8785 8786 8787 8788 8789 8790 8791 8792 8793 8794 8795 8796 8797 8798 8799 8800 8801 8802 8803 8804 8805 8806 8807 8808 8809 8810 8811 8812 8813 8814 8815 8816 8817 8818 8819 8820 8821 8822 8823 8824 8825 8826 8827 8828 8829 8830 8831 8832 8833 8834 8835 8836 8837 8838 8839 8840 8841 8842 8843 8844 8845 8846 8847 8848 8849 8850 8851 8852 8853 8854 8855 8856 8857 8858 8859 8860 8861 8862 8863 8864 8865 8866 8867 8868 8869 8870 8871 8872 8873 8874 8875 8876 8877 8878 8879 8880 8881 8882 8883 8884 8885 8886 8887 8888 8889 8890 8891 8892 8893 8894 8895 8896 8897 8898 8899 8900 8901 8902 8903 8904 8905 8906 8907 8908 8909 8910 8911 8912 8913 8914 8915 8916 8917 8918 8919 8920 8921 8922 8923 8924 8925 8926 8927 8928 8929 8930 8931 8932 8933 8934 8935 8936 8937 8938 8939 8940 8941 8942 8943 8944 8945 8946 8947 8948 8949 8950 8951 8952 8953 8954 8955 8956 8957 8958 8959 8960 8961 8962 8963 8964 8965 8966 8967 8968 8969 8970 8971 8972 8973 8974 8975 8976 8977 8978 8979 8980 8981 8982 8983 8984 8985 8986 8987 8988 8989 8990 8991 8992 8993 8994 8995 8996 8997 8998 8999 9000 9001 9002 9003 9004 9005 9006 9007 9008 9009 9010 9011 9012 9013 9014 9015 9016 9017 9018 9019 9020 9021 9022 9023 9024 9025 9026 9027 9028 9029 9030 9031 9032 9033 9034 9035 9036 9037 9038 9039 9040 9041 9042 9043 9044 9045 9046 9047 9048 9049 9050 9051 9052 9053 9054 9055 9056 9057 9058 9059 9060 9061 9062 9063 9064 9065 9066 9067 9068 9069 9070 9071 9072 9073 9074 9075 9076 9077 9078 9079 9080 9081 9082 9083 9084 9085 9086 9087 9088 9089 9090 9091 9092 9093 9094 9095 9096 9097 9098 9099 9100 9101 9102 9103 9104 9105 9106 9107 9108 9109 9110 9111 9112 9113 9114 9115 9116 9117 9118 9119 9120 9121 9122 9123 9124 9125 9126 9127 9128 9129 9130 9131 9132 9133 9134 9135 9136 9137 9138 9139 9140 9141 9142 9143 9144 9145 9146 9147 9148 9149 9150 9151 9152 9153 9154 9155 9156 9157 9158 9159 9160 9161 9162 9163 9164 9165 9166 9167 9168 9169 9170 9171 9172 9173 9174 9175 9176 9177 9178 9179 9180 9181 9182 9183 9184 9185 9186 9187 9188 9189 9190 9191 9192 9193 9194 9195 9196 9197 9198 9199 9200 9201 9202 9203 9204 9205 9206 9207 9208 9209 9210 9211 9212 9213 9214 9215 9216 9217 9218 9219 9220 9221 9222 9223 9224 9225 9226 9227 9228 9229 9230 9231 9232 9233 9234 9235 9236 9237 9238 9239 9240 9241 9242 9243 9244 9245 9246 9247 9248 9249 9250 9251 9252 9253 9254 9255 9256 9257 9258 9259 9260 9261 9262 9263 9264 9265 9266 9267 9268 9269 9270 9271 9272 9273 9274 9275 9276 9277 9278 9279 9280 9281 9282 9283 9284 9285 9286 9287 9288 9289 9290 9291 9292 9293 9294 9295 9296 9297 9298 9299 9300 9301 9302 9303 9304 9305 9306 9307 9308 9309 9310 9311 9312 9313 9314 9315 9316 9317 9318 9319 9320 9321 9322 9323 9324 9325 9326 9327 9328 9329 9330 9331 9332 9333 9334 9335 9336 9337 9338 9339 9340 9341 9342 9343 9344 9345 9346 9347 9348 9349 9350 9351 9352 9353 9354 9355 9356 9357 9358 9359 9360 9361 9362 9363 9364 9365 9366 9367 9368 9369 9370 9371 9372 9373 9374 9375 9376 9377 9378 9379 9380 9381 9382 9383 9384 9385 9386 9387 9388 9389 9390 9391 9392 9393 9394 9395 9396 9397 9398 9399 9400 9401 9402 9403 9404 9405 9406 9407 9408 9409 9410 9411 9412 9413 9414 9415 9416 9417 9418 9419 9420 9421 9422 9423 9424 9425 9426 9427 9428 9429 9430 9431 9432 9433 9434 9435 9436 9437 9438 9439 9440 9441 9442 9443 9444 9445 9446 9447 9448 9449 9450 9451 9452 9453 9454 9455
|
/* A Bison parser, made by GNU Bison 3.5.4. */
/* Bison implementation for Yacc-like parsers in C
Copyright (C) 1984, 1989-1990, 2000-2015, 2018-2020 Free Software Foundation,
Inc.
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 3 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, see <http://www.gnu.org/licenses/>. */
/* As a special exception, you may create a larger work that contains
part or all of the Bison parser skeleton and distribute that work
under terms of your choice, so long as that work isn't itself a
parser generator using the skeleton or a modified version thereof
as a parser skeleton. Alternatively, if you modify or redistribute
the parser skeleton itself, you may (at your option) remove this
special exception, which will cause the skeleton and the resulting
Bison output files to be licensed under the GNU General Public
License without this special exception.
This special exception was added by the Free Software Foundation in
version 2.2 of Bison. */
/* C LALR(1) parser skeleton written by Richard Stallman, by
simplifying the original so-called "semantic" parser. */
/* All symbols defined below should begin with yy or YY, to avoid
infringing on user name space. This should be done even for local
variables, as they might otherwise be expanded by user macros.
There are some unavoidable exceptions within include files to
define necessary library symbols; they are noted "INFRINGES ON
USER NAME SPACE" below. */
/* Undocumented macros, especially those whose name start with YY_,
are private implementation details. Do not rely on them. */
/* Identify Bison output. */
#define YYBISON 1
/* Bison version. */
#define YYBISON_VERSION "3.5.4"
/* Skeleton name. */
#define YYSKELETON_NAME "yacc.c"
/* Pure parsers. */
#define YYPURE 0
/* Push parsers. */
#define YYPUSH 0
/* Pull parsers. */
#define YYPULL 1
/* First part of user prologue. */
#line 26 "awkgram.y"
#ifdef GAWKDEBUG
#define YYDEBUG 12
#endif
#include "awk.h"
#if defined(__STDC__) && __STDC__ < 1 /* VMS weirdness, maybe elsewhere */
#define signed /**/
#endif
static void yyerror(const char *m, ...) ATTRIBUTE_PRINTF_1;
static void error_ln(int line, const char *m, ...) ATTRIBUTE_PRINTF_2;
static void lintwarn_ln(int line, const char *m, ...) ATTRIBUTE_PRINTF_2;
static void warning_ln(int line, const char *m, ...) ATTRIBUTE_PRINTF_2;
static char *get_src_buf(void);
static int yylex(void);
int yyparse(void);
static INSTRUCTION *snode(INSTRUCTION *subn, INSTRUCTION *op);
static char **check_params(char *fname, int pcount, INSTRUCTION *list);
static int install_function(char *fname, INSTRUCTION *fi, INSTRUCTION *plist);
static NODE *mk_rexp(INSTRUCTION *exp);
static void param_sanity(INSTRUCTION *arglist);
static int parms_shadow(INSTRUCTION *pc, bool *shadow);
#ifndef NO_LINT
static int isnoeffect(OPCODE type);
#endif
static INSTRUCTION *make_assignable(INSTRUCTION *ip);
static void dumpintlstr(const char *str, size_t len);
static void dumpintlstr2(const char *str1, size_t len1, const char *str2, size_t len2);
static bool include_source(INSTRUCTION *file, void **srcfile_p);
static bool load_library(INSTRUCTION *file, void **srcfile_p);
static void set_namespace(INSTRUCTION *ns, INSTRUCTION *comment);
static void next_sourcefile(void);
static char *tokexpand(void);
static NODE *set_profile_text(NODE *n, const char *str, size_t len);
static int check_qualified_special(char *token);
static char *qualify_name(const char *name, size_t len);
static INSTRUCTION *trailing_comment;
static INSTRUCTION *outer_comment;
static INSTRUCTION *interblock_comment;
static INSTRUCTION *pending_comment;
static INSTRUCTION *namespace_chain;
#ifdef DEBUG_COMMENTS
static void
debug_print_comment_s(const char *name, INSTRUCTION *comment, int line)
{
if (comment != NULL)
fprintf(stderr, "%d: %s: <%.*s>\n", line, name,
(int) (comment->memory->stlen - 1),
comment->memory->stptr);
}
#define debug_print_comment(comment) \
debug_print_comment_s(# comment, comment, __LINE__)
#endif
#define instruction(t) bcalloc(t, 1, 0)
static INSTRUCTION *mk_program(void);
static INSTRUCTION *append_rule(INSTRUCTION *pattern, INSTRUCTION *action);
static INSTRUCTION *mk_function(INSTRUCTION *fi, INSTRUCTION *def);
static INSTRUCTION *mk_condition(INSTRUCTION *cond, INSTRUCTION *ifp, INSTRUCTION *true_branch,
INSTRUCTION *elsep, INSTRUCTION *false_branch);
static INSTRUCTION *mk_expression_list(INSTRUCTION *list, INSTRUCTION *s1);
static INSTRUCTION *mk_for_loop(INSTRUCTION *forp, INSTRUCTION *init, INSTRUCTION *cond,
INSTRUCTION *incr, INSTRUCTION *body);
static void fix_break_continue(INSTRUCTION *list, INSTRUCTION *b_target, INSTRUCTION *c_target);
static INSTRUCTION *mk_binary(INSTRUCTION *s1, INSTRUCTION *s2, INSTRUCTION *op);
static INSTRUCTION *mk_boolean(INSTRUCTION *left, INSTRUCTION *right, INSTRUCTION *op);
static INSTRUCTION *mk_assignment(INSTRUCTION *lhs, INSTRUCTION *rhs, INSTRUCTION *op);
static INSTRUCTION *mk_getline(INSTRUCTION *op, INSTRUCTION *opt_var, INSTRUCTION *redir, int redirtype);
static int count_expressions(INSTRUCTION **list, bool isarg);
static INSTRUCTION *optimize_assignment(INSTRUCTION *exp);
static void add_lint(INSTRUCTION *list, LINTTYPE linttype);
enum defref { FUNC_DEFINE, FUNC_USE, FUNC_EXT };
static void func_use(const char *name, enum defref how);
static void check_funcs(void);
static ssize_t read_one_line(int fd, void *buffer, size_t count);
static int one_line_close(int fd);
static void merge_comments(INSTRUCTION *c1, INSTRUCTION *c2);
static INSTRUCTION *make_braced_statements(INSTRUCTION *lbrace, INSTRUCTION *stmts, INSTRUCTION *rbrace);
static void add_sign_to_num(NODE *n, char sign);
static bool at_seen = false;
static bool want_source = false;
static bool want_regexp = false; /* lexical scanning kludge */
static enum {
FUNC_HEADER,
FUNC_BODY,
DONT_CHECK
} want_param_names = DONT_CHECK; /* ditto */
static bool in_function; /* parsing kludge */
static int rule = 0;
const char *const ruletab[] = {
"?",
"BEGIN",
"Rule",
"END",
"BEGINFILE",
"ENDFILE",
};
static bool in_print = false; /* lexical scanning kludge for print */
static int in_parens = 0; /* lexical scanning kludge for print */
static int sub_counter = 0; /* array dimension counter for use in delete */
static char *lexptr; /* pointer to next char during parsing */
static char *lexend; /* end of buffer */
static char *lexptr_begin; /* keep track of where we were for error msgs */
static char *lexeme; /* beginning of lexeme for debugging */
static bool lexeof; /* seen EOF for current source? */
static char *thisline = NULL;
static int in_braces = 0; /* count braces for firstline, lastline in an 'action' */
static int lastline = 0;
static int firstline = 0;
static SRCFILE *sourcefile = NULL; /* current program source */
static int lasttok = 0;
static bool eof_warned = false; /* GLOBAL: want warning for each file */
static int break_allowed; /* kludge for break */
static int continue_allowed; /* kludge for continue */
#define END_FILE -1000
#define END_SRC -2000
#define YYDEBUG_LEXER_TEXT (lexeme)
static char *tokstart = NULL;
static char *tok = NULL;
static char *tokend;
int errcount = 0;
extern char *source;
extern int sourceline;
extern SRCFILE *srcfiles;
extern INSTRUCTION *rule_list;
extern int max_args;
extern NODE **args_array;
const char awk_namespace[] = "awk";
const char *current_namespace = awk_namespace;
bool namespace_changed = false;
static INSTRUCTION *rule_block[sizeof(ruletab)];
static INSTRUCTION *ip_rec;
static INSTRUCTION *ip_newfile;
static INSTRUCTION *ip_atexit = NULL;
static INSTRUCTION *ip_end;
static INSTRUCTION *ip_endfile;
static INSTRUCTION *ip_beginfile;
INSTRUCTION *main_beginfile;
static bool called_from_eval = false;
static inline INSTRUCTION *list_create(INSTRUCTION *x);
static inline INSTRUCTION *list_append(INSTRUCTION *l, INSTRUCTION *x);
static inline INSTRUCTION *list_prepend(INSTRUCTION *l, INSTRUCTION *x);
static inline INSTRUCTION *list_merge(INSTRUCTION *l1, INSTRUCTION *l2);
extern double fmod(double x, double y);
#define YYSTYPE INSTRUCTION *
#line 235 "awkgram.c"
# ifndef YY_CAST
# ifdef __cplusplus
# define YY_CAST(Type, Val) static_cast<Type> (Val)
# define YY_REINTERPRET_CAST(Type, Val) reinterpret_cast<Type> (Val)
# else
# define YY_CAST(Type, Val) ((Type) (Val))
# define YY_REINTERPRET_CAST(Type, Val) ((Type) (Val))
# endif
# endif
# ifndef YY_NULLPTR
# if defined __cplusplus
# if 201103L <= __cplusplus
# define YY_NULLPTR nullptr
# else
# define YY_NULLPTR 0
# endif
# else
# define YY_NULLPTR ((void*)0)
# endif
# endif
/* Enabling verbose error messages. */
#ifdef YYERROR_VERBOSE
# undef YYERROR_VERBOSE
# define YYERROR_VERBOSE 1
#else
# define YYERROR_VERBOSE 0
#endif
/* Debug traces. */
#ifndef YYDEBUG
# define YYDEBUG 0
#endif
#if YYDEBUG
extern int yydebug;
#endif
/* Token type. */
#ifndef YYTOKENTYPE
# define YYTOKENTYPE
enum yytokentype
{
FUNC_CALL = 258,
NAME = 259,
REGEXP = 260,
FILENAME = 261,
YNUMBER = 262,
YSTRING = 263,
TYPED_REGEXP = 264,
RELOP = 265,
IO_OUT = 266,
IO_IN = 267,
ASSIGNOP = 268,
ASSIGN = 269,
MATCHOP = 270,
CONCAT_OP = 271,
SUBSCRIPT = 272,
LEX_BEGIN = 273,
LEX_END = 274,
LEX_IF = 275,
LEX_ELSE = 276,
LEX_RETURN = 277,
LEX_DELETE = 278,
LEX_SWITCH = 279,
LEX_CASE = 280,
LEX_DEFAULT = 281,
LEX_WHILE = 282,
LEX_DO = 283,
LEX_FOR = 284,
LEX_BREAK = 285,
LEX_CONTINUE = 286,
LEX_PRINT = 287,
LEX_PRINTF = 288,
LEX_NEXT = 289,
LEX_EXIT = 290,
LEX_FUNCTION = 291,
LEX_BEGINFILE = 292,
LEX_ENDFILE = 293,
LEX_GETLINE = 294,
LEX_NEXTFILE = 295,
LEX_IN = 296,
LEX_AND = 297,
LEX_OR = 298,
INCREMENT = 299,
DECREMENT = 300,
LEX_BUILTIN = 301,
LEX_LENGTH = 302,
LEX_EOF = 303,
LEX_INCLUDE = 304,
LEX_EVAL = 305,
LEX_LOAD = 306,
LEX_NAMESPACE = 307,
NEWLINE = 308,
SLASH_BEFORE_EQUAL = 309,
UNARY = 310
};
#endif
/* Tokens. */
#define FUNC_CALL 258
#define NAME 259
#define REGEXP 260
#define FILENAME 261
#define YNUMBER 262
#define YSTRING 263
#define TYPED_REGEXP 264
#define RELOP 265
#define IO_OUT 266
#define IO_IN 267
#define ASSIGNOP 268
#define ASSIGN 269
#define MATCHOP 270
#define CONCAT_OP 271
#define SUBSCRIPT 272
#define LEX_BEGIN 273
#define LEX_END 274
#define LEX_IF 275
#define LEX_ELSE 276
#define LEX_RETURN 277
#define LEX_DELETE 278
#define LEX_SWITCH 279
#define LEX_CASE 280
#define LEX_DEFAULT 281
#define LEX_WHILE 282
#define LEX_DO 283
#define LEX_FOR 284
#define LEX_BREAK 285
#define LEX_CONTINUE 286
#define LEX_PRINT 287
#define LEX_PRINTF 288
#define LEX_NEXT 289
#define LEX_EXIT 290
#define LEX_FUNCTION 291
#define LEX_BEGINFILE 292
#define LEX_ENDFILE 293
#define LEX_GETLINE 294
#define LEX_NEXTFILE 295
#define LEX_IN 296
#define LEX_AND 297
#define LEX_OR 298
#define INCREMENT 299
#define DECREMENT 300
#define LEX_BUILTIN 301
#define LEX_LENGTH 302
#define LEX_EOF 303
#define LEX_INCLUDE 304
#define LEX_EVAL 305
#define LEX_LOAD 306
#define LEX_NAMESPACE 307
#define NEWLINE 308
#define SLASH_BEFORE_EQUAL 309
#define UNARY 310
/* Value type. */
#if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED
typedef int YYSTYPE;
# define YYSTYPE_IS_TRIVIAL 1
# define YYSTYPE_IS_DECLARED 1
#endif
extern YYSTYPE yylval;
int yyparse (void);
#ifdef short
# undef short
#endif
/* On compilers that do not define __PTRDIFF_MAX__ etc., make sure
<limits.h> and (if available) <stdint.h> are included
so that the code can choose integer types of a good width. */
#ifndef __PTRDIFF_MAX__
# include <limits.h> /* INFRINGES ON USER NAME SPACE */
# if defined __STDC_VERSION__ && 199901 <= __STDC_VERSION__
# include <stdint.h> /* INFRINGES ON USER NAME SPACE */
# define YY_STDINT_H
# endif
#endif
/* Narrow types that promote to a signed type and that can represent a
signed or unsigned integer of at least N bits. In tables they can
save space and decrease cache pressure. Promoting to a signed type
helps avoid bugs in integer arithmetic. */
#ifdef __INT_LEAST8_MAX__
typedef __INT_LEAST8_TYPE__ yytype_int8;
#elif defined YY_STDINT_H
typedef int_least8_t yytype_int8;
#else
typedef signed char yytype_int8;
#endif
#ifdef __INT_LEAST16_MAX__
typedef __INT_LEAST16_TYPE__ yytype_int16;
#elif defined YY_STDINT_H
typedef int_least16_t yytype_int16;
#else
typedef short yytype_int16;
#endif
#if defined __UINT_LEAST8_MAX__ && __UINT_LEAST8_MAX__ <= __INT_MAX__
typedef __UINT_LEAST8_TYPE__ yytype_uint8;
#elif (!defined __UINT_LEAST8_MAX__ && defined YY_STDINT_H \
&& UINT_LEAST8_MAX <= INT_MAX)
typedef uint_least8_t yytype_uint8;
#elif !defined __UINT_LEAST8_MAX__ && UCHAR_MAX <= INT_MAX
typedef unsigned char yytype_uint8;
#else
typedef short yytype_uint8;
#endif
#if defined __UINT_LEAST16_MAX__ && __UINT_LEAST16_MAX__ <= __INT_MAX__
typedef __UINT_LEAST16_TYPE__ yytype_uint16;
#elif (!defined __UINT_LEAST16_MAX__ && defined YY_STDINT_H \
&& UINT_LEAST16_MAX <= INT_MAX)
typedef uint_least16_t yytype_uint16;
#elif !defined __UINT_LEAST16_MAX__ && USHRT_MAX <= INT_MAX
typedef unsigned short yytype_uint16;
#else
typedef int yytype_uint16;
#endif
#ifndef YYPTRDIFF_T
# if defined __PTRDIFF_TYPE__ && defined __PTRDIFF_MAX__
# define YYPTRDIFF_T __PTRDIFF_TYPE__
# define YYPTRDIFF_MAXIMUM __PTRDIFF_MAX__
# elif defined PTRDIFF_MAX
# ifndef ptrdiff_t
# include <stddef.h> /* INFRINGES ON USER NAME SPACE */
# endif
# define YYPTRDIFF_T ptrdiff_t
# define YYPTRDIFF_MAXIMUM PTRDIFF_MAX
# else
# define YYPTRDIFF_T long
# define YYPTRDIFF_MAXIMUM LONG_MAX
# endif
#endif
#ifndef YYSIZE_T
# ifdef __SIZE_TYPE__
# define YYSIZE_T __SIZE_TYPE__
# elif defined size_t
# define YYSIZE_T size_t
# elif defined __STDC_VERSION__ && 199901 <= __STDC_VERSION__
# include <stddef.h> /* INFRINGES ON USER NAME SPACE */
# define YYSIZE_T size_t
# else
# define YYSIZE_T unsigned
# endif
#endif
#define YYSIZE_MAXIMUM \
YY_CAST (YYPTRDIFF_T, \
(YYPTRDIFF_MAXIMUM < YY_CAST (YYSIZE_T, -1) \
? YYPTRDIFF_MAXIMUM \
: YY_CAST (YYSIZE_T, -1)))
#define YYSIZEOF(X) YY_CAST (YYPTRDIFF_T, sizeof (X))
/* Stored state numbers (used for stacks). */
typedef yytype_int16 yy_state_t;
/* State numbers in computations. */
typedef int yy_state_fast_t;
#ifndef YY_
# if defined YYENABLE_NLS && YYENABLE_NLS
# if ENABLE_NLS
# include <libintl.h> /* INFRINGES ON USER NAME SPACE */
# define YY_(Msgid) dgettext ("bison-runtime", Msgid)
# endif
# endif
# ifndef YY_
# define YY_(Msgid) Msgid
# endif
#endif
#ifndef YY_ATTRIBUTE_PURE
# if defined __GNUC__ && 2 < __GNUC__ + (96 <= __GNUC_MINOR__)
# define YY_ATTRIBUTE_PURE __attribute__ ((__pure__))
# else
# define YY_ATTRIBUTE_PURE
# endif
#endif
#ifndef YY_ATTRIBUTE_UNUSED
# if defined __GNUC__ && 2 < __GNUC__ + (7 <= __GNUC_MINOR__)
# define YY_ATTRIBUTE_UNUSED __attribute__ ((__unused__))
# else
# define YY_ATTRIBUTE_UNUSED
# endif
#endif
/* Suppress unused-variable warnings by "using" E. */
#if ! defined lint || defined __GNUC__
# define YYUSE(E) ((void) (E))
#else
# define YYUSE(E) /* empty */
#endif
#if defined __GNUC__ && ! defined __ICC && 407 <= __GNUC__ * 100 + __GNUC_MINOR__
/* Suppress an incorrect diagnostic about yylval being uninitialized. */
# define YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN \
_Pragma ("GCC diagnostic push") \
_Pragma ("GCC diagnostic ignored \"-Wuninitialized\"") \
_Pragma ("GCC diagnostic ignored \"-Wmaybe-uninitialized\"")
# define YY_IGNORE_MAYBE_UNINITIALIZED_END \
_Pragma ("GCC diagnostic pop")
#else
# define YY_INITIAL_VALUE(Value) Value
#endif
#ifndef YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN
# define YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN
# define YY_IGNORE_MAYBE_UNINITIALIZED_END
#endif
#ifndef YY_INITIAL_VALUE
# define YY_INITIAL_VALUE(Value) /* Nothing. */
#endif
#if defined __cplusplus && defined __GNUC__ && ! defined __ICC && 6 <= __GNUC__
# define YY_IGNORE_USELESS_CAST_BEGIN \
_Pragma ("GCC diagnostic push") \
_Pragma ("GCC diagnostic ignored \"-Wuseless-cast\"")
# define YY_IGNORE_USELESS_CAST_END \
_Pragma ("GCC diagnostic pop")
#endif
#ifndef YY_IGNORE_USELESS_CAST_BEGIN
# define YY_IGNORE_USELESS_CAST_BEGIN
# define YY_IGNORE_USELESS_CAST_END
#endif
#define YY_ASSERT(E) ((void) (0 && (E)))
#if ! defined yyoverflow || YYERROR_VERBOSE
/* The parser invokes alloca or malloc; define the necessary symbols. */
# ifdef YYSTACK_USE_ALLOCA
# if YYSTACK_USE_ALLOCA
# ifdef __GNUC__
# define YYSTACK_ALLOC __builtin_alloca
# elif defined __BUILTIN_VA_ARG_INCR
# include <alloca.h> /* INFRINGES ON USER NAME SPACE */
# elif defined _AIX
# define YYSTACK_ALLOC __alloca
# elif defined _MSC_VER
# include <malloc.h> /* INFRINGES ON USER NAME SPACE */
# define alloca _alloca
# else
# define YYSTACK_ALLOC alloca
# if ! defined _ALLOCA_H && ! defined EXIT_SUCCESS
# include <stdlib.h> /* INFRINGES ON USER NAME SPACE */
/* Use EXIT_SUCCESS as a witness for stdlib.h. */
# ifndef EXIT_SUCCESS
# define EXIT_SUCCESS 0
# endif
# endif
# endif
# endif
# endif
# ifdef YYSTACK_ALLOC
/* Pacify GCC's 'empty if-body' warning. */
# define YYSTACK_FREE(Ptr) do { /* empty */; } while (0)
# ifndef YYSTACK_ALLOC_MAXIMUM
/* The OS might guarantee only one guard page at the bottom of the stack,
and a page size can be as small as 4096 bytes. So we cannot safely
invoke alloca (N) if N exceeds 4096. Use a slightly smaller number
to allow for a few compiler-allocated temporary stack slots. */
# define YYSTACK_ALLOC_MAXIMUM 4032 /* reasonable circa 2006 */
# endif
# else
# define YYSTACK_ALLOC YYMALLOC
# define YYSTACK_FREE YYFREE
# ifndef YYSTACK_ALLOC_MAXIMUM
# define YYSTACK_ALLOC_MAXIMUM YYSIZE_MAXIMUM
# endif
# if (defined __cplusplus && ! defined EXIT_SUCCESS \
&& ! ((defined YYMALLOC || defined malloc) \
&& (defined YYFREE || defined free)))
# include <stdlib.h> /* INFRINGES ON USER NAME SPACE */
# ifndef EXIT_SUCCESS
# define EXIT_SUCCESS 0
# endif
# endif
# ifndef YYMALLOC
# define YYMALLOC malloc
# if ! defined malloc && ! defined EXIT_SUCCESS
void *malloc (YYSIZE_T); /* INFRINGES ON USER NAME SPACE */
# endif
# endif
# ifndef YYFREE
# define YYFREE free
# if ! defined free && ! defined EXIT_SUCCESS
void free (void *); /* INFRINGES ON USER NAME SPACE */
# endif
# endif
# endif
#endif /* ! defined yyoverflow || YYERROR_VERBOSE */
#if (! defined yyoverflow \
&& (! defined __cplusplus \
|| (defined YYSTYPE_IS_TRIVIAL && YYSTYPE_IS_TRIVIAL)))
/* A type that is properly aligned for any stack member. */
union yyalloc
{
yy_state_t yyss_alloc;
YYSTYPE yyvs_alloc;
};
/* The size of the maximum gap between one aligned stack and the next. */
# define YYSTACK_GAP_MAXIMUM (YYSIZEOF (union yyalloc) - 1)
/* The size of an array large to enough to hold all stacks, each with
N elements. */
# define YYSTACK_BYTES(N) \
((N) * (YYSIZEOF (yy_state_t) + YYSIZEOF (YYSTYPE)) \
+ YYSTACK_GAP_MAXIMUM)
# define YYCOPY_NEEDED 1
/* Relocate STACK from its old location to the new one. The
local variables YYSIZE and YYSTACKSIZE give the old and new number of
elements in the stack, and YYPTR gives the new location of the
stack. Advance YYPTR to a properly aligned location for the next
stack. */
# define YYSTACK_RELOCATE(Stack_alloc, Stack) \
do \
{ \
YYPTRDIFF_T yynewbytes; \
YYCOPY (&yyptr->Stack_alloc, Stack, yysize); \
Stack = &yyptr->Stack_alloc; \
yynewbytes = yystacksize * YYSIZEOF (*Stack) + YYSTACK_GAP_MAXIMUM; \
yyptr += yynewbytes / YYSIZEOF (*yyptr); \
} \
while (0)
#endif
#if defined YYCOPY_NEEDED && YYCOPY_NEEDED
/* Copy COUNT objects from SRC to DST. The source and destination do
not overlap. */
# ifndef YYCOPY
# if defined __GNUC__ && 1 < __GNUC__
# define YYCOPY(Dst, Src, Count) \
__builtin_memcpy (Dst, Src, YY_CAST (YYSIZE_T, (Count)) * sizeof (*(Src)))
# else
# define YYCOPY(Dst, Src, Count) \
do \
{ \
YYPTRDIFF_T yyi; \
for (yyi = 0; yyi < (Count); yyi++) \
(Dst)[yyi] = (Src)[yyi]; \
} \
while (0)
# endif
# endif
#endif /* !YYCOPY_NEEDED */
/* YYFINAL -- State number of the termination state. */
#define YYFINAL 2
/* YYLAST -- Last index in YYTABLE. */
#define YYLAST 1191
/* YYNTOKENS -- Number of terminals. */
#define YYNTOKENS 77
/* YYNNTS -- Number of nonterminals. */
#define YYNNTS 71
/* YYNRULES -- Number of rules. */
#define YYNRULES 207
/* YYNSTATES -- Number of states. */
#define YYNSTATES 355
#define YYUNDEFTOK 2
#define YYMAXUTOK 310
/* YYTRANSLATE(TOKEN-NUM) -- Symbol number corresponding to TOKEN-NUM
as returned by yylex, with out-of-bounds checking. */
#define YYTRANSLATE(YYX) \
(0 <= (YYX) && (YYX) <= YYMAXUTOK ? yytranslate[YYX] : YYUNDEFTOK)
/* YYTRANSLATE[TOKEN-NUM] -- Symbol number corresponding to TOKEN-NUM
as returned by yylex. */
static const yytype_int8 yytranslate[] =
{
0, 2, 2, 2, 2, 2, 2, 2, 2, 2,
2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
2, 2, 2, 65, 2, 2, 68, 64, 2, 2,
69, 70, 62, 60, 57, 61, 2, 63, 2, 2,
2, 2, 2, 2, 2, 2, 2, 2, 56, 76,
58, 2, 59, 55, 71, 2, 2, 2, 2, 2,
2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
2, 72, 2, 73, 67, 2, 2, 2, 2, 2,
2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
2, 2, 2, 74, 2, 75, 2, 2, 2, 2,
2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
2, 2, 2, 2, 2, 2, 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,
66
};
#if YYDEBUG
/* YYRLINE[YYN] -- Source line where rule number YYN was defined. */
static const yytype_int16 yyrline[] =
{
0, 232, 232, 233, 238, 248, 252, 264, 272, 286,
297, 307, 317, 330, 340, 342, 347, 357, 359, 364,
366, 368, 374, 378, 383, 413, 425, 437, 443, 452,
470, 471, 482, 488, 496, 497, 501, 501, 535, 534,
568, 583, 585, 590, 591, 611, 616, 617, 621, 632,
637, 644, 752, 803, 853, 979, 1001, 1022, 1032, 1042,
1052, 1063, 1076, 1094, 1093, 1110, 1128, 1128, 1230, 1230,
1263, 1293, 1301, 1302, 1308, 1309, 1316, 1321, 1334, 1349,
1351, 1359, 1366, 1368, 1376, 1385, 1387, 1396, 1397, 1405,
1410, 1410, 1423, 1430, 1443, 1447, 1469, 1470, 1476, 1477,
1486, 1487, 1492, 1497, 1514, 1516, 1518, 1525, 1526, 1532,
1533, 1538, 1540, 1547, 1549, 1557, 1562, 1573, 1574, 1579,
1581, 1588, 1590, 1598, 1603, 1613, 1614, 1619, 1626, 1630,
1632, 1634, 1647, 1664, 1674, 1681, 1683, 1688, 1690, 1692,
1700, 1702, 1707, 1709, 1714, 1716, 1718, 1775, 1777, 1779,
1781, 1783, 1785, 1787, 1789, 1803, 1808, 1813, 1839, 1845,
1847, 1849, 1851, 1853, 1855, 1860, 1864, 1896, 1904, 1910,
1916, 1929, 1930, 1931, 1936, 1941, 1945, 1949, 1964, 1985,
1990, 2027, 2064, 2065, 2071, 2072, 2077, 2079, 2086, 2103,
2120, 2122, 2129, 2134, 2140, 2151, 2163, 2172, 2176, 2181,
2185, 2189, 2193, 2198, 2199, 2203, 2207, 2211
};
#endif
#if YYDEBUG || YYERROR_VERBOSE || 0
/* YYTNAME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM.
First, the terminals, then, starting at YYNTOKENS, nonterminals. */
static const char *const yytname[] =
{
"$end", "error", "$undefined", "FUNC_CALL", "NAME", "REGEXP",
"FILENAME", "YNUMBER", "YSTRING", "TYPED_REGEXP", "RELOP", "IO_OUT",
"IO_IN", "ASSIGNOP", "ASSIGN", "MATCHOP", "CONCAT_OP", "SUBSCRIPT",
"LEX_BEGIN", "LEX_END", "LEX_IF", "LEX_ELSE", "LEX_RETURN", "LEX_DELETE",
"LEX_SWITCH", "LEX_CASE", "LEX_DEFAULT", "LEX_WHILE", "LEX_DO",
"LEX_FOR", "LEX_BREAK", "LEX_CONTINUE", "LEX_PRINT", "LEX_PRINTF",
"LEX_NEXT", "LEX_EXIT", "LEX_FUNCTION", "LEX_BEGINFILE", "LEX_ENDFILE",
"LEX_GETLINE", "LEX_NEXTFILE", "LEX_IN", "LEX_AND", "LEX_OR",
"INCREMENT", "DECREMENT", "LEX_BUILTIN", "LEX_LENGTH", "LEX_EOF",
"LEX_INCLUDE", "LEX_EVAL", "LEX_LOAD", "LEX_NAMESPACE", "NEWLINE",
"SLASH_BEFORE_EQUAL", "'?'", "':'", "','", "'<'", "'>'", "'+'", "'-'",
"'*'", "'/'", "'%'", "'!'", "UNARY", "'^'", "'$'", "'('", "')'", "'@'",
"'['", "']'", "'{'", "'}'", "';'", "$accept", "program", "rule",
"source", "library", "namespace", "pattern", "action", "func_name",
"lex_builtin", "function_prologue", "$@1", "regexp", "$@2",
"typed_regexp", "a_slash", "statements", "statement_term", "statement",
"non_compound_stmt", "$@3", "simple_stmt", "$@4", "$@5",
"opt_simple_stmt", "case_statements", "case_statement", "case_value",
"print", "print_expression_list", "output_redir", "$@6", "if_statement",
"nls", "opt_nls", "input_redir", "opt_param_list", "param_list",
"opt_exp", "opt_expression_list", "expression_list",
"opt_fcall_expression_list", "fcall_expression_list", "fcall_exp", "exp",
"assign_operator", "relop_or_less", "a_relop", "common_exp", "simp_exp",
"simp_exp_nc", "non_post_simp_exp", "func_call", "direct_func_call",
"opt_variable", "delete_subscript_list", "delete_subscript",
"delete_exp_list", "bracketed_exp_list", "subscript", "subscript_list",
"simple_variable", "variable", "opt_incdec", "l_brace", "r_brace",
"r_paren", "opt_semi", "semi", "colon", "comma", YY_NULLPTR
};
#endif
# ifdef YYPRINT
/* YYTOKNUM[NUM] -- (External) token number corresponding to the
(internal) symbol number NUM (which must be that of a token). */
static const yytype_int16 yytoknum[] =
{
0, 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, 63, 58, 44, 60, 62,
43, 45, 42, 47, 37, 33, 310, 94, 36, 40,
41, 64, 91, 93, 123, 125, 59
};
# endif
#define YYPACT_NINF (-283)
#define yypact_value_is_default(Yyn) \
((Yyn) == YYPACT_NINF)
#define YYTABLE_NINF (-119)
#define yytable_value_is_error(Yyn) \
((Yyn) == YYTABLE_NINF)
/* YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing
STATE-NUM. */
static const yytype_int16 yypact[] =
{
-283, 316, -283, -283, -45, -28, -283, -283, -283, -283,
160, -283, -283, 23, 23, 23, -39, -18, -283, -283,
-283, 1047, 1047, -283, 1047, 1075, 818, 257, -283, 99,
-20, -283, -283, 11, 1017, 974, 378, 415, -283, -283,
-283, -283, 329, 742, 818, -283, 0, -283, -283, -283,
-283, -283, 25, 9, -283, 22, -283, -283, -283, 742,
742, 79, 46, 18, 46, 46, 1047, 114, -283, -283,
13, 286, 44, 47, 60, -283, 94, -283, -283, -283,
11, -283, 94, -283, 151, -283, -283, 1002, 162, 1047,
1047, 1047, 94, -283, -283, -283, 1047, 1047, 132, 378,
1047, 1047, 1047, 1047, 1047, 1047, 1047, 1047, 1047, 1047,
1047, 1047, -283, 170, -283, -283, 168, 1047, -283, -283,
-283, 116, 14, -283, 1132, 76, 1132, -283, -283, -283,
-283, 1047, -283, 116, 116, 286, -283, -283, -283, 1047,
-283, 144, 846, -283, -283, 34, 91, -283, 39, 91,
-283, 59, 91, 11, -283, 542, -283, -283, -283, 145,
-283, 135, 580, 1113, -283, 189, 1132, 23, 230, 230,
46, 46, 46, 46, 230, 230, 46, 46, 46, 46,
-283, -283, 1132, -283, 1002, 770, -283, 27, 378, -283,
-283, 1132, 162, -283, 1132, -283, -283, -283, -283, -283,
-283, -283, 119, -283, 12, 123, 126, 94, 128, 91,
91, -283, -283, 91, 1047, 91, 94, -283, -283, 91,
-283, -283, 1132, -283, 122, 94, 1047, -283, -283, -283,
-283, -283, -283, 116, 73, -283, 1047, 1047, -283, 198,
1047, 1047, 660, 895, -283, -283, -283, 91, 1132, -283,
-283, -283, 590, 542, 94, -283, -283, 1132, 94, -283,
28, 286, 91, -28, 141, 286, 286, 190, -23, -283,
122, -283, 818, 205, -283, 325, -283, -283, -283, -283,
-283, 94, -283, -283, 115, -283, -283, -283, 94, 94,
153, 162, 94, 13, -283, -283, 660, -283, -283, -20,
660, 1047, 116, 694, 144, 1047, 209, -283, -283, 286,
94, 1090, 94, 974, 94, 152, 94, 660, 94, 929,
660, -283, 342, 176, -283, 158, -283, -283, 929, 116,
-283, -283, -283, 236, 243, -283, -283, 176, -283, 94,
-283, 116, 94, -283, -283, 94, -283, 94, 660, -283,
390, 660, -283, 466, -283
};
/* YYDEFACT[STATE-NUM] -- Default reduction number in state STATE-NUM.
Performed when YYTABLE does not specify something else to do. Zero
means the default is an error. */
static const yytype_uint8 yydefact[] =
{
2, 0, 1, 6, 0, 193, 175, 176, 25, 26,
0, 27, 28, 182, 0, 0, 0, 170, 5, 94,
42, 0, 0, 41, 0, 0, 0, 0, 3, 0,
0, 165, 38, 4, 23, 136, 144, 145, 147, 171,
179, 195, 172, 0, 0, 190, 0, 194, 31, 30,
34, 35, 0, 0, 32, 98, 183, 173, 174, 0,
0, 0, 178, 172, 177, 166, 0, 199, 172, 113,
0, 111, 0, 0, 0, 180, 96, 205, 7, 8,
46, 43, 96, 9, 0, 95, 140, 0, 0, 0,
0, 0, 96, 141, 143, 142, 0, 0, 0, 146,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 138, 137, 155, 156, 0, 0, 121, 40,
126, 0, 0, 119, 125, 0, 111, 192, 191, 33,
36, 0, 154, 0, 0, 0, 197, 198, 196, 114,
202, 0, 0, 167, 15, 0, 0, 18, 0, 0,
21, 0, 0, 97, 200, 0, 47, 39, 131, 132,
133, 129, 130, 0, 207, 134, 24, 182, 152, 153,
149, 150, 151, 148, 163, 164, 160, 161, 162, 159,
128, 139, 127, 181, 122, 0, 189, 0, 99, 168,
169, 115, 0, 116, 112, 14, 10, 17, 11, 20,
12, 45, 0, 63, 0, 0, 0, 96, 0, 0,
0, 85, 86, 0, 107, 0, 96, 44, 57, 0,
66, 50, 71, 43, 203, 96, 0, 158, 123, 124,
120, 104, 102, 0, 0, 157, 0, 107, 68, 0,
0, 0, 0, 72, 58, 59, 60, 0, 108, 61,
201, 65, 0, 0, 96, 204, 48, 135, 96, 105,
0, 0, 0, 184, 0, 0, 0, 0, 193, 73,
0, 62, 0, 89, 87, 0, 49, 29, 37, 106,
103, 96, 64, 69, 0, 186, 188, 70, 96, 96,
0, 0, 96, 0, 90, 67, 0, 185, 187, 0,
0, 0, 0, 0, 88, 0, 92, 74, 52, 0,
96, 0, 96, 91, 96, 0, 96, 0, 96, 72,
0, 76, 0, 0, 75, 0, 53, 54, 72, 0,
93, 79, 82, 0, 0, 83, 84, 0, 206, 96,
51, 0, 96, 81, 80, 96, 43, 96, 0, 43,
0, 0, 56, 0, 55
};
/* YYPGOTO[NTERM-NUM]. */
static const yytype_int16 yypgoto[] =
{
-283, -283, -283, -283, -283, -283, -283, 226, -283, -283,
-283, -283, -63, -283, -77, -283, -215, -73, -30, -283,
-283, -234, -283, -283, -282, -283, -283, -283, -283, -283,
-283, -283, -283, 5, -35, -283, -283, -283, 24, -283,
-43, 101, -283, -15, -1, -283, -283, -283, -40, 17,
-283, 237, -283, -6, 96, -283, -283, -16, -42, -283,
-283, -81, -2, -283, -27, -186, -65, -283, -62, -68,
-8
};
/* YYDEFGOTO[NTERM-NUM]. */
static const yytype_int16 yydefgoto[] =
{
-1, 1, 28, 146, 149, 152, 29, 78, 53, 54,
30, 187, 31, 84, 120, 32, 155, 79, 217, 218,
237, 219, 252, 263, 270, 315, 324, 337, 220, 273,
295, 305, 221, 153, 154, 132, 233, 234, 247, 274,
70, 121, 122, 123, 222, 117, 95, 96, 35, 36,
37, 38, 39, 40, 55, 283, 284, 285, 45, 46,
47, 41, 42, 138, 223, 224, 143, 254, 82, 339,
142
};
/* YYTABLE[YYPACT[STATE-NUM]] -- What to do in state STATE-NUM. If
positive, shift that token. If negative, reduce the rule whose
number is the opposite. If YYTABLE_NINF, syntax error. */
static const yytype_int16 yytable[] =
{
34, 125, 81, 81, 128, 141, 33, 160, 253, 269,
158, 56, 57, 58, 139, 184, 238, 127, 291, 63,
63, 75, 63, 68, 43, 71, 97, 5, 231, 279,
59, 232, 280, 63, 80, 195, 180, 329, 62, 64,
197, 65, 124, 126, 44, 144, 341, 156, 147, 44,
145, 60, 99, 148, 76, 75, 183, 164, 124, 124,
199, 150, 114, 115, 85, 135, 151, 276, 189, 190,
92, 92, 44, 196, 259, 129, 198, 139, 130, 200,
131, 239, 4, 140, -118, 269, 159, -13, 161, 162,
163, 25, -16, 225, 269, 165, 166, -100, 63, 63,
63, 63, 63, 63, 63, 63, 63, 63, 63, 63,
-13, 235, -19, 105, 185, -16, 182, 168, 169, 170,
171, 172, 173, 174, 175, 176, 177, 178, 179, 63,
92, 350, 297, 92, 353, -19, 244, 245, 191, 340,
246, 194, 249, -101, 19, 86, 251, 19, 188, 186,
87, 80, 19, 321, 80, 86, 157, 80, 136, 137,
133, 134, 255, 48, 49, 56, 5, 77, 258, 228,
230, 167, 242, 76, 271, 77, 88, 322, 323, 119,
225, 250, 181, 124, 124, 192, 140, 44, 236, 282,
256, 225, 240, 93, 94, 241, 281, 243, 77, -119,
288, 289, 264, 93, 94, 19, 50, 51, 292, 275,
302, 287, 267, 248, 80, 80, 294, 290, 80, 277,
80, 286, 301, 278, 80, 257, 260, -96, 304, 293,
314, 52, 338, 216, 225, 261, 248, 310, 225, 265,
266, 312, 286, 343, 316, 336, 296, -119, -119, 318,
344, 126, 80, 299, 300, 225, 83, 303, 225, 335,
4, 262, 67, 227, 342, 313, 306, 80, 298, 345,
308, 71, 307, 0, 0, 317, 347, 319, 0, 320,
325, 326, 0, 328, 0, 0, 225, 327, 225, 225,
330, 225, 102, 103, 104, 0, 86, 105, 0, 0,
309, 87, 311, 63, 346, 0, 72, 348, 73, 74,
349, 63, 351, 0, 0, 0, 2, 3, 352, 4,
5, 354, 0, 6, 7, 0, 139, 88, 89, 90,
99, 0, 0, 0, 8, 9, -110, 0, 0, 0,
0, 91, 112, 113, 93, 94, 0, 0, 0, 331,
332, 119, 10, 11, 12, 13, 140, 0, 0, 0,
14, 15, 16, 17, 18, 0, 0, 0, 0, 19,
20, 0, 0, 114, 115, 0, 21, 22, -110, 23,
0, 24, 92, 116, 25, 26, 0, 27, 0, 0,
-22, 201, -22, 4, 5, -110, 20, 6, 7, 0,
0, -110, 333, 334, 0, 23, 0, 0, 0, 0,
202, 0, 203, 204, 205, -78, -78, 206, 207, 208,
209, 210, 211, 212, 213, 214, 0, 0, 0, 13,
215, 0, 0, 0, 14, 15, 16, 17, 100, 101,
102, 103, 104, -78, 20, 105, 0, 0, 0, 0,
21, 22, 0, 23, 0, 24, 0, 0, 25, 26,
0, 61, 0, 0, 76, -78, 77, 201, 0, 4,
5, 0, 0, 6, 7, 106, 107, 108, 109, 110,
0, 0, 111, 0, 0, 0, 202, 0, 203, 204,
205, -77, -77, 206, 207, 208, 209, 210, 211, 212,
213, 214, 0, 0, 0, 13, 215, 0, 0, 0,
14, 15, 16, 17, 0, 0, 0, 0, 0, -77,
20, 0, 0, 0, 0, 0, 21, 22, 0, 23,
0, 24, 0, 0, 25, 26, 0, 61, 0, 0,
76, -77, 77, 201, 0, 4, 5, 0, 0, 6,
7, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 202, 0, 203, 204, 205, 0, 0, 206,
207, 208, 209, 210, 211, 212, 213, 214, 0, 0,
0, 13, 215, 0, 0, 0, 14, 15, 16, 17,
86, 69, 0, 4, 5, 87, 20, 6, 7, 0,
0, -109, 21, 22, 0, 23, 0, 24, 0, 0,
25, 26, 0, 61, 0, 0, 76, 216, 77, 0,
0, 88, 89, 0, 0, 0, 0, 0, 0, 13,
0, 0, 0, 0, 14, 15, 16, 17, 93, 94,
0, 0, 0, -109, 20, 0, 0, 0, 0, 0,
21, 22, 0, 23, 0, 24, 0, 0, 25, 272,
-109, 61, 0, 4, 5, 0, -109, 6, 7, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
202, 0, 203, 204, 205, 0, 0, 206, 207, 208,
209, 210, 211, 212, 213, 214, 0, 4, 5, 13,
215, 6, 7, 0, 14, 15, 16, 17, 0, 0,
0, 0, 0, 0, 20, 0, 0, 0, 0, 0,
21, 22, 0, 23, 0, 24, 0, 0, 25, 26,
0, 61, 0, 13, 76, 0, 77, 0, 14, 15,
16, 17, 0, 118, 0, 4, 5, 0, 20, 6,
7, 119, 0, 0, 21, 22, 0, 23, 0, 24,
0, 0, 25, 26, 0, 61, 0, 0, 0, 0,
77, 229, 0, 4, 5, 0, 0, 6, 7, 119,
0, 13, 0, 0, 0, 0, 14, 15, 16, 17,
0, 0, 0, 0, 0, 0, 20, 0, 0, 0,
0, 0, 21, 22, 0, 23, 0, 24, 0, 13,
25, 26, -117, 61, 14, 15, 16, 17, 0, 69,
0, 4, 5, 0, 20, 6, 7, 0, 0, 0,
21, 22, 0, 23, 0, 24, 0, 0, 25, 26,
0, 61, 0, 0, 0, 0, 0, 193, 0, 4,
5, 0, 0, 6, 7, 0, 0, 13, 0, 0,
0, 0, 14, 15, 16, 17, 0, 0, 0, 0,
0, 0, 20, 0, 0, 0, 0, 0, 21, 22,
0, 23, 0, 24, 0, 13, 25, 26, 0, 61,
14, 15, 16, 17, 0, 0, 0, 0, 4, 268,
20, 0, 6, 7, 0, 0, 21, 22, 0, 23,
0, 24, 0, 0, 25, 26, 0, 61, 204, 0,
0, 0, 0, 0, 0, 0, 0, 211, 212, 0,
0, 0, 4, 5, 13, 0, 6, 7, 0, 14,
15, 16, 17, 0, 0, 0, 0, 0, 0, 20,
0, 0, 204, 0, 0, 21, 22, 0, 23, 0,
24, 211, 212, 25, 26, 0, 61, 0, 13, 0,
0, 0, 0, 14, 15, 16, 17, 4, 5, 0,
0, 6, 7, 20, 0, 0, 98, 0, 0, 21,
22, 0, 23, 0, 24, 0, 0, 25, 26, 0,
61, 0, 0, 0, 0, 4, 5, 0, 0, 6,
7, 119, 0, 13, 0, 0, 0, 0, 14, 15,
16, 17, 0, 0, 0, 0, 0, 86, 20, 0,
0, 0, 87, 0, 21, 22, 0, 23, 0, 24,
0, 13, 25, 26, 0, 61, 14, 15, 16, 17,
4, 5, 0, 0, 6, 7, 20, 0, 88, 89,
90, 0, 21, 22, 0, 23, 0, 24, 0, 0,
25, 26, 91, 61, 92, 93, 94, 0, 4, 5,
0, 0, 6, 7, 0, 0, 13, 0, 0, 0,
0, 14, 15, 16, 17, 0, 0, 0, 0, 0,
86, 20, 0, 0, 0, 87, 0, 21, 22, 0,
23, 0, 24, 0, 0, 25, 26, 0, 61, 14,
15, 16, 17, 86, 0, 0, 0, 0, 87, 20,
0, 88, 89, 90, 0, 21, 22, 0, 23, 0,
24, 0, 86, 25, 66, 91, 61, 87, 93, 94,
0, 0, 0, 0, 88, 89, 90, 0, 0, 0,
0, 0, 0, 0, 0, 0, 77, 0, 91, 226,
0, 93, 94, 88, 89, 90, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 91, 0, 0,
93, 94
};
static const yytype_int16 yycheck[] =
{
1, 44, 29, 30, 46, 70, 1, 88, 223, 243,
87, 13, 14, 15, 1, 1, 4, 17, 41, 21,
22, 27, 24, 25, 69, 26, 34, 4, 1, 1,
69, 4, 4, 35, 29, 1, 113, 319, 21, 22,
1, 24, 43, 44, 72, 1, 328, 82, 1, 72,
6, 69, 35, 6, 74, 61, 121, 92, 59, 60,
1, 1, 44, 45, 53, 66, 6, 253, 133, 134,
57, 57, 72, 146, 1, 50, 149, 1, 69, 152,
58, 69, 3, 70, 70, 319, 87, 53, 89, 90,
91, 68, 53, 155, 328, 96, 97, 70, 100, 101,
102, 103, 104, 105, 106, 107, 108, 109, 110, 111,
76, 192, 53, 67, 122, 76, 117, 100, 101, 102,
103, 104, 105, 106, 107, 108, 109, 110, 111, 131,
57, 346, 17, 57, 349, 76, 209, 210, 139, 325,
213, 142, 215, 70, 53, 10, 219, 53, 131, 73,
15, 146, 53, 1, 149, 10, 5, 152, 44, 45,
59, 60, 224, 3, 4, 167, 4, 76, 233, 184,
185, 39, 207, 74, 247, 76, 41, 25, 26, 9,
242, 216, 14, 184, 185, 41, 70, 72, 69, 262,
225, 253, 69, 58, 59, 69, 261, 69, 76, 10,
265, 266, 4, 58, 59, 53, 46, 47, 270, 252,
291, 70, 242, 214, 209, 210, 11, 27, 213, 254,
215, 263, 69, 258, 219, 226, 234, 75, 293, 272,
21, 71, 56, 75, 296, 236, 237, 302, 300, 240,
241, 303, 284, 7, 309, 322, 281, 58, 59, 311,
7, 252, 247, 288, 289, 317, 30, 292, 320, 322,
3, 237, 25, 167, 329, 305, 296, 262, 284, 337,
300, 272, 299, -1, -1, 310, 341, 312, -1, 314,
315, 316, -1, 318, -1, -1, 348, 317, 350, 351,
320, 353, 62, 63, 64, -1, 10, 67, -1, -1,
301, 15, 303, 305, 339, -1, 49, 342, 51, 52,
345, 313, 347, -1, -1, -1, 0, 1, 348, 3,
4, 351, -1, 7, 8, -1, 1, 41, 42, 43,
313, -1, -1, -1, 18, 19, 11, -1, -1, -1,
-1, 55, 13, 14, 58, 59, -1, -1, -1, 7,
8, 9, 36, 37, 38, 39, 70, -1, -1, -1,
44, 45, 46, 47, 48, -1, -1, -1, -1, 53,
54, -1, -1, 44, 45, -1, 60, 61, 53, 63,
-1, 65, 57, 54, 68, 69, -1, 71, -1, -1,
74, 1, 76, 3, 4, 70, 54, 7, 8, -1,
-1, 76, 60, 61, -1, 63, -1, -1, -1, -1,
20, -1, 22, 23, 24, 25, 26, 27, 28, 29,
30, 31, 32, 33, 34, 35, -1, -1, -1, 39,
40, -1, -1, -1, 44, 45, 46, 47, 60, 61,
62, 63, 64, 53, 54, 67, -1, -1, -1, -1,
60, 61, -1, 63, -1, 65, -1, -1, 68, 69,
-1, 71, -1, -1, 74, 75, 76, 1, -1, 3,
4, -1, -1, 7, 8, 60, 61, 62, 63, 64,
-1, -1, 67, -1, -1, -1, 20, -1, 22, 23,
24, 25, 26, 27, 28, 29, 30, 31, 32, 33,
34, 35, -1, -1, -1, 39, 40, -1, -1, -1,
44, 45, 46, 47, -1, -1, -1, -1, -1, 53,
54, -1, -1, -1, -1, -1, 60, 61, -1, 63,
-1, 65, -1, -1, 68, 69, -1, 71, -1, -1,
74, 75, 76, 1, -1, 3, 4, -1, -1, 7,
8, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, 20, -1, 22, 23, 24, -1, -1, 27,
28, 29, 30, 31, 32, 33, 34, 35, -1, -1,
-1, 39, 40, -1, -1, -1, 44, 45, 46, 47,
10, 1, -1, 3, 4, 15, 54, 7, 8, -1,
-1, 11, 60, 61, -1, 63, -1, 65, -1, -1,
68, 69, -1, 71, -1, -1, 74, 75, 76, -1,
-1, 41, 42, -1, -1, -1, -1, -1, -1, 39,
-1, -1, -1, -1, 44, 45, 46, 47, 58, 59,
-1, -1, -1, 53, 54, -1, -1, -1, -1, -1,
60, 61, -1, 63, -1, 65, -1, -1, 68, 69,
70, 71, -1, 3, 4, -1, 76, 7, 8, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
20, -1, 22, 23, 24, -1, -1, 27, 28, 29,
30, 31, 32, 33, 34, 35, -1, 3, 4, 39,
40, 7, 8, -1, 44, 45, 46, 47, -1, -1,
-1, -1, -1, -1, 54, -1, -1, -1, -1, -1,
60, 61, -1, 63, -1, 65, -1, -1, 68, 69,
-1, 71, -1, 39, 74, -1, 76, -1, 44, 45,
46, 47, -1, 1, -1, 3, 4, -1, 54, 7,
8, 9, -1, -1, 60, 61, -1, 63, -1, 65,
-1, -1, 68, 69, -1, 71, -1, -1, -1, -1,
76, 1, -1, 3, 4, -1, -1, 7, 8, 9,
-1, 39, -1, -1, -1, -1, 44, 45, 46, 47,
-1, -1, -1, -1, -1, -1, 54, -1, -1, -1,
-1, -1, 60, 61, -1, 63, -1, 65, -1, 39,
68, 69, 70, 71, 44, 45, 46, 47, -1, 1,
-1, 3, 4, -1, 54, 7, 8, -1, -1, -1,
60, 61, -1, 63, -1, 65, -1, -1, 68, 69,
-1, 71, -1, -1, -1, -1, -1, 1, -1, 3,
4, -1, -1, 7, 8, -1, -1, 39, -1, -1,
-1, -1, 44, 45, 46, 47, -1, -1, -1, -1,
-1, -1, 54, -1, -1, -1, -1, -1, 60, 61,
-1, 63, -1, 65, -1, 39, 68, 69, -1, 71,
44, 45, 46, 47, -1, -1, -1, -1, 3, 4,
54, -1, 7, 8, -1, -1, 60, 61, -1, 63,
-1, 65, -1, -1, 68, 69, -1, 71, 23, -1,
-1, -1, -1, -1, -1, -1, -1, 32, 33, -1,
-1, -1, 3, 4, 39, -1, 7, 8, -1, 44,
45, 46, 47, -1, -1, -1, -1, -1, -1, 54,
-1, -1, 23, -1, -1, 60, 61, -1, 63, -1,
65, 32, 33, 68, 69, -1, 71, -1, 39, -1,
-1, -1, -1, 44, 45, 46, 47, 3, 4, -1,
-1, 7, 8, 54, -1, -1, 12, -1, -1, 60,
61, -1, 63, -1, 65, -1, -1, 68, 69, -1,
71, -1, -1, -1, -1, 3, 4, -1, -1, 7,
8, 9, -1, 39, -1, -1, -1, -1, 44, 45,
46, 47, -1, -1, -1, -1, -1, 10, 54, -1,
-1, -1, 15, -1, 60, 61, -1, 63, -1, 65,
-1, 39, 68, 69, -1, 71, 44, 45, 46, 47,
3, 4, -1, -1, 7, 8, 54, -1, 41, 42,
43, -1, 60, 61, -1, 63, -1, 65, -1, -1,
68, 69, 55, 71, 57, 58, 59, -1, 3, 4,
-1, -1, 7, 8, -1, -1, 39, -1, -1, -1,
-1, 44, 45, 46, 47, -1, -1, -1, -1, -1,
10, 54, -1, -1, -1, 15, -1, 60, 61, -1,
63, -1, 65, -1, -1, 68, 69, -1, 71, 44,
45, 46, 47, 10, -1, -1, -1, -1, 15, 54,
-1, 41, 42, 43, -1, 60, 61, -1, 63, -1,
65, -1, 10, 68, 69, 55, 71, 15, 58, 59,
-1, -1, -1, -1, 41, 42, 43, -1, -1, -1,
-1, -1, -1, -1, -1, -1, 76, -1, 55, 56,
-1, 58, 59, 41, 42, 43, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, 55, -1, -1,
58, 59
};
/* YYSTOS[STATE-NUM] -- The (internal number of the) accessing
symbol of state STATE-NUM. */
static const yytype_uint8 yystos[] =
{
0, 78, 0, 1, 3, 4, 7, 8, 18, 19,
36, 37, 38, 39, 44, 45, 46, 47, 48, 53,
54, 60, 61, 63, 65, 68, 69, 71, 79, 83,
87, 89, 92, 110, 121, 125, 126, 127, 128, 129,
130, 138, 139, 69, 72, 135, 136, 137, 3, 4,
46, 47, 71, 85, 86, 131, 139, 139, 139, 69,
69, 71, 126, 139, 126, 126, 69, 128, 139, 1,
117, 121, 49, 51, 52, 130, 74, 76, 84, 94,
110, 141, 145, 84, 90, 53, 10, 15, 41, 42,
43, 55, 57, 58, 59, 123, 124, 147, 12, 126,
60, 61, 62, 63, 64, 67, 60, 61, 62, 63,
64, 67, 13, 14, 44, 45, 54, 122, 1, 9,
91, 118, 119, 120, 121, 117, 121, 17, 135, 50,
69, 58, 112, 118, 118, 121, 44, 45, 140, 1,
70, 143, 147, 143, 1, 6, 80, 1, 6, 81,
1, 6, 82, 110, 111, 93, 111, 5, 91, 121,
138, 121, 121, 121, 111, 121, 121, 39, 126, 126,
126, 126, 126, 126, 126, 126, 126, 126, 126, 126,
91, 14, 121, 143, 1, 147, 73, 88, 126, 143,
143, 121, 41, 1, 121, 1, 94, 1, 94, 1,
94, 1, 20, 22, 23, 24, 27, 28, 29, 30,
31, 32, 33, 34, 35, 40, 75, 95, 96, 98,
105, 109, 121, 141, 142, 145, 56, 131, 120, 1,
120, 1, 4, 113, 114, 138, 69, 97, 4, 69,
69, 69, 111, 69, 94, 94, 94, 115, 121, 94,
111, 94, 99, 93, 144, 145, 111, 121, 143, 1,
147, 121, 115, 100, 4, 121, 121, 95, 4, 98,
101, 94, 69, 106, 116, 117, 142, 111, 111, 1,
4, 143, 94, 132, 133, 134, 135, 70, 143, 143,
27, 41, 145, 117, 11, 107, 111, 17, 134, 111,
111, 69, 138, 111, 143, 108, 95, 141, 95, 121,
143, 121, 145, 125, 21, 102, 143, 111, 145, 111,
111, 1, 25, 26, 103, 111, 111, 95, 111, 101,
95, 7, 8, 60, 61, 89, 91, 104, 56, 146,
142, 101, 143, 7, 7, 146, 111, 143, 111, 111,
93, 111, 95, 93, 95
};
/* YYR1[YYN] -- Symbol number of symbol that rule YYN derives. */
static const yytype_uint8 yyr1[] =
{
0, 77, 78, 78, 78, 78, 78, 79, 79, 79,
79, 79, 79, 80, 80, 80, 81, 81, 81, 82,
82, 82, 83, 83, 83, 83, 83, 83, 83, 84,
85, 85, 85, 85, 86, 86, 88, 87, 90, 89,
91, 92, 92, 93, 93, 93, 94, 94, 95, 95,
95, 95, 95, 95, 95, 95, 95, 95, 96, 96,
96, 96, 96, 97, 96, 96, 99, 98, 100, 98,
98, 98, 101, 101, 102, 102, 102, 103, 103, 104,
104, 104, 104, 104, 104, 105, 105, 106, 106, 107,
108, 107, 109, 109, 110, 110, 111, 111, 112, 112,
113, 113, 114, 114, 114, 114, 114, 115, 115, 116,
116, 117, 117, 117, 117, 117, 117, 118, 118, 119,
119, 119, 119, 119, 119, 120, 120, 121, 121, 121,
121, 121, 121, 121, 121, 121, 121, 122, 122, 122,
123, 123, 124, 124, 125, 125, 125, 126, 126, 126,
126, 126, 126, 126, 126, 126, 126, 126, 127, 127,
127, 127, 127, 127, 127, 128, 128, 128, 128, 128,
128, 128, 128, 128, 128, 128, 128, 128, 128, 129,
129, 130, 131, 131, 132, 132, 133, 133, 134, 135,
136, 136, 137, 138, 138, 139, 139, 140, 140, 140,
141, 142, 143, 144, 144, 145, 146, 147
};
/* YYR2[YYN] -- Number of symbols on the right hand side of rule YYN. */
static const yytype_int8 yyr2[] =
{
0, 2, 0, 2, 2, 2, 2, 2, 2, 2,
4, 4, 4, 1, 2, 1, 1, 2, 1, 1,
2, 1, 0, 1, 3, 1, 1, 1, 1, 5,
1, 1, 1, 2, 1, 1, 0, 7, 0, 3,
1, 1, 1, 0, 2, 2, 1, 2, 2, 3,
1, 9, 6, 8, 8, 12, 11, 1, 2, 2,
2, 2, 3, 0, 4, 2, 0, 4, 0, 4,
4, 1, 0, 1, 0, 2, 2, 5, 4, 1,
2, 2, 1, 1, 1, 1, 1, 1, 3, 0,
0, 3, 6, 9, 1, 2, 0, 1, 0, 2,
0, 1, 1, 3, 1, 2, 3, 0, 1, 0,
1, 1, 3, 1, 2, 3, 3, 0, 1, 1,
3, 1, 2, 3, 3, 1, 1, 3, 3, 3,
3, 3, 3, 3, 3, 5, 1, 1, 1, 2,
1, 1, 1, 1, 1, 1, 2, 1, 3, 3,
3, 3, 3, 3, 3, 2, 2, 5, 4, 3,
3, 3, 3, 3, 3, 1, 2, 3, 4, 4,
1, 1, 1, 2, 2, 1, 1, 2, 2, 1,
2, 4, 0, 1, 0, 2, 1, 2, 1, 3,
1, 2, 2, 1, 2, 1, 3, 1, 1, 0,
2, 2, 1, 0, 1, 1, 1, 2
};
#define yyerrok (yyerrstatus = 0)
#define yyclearin (yychar = YYEMPTY)
#define YYEMPTY (-2)
#define YYEOF 0
#define YYACCEPT goto yyacceptlab
#define YYABORT goto yyabortlab
#define YYERROR goto yyerrorlab
#define YYRECOVERING() (!!yyerrstatus)
#define YYBACKUP(Token, Value) \
do \
if (yychar == YYEMPTY) \
{ \
yychar = (Token); \
yylval = (Value); \
YYPOPSTACK (yylen); \
yystate = *yyssp; \
goto yybackup; \
} \
else \
{ \
yyerror (YY_("syntax error: cannot back up")); \
YYERROR; \
} \
while (0)
/* Error token number */
#define YYTERROR 1
#define YYERRCODE 256
/* Enable debugging if requested. */
#if YYDEBUG
# ifndef YYFPRINTF
# include <stdio.h> /* INFRINGES ON USER NAME SPACE */
# define YYFPRINTF fprintf
# endif
# define YYDPRINTF(Args) \
do { \
if (yydebug) \
YYFPRINTF Args; \
} while (0)
/* This macro is provided for backward compatibility. */
#ifndef YY_LOCATION_PRINT
# define YY_LOCATION_PRINT(File, Loc) ((void) 0)
#endif
# define YY_SYMBOL_PRINT(Title, Type, Value, Location) \
do { \
if (yydebug) \
{ \
YYFPRINTF (stderr, "%s ", Title); \
yy_symbol_print (stderr, \
Type, Value); \
YYFPRINTF (stderr, "\n"); \
} \
} while (0)
/*-----------------------------------.
| Print this symbol's value on YYO. |
`-----------------------------------*/
static void
yy_symbol_value_print (FILE *yyo, int yytype, YYSTYPE const * const yyvaluep)
{
FILE *yyoutput = yyo;
YYUSE (yyoutput);
if (!yyvaluep)
return;
# ifdef YYPRINT
if (yytype < YYNTOKENS)
YYPRINT (yyo, yytoknum[yytype], *yyvaluep);
# endif
YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN
YYUSE (yytype);
YY_IGNORE_MAYBE_UNINITIALIZED_END
}
/*---------------------------.
| Print this symbol on YYO. |
`---------------------------*/
static void
yy_symbol_print (FILE *yyo, int yytype, YYSTYPE const * const yyvaluep)
{
YYFPRINTF (yyo, "%s %s (",
yytype < YYNTOKENS ? "token" : "nterm", yytname[yytype]);
yy_symbol_value_print (yyo, yytype, yyvaluep);
YYFPRINTF (yyo, ")");
}
/*------------------------------------------------------------------.
| yy_stack_print -- Print the state stack from its BOTTOM up to its |
| TOP (included). |
`------------------------------------------------------------------*/
static void
yy_stack_print (yy_state_t *yybottom, yy_state_t *yytop)
{
YYFPRINTF (stderr, "Stack now");
for (; yybottom <= yytop; yybottom++)
{
int yybot = *yybottom;
YYFPRINTF (stderr, " %d", yybot);
}
YYFPRINTF (stderr, "\n");
}
# define YY_STACK_PRINT(Bottom, Top) \
do { \
if (yydebug) \
yy_stack_print ((Bottom), (Top)); \
} while (0)
/*------------------------------------------------.
| Report that the YYRULE is going to be reduced. |
`------------------------------------------------*/
static void
yy_reduce_print (yy_state_t *yyssp, YYSTYPE *yyvsp, int yyrule)
{
int yylno = yyrline[yyrule];
int yynrhs = yyr2[yyrule];
int yyi;
YYFPRINTF (stderr, "Reducing stack by rule %d (line %d):\n",
yyrule - 1, yylno);
/* The symbols being reduced. */
for (yyi = 0; yyi < yynrhs; yyi++)
{
YYFPRINTF (stderr, " $%d = ", yyi + 1);
yy_symbol_print (stderr,
yystos[+yyssp[yyi + 1 - yynrhs]],
&yyvsp[(yyi + 1) - (yynrhs)]
);
YYFPRINTF (stderr, "\n");
}
}
# define YY_REDUCE_PRINT(Rule) \
do { \
if (yydebug) \
yy_reduce_print (yyssp, yyvsp, Rule); \
} while (0)
/* Nonzero means print parse trace. It is left uninitialized so that
multiple parsers can coexist. */
int yydebug;
#else /* !YYDEBUG */
# define YYDPRINTF(Args)
# define YY_SYMBOL_PRINT(Title, Type, Value, Location)
# define YY_STACK_PRINT(Bottom, Top)
# define YY_REDUCE_PRINT(Rule)
#endif /* !YYDEBUG */
/* YYINITDEPTH -- initial size of the parser's stacks. */
#ifndef YYINITDEPTH
# define YYINITDEPTH 200
#endif
/* YYMAXDEPTH -- maximum size the stacks can grow to (effective only
if the built-in stack extension method is used).
Do not make this value too large; the results are undefined if
YYSTACK_ALLOC_MAXIMUM < YYSTACK_BYTES (YYMAXDEPTH)
evaluated with infinite-precision integer arithmetic. */
#ifndef YYMAXDEPTH
# define YYMAXDEPTH 10000
#endif
#if YYERROR_VERBOSE
# ifndef yystrlen
# if defined __GLIBC__ && defined _STRING_H
# define yystrlen(S) (YY_CAST (YYPTRDIFF_T, strlen (S)))
# else
/* Return the length of YYSTR. */
static YYPTRDIFF_T
yystrlen (const char *yystr)
{
YYPTRDIFF_T yylen;
for (yylen = 0; yystr[yylen]; yylen++)
continue;
return yylen;
}
# endif
# endif
# ifndef yystpcpy
# if defined __GLIBC__ && defined _STRING_H && defined _GNU_SOURCE
# define yystpcpy stpcpy
# else
/* Copy YYSRC to YYDEST, returning the address of the terminating '\0' in
YYDEST. */
static char *
yystpcpy (char *yydest, const char *yysrc)
{
char *yyd = yydest;
const char *yys = yysrc;
while ((*yyd++ = *yys++) != '\0')
continue;
return yyd - 1;
}
# endif
# endif
# ifndef yytnamerr
/* Copy to YYRES the contents of YYSTR after stripping away unnecessary
quotes and backslashes, so that it's suitable for yyerror. The
heuristic is that double-quoting is unnecessary unless the string
contains an apostrophe, a comma, or backslash (other than
backslash-backslash). YYSTR is taken from yytname. If YYRES is
null, do not copy; instead, return the length of what the result
would have been. */
static YYPTRDIFF_T
yytnamerr (char *yyres, const char *yystr)
{
if (*yystr == '"')
{
YYPTRDIFF_T yyn = 0;
char const *yyp = yystr;
for (;;)
switch (*++yyp)
{
case '\'':
case ',':
goto do_not_strip_quotes;
case '\\':
if (*++yyp != '\\')
goto do_not_strip_quotes;
else
goto append;
append:
default:
if (yyres)
yyres[yyn] = *yyp;
yyn++;
break;
case '"':
if (yyres)
yyres[yyn] = '\0';
return yyn;
}
do_not_strip_quotes: ;
}
if (yyres)
return yystpcpy (yyres, yystr) - yyres;
else
return yystrlen (yystr);
}
# endif
/* Copy into *YYMSG, which is of size *YYMSG_ALLOC, an error message
about the unexpected token YYTOKEN for the state stack whose top is
YYSSP.
Return 0 if *YYMSG was successfully written. Return 1 if *YYMSG is
not large enough to hold the message. In that case, also set
*YYMSG_ALLOC to the required number of bytes. Return 2 if the
required number of bytes is too large to store. */
static int
yysyntax_error (YYPTRDIFF_T *yymsg_alloc, char **yymsg,
yy_state_t *yyssp, int yytoken)
{
enum { YYERROR_VERBOSE_ARGS_MAXIMUM = 5 };
/* Internationalized format string. */
const char *yyformat = YY_NULLPTR;
/* Arguments of yyformat: reported tokens (one for the "unexpected",
one per "expected"). */
char const *yyarg[YYERROR_VERBOSE_ARGS_MAXIMUM];
/* Actual size of YYARG. */
int yycount = 0;
/* Cumulated lengths of YYARG. */
YYPTRDIFF_T yysize = 0;
/* There are many possibilities here to consider:
- If this state is a consistent state with a default action, then
the only way this function was invoked is if the default action
is an error action. In that case, don't check for expected
tokens because there are none.
- The only way there can be no lookahead present (in yychar) is if
this state is a consistent state with a default action. Thus,
detecting the absence of a lookahead is sufficient to determine
that there is no unexpected or expected token to report. In that
case, just report a simple "syntax error".
- Don't assume there isn't a lookahead just because this state is a
consistent state with a default action. There might have been a
previous inconsistent state, consistent state with a non-default
action, or user semantic action that manipulated yychar.
- Of course, the expected token list depends on states to have
correct lookahead information, and it depends on the parser not
to perform extra reductions after fetching a lookahead from the
scanner and before detecting a syntax error. Thus, state merging
(from LALR or IELR) and default reductions corrupt the expected
token list. However, the list is correct for canonical LR with
one exception: it will still contain any token that will not be
accepted due to an error action in a later state.
*/
if (yytoken != YYEMPTY)
{
int yyn = yypact[+*yyssp];
YYPTRDIFF_T yysize0 = yytnamerr (YY_NULLPTR, yytname[yytoken]);
yysize = yysize0;
yyarg[yycount++] = yytname[yytoken];
if (!yypact_value_is_default (yyn))
{
/* Start YYX at -YYN if negative to avoid negative indexes in
YYCHECK. In other words, skip the first -YYN actions for
this state because they are default actions. */
int yyxbegin = yyn < 0 ? -yyn : 0;
/* Stay within bounds of both yycheck and yytname. */
int yychecklim = YYLAST - yyn + 1;
int yyxend = yychecklim < YYNTOKENS ? yychecklim : YYNTOKENS;
int yyx;
for (yyx = yyxbegin; yyx < yyxend; ++yyx)
if (yycheck[yyx + yyn] == yyx && yyx != YYTERROR
&& !yytable_value_is_error (yytable[yyx + yyn]))
{
if (yycount == YYERROR_VERBOSE_ARGS_MAXIMUM)
{
yycount = 1;
yysize = yysize0;
break;
}
yyarg[yycount++] = yytname[yyx];
{
YYPTRDIFF_T yysize1
= yysize + yytnamerr (YY_NULLPTR, yytname[yyx]);
if (yysize <= yysize1 && yysize1 <= YYSTACK_ALLOC_MAXIMUM)
yysize = yysize1;
else
return 2;
}
}
}
}
switch (yycount)
{
# define YYCASE_(N, S) \
case N: \
yyformat = S; \
break
default: /* Avoid compiler warnings. */
YYCASE_(0, YY_("syntax error"));
YYCASE_(1, YY_("syntax error, unexpected %s"));
YYCASE_(2, YY_("syntax error, unexpected %s, expecting %s"));
YYCASE_(3, YY_("syntax error, unexpected %s, expecting %s or %s"));
YYCASE_(4, YY_("syntax error, unexpected %s, expecting %s or %s or %s"));
YYCASE_(5, YY_("syntax error, unexpected %s, expecting %s or %s or %s or %s"));
# undef YYCASE_
}
{
/* Don't count the "%s"s in the final size, but reserve room for
the terminator. */
YYPTRDIFF_T yysize1 = yysize + (yystrlen (yyformat) - 2 * yycount) + 1;
if (yysize <= yysize1 && yysize1 <= YYSTACK_ALLOC_MAXIMUM)
yysize = yysize1;
else
return 2;
}
if (*yymsg_alloc < yysize)
{
*yymsg_alloc = 2 * yysize;
if (! (yysize <= *yymsg_alloc
&& *yymsg_alloc <= YYSTACK_ALLOC_MAXIMUM))
*yymsg_alloc = YYSTACK_ALLOC_MAXIMUM;
return 1;
}
/* Avoid sprintf, as that infringes on the user's name space.
Don't have undefined behavior even if the translation
produced a string with the wrong number of "%s"s. */
{
char *yyp = *yymsg;
int yyi = 0;
while ((*yyp = *yyformat) != '\0')
if (*yyp == '%' && yyformat[1] == 's' && yyi < yycount)
{
yyp += yytnamerr (yyp, yyarg[yyi++]);
yyformat += 2;
}
else
{
++yyp;
++yyformat;
}
}
return 0;
}
#endif /* YYERROR_VERBOSE */
/*-----------------------------------------------.
| Release the memory associated to this symbol. |
`-----------------------------------------------*/
static void
yydestruct (const char *yymsg, int yytype, YYSTYPE *yyvaluep)
{
YYUSE (yyvaluep);
if (!yymsg)
yymsg = "Deleting";
YY_SYMBOL_PRINT (yymsg, yytype, yyvaluep, yylocationp);
YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN
YYUSE (yytype);
YY_IGNORE_MAYBE_UNINITIALIZED_END
}
/* The lookahead symbol. */
int yychar;
/* The semantic value of the lookahead symbol. */
YYSTYPE yylval;
/* Number of syntax errors so far. */
int yynerrs;
/*----------.
| yyparse. |
`----------*/
int
yyparse (void)
{
yy_state_fast_t yystate;
/* Number of tokens to shift before error messages enabled. */
int yyerrstatus;
/* The stacks and their tools:
'yyss': related to states.
'yyvs': related to semantic values.
Refer to the stacks through separate pointers, to allow yyoverflow
to reallocate them elsewhere. */
/* The state stack. */
yy_state_t yyssa[YYINITDEPTH];
yy_state_t *yyss;
yy_state_t *yyssp;
/* The semantic value stack. */
YYSTYPE yyvsa[YYINITDEPTH];
YYSTYPE *yyvs;
YYSTYPE *yyvsp;
YYPTRDIFF_T yystacksize;
int yyn;
int yyresult;
/* Lookahead token as an internal (translated) token number. */
int yytoken = 0;
/* The variables used to return semantic value and location from the
action routines. */
YYSTYPE yyval;
#if YYERROR_VERBOSE
/* Buffer for error messages, and its allocated size. */
char yymsgbuf[128];
char *yymsg = yymsgbuf;
YYPTRDIFF_T yymsg_alloc = sizeof yymsgbuf;
#endif
#define YYPOPSTACK(N) (yyvsp -= (N), yyssp -= (N))
/* The number of symbols on the RHS of the reduced rule.
Keep to zero when no symbol should be popped. */
int yylen = 0;
yyssp = yyss = yyssa;
yyvsp = yyvs = yyvsa;
yystacksize = YYINITDEPTH;
YYDPRINTF ((stderr, "Starting parse\n"));
yystate = 0;
yyerrstatus = 0;
yynerrs = 0;
yychar = YYEMPTY; /* Cause a token to be read. */
goto yysetstate;
/*------------------------------------------------------------.
| yynewstate -- push a new state, which is found in yystate. |
`------------------------------------------------------------*/
yynewstate:
/* In all cases, when you get here, the value and location stacks
have just been pushed. So pushing a state here evens the stacks. */
yyssp++;
/*--------------------------------------------------------------------.
| yysetstate -- set current state (the top of the stack) to yystate. |
`--------------------------------------------------------------------*/
yysetstate:
YYDPRINTF ((stderr, "Entering state %d\n", yystate));
YY_ASSERT (0 <= yystate && yystate < YYNSTATES);
YY_IGNORE_USELESS_CAST_BEGIN
*yyssp = YY_CAST (yy_state_t, yystate);
YY_IGNORE_USELESS_CAST_END
if (yyss + yystacksize - 1 <= yyssp)
#if !defined yyoverflow && !defined YYSTACK_RELOCATE
goto yyexhaustedlab;
#else
{
/* Get the current used size of the three stacks, in elements. */
YYPTRDIFF_T yysize = yyssp - yyss + 1;
# if defined yyoverflow
{
/* Give user a chance to reallocate the stack. Use copies of
these so that the &'s don't force the real ones into
memory. */
yy_state_t *yyss1 = yyss;
YYSTYPE *yyvs1 = yyvs;
/* Each stack pointer address is followed by the size of the
data in use in that stack, in bytes. This used to be a
conditional around just the two extra args, but that might
be undefined if yyoverflow is a macro. */
yyoverflow (YY_("memory exhausted"),
&yyss1, yysize * YYSIZEOF (*yyssp),
&yyvs1, yysize * YYSIZEOF (*yyvsp),
&yystacksize);
yyss = yyss1;
yyvs = yyvs1;
}
# else /* defined YYSTACK_RELOCATE */
/* Extend the stack our own way. */
if (YYMAXDEPTH <= yystacksize)
goto yyexhaustedlab;
yystacksize *= 2;
if (YYMAXDEPTH < yystacksize)
yystacksize = YYMAXDEPTH;
{
yy_state_t *yyss1 = yyss;
union yyalloc *yyptr =
YY_CAST (union yyalloc *,
YYSTACK_ALLOC (YY_CAST (YYSIZE_T, YYSTACK_BYTES (yystacksize))));
if (! yyptr)
goto yyexhaustedlab;
YYSTACK_RELOCATE (yyss_alloc, yyss);
YYSTACK_RELOCATE (yyvs_alloc, yyvs);
# undef YYSTACK_RELOCATE
if (yyss1 != yyssa)
YYSTACK_FREE (yyss1);
}
# endif
yyssp = yyss + yysize - 1;
yyvsp = yyvs + yysize - 1;
YY_IGNORE_USELESS_CAST_BEGIN
YYDPRINTF ((stderr, "Stack size increased to %ld\n",
YY_CAST (long, yystacksize)));
YY_IGNORE_USELESS_CAST_END
if (yyss + yystacksize - 1 <= yyssp)
YYABORT;
}
#endif /* !defined yyoverflow && !defined YYSTACK_RELOCATE */
if (yystate == YYFINAL)
YYACCEPT;
goto yybackup;
/*-----------.
| yybackup. |
`-----------*/
yybackup:
/* Do appropriate processing given the current state. Read a
lookahead token if we need one and don't already have one. */
/* First try to decide what to do without reference to lookahead token. */
yyn = yypact[yystate];
if (yypact_value_is_default (yyn))
goto yydefault;
/* Not known => get a lookahead token if don't already have one. */
/* YYCHAR is either YYEMPTY or YYEOF or a valid lookahead symbol. */
if (yychar == YYEMPTY)
{
YYDPRINTF ((stderr, "Reading a token: "));
yychar = yylex ();
}
if (yychar <= YYEOF)
{
yychar = yytoken = YYEOF;
YYDPRINTF ((stderr, "Now at end of input.\n"));
}
else
{
yytoken = YYTRANSLATE (yychar);
YY_SYMBOL_PRINT ("Next token is", yytoken, &yylval, &yylloc);
}
/* If the proper action on seeing token YYTOKEN is to reduce or to
detect an error, take that action. */
yyn += yytoken;
if (yyn < 0 || YYLAST < yyn || yycheck[yyn] != yytoken)
goto yydefault;
yyn = yytable[yyn];
if (yyn <= 0)
{
if (yytable_value_is_error (yyn))
goto yyerrlab;
yyn = -yyn;
goto yyreduce;
}
/* Count tokens shifted since error; after three, turn off error
status. */
if (yyerrstatus)
yyerrstatus--;
/* Shift the lookahead token. */
YY_SYMBOL_PRINT ("Shifting", yytoken, &yylval, &yylloc);
yystate = yyn;
YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN
*++yyvsp = yylval;
YY_IGNORE_MAYBE_UNINITIALIZED_END
/* Discard the shifted token. */
yychar = YYEMPTY;
goto yynewstate;
/*-----------------------------------------------------------.
| yydefault -- do the default action for the current state. |
`-----------------------------------------------------------*/
yydefault:
yyn = yydefact[yystate];
if (yyn == 0)
goto yyerrlab;
goto yyreduce;
/*-----------------------------.
| yyreduce -- do a reduction. |
`-----------------------------*/
yyreduce:
/* yyn is the number of a rule to reduce with. */
yylen = yyr2[yyn];
/* If YYLEN is nonzero, implement the default value of the action:
'$$ = $1'.
Otherwise, the following line sets YYVAL to garbage.
This behavior is undocumented and Bison
users should not rely upon it. Assigning to YYVAL
unconditionally makes the parser a bit smaller, and it avoids a
GCC warning that YYVAL may be used uninitialized. */
yyval = yyvsp[1-yylen];
YY_REDUCE_PRINT (yyn);
switch (yyn)
{
case 2:
#line 232 "awkgram.y"
{ yyval = NULL; }
#line 2007 "awkgram.c"
break;
case 3:
#line 234 "awkgram.y"
{
rule = 0;
yyerrok;
}
#line 2016 "awkgram.c"
break;
case 4:
#line 239 "awkgram.y"
{
if (yyvsp[0] != NULL) {
if (yyvsp[-1] == NULL)
outer_comment = yyvsp[0];
else
interblock_comment = yyvsp[0];
}
yyval = yyvsp[-1];
}
#line 2030 "awkgram.c"
break;
case 5:
#line 249 "awkgram.y"
{
next_sourcefile();
}
#line 2038 "awkgram.c"
break;
case 6:
#line 253 "awkgram.y"
{
rule = 0;
/*
* If errors, give up, don't produce an infinite
* stream of syntax error messages.
*/
/* yyerrok; */
}
#line 2051 "awkgram.c"
break;
case 7:
#line 265 "awkgram.y"
{
(void) append_rule(yyvsp[-1], yyvsp[0]);
if (pending_comment != NULL) {
interblock_comment = pending_comment;
pending_comment = NULL;
}
}
#line 2063 "awkgram.c"
break;
case 8:
#line 273 "awkgram.y"
{
if (rule != Rule) {
msg(_("%s blocks must have an action part"), ruletab[rule]);
errcount++;
} else if (yyvsp[-1] == NULL) {
msg(_("each rule must have a pattern or an action part"));
errcount++;
} else { /* pattern rule with non-empty pattern */
if (yyvsp[0] != NULL)
list_append(yyvsp[-1], yyvsp[0]);
(void) append_rule(yyvsp[-1], NULL);
}
}
#line 2081 "awkgram.c"
break;
case 9:
#line 287 "awkgram.y"
{
in_function = false;
(void) mk_function(yyvsp[-1], yyvsp[0]);
want_param_names = DONT_CHECK;
if (pending_comment != NULL) {
interblock_comment = pending_comment;
pending_comment = NULL;
}
yyerrok;
}
#line 2096 "awkgram.c"
break;
case 10:
#line 298 "awkgram.y"
{
want_source = false;
at_seen = false;
if (yyvsp[-1] != NULL && yyvsp[0] != NULL) {
SRCFILE *s = (SRCFILE *) yyvsp[-1];
s->comment = yyvsp[0];
}
yyerrok;
}
#line 2110 "awkgram.c"
break;
case 11:
#line 308 "awkgram.y"
{
want_source = false;
at_seen = false;
if (yyvsp[-1] != NULL && yyvsp[0] != NULL) {
SRCFILE *s = (SRCFILE *) yyvsp[-1];
s->comment = yyvsp[0];
}
yyerrok;
}
#line 2124 "awkgram.c"
break;
case 12:
#line 318 "awkgram.y"
{
want_source = false;
at_seen = false;
// this frees $3 storage in all cases
set_namespace(yyvsp[-1], yyvsp[0]);
yyerrok;
}
#line 2138 "awkgram.c"
break;
case 13:
#line 331 "awkgram.y"
{
void *srcfile = NULL;
if (! include_source(yyvsp[0], & srcfile))
YYABORT;
efree(yyvsp[0]->lextok);
bcfree(yyvsp[0]);
yyval = (INSTRUCTION *) srcfile;
}
#line 2152 "awkgram.c"
break;
case 14:
#line 341 "awkgram.y"
{ yyval = NULL; }
#line 2158 "awkgram.c"
break;
case 15:
#line 343 "awkgram.y"
{ yyval = NULL; }
#line 2164 "awkgram.c"
break;
case 16:
#line 348 "awkgram.y"
{
void *srcfile;
if (! load_library(yyvsp[0], & srcfile))
YYABORT;
efree(yyvsp[0]->lextok);
bcfree(yyvsp[0]);
yyval = (INSTRUCTION *) srcfile;
}
#line 2178 "awkgram.c"
break;
case 17:
#line 358 "awkgram.y"
{ yyval = NULL; }
#line 2184 "awkgram.c"
break;
case 18:
#line 360 "awkgram.y"
{ yyval = NULL; }
#line 2190 "awkgram.c"
break;
case 19:
#line 365 "awkgram.y"
{ yyval = yyvsp[0]; }
#line 2196 "awkgram.c"
break;
case 20:
#line 367 "awkgram.y"
{ yyval = NULL; }
#line 2202 "awkgram.c"
break;
case 21:
#line 369 "awkgram.y"
{ yyval = NULL; }
#line 2208 "awkgram.c"
break;
case 22:
#line 374 "awkgram.y"
{
rule = Rule;
yyval = NULL;
}
#line 2217 "awkgram.c"
break;
case 23:
#line 379 "awkgram.y"
{
rule = Rule;
}
#line 2225 "awkgram.c"
break;
case 24:
#line 384 "awkgram.y"
{
INSTRUCTION *tp;
add_lint(yyvsp[-2], LINT_assign_in_cond);
add_lint(yyvsp[0], LINT_assign_in_cond);
tp = instruction(Op_no_op);
list_prepend(yyvsp[-2], bcalloc(Op_line_range, !!do_pretty_print + 1, 0));
yyvsp[-2]->nexti->triggered = false;
yyvsp[-2]->nexti->target_jmp = yyvsp[0]->nexti;
list_append(yyvsp[-2], instruction(Op_cond_pair));
yyvsp[-2]->lasti->line_range = yyvsp[-2]->nexti;
yyvsp[-2]->lasti->target_jmp = tp;
list_append(yyvsp[0], instruction(Op_cond_pair));
yyvsp[0]->lasti->line_range = yyvsp[-2]->nexti;
yyvsp[0]->lasti->target_jmp = tp;
if (do_pretty_print) {
(yyvsp[-2]->nexti + 1)->condpair_left = yyvsp[-2]->lasti;
(yyvsp[-2]->nexti + 1)->condpair_right = yyvsp[0]->lasti;
}
/* Put any comments in front of the range expression */
if (yyvsp[-1] != NULL)
yyval = list_append(list_merge(list_prepend(yyvsp[-2], yyvsp[-1]), yyvsp[0]), tp);
else
yyval = list_append(list_merge(yyvsp[-2], yyvsp[0]), tp);
rule = Rule;
}
#line 2259 "awkgram.c"
break;
case 25:
#line 414 "awkgram.y"
{
static int begin_seen = 0;
if (do_lint_old && ++begin_seen == 2)
lintwarn_ln(yyvsp[0]->source_line,
_("old awk does not support multiple `BEGIN' or `END' rules"));
yyvsp[0]->in_rule = rule = BEGIN;
yyvsp[0]->source_file = source;
yyval = yyvsp[0];
}
#line 2275 "awkgram.c"
break;
case 26:
#line 426 "awkgram.y"
{
static int end_seen = 0;
if (do_lint_old && ++end_seen == 2)
lintwarn_ln(yyvsp[0]->source_line,
_("old awk does not support multiple `BEGIN' or `END' rules"));
yyvsp[0]->in_rule = rule = END;
yyvsp[0]->source_file = source;
yyval = yyvsp[0];
}
#line 2291 "awkgram.c"
break;
case 27:
#line 438 "awkgram.y"
{
yyvsp[0]->in_rule = rule = BEGINFILE;
yyvsp[0]->source_file = source;
yyval = yyvsp[0];
}
#line 2301 "awkgram.c"
break;
case 28:
#line 444 "awkgram.y"
{
yyvsp[0]->in_rule = rule = ENDFILE;
yyvsp[0]->source_file = source;
yyval = yyvsp[0];
}
#line 2311 "awkgram.c"
break;
case 29:
#line 453 "awkgram.y"
{
INSTRUCTION *ip = make_braced_statements(yyvsp[-4], yyvsp[-3], yyvsp[-2]);
if (yyvsp[-2] != NULL && yyvsp[0] != NULL) {
merge_comments(yyvsp[-2], yyvsp[0]);
pending_comment = yyvsp[-2];
} else if (yyvsp[-2] != NULL) {
pending_comment = yyvsp[-2];
} else if (yyvsp[0] != NULL) {
pending_comment = yyvsp[0];
}
yyval = ip;
}
#line 2330 "awkgram.c"
break;
case 31:
#line 472 "awkgram.y"
{
const char *name = yyvsp[0]->lextok;
char *qname = qualify_name(name, strlen(name));
if (qname != name) {
efree((void *)name);
yyvsp[0]->lextok = qname;
}
yyval = yyvsp[0];
}
#line 2345 "awkgram.c"
break;
case 32:
#line 483 "awkgram.y"
{
yyerror(_("`%s' is a built-in function, it cannot be redefined"),
tokstart);
YYABORT;
}
#line 2355 "awkgram.c"
break;
case 33:
#line 489 "awkgram.y"
{
yyval = yyvsp[0];
at_seen = false;
}
#line 2364 "awkgram.c"
break;
case 36:
#line 501 "awkgram.y"
{ want_param_names = FUNC_HEADER; }
#line 2370 "awkgram.c"
break;
case 37:
#line 502 "awkgram.y"
{
INSTRUCTION *func_comment = NULL;
// Merge any comments found in the parameter list with those
// following the function header, associate the whole shebang
// with the function as one block comment.
if (yyvsp[-2] != NULL && yyvsp[-2]->comment != NULL) {
if (yyvsp[0] != NULL) {
merge_comments(yyvsp[-2]->comment, yyvsp[0]);
}
func_comment = yyvsp[-2]->comment;
} else if (yyvsp[0] != NULL) {
func_comment = yyvsp[0];
}
yyvsp[-6]->source_file = source;
yyvsp[-6]->comment = func_comment;
if (install_function(yyvsp[-5]->lextok, yyvsp[-6], yyvsp[-2]) < 0)
YYABORT;
in_function = true;
yyvsp[-5]->lextok = NULL;
bcfree(yyvsp[-5]);
/* $5 already free'd in install_function */
yyval = yyvsp[-6];
want_param_names = FUNC_BODY;
}
#line 2400 "awkgram.c"
break;
case 38:
#line 535 "awkgram.y"
{ want_regexp = true; }
#line 2406 "awkgram.c"
break;
case 39:
#line 537 "awkgram.y"
{
NODE *n, *exp;
char *re;
size_t len;
re = yyvsp[0]->lextok;
yyvsp[0]->lextok = NULL;
len = strlen(re);
if (do_lint) {
if (len == 0)
lintwarn_ln(yyvsp[0]->source_line,
_("regexp constant `//' looks like a C++ comment, but is not"));
else if (re[0] == '*' && re[len-1] == '*')
/* possible C comment */
lintwarn_ln(yyvsp[0]->source_line,
_("regexp constant `/%s/' looks like a C comment, but is not"), re);
}
exp = make_str_node(re, len, ALREADY_MALLOCED);
n = make_regnode(Node_regex, exp);
if (n == NULL) {
unref(exp);
YYABORT;
}
yyval = yyvsp[0];
yyval->opcode = Op_match_rec;
yyval->memory = n;
}
#line 2439 "awkgram.c"
break;
case 40:
#line 569 "awkgram.y"
{
char *re;
size_t len;
re = yyvsp[0]->lextok;
yyvsp[0]->lextok = NULL;
len = strlen(re);
yyval = yyvsp[0];
yyval->opcode = Op_push_re;
yyval->memory = make_typed_regex(re, len);
}
#line 2456 "awkgram.c"
break;
case 41:
#line 584 "awkgram.y"
{ bcfree(yyvsp[0]); }
#line 2462 "awkgram.c"
break;
case 43:
#line 590 "awkgram.y"
{ yyval = NULL; }
#line 2468 "awkgram.c"
break;
case 44:
#line 592 "awkgram.y"
{
if (yyvsp[0] == NULL) {
yyval = yyvsp[-1];
} else {
add_lint(yyvsp[0], LINT_no_effect);
if (yyvsp[-1] == NULL) {
yyval = yyvsp[0];
} else {
yyval = list_merge(yyvsp[-1], yyvsp[0]);
}
}
if (trailing_comment != NULL) {
yyval = list_append(yyval, trailing_comment);
trailing_comment = NULL;
}
yyerrok;
}
#line 2492 "awkgram.c"
break;
case 45:
#line 612 "awkgram.y"
{ yyval = NULL; }
#line 2498 "awkgram.c"
break;
case 46:
#line 616 "awkgram.y"
{ yyval = yyvsp[0]; }
#line 2504 "awkgram.c"
break;
case 47:
#line 617 "awkgram.y"
{ yyval = yyvsp[0]; }
#line 2510 "awkgram.c"
break;
case 48:
#line 622 "awkgram.y"
{
if (yyvsp[0] != NULL) {
INSTRUCTION *ip;
merge_comments(yyvsp[0], NULL);
ip = list_create(instruction(Op_no_op));
yyval = list_append(ip, yyvsp[0]);
} else
yyval = NULL;
}
#line 2525 "awkgram.c"
break;
case 49:
#line 633 "awkgram.y"
{
trailing_comment = yyvsp[0]; // NULL or comment
yyval = make_braced_statements(yyvsp[-2], yyvsp[-1], yyvsp[0]);
}
#line 2534 "awkgram.c"
break;
case 50:
#line 638 "awkgram.y"
{
if (do_pretty_print)
yyval = list_prepend(yyvsp[0], instruction(Op_exec_count));
else
yyval = yyvsp[0];
}
#line 2545 "awkgram.c"
break;
case 51:
#line 645 "awkgram.y"
{
INSTRUCTION *dflt, *curr = NULL, *cexp, *cstmt;
INSTRUCTION *ip, *nextc, *tbreak;
const char **case_values = NULL;
int maxcount = 128;
int case_count = 0;
int i;
tbreak = instruction(Op_no_op);
cstmt = list_create(tbreak);
cexp = list_create(instruction(Op_pop));
dflt = instruction(Op_jmp);
dflt->target_jmp = tbreak; /* if no case match and no explicit default */
if (yyvsp[-2] != NULL) {
curr = yyvsp[-2]->nexti;
bcfree(yyvsp[-2]); /* Op_list */
}
/* else
curr = NULL; */
for (; curr != NULL; curr = nextc) {
INSTRUCTION *caseexp = curr->case_exp;
INSTRUCTION *casestmt = curr->case_stmt;
nextc = curr->nexti;
if (curr->opcode == Op_K_case) {
if (caseexp->opcode == Op_push_i) {
/* a constant scalar */
char *caseval;
caseval = force_string(caseexp->memory)->stptr;
for (i = 0; i < case_count; i++) {
if (strcmp(caseval, case_values[i]) == 0)
error_ln(curr->source_line,
_("duplicate case values in switch body: %s"), caseval);
}
if (case_values == NULL)
emalloc(case_values, const char **, sizeof(char *) * maxcount, "statement");
else if (case_count >= maxcount) {
maxcount += 128;
erealloc(case_values, const char **, sizeof(char*) * maxcount, "statement");
}
case_values[case_count++] = caseval;
} else {
/* match a constant regex against switch expression. */
(curr + 1)->match_exp = true;
}
curr->stmt_start = casestmt->nexti;
curr->stmt_end = casestmt->lasti;
(void) list_prepend(cexp, curr);
(void) list_prepend(cexp, caseexp);
} else {
if (dflt->target_jmp != tbreak)
error_ln(curr->source_line,
_("duplicate `default' detected in switch body"));
else
dflt->target_jmp = casestmt->nexti;
if (do_pretty_print) {
curr->stmt_start = casestmt->nexti;
curr->stmt_end = casestmt->lasti;
(void) list_prepend(cexp, curr);
} else
bcfree(curr);
}
cstmt = list_merge(casestmt, cstmt);
}
if (case_values != NULL)
efree(case_values);
ip = yyvsp[-6];
if (do_pretty_print) {
// first merge comments
INSTRUCTION *head_comment = NULL;
if (yyvsp[-4] != NULL && yyvsp[-3] != NULL) {
merge_comments(yyvsp[-4], yyvsp[-3]);
head_comment = yyvsp[-4];
} else if (yyvsp[-4] != NULL)
head_comment = yyvsp[-4];
else
head_comment = yyvsp[-3];
yyvsp[-8]->comment = head_comment;
(void) list_prepend(ip, yyvsp[-8]);
(void) list_prepend(ip, instruction(Op_exec_count));
yyvsp[-8]->target_break = tbreak;
(yyvsp[-8] + 1)->switch_start = cexp->nexti;
(yyvsp[-8] + 1)->switch_end = cexp->lasti;
(yyvsp[-8] + 1)->switch_end->comment = yyvsp[0];
}
/* else
$1 is NULL */
(void) list_append(cexp, dflt);
(void) list_merge(ip, cexp);
if (yyvsp[-1] != NULL)
(void) list_append(cstmt, yyvsp[-1]);
yyval = list_merge(ip, cstmt);
break_allowed--;
fix_break_continue(ip, tbreak, NULL);
}
#line 2657 "awkgram.c"
break;
case 52:
#line 753 "awkgram.y"
{
/*
* -----------------
* tc:
* cond
* -----------------
* [Op_jmp_false tb ]
* -----------------
* body
* -----------------
* [Op_jmp tc ]
* tb:[Op_no_op ]
*/
INSTRUCTION *ip, *tbreak, *tcont;
tbreak = instruction(Op_no_op);
add_lint(yyvsp[-3], LINT_assign_in_cond);
tcont = yyvsp[-3]->nexti;
ip = list_append(yyvsp[-3], instruction(Op_jmp_false));
ip->lasti->target_jmp = tbreak;
if (do_pretty_print) {
(void) list_append(ip, instruction(Op_exec_count));
yyvsp[-5]->target_break = tbreak;
yyvsp[-5]->target_continue = tcont;
(yyvsp[-5] + 1)->while_body = ip->lasti;
(void) list_prepend(ip, yyvsp[-5]);
}
/* else
$1 is NULL */
if (yyvsp[-1] != NULL) {
if (yyvsp[0] == NULL)
yyvsp[0] = list_create(instruction(Op_no_op));
yyvsp[-1]->memory->comment_type = BLOCK_COMMENT;
yyvsp[0] = list_prepend(yyvsp[0], yyvsp[-1]);
}
if (yyvsp[0] != NULL)
(void) list_merge(ip, yyvsp[0]);
(void) list_append(ip, instruction(Op_jmp));
ip->lasti->target_jmp = tcont;
yyval = list_append(ip, tbreak);
break_allowed--;
continue_allowed--;
fix_break_continue(ip, tbreak, tcont);
}
#line 2712 "awkgram.c"
break;
case 53:
#line 804 "awkgram.y"
{
/*
* -----------------
* z:
* body
* -----------------
* tc:
* cond
* -----------------
* [Op_jmp_true | z ]
* tb:[Op_no_op ]
*/
INSTRUCTION *ip, *tbreak, *tcont;
tbreak = instruction(Op_no_op);
tcont = yyvsp[-2]->nexti;
add_lint(yyvsp[-2], LINT_assign_in_cond);
if (yyvsp[-5] != NULL)
ip = list_merge(yyvsp[-5], yyvsp[-2]);
else
ip = list_prepend(yyvsp[-2], instruction(Op_no_op));
if (yyvsp[-6] != NULL)
(void) list_prepend(ip, yyvsp[-6]);
if (do_pretty_print)
(void) list_prepend(ip, instruction(Op_exec_count));
(void) list_append(ip, instruction(Op_jmp_true));
ip->lasti->target_jmp = ip->nexti;
yyval = list_append(ip, tbreak);
break_allowed--;
continue_allowed--;
fix_break_continue(ip, tbreak, tcont);
if (do_pretty_print) {
yyvsp[-7]->target_break = tbreak;
yyvsp[-7]->target_continue = tcont;
(yyvsp[-7] + 1)->doloop_cond = tcont;
yyval = list_prepend(ip, yyvsp[-7]);
bcfree(yyvsp[-4]);
if (yyvsp[0] != NULL)
yyvsp[-7]->comment = yyvsp[0];
}
/* else
$1 and $4 are NULLs */
}
#line 2766 "awkgram.c"
break;
case 54:
#line 854 "awkgram.y"
{
INSTRUCTION *ip;
char *var_name = yyvsp[-5]->lextok;
if (yyvsp[0] != NULL
&& yyvsp[0]->lasti->opcode == Op_K_delete
&& yyvsp[0]->lasti->expr_count == 1
&& yyvsp[0]->nexti->opcode == Op_push
&& (yyvsp[0]->nexti->memory->type != Node_var || !(yyvsp[0]->nexti->memory->var_update))
&& strcmp(yyvsp[0]->nexti->memory->vname, var_name) == 0
) {
/*
* Efficiency hack. Recognize the special case of
*
* for (iggy in foo)
* delete foo[iggy]
*
* and treat it as if it were
*
* delete foo
*
* Check that the body is a `delete a[i]' statement,
* and that both the loop var and array names match.
*/
NODE *arr = NULL;
ip = yyvsp[0]->nexti->nexti;
if (yyvsp[-3]->nexti->opcode == Op_push && yyvsp[-3]->lasti == yyvsp[-3]->nexti)
arr = yyvsp[-3]->nexti->memory;
if (arr != NULL
&& ip->opcode == Op_no_op
&& ip->nexti->opcode == Op_push_array
&& strcmp(ip->nexti->memory->vname, arr->vname) == 0
&& ip->nexti->nexti == yyvsp[0]->lasti
) {
(void) make_assignable(yyvsp[0]->nexti);
yyvsp[0]->lasti->opcode = Op_K_delete_loop;
yyvsp[0]->lasti->expr_count = 0;
if (yyvsp[-7] != NULL)
bcfree(yyvsp[-7]);
efree(var_name);
bcfree(yyvsp[-5]);
bcfree(yyvsp[-4]);
bcfree(yyvsp[-3]);
if (yyvsp[-1] != NULL) {
merge_comments(yyvsp[-1], NULL);
yyvsp[0] = list_prepend(yyvsp[0], yyvsp[-1]);
}
yyval = yyvsp[0];
} else
goto regular_loop;
} else {
INSTRUCTION *tbreak, *tcont;
/* [ Op_push_array a ]
* [ Op_arrayfor_init | ib ]
* ic:[ Op_arrayfor_incr | ib ]
* [ Op_var_assign if any ]
*
* body
*
* [Op_jmp | ic ]
* ib:[Op_arrayfor_final ]
*/
regular_loop:
ip = yyvsp[-3];
ip->nexti->opcode = Op_push_array;
tbreak = instruction(Op_arrayfor_final);
yyvsp[-4]->opcode = Op_arrayfor_incr;
yyvsp[-4]->array_var = variable(yyvsp[-5]->source_line, var_name, Node_var);
yyvsp[-4]->target_jmp = tbreak;
tcont = yyvsp[-4];
yyvsp[-5]->opcode = Op_arrayfor_init;
yyvsp[-5]->target_jmp = tbreak;
(void) list_append(ip, yyvsp[-5]);
if (do_pretty_print) {
yyvsp[-7]->opcode = Op_K_arrayfor;
yyvsp[-7]->target_continue = tcont;
yyvsp[-7]->target_break = tbreak;
(void) list_append(ip, yyvsp[-7]);
}
/* else
$1 is NULL */
/* add update_FOO instruction if necessary */
if (yyvsp[-4]->array_var->type == Node_var && yyvsp[-4]->array_var->var_update) {
(void) list_append(ip, instruction(Op_var_update));
ip->lasti->update_var = yyvsp[-4]->array_var->var_update;
}
(void) list_append(ip, yyvsp[-4]);
/* add set_FOO instruction if necessary */
if (yyvsp[-4]->array_var->type == Node_var && yyvsp[-4]->array_var->var_assign) {
(void) list_append(ip, instruction(Op_var_assign));
ip->lasti->assign_var = yyvsp[-4]->array_var->var_assign;
}
if (do_pretty_print) {
(void) list_append(ip, instruction(Op_exec_count));
(yyvsp[-7] + 1)->forloop_cond = yyvsp[-4];
(yyvsp[-7] + 1)->forloop_body = ip->lasti;
}
if (yyvsp[-1] != NULL)
merge_comments(yyvsp[-1], NULL);
if (yyvsp[0] != NULL) {
if (yyvsp[-1] != NULL)
yyvsp[0] = list_prepend(yyvsp[0], yyvsp[-1]);
(void) list_merge(ip, yyvsp[0]);
} else if (yyvsp[-1] != NULL)
(void) list_append(ip, yyvsp[-1]);
(void) list_append(ip, instruction(Op_jmp));
ip->lasti->target_jmp = yyvsp[-4];
yyval = list_append(ip, tbreak);
fix_break_continue(ip, tbreak, tcont);
}
break_allowed--;
continue_allowed--;
}
#line 2896 "awkgram.c"
break;
case 55:
#line 980 "awkgram.y"
{
if (yyvsp[-7] != NULL) {
merge_comments(yyvsp[-7], NULL);
yyvsp[-11]->comment = yyvsp[-7];
}
if (yyvsp[-4] != NULL) {
merge_comments(yyvsp[-4], NULL);
if (yyvsp[-11]->comment == NULL) {
yyvsp[-4]->memory->comment_type = FOR_COMMENT;
yyvsp[-11]->comment = yyvsp[-4];
} else
yyvsp[-11]->comment->comment = yyvsp[-4];
}
if (yyvsp[-1] != NULL)
yyvsp[0] = list_prepend(yyvsp[0], yyvsp[-1]);
add_lint(yyvsp[-6], LINT_assign_in_cond);
yyval = mk_for_loop(yyvsp[-11], yyvsp[-9], yyvsp[-6], yyvsp[-3], yyvsp[0]);
break_allowed--;
continue_allowed--;
}
#line 2922 "awkgram.c"
break;
case 56:
#line 1002 "awkgram.y"
{
if (yyvsp[-6] != NULL) {
merge_comments(yyvsp[-6], NULL);
yyvsp[-10]->comment = yyvsp[-6];
}
if (yyvsp[-4] != NULL) {
merge_comments(yyvsp[-4], NULL);
if (yyvsp[-10]->comment == NULL) {
yyvsp[-4]->memory->comment_type = FOR_COMMENT;
yyvsp[-10]->comment = yyvsp[-4];
} else
yyvsp[-10]->comment->comment = yyvsp[-4];
}
if (yyvsp[-1] != NULL)
yyvsp[0] = list_prepend(yyvsp[0], yyvsp[-1]);
yyval = mk_for_loop(yyvsp[-10], yyvsp[-8], (INSTRUCTION *) NULL, yyvsp[-3], yyvsp[0]);
break_allowed--;
continue_allowed--;
}
#line 2947 "awkgram.c"
break;
case 57:
#line 1023 "awkgram.y"
{
if (do_pretty_print)
yyval = list_prepend(yyvsp[0], instruction(Op_exec_count));
else
yyval = yyvsp[0];
}
#line 2958 "awkgram.c"
break;
case 58:
#line 1033 "awkgram.y"
{
if (! break_allowed)
error_ln(yyvsp[-1]->source_line,
_("`break' is not allowed outside a loop or switch"));
yyvsp[-1]->target_jmp = NULL;
yyval = list_create(yyvsp[-1]);
if (yyvsp[0] != NULL)
yyval = list_append(yyval, yyvsp[0]);
}
#line 2972 "awkgram.c"
break;
case 59:
#line 1043 "awkgram.y"
{
if (! continue_allowed)
error_ln(yyvsp[-1]->source_line,
_("`continue' is not allowed outside a loop"));
yyvsp[-1]->target_jmp = NULL;
yyval = list_create(yyvsp[-1]);
if (yyvsp[0] != NULL)
yyval = list_append(yyval, yyvsp[0]);
}
#line 2986 "awkgram.c"
break;
case 60:
#line 1053 "awkgram.y"
{
/* if inside function (rule = 0), resolve context at run-time */
if (rule && rule != Rule)
error_ln(yyvsp[-1]->source_line,
_("`next' used in %s action"), ruletab[rule]);
yyvsp[-1]->target_jmp = ip_rec;
yyval = list_create(yyvsp[-1]);
if (yyvsp[0] != NULL)
yyval = list_append(yyval, yyvsp[0]);
}
#line 3001 "awkgram.c"
break;
case 61:
#line 1064 "awkgram.y"
{
/* if inside function (rule = 0), resolve context at run-time */
if (rule == BEGIN || rule == END || rule == ENDFILE)
error_ln(yyvsp[-1]->source_line,
_("`nextfile' used in %s action"), ruletab[rule]);
yyvsp[-1]->target_newfile = ip_newfile;
yyvsp[-1]->target_endfile = ip_endfile;
yyval = list_create(yyvsp[-1]);
if (yyvsp[0] != NULL)
yyval = list_append(yyval, yyvsp[0]);
}
#line 3018 "awkgram.c"
break;
case 62:
#line 1077 "awkgram.y"
{
/* Initialize the two possible jump targets, the actual target
* is resolved at run-time.
*/
yyvsp[-2]->target_end = ip_end; /* first instruction in end_block */
yyvsp[-2]->target_atexit = ip_atexit; /* cleanup and go home */
if (yyvsp[-1] == NULL) {
yyval = list_create(yyvsp[-2]);
(void) list_prepend(yyval, instruction(Op_push_i));
yyval->nexti->memory = dupnode(Nnull_string);
} else
yyval = list_append(yyvsp[-1], yyvsp[-2]);
if (yyvsp[0] != NULL)
yyval = list_append(yyval, yyvsp[0]);
}
#line 3039 "awkgram.c"
break;
case 63:
#line 1094 "awkgram.y"
{
if (! in_function)
yyerror(_("`return' used outside function context"));
}
#line 3048 "awkgram.c"
break;
case 64:
#line 1097 "awkgram.y"
{
if (called_from_eval)
yyvsp[-3]->opcode = Op_K_return_from_eval;
if (yyvsp[-1] == NULL) {
yyval = list_create(yyvsp[-3]);
(void) list_prepend(yyval, instruction(Op_push_i));
yyval->nexti->memory = dupnode(Nnull_string);
} else
yyval = list_append(yyvsp[-1], yyvsp[-3]);
if (yyvsp[0] != NULL)
yyval = list_append(yyval, yyvsp[0]);
}
#line 3066 "awkgram.c"
break;
case 65:
#line 1111 "awkgram.y"
{
if (yyvsp[0] != NULL)
yyval = list_append(yyvsp[-1], yyvsp[0]);
else
yyval = yyvsp[-1];
}
#line 3077 "awkgram.c"
break;
case 66:
#line 1128 "awkgram.y"
{ in_print = true; in_parens = 0; }
#line 3083 "awkgram.c"
break;
case 67:
#line 1129 "awkgram.y"
{
/*
* Optimization: plain `print' has no expression list, so $3 is null.
* If $3 is NULL or is a bytecode list for $0 use Op_K_print_rec,
* which is faster for these two cases.
*/
if (do_optimize && yyvsp[-3]->opcode == Op_K_print &&
(yyvsp[-1] == NULL
|| (yyvsp[-1]->lasti->opcode == Op_field_spec
&& yyvsp[-1]->nexti->nexti->nexti == yyvsp[-1]->lasti
&& yyvsp[-1]->nexti->nexti->opcode == Op_push_i
&& yyvsp[-1]->nexti->nexti->memory->type == Node_val)
)
) {
static bool warned = false;
/* -----------------
* output_redir
* [ redirect exp ]
* -----------------
* expression_list
* ------------------
* [Op_K_print_rec | NULL | redir_type | expr_count]
*/
if (yyvsp[-1] != NULL) {
NODE *n = yyvsp[-1]->nexti->nexti->memory;
if (! iszero(n))
goto regular_print;
bcfree(yyvsp[-1]->lasti); /* Op_field_spec */
unref(n); /* Node_val */
bcfree(yyvsp[-1]->nexti->nexti); /* Op_push_i */
bcfree(yyvsp[-1]->nexti); /* Op_list */
bcfree(yyvsp[-1]); /* Op_list */
} else {
if (do_lint && (rule == BEGIN || rule == END) && ! warned) {
warned = true;
lintwarn_ln(yyvsp[-3]->source_line,
_("plain `print' in BEGIN or END rule should probably be `print \"\"'"));
}
}
yyvsp[-3]->expr_count = 0;
yyvsp[-3]->opcode = Op_K_print_rec;
if (yyvsp[0] == NULL) { /* no redircetion */
yyvsp[-3]->redir_type = redirect_none;
yyval = list_create(yyvsp[-3]);
} else {
INSTRUCTION *ip;
ip = yyvsp[0]->nexti;
yyvsp[-3]->redir_type = ip->redir_type;
yyvsp[0]->nexti = ip->nexti;
bcfree(ip);
yyval = list_append(yyvsp[0], yyvsp[-3]);
}
} else {
/* -----------------
* [ output_redir ]
* [ redirect exp ]
* -----------------
* [ expression_list ]
* ------------------
* [$1 | NULL | redir_type | expr_count]
*
*/
regular_print:
if (yyvsp[0] == NULL) { /* no redirection */
if (yyvsp[-1] == NULL) { /* print/printf without arg */
yyvsp[-3]->expr_count = 0;
if (yyvsp[-3]->opcode == Op_K_print)
yyvsp[-3]->opcode = Op_K_print_rec;
yyvsp[-3]->redir_type = redirect_none;
yyval = list_create(yyvsp[-3]);
} else {
INSTRUCTION *t = yyvsp[-1];
yyvsp[-3]->expr_count = count_expressions(&t, false);
yyvsp[-3]->redir_type = redirect_none;
yyval = list_append(t, yyvsp[-3]);
}
} else {
INSTRUCTION *ip;
ip = yyvsp[0]->nexti;
yyvsp[-3]->redir_type = ip->redir_type;
yyvsp[0]->nexti = ip->nexti;
bcfree(ip);
if (yyvsp[-1] == NULL) {
yyvsp[-3]->expr_count = 0;
if (yyvsp[-3]->opcode == Op_K_print)
yyvsp[-3]->opcode = Op_K_print_rec;
yyval = list_append(yyvsp[0], yyvsp[-3]);
} else {
INSTRUCTION *t = yyvsp[-1];
yyvsp[-3]->expr_count = count_expressions(&t, false);
yyval = list_append(list_merge(yyvsp[0], t), yyvsp[-3]);
}
}
}
}
#line 3188 "awkgram.c"
break;
case 68:
#line 1230 "awkgram.y"
{ sub_counter = 0; }
#line 3194 "awkgram.c"
break;
case 69:
#line 1231 "awkgram.y"
{
char *arr = yyvsp[-2]->lextok;
yyvsp[-2]->opcode = Op_push_array;
yyvsp[-2]->memory = variable(yyvsp[-2]->source_line, arr, Node_var_new);
if (! do_posix && ! do_traditional) {
if (yyvsp[-2]->memory == symbol_table)
fatal(_("`delete' is not allowed with SYMTAB"));
else if (yyvsp[-2]->memory == func_table)
fatal(_("`delete' is not allowed with FUNCTAB"));
}
if (yyvsp[0] == NULL) {
/*
* As of September 2012, POSIX has added support
* for `delete array'. See:
* http://austingroupbugs.net/view.php?id=544
*
* Thanks to Nathan Weeks for the initiative.
*
* Thus we no longer warn or check do_posix.
* Also, since BWK awk supports it, we don't have to
* check do_traditional either.
*/
yyvsp[-3]->expr_count = 0;
yyval = list_append(list_create(yyvsp[-2]), yyvsp[-3]);
} else {
yyvsp[-3]->expr_count = sub_counter;
yyval = list_append(list_append(yyvsp[0], yyvsp[-2]), yyvsp[-3]);
}
}
#line 3231 "awkgram.c"
break;
case 70:
#line 1268 "awkgram.y"
{
static bool warned = false;
char *arr = yyvsp[-1]->lextok;
if (do_lint && ! warned) {
warned = true;
lintwarn_ln(yyvsp[-3]->source_line,
_("`delete(array)' is a non-portable tawk extension"));
}
if (do_traditional) {
error_ln(yyvsp[-3]->source_line,
_("`delete(array)' is a non-portable tawk extension"));
}
yyvsp[-1]->memory = variable(yyvsp[-1]->source_line, arr, Node_var_new);
yyvsp[-1]->opcode = Op_push_array;
yyvsp[-3]->expr_count = 0;
yyval = list_append(list_create(yyvsp[-1]), yyvsp[-3]);
if (! do_posix && ! do_traditional) {
if (yyvsp[-1]->memory == symbol_table)
fatal(_("`delete' is not allowed with SYMTAB"));
else if (yyvsp[-1]->memory == func_table)
fatal(_("`delete' is not allowed with FUNCTAB"));
}
}
#line 3261 "awkgram.c"
break;
case 71:
#line 1294 "awkgram.y"
{
yyval = optimize_assignment(yyvsp[0]);
}
#line 3269 "awkgram.c"
break;
case 72:
#line 1301 "awkgram.y"
{ yyval = NULL; }
#line 3275 "awkgram.c"
break;
case 73:
#line 1303 "awkgram.y"
{ yyval = yyvsp[0]; }
#line 3281 "awkgram.c"
break;
case 74:
#line 1308 "awkgram.y"
{ yyval = NULL; }
#line 3287 "awkgram.c"
break;
case 75:
#line 1310 "awkgram.y"
{
if (yyvsp[-1] == NULL)
yyval = list_create(yyvsp[0]);
else
yyval = list_prepend(yyvsp[-1], yyvsp[0]);
}
#line 3298 "awkgram.c"
break;
case 76:
#line 1317 "awkgram.y"
{ yyval = NULL; }
#line 3304 "awkgram.c"
break;
case 77:
#line 1322 "awkgram.y"
{
INSTRUCTION *casestmt = yyvsp[0];
if (yyvsp[0] == NULL)
casestmt = list_create(instruction(Op_no_op));
if (do_pretty_print)
(void) list_prepend(casestmt, instruction(Op_exec_count));
yyvsp[-4]->case_exp = yyvsp[-3];
yyvsp[-4]->case_stmt = casestmt;
yyvsp[-4]->comment = yyvsp[-1];
bcfree(yyvsp[-2]);
yyval = yyvsp[-4];
}
#line 3321 "awkgram.c"
break;
case 78:
#line 1335 "awkgram.y"
{
INSTRUCTION *casestmt = yyvsp[0];
if (yyvsp[0] == NULL)
casestmt = list_create(instruction(Op_no_op));
if (do_pretty_print)
(void) list_prepend(casestmt, instruction(Op_exec_count));
bcfree(yyvsp[-2]);
yyvsp[-3]->case_stmt = casestmt;
yyvsp[-3]->comment = yyvsp[-1];
yyval = yyvsp[-3];
}
#line 3337 "awkgram.c"
break;
case 79:
#line 1350 "awkgram.y"
{ yyval = yyvsp[0]; }
#line 3343 "awkgram.c"
break;
case 80:
#line 1352 "awkgram.y"
{
NODE *n = yyvsp[0]->memory;
(void) force_number(n);
negate_num(n);
bcfree(yyvsp[-1]);
yyval = yyvsp[0];
}
#line 3355 "awkgram.c"
break;
case 81:
#line 1360 "awkgram.y"
{
NODE *n = yyvsp[0]->lasti->memory;
bcfree(yyvsp[-1]);
add_sign_to_num(n, '+');
yyval = yyvsp[0];
}
#line 3366 "awkgram.c"
break;
case 82:
#line 1367 "awkgram.y"
{ yyval = yyvsp[0]; }
#line 3372 "awkgram.c"
break;
case 83:
#line 1369 "awkgram.y"
{
if (yyvsp[0]->memory->type == Node_regex)
yyvsp[0]->opcode = Op_push_re;
else
yyvsp[0]->opcode = Op_push;
yyval = yyvsp[0];
}
#line 3384 "awkgram.c"
break;
case 84:
#line 1377 "awkgram.y"
{
assert((yyvsp[0]->memory->flags & REGEX) == REGEX);
yyvsp[0]->opcode = Op_push_re;
yyval = yyvsp[0];
}
#line 3394 "awkgram.c"
break;
case 85:
#line 1386 "awkgram.y"
{ yyval = yyvsp[0]; }
#line 3400 "awkgram.c"
break;
case 86:
#line 1388 "awkgram.y"
{ yyval = yyvsp[0]; }
#line 3406 "awkgram.c"
break;
case 88:
#line 1398 "awkgram.y"
{
yyval = yyvsp[-1];
}
#line 3414 "awkgram.c"
break;
case 89:
#line 1405 "awkgram.y"
{
in_print = false;
in_parens = 0;
yyval = NULL;
}
#line 3424 "awkgram.c"
break;
case 90:
#line 1410 "awkgram.y"
{ in_print = false; in_parens = 0; }
#line 3430 "awkgram.c"
break;
case 91:
#line 1411 "awkgram.y"
{
if (yyvsp[-2]->redir_type == redirect_twoway
&& yyvsp[0]->lasti->opcode == Op_K_getline_redir
&& yyvsp[0]->lasti->redir_type == redirect_twoway)
yyerror(_("multistage two-way pipelines don't work"));
if (do_lint && yyvsp[-2]->redir_type == redirect_output && yyvsp[0]->lasti->opcode == Op_concat)
lintwarn(_("concatenation as I/O `>' redirection target is ambiguous"));
yyval = list_prepend(yyvsp[0], yyvsp[-2]);
}
#line 3444 "awkgram.c"
break;
case 92:
#line 1424 "awkgram.y"
{
if (yyvsp[-1] != NULL)
yyvsp[-5]->comment = yyvsp[-1];
add_lint(yyvsp[-3], LINT_assign_in_cond);
yyval = mk_condition(yyvsp[-3], yyvsp[-5], yyvsp[0], NULL, NULL);
}
#line 3455 "awkgram.c"
break;
case 93:
#line 1432 "awkgram.y"
{
if (yyvsp[-4] != NULL)
yyvsp[-8]->comment = yyvsp[-4];
if (yyvsp[-1] != NULL)
yyvsp[-2]->comment = yyvsp[-1];
add_lint(yyvsp[-6], LINT_assign_in_cond);
yyval = mk_condition(yyvsp[-6], yyvsp[-8], yyvsp[-3], yyvsp[-2], yyvsp[0]);
}
#line 3468 "awkgram.c"
break;
case 94:
#line 1444 "awkgram.y"
{
yyval = yyvsp[0];
}
#line 3476 "awkgram.c"
break;
case 95:
#line 1448 "awkgram.y"
{
if (yyvsp[-1] != NULL && yyvsp[0] != NULL) {
if (yyvsp[-1]->memory->comment_type == EOL_COMMENT) {
assert(yyvsp[0]->memory->comment_type == BLOCK_COMMENT);
yyvsp[-1]->comment = yyvsp[0]; // chain them
} else {
merge_comments(yyvsp[-1], yyvsp[0]);
}
yyval = yyvsp[-1];
} else if (yyvsp[-1] != NULL) {
yyval = yyvsp[-1];
} else if (yyvsp[0] != NULL) {
yyval = yyvsp[0];
} else
yyval = NULL;
}
#line 3498 "awkgram.c"
break;
case 96:
#line 1469 "awkgram.y"
{ yyval = NULL; }
#line 3504 "awkgram.c"
break;
case 97:
#line 1471 "awkgram.y"
{ yyval = yyvsp[0]; }
#line 3510 "awkgram.c"
break;
case 98:
#line 1476 "awkgram.y"
{ yyval = NULL; }
#line 3516 "awkgram.c"
break;
case 99:
#line 1478 "awkgram.y"
{
bcfree(yyvsp[-1]);
yyval = yyvsp[0];
}
#line 3525 "awkgram.c"
break;
case 100:
#line 1486 "awkgram.y"
{ yyval = NULL; }
#line 3531 "awkgram.c"
break;
case 101:
#line 1488 "awkgram.y"
{ yyval = yyvsp[0]; }
#line 3537 "awkgram.c"
break;
case 102:
#line 1493 "awkgram.y"
{
yyvsp[0]->param_count = 0;
yyval = list_create(yyvsp[0]);
}
#line 3546 "awkgram.c"
break;
case 103:
#line 1498 "awkgram.y"
{
if (yyvsp[-2] != NULL && yyvsp[0] != NULL) {
yyvsp[0]->param_count = yyvsp[-2]->lasti->param_count + 1;
yyval = list_append(yyvsp[-2], yyvsp[0]);
yyerrok;
// newlines are allowed after commas, catch any comments
if (yyvsp[-1] != NULL) {
if (yyvsp[-2]->comment != NULL)
merge_comments(yyvsp[-2]->comment, yyvsp[-1]);
else
yyvsp[-2]->comment = yyvsp[-1];
}
} else
yyval = NULL;
}
#line 3567 "awkgram.c"
break;
case 104:
#line 1515 "awkgram.y"
{ yyval = NULL; }
#line 3573 "awkgram.c"
break;
case 105:
#line 1517 "awkgram.y"
{ yyval = yyvsp[-1]; }
#line 3579 "awkgram.c"
break;
case 106:
#line 1519 "awkgram.y"
{ yyval = yyvsp[-2]; }
#line 3585 "awkgram.c"
break;
case 107:
#line 1525 "awkgram.y"
{ yyval = NULL; }
#line 3591 "awkgram.c"
break;
case 108:
#line 1527 "awkgram.y"
{ yyval = yyvsp[0]; }
#line 3597 "awkgram.c"
break;
case 109:
#line 1532 "awkgram.y"
{ yyval = NULL; }
#line 3603 "awkgram.c"
break;
case 110:
#line 1534 "awkgram.y"
{ yyval = yyvsp[0]; }
#line 3609 "awkgram.c"
break;
case 111:
#line 1539 "awkgram.y"
{ yyval = mk_expression_list(NULL, yyvsp[0]); }
#line 3615 "awkgram.c"
break;
case 112:
#line 1541 "awkgram.y"
{
if (yyvsp[-1] != NULL)
yyvsp[-2]->lasti->comment = yyvsp[-1];
yyval = mk_expression_list(yyvsp[-2], yyvsp[0]);
yyerrok;
}
#line 3626 "awkgram.c"
break;
case 113:
#line 1548 "awkgram.y"
{ yyval = NULL; }
#line 3632 "awkgram.c"
break;
case 114:
#line 1550 "awkgram.y"
{
/*
* Returning the expression list instead of NULL lets
* snode get a list of arguments that it can count.
*/
yyval = yyvsp[-1];
}
#line 3644 "awkgram.c"
break;
case 115:
#line 1558 "awkgram.y"
{
/* Ditto */
yyval = mk_expression_list(yyvsp[-2], yyvsp[0]);
}
#line 3653 "awkgram.c"
break;
case 116:
#line 1563 "awkgram.y"
{
/* Ditto */
if (yyvsp[-1] != NULL)
yyvsp[-2]->lasti->comment = yyvsp[-1];
yyval = yyvsp[-2];
}
#line 3664 "awkgram.c"
break;
case 117:
#line 1573 "awkgram.y"
{ yyval = NULL; }
#line 3670 "awkgram.c"
break;
case 118:
#line 1575 "awkgram.y"
{ yyval = yyvsp[0]; }
#line 3676 "awkgram.c"
break;
case 119:
#line 1580 "awkgram.y"
{ yyval = mk_expression_list(NULL, yyvsp[0]); }
#line 3682 "awkgram.c"
break;
case 120:
#line 1582 "awkgram.y"
{
if (yyvsp[-1] != NULL)
yyvsp[-2]->lasti->comment = yyvsp[-1];
yyval = mk_expression_list(yyvsp[-2], yyvsp[0]);
yyerrok;
}
#line 3693 "awkgram.c"
break;
case 121:
#line 1589 "awkgram.y"
{ yyval = NULL; }
#line 3699 "awkgram.c"
break;
case 122:
#line 1591 "awkgram.y"
{
/*
* Returning the expression list instead of NULL lets
* snode get a list of arguments that it can count.
*/
yyval = yyvsp[-1];
}
#line 3711 "awkgram.c"
break;
case 123:
#line 1599 "awkgram.y"
{
/* Ditto */
yyval = mk_expression_list(yyvsp[-2], yyvsp[0]);
}
#line 3720 "awkgram.c"
break;
case 124:
#line 1604 "awkgram.y"
{
/* Ditto */
if (yyvsp[-1] != NULL)
yyvsp[-2]->comment = yyvsp[-1];
yyval = yyvsp[-2];
}
#line 3731 "awkgram.c"
break;
case 125:
#line 1613 "awkgram.y"
{ yyval = yyvsp[0]; }
#line 3737 "awkgram.c"
break;
case 126:
#line 1614 "awkgram.y"
{ yyval = list_create(yyvsp[0]); }
#line 3743 "awkgram.c"
break;
case 127:
#line 1620 "awkgram.y"
{
if (do_lint && yyvsp[0]->lasti->opcode == Op_match_rec)
lintwarn_ln(yyvsp[-1]->source_line,
_("regular expression on right of assignment"));
yyval = mk_assignment(yyvsp[-2], yyvsp[0], yyvsp[-1]);
}
#line 3754 "awkgram.c"
break;
case 128:
#line 1627 "awkgram.y"
{
yyval = mk_assignment(yyvsp[-2], list_create(yyvsp[0]), yyvsp[-1]);
}
#line 3762 "awkgram.c"
break;
case 129:
#line 1631 "awkgram.y"
{ yyval = mk_boolean(yyvsp[-2], yyvsp[0], yyvsp[-1]); }
#line 3768 "awkgram.c"
break;
case 130:
#line 1633 "awkgram.y"
{ yyval = mk_boolean(yyvsp[-2], yyvsp[0], yyvsp[-1]); }
#line 3774 "awkgram.c"
break;
case 131:
#line 1635 "awkgram.y"
{
if (yyvsp[-2]->lasti->opcode == Op_match_rec)
warning_ln(yyvsp[-1]->source_line,
_("regular expression on left of `~' or `!~' operator"));
assert(yyvsp[0]->opcode == Op_push_re
&& (yyvsp[0]->memory->flags & REGEX) != 0);
/* RHS is @/.../ */
yyvsp[-1]->memory = yyvsp[0]->memory;
bcfree(yyvsp[0]);
yyval = list_append(yyvsp[-2], yyvsp[-1]);
}
#line 3791 "awkgram.c"
break;
case 132:
#line 1648 "awkgram.y"
{
if (yyvsp[-2]->lasti->opcode == Op_match_rec)
warning_ln(yyvsp[-1]->source_line,
_("regular expression on left of `~' or `!~' operator"));
if (yyvsp[0]->lasti == yyvsp[0]->nexti && yyvsp[0]->nexti->opcode == Op_match_rec) {
/* RHS is /.../ */
yyvsp[-1]->memory = yyvsp[0]->nexti->memory;
bcfree(yyvsp[0]->nexti); /* Op_match_rec */
bcfree(yyvsp[0]); /* Op_list */
yyval = list_append(yyvsp[-2], yyvsp[-1]);
} else {
yyvsp[-1]->memory = make_regnode(Node_dynregex, NULL);
yyval = list_append(list_merge(yyvsp[-2], yyvsp[0]), yyvsp[-1]);
}
}
#line 3812 "awkgram.c"
break;
case 133:
#line 1665 "awkgram.y"
{
if (do_lint_old)
lintwarn_ln(yyvsp[-1]->source_line,
_("old awk does not support the keyword `in' except after `for'"));
yyvsp[0]->nexti->opcode = Op_push_array;
yyvsp[-1]->opcode = Op_in_array;
yyvsp[-1]->expr_count = 1;
yyval = list_append(list_merge(yyvsp[-2], yyvsp[0]), yyvsp[-1]);
}
#line 3826 "awkgram.c"
break;
case 134:
#line 1675 "awkgram.y"
{
if (do_lint && yyvsp[0]->lasti->opcode == Op_match_rec)
lintwarn_ln(yyvsp[-1]->source_line,
_("regular expression on right of comparison"));
yyval = list_append(list_merge(yyvsp[-2], yyvsp[0]), yyvsp[-1]);
}
#line 3837 "awkgram.c"
break;
case 135:
#line 1682 "awkgram.y"
{ yyval = mk_condition(yyvsp[-4], yyvsp[-3], yyvsp[-2], yyvsp[-1], yyvsp[0]); }
#line 3843 "awkgram.c"
break;
case 136:
#line 1684 "awkgram.y"
{ yyval = yyvsp[0]; }
#line 3849 "awkgram.c"
break;
case 137:
#line 1689 "awkgram.y"
{ yyval = yyvsp[0]; }
#line 3855 "awkgram.c"
break;
case 138:
#line 1691 "awkgram.y"
{ yyval = yyvsp[0]; }
#line 3861 "awkgram.c"
break;
case 139:
#line 1693 "awkgram.y"
{
yyvsp[0]->opcode = Op_assign_quotient;
yyval = yyvsp[0];
}
#line 3870 "awkgram.c"
break;
case 140:
#line 1701 "awkgram.y"
{ yyval = yyvsp[0]; }
#line 3876 "awkgram.c"
break;
case 141:
#line 1703 "awkgram.y"
{ yyval = yyvsp[0]; }
#line 3882 "awkgram.c"
break;
case 142:
#line 1708 "awkgram.y"
{ yyval = yyvsp[0]; }
#line 3888 "awkgram.c"
break;
case 143:
#line 1710 "awkgram.y"
{ yyval = yyvsp[0]; }
#line 3894 "awkgram.c"
break;
case 144:
#line 1715 "awkgram.y"
{ yyval = yyvsp[0]; }
#line 3900 "awkgram.c"
break;
case 145:
#line 1717 "awkgram.y"
{ yyval = yyvsp[0]; }
#line 3906 "awkgram.c"
break;
case 146:
#line 1719 "awkgram.y"
{
int count = 2;
bool is_simple_var = false;
if (yyvsp[-1]->lasti->opcode == Op_concat) {
/* multiple (> 2) adjacent strings optimization */
is_simple_var = (yyvsp[-1]->lasti->concat_flag & CSVAR) != 0;
count = yyvsp[-1]->lasti->expr_count + 1;
yyvsp[-1]->lasti->opcode = Op_no_op;
} else {
is_simple_var = (yyvsp[-1]->nexti->opcode == Op_push
&& yyvsp[-1]->lasti == yyvsp[-1]->nexti); /* first exp. is a simple
* variable?; kludge for use
* in Op_assign_concat.
*/
}
if (do_optimize
&& yyvsp[-1]->nexti == yyvsp[-1]->lasti && yyvsp[-1]->nexti->opcode == Op_push_i
&& yyvsp[0]->nexti == yyvsp[0]->lasti && yyvsp[0]->nexti->opcode == Op_push_i
) {
NODE *n1 = yyvsp[-1]->nexti->memory;
NODE *n2 = yyvsp[0]->nexti->memory;
size_t nlen;
// 1.5 "" # can't fold this if program mucks with CONVFMT.
// See test #12 in test/posix.awk.
// Also can't fold if one or the other is translatable.
if ((n1->flags & (NUMBER|NUMINT|INTLSTR)) != 0 || (n2->flags & (NUMBER|NUMINT|INTLSTR)) != 0)
goto plain_concat;
n1 = force_string(n1);
n2 = force_string(n2);
nlen = n1->stlen + n2->stlen;
erealloc(n1->stptr, char *, nlen + 1, "constant fold");
memcpy(n1->stptr + n1->stlen, n2->stptr, n2->stlen);
n1->stlen = nlen;
n1->stptr[nlen] = '\0';
n1->flags &= ~(NUMCUR|NUMBER|NUMINT);
n1->flags |= (STRING|STRCUR);
unref(n2);
bcfree(yyvsp[0]->nexti);
bcfree(yyvsp[0]);
yyval = yyvsp[-1];
} else {
plain_concat:
yyval = list_append(list_merge(yyvsp[-1], yyvsp[0]), instruction(Op_concat));
yyval->lasti->concat_flag = (is_simple_var ? CSVAR : 0);
yyval->lasti->expr_count = count;
if (count > max_args)
max_args = count;
}
}
#line 3964 "awkgram.c"
break;
case 148:
#line 1778 "awkgram.y"
{ yyval = mk_binary(yyvsp[-2], yyvsp[0], yyvsp[-1]); }
#line 3970 "awkgram.c"
break;
case 149:
#line 1780 "awkgram.y"
{ yyval = mk_binary(yyvsp[-2], yyvsp[0], yyvsp[-1]); }
#line 3976 "awkgram.c"
break;
case 150:
#line 1782 "awkgram.y"
{ yyval = mk_binary(yyvsp[-2], yyvsp[0], yyvsp[-1]); }
#line 3982 "awkgram.c"
break;
case 151:
#line 1784 "awkgram.y"
{ yyval = mk_binary(yyvsp[-2], yyvsp[0], yyvsp[-1]); }
#line 3988 "awkgram.c"
break;
case 152:
#line 1786 "awkgram.y"
{ yyval = mk_binary(yyvsp[-2], yyvsp[0], yyvsp[-1]); }
#line 3994 "awkgram.c"
break;
case 153:
#line 1788 "awkgram.y"
{ yyval = mk_binary(yyvsp[-2], yyvsp[0], yyvsp[-1]); }
#line 4000 "awkgram.c"
break;
case 154:
#line 1790 "awkgram.y"
{
/*
* In BEGINFILE/ENDFILE, allow `getline [var] < file'
*/
if ((rule == BEGINFILE || rule == ENDFILE) && yyvsp[0] == NULL)
error_ln(yyvsp[-2]->source_line,
_("non-redirected `getline' invalid inside `%s' rule"), ruletab[rule]);
if (do_lint && rule == END && yyvsp[0] == NULL)
lintwarn_ln(yyvsp[-2]->source_line,
_("non-redirected `getline' undefined inside END action"));
yyval = mk_getline(yyvsp[-2], yyvsp[-1], yyvsp[0], redirect_input);
}
#line 4018 "awkgram.c"
break;
case 155:
#line 1804 "awkgram.y"
{
yyvsp[0]->opcode = Op_postincrement;
yyval = mk_assignment(yyvsp[-1], NULL, yyvsp[0]);
}
#line 4027 "awkgram.c"
break;
case 156:
#line 1809 "awkgram.y"
{
yyvsp[0]->opcode = Op_postdecrement;
yyval = mk_assignment(yyvsp[-1], NULL, yyvsp[0]);
}
#line 4036 "awkgram.c"
break;
case 157:
#line 1814 "awkgram.y"
{
if (do_lint_old) {
/* first one is warning so that second one comes out if warnings are fatal */
warning_ln(yyvsp[-1]->source_line,
_("old awk does not support the keyword `in' except after `for'"));
lintwarn_ln(yyvsp[-1]->source_line,
_("old awk does not support multidimensional arrays"));
}
yyvsp[0]->nexti->opcode = Op_push_array;
yyvsp[-1]->opcode = Op_in_array;
if (yyvsp[-3] == NULL) { /* error */
errcount++;
yyvsp[-1]->expr_count = 0;
yyval = list_merge(yyvsp[0], yyvsp[-1]);
} else {
INSTRUCTION *t = yyvsp[-3];
yyvsp[-1]->expr_count = count_expressions(&t, false);
yyval = list_append(list_merge(t, yyvsp[0]), yyvsp[-1]);
}
}
#line 4061 "awkgram.c"
break;
case 158:
#line 1840 "awkgram.y"
{
yyval = mk_getline(yyvsp[-1], yyvsp[0], yyvsp[-3], yyvsp[-2]->redir_type);
bcfree(yyvsp[-2]);
}
#line 4070 "awkgram.c"
break;
case 159:
#line 1846 "awkgram.y"
{ yyval = mk_binary(yyvsp[-2], yyvsp[0], yyvsp[-1]); }
#line 4076 "awkgram.c"
break;
case 160:
#line 1848 "awkgram.y"
{ yyval = mk_binary(yyvsp[-2], yyvsp[0], yyvsp[-1]); }
#line 4082 "awkgram.c"
break;
case 161:
#line 1850 "awkgram.y"
{ yyval = mk_binary(yyvsp[-2], yyvsp[0], yyvsp[-1]); }
#line 4088 "awkgram.c"
break;
case 162:
#line 1852 "awkgram.y"
{ yyval = mk_binary(yyvsp[-2], yyvsp[0], yyvsp[-1]); }
#line 4094 "awkgram.c"
break;
case 163:
#line 1854 "awkgram.y"
{ yyval = mk_binary(yyvsp[-2], yyvsp[0], yyvsp[-1]); }
#line 4100 "awkgram.c"
break;
case 164:
#line 1856 "awkgram.y"
{ yyval = mk_binary(yyvsp[-2], yyvsp[0], yyvsp[-1]); }
#line 4106 "awkgram.c"
break;
case 165:
#line 1861 "awkgram.y"
{
yyval = list_create(yyvsp[0]);
}
#line 4114 "awkgram.c"
break;
case 166:
#line 1865 "awkgram.y"
{
if (yyvsp[0]->opcode == Op_match_rec) {
yyvsp[0]->opcode = Op_nomatch;
yyvsp[-1]->opcode = Op_push_i;
yyvsp[-1]->memory = set_profile_text(make_number(0.0), "0", 1);
yyval = list_append(list_append(list_create(yyvsp[-1]),
instruction(Op_field_spec)), yyvsp[0]);
} else {
if (do_optimize && yyvsp[0]->nexti == yyvsp[0]->lasti
&& yyvsp[0]->nexti->opcode == Op_push_i
&& (yyvsp[0]->nexti->memory->flags & (MPFN|MPZN|INTLSTR)) == 0
) {
NODE *n = yyvsp[0]->nexti->memory;
if ((n->flags & STRING) != 0) {
n->numbr = (AWKNUM) (n->stlen == 0);
n->flags &= ~(STRCUR|STRING);
n->flags |= (NUMCUR|NUMBER);
efree(n->stptr);
n->stptr = NULL;
n->stlen = 0;
} else
n->numbr = (AWKNUM) (n->numbr == 0.0);
bcfree(yyvsp[-1]);
yyval = yyvsp[0];
} else {
yyvsp[-1]->opcode = Op_not;
add_lint(yyvsp[0], LINT_assign_in_cond);
yyval = list_append(yyvsp[0], yyvsp[-1]);
}
}
}
#line 4150 "awkgram.c"
break;
case 167:
#line 1897 "awkgram.y"
{
// Always include. Allows us to lint warn on
// print "foo" > "bar" 1
// but not warn on
// print "foo" > ("bar" 1)
yyval = list_append(yyvsp[-1], bcalloc(Op_parens, 1, sourceline));
}
#line 4162 "awkgram.c"
break;
case 168:
#line 1905 "awkgram.y"
{
yyval = snode(yyvsp[-1], yyvsp[-3]);
if (yyval == NULL)
YYABORT;
}
#line 4172 "awkgram.c"
break;
case 169:
#line 1911 "awkgram.y"
{
yyval = snode(yyvsp[-1], yyvsp[-3]);
if (yyval == NULL)
YYABORT;
}
#line 4182 "awkgram.c"
break;
case 170:
#line 1917 "awkgram.y"
{
static bool warned = false;
if (do_lint && ! warned) {
warned = true;
lintwarn_ln(yyvsp[0]->source_line,
_("call of `length' without parentheses is not portable"));
}
yyval = snode(NULL, yyvsp[0]);
if (yyval == NULL)
YYABORT;
}
#line 4199 "awkgram.c"
break;
case 173:
#line 1932 "awkgram.y"
{
yyvsp[-1]->opcode = Op_preincrement;
yyval = mk_assignment(yyvsp[0], NULL, yyvsp[-1]);
}
#line 4208 "awkgram.c"
break;
case 174:
#line 1937 "awkgram.y"
{
yyvsp[-1]->opcode = Op_predecrement;
yyval = mk_assignment(yyvsp[0], NULL, yyvsp[-1]);
}
#line 4217 "awkgram.c"
break;
case 175:
#line 1942 "awkgram.y"
{
yyval = list_create(yyvsp[0]);
}
#line 4225 "awkgram.c"
break;
case 176:
#line 1946 "awkgram.y"
{
yyval = list_create(yyvsp[0]);
}
#line 4233 "awkgram.c"
break;
case 177:
#line 1950 "awkgram.y"
{
if (yyvsp[0]->lasti->opcode == Op_push_i
&& (yyvsp[0]->lasti->memory->flags & STRING) == 0
) {
NODE *n = yyvsp[0]->lasti->memory;
(void) force_number(n);
negate_num(n);
yyval = yyvsp[0];
bcfree(yyvsp[-1]);
} else {
yyvsp[-1]->opcode = Op_unary_minus;
yyval = list_append(yyvsp[0], yyvsp[-1]);
}
}
#line 4252 "awkgram.c"
break;
case 178:
#line 1965 "awkgram.y"
{
if (yyvsp[0]->lasti->opcode == Op_push_i
&& (yyvsp[0]->lasti->memory->flags & STRING) == 0
&& (yyvsp[0]->lasti->memory->flags & NUMCONSTSTR) != 0) {
NODE *n = yyvsp[0]->lasti->memory;
add_sign_to_num(n, '+');
yyval = yyvsp[0];
bcfree(yyvsp[-1]);
} else {
/*
* was: $$ = $2
* POSIX semantics: force a conversion to numeric type
*/
yyvsp[-1]->opcode = Op_unary_plus;
yyval = list_append(yyvsp[0], yyvsp[-1]);
}
}
#line 4274 "awkgram.c"
break;
case 179:
#line 1986 "awkgram.y"
{
func_use(yyvsp[0]->lasti->func_name, FUNC_USE);
yyval = yyvsp[0];
}
#line 4283 "awkgram.c"
break;
case 180:
#line 1991 "awkgram.y"
{
/* indirect function call */
INSTRUCTION *f, *t;
char *name;
NODE *indirect_var;
static bool warned = false;
const char *msg = _("indirect function calls are a gawk extension");
if (do_traditional || do_posix)
yyerror("%s", msg);
else if (do_lint_extensions && ! warned) {
warned = true;
lintwarn("%s", msg);
}
f = yyvsp[0]->lasti;
f->opcode = Op_indirect_func_call;
name = estrdup(f->func_name, strlen(f->func_name));
if (is_std_var(name))
yyerror(_("cannot use special variable `%s' for indirect function call"), name);
indirect_var = variable(f->source_line, name, Node_var_new);
t = instruction(Op_push);
t->memory = indirect_var;
/* prepend indirect var instead of appending to arguments (opt_expression_list),
* and pop it off in setup_frame (eval.c) (left to right evaluation order); Test case:
* f = "fun"
* @f(f="real_fun")
*/
yyval = list_prepend(yyvsp[0], t);
at_seen = false;
}
#line 4321 "awkgram.c"
break;
case 181:
#line 2028 "awkgram.y"
{
NODE *n;
char *name = yyvsp[-3]->func_name;
char *qname = qualify_name(name, strlen(name));
if (qname != name) {
efree((char *) name);
yyvsp[-3]->func_name = qname;
}
if (! at_seen) {
n = lookup(yyvsp[-3]->func_name);
if (n != NULL && n->type != Node_func
&& n->type != Node_ext_func) {
error_ln(yyvsp[-3]->source_line,
_("attempt to use non-function `%s' in function call"),
yyvsp[-3]->func_name);
}
}
param_sanity(yyvsp[-1]);
yyvsp[-3]->opcode = Op_func_call;
yyvsp[-3]->func_body = NULL;
if (yyvsp[-1] == NULL) { /* no argument or error */
(yyvsp[-3] + 1)->expr_count = 0;
yyval = list_create(yyvsp[-3]);
} else {
INSTRUCTION *t = yyvsp[-1];
(yyvsp[-3] + 1)->expr_count = count_expressions(&t, true);
yyval = list_append(t, yyvsp[-3]);
}
}
#line 4358 "awkgram.c"
break;
case 182:
#line 2064 "awkgram.y"
{ yyval = NULL; }
#line 4364 "awkgram.c"
break;
case 183:
#line 2066 "awkgram.y"
{ yyval = yyvsp[0]; }
#line 4370 "awkgram.c"
break;
case 184:
#line 2071 "awkgram.y"
{ yyval = NULL; }
#line 4376 "awkgram.c"
break;
case 185:
#line 2073 "awkgram.y"
{ yyval = yyvsp[-1]; }
#line 4382 "awkgram.c"
break;
case 186:
#line 2078 "awkgram.y"
{ yyval = yyvsp[0]; }
#line 4388 "awkgram.c"
break;
case 187:
#line 2080 "awkgram.y"
{
yyval = list_merge(yyvsp[-1], yyvsp[0]);
}
#line 4396 "awkgram.c"
break;
case 188:
#line 2087 "awkgram.y"
{
INSTRUCTION *ip = yyvsp[0]->lasti;
int count = ip->sub_count; /* # of SUBSEP-seperated expressions */
if (count > 1) {
/* change Op_subscript or Op_sub_array to Op_concat */
ip->opcode = Op_concat;
ip->concat_flag = CSUBSEP;
ip->expr_count = count;
} else
ip->opcode = Op_no_op;
sub_counter++; /* count # of dimensions */
yyval = yyvsp[0];
}
#line 4414 "awkgram.c"
break;
case 189:
#line 2104 "awkgram.y"
{
INSTRUCTION *t = yyvsp[-1];
if (yyvsp[-1] == NULL) {
error_ln(yyvsp[0]->source_line,
_("invalid subscript expression"));
/* install Null string as subscript. */
t = list_create(instruction(Op_push_i));
t->nexti->memory = dupnode(Nnull_string);
yyvsp[0]->sub_count = 1;
} else
yyvsp[0]->sub_count = count_expressions(&t, false);
yyval = list_append(t, yyvsp[0]);
}
#line 4432 "awkgram.c"
break;
case 190:
#line 2121 "awkgram.y"
{ yyval = yyvsp[0]; }
#line 4438 "awkgram.c"
break;
case 191:
#line 2123 "awkgram.y"
{
yyval = list_merge(yyvsp[-1], yyvsp[0]);
}
#line 4446 "awkgram.c"
break;
case 192:
#line 2130 "awkgram.y"
{ yyval = yyvsp[-1]; }
#line 4452 "awkgram.c"
break;
case 193:
#line 2135 "awkgram.y"
{
yyvsp[0]->opcode = Op_push;
yyvsp[0]->memory = variable(yyvsp[0]->source_line, yyvsp[0]->lextok, Node_var_new);
yyval = list_create(yyvsp[0]);
}
#line 4462 "awkgram.c"
break;
case 194:
#line 2141 "awkgram.y"
{
char *arr = yyvsp[-1]->lextok;
yyvsp[-1]->memory = variable(yyvsp[-1]->source_line, arr, Node_var_new);
yyvsp[-1]->opcode = Op_push_array;
yyval = list_prepend(yyvsp[0], yyvsp[-1]);
}
#line 4474 "awkgram.c"
break;
case 195:
#line 2152 "awkgram.y"
{
INSTRUCTION *ip = yyvsp[0]->nexti;
if (ip->opcode == Op_push
&& ip->memory->type == Node_var
&& ip->memory->var_update
) {
yyval = list_prepend(yyvsp[0], instruction(Op_var_update));
yyval->nexti->update_var = ip->memory->var_update;
} else
yyval = yyvsp[0];
}
#line 4490 "awkgram.c"
break;
case 196:
#line 2164 "awkgram.y"
{
yyval = list_append(yyvsp[-1], yyvsp[-2]);
if (yyvsp[0] != NULL)
mk_assignment(yyvsp[-1], NULL, yyvsp[0]);
}
#line 4500 "awkgram.c"
break;
case 197:
#line 2173 "awkgram.y"
{
yyvsp[0]->opcode = Op_postincrement;
}
#line 4508 "awkgram.c"
break;
case 198:
#line 2177 "awkgram.y"
{
yyvsp[0]->opcode = Op_postdecrement;
}
#line 4516 "awkgram.c"
break;
case 199:
#line 2181 "awkgram.y"
{ yyval = NULL; }
#line 4522 "awkgram.c"
break;
case 200:
#line 2185 "awkgram.y"
{ yyval = yyvsp[0]; }
#line 4528 "awkgram.c"
break;
case 201:
#line 2189 "awkgram.y"
{ yyval = yyvsp[0]; yyerrok; }
#line 4534 "awkgram.c"
break;
case 202:
#line 2193 "awkgram.y"
{ yyerrok; }
#line 4540 "awkgram.c"
break;
case 203:
#line 2198 "awkgram.y"
{ yyval = NULL; }
#line 4546 "awkgram.c"
break;
case 205:
#line 2203 "awkgram.y"
{ yyerrok; }
#line 4552 "awkgram.c"
break;
case 206:
#line 2207 "awkgram.y"
{ yyval = yyvsp[0]; yyerrok; }
#line 4558 "awkgram.c"
break;
case 207:
#line 2211 "awkgram.y"
{ yyval = yyvsp[0]; yyerrok; }
#line 4564 "awkgram.c"
break;
#line 4568 "awkgram.c"
default: break;
}
/* User semantic actions sometimes alter yychar, and that requires
that yytoken be updated with the new translation. We take the
approach of translating immediately before every use of yytoken.
One alternative is translating here after every semantic action,
but that translation would be missed if the semantic action invokes
YYABORT, YYACCEPT, or YYERROR immediately after altering yychar or
if it invokes YYBACKUP. In the case of YYABORT or YYACCEPT, an
incorrect destructor might then be invoked immediately. In the
case of YYERROR or YYBACKUP, subsequent parser actions might lead
to an incorrect destructor call or verbose syntax error message
before the lookahead is translated. */
YY_SYMBOL_PRINT ("-> $$ =", yyr1[yyn], &yyval, &yyloc);
YYPOPSTACK (yylen);
yylen = 0;
YY_STACK_PRINT (yyss, yyssp);
*++yyvsp = yyval;
/* Now 'shift' the result of the reduction. Determine what state
that goes to, based on the state we popped back to and the rule
number reduced by. */
{
const int yylhs = yyr1[yyn] - YYNTOKENS;
const int yyi = yypgoto[yylhs] + *yyssp;
yystate = (0 <= yyi && yyi <= YYLAST && yycheck[yyi] == *yyssp
? yytable[yyi]
: yydefgoto[yylhs]);
}
goto yynewstate;
/*--------------------------------------.
| yyerrlab -- here on detecting error. |
`--------------------------------------*/
yyerrlab:
/* Make sure we have latest lookahead translation. See comments at
user semantic actions for why this is necessary. */
yytoken = yychar == YYEMPTY ? YYEMPTY : YYTRANSLATE (yychar);
/* If not already recovering from an error, report this error. */
if (!yyerrstatus)
{
++yynerrs;
#if ! YYERROR_VERBOSE
yyerror (YY_("syntax error"));
#else
# define YYSYNTAX_ERROR yysyntax_error (&yymsg_alloc, &yymsg, \
yyssp, yytoken)
{
char const *yymsgp = YY_("syntax error");
int yysyntax_error_status;
yysyntax_error_status = YYSYNTAX_ERROR;
if (yysyntax_error_status == 0)
yymsgp = yymsg;
else if (yysyntax_error_status == 1)
{
if (yymsg != yymsgbuf)
YYSTACK_FREE (yymsg);
yymsg = YY_CAST (char *, YYSTACK_ALLOC (YY_CAST (YYSIZE_T, yymsg_alloc)));
if (!yymsg)
{
yymsg = yymsgbuf;
yymsg_alloc = sizeof yymsgbuf;
yysyntax_error_status = 2;
}
else
{
yysyntax_error_status = YYSYNTAX_ERROR;
yymsgp = yymsg;
}
}
yyerror (yymsgp);
if (yysyntax_error_status == 2)
goto yyexhaustedlab;
}
# undef YYSYNTAX_ERROR
#endif
}
if (yyerrstatus == 3)
{
/* If just tried and failed to reuse lookahead token after an
error, discard it. */
if (yychar <= YYEOF)
{
/* Return failure if at end of input. */
if (yychar == YYEOF)
YYABORT;
}
else
{
yydestruct ("Error: discarding",
yytoken, &yylval);
yychar = YYEMPTY;
}
}
/* Else will try to reuse lookahead token after shifting the error
token. */
goto yyerrlab1;
/*---------------------------------------------------.
| yyerrorlab -- error raised explicitly by YYERROR. |
`---------------------------------------------------*/
yyerrorlab:
/* Pacify compilers when the user code never invokes YYERROR and the
label yyerrorlab therefore never appears in user code. */
if (0)
YYERROR;
/* Do not reclaim the symbols of the rule whose action triggered
this YYERROR. */
YYPOPSTACK (yylen);
yylen = 0;
YY_STACK_PRINT (yyss, yyssp);
yystate = *yyssp;
goto yyerrlab1;
/*-------------------------------------------------------------.
| yyerrlab1 -- common code for both syntax error and YYERROR. |
`-------------------------------------------------------------*/
yyerrlab1:
yyerrstatus = 3; /* Each real token shifted decrements this. */
for (;;)
{
yyn = yypact[yystate];
if (!yypact_value_is_default (yyn))
{
yyn += YYTERROR;
if (0 <= yyn && yyn <= YYLAST && yycheck[yyn] == YYTERROR)
{
yyn = yytable[yyn];
if (0 < yyn)
break;
}
}
/* Pop the current state because it cannot handle the error token. */
if (yyssp == yyss)
YYABORT;
yydestruct ("Error: popping",
yystos[yystate], yyvsp);
YYPOPSTACK (1);
yystate = *yyssp;
YY_STACK_PRINT (yyss, yyssp);
}
YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN
*++yyvsp = yylval;
YY_IGNORE_MAYBE_UNINITIALIZED_END
/* Shift the error token. */
YY_SYMBOL_PRINT ("Shifting", yystos[yyn], yyvsp, yylsp);
yystate = yyn;
goto yynewstate;
/*-------------------------------------.
| yyacceptlab -- YYACCEPT comes here. |
`-------------------------------------*/
yyacceptlab:
yyresult = 0;
goto yyreturn;
/*-----------------------------------.
| yyabortlab -- YYABORT comes here. |
`-----------------------------------*/
yyabortlab:
yyresult = 1;
goto yyreturn;
#if !defined yyoverflow || YYERROR_VERBOSE
/*-------------------------------------------------.
| yyexhaustedlab -- memory exhaustion comes here. |
`-------------------------------------------------*/
yyexhaustedlab:
yyerror (YY_("memory exhausted"));
yyresult = 2;
/* Fall through. */
#endif
/*-----------------------------------------------------.
| yyreturn -- parsing is finished, return the result. |
`-----------------------------------------------------*/
yyreturn:
if (yychar != YYEMPTY)
{
/* Make sure we have latest lookahead translation. See comments at
user semantic actions for why this is necessary. */
yytoken = YYTRANSLATE (yychar);
yydestruct ("Cleanup: discarding lookahead",
yytoken, &yylval);
}
/* Do not reclaim the symbols of the rule whose action triggered
this YYABORT or YYACCEPT. */
YYPOPSTACK (yylen);
YY_STACK_PRINT (yyss, yyssp);
while (yyssp != yyss)
{
yydestruct ("Cleanup: popping",
yystos[+*yyssp], yyvsp);
YYPOPSTACK (1);
}
#ifndef yyoverflow
if (yyss != yyssa)
YYSTACK_FREE (yyss);
#endif
#if YYERROR_VERBOSE
if (yymsg != yymsgbuf)
YYSTACK_FREE (yymsg);
#endif
return yyresult;
}
#line 2213 "awkgram.y"
struct token {
const char *operator; /* text to match */
OPCODE value; /* type */
int class; /* lexical class */
unsigned flags; /* # of args. allowed and compatability */
# define ARGS 0xFF /* 0, 1, 2, 3 args allowed (any combination */
# define A(n) (1<<(n))
# define VERSION_MASK 0xFF00 /* old awk is zero */
# define NOT_OLD 0x0100 /* feature not in old awk */
# define NOT_POSIX 0x0200 /* feature not in POSIX */
# define GAWKX 0x0400 /* gawk extension */
# define BREAK 0x0800 /* break allowed inside */
# define CONTINUE 0x1000 /* continue allowed inside */
# define DEBUG_USE 0x2000 /* for use by developers */
NODE *(*ptr)(int); /* function that implements this keyword */
NODE *(*ptr2)(int); /* alternate arbitrary-precision function */
};
#ifdef USE_EBCDIC
/* tokcompare --- lexicographically compare token names for sorting */
static int
tokcompare(const void *l, const void *r)
{
struct token *lhs, *rhs;
lhs = (struct token *) l;
rhs = (struct token *) r;
return strcmp(lhs->operator, rhs->operator);
}
#endif
/*
* Tokentab is sorted ASCII ascending order, so it can be binary searched.
* See check_special(), which sorts the table on EBCDIC systems.
* Function pointers come from declarations in awk.h.
*/
#ifdef HAVE_MPFR
#define MPF(F) do_mpfr_##F
#else
#define MPF(F) 0
#endif
static const struct token tokentab[] = {
{"BEGIN", Op_rule, LEX_BEGIN, 0, 0, 0},
{"BEGINFILE", Op_rule, LEX_BEGINFILE, GAWKX, 0, 0},
{"END", Op_rule, LEX_END, 0, 0, 0},
{"ENDFILE", Op_rule, LEX_ENDFILE, GAWKX, 0, 0},
#ifdef ARRAYDEBUG
{"adump", Op_builtin, LEX_BUILTIN, GAWKX|A(1)|A(2)|DEBUG_USE, do_adump, 0},
#endif
{"and", Op_builtin, LEX_BUILTIN, GAWKX, do_and, MPF(and)},
{"asort", Op_builtin, LEX_BUILTIN, GAWKX|A(1)|A(2)|A(3), do_asort, 0},
{"asorti", Op_builtin, LEX_BUILTIN, GAWKX|A(1)|A(2)|A(3), do_asorti, 0},
{"atan2", Op_builtin, LEX_BUILTIN, NOT_OLD|A(2), do_atan2, MPF(atan2)},
{"bindtextdomain", Op_builtin, LEX_BUILTIN, GAWKX|A(1)|A(2), do_bindtextdomain, 0},
{"break", Op_K_break, LEX_BREAK, 0, 0, 0},
{"case", Op_K_case, LEX_CASE, GAWKX, 0, 0},
{"close", Op_builtin, LEX_BUILTIN, NOT_OLD|A(1)|A(2), do_close, 0},
{"compl", Op_builtin, LEX_BUILTIN, GAWKX|A(1), do_compl, MPF(compl)},
{"continue", Op_K_continue, LEX_CONTINUE, 0, 0, 0},
{"cos", Op_builtin, LEX_BUILTIN, NOT_OLD|A(1), do_cos, MPF(cos)},
{"dcgettext", Op_builtin, LEX_BUILTIN, GAWKX|A(1)|A(2)|A(3), do_dcgettext, 0},
{"dcngettext", Op_builtin, LEX_BUILTIN, GAWKX|A(1)|A(2)|A(3)|A(4)|A(5), do_dcngettext, 0},
{"default", Op_K_default, LEX_DEFAULT, GAWKX, 0, 0},
{"delete", Op_K_delete, LEX_DELETE, NOT_OLD, 0, 0},
{"do", Op_K_do, LEX_DO, NOT_OLD|BREAK|CONTINUE, 0, 0},
{"else", Op_K_else, LEX_ELSE, 0, 0, 0},
{"eval", Op_symbol, LEX_EVAL, 0, 0, 0},
{"exit", Op_K_exit, LEX_EXIT, 0, 0, 0},
{"exp", Op_builtin, LEX_BUILTIN, A(1), do_exp, MPF(exp)},
{"fflush", Op_builtin, LEX_BUILTIN, A(0)|A(1), do_fflush, 0},
{"for", Op_K_for, LEX_FOR, BREAK|CONTINUE, 0, 0},
{"func", Op_func, LEX_FUNCTION, NOT_POSIX|NOT_OLD, 0, 0},
{"function", Op_func, LEX_FUNCTION, NOT_OLD, 0, 0},
{"gensub", Op_sub_builtin, LEX_BUILTIN, GAWKX|A(3)|A(4), 0, 0},
{"getline", Op_K_getline_redir, LEX_GETLINE, NOT_OLD, 0, 0},
{"gsub", Op_sub_builtin, LEX_BUILTIN, NOT_OLD|A(2)|A(3), 0, 0},
{"if", Op_K_if, LEX_IF, 0, 0, 0},
{"in", Op_symbol, LEX_IN, 0, 0, 0},
{"include", Op_symbol, LEX_INCLUDE, GAWKX, 0, 0},
{"index", Op_builtin, LEX_BUILTIN, A(2), do_index, 0},
{"int", Op_builtin, LEX_BUILTIN, A(1), do_int, MPF(int)},
#ifdef SUPPLY_INTDIV
{"intdiv0", Op_builtin, LEX_BUILTIN, GAWKX|A(3), do_intdiv, MPF(intdiv)},
#endif
{"isarray", Op_builtin, LEX_BUILTIN, GAWKX|A(1), do_isarray, 0},
{"length", Op_builtin, LEX_LENGTH, A(0)|A(1), do_length, 0},
{"load", Op_symbol, LEX_LOAD, GAWKX, 0, 0},
{"log", Op_builtin, LEX_BUILTIN, A(1), do_log, MPF(log)},
{"lshift", Op_builtin, LEX_BUILTIN, GAWKX|A(2), do_lshift, MPF(lshift)},
{"match", Op_builtin, LEX_BUILTIN, NOT_OLD|A(2)|A(3), do_match, 0},
{"mktime", Op_builtin, LEX_BUILTIN, GAWKX|A(1)|A(2), do_mktime, 0},
{"namespace", Op_symbol, LEX_NAMESPACE, GAWKX, 0, 0},
{"next", Op_K_next, LEX_NEXT, 0, 0, 0},
{"nextfile", Op_K_nextfile, LEX_NEXTFILE, 0, 0, 0},
{"or", Op_builtin, LEX_BUILTIN, GAWKX, do_or, MPF(or)},
{"patsplit", Op_builtin, LEX_BUILTIN, GAWKX|A(2)|A(3)|A(4), do_patsplit, 0},
{"print", Op_K_print, LEX_PRINT, 0, 0, 0},
{"printf", Op_K_printf, LEX_PRINTF, 0, 0, 0},
{"rand", Op_builtin, LEX_BUILTIN, NOT_OLD|A(0), do_rand, MPF(rand)},
{"return", Op_K_return, LEX_RETURN, NOT_OLD, 0, 0},
{"rshift", Op_builtin, LEX_BUILTIN, GAWKX|A(2), do_rshift, MPF(rshift)},
{"sin", Op_builtin, LEX_BUILTIN, NOT_OLD|A(1), do_sin, MPF(sin)},
{"split", Op_builtin, LEX_BUILTIN, A(2)|A(3)|A(4), do_split, 0},
{"sprintf", Op_builtin, LEX_BUILTIN, 0, do_sprintf, 0},
{"sqrt", Op_builtin, LEX_BUILTIN, A(1), do_sqrt, MPF(sqrt)},
{"srand", Op_builtin, LEX_BUILTIN, NOT_OLD|A(0)|A(1), do_srand, MPF(srand)},
#if defined(GAWKDEBUG) || defined(ARRAYDEBUG) /* || ... */
{"stopme", Op_builtin, LEX_BUILTIN, GAWKX|A(0)|DEBUG_USE, stopme, 0},
#endif
{"strftime", Op_builtin, LEX_BUILTIN, GAWKX|A(0)|A(1)|A(2)|A(3), do_strftime, 0},
{"strtonum", Op_builtin, LEX_BUILTIN, GAWKX|A(1), do_strtonum, MPF(strtonum)},
{"sub", Op_sub_builtin, LEX_BUILTIN, NOT_OLD|A(2)|A(3), 0, 0},
{"substr", Op_builtin, LEX_BUILTIN, A(2)|A(3), do_substr, 0},
{"switch", Op_K_switch, LEX_SWITCH, GAWKX|BREAK, 0, 0},
{"system", Op_builtin, LEX_BUILTIN, NOT_OLD|A(1), do_system, 0},
{"systime", Op_builtin, LEX_BUILTIN, GAWKX|A(0), do_systime, 0},
{"tolower", Op_builtin, LEX_BUILTIN, NOT_OLD|A(1), do_tolower, 0},
{"toupper", Op_builtin, LEX_BUILTIN, NOT_OLD|A(1), do_toupper, 0},
{"typeof", Op_builtin, LEX_BUILTIN, GAWKX|A(1)|A(2), do_typeof, 0},
{"while", Op_K_while, LEX_WHILE, BREAK|CONTINUE, 0, 0},
{"xor", Op_builtin, LEX_BUILTIN, GAWKX, do_xor, MPF(xor)},
};
/* Variable containing the current shift state. */
static mbstate_t cur_mbstate;
/* Ring buffer containing current characters. */
#define MAX_CHAR_IN_RING_BUFFER 8
#define RING_BUFFER_SIZE (MAX_CHAR_IN_RING_BUFFER * MB_LEN_MAX)
static char cur_char_ring[RING_BUFFER_SIZE];
/* Index for ring buffers. */
static int cur_ring_idx;
/* This macro means that last nextc() return a singlebyte character
or 1st byte of a multibyte character. */
#define nextc_is_1stbyte (cur_char_ring[cur_ring_idx] == 1)
/* getfname --- return name of a builtin function (for pretty printing) */
const char *
getfname(NODE *(*fptr)(int), bool prepend_awk)
{
int i, j;
static char buf[100];
j = sizeof(tokentab) / sizeof(tokentab[0]);
/* linear search, no other way to do it */
for (i = 0; i < j; i++) {
if (tokentab[i].ptr == fptr || tokentab[i].ptr2 == fptr) {
if (prepend_awk && (tokentab[i].flags & GAWKX) != 0) {
sprintf(buf, "awk::%s", tokentab[i].operator);
return buf;
}
return tokentab[i].operator;
}
}
return NULL;
}
/* negate_num --- negate a number in NODE */
void
negate_num(NODE *n)
{
#ifdef HAVE_MPFR
int tval = 0;
#endif
add_sign_to_num(n, '-');
if (! is_mpg_number(n)) {
n->numbr = -n->numbr;
return;
}
#ifdef HAVE_MPFR
if (is_mpg_integer(n)) {
if (! iszero(n)) {
mpz_neg(n->mpg_i, n->mpg_i);
return;
}
/*
* 0 --> -0 conversion. Requires turning the MPG integer
* into an MPFR float.
*/
mpz_clear(n->mpg_i); /* release the integer storage */
/* Convert and fall through. */
tval = mpfr_set_d(n->mpg_numbr, 0.0, ROUND_MODE);
IEEE_FMT(n->mpg_numbr, tval);
n->flags &= ~MPZN;
n->flags |= MPFN;
}
/* mpfr float case */
tval = mpfr_neg(n->mpg_numbr, n->mpg_numbr, ROUND_MODE);
IEEE_FMT(n->mpg_numbr, tval);
#endif
}
/* add_sign_to_num --- make a constant unary plus or minus for profiling */
static void
add_sign_to_num(NODE *n, char sign)
{
if ((n->flags & NUMCONSTSTR) != 0) {
char *s;
s = n->stptr;
memmove(& s[1], & s[0], n->stlen + 1);
s[0] = sign;
n->stlen++;
}
}
/* print_included_from --- print `Included from ..' file names and locations */
static void
print_included_from()
{
int saveline, line;
SRCFILE *s;
/* suppress current file name, line # from `.. included from ..' msgs */
saveline = sourceline;
sourceline = 0;
for (s = sourcefile; s != NULL && s->stype == SRC_INC; ) {
s = s->next;
if (s == NULL || s->fd <= INVALID_HANDLE)
continue;
line = s->srclines;
/* if last token is NEWLINE, line number is off by 1. */
if (s->lasttok == NEWLINE)
line--;
msg("%s %s:%d%c",
s->prev == sourcefile ? "In file included from"
: " from",
(s->stype == SRC_INC ||
s->stype == SRC_FILE) ? s->src : "cmd. line",
line,
s->stype == SRC_INC ? ',' : ':'
);
}
sourceline = saveline;
}
/* warning_ln --- print a warning message with location */
static void
warning_ln(int line, const char *mesg, ...)
{
va_list args;
int saveline;
saveline = sourceline;
sourceline = line;
print_included_from();
va_start(args, mesg);
err(false, _("warning: "), mesg, args);
va_end(args);
sourceline = saveline;
}
/* lintwarn_ln --- print a lint warning and location */
static void
lintwarn_ln(int line, const char *mesg, ...)
{
va_list args;
int saveline;
saveline = sourceline;
sourceline = line;
print_included_from();
va_start(args, mesg);
if (lintfunc == r_fatal)
err(true, _("fatal: "), mesg, args);
else
err(false, _("warning: "), mesg, args);
va_end(args);
sourceline = saveline;
if (lintfunc == r_fatal)
gawk_exit(EXIT_FATAL);
}
/* error_ln --- print an error message and location */
static void
error_ln(int line, const char *m, ...)
{
va_list args;
int saveline;
saveline = sourceline;
sourceline = line;
print_included_from();
errcount++;
va_start(args, m);
err(false, "error: ", m, args);
va_end(args);
sourceline = saveline;
}
/* yyerror --- print a syntax error message, show where */
static void
yyerror(const char *m, ...)
{
va_list args;
const char *mesg = NULL;
char *bp, *cp;
char *scan;
char *buf;
int count;
static char end_of_file_line[] = "(END OF FILE)";
static char syntax_error[] = "syntax error";
static size_t syn_err_len = sizeof(syntax_error) - 1;
bool generic_error = (strncmp(m, syntax_error, syn_err_len) == 0);
print_included_from();
errcount++;
/* Find the current line in the input file */
if (lexptr && lexeme) {
if (thisline == NULL) {
cp = lexeme;
if (*cp == '\n') {
if (cp > lexptr_begin)
cp--;
mesg = _("unexpected newline or end of string");
}
for (; cp != lexptr_begin && *cp != '\n'; --cp)
continue;
if (*cp == '\n')
cp++;
thisline = cp;
}
/* NL isn't guaranteed */
bp = lexeme;
if (bp < thisline)
bp = thisline + 1;
while (bp < lexend && *bp && *bp != '\n')
bp++;
} else {
thisline = end_of_file_line;
bp = thisline + strlen(thisline);
}
if (lexeof && mesg == NULL && generic_error) {
msg("%s", end_of_file_line);
mesg = _("source files / command-line arguments must contain complete functions or rules");
} else
msg("%.*s", (int) (bp - thisline), thisline);
va_start(args, m);
if (mesg == NULL)
mesg = m;
count = strlen(mesg) + 1;
if (lexptr != NULL)
count += (lexeme - thisline) + 2;
ezalloc(buf, char *, count+1, "yyerror");
bp = buf;
if (lexptr != NULL) {
scan = thisline;
while (scan < lexeme)
if (*scan++ == '\t')
*bp++ = '\t';
else
*bp++ = ' ';
*bp++ = '^';
*bp++ = ' ';
}
strcpy(bp, mesg);
err(false, "", buf, args);
va_end(args);
efree(buf);
}
/* mk_program --- create a single list of instructions */
static INSTRUCTION *
mk_program()
{
INSTRUCTION *cp, *tmp;
#define begin_block rule_block[BEGIN]
#define end_block rule_block[END]
#define prog_block rule_block[Rule]
#define beginfile_block rule_block[BEGINFILE]
#define endfile_block rule_block[ENDFILE]
if (end_block == NULL)
end_block = list_create(ip_end);
else
(void) list_prepend(end_block, ip_end);
if (! in_main_context()) {
if (begin_block != NULL && prog_block != NULL)
cp = list_merge(begin_block, prog_block);
else
cp = (begin_block != NULL) ? begin_block : prog_block;
if (cp != NULL)
(void) list_merge(cp, end_block);
else
cp = end_block;
(void) list_append(cp, instruction(Op_stop));
goto out;
}
if (endfile_block == NULL)
endfile_block = list_create(ip_endfile);
else {
ip_rec->has_endfile = true;
(void) list_prepend(endfile_block, ip_endfile);
}
if (beginfile_block == NULL)
beginfile_block = list_create(ip_beginfile);
else
(void) list_prepend(beginfile_block, ip_beginfile);
if (prog_block == NULL) {
if (end_block->nexti == end_block->lasti
&& beginfile_block->nexti == beginfile_block->lasti
&& endfile_block->nexti == endfile_block->lasti
) {
/* no pattern-action and (real) end, beginfile or endfile blocks */
bcfree(ip_rec);
bcfree(ip_newfile);
ip_rec = ip_newfile = NULL;
list_append(beginfile_block, instruction(Op_after_beginfile));
(void) list_append(endfile_block, instruction(Op_after_endfile));
if (begin_block == NULL) /* no program at all */
cp = end_block;
else
cp = list_merge(begin_block, end_block);
if (interblock_comment != NULL) {
(void) list_append(cp, interblock_comment);
interblock_comment = NULL;
}
(void) list_append(cp, ip_atexit);
(void) list_append(cp, instruction(Op_stop));
/* append beginfile_block and endfile_block for sole use
* in getline without redirection (Op_K_getline).
*/
(void) list_merge(cp, beginfile_block);
(void) list_merge(cp, endfile_block);
if (outer_comment != NULL) {
cp = list_merge(list_create(outer_comment), cp);
outer_comment = NULL;
}
if (interblock_comment != NULL) {
(void) list_append(cp, interblock_comment);
interblock_comment = NULL;
}
goto out;
} else {
/* install a do-nothing prog block */
prog_block = list_create(instruction(Op_no_op));
}
}
(void) list_append(endfile_block, instruction(Op_after_endfile));
(void) list_prepend(prog_block, ip_rec);
(void) list_append(prog_block, instruction(Op_jmp));
prog_block->lasti->target_jmp = ip_rec;
list_append(beginfile_block, instruction(Op_after_beginfile));
cp = list_merge(beginfile_block, prog_block);
(void) list_prepend(cp, ip_newfile);
(void) list_merge(cp, endfile_block);
(void) list_merge(cp, end_block);
if (begin_block != NULL)
cp = list_merge(begin_block, cp);
if (outer_comment != NULL) {
cp = list_merge(list_create(outer_comment), cp);
outer_comment = NULL;
}
if (interblock_comment != NULL) {
(void) list_append(cp, interblock_comment);
interblock_comment = NULL;
}
(void) list_append(cp, ip_atexit);
(void) list_append(cp, instruction(Op_stop));
out:
/* delete the Op_list, not needed */
tmp = cp->nexti;
bcfree(cp);
return tmp;
#undef begin_block
#undef end_block
#undef prog_block
#undef beginfile_block
#undef endfile_block
}
/* parse_program --- read in the program and convert into a list of instructions */
int
parse_program(INSTRUCTION **pcode, bool from_eval)
{
int ret;
called_from_eval = from_eval;
/* pre-create non-local jump targets
* ip_end (Op_no_op) -- used as jump target for `exit'
* outside an END block.
*/
ip_end = instruction(Op_no_op);
if (! in_main_context())
ip_newfile = ip_rec = ip_atexit = ip_beginfile = ip_endfile = NULL;
else {
ip_endfile = instruction(Op_no_op);
main_beginfile = ip_beginfile = instruction(Op_no_op);
ip_rec = instruction(Op_get_record); /* target for `next', also ip_newfile */
ip_newfile = bcalloc(Op_newfile, 2, 0); /* target for `nextfile' */
ip_newfile->target_jmp = ip_end;
ip_newfile->target_endfile = ip_endfile;
(ip_newfile + 1)->target_get_record = ip_rec;
ip_rec->target_newfile = ip_newfile;
ip_atexit = instruction(Op_atexit); /* target for `exit' in END block */
}
for (sourcefile = srcfiles->next; sourcefile->stype == SRC_EXTLIB;
sourcefile = sourcefile->next)
;
lexeof = false;
lexptr = NULL;
lasttok = 0;
memset(rule_block, 0, sizeof(ruletab) * sizeof(INSTRUCTION *));
errcount = 0;
tok = tokstart != NULL ? tokstart : tokexpand();
ret = yyparse();
*pcode = mk_program();
/* avoid false source indications */
source = NULL;
sourceline = 0;
if (ret == 0) /* avoid spurious warning if parser aborted with YYABORT */
check_funcs();
if (do_posix && ! check_param_names())
errcount++;
if (args_array == NULL)
emalloc(args_array, NODE **, (max_args + 2) * sizeof(NODE *), "parse_program");
else
erealloc(args_array, NODE **, (max_args + 2) * sizeof(NODE *), "parse_program");
return (ret || errcount);
}
/* free_srcfile --- free a SRCFILE struct */
void
free_srcfile(SRCFILE *thisfile)
{
efree(thisfile->src);
efree(thisfile);
}
/* do_add_srcfile --- add one item to srcfiles */
static SRCFILE *
do_add_srcfile(enum srctype stype, char *src, char *path, SRCFILE *thisfile)
{
SRCFILE *s;
ezalloc(s, SRCFILE *, sizeof(SRCFILE), "do_add_srcfile");
s->src = estrdup(src, strlen(src));
s->fullpath = path;
s->stype = stype;
s->fd = INVALID_HANDLE;
s->next = thisfile;
s->prev = thisfile->prev;
thisfile->prev->next = s;
thisfile->prev = s;
return s;
}
/* add_srcfile --- add one item to srcfiles after checking if
* a source file exists and not already in list.
*/
SRCFILE *
add_srcfile(enum srctype stype, char *src, SRCFILE *thisfile, bool *already_included, int *errcode)
{
SRCFILE *s;
struct stat sbuf;
char *path;
int errno_val = 0;
if (already_included)
*already_included = false;
if (errcode)
*errcode = 0;
if (stype == SRC_CMDLINE || stype == SRC_STDIN)
return do_add_srcfile(stype, src, NULL, thisfile);
path = find_source(src, & sbuf, & errno_val, stype == SRC_EXTLIB);
if (path == NULL) {
if (errcode) {
*errcode = errno_val;
return NULL;
}
/* use full messages to ease translation */
fatal(stype != SRC_EXTLIB
? _("cannot open source file `%s' for reading: %s")
: _("cannot open shared library `%s' for reading: %s"),
src,
errno_val ? strerror(errno_val) : _("reason unknown"));
}
/* N.B. We do not eliminate duplicate SRC_FILE (-f) programs. */
for (s = srcfiles->next; s != srcfiles; s = s->next) {
if ((s->stype == SRC_FILE || s->stype == SRC_INC || s->stype == SRC_EXTLIB) && files_are_same(path, s)) {
if (stype == SRC_INC || stype == SRC_EXTLIB) {
/* eliminate duplicates */
if ((stype == SRC_INC) && (s->stype == SRC_FILE))
fatal(_("cannot include `%s' and use it as a program file"), src);
if (do_lint) {
int line = sourceline;
/* Kludge: the line number may be off for `@include file'.
* Since, this function is also used for '-f file' in main.c,
* sourceline > 1 check ensures that the call is at
* parse time.
*/
if (sourceline > 1 && lasttok == NEWLINE)
line--;
lintwarn_ln(line,
stype != SRC_EXTLIB
? _("already included source file `%s'")
: _("already loaded shared library `%s'"),
src);
}
efree(path);
if (already_included)
*already_included = true;
return NULL;
} else {
/* duplicates are allowed for -f */
if (s->stype == SRC_INC)
fatal(_("cannot include `%s' and use it as a program file"), src);
/* no need to scan for further matches, since
* they must be of homogeneous type */
break;
}
}
}
s = do_add_srcfile(stype, src, path, thisfile);
s->sbuf = sbuf;
s->mtime = sbuf.st_mtime;
return s;
}
/* include_source --- read program from source included using `@include' */
static bool
include_source(INSTRUCTION *file, void **srcfile_p)
{
SRCFILE *s;
char *src = file->lextok;
int errcode;
bool already_included;
*srcfile_p = NULL;
if (do_traditional || do_posix) {
error_ln(file->source_line, _("@include is a gawk extension"));
return false;
}
if (strlen(src) == 0) {
if (do_lint)
lintwarn_ln(file->source_line, _("empty filename after @include"));
return true;
}
s = add_srcfile(SRC_INC, src, sourcefile, &already_included, &errcode);
if (s == NULL) {
if (already_included)
return true;
error_ln(file->source_line,
_("cannot open source file `%s' for reading: %s"),
src, errcode ? strerror(errcode) : _("reason unknown"));
return false;
}
/* save scanner state for the current sourcefile */
sourcefile->srclines = sourceline;
sourcefile->lexptr = lexptr;
sourcefile->lexend = lexend;
sourcefile->lexptr_begin = lexptr_begin;
sourcefile->lexeme = lexeme;
sourcefile->lasttok = lasttok;
sourcefile->namespace = current_namespace;
/* included file becomes the current source */
sourcefile = s;
lexptr = NULL;
sourceline = 0;
source = NULL;
lasttok = 0;
lexeof = false;
eof_warned = false;
current_namespace = awk_namespace;
*srcfile_p = (void *) s;
return true;
}
/* load_library --- load a shared library */
static bool
load_library(INSTRUCTION *file, void **srcfile_p)
{
SRCFILE *s;
char *src = file->lextok;
int errcode;
bool already_included;
*srcfile_p = NULL;
if (do_traditional || do_posix) {
error_ln(file->source_line, _("@load is a gawk extension"));
return false;
}
if (strlen(src) == 0) {
if (do_lint)
lintwarn_ln(file->source_line, _("empty filename after @load"));
return true;
}
if (do_pretty_print && ! do_profile) {
// create a fake one, don't try to open the file
s = do_add_srcfile(SRC_EXTLIB, src, src, sourcefile);
} else {
s = add_srcfile(SRC_EXTLIB, src, sourcefile, &already_included, &errcode);
if (s == NULL) {
if (already_included)
return true;
error_ln(file->source_line,
_("cannot open shared library `%s' for reading: %s"),
src, errcode ? strerror(errcode) : _("reason unknown"));
return false;
}
load_ext(s->fullpath);
}
*srcfile_p = (void *) s;
return true;
}
/* next_sourcefile --- read program from the next source in srcfiles */
static void
next_sourcefile()
{
static int (*closefunc)(int fd) = NULL;
if (closefunc == NULL) {
char *cp = getenv("AWKREADFUNC");
/* If necessary, one day, test value for different functions. */
if (cp == NULL)
closefunc = close;
else
closefunc = one_line_close;
}
/*
* This won't be true if there's an invalid character in
* the source file or source string (e.g., user typo).
* Previous versions of gawk did not core dump in such a
* case.
*
* assert(lexeof == true);
*/
lexeof = false;
eof_warned = false;
sourcefile->srclines = sourceline; /* total no of lines in current file */
if (sourcefile->fd > INVALID_HANDLE) {
if (sourcefile->fd != fileno(stdin)) /* safety */
(*closefunc)(sourcefile->fd);
sourcefile->fd = INVALID_HANDLE;
}
if (sourcefile->buf != NULL) {
efree(sourcefile->buf);
sourcefile->buf = NULL;
sourcefile->lexptr_begin = NULL;
}
while ((sourcefile = sourcefile->next) != NULL) {
if (sourcefile == srcfiles)
return;
if (sourcefile->stype != SRC_EXTLIB)
break;
}
if (sourcefile->lexptr_begin != NULL) {
/* resume reading from already opened file (postponed to process '@include') */
lexptr = sourcefile->lexptr;
lexend = sourcefile->lexend;
lasttok = sourcefile->lasttok;
lexptr_begin = sourcefile->lexptr_begin;
lexeme = sourcefile->lexeme;
sourceline = sourcefile->srclines;
source = sourcefile->src;
set_current_namespace(sourcefile->namespace);
} else {
lexptr = NULL;
sourceline = 0;
source = NULL;
lasttok = 0;
set_current_namespace(awk_namespace);
}
}
/* get_src_buf --- read the next buffer of source program */
static char *
get_src_buf()
{
int n;
char *scan;
bool newfile;
int savelen;
struct stat sbuf;
/*
* No argument prototype on readfunc on purpose,
* avoids problems with some ancient systems where
* the types of arguments to read() aren't up to date.
*/
static ssize_t (*readfunc)() = 0;
if (readfunc == NULL) {
char *cp = getenv("AWKREADFUNC");
/* If necessary, one day, test value for different functions. */
if (cp == NULL)
/*
* cast is to remove warnings on systems with
* different return types for read.
*/
readfunc = ( ssize_t(*)() ) read;
else
readfunc = read_one_line;
}
newfile = false;
if (sourcefile == srcfiles)
return NULL;
if (sourcefile->stype == SRC_CMDLINE) {
if (sourcefile->bufsize == 0) {
sourcefile->bufsize = strlen(sourcefile->src);
lexptr = lexptr_begin = lexeme = sourcefile->src;
lexend = lexptr + sourcefile->bufsize;
sourceline = 1;
if (sourcefile->bufsize == 0) {
/*
* Yet Another Special case:
* gawk '' /path/name
* Sigh.
*/
static bool warned = false;
if (do_lint && ! warned) {
warned = true;
lintwarn(_("empty program text on command line"));
}
lexeof = true;
}
} else if (sourcefile->buf == NULL && *(lexptr-1) != '\n') {
/*
* The following goop is to ensure that the source
* ends with a newline and that the entire current
* line is available for error messages.
*/
int offset;
char *buf;
offset = lexptr - lexeme;
for (scan = lexeme; scan > lexptr_begin; scan--)
if (*scan == '\n') {
scan++;
break;
}
savelen = lexptr - scan;
emalloc(buf, char *, savelen + 1, "get_src_buf");
memcpy(buf, scan, savelen);
thisline = buf;
lexptr = buf + savelen;
*lexptr = '\n';
lexeme = lexptr - offset;
lexptr_begin = buf;
lexend = lexptr + 1;
sourcefile->buf = buf;
} else
lexeof = true;
return lexptr;
}
if (sourcefile->fd <= INVALID_HANDLE) {
int fd;
int l;
source = sourcefile->src;
if (source == NULL)
return NULL;
fd = srcopen(sourcefile);
if (fd <= INVALID_HANDLE) {
char *in;
/* suppress file name and line no. in error mesg */
in = source;
source = NULL;
error(_("cannot open source file `%s' for reading: %s"),
in, strerror(errno));
errcount++;
lexeof = true;
return sourcefile->src;
}
sourcefile->fd = fd;
l = optimal_bufsize(fd, &sbuf);
/*
* Make sure that something silly like
* AWKBUFSIZE=8 make check
* works ok.
*/
#define A_DECENT_BUFFER_SIZE 128
if (l < A_DECENT_BUFFER_SIZE)
l = A_DECENT_BUFFER_SIZE;
#undef A_DECENT_BUFFER_SIZE
sourcefile->bufsize = l;
newfile = true;
emalloc(sourcefile->buf, char *, sourcefile->bufsize, "get_src_buf");
memset(sourcefile->buf, '\0', sourcefile->bufsize); // keep valgrind happy
lexptr = lexptr_begin = lexeme = sourcefile->buf;
savelen = 0;
sourceline = 1;
thisline = NULL;
} else {
/*
* Here, we retain the current source line in the beginning of the buffer.
*/
int offset;
for (scan = lexeme; scan > lexptr_begin; scan--)
if (*scan == '\n') {
scan++;
break;
}
savelen = lexptr - scan;
offset = lexptr - lexeme;
if (savelen > 0) {
/*
* Need to make sure we have room left for reading new text;
* grow the buffer (by doubling, an arbitrary choice), if the retained line
* takes up more than a certain percentage (50%, again an arbitrary figure)
* of the available space.
*/
if (savelen > sourcefile->bufsize / 2) { /* long line or token */
sourcefile->bufsize *= 2;
erealloc(sourcefile->buf, char *, sourcefile->bufsize, "get_src_buf");
scan = sourcefile->buf + (scan - lexptr_begin);
lexptr_begin = sourcefile->buf;
}
thisline = lexptr_begin;
memmove(thisline, scan, savelen);
lexptr = thisline + savelen;
lexeme = lexptr - offset;
} else {
savelen = 0;
lexptr = lexeme = lexptr_begin;
thisline = NULL;
}
}
n = (*readfunc)(sourcefile->fd, lexptr, sourcefile->bufsize - savelen);
if (n == -1) {
error(_("cannot read source file `%s': %s"),
source, strerror(errno));
errcount++;
lexeof = true;
} else {
lexend = lexptr + n;
if (n == 0) {
static bool warned = false;
if (do_lint && newfile && ! warned) {
warned = true;
sourceline = 0;
lintwarn(_("source file `%s' is empty"), source);
}
lexeof = true;
}
}
return sourcefile->buf;
}
/* tokadd --- add a character to the token buffer */
#define tokadd(x) (*tok++ = (x), tok == tokend ? tokexpand() : tok)
/* tokexpand --- grow the token buffer */
static char *
tokexpand()
{
static int toksize;
int tokoffset;
if (tokstart != NULL) {
tokoffset = tok - tokstart;
toksize *= 2;
erealloc(tokstart, char *, toksize, "tokexpand");
tok = tokstart + tokoffset;
} else {
toksize = 60;
emalloc(tokstart, char *, toksize, "tokexpand");
tok = tokstart;
}
tokend = tokstart + toksize;
return tok;
}
/* check_bad_char --- fatal if c isn't allowed in gawk source code */
/*
* The error message was inspired by someone who decided to put
* a physical \0 byte into the source code to see what would
* happen and then filed a bug report about it. Sigh.
*/
static void
check_bad_char(int c)
{
/* allow escapes. needed for autoconf. bleah. */
switch (c) {
case '\a':
case '\b':
case '\f':
case '\n':
case '\r':
case '\t':
return;
default:
break;
}
if (iscntrl(c) && ! isspace(c))
// This is a PEBKAC error, but we'll be nice and not say so.
fatal(_("error: invalid character '\\%03o' in source code"), c & 0xFF);
}
/* nextc --- get the next input character */
// For namespaces, -e chunks must be syntactic units.
#define NO_CONTINUE_SOURCE_STRINGS 1
static int
nextc(bool check_for_bad)
{
if (gawk_mb_cur_max > 1) {
again:
#ifdef NO_CONTINUE_SOURCE_STRINGS
if (lexeof)
return END_FILE;
#else
if (lexeof) {
if (sourcefile->next == srcfiles)
return END_FILE;
else
next_sourcefile();
}
#endif
if (lexptr == NULL || lexptr >= lexend) {
if (get_src_buf())
goto again;
return END_SRC;
}
/* Update the buffer index. */
cur_ring_idx = (cur_ring_idx == RING_BUFFER_SIZE - 1)? 0 :
cur_ring_idx + 1;
/* Did we already check the current character? */
if (cur_char_ring[cur_ring_idx] == 0) {
/* No, we need to check the next character on the buffer. */
int idx, work_ring_idx = cur_ring_idx;
mbstate_t tmp_state;
size_t mbclen;
for (idx = 0; lexptr + idx < lexend; idx++) {
tmp_state = cur_mbstate;
mbclen = mbrlen(lexptr, idx + 1, &tmp_state);
if (mbclen == 1 || mbclen == (size_t)-1 || mbclen == 0) {
/* It is a singlebyte character, non-complete multibyte
character or EOF. We treat it as a singlebyte
character. */
cur_char_ring[work_ring_idx] = 1;
break;
} else if (mbclen == (size_t)-2) {
/* It is not a complete multibyte character. */
cur_char_ring[work_ring_idx] = idx + 1;
} else {
/* mbclen > 1 */
cur_char_ring[work_ring_idx] = mbclen;
break;
}
work_ring_idx = (work_ring_idx == RING_BUFFER_SIZE - 1)?
0 : work_ring_idx + 1;
}
cur_mbstate = tmp_state;
/* Put a mark on the position on which we write next character. */
work_ring_idx = (work_ring_idx == RING_BUFFER_SIZE - 1)?
0 : work_ring_idx + 1;
cur_char_ring[work_ring_idx] = 0;
}
if (check_for_bad || *lexptr == '\0')
check_bad_char(*lexptr);
return (int) (unsigned char) *lexptr++;
} else {
do {
#ifdef NO_CONTINUE_SOURCE_STRINGS
if (lexeof)
return END_FILE;
#else
if (lexeof) {
if (sourcefile->next == srcfiles)
return END_FILE;
else
next_sourcefile();
}
#endif
if (lexptr && lexptr < lexend) {
if (check_for_bad || *lexptr == '\0')
check_bad_char(*lexptr);
return ((int) (unsigned char) *lexptr++);
}
} while (get_src_buf());
return END_SRC;
}
}
#undef NO_CONTINUE_SOURCE_STRINGS
/* pushback --- push a character back on the input */
static inline void
pushback(void)
{
if (gawk_mb_cur_max > 1)
cur_ring_idx = (cur_ring_idx == 0)? RING_BUFFER_SIZE - 1 :
cur_ring_idx - 1;
(! lexeof && lexptr && lexptr > lexptr_begin ? lexptr-- : lexptr);
}
/*
* get_comment --- collect comment text.
* Flag = EOL_COMMENT for end-of-line comments.
* Flag = BLOCK_COMMENT for self-contained comments.
*/
static int
get_comment(enum commenttype flag, INSTRUCTION **comment_instruction)
{
int c;
int sl;
char *p1;
char *p2;
tok = tokstart;
tokadd('#');
sl = sourceline;
while (true) {
while ((c = nextc(false)) != '\n' && c != END_FILE) {
/* ignore \r characters */
if (c != '\r')
tokadd(c);
}
if (flag == EOL_COMMENT) {
/* comment at end of line. */
if (c == '\n')
tokadd(c);
break;
}
if (c == '\n') {
tokadd(c);
sourceline++;
do {
c = nextc(false);
if (c == '\n') {
sourceline++;
tokadd(c);
}
} while (isspace(c) && c != END_FILE);
if (c == END_FILE)
break;
else if (c != '#') {
pushback();
sourceline--;
break;
} else
tokadd(c);
} else
break;
}
/* remove any trailing blank lines (consecutive \n) from comment */
p1 = tok - 1;
p2 = tok - 2;
while (*p1 == '\n' && *p2 == '\n') {
p1--;
p2--;
tok--;
}
(*comment_instruction) = bcalloc(Op_comment, 1, sl);
(*comment_instruction)->source_file = source;
(*comment_instruction)->memory = make_str_node(tokstart, tok - tokstart, 0);
(*comment_instruction)->memory->comment_type = flag;
return c;
}
/* allow_newline --- allow newline after &&, ||, ? and : */
static void
allow_newline(INSTRUCTION **new_comment)
{
int c;
for (;;) {
c = nextc(true);
if (c == END_FILE) {
pushback();
break;
}
if (c == '#') {
if (do_pretty_print && ! do_profile) {
/* collect comment byte code iff doing pretty print but not profiling. */
c = get_comment(EOL_COMMENT, new_comment);
} else {
while ((c = nextc(false)) != '\n' && c != END_FILE)
continue;
}
if (c == END_FILE) {
pushback();
break;
}
}
if (c == '\n')
sourceline++;
if (! isspace(c)) {
pushback();
break;
}
}
}
/* newline_eof --- return newline or EOF as needed and adjust variables */
/*
* This routine used to be a macro, however GCC 4.6.2 warned about
* the result of a computation not being used. Converting to a function
* removes the warnings.
*/
static int
newline_eof()
{
/* NB: a newline at end does not start a source line. */
if (lasttok != NEWLINE) {
pushback();
if (do_lint && ! eof_warned) {
lintwarn(_("source file does not end in newline"));
eof_warned = true;
}
sourceline++;
return NEWLINE;
}
sourceline--;
eof_warned = false;
return LEX_EOF;
}
/* yylex --- Read the input and turn it into tokens. */
static int
#ifdef USE_EBCDIC
yylex_ebcdic(void)
#else
yylex(void)
#endif
{
int c;
bool seen_e = false; /* These are for numbers */
bool seen_point = false;
bool esc_seen; /* for literal strings */
int mid;
int base;
static bool did_newline = false;
char *tokkey;
bool inhex = false;
bool intlstr = false;
AWKNUM d;
bool collecting_typed_regexp = false;
static int qm_col_count = 0;
#define GET_INSTRUCTION(op) bcalloc(op, 1, sourceline)
#define NEWLINE_EOF newline_eof()
yylval = (INSTRUCTION *) NULL;
if (lasttok == SUBSCRIPT) {
lasttok = 0;
return SUBSCRIPT;
}
if (lasttok == LEX_EOF) /* error earlier in current source, must give up !! */
return 0;
c = nextc(! want_regexp);
if (c == END_SRC)
return 0;
if (c == END_FILE)
return lasttok = NEWLINE_EOF;
pushback();
#if defined __EMX__
/*
* added for OS/2's extproc feature of cmd.exe
* (like #! in BSD sh)
*/
if (strncasecmp(lexptr, "extproc ", 8) == 0) {
while (*lexptr && *lexptr != '\n')
lexptr++;
}
#endif
lexeme = lexptr;
thisline = NULL;
collect_regexp:
if (want_regexp) {
int in_brack = 0; /* count brackets, [[:alnum:]] allowed */
int b_index = -1;
int cur_index = 0;
/*
* Here is what's ok with brackets:
*
* [..[..] []] [^]] [.../...]
* [...\[...] [...\]...] [...\/...]
*
* (Remember that all of the above are inside /.../)
*
* The code for \ handles \[, \] and \/.
*
* Otherwise, track the first open [ position, and if
* an embedded ] occurs, allow it to pass through
* if it's right after the first [ or after [^.
*
* Whew!
*/
want_regexp = false;
tok = tokstart;
for (;;) {
c = nextc(false);
cur_index = tok - tokstart;
if (gawk_mb_cur_max == 1 || nextc_is_1stbyte) switch (c) {
case '[':
if (nextc(false) == ':' || in_brack == 0) {
in_brack++;
if (in_brack == 1)
b_index = tok - tokstart;
}
pushback();
break;
case ']':
if (in_brack > 0
&& (cur_index == b_index + 1
|| (cur_index == b_index + 2 && tok[-1] == '^')))
; /* do nothing */
else {
in_brack--;
if (in_brack == 0)
b_index = -1;
}
break;
case '\\':
if ((c = nextc(false)) == END_FILE) {
pushback();
yyerror(_("unterminated regexp ends with `\\' at end of file"));
goto end_regexp; /* kludge */
}
if (c == '\r') /* allow MS-DOS files. bleah */
c = nextc(true);
if (c == '\n') {
sourceline++;
continue;
} else {
tokadd('\\');
tokadd(c);
continue;
}
break;
case '/': /* end of the regexp */
if (in_brack > 0)
break;
end_regexp:
yylval = GET_INSTRUCTION(Op_token);
yylval->lextok = estrdup(tokstart, tok - tokstart);
if (do_lint) {
int peek = nextc(true);
pushback();
if (peek == 'i' || peek == 's') {
if (source)
lintwarn(
_("%s: %d: tawk regex modifier `/.../%c' doesn't work in gawk"),
source, sourceline, peek);
else
lintwarn(
_("tawk regex modifier `/.../%c' doesn't work in gawk"),
peek);
}
}
if (collecting_typed_regexp) {
collecting_typed_regexp = false;
lasttok = TYPED_REGEXP;
} else
lasttok = REGEXP;
return lasttok;
case '\n':
pushback();
yyerror(_("unterminated regexp"));
goto end_regexp; /* kludge */
case END_FILE:
pushback();
yyerror(_("unterminated regexp at end of file"));
goto end_regexp; /* kludge */
}
tokadd(c);
}
}
retry:
/* skipping \r is a hack, but windows is just too pervasive. sigh. */
while ((c = nextc(true)) == ' ' || c == '\t' || c == '\r')
continue;
lexeme = lexptr ? lexptr - 1 : lexptr;
thisline = NULL;
tok = tokstart;
if (gawk_mb_cur_max == 1 || nextc_is_1stbyte)
switch (c) {
case END_SRC:
return 0;
case END_FILE:
return lasttok = NEWLINE_EOF;
case '\n':
sourceline++;
return lasttok = NEWLINE;
case '#': /* it's a comment */
yylval = NULL;
if (do_pretty_print && ! do_profile) {
/*
* Collect comment byte code iff doing pretty print
* but not profiling.
*/
INSTRUCTION *new_comment;
if (lasttok == NEWLINE || lasttok == 0)
c = get_comment(BLOCK_COMMENT, & new_comment);
else
c = get_comment(EOL_COMMENT, & new_comment);
yylval = new_comment;
if (c == END_FILE) {
pushback();
return lasttok = NEWLINE;
}
} else {
while ((c = nextc(false)) != '\n') {
if (c == END_FILE)
return lasttok = NEWLINE_EOF;
}
}
sourceline++;
return lasttok = NEWLINE;
case '@':
c = nextc(true);
if (c == '/') {
want_regexp = true;
collecting_typed_regexp = true;
goto collect_regexp;
}
pushback();
at_seen = true;
return lasttok = '@';
case '\\':
#ifdef RELAXED_CONTINUATION
/*
* This code purports to allow comments and/or whitespace
* after the `\' at the end of a line used for continuation.
* Use it at your own risk. We think it's a bad idea, which
* is why it's not on by default.
*/
yylval = NULL;
if (! do_traditional) {
INSTRUCTION *new_comment;
/* strip trailing white-space and/or comment */
while ((c = nextc(true)) == ' ' || c == '\t' || c == '\r')
continue;
if (c == '#') {
static bool warned = false;
if (do_lint && ! warned) {
warned = true;
lintwarn(
_("use of `\\ #...' line continuation is not portable"));
}
if (do_pretty_print && ! do_profile) {
c = get_comment(EOL_COMMENT, & new_comment);
yylval = new_comment;
return lasttok = c;
} else {
while ((c = nextc(false)) != '\n')
if (c == END_FILE)
break;
}
}
pushback();
}
#endif /* RELAXED_CONTINUATION */
c = nextc(true);
if (c == '\r') /* allow MS-DOS files. bleah */
c = nextc(true);
if (c == '\n') {
sourceline++;
goto retry;
} else {
yyerror(_("backslash not last character on line"));
return lasttok = LEX_EOF;
}
break;
case '?':
qm_col_count++;
// fall through
case ':':
yylval = GET_INSTRUCTION(Op_cond_exp);
if (qm_col_count > 0) {
if (! do_posix) {
INSTRUCTION *new_comment = NULL;
allow_newline(& new_comment);
yylval->comment = new_comment;
}
if (c == ':')
qm_col_count--;
}
return lasttok = c;
/*
* in_parens is undefined unless we are parsing a print
* statement (in_print), but why bother with a check?
*/
case ')':
in_parens--;
return lasttok = c;
case '(':
in_parens++;
return lasttok = c;
case '$':
yylval = GET_INSTRUCTION(Op_field_spec);
return lasttok = c;
case '{':
if (++in_braces == 1)
firstline = sourceline;
case ';':
case ',':
case '[':
return lasttok = c;
case ']':
c = nextc(true);
pushback();
if (c == '[') {
if (do_traditional)
fatal(_("multidimensional arrays are a gawk extension"));
if (do_lint_extensions)
lintwarn(_("multidimensional arrays are a gawk extension"));
yylval = GET_INSTRUCTION(Op_sub_array);
lasttok = ']';
} else {
yylval = GET_INSTRUCTION(Op_subscript);
lasttok = SUBSCRIPT; /* end of subscripts */
}
return ']';
case '*':
if ((c = nextc(true)) == '=') {
yylval = GET_INSTRUCTION(Op_assign_times);
return lasttok = ASSIGNOP;
} else if (do_posix) {
pushback();
yylval = GET_INSTRUCTION(Op_times);
return lasttok = '*';
} else if (c == '*') {
/* make ** and **= aliases for ^ and ^= */
static bool did_warn_op = false, did_warn_assgn = false;
if (nextc(true) == '=') {
if (! did_warn_assgn) {
did_warn_assgn = true;
if (do_lint)
lintwarn(_("POSIX does not allow operator `%s'"), "**=");
if (do_lint_old)
lintwarn(_("operator `%s' is not supported in old awk"), "**=");
}
yylval = GET_INSTRUCTION(Op_assign_exp);
return ASSIGNOP;
} else {
pushback();
if (! did_warn_op) {
did_warn_op = true;
if (do_lint)
lintwarn(_("POSIX does not allow operator `%s'"), "**");
if (do_lint_old)
lintwarn(_("operator `%s' is not supported in old awk"), "**");
}
yylval = GET_INSTRUCTION(Op_exp);
return lasttok = '^';
}
}
pushback();
yylval = GET_INSTRUCTION(Op_times);
return lasttok = '*';
case '/':
if (nextc(false) == '=') {
pushback();
return lasttok = SLASH_BEFORE_EQUAL;
}
pushback();
yylval = GET_INSTRUCTION(Op_quotient);
return lasttok = '/';
case '%':
if (nextc(true) == '=') {
yylval = GET_INSTRUCTION(Op_assign_mod);
return lasttok = ASSIGNOP;
}
pushback();
yylval = GET_INSTRUCTION(Op_mod);
return lasttok = '%';
case '^':
{
static bool did_warn_op = false, did_warn_assgn = false;
if (nextc(true) == '=') {
if (do_lint_old && ! did_warn_assgn) {
did_warn_assgn = true;
lintwarn(_("operator `%s' is not supported in old awk"), "^=");
}
yylval = GET_INSTRUCTION(Op_assign_exp);
return lasttok = ASSIGNOP;
}
pushback();
if (do_lint_old && ! did_warn_op) {
did_warn_op = true;
lintwarn(_("operator `%s' is not supported in old awk"), "^");
}
yylval = GET_INSTRUCTION(Op_exp);
return lasttok = '^';
}
case '+':
if ((c = nextc(true)) == '=') {
yylval = GET_INSTRUCTION(Op_assign_plus);
return lasttok = ASSIGNOP;
}
if (c == '+') {
yylval = GET_INSTRUCTION(Op_symbol);
return lasttok = INCREMENT;
}
pushback();
yylval = GET_INSTRUCTION(Op_plus);
return lasttok = '+';
case '!':
if ((c = nextc(true)) == '=') {
yylval = GET_INSTRUCTION(Op_notequal);
return lasttok = RELOP;
}
if (c == '~') {
yylval = GET_INSTRUCTION(Op_nomatch);
return lasttok = MATCHOP;
}
pushback();
yylval = GET_INSTRUCTION(Op_symbol);
return lasttok = '!';
case '<':
if (nextc(true) == '=') {
yylval = GET_INSTRUCTION(Op_leq);
return lasttok = RELOP;
}
yylval = GET_INSTRUCTION(Op_less);
pushback();
return lasttok = '<';
case '=':
if (nextc(true) == '=') {
yylval = GET_INSTRUCTION(Op_equal);
return lasttok = RELOP;
}
yylval = GET_INSTRUCTION(Op_assign);
pushback();
return lasttok = ASSIGN;
case '>':
if ((c = nextc(true)) == '=') {
yylval = GET_INSTRUCTION(Op_geq);
return lasttok = RELOP;
} else if (c == '>') {
yylval = GET_INSTRUCTION(Op_symbol);
yylval->redir_type = redirect_append;
return lasttok = IO_OUT;
}
pushback();
if (in_print && in_parens == 0) {
yylval = GET_INSTRUCTION(Op_symbol);
yylval->redir_type = redirect_output;
return lasttok = IO_OUT;
}
yylval = GET_INSTRUCTION(Op_greater);
return lasttok = '>';
case '~':
yylval = GET_INSTRUCTION(Op_match);
return lasttok = MATCHOP;
case '}':
/*
* Added did newline stuff. Easier than
* hacking the grammar.
*/
if (did_newline) {
did_newline = false;
if (--in_braces == 0)
lastline = sourceline;
return lasttok = c;
}
did_newline = true;
--lexptr; /* pick up } next time */
return lasttok = NEWLINE;
case '"':
string:
esc_seen = false;
/*
* Allow any kind of junk in quoted string,
* so pass false to nextc().
*/
while ((c = nextc(false)) != '"') {
if (c == '\n') {
pushback();
yyerror(_("unterminated string"));
return lasttok = LEX_EOF;
}
if ((gawk_mb_cur_max == 1 || nextc_is_1stbyte) &&
c == '\\') {
c = nextc(true);
if (c == '\r') /* allow MS-DOS files. bleah */
c = nextc(true);
if (c == '\n') {
if (do_posix)
fatal(_("POSIX does not allow physical newlines in string values"));
else if (do_lint)
lintwarn(_("backslash string continuation is not portable"));
sourceline++;
continue;
}
esc_seen = true;
if (! want_source || c != '"')
tokadd('\\');
}
if (c == END_FILE) {
pushback();
yyerror(_("unterminated string"));
return lasttok = LEX_EOF;
}
tokadd(c);
}
yylval = GET_INSTRUCTION(Op_token);
if (want_source) {
yylval->lextok = estrdup(tokstart, tok - tokstart);
return lasttok = FILENAME;
}
yylval->opcode = Op_push_i;
yylval->memory = make_str_node(tokstart,
tok - tokstart, esc_seen ? SCAN : 0);
if (intlstr) {
yylval->memory->flags |= INTLSTR;
intlstr = false;
if (do_intl)
dumpintlstr(yylval->memory->stptr, yylval->memory->stlen);
}
return lasttok = YSTRING;
case '-':
if ((c = nextc(true)) == '=') {
yylval = GET_INSTRUCTION(Op_assign_minus);
return lasttok = ASSIGNOP;
}
if (c == '-') {
yylval = GET_INSTRUCTION(Op_symbol);
return lasttok = DECREMENT;
}
pushback();
yylval = GET_INSTRUCTION(Op_minus);
return lasttok = '-';
case '.':
c = nextc(true);
pushback();
if (! isdigit(c))
return lasttok = '.';
else
c = '.';
/* FALL THROUGH */
case '0':
case '1':
case '2':
case '3':
case '4':
case '5':
case '6':
case '7':
case '8':
case '9':
/* It's a number */
for (;;) {
bool gotnumber = false;
tokadd(c);
switch (c) {
case 'x':
case 'X':
if (do_traditional)
goto done;
if (tok == tokstart + 2) {
int peek = nextc(true);
if (isxdigit(peek)) {
inhex = true;
pushback(); /* following digit */
} else {
pushback(); /* x or X */
goto done;
}
}
break;
case '.':
/* period ends exponent part of floating point number */
if (seen_point || seen_e) {
gotnumber = true;
break;
}
seen_point = true;
break;
case 'e':
case 'E':
if (inhex)
break;
if (seen_e) {
gotnumber = true;
break;
}
seen_e = true;
if ((c = nextc(true)) == '-' || c == '+') {
int c2 = nextc(true);
if (isdigit(c2)) {
tokadd(c);
tokadd(c2);
} else {
pushback(); /* non-digit after + or - */
pushback(); /* + or - */
pushback(); /* e or E */
}
} else if (! isdigit(c)) {
pushback(); /* character after e or E */
pushback(); /* e or E */
} else {
pushback(); /* digit */
}
break;
case 'a':
case 'A':
case 'b':
case 'B':
case 'c':
case 'C':
case 'D':
case 'd':
case 'f':
case 'F':
if (do_traditional || ! inhex)
goto done;
/* fall through */
case '0':
case '1':
case '2':
case '3':
case '4':
case '5':
case '6':
case '7':
case '8':
case '9':
break;
default:
done:
gotnumber = true;
}
if (gotnumber)
break;
c = nextc(true);
}
pushback();
tokadd('\0');
yylval = GET_INSTRUCTION(Op_push_i);
base = 10;
if (! do_traditional) {
base = get_numbase(tokstart, strlen(tokstart)-1, false);
if (do_lint) {
if (base == 8)
lintwarn("numeric constant `%.*s' treated as octal",
(int) strlen(tokstart)-1, tokstart);
else if (base == 16)
lintwarn("numeric constant `%.*s' treated as hexadecimal",
(int) strlen(tokstart)-1, tokstart);
}
}
#ifdef HAVE_MPFR
if (do_mpfr) {
NODE *r;
if (! seen_point && ! seen_e) {
r = mpg_integer();
mpg_strtoui(r->mpg_i, tokstart, strlen(tokstart), NULL, base);
errno = 0;
} else {
int tval;
r = mpg_float();
tval = mpfr_strtofr(r->mpg_numbr, tokstart, NULL, base, ROUND_MODE);
errno = 0;
IEEE_FMT(r->mpg_numbr, tval);
}
yylval->memory = set_profile_text(r, tokstart, strlen(tokstart)-1);
return lasttok = YNUMBER;
}
#endif
if (base != 10)
d = nondec2awknum(tokstart, strlen(tokstart)-1, NULL);
else
d = atof(tokstart);
yylval->memory = set_profile_text(make_number(d), tokstart, strlen(tokstart) - 1);
if (d <= INT32_MAX && d >= INT32_MIN && d == (int32_t) d)
yylval->memory->flags |= NUMINT;
return lasttok = YNUMBER;
case '&':
if ((c = nextc(true)) == '&') {
yylval = GET_INSTRUCTION(Op_and);
INSTRUCTION *new_comment = NULL;
allow_newline(& new_comment);
yylval->comment = new_comment;
return lasttok = LEX_AND;
}
pushback();
yylval = GET_INSTRUCTION(Op_symbol);
return lasttok = '&';
case '|':
if ((c = nextc(true)) == '|') {
yylval = GET_INSTRUCTION(Op_or);
INSTRUCTION *new_comment = NULL;
allow_newline(& new_comment);
yylval->comment = new_comment;
return lasttok = LEX_OR;
} else if (! do_traditional && c == '&') {
yylval = GET_INSTRUCTION(Op_symbol);
yylval->redir_type = redirect_twoway;
return lasttok = (in_print && in_parens == 0 ? IO_OUT : IO_IN);
}
pushback();
if (in_print && in_parens == 0) {
yylval = GET_INSTRUCTION(Op_symbol);
yylval->redir_type = redirect_pipe;
return lasttok = IO_OUT;
} else {
yylval = GET_INSTRUCTION(Op_symbol);
yylval->redir_type = redirect_pipein;
return lasttok = IO_IN;
}
}
if (! is_letter(c)) {
yyerror(_("invalid char '%c' in expression"), c);
return lasttok = LEX_EOF;
}
/*
* Lots of fog here. Consider:
*
* print "xyzzy"$_"foo"
*
* Without the check for ` lasttok != '$' ', this is parsed as
*
* print "xxyzz" $(_"foo")
*
* With the check, it is "correctly" parsed as three
* string concatenations. Sigh. This seems to be
* "more correct", but this is definitely one of those
* occasions where the interactions are funny.
*/
if (! do_traditional && c == '_' && lasttok != '$') {
if ((c = nextc(true)) == '"') {
intlstr = true;
goto string;
}
pushback();
c = '_';
}
/* it's some type of name-type-thing. Find its length. */
tok = tokstart;
while (c != END_FILE && is_identchar(c)) {
tokadd(c);
c = nextc(true);
if (! do_traditional && c == ':') {
int peek = nextc(true);
if (peek == ':') { // saw identifier::
tokadd(c);
tokadd(c);
c = nextc(true);
} else
pushback();
// then continue around the loop, c == ':'
}
}
tokadd('\0');
pushback();
(void) validate_qualified_name(tokstart);
/* See if it is a special token. */
if ((mid = check_qualified_special(tokstart)) >= 0) {
static int warntab[sizeof(tokentab) / sizeof(tokentab[0])];
int class = tokentab[mid].class;
switch (class) {
case LEX_EVAL:
case LEX_INCLUDE:
case LEX_LOAD:
case LEX_NAMESPACE:
if (lasttok != '@')
goto out;
default:
break;
}
/* allow parameter names to shadow the names of gawk extension built-ins */
if ((tokentab[mid].flags & GAWKX) != 0) {
NODE *f;
switch (want_param_names) {
case FUNC_HEADER:
/* in header, defining parameter names */
goto out;
case FUNC_BODY:
/* in body, name must be in symbol table for it to be a parameter */
if ((f = lookup(tokstart)) != NULL) {
if (f->type == Node_builtin_func)
break;
else
goto out;
}
/* else
fall through */
case DONT_CHECK:
/* regular code */
break;
default:
cant_happen();
break;
}
}
if (do_lint) {
if (do_lint_extensions && (tokentab[mid].flags & GAWKX) != 0 && (warntab[mid] & GAWKX) == 0) {
lintwarn(_("`%s' is a gawk extension"),
tokentab[mid].operator);
warntab[mid] |= GAWKX;
}
if ((tokentab[mid].flags & NOT_POSIX) != 0 && (warntab[mid] & NOT_POSIX) == 0) {
lintwarn(_("POSIX does not allow `%s'"),
tokentab[mid].operator);
warntab[mid] |= NOT_POSIX;
}
}
if (do_lint_old && (tokentab[mid].flags & NOT_OLD) != 0
&& (warntab[mid] & NOT_OLD) == 0
) {
lintwarn(_("`%s' is not supported in old awk"),
tokentab[mid].operator);
warntab[mid] |= NOT_OLD;
}
if ((tokentab[mid].flags & BREAK) != 0)
break_allowed++;
if ((tokentab[mid].flags & CONTINUE) != 0)
continue_allowed++;
switch (class) {
case LEX_NAMESPACE:
case LEX_INCLUDE:
case LEX_LOAD:
want_source = true;
break;
case LEX_EVAL:
if (in_main_context())
goto out;
emalloc(tokkey, char *, tok - tokstart + 1, "yylex");
tokkey[0] = '@';
memcpy(tokkey + 1, tokstart, tok - tokstart);
yylval = GET_INSTRUCTION(Op_token);
yylval->lextok = tokkey;
break;
case LEX_FUNCTION:
case LEX_BEGIN:
case LEX_END:
case LEX_BEGINFILE:
case LEX_ENDFILE:
yylval = bcalloc(tokentab[mid].value, 4, sourceline);
break;
case LEX_FOR:
case LEX_WHILE:
case LEX_DO:
case LEX_SWITCH:
if (! do_pretty_print)
return lasttok = class;
/* fall through */
case LEX_CASE:
yylval = bcalloc(tokentab[mid].value, 2, sourceline);
break;
/*
* These must be checked here, due to the LALR nature of the parser,
* the rules for continue and break may not be reduced until after
* a token that increments the xxx_allowed varibles is seen. Bleah.
*/
case LEX_CONTINUE:
if (! continue_allowed) {
error_ln(sourceline,
_("`continue' is not allowed outside a loop"));
errcount++;
}
goto make_instruction;
case LEX_BREAK:
if (! break_allowed) {
error_ln(sourceline,
_("`break' is not allowed outside a loop or switch"));
errcount++;
}
goto make_instruction;
default:
make_instruction:
yylval = GET_INSTRUCTION(tokentab[mid].value);
if (class == LEX_BUILTIN || class == LEX_LENGTH)
yylval->builtin_idx = mid;
break;
}
return lasttok = class;
}
out:
if (want_param_names == FUNC_HEADER)
tokkey = estrdup(tokstart, tok - tokstart - 1);
else
tokkey = qualify_name(tokstart, tok - tokstart - 1);
if (*lexptr == '(') {
yylval = bcalloc(Op_token, 2, sourceline);
yylval->lextok = tokkey;
return lasttok = FUNC_CALL;
} else {
static bool goto_warned = false;
yylval = GET_INSTRUCTION(Op_token);
yylval->lextok = tokkey;
#define SMART_ALECK 1
if (SMART_ALECK
&& do_lint
&& ! goto_warned
&& tolower(tokkey[0]) == 'g'
&& strcasecmp(tokkey, "goto") == 0) {
goto_warned = true;
lintwarn(_("`goto' considered harmful!"));
}
return lasttok = NAME;
}
#undef GET_INSTRUCTION
#undef NEWLINE_EOF
}
/* It's EBCDIC in a Bison grammar, run for the hills!
Or, convert single-character tokens coming out of yylex() from EBCDIC to
ASCII values on-the-fly so that the parse tables need not be regenerated
for EBCDIC systems. */
#ifdef USE_EBCDIC
static int
yylex(void)
{
static char etoa_xlate[256];
static bool do_etoa_init = true;
int tok;
if (do_etoa_init)
{
for (tok = 0; tok < 256; tok++)
etoa_xlate[tok] = (char) tok;
#ifdef HAVE___ETOA_L
/* IBM helpfully provides this function. */
__etoa_l(etoa_xlate, sizeof(etoa_xlate));
#else
# error "An EBCDIC-to-ASCII translation function is needed for this system"
#endif
do_etoa_init = false;
}
tok = yylex_ebcdic();
if (tok >= 0 && tok <= 0xFF)
tok = etoa_xlate[tok];
return tok;
}
#endif /* USE_EBCDIC */
/* snode --- instructions for builtin functions. Checks for arg. count
and supplies defaults where possible. */
static INSTRUCTION *
snode(INSTRUCTION *subn, INSTRUCTION *r)
{
INSTRUCTION *arg;
INSTRUCTION *ip;
NODE *n;
int nexp = 0;
int args_allowed;
int idx = r->builtin_idx;
if (subn != NULL) {
INSTRUCTION *tp;
for (tp = subn->nexti; tp; tp = tp->nexti) {
tp = tp->lasti;
nexp++;
}
assert(nexp > 0);
}
/* check against how many args. are allowed for this builtin */
args_allowed = tokentab[idx].flags & ARGS;
if (args_allowed && (args_allowed & A(nexp)) == 0) {
yyerror(_("%d is invalid as number of arguments for %s"),
nexp, tokentab[idx].operator);
return NULL;
}
/* special processing for sub, gsub and gensub */
if (tokentab[idx].value == Op_sub_builtin) {
const char *operator = tokentab[idx].operator;
r->sub_flags = 0;
arg = subn->nexti; /* first arg list */
(void) mk_rexp(arg);
if (strcmp(operator, "gensub") != 0) {
/* sub and gsub */
if (strcmp(operator, "gsub") == 0)
r->sub_flags |= GSUB;
arg = arg->lasti->nexti; /* 2nd arg list */
if (nexp == 2) {
INSTRUCTION *expr;
expr = list_create(instruction(Op_push_i));
expr->nexti->memory = set_profile_text(make_number(0.0), "0", 1);
(void) mk_expression_list(subn,
list_append(expr, instruction(Op_field_spec)));
}
arg = arg->lasti->nexti; /* third arg list */
ip = arg->lasti;
if (ip->opcode == Op_push_i) {
if (do_lint)
lintwarn(_("%s: string literal as last argument of substitute has no effect"),
operator);
r->sub_flags |= LITERAL;
} else {
if (make_assignable(ip) == NULL)
yyerror(_("%s third parameter is not a changeable object"),
operator);
else
ip->do_reference = true;
}
r->expr_count = count_expressions(&subn, false);
ip = subn->lasti;
(void) list_append(subn, r);
/* add after_assign code */
if (ip->opcode == Op_push_lhs && ip->memory->type == Node_var && ip->memory->var_assign) {
(void) list_append(subn, instruction(Op_var_assign));
subn->lasti->assign_ctxt = Op_sub_builtin;
subn->lasti->assign_var = ip->memory->var_assign;
} else if (ip->opcode == Op_field_spec_lhs) {
(void) list_append(subn, instruction(Op_field_assign));
subn->lasti->assign_ctxt = Op_sub_builtin;
subn->lasti->field_assign = (Func_ptr) 0;
ip->target_assign = subn->lasti;
} else if (ip->opcode == Op_subscript_lhs) {
(void) list_append(subn, instruction(Op_subscript_assign));
subn->lasti->assign_ctxt = Op_sub_builtin;
}
return subn;
} else {
/* gensub */
r->sub_flags |= GENSUB;
if (nexp == 3) {
ip = instruction(Op_push_i);
ip->memory = set_profile_text(make_number(0.0), "0", 1);
(void) mk_expression_list(subn,
list_append(list_create(ip), instruction(Op_field_spec)));
}
r->expr_count = count_expressions(&subn, false);
return list_append(subn, r);
}
}
#ifdef HAVE_MPFR
/* N.B.: If necessary, add special processing for alternate builtin, below */
if (do_mpfr && tokentab[idx].ptr2)
r->builtin = tokentab[idx].ptr2;
else
#endif
r->builtin = tokentab[idx].ptr;
/* special case processing for a few builtins */
if (r->builtin == do_length) {
if (nexp == 0) {
/* no args. Use $0 */
INSTRUCTION *list;
r->expr_count = 1;
list = list_create(r);
(void) list_prepend(list, instruction(Op_field_spec));
(void) list_prepend(list, instruction(Op_push_i));
list->nexti->memory = set_profile_text(make_number(0.0), "0", 1);
return list;
} else {
arg = subn->nexti;
if (arg->nexti == arg->lasti && arg->nexti->opcode == Op_push)
arg->nexti->opcode = Op_push_arg; /* argument may be array */
}
} else if (r->builtin == do_isarray) {
arg = subn->nexti;
if (arg->nexti == arg->lasti && arg->nexti->opcode == Op_push)
arg->nexti->opcode = Op_push_arg_untyped; /* argument may be untyped */
} else if (r->builtin == do_typeof) {
arg = subn->nexti;
if (arg->nexti == arg->lasti && arg->nexti->opcode == Op_push)
arg->nexti->opcode = Op_push_arg_untyped; /* argument may be untyped */
if (nexp == 2) { /* 2nd argument there */
arg = subn->nexti->lasti->nexti; /* 2nd arg list */
ip = arg->lasti;
if (ip->opcode == Op_push)
ip->opcode = Op_push_array;
}
#ifdef SUPPLY_INTDIV
} else if (r->builtin == do_intdiv
#ifdef HAVE_MPFR
|| r->builtin == MPF(intdiv)
#endif
) {
arg = subn->nexti->lasti->nexti->lasti->nexti; /* 3rd arg list */
ip = arg->lasti;
if (ip->opcode == Op_push)
ip->opcode = Op_push_array;
#endif /* SUPPLY_INTDIV */
} else if (r->builtin == do_match) {
static bool warned = false;
arg = subn->nexti->lasti->nexti; /* 2nd arg list */
(void) mk_rexp(arg);
if (nexp == 3) { /* 3rd argument there */
if (do_lint_extensions && ! warned) {
warned = true;
lintwarn(_("match: third argument is a gawk extension"));
}
if (do_traditional) {
yyerror(_("match: third argument is a gawk extension"));
return NULL;
}
arg = arg->lasti->nexti; /* third arg list */
ip = arg->lasti;
if (/*ip == arg->nexti && */ ip->opcode == Op_push)
ip->opcode = Op_push_array;
}
} else if (r->builtin == do_split) {
arg = subn->nexti->lasti->nexti; /* 2nd arg list */
ip = arg->lasti;
if (ip->opcode == Op_push)
ip->opcode = Op_push_array;
if (nexp == 2) {
INSTRUCTION *expr;
expr = list_create(instruction(Op_push));
expr->nexti->memory = FS_node;
(void) mk_expression_list(subn, expr);
}
arg = arg->lasti->nexti;
n = mk_rexp(arg);
if (nexp == 2)
n->re_flags |= FS_DFLT;
if (nexp == 4) {
arg = arg->lasti->nexti;
ip = arg->lasti;
if (ip->opcode == Op_push)
ip->opcode = Op_push_array;
}
} else if (r->builtin == do_patsplit) {
arg = subn->nexti->lasti->nexti; /* 2nd arg list */
ip = arg->lasti;
if (ip->opcode == Op_push)
ip->opcode = Op_push_array;
if (nexp == 2) {
INSTRUCTION *expr;
expr = list_create(instruction(Op_push));
expr->nexti->memory = FPAT_node;
(void) mk_expression_list(subn, expr);
}
arg = arg->lasti->nexti;
n = mk_rexp(arg);
if (nexp == 4) {
arg = arg->lasti->nexti;
ip = arg->lasti;
if (ip->opcode == Op_push)
ip->opcode = Op_push_array;
}
} else if (r->builtin == do_close) {
static bool warned = false;
if (nexp == 2) {
if (do_lint_extensions && ! warned) {
warned = true;
lintwarn(_("close: second argument is a gawk extension"));
}
if (do_traditional) {
yyerror(_("close: second argument is a gawk extension"));
return NULL;
}
}
} else if (do_intl /* --gen-po */
&& r->builtin == do_dcgettext /* dcgettext(...) */
&& subn->nexti->lasti->opcode == Op_push_i /* 1st arg is constant */
&& (subn->nexti->lasti->memory->flags & STRING) != 0) { /* it's a string constant */
/* ala xgettext, dcgettext("some string" ...) dumps the string */
NODE *str = subn->nexti->lasti->memory;
if ((str->flags & INTLSTR) != 0)
warning(_("use of dcgettext(_\"...\") is incorrect: remove leading underscore"));
/* don't dump it, the lexer already did */
else
dumpintlstr(str->stptr, str->stlen);
} else if (do_intl /* --gen-po */
&& r->builtin == do_dcngettext /* dcngettext(...) */
&& subn->nexti->lasti->opcode == Op_push_i /* 1st arg is constant */
&& (subn->nexti->lasti->memory->flags & STRING) != 0 /* it's a string constant */
&& subn->nexti->lasti->nexti->lasti->opcode == Op_push_i /* 2nd arg is constant too */
&& (subn->nexti->lasti->nexti->lasti->memory->flags & STRING) != 0) { /* it's a string constant */
/* ala xgettext, dcngettext("some string", "some plural" ...) dumps the string */
NODE *str1 = subn->nexti->lasti->memory;
NODE *str2 = subn->nexti->lasti->nexti->lasti->memory;
if (((str1->flags | str2->flags) & INTLSTR) != 0)
warning(_("use of dcngettext(_\"...\") is incorrect: remove leading underscore"));
else
dumpintlstr2(str1->stptr, str1->stlen, str2->stptr, str2->stlen);
} else if (r->builtin == do_asort || r->builtin == do_asorti) {
arg = subn->nexti; /* 1st arg list */
ip = arg->lasti;
if (ip->opcode == Op_push)
ip->opcode = Op_push_array;
if (nexp >= 2) {
arg = ip->nexti;
ip = arg->lasti;
if (ip->opcode == Op_push)
ip->opcode = Op_push_array;
}
}
else if (r->builtin == do_index) {
arg = subn->nexti->lasti->nexti; /* 2nd arg list */
ip = arg->lasti;
if (ip->opcode == Op_match_rec || ip->opcode == Op_push_re)
fatal(_("index: regexp constant as second argument is not allowed"));
}
#ifdef ARRAYDEBUG
else if (r->builtin == do_adump) {
ip = subn->nexti->lasti;
if (ip->opcode == Op_push)
ip->opcode = Op_push_array;
}
#endif
if (subn != NULL) {
r->expr_count = count_expressions(&subn, false);
return list_append(subn, r);
}
r->expr_count = 0;
return list_create(r);
}
/* parms_shadow --- check if parameters shadow globals */
static int
parms_shadow(INSTRUCTION *pc, bool *shadow)
{
int pcount, i;
bool ret = false;
NODE *func, *fp;
char *fname;
func = pc->func_body;
fname = func->vname;
fp = func->fparms;
#if 0 /* can't happen, already exited if error ? */
if (fname == NULL || func == NULL) /* error earlier */
return false;
#endif
pcount = func->param_cnt;
if (pcount == 0) /* no args, no problem */
return 0;
source = pc->source_file;
sourceline = pc->source_line;
/*
* Use warning() and not lintwarn() so that can warn
* about all shadowed parameters.
*/
for (i = 0; i < pcount; i++) {
if (lookup(fp[i].param) != NULL) {
warning(
_("function `%s': parameter `%s' shadows global variable"),
fname, fp[i].param);
ret = true;
}
}
*shadow |= ret;
return 0;
}
/* valinfo --- dump var info */
void
valinfo(NODE *n, Func_print print_func, FILE *fp)
{
if (n == Nnull_string)
print_func(fp, "uninitialized scalar\n");
else if ((n->flags & REGEX) != 0)
print_func(fp, "@/%.*s/\n", n->stlen, n->stptr);
else if ((n->flags & STRING) != 0) {
pp_string_fp(print_func, fp, n->stptr, n->stlen, '"', false);
print_func(fp, "\n");
} else if ((n->flags & NUMBER) != 0) {
#ifdef HAVE_MPFR
if (is_mpg_float(n))
print_func(fp, "%s\n", mpg_fmt("%.17R*g", ROUND_MODE, n->mpg_numbr));
else if (is_mpg_integer(n))
print_func(fp, "%s\n", mpg_fmt("%Zd", n->mpg_i));
else
#endif
print_func(fp, "%.17g\n", n->numbr);
} else
print_func(fp, "?? flags %s\n", flags2str(n->flags));
}
/* dump_vars --- dump the symbol table */
void
dump_vars(const char *fname)
{
FILE *fp;
NODE **vars;
if (fname == NULL)
fp = stderr;
else if (strcmp(fname, "-") == 0)
fp = stdout;
else if ((fp = fopen(fname, "w")) == NULL) {
warning(_("could not open `%s' for writing: %s"), fname, strerror(errno));
warning(_("sending variable list to standard error"));
fp = stderr;
}
vars = variable_list();
print_vars(vars, fprintf, fp);
efree(vars);
if (fp != stdout && fp != stderr && fclose(fp) != 0)
warning(_("%s: close failed: %s"), fname, strerror(errno));
}
/* dump_funcs --- print all functions */
void
dump_funcs()
{
NODE **funcs;
funcs = function_list(true);
(void) foreach_func(funcs, (int (*)(INSTRUCTION *, void *)) pp_func, (void *) 0);
efree(funcs);
}
/* shadow_funcs --- check all functions for parameters that shadow globals */
void
shadow_funcs()
{
static int calls = 0;
bool shadow = false;
NODE **funcs;
if (calls++ != 0)
fatal(_("shadow_funcs() called twice!"));
funcs = function_list(true);
(void) foreach_func(funcs, (int (*)(INSTRUCTION *, void *)) parms_shadow, & shadow);
efree(funcs);
/* End with fatal if the user requested it. */
if (shadow && lintfunc == r_fatal)
lintwarn(_("there were shadowed variables."));
}
/* mk_function --- finalize function definition node; remove parameters
* out of the symbol table.
*/
static INSTRUCTION *
mk_function(INSTRUCTION *fi, INSTRUCTION *def)
{
NODE *thisfunc;
thisfunc = fi->func_body;
assert(thisfunc != NULL);
/* add any pre-function comment to start of action for profile.c */
if (interblock_comment != NULL) {
interblock_comment->source_line = 0;
merge_comments(interblock_comment, fi->comment);
fi->comment = interblock_comment;
interblock_comment = NULL;
}
/*
* Add an implicit return at end;
* also used by 'return' command in debugger
*/
(void) list_append(def, instruction(Op_push_i));
def->lasti->memory = dupnode(Nnull_string);
(void) list_append(def, instruction(Op_K_return));
if (trailing_comment != NULL) {
(void) list_append(def, trailing_comment);
trailing_comment = NULL;
}
if (do_pretty_print) {
fi[3].nexti = namespace_chain;
namespace_chain = NULL;
(void) list_prepend(def, instruction(Op_exec_count));
}
/* fi->opcode = Op_func */
(fi + 1)->firsti = def->nexti;
(fi + 1)->lasti = def->lasti;
(fi + 2)->first_line = fi->source_line;
(fi + 2)->last_line = lastline;
fi->nexti = def->nexti;
bcfree(def);
(void) list_append(rule_list, fi + 1); /* debugging */
/* update lint table info */
func_use(thisfunc->vname, FUNC_DEFINE);
/* remove params from symbol table */
remove_params(thisfunc);
return fi;
}
/*
* install_function:
* install function name in the symbol table.
* Extra work, build up and install a list of the parameter names.
*/
static int
install_function(char *fname, INSTRUCTION *fi, INSTRUCTION *plist)
{
NODE *r, *f;
int pcount = 0;
r = lookup(fname);
if (r != NULL) {
error_ln(fi->source_line, _("function name `%s' previously defined"), fname);
return -1;
}
if (plist != NULL)
pcount = plist->lasti->param_count + 1;
f = install_symbol(fname, Node_func);
if (f->vname != fname) {
// DON'T free fname, it's done later
fname = f->vname;
}
fi->func_body = f;
f->param_cnt = pcount;
f->code_ptr = fi;
f->fparms = NULL;
if (pcount > 0) {
char **pnames;
pnames = check_params(fname, pcount, plist); /* frees plist */
f->fparms = make_params(pnames, pcount);
efree(pnames);
install_params(f);
}
return 0;
}
/* check_params --- build a list of function parameter names after
* making sure that the names are valid and there are no duplicates.
*/
static char **
check_params(char *fname, int pcount, INSTRUCTION *list)
{
INSTRUCTION *p, *np;
int i, j;
char *name;
char **pnames;
assert(pcount > 0);
emalloc(pnames, char **, pcount * sizeof(char *), "check_params");
for (i = 0, p = list->nexti; p != NULL; i++, p = np) {
np = p->nexti;
name = p->lextok;
p->lextok = NULL;
if (strcmp(name, fname) == 0) {
/* check for function foo(foo) { ... }. bleah. */
error_ln(p->source_line,
_("function `%s': cannot use function name as parameter name"), fname);
} else if (is_std_var(name)) {
error_ln(p->source_line,
_("function `%s': cannot use special variable `%s' as a function parameter"),
fname, name);
} else if (strchr(name, ':') != NULL)
error_ln(p->source_line,
_("function `%s': parameter `%s' cannot contain a namespace"),
fname, name);
/* check for duplicate parameters */
for (j = 0; j < i; j++) {
if (strcmp(name, pnames[j]) == 0) {
error_ln(p->source_line,
_("function `%s': parameter #%d, `%s', duplicates parameter #%d"),
fname, i + 1, name, j + 1);
}
}
pnames[i] = name;
bcfree(p);
}
bcfree(list);
return pnames;
}
#ifdef HASHSIZE
undef HASHSIZE
#endif
#define HASHSIZE 1021
static struct fdesc {
char *name;
short used;
short defined;
short extension;
struct fdesc *next;
} *ftable[HASHSIZE];
/* func_use --- track uses and definitions of functions */
static void
func_use(const char *name, enum defref how)
{
struct fdesc *fp;
int len;
int ind;
len = strlen(name);
ind = hash(name, len, HASHSIZE, NULL);
for (fp = ftable[ind]; fp != NULL; fp = fp->next)
if (strcmp(fp->name, name) == 0)
goto update_value;
/* not in the table, fall through to allocate a new one */
ezalloc(fp, struct fdesc *, sizeof(struct fdesc), "func_use");
emalloc(fp->name, char *, len + 1, "func_use");
strcpy(fp->name, name);
fp->next = ftable[ind];
ftable[ind] = fp;
update_value:
if (how == FUNC_DEFINE)
fp->defined++;
else if (how == FUNC_EXT) {
fp->defined++;
fp->extension++;
} else
fp->used++;
}
/* track_ext_func --- add an extension function to the table */
void
track_ext_func(const char *name)
{
func_use(name, FUNC_EXT);
}
/* check_funcs --- verify functions that are called but not defined */
static void
check_funcs()
{
struct fdesc *fp, *next;
int i;
if (! in_main_context())
goto free_mem;
for (i = 0; i < HASHSIZE; i++) {
for (fp = ftable[i]; fp != NULL; fp = fp->next) {
if (do_lint && ! fp->extension) {
/*
* Making this not a lint check and
* incrementing * errcount breaks old code.
* Sigh.
*/
if (fp->defined == 0)
lintwarn(_("function `%s' called but never defined"),
fp->name);
if (fp->used == 0)
lintwarn(_("function `%s' defined but never called directly"),
fp->name);
}
}
}
free_mem:
/* now let's free all the memory */
for (i = 0; i < HASHSIZE; i++) {
for (fp = ftable[i]; fp != NULL; fp = next) {
next = fp->next;
efree(fp->name);
efree(fp);
}
ftable[i] = NULL;
}
}
/* param_sanity --- look for parameters that are regexp constants */
static void
param_sanity(INSTRUCTION *arglist)
{
INSTRUCTION *argl, *arg;
int i = 1;
if (arglist == NULL)
return;
for (argl = arglist->nexti; argl; ) {
arg = argl->lasti;
if (arg->opcode == Op_match_rec)
warning_ln(arg->source_line,
_("regexp constant for parameter #%d yields boolean value"), i);
argl = arg->nexti;
i++;
}
}
/* variable --- make sure NAME is in the symbol table */
NODE *
variable(int location, char *name, NODETYPE type)
{
NODE *r;
if ((r = lookup(name)) != NULL) {
if (r->type == Node_func || r->type == Node_ext_func )
error_ln(location, _("function `%s' called with space between name and `(',\nor used as a variable or an array"),
r->vname);
} else {
/* not found */
return install_symbol(name, type);
}
efree(name);
return r;
}
/* make_regnode --- make a regular expression node */
NODE *
make_regnode(int type, NODE *exp)
{
NODE *n;
assert(type == Node_regex || type == Node_dynregex);
getnode(n);
memset(n, 0, sizeof(NODE));
n->type = type;
n->re_cnt = 1;
if (type == Node_regex) {
n->re_reg[0] = make_regexp(exp->stptr, exp->stlen, false, true, false);
if (n->re_reg[0] == NULL) {
freenode(n);
return NULL;
}
n->re_exp = exp;
n->re_flags = CONSTANT;
}
return n;
}
/* mk_rexp --- make a regular expression constant */
static NODE *
mk_rexp(INSTRUCTION *list)
{
INSTRUCTION *ip;
ip = list->nexti;
if (ip == list->lasti && ip->opcode == Op_match_rec)
ip->opcode = Op_push_re;
else if (ip == list->lasti && ip->opcode == Op_push_re)
; /* do nothing --- @/.../ */
else {
ip = instruction(Op_push_re);
ip->memory = make_regnode(Node_dynregex, NULL);
ip->nexti = list->lasti->nexti;
list->lasti->nexti = ip;
list->lasti = ip;
}
return ip->memory;
}
#ifndef NO_LINT
/* isnoeffect --- when used as a statement, has no side effects */
static int
isnoeffect(OPCODE type)
{
switch (type) {
case Op_times:
case Op_times_i:
case Op_quotient:
case Op_quotient_i:
case Op_mod:
case Op_mod_i:
case Op_plus:
case Op_plus_i:
case Op_minus:
case Op_minus_i:
case Op_subscript:
case Op_concat:
case Op_exp:
case Op_exp_i:
case Op_unary_minus:
case Op_field_spec:
case Op_and_final:
case Op_or_final:
case Op_equal:
case Op_notequal:
case Op_less:
case Op_greater:
case Op_leq:
case Op_geq:
case Op_match:
case Op_nomatch:
case Op_match_rec:
case Op_not:
case Op_in_array:
return true;
default:
break; /* keeps gcc -Wall happy */
}
return false;
}
#endif /* NO_LINT */
/* make_assignable --- make this operand an assignable one if posiible */
static INSTRUCTION *
make_assignable(INSTRUCTION *ip)
{
switch (ip->opcode) {
case Op_push:
ip->opcode = Op_push_lhs;
return ip;
case Op_field_spec:
ip->opcode = Op_field_spec_lhs;
return ip;
case Op_subscript:
ip->opcode = Op_subscript_lhs;
return ip;
default:
break; /* keeps gcc -Wall happy */
}
return NULL;
}
/* stopme --- for debugging */
NODE *
stopme(int nargs ATTRIBUTE_UNUSED)
{
return make_number(0.0);
}
/* dumpintlstr --- write out an initial .po file entry for the string */
static void
dumpintlstr(const char *str, size_t len)
{
char *cp;
/* See the GNU gettext distribution for details on the file format */
if (source != NULL) {
/* ala the gettext sources, remove leading `./'s */
for (cp = source; cp[0] == '.' && cp[1] == '/'; cp += 2)
continue;
printf("#: %s:%d\n", cp, sourceline);
}
printf("msgid ");
pp_string_fp(fprintf, stdout, str, len, '"', true);
putchar('\n');
printf("msgstr \"\"\n\n");
fflush(stdout);
}
/* dumpintlstr2 --- write out an initial .po file entry for the string and its plural */
static void
dumpintlstr2(const char *str1, size_t len1, const char *str2, size_t len2)
{
char *cp;
/* See the GNU gettext distribution for details on the file format */
if (source != NULL) {
/* ala the gettext sources, remove leading `./'s */
for (cp = source; cp[0] == '.' && cp[1] == '/'; cp += 2)
continue;
printf("#: %s:%d\n", cp, sourceline);
}
printf("msgid ");
pp_string_fp(fprintf, stdout, str1, len1, '"', true);
putchar('\n');
printf("msgid_plural ");
pp_string_fp(fprintf, stdout, str2, len2, '"', true);
putchar('\n');
printf("msgstr[0] \"\"\nmsgstr[1] \"\"\n\n");
fflush(stdout);
}
/* mk_binary --- instructions for binary operators */
static INSTRUCTION *
mk_binary(INSTRUCTION *s1, INSTRUCTION *s2, INSTRUCTION *op)
{
INSTRUCTION *ip1,*ip2;
AWKNUM res;
ip2 = s2->nexti;
if (s2->lasti == ip2 && ip2->opcode == Op_push_i) {
/* do any numeric constant folding */
ip1 = s1->nexti;
if (do_optimize
&& ip1 == s1->lasti && ip1->opcode == Op_push_i
&& (ip1->memory->flags & (MPFN|MPZN|STRCUR|STRING)) == 0
&& (ip2->memory->flags & (MPFN|MPZN|STRCUR|STRING)) == 0
) {
NODE *n1 = ip1->memory, *n2 = ip2->memory;
res = force_number(n1)->numbr;
(void) force_number(n2);
switch (op->opcode) {
case Op_times:
res *= n2->numbr;
break;
case Op_quotient:
if (n2->numbr == 0.0) {
/* don't fatalize, allow parsing rest of the input */
error_ln(op->source_line, _("division by zero attempted"));
goto regular;
}
res /= n2->numbr;
break;
case Op_mod:
if (n2->numbr == 0.0) {
/* don't fatalize, allow parsing rest of the input */
error_ln(op->source_line, _("division by zero attempted in `%%'"));
goto regular;
}
#ifdef HAVE_FMOD
res = fmod(res, n2->numbr);
#else /* ! HAVE_FMOD */
(void) modf(res / n2->numbr, &res);
res = n1->numbr - res * n2->numbr;
#endif /* ! HAVE_FMOD */
break;
case Op_plus:
res += n2->numbr;
break;
case Op_minus:
res -= n2->numbr;
break;
case Op_exp:
res = calc_exp(res, n2->numbr);
break;
default:
goto regular;
}
op->opcode = Op_push_i;
// We don't need to call set_profile_text() here since
// optimizing is disabled when doing pretty printing.
op->memory = make_number(res);
unref(n1);
unref(n2);
bcfree(ip1);
bcfree(ip2);
bcfree(s1);
bcfree(s2);
return list_create(op);
} else {
/* do basic arithmetic optimisation */
/* convert (Op_push_i Node_val) + (Op_plus) to (Op_plus_i Node_val) */
switch (op->opcode) {
case Op_times:
op->opcode = Op_times_i;
break;
case Op_quotient:
op->opcode = Op_quotient_i;
break;
case Op_mod:
op->opcode = Op_mod_i;
break;
case Op_plus:
op->opcode = Op_plus_i;
break;
case Op_minus:
op->opcode = Op_minus_i;
break;
case Op_exp:
op->opcode = Op_exp_i;
break;
default:
goto regular;
}
op->memory = ip2->memory;
bcfree(ip2);
bcfree(s2); /* Op_list */
return list_append(s1, op);
}
}
regular:
/* append lists s1, s2 and add `op' bytecode */
(void) list_merge(s1, s2);
return list_append(s1, op);
}
/* mk_boolean --- instructions for boolean and, or */
static INSTRUCTION *
mk_boolean(INSTRUCTION *left, INSTRUCTION *right, INSTRUCTION *op)
{
INSTRUCTION *tp;
OPCODE opc, final_opc;
opc = op->opcode; /* Op_and or Op_or */
final_opc = (opc == Op_or) ? Op_or_final : Op_and_final;
add_lint(right, LINT_assign_in_cond);
tp = left->lasti;
if (tp->opcode != final_opc) { /* x || y */
list_append(right, instruction(final_opc));
add_lint(left, LINT_assign_in_cond);
(void) list_append(left, op);
left->lasti->target_jmp = right->lasti;
/* NB: target_stmt points to previous Op_and(Op_or) in a chain;
* target_stmt only used in the parser (see below).
*/
left->lasti->target_stmt = left->lasti;
right->lasti->target_stmt = left->lasti;
} else { /* optimization for x || y || z || ... */
INSTRUCTION *ip;
op->opcode = final_opc;
(void) list_append(right, op);
op->target_stmt = tp;
tp->opcode = opc;
tp->target_jmp = op;
/* update jump targets */
for (ip = tp->target_stmt; ; ip = ip->target_stmt) {
assert(ip->opcode == opc);
assert(ip->target_jmp == tp);
/* if (ip->opcode == opc && ip->target_jmp == tp) */
ip->target_jmp = op;
if (ip->target_stmt == ip)
break;
}
}
return list_merge(left, right);
}
/* mk_condition --- if-else and conditional */
static INSTRUCTION *
mk_condition(INSTRUCTION *cond, INSTRUCTION *ifp, INSTRUCTION *true_branch,
INSTRUCTION *elsep, INSTRUCTION *false_branch)
{
/*
* ----------------
* cond
* ----------------
* t: [Op_jmp_false f ]
* ----------------
* true_branch
*
* ----------------
* [Op_jmp y]
* ----------------
* f:
* false_branch
* ----------------
* y: [Op_no_op]
* ----------------
*/
INSTRUCTION *ip;
bool setup_else_part = true;
if (false_branch == NULL) {
false_branch = list_create(instruction(Op_no_op));
if (elsep == NULL) { /* else { } */
setup_else_part = false;
}
} else {
/* assert(elsep != NULL); */
/* avoid a series of no_op's: if .. else if .. else if .. */
if (false_branch->lasti->opcode != Op_no_op)
(void) list_append(false_branch, instruction(Op_no_op));
}
if (setup_else_part) {
if (do_pretty_print) {
(void) list_prepend(false_branch, elsep);
false_branch->nexti->branch_end = false_branch->lasti;
(void) list_prepend(false_branch, instruction(Op_exec_count));
} else
bcfree(elsep);
}
(void) list_prepend(false_branch, instruction(Op_jmp));
false_branch->nexti->target_jmp = false_branch->lasti;
add_lint(cond, LINT_assign_in_cond);
ip = list_append(cond, instruction(Op_jmp_false));
ip->lasti->target_jmp = false_branch->nexti->nexti;
if (do_pretty_print) {
(void) list_prepend(ip, ifp);
(void) list_append(ip, instruction(Op_exec_count));
ip->nexti->branch_if = ip->lasti;
ip->nexti->branch_else = false_branch->nexti;
} else
bcfree(ifp);
if (true_branch != NULL)
list_merge(ip, true_branch);
return list_merge(ip, false_branch);
}
enum defline { FIRST_LINE, LAST_LINE };
/* find_line -- find the first(last) line in a list of (pattern) instructions */
static int
find_line(INSTRUCTION *pattern, enum defline what)
{
INSTRUCTION *ip;
int lineno = 0;
for (ip = pattern->nexti; ip; ip = ip->nexti) {
if (what == LAST_LINE) {
if (ip->source_line > lineno)
lineno = ip->source_line;
} else { /* FIRST_LINE */
if (ip->source_line > 0
&& (lineno == 0 || ip->source_line < lineno))
lineno = ip->source_line;
}
if (ip == pattern->lasti)
break;
}
assert(lineno > 0);
return lineno;
}
/* append_rule --- pattern-action instructions */
static INSTRUCTION *
append_rule(INSTRUCTION *pattern, INSTRUCTION *action)
{
/*
* ----------------
* pattern
* ----------------
* [Op_jmp_false f ]
* ----------------
* action
* ----------------
* f: [Op_no_op ]
* ----------------
*/
INSTRUCTION *rp;
INSTRUCTION *tp;
INSTRUCTION *ip;
if (rule != Rule) {
rp = pattern;
if (do_pretty_print) {
rp[3].nexti = namespace_chain;
namespace_chain = NULL;
(void) list_append(action, instruction(Op_no_op));
}
(rp + 1)->firsti = action->nexti;
(rp + 1)->lasti = action->lasti;
(rp + 2)->first_line = pattern->source_line;
(rp + 2)->last_line = lastline;
ip = list_prepend(action, rp);
if (interblock_comment != NULL) {
ip = list_prepend(ip, interblock_comment);
interblock_comment = NULL;
}
} else {
rp = bcalloc(Op_rule, 4, 0);
rp->in_rule = Rule;
rp->source_file = source;
tp = instruction(Op_no_op);
if (do_pretty_print) {
rp[3].nexti = namespace_chain;
namespace_chain = NULL;
}
if (pattern == NULL) {
/* assert(action != NULL); */
if (do_pretty_print)
(void) list_prepend(action, instruction(Op_exec_count));
(rp + 1)->firsti = action->nexti;
(rp + 1)->lasti = tp;
(rp + 2)->first_line = firstline;
(rp + 2)->last_line = lastline;
rp->source_line = firstline;
ip = list_prepend(list_append(action, tp), rp);
} else {
(void) list_append(pattern, instruction(Op_jmp_false));
pattern->lasti->target_jmp = tp;
(rp + 2)->first_line = find_line(pattern, FIRST_LINE);
rp->source_line = (rp + 2)->first_line;
if (action == NULL) {
(rp + 2)->last_line = find_line(pattern, LAST_LINE);
action = list_create(instruction(Op_K_print_rec));
if (do_pretty_print)
action = list_prepend(action, instruction(Op_exec_count));
} else
(rp + 2)->last_line = lastline;
if (interblock_comment != NULL) { // was after previous action
pattern = list_prepend(pattern, interblock_comment);
interblock_comment = NULL;
}
if (do_pretty_print) {
pattern = list_prepend(pattern, instruction(Op_exec_count));
action = list_prepend(action, instruction(Op_exec_count));
}
(rp + 1)->firsti = action->nexti;
(rp + 1)->lasti = tp;
ip = list_append(
list_merge(list_prepend(pattern, rp),
action),
tp);
}
}
list_append(rule_list, rp + 1);
if (rule_block[rule] == NULL)
rule_block[rule] = ip;
else
(void) list_merge(rule_block[rule], ip);
return rule_block[rule];
}
/* mk_assignment --- assignment bytecodes */
static INSTRUCTION *
mk_assignment(INSTRUCTION *lhs, INSTRUCTION *rhs, INSTRUCTION *op)
{
INSTRUCTION *tp;
INSTRUCTION *ip;
tp = lhs->lasti;
switch (tp->opcode) {
case Op_field_spec:
tp->opcode = Op_field_spec_lhs;
break;
case Op_subscript:
tp->opcode = Op_subscript_lhs;
break;
case Op_push:
case Op_push_array:
tp->opcode = Op_push_lhs;
break;
case Op_field_assign:
yyerror(_("cannot assign a value to the result of a field post-increment expression"));
break;
default:
yyerror(_("invalid target of assignment (opcode %s)"),
opcode2str(tp->opcode));
break;
}
tp->do_reference = (op->opcode != Op_assign); /* check for uninitialized reference */
if (rhs != NULL)
ip = list_merge(rhs, lhs);
else
ip = lhs;
(void) list_append(ip, op);
if (tp->opcode == Op_push_lhs
&& tp->memory->type == Node_var
&& tp->memory->var_assign
) {
tp->do_reference = false; /* no uninitialized reference checking
* for a special variable.
*/
(void) list_append(ip, instruction(Op_var_assign));
ip->lasti->assign_var = tp->memory->var_assign;
} else if (tp->opcode == Op_field_spec_lhs) {
(void) list_append(ip, instruction(Op_field_assign));
ip->lasti->field_assign = (Func_ptr) 0;
tp->target_assign = ip->lasti;
} else if (tp->opcode == Op_subscript_lhs) {
(void) list_append(ip, instruction(Op_subscript_assign));
}
return ip;
}
/* optimize_assignment --- peephole optimization for assignment */
static INSTRUCTION *
optimize_assignment(INSTRUCTION *exp)
{
INSTRUCTION *i1, *i2, *i3;
/*
* Optimize assignment statements array[subs] = x; var = x; $n = x;
* string concatenation of the form s = s t.
*
* 1) Array element assignment array[subs] = x:
* Replaces Op_push_array + Op_subscript_lhs + Op_assign + Op_pop
* with single instruction Op_store_sub.
* Limitation: 1 dimension and sub is simple var/value.
*
* 2) Simple variable assignment var = x:
* Replaces Op_push_lhs + Op_assign + Op_pop with Op_store_var.
*
* 3) Field assignment $n = x:
* Replaces Op_field_spec_lhs + Op_assign + Op_field_assign + Op_pop
* with Op_store_field.
*
* 4) Optimization for string concatenation:
* For cases like x = x y, uses realloc to include y in x;
* also eliminates instructions Op_push_lhs and Op_pop.
*/
/*
* N.B.: do not append Op_pop instruction to the returned
* instruction list if optimized. None of these
* optimized instructions pushes the r-value of assignment
* onto the runtime stack.
*/
i2 = NULL;
i1 = exp->lasti;
if ( i1->opcode != Op_assign
&& i1->opcode != Op_field_assign)
return list_append(exp, instruction(Op_pop));
for (i2 = exp->nexti; i2 != i1; i2 = i2->nexti) {
switch (i2->opcode) {
case Op_concat:
if (i2->nexti->opcode == Op_push_lhs /* l.h.s is a simple variable */
&& (i2->concat_flag & CSVAR) != 0 /* 1st exp in r.h.s is a simple variable;
* see Op_concat in the grammer above.
*/
&& i2->nexti->memory == exp->nexti->memory /* and the same as in l.h.s */
&& i2->nexti->nexti == i1
&& i1->opcode == Op_assign
) {
/* s = s ... optimization */
/* avoid stuff like x = x (x = y) or x = x gsub(/./, "b", x);
* check for l-value reference to this variable in the r.h.s.
* Also, avoid function calls in general to guard against
* global variable assignment.
*/
for (i3 = exp->nexti->nexti; i3 != i2; i3 = i3->nexti) {
if ((i3->opcode == Op_push_lhs && i3->memory == i2->nexti->memory)
|| i3->opcode == Op_func_call)
return list_append(exp, instruction(Op_pop)); /* no optimization */
}
/* remove the variable from r.h.s */
i3 = exp->nexti;
exp->nexti = i3->nexti;
bcfree(i3);
if (--i2->expr_count == 1) /* one less expression in Op_concat */
i2->opcode = Op_no_op;
i3 = i2->nexti;
assert(i3->opcode == Op_push_lhs);
i3->opcode = Op_assign_concat; /* change Op_push_lhs to Op_assign_concat */
i3->nexti = NULL;
bcfree(i1); /* Op_assign */
exp->lasti = i3; /* update Op_list */
return exp;
}
break;
case Op_field_spec_lhs:
if (i2->nexti->opcode == Op_assign
&& i2->nexti->nexti == i1
&& i1->opcode == Op_field_assign
) {
/* $n = .. */
i2->opcode = Op_store_field;
bcfree(i2->nexti); /* Op_assign */
i2->nexti = NULL;
bcfree(i1); /* Op_field_assign */
exp->lasti = i2; /* update Op_list */
return exp;
}
break;
case Op_push_array:
if (i2->nexti->nexti->opcode == Op_subscript_lhs) {
i3 = i2->nexti->nexti;
if (i3->sub_count == 1
&& i3->nexti == i1
&& i1->opcode == Op_assign
) {
/* array[sub] = .. */
i3->opcode = Op_store_sub;
i3->memory = i2->memory;
i3->expr_count = 1; /* sub_count shadows memory,
* so use expr_count instead.
*/
i3->nexti = NULL;
i2->opcode = Op_no_op;
bcfree(i1); /* Op_assign */
exp->lasti = i3; /* update Op_list */
return exp;
}
}
break;
case Op_push_lhs:
if (i2->nexti == i1
&& i1->opcode == Op_assign
) {
/* var = .. */
i2->opcode = Op_store_var;
i2->nexti = NULL;
bcfree(i1); /* Op_assign */
exp->lasti = i2; /* update Op_list */
i3 = exp->nexti;
if (i3->opcode == Op_push_i
&& (i3->memory->flags & INTLSTR) == 0
&& i3->nexti == i2
) {
/* constant initializer */
i2->initval = i3->memory;
bcfree(i3);
exp->nexti = i2;
} else
i2->initval = NULL;
return exp;
}
break;
default:
break;
}
}
/* no optimization */
return list_append(exp, instruction(Op_pop));
}
/* mk_getline --- make instructions for getline */
static INSTRUCTION *
mk_getline(INSTRUCTION *op, INSTRUCTION *var, INSTRUCTION *redir, int redirtype)
{
INSTRUCTION *ip;
INSTRUCTION *tp;
INSTRUCTION *asgn = NULL;
/*
* getline [var] < [file]
*
* [ file (simp_exp)]
* [ [ var ] ]
* [ Op_K_getline_redir|NULL|redir_type|into_var]
* [ [var_assign] ]
*
*/
if (redir == NULL) {
int sline = op->source_line;
bcfree(op);
op = bcalloc(Op_K_getline, 2, sline);
(op + 1)->target_endfile = ip_endfile;
(op + 1)->target_beginfile = ip_beginfile;
}
if (var != NULL) {
tp = make_assignable(var->lasti);
assert(tp != NULL);
/* check if we need after_assign bytecode */
if (tp->opcode == Op_push_lhs
&& tp->memory->type == Node_var
&& tp->memory->var_assign
) {
asgn = instruction(Op_var_assign);
asgn->assign_ctxt = op->opcode;
asgn->assign_var = tp->memory->var_assign;
} else if (tp->opcode == Op_field_spec_lhs) {
asgn = instruction(Op_field_assign);
asgn->assign_ctxt = op->opcode;
asgn->field_assign = (Func_ptr) 0; /* determined at run time */
tp->target_assign = asgn;
} else if (tp->opcode == Op_subscript_lhs) {
asgn = instruction(Op_subscript_assign);
asgn->assign_ctxt = op->opcode;
}
if (redir != NULL) {
ip = list_merge(redir, var);
(void) list_append(ip, op);
} else
ip = list_append(var, op);
} else if (redir != NULL)
ip = list_append(redir, op);
else
ip = list_create(op);
op->into_var = (var != NULL);
op->redir_type = (redir != NULL) ? redirtype : redirect_none;
return (asgn == NULL ? ip : list_append(ip, asgn));
}
/* mk_for_loop --- for loop bytecodes */
static INSTRUCTION *
mk_for_loop(INSTRUCTION *forp, INSTRUCTION *init, INSTRUCTION *cond,
INSTRUCTION *incr, INSTRUCTION *body)
{
/*
* ------------------------
* init (may be NULL)
* ------------------------
* x:
* cond (Op_no_op if NULL)
* ------------------------
* [ Op_jmp_false tb ]
* ------------------------
* body (may be NULL)
* ------------------------
* tc:
* incr (may be NULL)
* [ Op_jmp x ]
* ------------------------
* tb:[ Op_no_op ]
*/
INSTRUCTION *ip, *tbreak, *tcont;
INSTRUCTION *jmp;
INSTRUCTION *pp_cond;
INSTRUCTION *ret;
tbreak = instruction(Op_no_op);
if (cond != NULL) {
add_lint(cond, LINT_assign_in_cond);
pp_cond = cond->nexti;
ip = cond;
(void) list_append(ip, instruction(Op_jmp_false));
ip->lasti->target_jmp = tbreak;
} else {
pp_cond = instruction(Op_no_op);
ip = list_create(pp_cond);
}
if (init != NULL)
ip = list_merge(init, ip);
if (do_pretty_print) {
(void) list_append(ip, instruction(Op_exec_count));
(forp + 1)->forloop_cond = pp_cond;
(forp + 1)->forloop_body = ip->lasti;
}
if (body != NULL)
(void) list_merge(ip, body);
jmp = instruction(Op_jmp);
jmp->target_jmp = pp_cond;
if (incr == NULL)
tcont = jmp;
else {
tcont = incr->nexti;
(void) list_merge(ip, incr);
}
(void) list_append(ip, jmp);
ret = list_append(ip, tbreak);
fix_break_continue(ret, tbreak, tcont);
if (do_pretty_print) {
forp->target_break = tbreak;
forp->target_continue = tcont;
ret = list_prepend(ret, forp);
}
/* else
forp is NULL */
return ret;
}
/* add_lint --- add lint warning bytecode if needed */
static void
add_lint(INSTRUCTION *list, LINTTYPE linttype)
{
#ifndef NO_LINT
INSTRUCTION *ip;
switch (linttype) {
case LINT_assign_in_cond:
ip = list->lasti;
if (ip->opcode == Op_var_assign || ip->opcode == Op_field_assign) {
assert(ip != list->nexti);
for (ip = list->nexti; ip->nexti != list->lasti; ip = ip->nexti)
;
}
if (ip->opcode == Op_assign || ip->opcode == Op_assign_concat) {
list_append(list, instruction(Op_lint));
list->lasti->lint_type = linttype;
}
break;
case LINT_no_effect:
if (list->lasti->opcode == Op_pop && list->nexti != list->lasti) {
int line = 0;
// Get down to the last instruction (FIXME: why?)
for (ip = list->nexti; ip->nexti != list->lasti; ip = ip->nexti) {
// along the way track line numbers, we will use the line
// closest to the opcode if that opcode doesn't have one
if (ip->source_line != 0)
line = ip->source_line;
}
if (do_lint) { /* compile-time warning */
if (isnoeffect(ip->opcode)) {
if (ip->source_line != 0)
line = ip->source_line;
lintwarn_ln(line, ("statement may have no effect"));
}
}
if (ip->opcode == Op_push || ip->opcode == Op_push_i) { /* run-time warning */
list_append(list, instruction(Op_lint));
list->lasti->lint_type = linttype;
}
}
break;
default:
break;
}
#endif
}
/* mk_expression_list --- list of bytecode lists */
static INSTRUCTION *
mk_expression_list(INSTRUCTION *list, INSTRUCTION *s1)
{
INSTRUCTION *r;
/* we can't just combine all bytecodes, since we need to
* process individual expressions for a few builtins in snode() (-:
*/
/* -- list of lists */
/* [Op_list| ... ]------
* |
* [Op_list| ... ] -- |
* ... | |
* ... <------- |
* [Op_list| ... ] -- |
* ... | |
* ... | |
* ... <------- --
*/
assert(s1 != NULL && s1->opcode == Op_list);
if (list == NULL) {
list = instruction(Op_list);
list->nexti = s1;
list->lasti = s1->lasti;
return list;
}
/* append expression to the end of the list */
r = list->lasti;
r->nexti = s1;
list->lasti = s1->lasti;
return list;
}
/* count_expressions --- fixup expression_list from mk_expression_list.
* returns no of expressions in list. isarg is true
* for function arguments.
*/
static int
count_expressions(INSTRUCTION **list, bool isarg)
{
INSTRUCTION *expr;
INSTRUCTION *r = NULL;
int count = 0;
if (*list == NULL) /* error earlier */
return 0;
for (expr = (*list)->nexti; expr; ) {
INSTRUCTION *t1, *t2;
t1 = expr->nexti;
t2 = expr->lasti;
if (isarg && t1 == t2 && t1->opcode == Op_push)
t1->opcode = Op_push_param;
if (++count == 1)
r = expr;
else
(void) list_merge(r, expr);
expr = t2->nexti;
}
assert(count > 0);
if (! isarg && count > max_args)
max_args = count;
bcfree(*list);
*list = r;
return count;
}
/* fix_break_continue --- fix up break & continue codes in loop bodies */
static void
fix_break_continue(INSTRUCTION *list, INSTRUCTION *b_target, INSTRUCTION *c_target)
{
INSTRUCTION *ip;
list->lasti->nexti = NULL; /* just to make sure */
for (ip = list->nexti; ip != NULL; ip = ip->nexti) {
switch (ip->opcode) {
case Op_K_break:
if (ip->target_jmp == NULL)
ip->target_jmp = b_target;
break;
case Op_K_continue:
if (ip->target_jmp == NULL)
ip->target_jmp = c_target;
break;
default:
/* this is to keep the compiler happy. sheesh. */
break;
}
}
}
static inline INSTRUCTION *
list_create(INSTRUCTION *x)
{
INSTRUCTION *l;
l = instruction(Op_list);
l->nexti = x;
l->lasti = x;
return l;
}
static inline INSTRUCTION *
list_append(INSTRUCTION *l, INSTRUCTION *x)
{
#ifdef GAWKDEBUG
if (l->opcode != Op_list)
cant_happen();
#endif
l->lasti->nexti = x;
l->lasti = x;
return l;
}
static inline INSTRUCTION *
list_prepend(INSTRUCTION *l, INSTRUCTION *x)
{
#ifdef GAWKDEBUG
if (l->opcode != Op_list)
cant_happen();
#endif
x->nexti = l->nexti;
l->nexti = x;
return l;
}
static inline INSTRUCTION *
list_merge(INSTRUCTION *l1, INSTRUCTION *l2)
{
#ifdef GAWKDEBUG
if (l1->opcode != Op_list)
cant_happen();
if (l2->opcode != Op_list)
cant_happen();
#endif
l1->lasti->nexti = l2->nexti;
l1->lasti = l2->lasti;
bcfree(l2);
return l1;
}
/* See if name is a special token. */
int
check_special(const char *name)
{
int low, high, mid;
int i;
int non_standard_flags = 0;
#ifdef USE_EBCDIC
static bool did_sort = false;
if (! did_sort) {
qsort((void *) tokentab,
sizeof(tokentab) / sizeof(tokentab[0]),
sizeof(tokentab[0]), tokcompare);
did_sort = true;
}
#endif
if (do_traditional)
non_standard_flags |= GAWKX;
if (do_posix)
non_standard_flags |= NOT_POSIX;
low = 0;
high = (sizeof(tokentab) / sizeof(tokentab[0])) - 1;
while (low <= high) {
mid = (low + high) / 2;
i = *name - tokentab[mid].operator[0];
if (i == 0)
i = strcmp(name, tokentab[mid].operator);
if (i < 0) /* token < mid */
high = mid - 1;
else if (i > 0) /* token > mid */
low = mid + 1;
else {
if ((tokentab[mid].flags & non_standard_flags) != 0)
return -1;
return mid;
}
}
return -1;
}
/*
* This provides a private version of functions that act like VMS's
* variable-length record filesystem, where there was a bug on
* certain source files.
*/
static FILE *fp = NULL;
/* read_one_line --- return one input line at a time. mainly for debugging. */
static ssize_t
read_one_line(int fd, void *buffer, size_t count)
{
char buf[BUFSIZ];
/* Minor potential memory leak here. Too bad. */
if (fp == NULL) {
fp = fdopen(fd, "r");
if (fp == NULL) {
fprintf(stderr, "ugh. fdopen: %s\n", strerror(errno));
gawk_exit(EXIT_FAILURE);
}
}
if (fgets(buf, sizeof buf, fp) == NULL)
return 0;
memcpy(buffer, buf, strlen(buf));
return strlen(buf);
}
/* one_line_close --- close the open file being read with read_one_line() */
static int
one_line_close(int fd)
{
int ret;
if (fp == NULL || fd != fileno(fp))
fatal("debugging read/close screwed up!");
ret = fclose(fp);
fp = NULL;
return ret;
}
/* lookup_builtin --- find a builtin function or return NULL */
builtin_func_t
lookup_builtin(const char *name)
{
if (strncmp(name, "awk::", 5) == 0)
name += 5;
int mid = check_special(name);
if (mid == -1)
return NULL;
switch (tokentab[mid].class) {
case LEX_BUILTIN:
case LEX_LENGTH:
break;
default:
return NULL;
}
/* And another special case... */
if (tokentab[mid].value == Op_sub_builtin)
return (builtin_func_t) do_sub;
#ifdef HAVE_MPFR
if (do_mpfr)
return tokentab[mid].ptr2;
#endif
return tokentab[mid].ptr;
}
/* install_builtins --- add built-in functions to FUNCTAB */
void
install_builtins(void)
{
int i, j;
int flags_that_must_be_clear = DEBUG_USE;
if (do_traditional)
flags_that_must_be_clear |= GAWKX;
if (do_posix)
flags_that_must_be_clear |= NOT_POSIX;
j = sizeof(tokentab) / sizeof(tokentab[0]);
for (i = 0; i < j; i++) {
if ( (tokentab[i].class == LEX_BUILTIN
|| tokentab[i].class == LEX_LENGTH)
&& (tokentab[i].flags & flags_that_must_be_clear) == 0) {
(void) install_symbol(tokentab[i].operator, Node_builtin_func);
}
}
}
/*
* 9/2014: Gawk cannot use <ctype.h> isalpha or isalnum when
* parsing the program since that can let through non-English
* letters. So, we supply our own. !@#$%^&*()-ing locales!
*/
/* is_alpha --- return true if c is an English letter */
/*
* The scene of the murder was grisly to look upon. When the inspector
* arrived, the sergeant turned to him and said, "Another programmer stabbed
* in the back. He never knew what happened."
*
* The inspector replied, "Looks like the MO of isalpha, and his even meaner
* big brother, isalnum. The Locale brothers." The sergeant merely
* shuddered in horror.
*/
bool
is_alpha(int c)
{
switch (c) {
case 'a': case 'b': case 'c': case 'd': case 'e': case 'f':
case 'g': case 'h': case 'i': case 'j': case 'k': case 'l':
case 'm': case 'n': case 'o': case 'p': case 'q': case 'r':
case 's': case 't': case 'u': case 'v': case 'w': case 'x':
case 'y': case 'z':
case 'A': case 'B': case 'C': case 'D': case 'E': case 'F':
case 'G': case 'H': case 'I': case 'J': case 'K': case 'L':
case 'M': case 'N': case 'O': case 'P': case 'Q': case 'R':
case 'S': case 'T': case 'U': case 'V': case 'W': case 'X':
case 'Y': case 'Z':
return true;
}
return false;
}
/* is_alnum --- return true for alphanumeric, English only letters */
bool
is_alnum(int c)
{
/* digit test is good for EBCDIC too. so there. */
return (is_alpha(c) || ('0' <= c && c <= '9'));
}
/*
* is_letter --- function to check letters
* isalpha() isn't good enough since it can look at the locale.
* Underscore counts as a letter in awk identifiers
*/
bool
is_letter(int c)
{
return (is_alpha(c) || c == '_');
}
/* is_identchar --- return true if c can be in an identifier */
bool
is_identchar(int c)
{
return (is_alnum(c) || c == '_');
}
/* set_profile_text --- make a number that can be printed when profiling */
static NODE *
set_profile_text(NODE *n, const char *str, size_t len)
{
if (do_pretty_print) {
// two extra bytes: one for NUL termination, and another in
// case we need to add a leading minus sign in add_sign_to_num
emalloc(n->stptr, char *, len + 2, "set_profile_text");
memcpy(n->stptr, str, len);
n->stptr[len] = '\0';
n->stlen = len;
// Set STRCUR and n->stfmt for use when profiling
// (i.e., actually running the program) so that
// force_string() on this item will work ok.
// Thanks and a tip of the hatlo to valgrind.
n->flags |= (NUMCONSTSTR|STRCUR);
n->stfmt = STFMT_UNUSED;
#ifdef HAVE_MPFR
n->strndmode = MPFR_round_mode;
#endif
}
return n;
}
/*
* merge_comments --- merge c2 into c1 and free c2 if successful.
* Allow c2 to be NULL, in which case just merged chained
* comments in c1.
*/
static void
merge_comments(INSTRUCTION *c1, INSTRUCTION *c2)
{
assert(c1->opcode == Op_comment);
if (c1->comment == NULL && c2 == NULL) // nothing to do
return;
size_t total = c1->memory->stlen;
if (c1->comment != NULL)
total += 1 /* \n */ + c1->comment->memory->stlen;
if (c2 != NULL) {
assert(c2->opcode == Op_comment);
total += 1 /* \n */ + c2->memory->stlen;
if (c2->comment != NULL)
total += c2->comment->memory->stlen + 1;
}
char *buffer;
emalloc(buffer, char *, total + 1, "merge_comments");
strcpy(buffer, c1->memory->stptr);
if (c1->comment != NULL) {
strcat(buffer, "\n");
strcat(buffer, c1->comment->memory->stptr);
}
if (c2 != NULL) {
strcat(buffer, "\n");
strcat(buffer, c2->memory->stptr);
if (c2->comment != NULL) {
strcat(buffer, "\n");
strcat(buffer, c2->comment->memory->stptr);
}
unref(c2->memory);
if (c2->comment != NULL) {
unref(c2->comment->memory);
bcfree(c2->comment);
c2->comment = NULL;
}
bcfree(c2);
}
c1->memory->comment_type = BLOCK_COMMENT;
free(c1->memory->stptr);
c1->memory->stptr = buffer;
c1->memory->stlen = strlen(buffer);
// now free everything else
if (c1->comment != NULL) {
unref(c1->comment->memory);
bcfree(c1->comment);
c1->comment = NULL;
}
}
/* make_braced_statements --- handle `l_brace statements r_brace' with comments */
static INSTRUCTION *
make_braced_statements(INSTRUCTION *lbrace, INSTRUCTION *stmts, INSTRUCTION *rbrace)
{
INSTRUCTION *ip;
if (stmts == NULL)
ip = list_create(instruction(Op_no_op));
else
ip = stmts;
if (lbrace != NULL) {
INSTRUCTION *comment2 = lbrace->comment;
if (comment2 != NULL) {
ip = list_prepend(ip, comment2);
lbrace->comment = NULL;
}
ip = list_prepend(ip, lbrace);
}
return ip;
}
/* validate_qualified_name --- make sure that a qualified name is built correctly */
/*
* This routine returns upon first error, no need to produce multiple, possibly
* conflicting / confusing error messages.
*/
bool
validate_qualified_name(char *token)
{
char *cp, *cp2;
// no colon, by definition it's well formed
if ((cp = strchr(token, ':')) == NULL)
return true;
if (do_traditional || do_posix) {
error_ln(sourceline, _("identifier %s: qualified names not allowed in traditional / POSIX mode"), token);
return false;
}
if (cp[1] != ':') { // could happen from command line
error_ln(sourceline, _("identifier %s: namespace separator is two colons, not one"), token);
return false;
}
if (! is_letter(cp[2])) {
error_ln(sourceline,
_("qualified identifier `%s' is badly formed"),
token);
return false;
}
if ((cp2 = strchr(cp+2, ':')) != NULL) {
error_ln(sourceline,
_("identifier `%s': namespace separator can only appear once in a qualified name"),
token);
return false;
}
return true;
}
/* check_qualified_special --- decide if a name is special or not */
static int
check_qualified_special(char *token)
{
char *cp;
if ((cp = strchr(token, ':')) == NULL && current_namespace == awk_namespace)
return check_special(token);
/*
* Now it's more complicated. Here are the rules.
*
* 1. Namespace name cannot be a standard awk reserved word or function.
* 2. Subordinate part of the name cannot be standard awk reserved word or function.
* 3. If namespace part is explicitly "awk", return result of check_special().
* 4. Else return -1 (gawk extensions allowed, we check standard awk in step 2).
*/
const struct token *tok;
int i;
if (cp == NULL) { // namespace not awk, but a simple identifier
i = check_special(token);
if (i < 0)
return i;
tok = & tokentab[i];
if ((tok->flags & GAWKX) != 0 && tok->class == LEX_BUILTIN)
return -1;
else
return i;
}
char *ns, *end, *subname;
ns = token;
*(end = cp) = '\0'; // temporarily turn it into standalone string
subname = end + 2;
// First check the namespace part
i = check_special(ns);
if (i >= 0 && (tokentab[i].flags & GAWKX) == 0) {
error_ln(sourceline, _("using reserved identifier `%s' as a namespace is not allowed"), ns);
goto done;
}
// Now check the subordinate part
i = check_special(subname);
if (i >= 0 && (tokentab[i].flags & GAWKX) == 0 && strcmp(ns, "awk") != 0) {
error_ln(sourceline, _("using reserved identifier `%s' as second component of a qualified name is not allowed"), subname);
goto done;
}
if (strcmp(ns, "awk") == 0) {
i = check_special(subname);
if (i >= 0) {
if ((tokentab[i].flags & GAWKX) != 0 && tokentab[i].class == LEX_BUILTIN)
; // gawk additional builtin function, is ok
else
error_ln(sourceline, _("using reserved identifier `%s' as second component of a qualified name is not allowed"), subname);
}
} else
i = -1;
done:
*end = ':';
return i;
}
/* set_namespace --- change the current namespace */
static void
set_namespace(INSTRUCTION *ns, INSTRUCTION *comment)
{
if (ns == NULL)
return;
if (do_traditional || do_posix) {
error_ln(ns->source_line, _("@namespace is a gawk extension"));
efree(ns->lextok);
bcfree(ns);
return;
}
if (! is_valid_identifier(ns->lextok)) {
error_ln(ns->source_line, _("namespace name `%s' must meet identifier naming rules"), ns->lextok);
efree(ns->lextok);
bcfree(ns);
return;
}
int mid = check_special(ns->lextok);
if (mid >= 0) {
error_ln(ns->source_line, _("using reserved identifier `%s' as a namespace is not allowed"), ns->lextok);
efree(ns->lextok);
bcfree(ns);
return;
}
if (strcmp(ns->lextok, current_namespace) == 0)
; // nothing to do
else if (strcmp(ns->lextok, awk_namespace) == 0) {
set_current_namespace(awk_namespace);
} else {
set_current_namespace(estrdup(ns->lextok, strlen(ns->lextok)));
}
efree(ns->lextok);
// save info and push on front of list of namespaces seen
INSTRUCTION *new_ns = instruction(Op_K_namespace);
new_ns->comment = comment;
new_ns->ns_name = estrdup(current_namespace, strlen(current_namespace));
new_ns->nexti = namespace_chain;
namespace_chain = new_ns;
ns->lextok = NULL;
bcfree(ns);
namespace_changed = true;
return;
}
/* qualify_name --- put name into namespace */
static char *
qualify_name(const char *name, size_t len)
{
if (strchr(name, ':') != NULL) // already qualified
return estrdup(name, len);
NODE *p = lookup(name);
if (p != NULL && p->type == Node_param_list)
return estrdup(name, len);
if (current_namespace != awk_namespace && ! is_all_upper(name)) {
size_t length = strlen(current_namespace) + 2 + len + 1;
char *buf;
emalloc(buf, char *, length, "qualify_name");
sprintf(buf, "%s::%s", current_namespace, name);
return buf;
}
return estrdup(name, len);
}
|