expression.c 130 KB
Newer Older
1 2 3 4
/*
FILE:   expression.c
HEADER: expression.h

5
Common MIT License - Jan 31, 2018
6

7
ScriptBasic Copyright (c) 2018 Peter Verhas
8

9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
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

TO_HEADER:

#define MAX_LEXES_PER_LINE 14 // the maximum number of lexicals allowed on a line
                              // (note that an expression or an expression list is one lexical in this calculation)
#define MAX_GO_CONSTANTS 3    // the number of different unnamed label types a command may accept
                              // usually the only such construction is ENDIF that can finish an ELSE as
                              // well as an IF branch. But to be safe we have three.
#define MAX_SAME_LABELS 10    // the max number of labels that can point to the same line

typedef struct _SymbolUF { //User Function
  unsigned long FunId; // The serial number of the function
  long Argc; // the number of arguments (-1 means uninitialized)
  unsigned long node; // where the function is defined
  char *FunctionName; // the name of the function to print in error message when it is used, but not defined
  struct _SymbolUF *next;
  } SymbolUF, *pSymbolUF;


typedef struct _eNODE {
  long OpCode; // the code of operation
  unsigned long NodeId; // the id of the node
  char *szFileName;// where the lexeme is
  long lLineNumber;// from which this syntax node is made
  union {

    // when the node is a command
    struct {
      union {
        struct _SymbolLABEL *pLabel;
        struct _eNODE *pNode;
        struct _eNODE_l *pNodeList;
        long lLongValue;
        double dDoubleValue;
        char *szStringValue;
        }Argument;
      long sLen;
      struct _eNODE *next;
      }CommandArgument;

    // when the node is an operation
    struct {
      struct _eNODE_l *Argument;
      }Arguments;

    // when the node is a constant
    struct {
      union {
        double dValue;        
        long   lValue;        
        char  *sValue;
        }Value;
      long sLen; //the length of the string constant
      }Constant;

    // when the node is a variable
    struct {
      unsigned long Serial; // the serial number of the variable
      }Variable;

    // when node is a user functions
    struct {
      pSymbolUF pFunction; // pointer to the function
      struct _eNODE_l *Argument;
      }UserFunction;

    }Parameter;

  } eNODE,*peNODE;

// these values are used for the built-in functionalities
// other opcode values are defined in tables
enum {
  eNTYPE_ARR=1, // array access
  eNTYPE_SAR,   // assoc array access
  eNTYPE_FUN,   // function
  eNTYPE_LVR,   // local variable
  eNTYPE_GVR,   // global variable
  eNTYPE_DBL,   // constant double
  eNTYPE_LNG,   // constant long
  eNTYPE_STR,   // constant string
  eNTYPE_LST,   // list member (only after build)
  eNTYPE_CRG,   // command arguments

  __eNTYPE_DUMMY__
  };

// node list
typedef struct _eNODE_l{
  unsigned long NodeId; // the id of the node
  char *szFileName;// where the lexeme is
  long lLineNumber;// from which this syntax node is made
  peNODE actualm;
  struct _eNODE_l *rest;
  } eNODE_l, *peNODE_l;

typedef struct _SymbolLABEL { // label for GOTO and alikes
  long Serial; // serial value of the label
  unsigned long node; // where the label is placed (the node id)
  } SymbolLABEL, *pSymbolLABEL;

typedef struct _SymbolVAR { //Variable
  long Serial; // serial number of the variable
  } SymbolVAR, *pSymbolVAR;

typedef struct _LabelStack {
  pSymbolLABEL pLabel;
  struct _LabelStack *Flink;
  long Type;
  } LabelStack, *pLabelStack;

typedef struct _BFun {   // built in function
  long OpCode;  // Lexeme symbol code as well as operation code
  long MinArgs; // The minimum nulber of arguments
  long MaxArgs; // The maximum number of arguments
  } BFun, *pBFun;

typedef struct _PredLConst {
  char *name;
  long value;
  }PredLConst,*pPredLConst;

// constant values used in the line syntax description table
enum {
  EX_LEX_EXP = 1,  // expression
  EX_LEX_EXPL,     // expression list
  EX_LEX_LVAL,     // left value
  EX_LEX_LVALL,    // left value list
  EX_LEX_NSYMBOL,  // non-alpha symbol or alpha symbol which is reserved and therefore tokenized
  EX_LEX_SYMBOL,   // a symbol, like a variable
  EX_LEX_ASYMBOL,  // a symbol that does not need name space tuning (usually like MODULE xxx)
  EX_LEX_PRAGMA,   // a pragma symbol
  EX_LEX_SET_NAME_SPACE, // a symbol that sets the name space
  EX_LEX_RESET_NAME_SPACE, // end of name space, old name space is restored
  EX_LEX_CHARACTER,// a character, like '(' or ')'
  EX_LEX_LONG,     // a numeric integer value
  EX_LEX_DOUBLE,   // a numeric float value
  EX_LEX_STRING,   // a string value
  EX_LEX_LOCAL,    // a local variable, does not generate code, but is declared as local
  EX_LEX_LOCALL,   // local variable list,    -"-
  EX_LEX_GLOBAL,   // global variable, -"-
  EX_LEX_GLOBALL,  // global variable list , -"-
  EX_LEX_FUNCTION, // function or procedure definition symbol
  EX_LEX_THIS_FUNCTION, // the name of the current function
  EX_LEX_LABEL_DEFINITION, //a global label is defined (symbol)
  EX_LEX_LABEL,    // a global label is used
  EX_LEX_STAR,     // the star pseudo lexer that says the syntax failure is final
  EX_LEX_NOEXEC,   // the command needs no code
  EX_LEX_ARG_NUM,  // store the number of arguments

  EX_LEX_GO_FORWARD,
  EX_LEX_GO_BACK,
  EX_LEX_COME_FORWARD,
  EX_LEX_COME_BACK,

// The followings are pseudo syntax elements that instruct the
// compiler to do some semantic action, but does not actually
// match any lexical elements.
// These values should usually appear at the end of a line
// definition after the new line.

  EX_LEX_LOCAL_START, // start a new local area, like start of a user proc or user function
  EX_LEX_LOCAL_END,   // finish a local area

  EX_LEX_CONST_NAME,  // constant name
  EX_LEX_GCONST_NAME, // global constant name
  EX_LEX_CONST_VALUE, // constant value

  EX_LEX_DUMMY
  };

typedef struct _LineSyntaxUnit {
  int type;          // type of the syntactical element from the enum above
  long OpCode;       // the opcode
  long GoConstant[MAX_GO_CONSTANTS];
  } LineSyntaxUnit, *pLineSyntaxUnit;

typedef struct _LineSyntax {
  long CommandOpCode;
  peNODE (*pfAnalyzeFunction)();
  LineSyntaxUnit lexes[MAX_LEXES_PER_LINE];
  } LineSyntax, *pLineSyntax;

typedef struct _NameSpaceStack {
  struct _NameSpaceStack *next;
  char *ThisNameSpace;
  }NameSpaceStack, *pNameSpaceStack;

typedef struct _eXobject {
  void *(*memory_allocating_function)(size_t);
  void (*memory_releasing_function)(void *);
  void *pMemorySegment; //this pointer is passed to the memory allocating functions
                        //this pointer is initialized in ex_init
  void *pLocalVarMemorySegment; // this memory segment is used to allocate local memory variables
                                // initialized in ex_init
  void *pSymbolTableMemorySegment; // for all symbol table entries that are not local

  pLexObject pLex;    // the lexicals that we work up

  SymbolTable GlobalVariables;
  SymbolTable UserFunctions;
  SymbolTable LocalVariables;
  SymbolTable LocallyDeclaredGlobalVariables;
  SymbolTable GlobalLabels;  // currently there are only global labels, locality is done with name decoration
  SymbolTable GlobalConstants; // global constants, locality is done with name decoration
  long *plNrLocalVariables; //pointer to the long where we store the number of the local variables
                            // this value is known at the end of the user function or user proc,
                            // but should be stored in the func or proc head.
                            // Note that we do need a single variable for this, and not a push/pop stack
                            // because functions and procedures can not be nested
  pPredLConst PredeclaredLongConstants;
  long cGlobalVariables;
  long cGlobalLabels;
  long cLocalVariables;
  long cUserFunctions;

  pSymbolUF FirstUF; // the first User Function. Used to go throug the functions to check that all are defined.

  int iWeAreLocal; // is true when variables should be processed as local variables otherwise zero
  int iDeclareVars; // is true when all global/local variables have to be declared
  int iDefaultLocal; // it is true when all undefined variables are treated as local

// ScriptBasic supports modules and nested name spaces. However
// this is nothing else than allowing :: in names, like main::a.

// There is always a current name space during compilation. The default
// name space is main.

// A symbol or variable in the source can be absolute or relative
// regarding name spaces. An absolute reference is like T<main::v>
// a variable named T<v> from the name space main. Name spaces can
// arbitrarily be nested, therefore package::subpackage::v is a valid variable.

// The variable CurrentNameSpace contains the current name space and
// should always contain the trailing ::


  char *CurrentNameSpace;
  long cbCurrentNameSpace;
  pNameSpaceStack pOldNameSpace;

  unsigned long *Unaries; // array of token codes that are unary operations. Final element should be zero
  // This array contains the opcodes of the binary operations. Each odd element should give the opcode
  // of the operation and the next element is the precedence value. The final element is zero,
  // therefore zero can not be used as a legal opcode for binary operations.
  unsigned long *Binaries;
  unsigned long MAXPREC; // maximal precedence of binary operators

  pBFun BuiltInFunctions;

  pReportFunction report;
  void *reportptr; // this pointer is passed to the report function. The caller should set it.
  int iErrorCounter;
  unsigned long fErrorFlags;

  char *Buffer;
  size_t cbBuffer;

  pLineSyntax Command;

  peNODE_l pCommandList;

  unsigned long NodeCounter; // used to count the nodes and assign NodeId

  pSymbolUF ThisFunction; // the serial number of the current function

  // the stack to store the unnamed labels for loop and 'if then else' constructions
  pLabelStack pComeAndGoStack;
  pLabelStack pFreeComeAndGoStack; // to save global allocation we store freed label stack structures
                                   // in this list
  pSymbolLABEL LabelsWaiting[MAX_SAME_LABELS];
  unsigned long cLabelsWaiting;
  pSymbolUF pFunctionWaiting;

  unsigned long cbStringTable; // all the bytes of builder StringTable including the zeroes
  struct _PreprocObject *pPREP;
  } eXobject, *peXobject;

typedef void (*CommandFunctionType)();

*/

/*POD

The functions in this file compile a ScriptBasic expression into
internal form. The functions are quite general, and do NOT depend
on the actual operators that are implemented in the actual version.

This means that you can define extra operators as well as extra
built-in functions easily adding entries into tables and need not modify
the compiling code.

CUT*/

/*POD
=H What is an expression in ScriptBasic

Altough the syntax defintion in script basic is table driven and can easily be modified
expressions are not. The syntax of an expression is somewhat fix. Here we formally define
what the program thinks to be an expression. This restriction should not cause problem
in the usage of this module because this is the usual syntax of an expression. Any altering
to this would result in an expression syntax which is unusual, and therefore difficult to
use for the common users. The operators and functions along with therir precedence values are
defined in tables anyway, so you have flexibility.

The formal description of an expression syntax:

=verbatim
 tag ::= UNOP tag
         NUMBER
         STRING
         '(' expression ')'
         VARIABLE { '[' expression_list ']' }
         VARIABLE '{' expression_list '}'
         FUNC '(' expression_list ')'
         .

 expression_list ::= expression [ ',' expression_list ] .

 expression_i(1) ::= tag .

 expression_i(i) := expression_i(i-1) [ OP(i) expression_i(i) ] .

 expression ::= expression_i(MAX_PREC) .

 left_value ::= variable { '[' expression_list ']' } 
                variable '{' expression_list '}' .

=noverbatim

=itemize
=item UNOP

is unary operator as defined in tables in file operators.h

=item NUMBER 

is a number, lexical element.

=item STRING 

is a string, lexical element.

=item VARIABLE 

is a lexical element.

=item FUNC 

is a function either built in, or user defined

=item OP(i)

is an operator of precendece i as defined in tables.

=noitemize


CUT*/
#include <stdlib.h>
#include <string.h>
#include <stdio.h>


#include "errcodes.h"
#include "report.h"
#include "lexer.h"
#include "sym.h"
#include "expression.h"
#include "myalloc.h"

/* we need this to get the constant CMD_EQ, CMD_MINUS, CMD_PLUS */
#include "syntax.h"
#include "ipreproc.h"

#define new_eNODE()    _new_eNODE(pEx)
#define new_eNODE_l()  _new_eNODE_l(pEx,NULL,0L)
#define new_eNODE_lL() _new_eNODE_l(pEx,pszFileName,lLineNumber)
#define new_SymbolUF() _new_SymbolUF(pEx)
#define new_SymbolVAR(y) _new_SymbolVAR(pEx,y)
#define new_SymbolLABEL() _new_SymbolLABEL(pEx)
#define ex_PopLabel(y) _ex_PopLabel(pEx,y)
#define ex_CleanLabelStack() _ex_CleanLabelStack(pEx)
#define LOCAL_VAR 1
#define GLOBAL_VAR 0

#define LexemeLineNumber lex_LineNumber(pEx->pLex)
#define LexemeFileName   lex_FileName(pEx->pLex)
#define NextLexeme       lex_NextLexeme(pEx->pLex);
#define LexemeType       (lex_EOF(pEx->pLex) ? 0 : lex_Type(pEx->pLex))
#define LexemeCode       lex_Code(pEx->pLex)
#define LexemeChar       lex_Char(pEx->pLex)
#define LexemeStrLen     lex_StrLen(pEx->pLex)
#define LexemeString     lex_String(pEx->pLex)
#define LexemeDouble     lex_Double(pEx->pLex)
#define LexemeLong       lex_Long(pEx->pLex)
#define LexemeInt        lex_Int(pEx->pLex)
#define LexemeSymbol     lex_Symbol(pEx->pLex)
#define WeAreLocal       (pEx->iWeAreLocal)
#define WeAreNotLocal    (!pEx->iWeAreLocal)
#define DeclareVars   (pEx->iDeclareVars)
#define DefaultLocal     (pEx->iDefaultLocal)

#define COUNT_STRING_LEN (pEx->cbStringTable += sizeof(long));

#define CALL_PREPROCESSOR(X,Y) if( pEx->pPREP && pEx->pPREP->n )ipreproc_Process(pEx->pPREP,X,Y)

#define REPORT(x1,x2,x3,x4) do{if( pEx->report )pEx->report(pEx->reportptr,x1,x2,x3,REPORT_ERROR,&(pEx->iErrorCounter),x4,&(pEx->fErrorFlags));}while(0)

static isinset(int ch,char *string){
   while( ch != *string && *++string );
   return *string;
}

static void _ex_printVAR(char *name, void *value, void *f){
  FILE *fp = (FILE *)f;
  pSymbolVAR p = (pSymbolVAR)value;

  fprintf(f,"%s=%d\n",name,p->Serial);
  }

/*POD
=H ex_DumpVariables()

This function dumps the variables stored in the symbol table to the file pointed by
T<fp>

/*FUNCTION*/
void ex_DumpVariables(SymbolTable q,
                      FILE *fp
  ){
/*noverbatim

Note that this function is a debug function.
CUT*/
  sym_TraverseSymbolTable(q,_ex_printVAR,(void*)fp);
  }

static void _ex_pprint(FILE *f, peNODE p, peXobject pEx,int tab);
void _ex_pprint_l(FILE *f, peNODE_l p, peXobject pEx,int tab){
  fprintf(f,"%*sexpression list\n",tab,"");
  while( p ){
    fprintf(f,"%*sNode id=%d\n",tab,"",p->NodeId);
    _ex_pprint(f,p->actualm,pEx,tab+1);
    p = p->rest ;
    }
  }

static void _ex_pprint(FILE *f, peNODE p, peXobject pEx,int tab){
  unsigned long *q;
  pLineSyntax pCommand;
  peNODE_l z;
  int i,j;

#define OPCODE (p->OpCode)

  if( tab )fprintf(f,"%*s",tab,"");
  fprintf(f," %d ",p->NodeId);
  tab++;
  if( p == NULL  )return;
  switch(OPCODE){

    case eNTYPE_ARR: /* array access */
      fprintf(f,"Array access\n");
      _ex_pprint_l(f, p->Parameter.Arguments.Argument ,pEx,tab+1);
      break;
    case eNTYPE_SAR: /* associative array access */
      fprintf(f,"Associative array access\n");
      _ex_pprint_l(f, p->Parameter.Arguments.Argument ,pEx,tab+1);
      break;
    case eNTYPE_FUN: /* function */
      fprintf(f,"User function call starting at node %d\n",p->Parameter.UserFunction.pFunction->node);
      _ex_pprint_l(f, p->Parameter.UserFunction.Argument ,pEx,tab+1);
      break;
    case eNTYPE_LVR: /* local variable */
      fprintf(f,"Local variable %d\n",p->Parameter.Variable.Serial);
      return;
    case eNTYPE_GVR: /* global variable */
      fprintf(f,"Global variable %d\n",p->Parameter.Variable.Serial);
      return;
    case eNTYPE_DBL: /* constant double */
      fprintf(f,"Double: %f\n",p->Parameter.Constant.Value.dValue);
      return;
    case eNTYPE_LNG: /* constant long */
      fprintf(f,"Long: %d\n",p->Parameter.Constant.Value.lValue);
      return;
    case eNTYPE_STR: /* constant string */
      fprintf(f,"String %s\n",p->Parameter.Constant.Value.sValue);
      return;
    default: /* */
      q = pEx->Binaries;

      while( *q && *q != (unsigned)OPCODE )q+=2;
      if( *q ){
        fprintf(f,"Opcode: %d %s",OPCODE,lex_SymbolicName(pEx->pLex,OPCODE));
        fprintf(f,"bin\n");
        _ex_pprint(f,p->Parameter.Arguments.Argument->actualm,pEx,tab);
        fprintf(f,"rest %d\n",p->Parameter.Arguments.Argument->rest->NodeId);
        _ex_pprint(f,p->Parameter.Arguments.Argument->rest->actualm,pEx,tab);
        return;
        }
      q = pEx->Unaries;
      while( *q && *q != (unsigned)OPCODE )q++;
      if( *q ){
        fprintf(f,"Opcode: %d %s",OPCODE,lex_SymbolicName(pEx->pLex,OPCODE));
        fprintf(f,"una\n");
        _ex_pprint(f,p->Parameter.Arguments.Argument->actualm,pEx,tab);
        return;
        }
      pCommand = pEx->Command;
      while( pCommand && pCommand->CommandOpCode != 0 && pCommand->CommandOpCode != OPCODE )pCommand++;
      if( pCommand && pCommand->CommandOpCode ){
        fprintf(f,"Command %d %s\n",OPCODE,lex_SymbolicName(pEx->pLex,OPCODE));
        for( i=0,j=0 ; j < MAX_LEXES_PER_LINE && pCommand->lexes[j].type && p ; j++ ){
          switch( pCommand->lexes[j].type ){
            case EX_LEX_CHARACTER:
              break;
            case EX_LEX_NSYMBOL:
              break;
            case EX_LEX_EXP:
              fprintf(f,"%*sexpression %d\n",tab,"",p->Parameter.CommandArgument.Argument.pNode->NodeId);
              _ex_pprint(f,p->Parameter.CommandArgument.Argument.pNode,pEx,tab);
              p=p->Parameter.CommandArgument.next;
              break;
            case EX_LEX_EXPL:
              fprintf(f,"%*sexpression list\n",tab,"");
              z = p->Parameter.CommandArgument.Argument.pNodeList;
              while( z ){
                _ex_pprint(f,z->actualm,pEx,tab);
                z = z->rest;
                }
              p=p->Parameter.CommandArgument.next;
              break;
            case EX_LEX_LVAL:
              fprintf(f,"%*slval %d\n",tab,"",p->Parameter.CommandArgument.Argument.pNode->NodeId);
              _ex_pprint(f,p->Parameter.CommandArgument.Argument.pNode,pEx,tab);
              p=p->Parameter.CommandArgument.next;
              break;
            case EX_LEX_SYMBOL:
              fprintf(f,"%*ssymbol=%s\n",tab,"",p->Parameter.CommandArgument.Argument.szStringValue);
              p=p->Parameter.CommandArgument.next;
              break;
            case EX_LEX_LONG:
              fprintf(f,"%*slong=%d\n",tab,"",p->Parameter.CommandArgument.Argument.lLongValue);
              p=p->Parameter.CommandArgument.next;
              break;
            case EX_LEX_DOUBLE:
              fprintf(f,"%*sdouble=%f\n",tab,"",p->Parameter.CommandArgument.Argument.dDoubleValue);
              p=p->Parameter.CommandArgument.next;
              break;
            case EX_LEX_ASYMBOL:
              fprintf(f,"%*ssymbol=\"%s\"\n",tab,"",p->Parameter.CommandArgument.Argument.szStringValue);
              p=p->Parameter.CommandArgument.next;
              break;
            case EX_LEX_STRING:
              fprintf(f,"%*sstring=\"%s\"\n",tab,"",p->Parameter.CommandArgument.Argument.szStringValue);
              p=p->Parameter.CommandArgument.next;
              break;
            }       
          }
        return;
        }
      /* should be built-in function */
      fprintf(f,"Opcode: %d ",OPCODE);
      fprintf(f,"bif\n");
      z = p->Parameter.Arguments.Argument;
      while( z ){
         _ex_pprint(f,z->actualm,pEx,tab);
         z = z->rest;
         }
      return;
     }
#undef OPCODE
   }

/*POD
=H expression_PushNameSpace()

When a T<module name> instruction is encountered the name space is modified. However
the old name space should be reset when an T<end module> statement is reached. As the
modules can be nested into each other the name spaces are stored in a name space stack
during syntax analysis.

This function pushes the current name space onto the stack. After calling
this function the caller can put the new string into the T<pEx->>T<CurrentNameSpace>
variable and later calling R<ex_PopNameSpace()> can be called to retrive the saved name space.

/*FUNCTION*/
int expression_PushNameSpace(peXobject pEx
  ){
/*noverbatim
CUT*/
  pNameSpaceStack p;

  p = (pNameSpaceStack)alloc_Alloc(sizeof(NameSpaceStack),pEx->pMemorySegment);
  if( p == NULL )return EX_ERROR_MEMORY_LOW;

  p->ThisNameSpace = (char *)alloc_Alloc(strlen(pEx->CurrentNameSpace)+1,pEx->pMemorySegment);
  if( p->ThisNameSpace == NULL ){
    alloc_Free(p,pEx->pMemorySegment);
    return EX_ERROR_MEMORY_LOW;
    }
  strcpy(p->ThisNameSpace,pEx->CurrentNameSpace);

  p->next = pEx->pOldNameSpace;
  pEx->pOldNameSpace = p;
  return EX_ERROR_SUCCESS;
  }

/* This is a callback function that the function CheckUndefinedLabels
   function calls via the TraverseSymbolTable function.
*/
static void CUL_callback(char *LabelName, void *pL, void *f){
  peXobject pEx = (peXobject)f;
  pSymbolLABEL pLabel = (pSymbolLABEL)pL;

  if( pLabel->node == 0 ){
    if( pEx->report )
      REPORT("",0,EX_ERROR_LABEL_NOT_DEFINED,LabelName);
    else
      pEx->iErrorCounter++;
    }
  }

/*POD
=H ex_CheckUndefinedLabels()

This function traverses the label symbol table and reports all undefined
labels as error. Undefined labels reference the node with node-number zero. Jumping
on a label like that caused the program to stop instead of compile time error
in previous versions.

/*FUNCTION*/
void ex_CheckUndefinedLabels(peXobject pEx
  ){
/*noverbatim
CUT*/
  sym_TraverseSymbolTable(pEx->GlobalLabels,CUL_callback,pEx);
  }

/*POD
=H ex_CleanNameSpaceStack()

This function cleans the name space stack. This cleaning does not need to be done during
syntax analysis. It is needed after the analysis has been done to detect unclosed modules.

Note that the T<main::> module is implicit and can not and should not be closed
unless it was explicitly opened.

The function calls the report function if the name space is not empty when the function is called.
/*FUNCTION*/
void ex_CleanNameSpaceStack(peXobject pEx
  ){
/*noverbatim
CUT*/
   pNameSpaceStack p;

  if( pEx->pOldNameSpace )
    REPORT(LexemeFileName,LexemeLineNumber,EX_ERROR_UNFINISHED_MODULE,NULL);
  while( pEx->pOldNameSpace ){
    p = pEx->pOldNameSpace;
    pEx->pOldNameSpace = pEx->pOldNameSpace->next;
    alloc_Free(p->ThisNameSpace,pEx->pMemorySegment);
    alloc_Free(p,pEx->pMemorySegment);
    }
  }

/*POD
=H expression_PopNameSpace()

When a T<module name> instruction is encountered the name space is modified. However
the old name space should be reset when an T<end module> statement is reached. As the
modules can be nested into each other the name spaces are stored in a name space stack
during syntax analysis.

This function pops the name space from the name space stack and copies the value to the
T<pEx->>T<CurrentNameSpace> variable. This should be executed when a name space is closed
and we want to return to the embedding name space.

/*FUNCTION*/
int expression_PopNameSpace(peXobject pEx
  ){
/*noverbatim
CUT*/
  pNameSpaceStack p;

  if( (p=pEx->pOldNameSpace) == NULL )return EX_ERROR_NO_OLD_NAMESPACE;

  pEx->pOldNameSpace = pEx->pOldNameSpace->next;
  strcpy(pEx->CurrentNameSpace,p->ThisNameSpace);

  alloc_Free(p->ThisNameSpace,pEx->pMemorySegment);
  alloc_Free(p,pEx->pMemorySegment);
  return EX_ERROR_SUCCESS;
  }

/*POD
=H ex_PushWaitingLabel()

This function is used to define a label.

/*FUNCTION*/
int ex_PushWaitingLabel(peXobject pEx,
                         pSymbolLABEL pLbl
  ){
/*noverbatim

When a label is defined the T<eNode_l> that the label is going to belong still does not exists, and
therefore the T<NodeId> of that T<eNode_l> is not known. This function together with R<ex_PopWaitingLabel()>
maintains a stack that can store labels which are currently defined and still need a line to be assigned
to them. These labels all point to the same line. Altough it is very rare that many labels point to
the same line, it is possible. The number of labels that can point the same line is defined by the
constant T<MAX_SAME_LABELS> defined in T<expression.c>

To make it clear see the following BASIC code:

=verbatim

this_is_a_label:
REM this is a comment
            PRINT "hello word!!"

=noverbatim

The label is defined on the first line of the example. However the label belongs to the
third line containing the statement T<PRINT>. When the label is processed the compiler does
not know the node number of the code segment which is generated from the third line. Therefore
this function maintains a label-stack to store all labels that need a line. Whenever a line is
compiled so that a label can be assigned to that very line the stack is emptied and all labels waiting on the
stack are assigned to the line just built up. (Or the line is assigned to the labels if you
like the sentence the other way around.)

Note that not only labels given by a label defining statement are pushed on this stack, but also
labels generated by commands like 'while/wend' of 'if/else/endif'.

CUT*/
  if( pEx->cLabelsWaiting < MAX_SAME_LABELS ){
    pEx->LabelsWaiting[pEx->cLabelsWaiting++] = pLbl;
    return EX_ERROR_SUCCESS;
    }
  return EX_ERROR_TOO_MANY_WAITING_LABEL;
  }

/*POD
=H ex_PopWaitingLabel()

This function is used to get a label out of the waiting-label-stack.

/*FUNCTION*/
pSymbolLABEL ex_PopWaitingLabel(peXobject pEx
  ){
/*noverbatim

To get some description of waiting labels see the description of the function R<ex_PushWaitingLabel()>.

CUT*/
  if( pEx->cLabelsWaiting == 0 )return NULL;
  return pEx->LabelsWaiting[ -- (pEx->cLabelsWaiting) ];
  }

/*POD
=H _ex_PushLabel()

This function is used to push an unnamed label on the compile time stack.
For more detailed defintion of the unnamed labels and this stack see the
documentation of the function R<ex_PopLabel()>.

/*FUNCTION*/
int _ex_PushLabel(peXobject pEx,
                  pSymbolLABEL pLbl,
                  long Type,
                  void *pMemorySegment
  ){
/*noverbatim

The argument T<Type> is used to define the type of the unnamed label. This is usually defined
in the table created by the program T<syntaxer.pl>

=bold
Do NOT get confused! This stack is NOT the same as the waiting label stack. That is usually for named
labels.
=nobold

However the non-named labels are also pushed on that stack before they get value.

CUT*/
  pLabelStack p;

  if( pEx->pFreeComeAndGoStack == NULL ){
    pEx->pFreeComeAndGoStack = alloc_Alloc(sizeof(LabelStack),pMemorySegment);
    if( pEx->pFreeComeAndGoStack == NULL )return EX_ERROR_MEMORY_LOW;
    pEx->pFreeComeAndGoStack->Flink = NULL;
    }
  p = pEx->pFreeComeAndGoStack;
  pEx->pFreeComeAndGoStack = pEx->pFreeComeAndGoStack->Flink;
  p->Flink = pEx->pComeAndGoStack;
  p->Type = Type;
  pEx->pComeAndGoStack = p;
  p->pLabel = pLbl;  
  return 0;
  }

/*POD
=H _ex_PopLabel()

This function is used to pop an unnamed label off the compile stack.

When a construct, like T<IF/ELSE/ENDIF> or T<REPEAT/UNTIL> or T<WHILE/WEND> is created
it is defined using compile time label stack.

For example analyzing the instruction T<WHILE> pushes a "go forward" value on the compile time
label stack. When the instruction T<WEND> is analyzed it pops off the value and stores
T<NodeId> for the label. The label itself is not present in the global label symbol table,
because it is an unnamed label and is referenced during compile time by the pointer to the
label structure.

The value of the T<AcceptedType> ensures that a T<WEND> for example do not matches an T<IF>.


/*FUNCTION*/
pSymbolLABEL _ex_PopLabel(peXobject pEx,
                          long *pAcceptedType
  ){
/*noverbatim

The array T<pAcceptedType> is an array of long values that have T<MAX_GO_CONSTANTS> values.
This is usually points to a static table element which is generated by the program T<syntaxer.pl>.

=bold
Do NOT get confused! This stack is NOT the same as the waiting label stack. That is for named
labels.
=nobold
CUT*/
  pLabelStack q;
  pSymbolLABEL p;
  int i = MAX_GO_CONSTANTS;
  long lTypeOnStack;

  if( pEx->pComeAndGoStack == NULL )return NULL;
  p = pEx->pComeAndGoStack->pLabel;
  lTypeOnStack = pEx->pComeAndGoStack->Type;
  pEx->pComeAndGoStack->pLabel = NULL; /* be safe */
  q = pEx->pComeAndGoStack->Flink;
  pEx->pComeAndGoStack->Flink = pEx->pFreeComeAndGoStack;
  pEx->pFreeComeAndGoStack = pEx->pComeAndGoStack;
  pEx->pComeAndGoStack = q;

  if( pAcceptedType ){ /* passing NULL means that we do not care the type (usually to clean up the stack) */
    while( i-- )
      if( *pAcceptedType++ == lTypeOnStack )return p;
    REPORT(LexemeFileName,LexemeLineNumber,EX_ERROR_BAD_NESTING,NULL);
    }

  return p;
  }

/*POD
=H _ex_CleanLabelStack()

This function is used to clean the unnamed label stack whenever
a locality is left. This helps to detect when an instruction like
T<FOR> or T<WHILE> is not closed within a function.
/*FUNCTION*/
void _ex_CleanLabelStack(peXobject pEx
  ){
/*noverbatim
CUT*/

  if( ex_PopLabel(NULL) )
    REPORT(LexemeFileName,LexemeLineNumber,EX_ERROR_UNFINISHED_NESTING,NULL);
  while( ex_PopLabel(NULL) );
  }

/*POD
=H Some NOTE on SymbolXXX functions

The functions named T<SymbolXXX> like T<SymbolLABEL>, or T<SymbolUF> do NOT store 
the names of the symbols. They are named T<SymbolXXX> because they are natural
extensions of the symbol table system. In other compilers the functionality to
retrieve the arguments of a symbol is part of the symbol table handling routines.

In script basic the symbol table handling routines were developed to be general purpose.
Therefore all the arguments the symbol table functions bind toa symbol is a T<void *>
pointer. This pointer points to a struct that holds the arguments of the symbols,
and the functions T<SymbolXXX> allocate the storage for the arguments.

This way it is possible to allocate arguments for non-existing symbols, as it is done
for labels. Script basic uses non-named labels to arrange the "jump" instructions for
T<IF/ELSE/ENDIF> constructs. (And for some other constructs as well.) The label and
jump constructs look like:

=verbatim

       IF expression Then

       ELSE
label1:


       END IF
label2:

=noverbatim

The labels T<label1> and T<label2> do not have names in the system, not even autogenerated names.
They are referenced via pointers and their value (the T<NodeId> of the instruction) get into the
T<SymbolLABEL> structure and later int o the T<cNODE> during build.

CUT*/

/*POD
=H _new_SymbolLABEL()

This function should be used to create a new label. The label can be named or unnamed. Note that
this structure does NOT contain the name of the label.

/*FUNCTION*/
pSymbolLABEL _new_SymbolLABEL(peXobject pEx
  ){
/*noverbatim

Also note that all labels are global in a basic program and are subject to name space decoration.
However the same named label can not be used in two different functions in the same name space.

A label has a serial value, which is not actually used and a number of the node that it points to.

See the comments on R<ex_symbols()>.
CUT*/
  pSymbolLABEL p;

  p = (pSymbolLABEL)alloc_Alloc(sizeof(SymbolLABEL),pEx->pMemorySegment);
  if( p == NULL )return NULL;
  pEx->cGlobalLabels ++;
  p->Serial = pEx->cGlobalLabels;
  p->node = 0; /* this means that the struct has no value */
  return p;
  }

/*POD
=H _new_SymbolVAR()

This function should be used to create a new variable during compile time. A
variable is nothing else than a serial number. This serial number starts
from 1.

/*FUNCTION*/
pSymbolVAR _new_SymbolVAR(peXobject pEx,
                          int iLocal
  ){
/*noverbatim

The second argument should be true for local variables. The counting of local
variables are reset whenever the program enters a new locality. Localities can
not be nested.

Also note that local variables are allocated in a different segment because they
are deallocated whenever the syntax analyzer leaves a locality.
CUT*/
  pSymbolVAR p;

  if( iLocal ){
    p = (pSymbolVAR)alloc_Alloc(sizeof(SymbolVAR),pEx->pLocalVarMemorySegment);
    if( p == NULL )return NULL;
    pEx->cLocalVariables++;
    p->Serial = pEx->cLocalVariables;
    }else{
    p = (pSymbolVAR)alloc_Alloc(sizeof(SymbolVAR),pEx->pMemorySegment);
    if( p == NULL )return NULL;
    pEx->cGlobalVariables++;
    p->Serial = pEx->cGlobalVariables;
    }

  return p;
  }

/*POD
=H _new_SymbolUF()

This function should be used to create a new user defined function symbol.
/*FUNCTION*/
pSymbolUF _new_SymbolUF(peXobject pEx
  ){
/*noverbatim

A user function is defined by its serial number (serial number is actually not used in the
current sytsem) and by the node number where the function actually starts.

The number of arguments and the number of local variables are defined in the generated
command and not in the symbol table. This way these numbers are available as they should be
during run time.
CUT*/
  pSymbolUF p;

  p = (pSymbolUF)alloc_Alloc(sizeof(SymbolUF),pEx->pMemorySegment);
  if( p == NULL )return NULL;

  pEx->cUserFunctions ++;
  p->FunId = pEx->cUserFunctions;
  p->next = pEx->FirstUF;
  pEx->FirstUF = p;
  p->node = 0L;

  return p;
  }

/*POD
=H _new_eNODE()

This function should be used to create a new T<eNODE>.

/*FUNCTION*/
peNODE _new_eNODE(peXobject pEx
  ){
/*noverbatim

Each T<eNODE> and T<eNODE_l> structure has a serial number. The T<eNODE>s
are referencing each other using pointers. However after build these pointers
become integer numbers that refer to the ordinal number of the node. Nodes are
stored in a single memory block after they are packed during build.

An T<eNODE> is a structure that stores a unit of compiled code. For example
an addition in an expression is stored in an T<eNODE> containing the code for the
addition operator and containing pointers to the operands.

CUT*/
  peNODE p;

  p = (peNODE)alloc_Alloc(sizeof(eNODE),pEx->pMemorySegment);
  if( p == NULL )return NULL;
  pEx->NodeCounter ++;
  p->NodeId = pEx->NodeCounter;
  if( pEx->pLex->pLexCurrentLexeme ){
    p->szFileName = pEx->pLex->pLexCurrentLexeme->szFileName;
    p->lLineNumber = pEx->pLex->pLexCurrentLexeme->lLineNumber;
    }else{
    p->szFileName = NULL;
    p->lLineNumber = 0;
    }

  return p;
  }
/*POD
=H _new_eNODE_l()

This function should be used to create a new T<eNODE> list. This is nothing else
than a simple structure having two pointers. One pointer points to an T<eNODE>
while the other points to the next T<eNODE_l> struct or to NULL if the current
T<eNODE_l> is the last of a list.

/*FUNCTION*/
peNODE_l _new_eNODE_l(peXobject pEx,
                      char *pszFileName,
                      long lLineNumber
  ){
/*noverbatim

Note that T<eNODE> and T<eNODE_l> are converted to the same type of 
structure during build after the syntactical analysis is done.
CUT*/
  peNODE_l p;

  p = ((peNODE_l)alloc_Alloc(sizeof(eNODE_l),pEx->pMemorySegment));
  if( p == NULL )return NULL;
  pEx->NodeCounter ++;
  p->NodeId = pEx->NodeCounter;
  p->szFileName = NULL;
  p->lLineNumber = 0;
  if( pszFileName ){
    p->szFileName = pszFileName;
    p->lLineNumber = lLineNumber;
    }else
  if( pEx->pLex && pEx->pLex->pLexCurrentLexeme ){
    p->szFileName = pEx->pLex->pLexCurrentLexeme->szFileName;
    p->lLineNumber = pEx->pLex->pLexCurrentLexeme->lLineNumber;
    }
  /* initializing these pointers here makes life safer */
  p->rest = NULL;
  p->actualm = NULL;

  return p;
  }

/*POD
=H ex_free()

This function releases all memory that was allocated during syntax analysis.

/*FUNCTION*/
void ex_free(peXobject pEx
  ){
/*noverbatim
CUT*/

  alloc_FinishSegment(pEx->pMemorySegment);
  alloc_FinishSegment(pEx->pLocalVarMemorySegment);
  alloc_FinishSegment(pEx->pSymbolTableMemorySegment);
  pEx->pMemorySegment = NULL;
  }

/*POD
=H ex_init()

This function should be called before starting syntactical analysis. This
function 
=itemize
=item positions the lexeme pointer to the first lexeme,
=item initializes the memory segments needed for structured memory allocation, 
=item created the symbol tables
=item initializes 'class' variables
=item initializes the name space to be T<main::>
=noitemize

/*FUNCTION*/
int ex_init(peXobject pEx
  ){
/*noverbatim
CUT*/
  long i;


  lex_StartIteration(pEx->pLex);

  pEx->pMemorySegment
                      = alloc_InitSegment(pEx->memory_allocating_function,
                                          pEx->memory_releasing_function);
  if( pEx->pMemorySegment == NULL )return EX_ERROR_MEMORY_LOW;

  pEx->pSymbolTableMemorySegment
                      = alloc_InitSegment(pEx->memory_allocating_function,
                                          pEx->memory_releasing_function);
  if( pEx->pSymbolTableMemorySegment == NULL )return EX_ERROR_MEMORY_LOW;

  pEx->pLocalVarMemorySegment = alloc_InitSegment(pEx->memory_allocating_function,
                                          pEx->memory_releasing_function);
  if( pEx->pLocalVarMemorySegment == NULL )return EX_ERROR_MEMORY_LOW;


  pEx->GlobalVariables  = sym_NewSymbolTable(alloc_Alloc,pEx->pSymbolTableMemorySegment);
  pEx->GlobalLabels     = sym_NewSymbolTable(alloc_Alloc,pEx->pSymbolTableMemorySegment);
  pEx->GlobalConstants  = sym_NewSymbolTable(alloc_Alloc,pEx->pSymbolTableMemorySegment);

  if( pEx->GlobalVariables == NULL ||
      pEx->GlobalLabels == NULL ||
      pEx->GlobalConstants == NULL )return EX_ERROR_MEMORY_LOW;

  pEx->LocalVariables   = NULL; /* it is initialized when we go local */
  pEx->LocallyDeclaredGlobalVariables = NULL; /* it is initialized when we go local */
  pEx->UserFunctions    = sym_NewSymbolTable(alloc_Alloc,pEx->pSymbolTableMemorySegment);
  if( pEx->UserFunctions == NULL )return EX_ERROR_MEMORY_LOW;

  pEx->ThisFunction = NULL;

  pEx->NodeCounter = 0;

  /* no function is defined currently */
  pEx->pFunctionWaiting = NULL;

  /* no user functions are defined */
  pEx->FirstUF = NULL;

  /* there are no waiting come backs, nor waitiong go forwards */
  pEx->pComeAndGoStack = NULL;
  pEx->pFreeComeAndGoStack = NULL;

  /* we start with global variables and go to local when entering a user defined function */
  pEx->iWeAreLocal = 0;
  /* the default language feature is that globals need not be declared */
  pEx->iDeclareVars = 0;
  /* the default language feature is that undeclared variables are global */
  pEx->iDefaultLocal = 0;

  pEx->Buffer   = alloc_Alloc(pEx->cbBuffer*sizeof(char),pEx->pMemorySegment);
  pEx->CurrentNameSpace = alloc_Alloc(pEx->cbCurrentNameSpace*sizeof(char),pEx->pMemorySegment);

  if( !pEx->GlobalVariables  || 
      !pEx->UserFunctions    ||
      !pEx->BuiltInFunctions ||
      !pEx->GlobalLabels     ||
      !pEx->GlobalConstants  ||
      !pEx->Binaries         ||
      !pEx->CurrentNameSpace ||
    0
    ){
    ex_free(pEx);
    return EX_ERROR_MEMORY_LOW;
    }

  pEx->cGlobalLabels = 0;
  pEx->cGlobalVariables = 0;
  /* pEx->cLocalVariables  = 0; /* this is initialized when we go local */
  pEx->cUserFunctions   = 0;

  if( pEx->cbCurrentNameSpace < 7 ){
    ex_free(pEx);
    return EX_ERROR_TOO_LONG_NAME_SPACE;
    }
  strcpy(pEx->CurrentNameSpace,"main::");
  pEx->pOldNameSpace = NULL;
  pEx->cbStringTable = 0L;

  for( i=0 ; pEx->PredeclaredLongConstants[i].name ; i++ )
    ex_PredeclareGlobalLongConst(pEx,
                                 pEx->PredeclaredLongConstants[i].name,
                                 pEx->PredeclaredLongConstants[i].value);

  return EX_ERROR_SUCCESS;
}

/*POD
=H ex_CleanNamePath()

This function created a normalized name space name from a non normalized. This is a simple
string operation.

Think of name space as directories and variables as files. A simple variable name is in the
current name space. If there is a 'path' before the variable or function name the path has to be
used. This path can either be relative or absolute.

File system:

T< ../ > is used to denote the parent directory in file systems.

Name space:

T< _::> is used to denote the parent name space.

File system:

T< mydir/../yourdir> is the same as T<yourdir>

Name space:

T< myns::_::yourns> is the same as T<yourns>

This function removes the unneccesary downs and ups from the name space and creates the
result in the same buffer as the original. This can always be done as the result is always 
shorter. (Well, not longer.)

/*FUNCTION*/
void ex_CleanNamePath(char *s
  ){
/*noverbatim
CUT*/
  int i,j;
  int f; /* flag if we have found something to remove */

  while(1){
    j = 0; f = 0;
    for( i=0 ; s[i] ; i++ ){
      if( s[i] == ':' && s[i+1] == ':' && s[i+2] == '_' && s[i+3] == ':' && s[i+4] == ':' ){
        f = 1; /* relative upreference, like package::_::v is found */
        i += 5;
        break;
        }
      if( s[i] == ':' && s[i+1] == ':' ){
        j = i+2;
        i ++;
        continue;
        }
      }
    if( !f )return;
    while( s[j]=s[i] )i++,j++;/* pull down the end, and ...*/
    /* start over */
    }
  }

/*POD
=H ex_ConvertName()

Use this function to convert a relative name to absolute containing name space.

This function checks if the variable or function name is relative or absolute. If the
name is relative it creates the absolute name using the current name space as a base.

The result is always put into the T<Buffer>.

A name is relative if it does NOT contain T<::> at all (implicit relative),
if it starts with T<::> or is it starts with T<_::> (explicit relative).

/*FUNCTION*/
int ex_ConvertName(char *s,          /* name to convert            */
                   char *Buffer,     /* buffer to store the result */
                   size_t cbBuffer,  /* size of the buffer         */
                   peXobject pEx     /* current expression object  */
  ){
/*noverbatim

The error value is T<EX_ERROR_SUCCESS> (zero) menaing succesful conversion or
T<EX_ERROR_TOO_LONG_VARIABLE> meaning that the variable is too long for the
buffer.

Note that the buffer is allocated in R<ex_init()> according to the size value given in
the class variable T<cbBuffer>, which should be set by the main function calling
syntax analysis.
CUT*/
  int i;

  /* This is a zero or one character variable,
     it can not contain :: and therefore
     it is relative variable.                  */
  if( !s[0] || !s[1] ){
    if( cbBuffer < strlen(pEx->CurrentNameSpace) + strlen(s) + 1 )
      return EX_ERROR_TOO_LONG_VARIABLE;
    strcpy(Buffer,pEx->CurrentNameSpace);
    strcat(Buffer,s);
    return EX_ERROR_SUCCESS;
    }

  /* This starts with :: like ::variable or ::subpackage::variable
     This is an explicit relative variable.  */
  if( s[0] == ':' && s[1] == ':' ){
    if( cbBuffer < strlen(pEx->CurrentNameSpace) + strlen(s) - 1 )
      return EX_ERROR_TOO_LONG_VARIABLE;
    strcpy(Buffer,pEx->CurrentNameSpace);
    strcat(Buffer,s+2); /* current_name_space contains the trailing ::
                           we should not copy it twice. */
    ex_CleanNamePath(Buffer);    /* remove the package::_ references */
    return EX_ERROR_SUCCESS;
    }

  /* This starts with _:: like _::variable or _::subpackage::variable
     This is an explicit relative variable.  */
  if( s[0] == '_' && s[1] == ':' && s[2] == ':' ){
    if( cbBuffer < strlen(pEx->CurrentNameSpace) + strlen(s) + 1 )
      return EX_ERROR_TOO_LONG_VARIABLE;
    strcpy(Buffer,pEx->CurrentNameSpace);
    strcat(Buffer,s);
    ex_CleanNamePath(Buffer);    /* remove the package::_ references */
    return EX_ERROR_SUCCESS;
    }

  /* This is long enough to contain ::, and does not start with ::  */
  for( i=1 ; s[i] ; i++ ){
    /* if it contains :: inside and not in front then it is an absolute
       reference. */
    if( s[i] == ':' && s[i+1] == ':' ){
      if( cbBuffer < strlen(pEx->CurrentNameSpace) + 1 )
        return EX_ERROR_TOO_LONG_VARIABLE;
      strcpy(Buffer,s);
      ex_CleanNamePath(Buffer); /* let the user to write dirty paths if she wishes*/
      return EX_ERROR_SUCCESS;
      }
    }

   /* Finally this is a simple implicit relative variable
      without any :: inside or in front. */
   if( cbBuffer < strlen(pEx->CurrentNameSpace) + strlen(s) + 1 )
     return EX_ERROR_TOO_LONG_VARIABLE;
   strcpy(Buffer,pEx->CurrentNameSpace);
   strcat(Buffer,s);
   return EX_ERROR_SUCCESS;
}

/*POD
=H ex_IsBFun()

This function checks if the current lexeme is a built-in function and
returns pointer to the function in the table T<BuiltInFunctions> or
returns NULL if the symbol is not a built-in function.

/*FUNCTION*/
pBFun ex_IsBFun(peXobject pEx
  ){
/*noverbatim
CUT*/
  pBFun p;

  if( LexemeType != LEX_T_NSYMBOL )return NULL;
  p = pEx->BuiltInFunctions;

  while( p->OpCode && (long)p->OpCode != LexemeCode )p++;
  if( p->OpCode )return p;
  return NULL;
  }

/*POD
=H ex_IsUnop()

This function checks if the current lexeme is an unary operator and
returns the op code or zero if the lexem is not an unary operator.

/*FUNCTION*/
unsigned long ex_IsUnop(peXobject pEx
  ){
/*noverbatim
CUT*/
  unsigned long *p;

  if( LexemeType != LEX_T_NSYMBOL && LexemeType != LEX_T_ASYMBOL )return 0;
  p = pEx->Unaries;

  while( *p && (long)*p != LexemeCode )p++;
  return *p;
  }

/*POD
=H ex_IsBinop()

This function checks if the current lexeme is a binary operator of the given precedence
and returns the op code or zero.

/*FUNCTION*/
unsigned long ex_IsBinop(peXobject pEx,
               unsigned long precedence
  ){
/*noverbatim
CUT*/
  unsigned long *p;

  if( LexemeType != LEX_T_NSYMBOL && LexemeType != LEX_T_ASYMBOL )return 0;
  p = pEx->Binaries;

  while( *p && *p != (unsigned)LexemeCode )p += 2;
  if( *p && p[1] == precedence )return *p;
  return 0;
  }


/*POD
=H ex_LeftValueList()

This function works up a T<leftvalue_list> pseudo terminal and creates the nodes for it.

/*FUNCTION*/
peNODE_l ex_LeftValueList(peXobject pEx
  ){
/*noverbatim
CUT*/
  peNODE_l r;
  peNODE   q;

  q = ex_LeftValue(pEx);
  if( ! q )return NULL;
  r = new_eNODE_l();
  r->actualm = q;
  r->rest = NULL;
  if( LexemeType == LEX_T_CHARACTER && LexemeChar == ',' ){
    NextLexeme;
    r->rest = ex_LeftValueList(pEx);
    }
  return r;  
  }

/*POD
=H ex_ExpressionList()

This function works up an T<expression_list> pseudo terminal and creates
the nodes for it.
/*FUNCTION*/
peNODE_l ex_ExpressionList(peXobject pEx
  ){
/*noverbatim
CUT*/
  peNODE_l r;
  peNODE   q;

  q = ex_Expression_i(pEx,pEx->MAXPREC);
  if( ! q )return NULL;
  r = new_eNODE_l();
  r->actualm = q;
  r->rest = NULL;
  if( LexemeType == LEX_T_CHARACTER && LexemeChar == ',' ){
    NextLexeme;
    r->rest = ex_ExpressionList(pEx);
    if( r->rest == NULL )return NULL;
    }
  return r;  
  }

/*POD
=H ex_Local()

This function work up a T<local> pseudo terminal. This does not create any node.

/*FUNCTION*/
int ex_Local(peXobject pEx
  ){
/*noverbatim
The return value is T<0> if no error happens.

T<1> means sytax error (the coming token is not a symbol)

T<2> means that there is no local environment (aka. the T<local var> is not inside a function)
CUT*/
  void **pSymbol;

  if( LexemeType != LEX_T_ASYMBOL )return 1;
  ex_ConvertName(LexemeSymbol, pEx->Buffer,pEx->cbBuffer,pEx);
  if( WeAreNotLocal )return 2;
  pSymbol = sym_LookupSymbol(pEx->Buffer,        /* symbol we search */
                             pEx->LocallyDeclaredGlobalVariables,/* in this table */
                             0,                  /* do not insert the symbol as new */
                             alloc_Alloc,
                             alloc_Free,
                             pEx->pLocalVarMemorySegment);
  if( pSymbol )REPORT(LexemeFileName,LexemeLineNumber,EX_ERROR_GLODEF,pEx->Buffer);
  pSymbol = sym_LookupSymbol(pEx->Buffer,        /* symbol we search */
                             pEx->LocalVariables,/* in this table */
                             1,                  /* insert the symbol as new */
                             alloc_Alloc,
                             alloc_Free,
                             pEx->pLocalVarMemorySegment);
  /* if this variable was not declared yet as local then allocate a serial
     number for it and place to store the compile time information for it */
  if( *pSymbol == NULL )
    *pSymbol = (void *)new_SymbolVAR(LOCAL_VAR);
  NextLexeme;
  return 0;
  }

/*POD
=H ex_LocalList()

This function work up a T<local_list> pseudo terminal. This does not generate any node.

/*FUNCTION*/
int ex_LocalList(peXobject pEx
  ){
/*noverbatim
The return value is T<0> if no error happens.

T<1> means sytax error (the coming token is not a symbol)

T<2> means that there is no local environment (aka. the T<local var> is not inside a function)
CUT*/
  int iErr;

  iErr = ex_Local(pEx);
  if( iErr )return iErr;
  while( LexemeType == LEX_T_CHARACTER && LexemeChar == ',' ){
    NextLexeme;
    iErr = ex_Local(pEx);
    if( iErr )return iErr;
    }
  return 0;
  }




/*POD
=H ex_Global()

This function work up a T<global> pseudo terminal. This does not create any node.

/*FUNCTION*/
int ex_Global(peXobject pEx
  ){
/*noverbatim
The return value is T<0> if no error happens or the error is semantic and was
reported (global variable redefinition).

T<1> means syntax error (the coming token is not a symbol)

CUT*/
  void **pSymbol;
  void **plSymbol;

  if( LexemeType != LEX_T_ASYMBOL )return 1;
  ex_ConvertName(LexemeSymbol, pEx->Buffer,pEx->cbBuffer,pEx);

  /* when we are inside a sub or function (when we are local)
     GLOBAL only means that we want to use this global variable
     but it has to be declared before in global scope
   */
  if( WeAreLocal ){
    pSymbol = sym_LookupSymbol(pEx->Buffer,         /* symbol we search */
                              pEx->GlobalVariables,/* in this table */
                              0,
                              alloc_Alloc,
                              alloc_Free,
                              pEx->pMemorySegment);
    if( pSymbol == NULL ){
      if( DeclareVars )REPORT(LexemeFileName,LexemeLineNumber,EX_ERROR_UNDEF_GLOBAL,NULL);
      /* ok error was reported (or not) now declare the variable not to propagate the error */
      pSymbol = sym_LookupSymbol(pEx->Buffer,         /* symbol we search */
                                pEx->GlobalVariables,/* in this table */
                                1,                   /* insert the symbol as new */
                                alloc_Alloc,
                                alloc_Free,
                                pEx->pMemorySegment);
      }
    plSymbol = sym_LookupSymbol(pEx->Buffer,
                                pEx->LocalVariables,/* in this table */
                                0,                   /* do not insert the symbol as new */
                                alloc_Alloc,
                                alloc_Free,
                                pEx->pLocalVarMemorySegment);
    if( plSymbol ){/* this is declared as global, but it was already declared as local, confusing */
      REPORT(LexemeFileName,LexemeLineNumber,EX_ERROR_GLODEF,pEx->Buffer);
      NextLexeme;
      return 0;
      }
    /* now insert the symboil into this table so that we know that this global variable is in use in this subroutine */
    sym_LookupSymbol(pEx->Buffer,         /* symbol we search */
                      pEx->LocallyDeclaredGlobalVariables,/* in this table */
                      1,                   /* insert the symbol as new */
                      alloc_Alloc,
                      alloc_Free,
                      pEx->pLocalVarMemorySegment);
    }else{/* if WeAreNotLocal */
    pSymbol = sym_LookupSymbol(pEx->Buffer,        /* symbol we search         */
                              pEx->GlobalVariables,/* in this table            */
                              1,                   /* insert the symbol as new */
                              alloc_Alloc,
                              alloc_Free,
                              pEx->pMemorySegment);
    if( *pSymbol ){
      REPORT(LexemeFileName,LexemeLineNumber,EX_ERROR_GREDEF,pEx->Buffer);
      NextLexeme;
      return 0;
      }
    }
  *pSymbol = (void *)new_SymbolVAR(GLOBAL_VAR);
  NextLexeme;
  return 0;
  }

/*POD
=H ex_GlobalList()

This function work up a T<global_list> pseudo terminal. This does not generate any node.

/*FUNCTION*/
int ex_GlobalList(peXobject pEx
  ){
/*noverbatim
The return value is T<0> if no error happens.

T<1> means sytax error (the coming token is not a symbol)

T<2> means the variable was already defined
CUT*/
  int iErr;

  iErr = ex_Global(pEx);
  if( iErr )return iErr;
  while( LexemeType == LEX_T_CHARACTER && LexemeChar == ',' ){
    NextLexeme;
    iErr = ex_Global(pEx);
    if( iErr )return iErr;
    }
  return 0;
  }


/*POD
=H ex_LookupUserFunction()

This function searches a user defined function and returns a pointer to the symbol table entry.
If the second argument T<iInsert> is true the symbol is inserted into the table and an
undefined function is created. This is the case when a function is used before declared. If the
argument T<iInsert> is fales T<NULL> is returned if the function is not yet defined.

/*FUNCTION*/
void **ex_LookupUserFunction(peXobject pEx,
                             int iInsert
  ){
/*noverbatim
CUT*/
  void **pSymbol;

  pSymbol = sym_LookupSymbol(pEx->Buffer,
                             pEx->UserFunctions,
                             iInsert,
                             alloc_Alloc,
                             alloc_Free,
                             pEx->pSymbolTableMemorySegment);

  return pSymbol;
  }

/*POD
=H ex_LookupGlobalVariable

This function searches the global variable symbol table to find the global variable
with the name stored in T{pEx->Buffer}. If the variable was not declared then this function
inserts the variable into the symbol table if the argument T<iInsert> is true,
but nothing more: the symbol table entry remains T<NULL>.

/*FUNCTION*/
void **ex_LookupGlobalVariable(peXobject pEx,
                               int iInsert
  ){
/*noverbatim
The function returns pointer to the pointer stored in the symbol table associated with the global
variable.
CUT*/
  void **pSymbol;

  pSymbol = sym_LookupSymbol(pEx->Buffer,        /* the symbol we search */
                             pEx->GlobalVariables,/* in the global table */
                             iInsert,                   /* insert automatically as new if not found */
                             alloc_Alloc,
                             alloc_Free,
                             pEx->pSymbolTableMemorySegment);
  return pSymbol;
  }

/*POD
=H ex_LookupLocallyDeclaredGlobalVariable

This function searches the global variable symbol table to find the global variable
with the name stored in T{pEx->Buffer}. If the variable was not declared then this function
return T<NULL>. Othervise it returns a pointer to a T<void *> pointer, which is 
T<NULL>.

Note that this table is allocated when the program starts a T<sub> or T<function> (aka. when
we go local) and is used to register, which variables did the program declare
as global variables inside the subroutine. There is no any value associated with the symbols
in this table, as the symbols are also inserted into the global symbol table which serves
the purpose.

/*FUNCTION*/
void **ex_LookupLocallyDeclaredGlobalVariable(peXobject pEx
  ){
/*noverbatim
The function returns pointer to the pointer stored in the symbol table associated with the global
variable or T<NULL>.
CUT*/
  void **pSymbol;

  pSymbol = sym_LookupSymbol(pEx->Buffer,        /* the symbol we search */
                             pEx->LocallyDeclaredGlobalVariables,/* in the global table */
                             0,                   /* do not insert!  */
                             alloc_Alloc,
                             alloc_Free,
                             pEx->pLocalVarMemorySegment);
  return pSymbol;
  }

/*POD
=H ex_LookupLocalVariable

This function searches the local variable symbol table to find the local variable
with the name stored in T{pEx->Buffer}. If the variable was not declared and the argument T<iInsert>
is true then then this function inserts the variable into the symbol table, 
but nothing more: the symbol table entry remains
T<NULL>.

/*FUNCTION*/
void **ex_LookupLocalVariable(peXobject pEx,
                              int iInsert
  ){
/*noverbatim
The function returns pointer to the pointer stored in the symbol table associated with the global
variable.
CUT*/
  void **pSymbol;

  pSymbol = sym_LookupSymbol(pEx->Buffer,        /* the symbol we search */
                             pEx->LocalVariables,/* in the actual local table */
                             iInsert,                   /* insert automatically as new if not found */
                             alloc_Alloc,
                             alloc_Free,
                             pEx->pLocalVarMemorySegment);
  return pSymbol;
  }

/*POD
=H ex_Tag

This function implements the syntax analysis for the lowest syntax elements of an expression.
This function is called when syntax analysis believes that a TAG has to be worked up
in an expression. A tag is defined formally as

=verbatim
 tag ::= UNOP tag
         BUN '(' expression_list ')'
         NUMBER
         STRING
         '(' expression ')'
         VARIABLE { '[' expression_list ']' }
         VARIABLE '{' expression_list '}'
         FUNC '(' expression_list ')'
        .
=noverbatim

/*FUNCTION*/
peNODE ex_Tag(peXobject pEx
  ){
/*noverbatim
The function returns pointer to the new node.
CUT*/

/*
Hey!!! Unary operators do not have precedence! They are above all! Is this
your original intention, or did it just came out like this?!!
*/
  peNODE q,r;
  peNODE_l z;
  long OpCode;
  char *s,*pszFN;
  int is_local;
  int is_assoc; /* the array reference we are currently analize is associative */
  long arg_count;
  void **pSymbol;
  pBFun pFunction;
  pLexeme pConstantLexeme;

  /* BUN '(' expression_list ')' */
  if( pFunction = ex_IsBFun(pEx) ){
    q = new_eNODE();
    if( q == NULL )return NULL;
    q->OpCode = LexemeCode;
    NextLexeme;
    if( LexemeType == LEX_T_CHARACTER && LexemeChar == '('  ){
      NextLexeme;
      if( LexemeType == LEX_T_CHARACTER && LexemeChar == ')' ){
        NextLexeme;
        goto no_arguments; /* Sorry for the construct, I know this is dirty. */
        }
      q->Parameter.Arguments.Argument = ex_ExpressionList(pEx);
      if( LexemeType != LEX_T_CHARACTER || LexemeChar != ')' ){/* the closing ) is missing after function call */
        REPORT(LexemeFileName,LexemeLineNumber,EX_ERROR_MISSING_PAREN,NULL);
        }else{ NextLexeme; }
      /* go and check the number of arguments */
      z = q->Parameter.Arguments.Argument;
      arg_count = 0;
      while( z ){
        z = z->rest;
        arg_count++;
        }
      if( arg_count < pFunction->MinArgs )REPORT(LexemeFileName,LexemeLineNumber,EX_ERROR_TOO_FEW_ARGUMENTS,NULL);
      if( arg_count > pFunction->MaxArgs )REPORT(LexemeFileName,LexemeLineNumber,EX_ERROR_TOO_MANY_ARGUMENTS,NULL);
      return q;
      }else{/* if there is no '(' after the name of the built in function */
no_arguments:
      q->Parameter.Arguments.Argument = NULL;
      /* having a function call w/o () is OK if there is no need for arguments */
      if( pFunction->MinArgs == 0 )return q;
      REPORT(LexemeFileName,LexemeLineNumber,EX_ERROR_FUNCTION_NEEDS_ARGUMENTS,NULL);
      return q;
      }
    }

  /* UNOP tag */
  if( OpCode = ex_IsUnop(pEx) ){
    q = new_eNODE();
    if( q == NULL )return NULL;
    q->OpCode = OpCode;
    NextLexeme;
    q->Parameter.Arguments.Argument = new_eNODE_l();
    if( q->Parameter.Arguments.Argument == NULL ){
      alloc_Free(q,pEx->pMemorySegment);
      return NULL;
      }
    q->Parameter.Arguments.Argument->actualm = ex_Tag(pEx);
    q->Parameter.Arguments.Argument->rest = NULL;
    return q;
    }

  /* '(' expression ')' */
  if( LexemeType == LEX_T_CHARACTER && LexemeChar == '('  ){
    NextLexeme;
    q = ex_Expression_i(pEx,pEx->MAXPREC);
    if( LexemeType != LEX_T_CHARACTER || LexemeChar != ')' ){
      REPORT(LexemeFileName,LexemeLineNumber,EX_ERROR_MISSING_PAREN,NULL);
      }else{
      NextLexeme;
      }
    return q;
    }

  /* check declared constant, like

     const MyConstant = 1
                                       */
  /*--
     This piece of code checks if the current symbol is declared as local or global constant.
     First local constants are checked and then global constant. Locality and globality is done
     the same way as for labels.

     If a symbol is not a defined constant is_const remains zero and nothing happens, life goes on
     normal.

     If a symbol is a constant then the variable pConstantLexeme will
     point to the lexeme of the constant.
   */
  pConstantLexeme = NULL ;
  if( LexemeType == LEX_T_ASYMBOL ){
    if( ex_ConvertName(LexemeSymbol, pEx->Buffer,pEx->cbBuffer,pEx) )goto ConstFinish;
    strcat(pEx->Buffer,"'");
    if( pEx->ThisFunction ){
      if( strlen(pEx->Buffer) + strlen(pEx->ThisFunction->FunctionName) >= pEx->cbBuffer )
        goto ConstFinish;
      strcat(pEx->Buffer,pEx->ThisFunction->FunctionName );
      pSymbol = sym_LookupSymbol(pEx->Buffer, /* the symbol we search */
                                 pEx->GlobalConstants, /* in this table */
                                 0,                 /* do not insert the symbol as new */
                                 alloc_Alloc,
                                 alloc_Free,
                                 pEx->pSymbolTableMemorySegment);
      if( pSymbol ){
        pConstantLexeme = (pLexeme)*pSymbol;
        goto ConstFinish;
        }
      }
    /* we get here if this is not a local constant */
    for( s=pEx->Buffer ; *s && *s != '\'' ; s++ );
    if( *s )s++;
    if( *s )*s = (char)0; /* cut off the function name, try the global const if there is */
    pSymbol = sym_LookupSymbol(pEx->Buffer, /* the symbol we search */
                               pEx->GlobalConstants, /* in this table */
                               0,                 /* do not insert the symbol as new */
                               alloc_Alloc,
                               alloc_Free,
                               pEx->pSymbolTableMemorySegment);
    if( pSymbol ){
      pConstantLexeme = (pLexeme)*pSymbol;
      goto ConstFinish;
      }
    /* we get here if this is not a local symbol and is not module symbol try a global one */
    pSymbol = sym_LookupSymbol(LexemeSymbol, /* the symbol we search */
                               pEx->GlobalConstants, /* in this table */
                               0,                 /* do not insert the symbol as new */
                               alloc_Alloc,
                               alloc_Free,
                               pEx->pSymbolTableMemorySegment);
    if( pSymbol ){
      pConstantLexeme = (pLexeme)*pSymbol;
      goto ConstFinish;
      }
    }
ConstFinish:

  /* number or string */
  if( LexemeType == LEX_T_DOUBLE ||
      LexemeType == LEX_T_LONG   ||
      LexemeType == LEX_T_STRING ||
      pConstantLexeme
     ){

    if( pConstantLexeme == NULL )
      pConstantLexeme = pEx->pLex->pLexCurrentLexeme;

    q = new_eNODE();
    if( q == NULL )return NULL;
    switch( pConstantLexeme->type ){
      case LEX_T_DOUBLE:
        q->OpCode = eNTYPE_DBL;
        q->Parameter.Constant.Value.dValue = pConstantLexeme->value.dValue;
        break;
      case LEX_T_LONG:
        q->OpCode = eNTYPE_LNG;
        q->Parameter.Constant.Value.lValue = pConstantLexeme->value.lValue;
        break;
      case LEX_T_STRING: 
        q->OpCode = eNTYPE_STR;
        s = (char *)alloc_Alloc((pConstantLexeme->sLen+1)*sizeof(char),pEx->pMemorySegment);
        if( s == NULL ){
          alloc_Free(q,pEx->pMemorySegment);
          return NULL;
          }
        memcpy(s,pConstantLexeme->value.sValue,pConstantLexeme->sLen+1);
        pEx->cbStringTable += pConstantLexeme->sLen+1;
        COUNT_STRING_LEN
        q->Parameter.Constant.Value.sValue = s;
        q->Parameter.Constant.sLen = pConstantLexeme->sLen;
        break;
      default:
        REPORT(LexemeFileName,LexemeLineNumber,EX_ERROR_INTERNAL,NULL);
        break;
        }
    NextLexeme;
    return q;
    }

  /* variable or variable [ '[' expression_list ']' ]  or func '(' expression_list ')' */
   if( LexemeType == LEX_T_ASYMBOL ){
    q = new_eNODE();
    if( q == NULL )return NULL;
    ex_ConvertName(pszFN=LexemeSymbol, pEx->Buffer,pEx->cbBuffer,pEx);

    NextLexeme;
    if( LexemeType == LEX_T_CHARACTER && LexemeChar == '(' ){/* this is user function */
      pSymbol = ex_LookupUserFunction(pEx,1);
      if( *pSymbol == NULL ){
        /* This function has not been defined. */
        *pSymbol = (void *)new_SymbolUF();
        if( *pSymbol == NULL )return NULL;
        ((pSymbolUF)*pSymbol)->FunctionName = pszFN;
        }
      q->OpCode = eNTYPE_FUN;
      q->Parameter.UserFunction.pFunction = (pSymbolUF)(*pSymbol);
      NextLexeme;
      if( LexemeType == LEX_T_CHARACTER && LexemeChar == ')' ){
        /* empty parameter list */
        q->Parameter.UserFunction.Argument = NULL;
        NextLexeme;
        }else{
        q->Parameter.UserFunction.Argument = ex_ExpressionList(pEx);
        if( LexemeType != LEX_T_CHARACTER || LexemeChar != ')' ){/* the closing ) is missing after function call */
          REPORT(LexemeFileName,LexemeLineNumber,EX_ERROR_MISSING_PAREN,NULL);
          }else{ NextLexeme; }
        }
      return q;
      }
    if( LexemeType == LEX_T_CHARACTER && (LexemeChar == '[' || LexemeChar == '{') ){/* this is some array access */
      if( LexemeChar == '[' )is_assoc = 0; else is_assoc = 1;
      NextLexeme;
      q->OpCode = is_assoc ? eNTYPE_SAR : eNTYPE_ARR;
      if( WeAreNotLocal || (pSymbol = ex_LookupLocalVariable(pEx,0)) == NULL ){
        if( WeAreLocal && DefaultLocal && ex_LookupLocallyDeclaredGlobalVariable(pEx) == NULL ){
          pSymbol = ex_LookupLocalVariable(pEx,1);
          is_local = 1; 
          }else{
          pSymbol = ex_LookupGlobalVariable(pEx,1);
          is_local = 0; 
          }
        }else is_local = 1;

      if( *pSymbol == NULL ){/* this is a new variable symbol */
        if( DeclareVars )REPORT(LexemeFileName,LexemeLineNumber,EX_ERROR_UNDEF_GLOBAL,NULL);
      if( DefaultLocal && is_local )
          *pSymbol = (void *)new_SymbolVAR(LOCAL_VAR);
        else
          *pSymbol = (void *)new_SymbolVAR(GLOBAL_VAR);
        if( *pSymbol == NULL )return NULL;
        }else{/* this is an existing symbol */
        if( DeclareVars && DefaultLocal && is_local && ex_LookupLocallyDeclaredGlobalVariable(pEx) == NULL && ex_LookupLocalVariable(pEx,0) == NULL)
          REPORT(LexemeFileName,LexemeLineNumber,EX_ERROR_UNDEF_GLOBAL,NULL);
        }
      /* the first argument is the variable */
      q->Parameter.Arguments.Argument = new_eNODE_l();
      if( q->Parameter.Arguments.Argument == NULL )return NULL;
      q->Parameter.Arguments.Argument->actualm = new_eNODE();
      if( q->Parameter.Arguments.Argument->actualm == NULL )return NULL;
      q->Parameter.Arguments.Argument->actualm->Parameter.Variable.Serial = ((pSymbolVAR)(*pSymbol))->Serial;
      q->Parameter.Arguments.Argument->actualm->OpCode = is_local ? eNTYPE_LVR : eNTYPE_GVR;
      /* the rest of the arguments are the indices */
      q->Parameter.Arguments.Argument->rest = ex_ExpressionList(pEx);
      if( is_assoc )
        if( LexemeType != LEX_T_CHARACTER || LexemeChar != '}' ){/* the closing } is missing after array indexes */
          REPORT(LexemeFileName,LexemeLineNumber,EX_ERROR_MISSING_SAPAREN,NULL);
          }else{ NextLexeme; }
      else
        if( LexemeType != LEX_T_CHARACTER || LexemeChar != ']' ){/* the closing ] is missing after array indexes */
          REPORT(LexemeFileName,LexemeLineNumber,EX_ERROR_MISSING_APAREN,NULL);
          }else{ NextLexeme; }
      /* now process the additional indices, like a[13]{"alma"}[5] */
      while( LexemeType == LEX_T_CHARACTER && (LexemeChar == '[' || LexemeChar == '{') ){
        if( LexemeChar == '[' )is_assoc = 0; else is_assoc = 1;
        NextLexeme;
        r = q;
        q = new_eNODE();
        if( q == NULL )return NULL;
        q->OpCode = is_assoc ? eNTYPE_SAR : eNTYPE_ARR;
        q->Parameter.Arguments.Argument = new_eNODE_l();
        if( q->Parameter.Arguments.Argument == NULL )return NULL;
        /* The first element of the list is the array up to here, the rest is the actual index list. */
        q->Parameter.Arguments.Argument->actualm = r;
        /* the rest of the arguments are the indices */
        q->Parameter.Arguments.Argument->rest = ex_ExpressionList(pEx);
        if( is_assoc )
          if( LexemeType != LEX_T_CHARACTER || LexemeChar != '}' ){/* the closing } is missing after array indexes */
            REPORT(LexemeFileName,LexemeLineNumber,EX_ERROR_MISSING_SAPAREN,NULL);
            }else{ NextLexeme; }
        else
          if( LexemeType != LEX_T_CHARACTER || LexemeChar != ']' ){/* the closing ] is missing after array indexes */
            REPORT(LexemeFileName,LexemeLineNumber,EX_ERROR_MISSING_APAREN,NULL);
            }else{ NextLexeme; }
        }
      return q;
      }

    /* this is a simple variable */
    if( WeAreNotLocal || (pSymbol = ex_LookupLocalVariable(pEx,0)) == NULL ){
      if( WeAreLocal && DefaultLocal && ex_LookupLocallyDeclaredGlobalVariable(pEx) == NULL ){
        /* if we are local, the variable is not 
           declared and by default all undeclared variables are local */
        pSymbol = ex_LookupLocalVariable(pEx,1);
        is_local = 1;
        }else{
        /* if we are global or undeclared variables are global */
        pSymbol = ex_LookupGlobalVariable(pEx,1);
        is_local = 0;
        }
      }else is_local = 1;
    if( *pSymbol == NULL ){/* this is a new variable symbol */
      if( DeclareVars )REPORT(LexemeFileName,LexemeLineNumber,EX_ERROR_UNDEF_GLOBAL,NULL);
    if( DefaultLocal && is_local )
        *pSymbol = (void *)new_SymbolVAR(LOCAL_VAR);
      else
        *pSymbol = (void *)new_SymbolVAR(GLOBAL_VAR);
      if( *pSymbol == NULL )return NULL;
      }else{/* this is an existing symbol */
      if( DeclareVars && DefaultLocal && is_local && ex_LookupLocallyDeclaredGlobalVariable(pEx) == NULL && ex_LookupLocalVariable(pEx,0) == NULL)
        REPORT(LexemeFileName,LexemeLineNumber,EX_ERROR_UNDEF_GLOBAL,NULL);
      }
    q->OpCode = is_local ? eNTYPE_LVR : eNTYPE_GVR;
    q->Parameter.Variable.Serial = ((pSymbolVAR)(*pSymbol))->Serial;
    return q;
    }
   return NULL;
}

/*POD
=H ex_Expression_i

This function is called to analyze a sub-expression that has no lower precedence operators
than T<i> (unless enclosed in parentheses inside the sub expression).

If the argument variable T<i> is T<1> then this function simply calls R<ex_Tag>. Otherwise it
calls itself recursively twice with optionally compiling the operator between the 
two subexpressions.

/*FUNCTION*/
peNODE ex_Expression_i(peXobject pEx,
                       int i
  ){
/*noverbatim
The function returns pointer to the new node.
CUT*/
  peNODE fo; /* first operand */
  peNODE q;
  int iOperation;

  if( i == 1 )return ex_Tag(pEx);

  fo = ex_Expression_i(pEx,i-1); /* first operand */
  if( fo == NULL )return NULL;
  while( iOperation = ex_IsBinop(pEx,i-1) ){
    q = new_eNODE();
    if( q == NULL )return NULL;
    q->OpCode = iOperation;
    q->Parameter.Arguments.Argument = new_eNODE_l();
    if( q->Parameter.Arguments.Argument == NULL )return NULL;
    q->Parameter.Arguments.Argument->actualm = fo;
    q->Parameter.Arguments.Argument->rest = new_eNODE_l();
    if( q->Parameter.Arguments.Argument->rest == NULL )return NULL;
    NextLexeme;
    q->Parameter.Arguments.Argument->rest->actualm = ex_Expression_i(pEx,i-1);
    /*this was inserted for v1.0b20 to report error on expression having no right argument for an op, like
      if a= then 
    */
    if( q->Parameter.Arguments.Argument->rest->actualm == NULL )return NULL;
    fo = q;
    }
  return fo;
}

/*POD
=H ex_Expression_r

This function implements the syntax analysis for an expression. This is quite simple. It only
calls R<ex_Expression_i> to handle the lower precendece expression. 
/*FUNCTION*/
void ex_Expression_r(peXobject pEx,
                     peNODE *Result
  ){
/*noverbatim
CUT*/
  *Result = ex_Expression_i(pEx,pEx->MAXPREC);
  }

/*POD
=H ex_IsSymbolValidLval(pEx)

This function checks whether the actual symbol used in as a start symbol of a left value
is defined as a CONST in the BASIC program or not. If this is a const then the syntax analizer
has to report an error (since v1.0b31).

This function is called from the function R<ex_LeftValue> after the symbol was name space corrected.

Note that a symbol can be a global, name space independant constant, a name space local constant and
a function local constant. All these differ only in name decoration inside the interpreter.

If a symbol is a local variable but is also a module or global symbol, but is NOT a function local symbol
then that variable can indeed stand on the left side of a LET command. Therefore we check if the symbol
is in the local variables table and in case this is in some of the global or module contant table,
we just do not care.
/*FUNCTION*/
int ex_IsSymbolValidLval(peXobject pEx
  ){
/*noverbatim
The function returns 1 if the symbol is a constant or zero if not.
CUT*/
  void **pSymbol;
  char *s;
  char *fs;
  int isLocalVar;

  fs = pEx->Buffer + strlen(pEx->Buffer);
  if( pEx->iWeAreLocal && pEx->ThisFunction ){
    pSymbol = sym_LookupSymbol(pEx->Buffer,        /* symbol we search */
                               pEx->LocalVariables,/* in this table */
                               0,                  /* dont insert if this is not a local symbol */
                               alloc_Alloc,
                               alloc_Free,
                               pEx->pLocalVarMemorySegment);
    isLocalVar = NULL != pSymbol; /* this may be a local variable if it is in the symbol table,
                                     thoug let's check if this is a local constant */
    }else isLocalVar = 0; /* can not be a local variable in a global environment */

  strcpy(fs,"'");
  if( pEx->iWeAreLocal && pEx->ThisFunction ){
    if( strlen(pEx->Buffer) + strlen(pEx->ThisFunction->FunctionName) >= pEx->cbBuffer )
      return 0;
    strcat(pEx->Buffer,pEx->ThisFunction->FunctionName );
    pSymbol = sym_LookupSymbol(pEx->Buffer, /* the symbol we search */
                                pEx->GlobalConstants, /* in this table */
                                0,                 /* do not insert the symbol as new */
                                alloc_Alloc,
                                alloc_Free,
                                pEx->pSymbolTableMemorySegment);
    if( pSymbol && *pSymbol )return 1; /* this is a local constant */
    }

  /* If this is a local var then no further checks are needed. This is a local variable and that is it. */
  if( isLocalVar ){
    /* restore the symbol name cutting off all that has been appended, the ' and the function name */
    *fs = (char)0;
    return 0;/* this is not a const, this is a valid lval symbol */
    }

  /* we get here if this is not a function local constant nor a declared local variable */
  s = fs + 1 ;
  if( *s )*s = (char)0; /* cut off the function name, try the global const if there is */
  pSymbol = sym_LookupSymbol(pEx->Buffer, /* the symbol we search */
                             pEx->GlobalConstants, /* in this table */
                             0,                 /* do not insert the symbol as new */
                             alloc_Alloc,
                             alloc_Free,
                             pEx->pSymbolTableMemorySegment);
  if( pSymbol && *pSymbol )return 1;/* this is a module symbol */

  /* we get here if this is not a local symbol and is not module symbol try a global one */
  pSymbol = sym_LookupSymbol(LexemeSymbol, /* the symbol we search */
                              pEx->GlobalConstants, /* in this table */
                              0,                 /* do not insert the symbol as new */
                              alloc_Alloc,
                              alloc_Free,
                              pEx->pSymbolTableMemorySegment);
  if( pSymbol && *pSymbol )return 1;

  /* restore the symbol name cutting off all that has been appended */
  *fs = (char)0;
  /* give it up, this is not a const... */
  return 0;
  }

/*POD
=H ex_LeftValue

This function implements the syntax analisys for a left value.

/*FUNCTION*/
peNODE ex_LeftValue(peXobject pEx
  ){
/*noverbatim
The function returns pointer to the new node.
CUT*/
  peNODE q,r;
  int is_local;
  int is_assoc; /* is the array reference associative? */
  void **pSymbol;

  if( LexemeType != LEX_T_ASYMBOL )return NULL;
  ex_ConvertName(LexemeSymbol, pEx->Buffer,pEx->cbBuffer,pEx);
  if( ex_IsSymbolValidLval(pEx) )REPORT(LexemeFileName,LexemeLineNumber,EX_ERROR_CONST_LVAL,NULL);

  NextLexeme;
  if( LexemeType == LEX_T_CHARACTER && (LexemeChar == '[' || LexemeChar == '{') ){
    if( LexemeChar == '{' )is_assoc = 1; else is_assoc = 0;
    NextLexeme;
    q = new_eNODE();
    if( q == NULL )return NULL;
    q->OpCode = is_assoc ? eNTYPE_SAR : eNTYPE_ARR;
    if( WeAreNotLocal || (pSymbol = ex_LookupLocalVariable(pEx,0)) == NULL ){
      if( WeAreLocal && DefaultLocal && ex_LookupLocallyDeclaredGlobalVariable(pEx) == NULL ){
        pSymbol = ex_LookupLocalVariable(pEx,1);
        is_local = 1; 
        }else{
        pSymbol = ex_LookupGlobalVariable(pEx,1);
        is_local = 0; 
        }
      }else is_local = 1;

    if( *pSymbol == NULL ){/* this is a new variable symbol */
      if( DeclareVars )REPORT(LexemeFileName,LexemeLineNumber,EX_ERROR_UNDEF_GLOBAL,NULL);
    if( DefaultLocal && is_local )
        *pSymbol = (void *)new_SymbolVAR(LOCAL_VAR);
      else
        *pSymbol = (void *)new_SymbolVAR(GLOBAL_VAR);
      if( *pSymbol == NULL )return NULL;
      }else{/* this is an existing symbol */
      if( DeclareVars && DefaultLocal && is_local && ex_LookupLocallyDeclaredGlobalVariable(pEx) == NULL && ex_LookupLocalVariable(pEx,0) == NULL)
        REPORT(LexemeFileName,LexemeLineNumber,EX_ERROR_UNDEF_GLOBAL,NULL);
      }
    /* the first argument is the variable */
    q->Parameter.Arguments.Argument = new_eNODE_l();
    if( q->Parameter.Arguments.Argument == NULL )return NULL;
    q->Parameter.Arguments.Argument->actualm = new_eNODE();
    if( q->Parameter.Arguments.Argument->actualm == NULL )return NULL;
    q->Parameter.Arguments.Argument->actualm->Parameter.Variable.Serial = ((pSymbolVAR)(*pSymbol))->Serial;
    q->Parameter.Arguments.Argument->actualm->OpCode = is_local ? eNTYPE_LVR : eNTYPE_GVR;
    /* the rest of the arguments are the indices */
    q->Parameter.Arguments.Argument->rest = ex_ExpressionList(pEx);
    if( is_assoc )
      if( LexemeType != LEX_T_CHARACTER || LexemeChar != '}' ){/* the closing } is missing after array indexes */
        REPORT(LexemeFileName,LexemeLineNumber,EX_ERROR_MISSING_SAPAREN,NULL);
        }else{ NextLexeme; }
    else
      if( LexemeType != LEX_T_CHARACTER || LexemeChar != ']' ){/* the closing ] is missing after array indexes */
        REPORT(LexemeFileName,LexemeLineNumber,EX_ERROR_MISSING_APAREN,NULL);
        }else{ NextLexeme; }
    /* now process the additional indices, like a[13]{"alma"}[5] */
    while( LexemeType == LEX_T_CHARACTER && (LexemeChar == '[' || LexemeChar == '{') ){
      if( LexemeChar == '[' )is_assoc = 0; else is_assoc = 1;
      NextLexeme;
      r = q;
      q = new_eNODE();
      if( q == NULL )return NULL;
      q->OpCode = is_assoc ? eNTYPE_SAR : eNTYPE_ARR;
      q->Parameter.Arguments.Argument = new_eNODE_l();
      if( q->Parameter.Arguments.Argument == NULL )return NULL;
      /* The first element of the list is the array up to here, the rest is the actual index list. */
      q->Parameter.Arguments.Argument->actualm = r;
      /* the rest of the arguments are the indices */
      q->Parameter.Arguments.Argument->rest = ex_ExpressionList(pEx);
      if( is_assoc )
        if( LexemeType != LEX_T_CHARACTER || LexemeChar != '}' ){/* the closing } is missing after array indexes */
          REPORT(LexemeFileName,LexemeLineNumber,EX_ERROR_MISSING_SAPAREN,NULL);
          }else{ NextLexeme; }
      else
        if( LexemeType != LEX_T_CHARACTER || LexemeChar != ']' ){/* the closing ] is missing after array indexes */
          REPORT(LexemeFileName,LexemeLineNumber,EX_ERROR_MISSING_APAREN,NULL);
          }else{ NextLexeme; }
      }
    return q;
    }

  q = new_eNODE();
  if( q == NULL )return NULL;
  /* this is a simple variable */
  if( WeAreNotLocal || (pSymbol = ex_LookupLocalVariable(pEx,0)) == NULL ){
    if( WeAreLocal && DefaultLocal && ex_LookupLocallyDeclaredGlobalVariable(pEx) == NULL ){
      pSymbol = ex_LookupLocalVariable(pEx,1);
      is_local = 1; 
      }else{
      pSymbol = ex_LookupGlobalVariable(pEx,1);
      is_local = 0; 
      }
    }else is_local = 1;
  if( *pSymbol == NULL ){
    if( DeclareVars )REPORT(LexemeFileName,LexemeLineNumber,EX_ERROR_UNDEF_GLOBAL,NULL);
    if( DefaultLocal && is_local )
      *pSymbol = (void *)new_SymbolVAR(LOCAL_VAR);
    else
      *pSymbol = (void *)new_SymbolVAR(GLOBAL_VAR);
    }else{/* this is an existing symbol */
    if( DeclareVars && DefaultLocal && is_local && ex_LookupLocallyDeclaredGlobalVariable(pEx) == NULL && ex_LookupLocalVariable(pEx,0) == NULL)
      REPORT(LexemeFileName,LexemeLineNumber,EX_ERROR_UNDEF_GLOBAL,NULL);
    }
  q->OpCode = is_local ? eNTYPE_LVR : eNTYPE_GVR;
  q->Parameter.Variable.Serial = ((pSymbolVAR)(*pSymbol))->Serial;
  return q;
  }

/*POD
=H ex_PredeclareGlobalLongConst()

This function is used to declare the global constants that are given
in the syntax defintinon, and should be defined before the program
is started to be analized.

/*FUNCTION*/
int ex_PredeclareGlobalLongConst(peXobject pEx,
                                 char *pszConstName,
                                 long lConstValue
  ){
/*noverbatim
CUT*/
  void **pSymbol;
  pLexeme pConstValue;
  void *prepar[2];

  prepar[0] = (void *)pszConstName;
  prepar[1] = (void *)lConstValue;
  pConstValue = alloc_Alloc(sizeof(Lexeme),pEx->pSymbolTableMemorySegment);
  if( pConstValue == NULL )return EX_ERROR_MEMORY_LOW;
  pSymbol = sym_LookupSymbol(pszConstName, /* the symbol we search */
                             pEx->GlobalConstants, /* in this table */
                             1,                 /* insert the symbol as new */
                             alloc_Alloc,
                             alloc_Free,
                             pEx->pSymbolTableMemorySegment);
  if( pSymbol == NULL )return 1;
  *pSymbol = (void *)pConstValue; /* note that this const value can be NULL to force a previously*/
  pConstValue->type = LEX_T_LONG;
  pConstValue->value.lValue = lConstValue;
  return 0;
  }

/*POD
=H ex_IsCommandThis

This is the most general syntax analysis function that tries to match the syntax
of the actual line syntax provided in argument T<p> against the token list at the actual
position.

The function has several side effects altering optionally the global and local variable table,
define user defined functions and so on.

The function signals the success of its operation via the argument T<piFailure> setting the T<int>
pointed by it to be zero or the error code.

If the syntax does not match the token list then the function cleans up all its actions if possible
to allow the caller to iterate over to the next syntax defintion. In such a situation
T<*piFailure> is set T<EX_ERROR_SYNTAX>

If the syntax does not match the token list but the analysis went too far and had side effects that
cannot be reversed then no cleanup is made. In such a situation T<*piFailure> is set
T<EX_ERROR_SYNTAX_FATAL>.

T<*piFailure> is also set to this value if the syntax definition reaches a "star" point. If the syntax
analysis matches a line up to a "star" point then the line should match that syntax definition or is
known erroneous. For example a command starting with the two keywords T<'declare' 'command'> after these
two keywords reach a "star" point because no other line syntax but extrenal command declaration starts
with these two keywords. In such a situation signalling fatal syntax error saves the compiler time
to check other syntax definition.

A "star" point is named this way, because the file T<syntax.def> uses the character T<*> to denote
this point in the syntax definitions.

/*FUNCTION*/
peNODE ex_IsCommandThis(peXobject pEx,
                        pLineSyntax p,
                        int *piFailure
  ){
/*noverbatim
If the syntax analysis fully matches the syntax definition provided in the argument
then the function returns the node that was generated. If more then one nodes were generated
during the syntax analysis of the line then the root node of the generated nodes is returned.
CUT*/
#define ABORT goto SYNTAX_FAILURE_DO_CLEANUP
#define ARGUMENT pArgument->Parameter.CommandArgument.Argument
#define ASSERT_NON_NULL(x) if( (x) == NULL ){ *piFailure = EX_ERROR_MEMORY_LOW; ABORT; }

#define NewArgument if( (*ppArgument = new_eNODE()) == NULL ){\
                       *piFailure = EX_ERROR_MEMORY_LOW;\
                       ABORT;\
                       }else{\
                       pArgument = *ppArgument;\
                       ppArgument = &(pArgument->Parameter.CommandArgument.next);\
                       *ppArgument = NULL;\
                       }
/*
This function call uses the stored memory segment because the memory is not release
in case of error, but stored in a local free list. This caused error in former versions
because the segment was released, but the local list still used the same memory. */
#define ex_PushLabel(y,z) _ex_PushLabel(pEx,y,z,pMyMemorySegment)

  void *pMyMemorySegment,*pSwapMemorySegment;
#define ex_SwapMemorySegment() do{ pSwapMemorySegment  = pEx->pMemorySegment; \
                                   pEx->pMemorySegment = pMyMemorySegment;    \
                                   pMyMemorySegment    = pSwapMemorySegment; }while(0)
  int iCurrentLex;
  int iSaveWeAreLocal;
  peNODE pCommandNode;
  peNODE *ppArgument,pArgument;
  pSymbolUF pFunction;
  pSymbolLABEL pLabel;
  void **pSymbol;
  void **pFailedFunctionSymbol;
  char *pszNewNameSpace;
  char *pszLabelDefined;
  char *pszConstDefined;
  int iConstGlobal;
  pLexeme pConstValue;
  char szNumericLabelName[80]; /* who is writing 10000...00 such a long basic label ?*/
  int iSideEffectWas;
  int iCommandNeedsCode;
  int fResetNameSpace;
  int StackCleanc;
  int isig;
  long sLen;

  iCommandNeedsCode = 1; /* command needs code even if there are no argument of the command */
  fResetNameSpace = 0;
  *piFailure = EX_ERROR_SUCCESS;
  iSaveWeAreLocal     = pEx->iWeAreLocal;
  pszNewNameSpace     = NULL;
  pszLabelDefined     = NULL;
  pszConstDefined     = NULL;
  pConstValue         = NULL;
  iSideEffectWas      = 0; /* there was no side effect so far */
  StackCleanc = 0;
  pFailedFunctionSymbol = NULL;
  pMyMemorySegment    = pEx->pMemorySegment; /* store the old value */
  /* allocate a new segment which is dropped on failure or merged on success */
  pEx->pMemorySegment = alloc_InitSegment(pEx->memory_allocating_function,
                                       pEx->memory_releasing_function);

  if( pEx->pMemorySegment == NULL ){
    pEx->pMemorySegment = pMyMemorySegment;
    return NULL;
    }
  ppArgument = &pCommandNode;
  pCommandNode = NULL;

  for( iCurrentLex = 0; p->lexes[iCurrentLex].type ; iCurrentLex ++ ){
    switch( p->lexes[iCurrentLex].type ){

      case EX_LEX_LOCAL_START: /* start local scope */
        if( pEx->iWeAreLocal )ABORT;/* this is some nested function construct,not allowed */
        pEx->iWeAreLocal = 1;
        pEx->cLocalVariables  = 0;
        NewArgument;
        pEx->plNrLocalVariables = &(ARGUMENT.lLongValue);
        pEx->LocalVariables = sym_NewSymbolTable(alloc_Alloc,pEx->pLocalVarMemorySegment);
        pEx->LocallyDeclaredGlobalVariables = sym_NewSymbolTable(alloc_Alloc,pEx->pLocalVarMemorySegment);
        CALL_PREPROCESSOR(PreprocessorExStartLocal,pEx);
        break;

      case EX_LEX_ARG_NUM: /* store the number of arguments */
        NewArgument;
        ARGUMENT.lLongValue = pEx->cLocalVariables;
        break;

      case EX_LEX_LOCAL_END: /* finish local scope */
        if( pEx->plNrLocalVariables )/* this may be NULL when a syntax error occured */
          *(pEx->plNrLocalVariables) = pEx->cLocalVariables;
        pEx->plNrLocalVariables = NULL; /* just to be safe */
        pEx->iWeAreLocal = 0;
        CALL_PREPROCESSOR(PreprocessorExEndLocal,pEx);
        /* there are other actions when the whole line is matched */
        break;

     case EX_LEX_STAR:
        iSideEffectWas = 1;
        break;

     case EX_LEX_NOEXEC:
        iCommandNeedsCode = 0;
        break;
/*
       NOTE that local variables ARE inserted into the symbol table during the evaluation.
       This happens even if the matching process fails. This means a restriction on the
       normal syntax defintions. The syntax should know that this is a valid line and this
       is a local variable defintion when the analysis gets here.
*/
      case EX_LEX_LOCAL:    /* local variable definition */
        iSideEffectWas = 1;
        if( ex_Local(pEx) )ABORT;
        break;

      case EX_LEX_LOCALL:   /* local variable definition list*/
        iSideEffectWas = 1;
        if( ex_LocalList(pEx) )ABORT;
        break;

      case EX_LEX_GLOBAL: /* global variable definition */
        iSideEffectWas = 1;
        if( ex_Global(pEx) )ABORT;
        break;

      case EX_LEX_GLOBALL:   /* global variable definition list*/
        iSideEffectWas = 1;
        if( ex_GlobalList(pEx) )ABORT;
        break;

/*
       NOTE that analyzing an expression or left value has a lot of side effects therefore the same restrictions
       will apply for expressions as does for LOCAL and LOCALL.
*/

      case EX_LEX_EXP:      /* expression */
        iSideEffectWas = 1;
        NewArgument;
        ex_Expression_r(pEx,&(ARGUMENT.pNode));
        if( ARGUMENT.pNode == NULL )ABORT;
        break;

      case EX_LEX_EXPL:     /* expression list */
        iSideEffectWas = 1;
        NewArgument;
        if( (ARGUMENT.pNodeList = ex_ExpressionList(pEx)) != NULL ){
          break; 
          }else{
          ABORT;
          }

/* Generally the LET instruction that starts with a left value should be placed at the end of
   the command definition list. This is because left value analysis makes some side effects,
   like inserting undeclared global variables into the symbol table. Therefore when an LVAL
   syntax element is reached during syntax analysis it should be sure that the instruction is
   the one that is currently checked or is syntactically incorrect.

   However this is a very strict rule, and to ease the syntax defintion table build up we
   check that the very first lexeme that comes when a left value (or list of lvals)
   is indeed a symbol. If this is not a symbol, then nothing fatal has happened, and we can abort the
   check against the current syntax defintion line without prohibiting the syntax analyzer to
   go on for other lines.
*/

      case EX_LEX_LVAL:     /* left value */
        if( LexemeType != LEX_T_ASYMBOL )ABORT; /* this is needed only to ease a bit 
                                                   syntax defintion table build up. */
        iSideEffectWas = 1;
        NewArgument;
        if( (ARGUMENT.pNode = ex_LeftValue(pEx)) != NULL ){
          break;
          }else{
          ABORT;
          }

      case EX_LEX_LVALL:     /* left value list */
        if( LexemeType != LEX_T_ASYMBOL )ABORT; /* this is needed only to ease a bit 
                                                   syntax defintion table build up. */
        iSideEffectWas = 1;
        NewArgument;
        if( (ARGUMENT.pNodeList = ex_LeftValueList(pEx)) != NULL ){
          break;
          }else{
          ABORT;
          }
/*
       NOTE that COME and GO virtual syntax elements push or pop values to/from the compile time stack.
       Therefore these elements should only appear at the end of the syntax defintion line where it is sure
       that the line is going to be accepted by this syntax definition.
*/
      case EX_LEX_GO_FORWARD:
        iSideEffectWas = 1;
        NewArgument;
        pLabel = (ARGUMENT.pLabel = new_SymbolLABEL());
        ex_PushLabel(pLabel,p->lexes[iCurrentLex].GoConstant[0]);
        StackCleanc++;
        break;

      case EX_LEX_GO_BACK:
        iSideEffectWas = 1;
        NewArgument;
        pLabel = (ARGUMENT.pLabel = ex_PopLabel(p->lexes[iCurrentLex].GoConstant));
        break;

      case EX_LEX_COME_FORWARD:
        iSideEffectWas = 1;
        pLabel = ex_PopLabel(p->lexes[iCurrentLex].GoConstant);
        /* Kevin Landman proposed that this check has to be done here to detect ELSE w/o any IF */
        if( NULL == pLabel ){
	        *piFailure = EX_ERROR_BAD_NESTING;
	        ABORT;
          }
        ex_PushWaitingLabel(pEx,pLabel);
        break;

      case EX_LEX_COME_BACK:
        iSideEffectWas = 1;
        pLabel = new_SymbolLABEL();
        ex_PushWaitingLabel(pEx,pLabel);
        ex_PushLabel(pLabel,p->lexes[iCurrentLex].GoConstant[0]);
        StackCleanc++;
        break;

      case EX_LEX_NSYMBOL: /* alpha or non-alpha symbol to ease handling and to let define alpha alternatives for non-alpha symbols */
        if( LexemeType != LEX_T_NSYMBOL )ABORT;
        /* printf("%s =?= %s\n",lex_SymbolicName(pEx->pLex,LexemeCode),lex_SymbolicName(pEx->pLex,p->lexes[iCurrentLex].OpCode)); */
        if( LexemeCode != p->lexes[iCurrentLex].OpCode )ABORT;
        NextLexeme;
        break;

      case EX_LEX_FUNCTION: /* a symbol that stands for a function or procedure name when function or
                               procedure is defined */
        if( LexemeType != LEX_T_ASYMBOL )ABORT;
        *piFailure = ex_ConvertName(LexemeSymbol, pEx->Buffer,pEx->cbBuffer,pEx);
        if( *piFailure )ABORT;
        pSymbol = ex_LookupUserFunction(pEx,1);
        ASSERT_NON_NULL(pSymbol);
        if( *pSymbol == NULL ){
          pFailedFunctionSymbol = pSymbol; /* we need this in case the command fails. */
          *pSymbol = (void *)(pFunction=new_SymbolUF());
          pFunction->node = 0; /* not defined yet */
          }
        else{
          pFunction = (pSymbolUF)*pSymbol;
          pFailedFunctionSymbol = NULL;
          }
        ASSERT_NON_NULL(pFunction)
        pEx->pFunctionWaiting = pFunction;
        pEx->ThisFunction = pFunction;
        pEx->ThisFunction->Argc = -1;
        pEx->ThisFunction->FunctionName = LexemeSymbol;
        if( pFunction->node ){
          *piFailure = EX_ERROR_FUNCTION_DOUBLE_DEFINED;
          ABORT;
          }
        NextLexeme;
        break;

      case EX_LEX_THIS_FUNCTION: /* a symbol that stands for a function or procedure name */
        if( LexemeType != LEX_T_ASYMBOL )ABORT;
        ex_ConvertName(LexemeSymbol, pEx->Buffer,pEx->cbBuffer,pEx);
        pSymbol = ex_LookupUserFunction(pEx,0);
        if( pSymbol == NULL )ABORT; /* no this is not a function name */
        pFunction = (pSymbolUF)*pSymbol;
        if( pEx->ThisFunction == NULL || 
            pFunction->FunId != pEx->ThisFunction->FunId )ABORT; /* this is a function name, but not the current */
        NextLexeme;
        break;

      case EX_LEX_CONST_NAME: /* a const is going to be defined (symbol) */
        if( LexemeType != LEX_T_ASYMBOL && LexemeType != LEX_T_LONG )ABORT;
        pszConstDefined = LexemeSymbol; /* there can only be one const defined on a line */
        /* the real const defintion takes place when the whole line is matched */
        NextLexeme;
        iConstGlobal = 0;
        break;

      case EX_LEX_GCONST_NAME: /* a global const is going to be defined (symbol) */
        if( LexemeType != LEX_T_ASYMBOL && LexemeType != LEX_T_LONG )ABORT;
        pszConstDefined = LexemeSymbol; /* there can only be one const defined on a line */
        /* the real const defintion takes place when the whole line is matched */
        NextLexeme;
        iConstGlobal = 1;
        break;

      case EX_LEX_CONST_VALUE:
        /* Here we have to let the user specify "simple exppression" as constant.
           The string -nnn or +nnn is never recognized as signed number by the lexical analyzer.
           It should not recognize it as signed number, because in that case we could face problems