1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 2221 2222 2223 2224 2225 2226 2227 2228 2229 2230 2231 2232 2233 2234 2235 2236 2237 2238 2239 2240 2241 2242 2243 2244 2245 2246 2247 2248 2249 2250 2251 2252 2253 2254 2255 2256 2257 2258 2259 2260 2261 2262 2263 2264 2265 2266 2267 2268 2269 2270 2271 2272 2273 2274 2275 2276 2277 2278 2279 2280 2281 2282 2283 2284 2285 2286 2287 2288 2289 2290 2291 2292 2293 2294 2295 2296 2297 2298 2299 2300 2301 2302 2303 2304 2305 2306 2307 2308 2309 2310 2311 2312 2313 2314 2315 2316 2317 2318 2319 2320 2321 2322 2323 2324 2325 2326 2327 2328 2329 2330 2331 2332 2333 2334 2335 2336 2337 2338 2339 2340 2341 2342 2343 2344 2345 2346 2347 2348 2349 2350 2351 2352 2353 2354 2355 2356 2357 2358 2359 2360 2361 2362 2363 2364 2365 2366 2367 2368 2369 2370 2371 2372 2373 2374 2375 2376 2377 2378 2379 2380 2381 2382 2383 2384 2385 2386 2387 2388 2389 2390
|
/* Syntax analyzer of Modula-2 translator.
Copyright (C) 1993-1997 (see more details in file COPYING).
This file is part of Modula-2 translator. */
#include "m2-common.h"
#include "m2-scanner.h"
#include "m2-syntax.h"
static ICN_pointer expression ();
static ICN_pointer rest_of_designator ();
static ICN_pointer simple_type ();
static ICN_pointer field_list_sequence ();
static void optional_priority ();
static void procedure_heading ();
static void import_list ();
/* This macros is used in macros SET_PRESENCE_FLAG_AND_TEST_CURRENT_SYMBOL
and TEST_CURRENT_SYMBOL for implementation of pass of macro parameters
containing commas. */
#define OR ,
/* The following macros is common part of macros TEST_CURRENT_SYMBOL and
SET_PRESENCE_FLAG_AND_TEST_CURRENT_SYMBOL. This part declares set string
and initiates it (if it is needed) by symbol table CONTEXT. */
#define SYMBOL_SET_STRING_DECLARATION(set_string) \
static char *set_string = NULL;\
if (set_string == NULL) set_string = new_symbol_set_string(context)
/* The following macros tests that current symbol is an expected symbol. All
expected symbols are in table SYMBOLS. If it is false than error MESSAGE
is fixed and syntax error recovery is on. Set strings are used to speed
up testing (see commentaries for macros SYMBOL_SET_STRING_DECLARATION). */
#define TEST_CURRENT_SYMBOL(symbols, message) do{\
static enum symbol context[] = {symbols, SYMBOL_END_MARK};\
SYMBOL_SET_STRING_DECLARATION (symbol_set_string);\
test_current_symbol (symbol_set_string, message);\
}while(FALSE)
/* The following macros is analogous to macros TEST_CURRENT_SYMBOL. This
macros also sets up flag to TRUE if current symbol is an expected symbol
after testing and possibly syntax error recovery. */
#define SET_PRESENCE_FLAG_AND_TEST_CURRENT_SYMBOL(flag, symbols, message) do{\
static enum symbol context[] = {symbols, SYMBOL_END_MARK};\
SYMBOL_SET_STRING_DECLARATION (symbol_set_string);\
flag = test_current_symbol (symbol_set_string, message);\
}while(FALSE)
/* The following macros sets up flag to TRUE if current symbol is an expected
symbol. All expected symbols are in table SYMBOLS. Set strings are used
to speed up the work. */
#define SET_UP_PRESENCE_FLAG_FOR_CURRENT_SYMBOL(flag, symbols) do{\
static enum symbol context[] = {symbols, SYMBOL_END_MARK};\
SYMBOL_SET_STRING_DECLARATION (symbol_set_string);\
flag = symbol_is_in_set_string (current_symbol, symbol_set_string);\
}while(FALSE)
/* Modula-2 syntax parser is implemented by recursive functions. Each function
analyzes and creates icode representation (see commentaries in file
m2-icode.h) of some language construction. Syntax of the construction is
placed in commentaries of the corresponding function. If the function
returns pointer to icode node the pointer identifies icode subgraph which
represents the corresponding construction.
Modula-2 syntax parser works in three regimes. Parsing in the first
regime (global variable testing_main_module is equal to TRUE) serves for
testing that given module is a main module. The work in this regime
finishes after parsing first keyword. Parsing in the second regime
(global variable picking_names_of_imported_modules is equal to TRUE)
serves for collection of names of imported modules. The work in this
regime finishes after parsing import clauses. The second regime serves
for parsing all compilation unit.
To describe the syntax, the same formalism (extended Backus-Naur Formalism
called EBNF) as in Wirth's book is used. But there exists one extension.
The construction {A/s} denotes A, AsA, AsAsA and etc.
Regular and optional parts of the language are implemented by C control
statements. The language recursion is implemented by recursive calls
of the corresponding functions.
Local syntax error recovery is described in scanner. Global syntax error
recovery is implemented by the stop symbols method with statement level.
Parsing error construction is ceased only when any stop symbol is achieved.
Here the stop symbols are symbols expected after the corresponding
construction.*/
/* Code for parsing expressions and statements. */
/* qualident = {IDENTIFIER/"."} */
static ICN_pointer
qualident ()
{
register ICN_pointer qualident_ptr, qualification_node_ptr;
for (qualident_ptr = NULL;; next_symbol ())
{
if (current_symbol == SYMBOL_IDENTIFIER)
{
if (qualident_ptr != NULL)
QUALIFICATION_NODE (qualident_ptr)->right_operand
= icode_symbol_presentation;
else
qualident_ptr = icode_symbol_presentation;
}
if (match_symbol (ERR_in_qualified_identifier, SYMBOL_IDENTIFIER)
!= SYMBOL_PERIOD)
break;
qualification_node_ptr = create_node (ICNM_QUALIFICATION);
QUALIFICATION_NODE (qualification_node_ptr)->left_operand
= qualident_ptr;
qualident_ptr = qualification_node_ptr;
}
return qualident_ptr;
}
static ICN_pointer
case_label_list (it_is_in_record)
register int it_is_in_record;
/* case_label_list = {expression [".."expression]/ ","} */
{
register ICN_pointer case_label_node_ptr, predecessor_in_label_list;
register ICN_pointer expression_ptr, case_variant_node_ptr;
int case_label_line;
case_variant_node_ptr
= create_node ((it_is_in_record
? ICNM_RECORD_CASE_VARIANT : ICNM_CASE_STATEMENT_VARIANT));
for (predecessor_in_label_list = case_variant_node_ptr;; next_symbol ())
{
case_label_line = source_line_number;
expression_ptr = expression ();
TEST_CURRENT_SYMBOL (SYMBOL_RANGE OR SYMBOL_COMMA OR SYMBOL_COLON,
ERR_in_case_label_list);
if (current_symbol == SYMBOL_RANGE)
{
case_label_node_ptr
= create_node ((it_is_in_record
? ICNM_RECORD_CASE_LABEL_RANGE
: ICNM_CASE_STATEMENT_LABEL_RANGE));
next_symbol ();
CASE_LABEL_RANGE_NODE (case_label_node_ptr)
->case_label_range_left_bound = expression_ptr;
CASE_LABEL_RANGE_NODE (case_label_node_ptr)
->case_label_range_right_bound = expression ();
}
else
{
case_label_node_ptr
= create_node ((it_is_in_record
? ICNM_RECORD_CASE_LABEL_ELEMENT
: ICNM_CASE_STATEMENT_LABEL_ELEMENT));
LINE (case_label_node_ptr) = case_label_line;
CASE_LABEL_ELEMENT_NODE (case_label_node_ptr)->case_label_value
= expression_ptr;
}
CASE_LABEL_LIST (predecessor_in_label_list) = case_label_node_ptr;
predecessor_in_label_list = case_label_node_ptr;
TEST_CURRENT_SYMBOL (SYMBOL_COMMA OR SYMBOL_COLON,
ERR_in_case_label_list);
if (current_symbol != SYMBOL_COMMA)
break;
}
return case_variant_node_ptr;
}
/* designator = IDENTIFIER rest_of_designator */
static ICN_pointer
designator ()
{
register ICN_pointer identifier_node_ptr;
if (current_symbol == SYMBOL_IDENTIFIER)
identifier_node_ptr = icode_symbol_presentation;
else
identifier_node_ptr = NULL;
match_symbol (ERR_in_qualified_identifier, SYMBOL_IDENTIFIER);
return rest_of_designator (identifier_node_ptr);
}
/* rest_of_designator = {"." IDENTIFIER | "[" {expression/","} "]" | "^"} */
static ICN_pointer
rest_of_designator (first_designator_identifier_ptr)
ICN_pointer first_designator_identifier_ptr;
{
register ICN_pointer designator_ptr, operation_ptr;
for (designator_ptr = first_designator_identifier_ptr;;)
if (current_symbol == SYMBOL_PERIOD)
{
operation_ptr = create_node (ICNM_QUALIFICATION);
next_symbol ();
QUALIFICATION_NODE (operation_ptr)->left_operand = designator_ptr;
designator_ptr = operation_ptr;
if (current_symbol == SYMBOL_IDENTIFIER)
QUALIFICATION_NODE (operation_ptr)->right_operand
= icode_symbol_presentation;
match_symbol (ERR_in_qualified_identifier, SYMBOL_IDENTIFIER);
}
else if (current_symbol == SYMBOL_LEFT_BRACKET)
{
next_symbol ();
for (;; next_symbol ())
{
operation_ptr = create_node (ICNM_INDEXING);
INDEXING_NODE (operation_ptr)->left_operand = designator_ptr;
designator_ptr = operation_ptr;
INDEXING_NODE (operation_ptr)->right_operand = expression ();
if (current_symbol != SYMBOL_COMMA)
break;
}
match_symbol (ERR_in_index_value, SYMBOL_RIGHT_BRACKET);
}
else if (current_symbol == SYMBOL_DEREFERENCING)
{
operation_ptr = create_node (ICNM_DEREFERENCING);
next_symbol ();
DEREFERENCING_NODE (operation_ptr)->operand = designator_ptr;
designator_ptr = operation_ptr;
}
else
break;
return designator_ptr;
}
/* The following function used by function expression for testing that
the current symbol is an expected symbol. All expected symbols are in
SYMBOL_TABLE. If it is false the function does nothing. Otherwise
the function skips the symbol, creates icode node with the corresponding
mode from MODE_TABLE and returns pointer to it. */
static ICN_pointer
test_current_symbol_and_create_node (symbol_table, mode_table)
enum symbol *symbol_table;
ICN_mode *mode_table;
{
register ICN_pointer result;
register int n;
n = number_of_current_symbol_in_table (symbol_table);
if (n >= 0)
{
result = create_node ((enum icode_node_mode) mode_table[n]);
next_symbol ();
return result;
}
return NULL;
}
/* expression=
{unary_operator
{
{
{"NOT"} (constant | "(" expression ")" |
[qualident] "{" [{expression [".."expression] /","}] "}" |
qualident rest_of_designator [ "(" [{expression/","}] ")" ]
)
/mul_operator}
/add_operator}
/relation}*2
Construction `*2' means maximum number of repeats (of operands).
*/
static ICN_pointer
expression ()
{
int number_of_relation_operators, set_with_qualident;
int line_of_node, presence_flag;
register ICN_pointer icode_node_ptr;
register ICN_pointer primary_ptr, factor_ptr, term_ptr, expression_ptr;
register ICN_pointer unary_operation_ptr;
register ICN_pointer first_not_node_ptr, last_not_node_ptr;
register ICN_pointer first_actual_parameter_ptr, predecessor;
register ICN_pointer expression_in_set_ptr;
for (number_of_relation_operators = 0, expression_ptr = NULL;;)
{
{
static enum symbol unop_symbol_table[] =
{
SYMBOL_ADDITION, SYMBOL_SUBTRACTION, SYMBOL_END_MARK
};
static ICN_mode unop_mode_table[] =
{
(ICN_mode) ICNM_IDENTITY, (ICN_mode) ICNM_SIGN_CONVERSION
};
unary_operation_ptr
= test_current_symbol_and_create_node (unop_symbol_table,
unop_mode_table);
}
for (term_ptr = NULL;;)
{
for (factor_ptr = NULL;;)
{
for (first_not_node_ptr = last_not_node_ptr = NULL;
current_symbol == SYMBOL_NOT;)
{
icode_node_ptr = create_node (ICNM_NOT);
next_symbol ();
if (first_not_node_ptr == NULL)
first_not_node_ptr = icode_node_ptr;
if (last_not_node_ptr != NULL)
NOT_NODE (last_not_node_ptr)->operand = icode_node_ptr;
last_not_node_ptr = icode_node_ptr;
}
TEST_CURRENT_SYMBOL
(SYMBOL_INTEGER OR SYMBOL_REAL OR SYMBOL_CHAR OR SYMBOL_STRING
OR SYMBOL_LEFT_PARENTHESIS OR SYMBOL_IDENTIFIER
OR SYMBOL_LEFT_SET_BRACKET, ERR_in_expression);
SET_UP_PRESENCE_FLAG_FOR_CURRENT_SYMBOL
(presence_flag, SYMBOL_INTEGER OR SYMBOL_REAL OR SYMBOL_CHAR
OR SYMBOL_STRING);
if (presence_flag)
{
primary_ptr = icode_symbol_presentation;
next_symbol ();
}
else
primary_ptr = NULL;
if (primary_ptr == NULL)
{
if (current_symbol == SYMBOL_LEFT_PARENTHESIS)
{
next_symbol ();
primary_ptr = expression ();
match_symbol (ERR_in_expression,
SYMBOL_RIGHT_PARENTHESIS);
}
else
{
line_of_node = source_line_number;
if (current_symbol == SYMBOL_IDENTIFIER)
{
set_with_qualident = TRUE;
primary_ptr = qualident ();
}
else
set_with_qualident = FALSE;
if (current_symbol == SYMBOL_LEFT_SET_BRACKET)
{
icode_node_ptr = create_node (ICNM_SET_VALUE_START);
LINE (icode_node_ptr) = line_of_node;
if (set_with_qualident)
SET_VALUE_START_NODE (icode_node_ptr)->left_operand
= primary_ptr;
else
SET_VALUE_START_NODE (icode_node_ptr)->left_operand
= ICN_POINTER (&ICN_TD_bitset);
primary_ptr = icode_node_ptr;
predecessor = NULL;
if (match_symbol (ERR_in_expression,
SYMBOL_LEFT_SET_BRACKET)
!= SYMBOL_RIGHT_SET_BRACKET)
{
for (;; next_symbol ())
{
line_of_node = source_line_number;
expression_in_set_ptr = expression ();
TEST_CURRENT_SYMBOL
(SYMBOL_RANGE OR SYMBOL_COMMA
OR SYMBOL_RIGHT_SET_BRACKET, ERR_in_set);
if (current_symbol == SYMBOL_RANGE)
{
icode_node_ptr
= create_node
(ICNM_RANGE_IN_SET_VALUE);
next_symbol ();
RANGE_IN_SET_VALUE_NODE (icode_node_ptr)
->left_operand = expression_in_set_ptr;
RANGE_IN_SET_VALUE_NODE (icode_node_ptr)
->right_operand = expression ();
}
else
{
icode_node_ptr
= create_node
(ICNM_ELEMENT_IN_SET_VALUE);
LINE (icode_node_ptr) = line_of_node;
ELEMENT_IN_SET_VALUE_NODE
(icode_node_ptr)->operand
= expression_in_set_ptr;
}
if (predecessor != NULL)
RIGHT_OPERAND (predecessor)
= icode_node_ptr;
else
predecessor = icode_node_ptr;
TEST_CURRENT_SYMBOL
(SYMBOL_COMMA OR SYMBOL_RIGHT_SET_BRACKET,
ERR_in_set);
if (current_symbol != SYMBOL_COMMA)
break;
icode_node_ptr = create_node (ICNM_ADDITION);
LEFT_OPERAND (icode_node_ptr) = predecessor;
predecessor = icode_node_ptr;
}
}
match_symbol (ERR_in_set, SYMBOL_RIGHT_SET_BRACKET);
SET_VALUE_START_NODE (primary_ptr)->right_operand
= predecessor;
}
else if (set_with_qualident)
{
primary_ptr = rest_of_designator (primary_ptr);
if (current_symbol == SYMBOL_LEFT_PARENTHESIS)
{
icode_node_ptr
= create_node (ICNM_FUNCTION_CALL);
next_symbol ();
FUNCTION_CALL_NODE (icode_node_ptr)
->function_designator = primary_ptr;
primary_ptr = icode_node_ptr;
first_actual_parameter_ptr = NULL;
if (current_symbol != SYMBOL_RIGHT_PARENTHESIS)
for (predecessor = NULL;; next_symbol ())
{
icode_node_ptr
= create_node (ICNM_ACTUAL_PARAMETER);
ACTUAL_PARAMETER_NODE (icode_node_ptr)
->actual_parameter_expression
= expression ();
if (first_actual_parameter_ptr == NULL)
first_actual_parameter_ptr
= icode_node_ptr;
if (predecessor != NULL)
ACTUAL_PARAMETER_NODE (predecessor)
->next_actual_parameter
= icode_node_ptr;
predecessor = icode_node_ptr;
TEST_CURRENT_SYMBOL
(SYMBOL_COMMA
OR SYMBOL_RIGHT_PARENTHESIS,
ERR_in_actual_parameters);
if (current_symbol != SYMBOL_COMMA)
break;
}
FUNCTION_CALL_NODE (primary_ptr)
->function_actual_parameter_list
= first_actual_parameter_ptr;
match_symbol (ERR_in_actual_parameters,
SYMBOL_RIGHT_PARENTHESIS);
}
}
}
}
if (last_not_node_ptr != NULL)
{
NOT_NODE (last_not_node_ptr)->operand = primary_ptr;
primary_ptr = first_not_node_ptr;
}
if (factor_ptr != NULL)
RIGHT_OPERAND (factor_ptr) = primary_ptr;
else
factor_ptr = primary_ptr;
{
static enum symbol mulop_symbol_table[] =
{
SYMBOL_AND, SYMBOL_MULTIPLICATION, SYMBOL_DIV, SYMBOL_MOD,
SYMBOL_DIVISION, SYMBOL_END_MARK
};
static ICN_mode mulop_mode_table[] =
{
(ICN_mode) ICNM_AND, (ICN_mode) ICNM_MULT,
(ICN_mode) ICNM_DIV, (ICN_mode) ICNM_MOD,
(ICN_mode) ICNM_REAL_DIVISION
};
icode_node_ptr
= test_current_symbol_and_create_node (mulop_symbol_table,
mulop_mode_table);
}
if (icode_node_ptr == NULL)
break;
LEFT_OPERAND (icode_node_ptr) = factor_ptr;
factor_ptr = icode_node_ptr;
}
if (unary_operation_ptr != NULL)
{
OPERAND (unary_operation_ptr) = factor_ptr;
factor_ptr = unary_operation_ptr;
unary_operation_ptr = NULL;
}
if (term_ptr != NULL)
RIGHT_OPERAND (term_ptr) = factor_ptr;
else
term_ptr = factor_ptr;
{
static enum symbol addop_symbol_table[] =
{
SYMBOL_ADDITION, SYMBOL_SUBTRACTION, SYMBOL_OR, SYMBOL_END_MARK
};
static ICN_mode addop_mode_table[] =
{
(ICN_mode) ICNM_ADDITION, (ICN_mode) ICNM_SUBTRACTION,
(ICN_mode) ICNM_OR
};
icode_node_ptr
= test_current_symbol_and_create_node (addop_symbol_table,
addop_mode_table);
}
if (icode_node_ptr == NULL)
break;
LEFT_OPERAND (icode_node_ptr) = term_ptr;
term_ptr = icode_node_ptr;
}
if (expression_ptr != NULL)
RIGHT_OPERAND (expression_ptr) = term_ptr;
else
expression_ptr = term_ptr;
number_of_relation_operators++;
if (number_of_relation_operators > 1)
break;
else
{
{
static enum symbol relation_symbol_table[] =
{
SYMBOL_EQUAL, SYMBOL_UNEQUAL, SYMBOL_LESS_THAN,
SYMBOL_GREATER_THAN, SYMBOL_LESS_THAN_OR_EQUAL,
SYMBOL_GREATER_THAN_OR_EQUAL, SYMBOL_IN, SYMBOL_END_MARK
};
static ICN_mode relation_mode_table[] =
{
(ICN_mode) ICNM_EQUAL, (ICN_mode) ICNM_UNEQUAL,
(ICN_mode) ICNM_LESS_THAN, (ICN_mode) ICNM_GREATER_THAN,
(ICN_mode) ICNM_LESS_OR_EQUAL, (ICN_mode) ICNM_GREATER_OR_EQUAL,
(ICN_mode) ICNM_IN
};
icode_node_ptr
= test_current_symbol_and_create_node (relation_symbol_table,
relation_mode_table);
}
if (icode_node_ptr == NULL)
break;
}
LEFT_OPERAND (icode_node_ptr) = expression_ptr;
expression_ptr = icode_node_ptr;
}
return expression_ptr;
}
/* statement_sequence =
{
[
designator ":=" expression |
designator["(" [{expression/","}]")"] |
"EXIT" |
"RETURN" [expression] |
"IF" expression "THEN" statement_sequence
{"ELSIF" expression "THEN" statement_sequence}
["ELSE" statement_sequence] "END" |
"CASE" expression "OF"{[case_label_list ":" statement_sequence]/"|"}
["ELSE" statement_sequence] "END" |
"WHILE" expression "DO" statement_sequence "END" |
"REPEAT" statement_sequence "UNTIL" expression |
"FOR" IDENTIFIER":=" expression "TO" expression ["BY" expression]
"DO" statmentsequnence "END" |
"LOOP" statement_sequence "END" |
"WITH" designator "DO" statement_sequence "END" | CTEXT
]
/";"}
*/
static ICN_pointer
statement_sequence ()
{
register ICN_pointer current_statement_ptr;
register ICN_pointer node_ptr, pred_node_ptr, first_node_ptr;
register ICN_pointer statement_list_head, pred_statement_ptr;
int line_of_identifier, presence_flag;
char *C_text_in_icode_memory;
for (pred_statement_ptr = statement_list_head = NULL;;)
{
TEST_CURRENT_SYMBOL
(SYMBOL_IDENTIFIER OR SYMBOL_EXIT OR SYMBOL_RETURN OR SYMBOL_IF
OR SYMBOL_CASE OR SYMBOL_WHILE OR SYMBOL_REPEAT OR SYMBOL_FOR
OR SYMBOL_LOOP OR SYMBOL_WITH OR SYMBOL_C_TEXT OR SYMBOL_SEMICOLON
OR SYMBOL_END OR SYMBOL_ELSE OR SYMBOL_ELSIF OR SYMBOL_BAR
OR SYMBOL_UNTIL, ERR_in_statement);
ADD_STOP_SYMBOL (SYMBOL_SEMICOLON);
if (current_symbol == SYMBOL_IDENTIFIER)
{
line_of_identifier = source_line_number;
node_ptr = designator ();
TEST_CURRENT_SYMBOL
(SYMBOL_ASSIGNMENT OR SYMBOL_LEFT_PARENTHESIS OR SYMBOL_SEMICOLON
OR SYMBOL_END OR SYMBOL_ELSE OR SYMBOL_ELSIF OR SYMBOL_BAR
OR SYMBOL_UNTIL, ERR_in_statement);
if (current_symbol == SYMBOL_ASSIGNMENT)
{
current_statement_ptr = create_node (ICNM_ASSIGNMENT);
next_symbol ();
ASSIGNMENT_NODE (current_statement_ptr)->assignment_variable
= node_ptr;
ASSIGNMENT_NODE (current_statement_ptr)->assignment_expression
= expression ();
}
else
{
current_statement_ptr = create_node (ICNM_PROCEDURE_CALL);
LINE (current_statement_ptr) = line_of_identifier;
PROCEDURE_CALL_NODE (current_statement_ptr)->procedure_designator
= node_ptr;
first_node_ptr = NULL;
if (current_symbol == SYMBOL_LEFT_PARENTHESIS)
{
next_symbol ();
if (current_symbol != SYMBOL_RIGHT_PARENTHESIS)
{
for (pred_node_ptr = NULL;;)
{
node_ptr = create_node (ICNM_ACTUAL_PARAMETER);
ACTUAL_PARAMETER_NODE (node_ptr)
->actual_parameter_expression = expression ();
if (first_node_ptr == NULL)
first_node_ptr = node_ptr;
if (pred_node_ptr != NULL)
ACTUAL_PARAMETER_NODE (pred_node_ptr)
->next_actual_parameter = node_ptr;
pred_node_ptr = node_ptr;
TEST_CURRENT_SYMBOL
(SYMBOL_COMMA OR SYMBOL_RIGHT_PARENTHESIS,
ERR_in_actual_parameters);
if (current_symbol == SYMBOL_COMMA)
next_symbol ();
else if (current_symbol == SYMBOL_RIGHT_PARENTHESIS
|| it_is_stop_symbol[(int) current_symbol])
break;
}
}
match_symbol (ERR_in_actual_parameters,
SYMBOL_RIGHT_PARENTHESIS);
}
PROCEDURE_CALL_NODE (current_statement_ptr)
->procedure_actual_parameter_list = first_node_ptr;
}
}
else if (current_symbol == SYMBOL_EXIT)
{
current_statement_ptr = create_node (ICNM_EXIT_STATEMENT);
next_symbol ();
}
else if (current_symbol == SYMBOL_RETURN)
{
current_statement_ptr = create_node (ICNM_RETURN_WITHOUT_RESULT);
next_symbol ();
TEST_CURRENT_SYMBOL
(SYMBOL_ADDITION OR SYMBOL_SUBTRACTION OR SYMBOL_NOT
OR SYMBOL_INTEGER OR SYMBOL_REAL OR SYMBOL_CHAR OR SYMBOL_STRING
OR SYMBOL_LEFT_PARENTHESIS OR SYMBOL_IDENTIFIER
OR SYMBOL_SEMICOLON OR SYMBOL_END OR SYMBOL_ELSE OR SYMBOL_ELSIF
OR SYMBOL_BAR OR SYMBOL_UNTIL, ERR_in_statement);
SET_UP_PRESENCE_FLAG_FOR_CURRENT_SYMBOL
(presence_flag, SYMBOL_SEMICOLON OR SYMBOL_END OR SYMBOL_ELSE
OR SYMBOL_ELSIF OR SYMBOL_BAR OR SYMBOL_UNTIL);
if (!presence_flag)
{
delete_node (current_statement_ptr);
current_statement_ptr = create_node (ICNM_RETURN_WITH_RESULT);
RETURN_WITH_RESULT_NODE (current_statement_ptr)
->returned_expression = expression ();
}
}
else if (current_symbol == SYMBOL_IF)
{
current_statement_ptr = create_node (ICNM_IF_STATEMENT);
next_symbol ();
IF_STATEMENT_NODE (current_statement_ptr)->if_expression
= expression ();
match_symbol (ERR_in_if_condition, SYMBOL_THEN);
ADD_STOP_SYMBOL (SYMBOL_ELSIF);
ADD_STOP_SYMBOL (SYMBOL_ELSE);
ADD_STOP_SYMBOL (SYMBOL_END);
IF_STATEMENT_NODE (current_statement_ptr)->if_statements
= statement_sequence ();
TEST_CURRENT_SYMBOL (SYMBOL_END OR SYMBOL_ELSE OR SYMBOL_ELSIF,
ERR_in_if_statement);
for (pred_node_ptr = current_statement_ptr;;)
{
TEST_CURRENT_SYMBOL (SYMBOL_END OR SYMBOL_ELSE OR SYMBOL_ELSIF,
ERR_in_if_statement);
if (current_symbol == SYMBOL_ELSIF)
next_symbol ();
else if (current_symbol == SYMBOL_END
|| current_symbol == SYMBOL_ELSE
|| it_is_stop_symbol[(int) current_symbol])
break;
node_ptr = create_node (ICNM_ELSIF_CLAUSE);
ELSIF_CLAUSE_NODE (node_ptr)->elsif_expression = expression ();
match_symbol (ERR_in_if_condition, SYMBOL_THEN);
ELSIF_CLAUSE_NODE (node_ptr)->elsif_statements
= statement_sequence ();
if (MODE (pred_node_ptr) == ICNM_IF_STATEMENT)
IF_STATEMENT_NODE (pred_node_ptr)->if_continuation = node_ptr;
else
ELSIF_CLAUSE_NODE (pred_node_ptr)->elsif_continuation
= node_ptr;
pred_node_ptr = node_ptr;
}
REMOVE_STOP_SYMBOL (SYMBOL_ELSIF);
REMOVE_STOP_SYMBOL (SYMBOL_ELSE);
if (current_symbol == SYMBOL_ELSE)
{
next_symbol ();
if (MODE (pred_node_ptr) == ICNM_IF_STATEMENT)
IF_STATEMENT_NODE (pred_node_ptr)->if_continuation
= statement_sequence ();
else
ELSIF_CLAUSE_NODE (pred_node_ptr)->elsif_continuation
= statement_sequence ();
}
REMOVE_STOP_SYMBOL (SYMBOL_END);
match_symbol (ERR_in_statement, SYMBOL_END);
}
else if (current_symbol == SYMBOL_CASE)
{
current_statement_ptr = create_node (ICNM_CASE_STATEMENT);
next_symbol ();
CASE_STATEMENT_NODE (current_statement_ptr)->case_expression
= expression ();
match_symbol (ERR_in_case_value, SYMBOL_OF);
ADD_STOP_SYMBOL (SYMBOL_ELSE);
ADD_STOP_SYMBOL (SYMBOL_END);
for (first_node_ptr = pred_node_ptr = NULL;;)
{
SET_PRESENCE_FLAG_AND_TEST_CURRENT_SYMBOL
(presence_flag, SYMBOL_ADDITION OR SYMBOL_SUBTRACTION
OR SYMBOL_NOT OR SYMBOL_INTEGER OR SYMBOL_REAL OR SYMBOL_CHAR
OR SYMBOL_STRING OR SYMBOL_LEFT_PARENTHESIS
OR SYMBOL_IDENTIFIER OR SYMBOL_END OR SYMBOL_ELSE
OR SYMBOL_BAR, ERR_in_case_statement);
if (current_symbol == SYMBOL_BAR)
next_symbol ();
else if (current_symbol == SYMBOL_ELSE
|| current_symbol == SYMBOL_END
|| (!presence_flag
&& it_is_stop_symbol[(int) current_symbol]))
break;
else
{
node_ptr = case_label_list (FALSE);
match_symbol (ERR_in_case_label_list, SYMBOL_COLON);
ADD_STOP_SYMBOL (SYMBOL_BAR);
CASE_STATEMENT_VARIANT_NODE (node_ptr)->case_variant_elements
= statement_sequence ();
if (first_node_ptr == NULL)
first_node_ptr = node_ptr;
if (pred_node_ptr != NULL)
CASE_STATEMENT_VARIANT_NODE (pred_node_ptr)
->next_case_variant = node_ptr;
pred_node_ptr = node_ptr;
CASE_STATEMENT_VARIANT_NODE (node_ptr)->next_case_variant
= current_statement_ptr;
}
}
REMOVE_STOP_SYMBOL (SYMBOL_ELSE);
if (current_symbol == SYMBOL_ELSE)
{
node_ptr = create_node (ICNM_CASE_STATEMENT_VARIANT);
next_symbol ();
CASE_STATEMENT_VARIANT_NODE (node_ptr)->case_variant_elements
= statement_sequence ();
CASE_STATEMENT_VARIANT_NODE (node_ptr)->next_case_variant
= current_statement_ptr;
if (first_node_ptr == NULL)
first_node_ptr = node_ptr;
if (pred_node_ptr != NULL)
CASE_STATEMENT_VARIANT_NODE (pred_node_ptr)->next_case_variant
= node_ptr;
}
if (first_node_ptr != NULL)
CASE_STATEMENT_NODE (current_statement_ptr)
->case_statement_variant_list = first_node_ptr;
else
CASE_STATEMENT_NODE (current_statement_ptr)
->case_statement_variant_list = current_statement_ptr;
REMOVE_STOP_SYMBOL (SYMBOL_END);
match_symbol (ERR_in_statement, SYMBOL_END);
}
else if (current_symbol == SYMBOL_WHILE)
{
current_statement_ptr = create_node (ICNM_WHILE_STATEMENT);
next_symbol ();
WHILE_STATEMENT_NODE (current_statement_ptr)->while_expression
= expression ();
match_symbol (ERR_in_while_condition, SYMBOL_DO);
ADD_STOP_SYMBOL (SYMBOL_END);
WHILE_STATEMENT_NODE (current_statement_ptr)->while_statements
= statement_sequence ();
REMOVE_STOP_SYMBOL (SYMBOL_END);
match_symbol (ERR_in_statement, SYMBOL_END);
}
else if (current_symbol == SYMBOL_REPEAT)
{
current_statement_ptr = create_node (ICNM_REPEAT_STATEMENT);
next_symbol ();
ADD_STOP_SYMBOL (SYMBOL_UNTIL);
REPEAT_STATEMENT_NODE (current_statement_ptr)->repeat_statements
= statement_sequence ();
REMOVE_STOP_SYMBOL (SYMBOL_UNTIL);
match_symbol (ERR_in_statement, SYMBOL_UNTIL);
REPEAT_STATEMENT_NODE (current_statement_ptr)->until_expression
= expression ();
}
else if (current_symbol == SYMBOL_FOR)
{
current_statement_ptr = create_node (ICNM_FOR_STATEMENT);
next_symbol ();
if (current_symbol == SYMBOL_IDENTIFIER)
FOR_STATEMENT_NODE (current_statement_ptr)->for_control_variable
= icode_symbol_presentation;
match_symbol (ERR_identifier_expectation, SYMBOL_IDENTIFIER);
match_symbol (ERR_symbol_assignment_expectation, SYMBOL_ASSIGNMENT);
FOR_STATEMENT_NODE (current_statement_ptr)->for_starting_value
= expression ();
match_symbol (ERR_in_for_statement_start_value, SYMBOL_TO);
FOR_STATEMENT_NODE (current_statement_ptr)->for_limit
= expression ();
TEST_CURRENT_SYMBOL (SYMBOL_BY OR SYMBOL_DO,
ERR_in_for_statement_limit_or_increment);
if (current_symbol == SYMBOL_BY)
{
next_symbol ();
FOR_STATEMENT_NODE (current_statement_ptr)->for_increment
= expression ();
}
match_symbol (ERR_in_for_statement_limit_or_increment, SYMBOL_DO);
ADD_STOP_SYMBOL (SYMBOL_END);
FOR_STATEMENT_NODE (current_statement_ptr)->for_statements
= statement_sequence ();
REMOVE_STOP_SYMBOL (SYMBOL_END);
match_symbol (ERR_in_statement, SYMBOL_END);
}
else if (current_symbol == SYMBOL_LOOP)
{
current_statement_ptr = create_node (ICNM_LOOP_STATEMENT);
next_symbol ();
ADD_STOP_SYMBOL (SYMBOL_END);
LOOP_STATEMENT_NODE (current_statement_ptr)->loop_statements
= statement_sequence ();
REMOVE_STOP_SYMBOL (SYMBOL_END);
match_symbol (ERR_in_statement, SYMBOL_END);
}
else if (current_symbol == SYMBOL_WITH)
{
current_statement_ptr = create_node (ICNM_WITH_STATEMENT);
next_symbol ();
WITH_STATEMENT_NODE (current_statement_ptr)->with_designator
= designator ();
match_symbol (ERR_in_with_statement_variable, SYMBOL_DO);
ADD_STOP_SYMBOL (SYMBOL_END);
WITH_STATEMENT_NODE (current_statement_ptr)->with_statements
= statement_sequence ();
REMOVE_STOP_SYMBOL (SYMBOL_END);
match_symbol (ERR_in_statement, SYMBOL_END);
}
else if (current_symbol == SYMBOL_C_TEXT)
{
current_statement_ptr
= create_node_with_string
(ICNM_C_CODE_IN_STATEMENTS,
C_CODE_IN_DECLARATIONS_NODE (icode_symbol_presentation)->C_text,
&C_text_in_icode_memory);
C_CODE_IN_STATEMENTS_NODE (current_statement_ptr)->C_text
= C_text_in_icode_memory;
delete_node (icode_symbol_presentation);
next_symbol ();
}
else
current_statement_ptr = NULL;
if (current_statement_ptr != NULL)
{
if (statement_list_head == NULL)
statement_list_head = current_statement_ptr;
if (pred_statement_ptr != NULL)
NEXT_STATEMENT (pred_statement_ptr) = current_statement_ptr;
pred_statement_ptr = current_statement_ptr;
}
REMOVE_STOP_SYMBOL (SYMBOL_SEMICOLON);
SET_PRESENCE_FLAG_AND_TEST_CURRENT_SYMBOL
(presence_flag, SYMBOL_SEMICOLON OR SYMBOL_END OR SYMBOL_ELSE
OR SYMBOL_ELSIF OR SYMBOL_BAR OR SYMBOL_UNTIL, ERR_in_statement);
if (current_symbol == SYMBOL_SEMICOLON)
next_symbol ();
else if (presence_flag || it_is_stop_symbol[(int) current_symbol])
break;
}
return statement_list_head;
}
/* Code for parsing declarations. */
/* If current scope is open scope (record, procedure) than its value
is TRUE. */
static int current_scope_is_open;
/* The following variable is used for forming declaration list. */
static ICN_pointer pred_declaration_ptr;
/* The following variable is used for forming export list (it starts with
module node). */
static ICN_pointer pred_export_ptr;
/* Add declaration to the end of declaration list. Pointer to last element
in the list is always in the variable pred_declaration_ptr. */
static void
add_declaration_to_list (declaration_ptr)
register ICN_pointer declaration_ptr;
{
NEXT_DECLARATION_ELEMENT (pred_declaration_ptr) = declaration_ptr;
pred_declaration_ptr = declaration_ptr;
}
/* The following function creates declaration node (with members mode
equal to MODE, scope referring to current_scope, identifier referring
to current identifier and member in_definition_module equal to
IN_DEFINITION_MODULE), includes it to the hash table, add the node to
the declaration list and returns pointer to it. If current symbol is
not identifier or error is fixed then the node is not created and NULL
is returned. Fixed errors are standard identifier redeclaration in
open scope and redeclaration identifier in the current scope. Error
is not fixed (although as early the node is not created and NULL is
returned) if this is repeated declaration of import_node, export_node
from the same MODULE_EXPORTER and export_qualified_node (only for
local modules). MODULE_EXPORTER refers to identifier_node in the case
of processing import_node and to module_node in the case of processing
export_node. */
static ICN_pointer
create_and_include_declaration_node (mode, in_definition_module,
module_exporter)
int mode, in_definition_module;
ICN_pointer module_exporter;
{
register ICN_pointer declaration_node_ptr, old_declaration_node_ptr;
register struct stdid *stdid_ptr;
register int error_flag;
declaration_node_ptr = NULL;
if (current_symbol == SYMBOL_IDENTIFIER)
{
if (!current_scope_is_open)
stdid_ptr
= find_stdid
(IDENTIFIER_NODE (icode_symbol_presentation)->identifier_string,
strlen
(IDENTIFIER_NODE (icode_symbol_presentation)->identifier_string));
if (!current_scope_is_open && stdid_ptr != 0
&& (!stdid_ptr->lower_case_stdid || !only_upper_case_flag))
error (ERR_standard_indentifier_declaration);
else
{
declaration_node_ptr = create_node (mode);
IDENTIFIER (declaration_node_ptr) = icode_symbol_presentation;
SCOPE (declaration_node_ptr) = current_scope;
IN_DEFINITION_MODULE (declaration_node_ptr) = in_definition_module;
old_declaration_node_ptr =
find_in_or_else_include_to_table (declaration_node_ptr);
if (declaration_node_ptr != old_declaration_node_ptr)
{
declaration_node_ptr = NULL;
error_flag = TRUE;
if (MODE (old_declaration_node_ptr) == mode)
{
if (mode == ICNM_QUALIFIED_EXPORT
&& !it_is_definition_module)
/* The error for redeclartion of opaque type is fixed
because IT_IS_DEFINITION_MODULE is TRUE in this case. */
error_flag = FALSE;
else if (mode == ICNM_IMPORT)
error_flag
= ((IMPORT_NODE (old_declaration_node_ptr)
->module_exporter != NULL
&& MODE (IMPORT_NODE (old_declaration_node_ptr)
->module_exporter) != ICNM_IDENTIFIER
? IDENTIFIER (IMPORT_NODE (old_declaration_node_ptr)
->module_exporter)
: (IMPORT_NODE (old_declaration_node_ptr)
->module_exporter))
!= module_exporter);
else if (mode == ICNM_EXPORT)
error_flag = (module_exporter
!= (EXPORT_NODE (old_declaration_node_ptr)
->module_exporter));
}
if (error_flag)
error_with_parameter
(ERR_repeated_identifier_declaration,
IDENTIFIER_NODE (icode_symbol_presentation)
->identifier_string);
}
else
add_declaration_to_list (declaration_node_ptr);
}
}
return declaration_node_ptr;
}
/* Add export node PTR to the end of export node list. Pointer to last element
in the list is always in the variable pred_export_ptr. */
#define ADD_EXPORT_TO_LIST(ptr) {EXPORT_LIST(pred_export_ptr)=ptr;\
pred_export_ptr=ptr;}
/* The following function is analogous to function
create_and_include_declaration_node. But this function returns nothing
and sets up member opaque_type equal to IT_IS_OPAQUE_TYPE. */
static void
create_and_include_qualified_export_node (it_is_opaque_type)
int it_is_opaque_type;
{
register ICN_pointer node_ptr;
node_ptr = create_and_include_declaration_node (ICNM_QUALIFIED_EXPORT,
FALSE, NULL);
if (node_ptr != NULL)
QUALIFIED_EXPORT_NODE (node_ptr)->opaque_type = it_is_opaque_type;
}
/* The following function tests that the current symbol is symbol C text.
If it is false the function does nothing and returns FALSE. Otherwise
the function adds the corresponding icode node to the end of the declaration
list, skips the symbol and and returns TRUE. */
static int
test_and_process_C_text ()
{
if (current_symbol == SYMBOL_C_TEXT)
{
add_declaration_to_list (icode_symbol_presentation);
next_symbol ();
return TRUE;
}
return FALSE;
}
/* { constant_declaration = IDENTIFIER "=" const_expression ";" | CTEXT } */
static void
constant_declaration_list ()
{
register ICN_pointer constant_declaration_ptr, expression_ptr;
for (;;)
{
TEST_CURRENT_SYMBOL
(SYMBOL_IDENTIFIER OR SYMBOL_C_TEXT OR SYMBOL_CONST
OR SYMBOL_TYPE OR SYMBOL_VAR OR SYMBOL_PROCEDURE OR SYMBOL_MODULE
OR SYMBOL_BEGIN OR SYMBOL_END, ERR_in_constant_declaration_part);
if (current_symbol == SYMBOL_IDENTIFIER)
{
constant_declaration_ptr
= create_and_include_declaration_node
(ICNM_CONSTANT_DECLARATION, it_is_definition_module, NULL);
next_symbol ();
match_symbol (ERR_symbol_equal_expectation, SYMBOL_EQUAL);
new_error_flag = FALSE;
expression_ptr = expression ();
if (constant_declaration_ptr != NULL && !new_error_flag)
CONSTANT_DECLARATION_NODE (constant_declaration_ptr)
->constant_expression = expression_ptr;
match_symbol (ERR_in_constant_expression, SYMBOL_SEMICOLON);
}
else if (!test_and_process_C_text ())
break;
}
}
/* The following function is used in function type for forming
type definition node list on member basic_type (e.g. POINTER TO
POINTER TO ARRAY s OF ...). The function adds node ADDED_NODE to the list
and sets up correspondingly variable *FIRST_NODE_PTR
and *PREDECESSOR_NODE_PTR. */
static void
new_type_definition_node (first_node_ptr, predecessor_node_ptr, added_node)
register ICN_pointer *first_node_ptr, *predecessor_node_ptr;
register ICN_pointer added_node;
{
if (*first_node_ptr == NULL)
*first_node_ptr = added_node;
if (*predecessor_node_ptr != NULL)
BASE_TYPE (*predecessor_node_ptr) = added_node;
*predecessor_node_ptr = added_node;
}
/* type = {"POINTER" "TO" | "ARRAY" {simple_type/","} "OF"}
("RECORD" field_list_sequence "END" |
"PROCEDURE" ( | "(" [ { [ "VAR" ][ "ARRAY" "OF" ] qualident/ ","} ] ")"
( |":"qualident)) |
["SET" "OF"] simple_type
)
*/
static ICN_pointer
type ()
{
int saved_current_scope_is_open;
register ICN_pointer current_type_node_ptr, first_parameter_type_ptr;
register ICN_pointer last_parameter_type_ptr, parameter_type_ptr;
ICN_pointer first_type_node_ptr, pred_type_node_ptr;
for (first_type_node_ptr = pred_type_node_ptr = NULL;;)
{
TEST_CURRENT_SYMBOL
(SYMBOL_POINTER OR SYMBOL_ARRAY OR SYMBOL_RECORD OR SYMBOL_PROCEDURE
OR SYMBOL_SET OR SYMBOL_LEFT_PARENTHESIS OR SYMBOL_IDENTIFIER
OR SYMBOL_LEFT_BRACKET, ERR_in_type);
if (current_symbol == SYMBOL_POINTER)
{
current_type_node_ptr = create_node (ICNM_POINTER_TYPE);
next_symbol ();
match_symbol (ERR_keyword_to_expectation, SYMBOL_TO);
}
else if (current_symbol == SYMBOL_ARRAY)
{
next_symbol ();
for (;; next_symbol ())
{
current_type_node_ptr = create_node (ICNM_ARRAY_TYPE);
ARRAY_TYPE_NODE (current_type_node_ptr)->array_index_type
= simple_type ();
if (current_symbol != SYMBOL_COMMA)
break;
new_type_definition_node
(&first_type_node_ptr, &pred_type_node_ptr,
current_type_node_ptr);
}
match_symbol (ERR_in_index_type, SYMBOL_OF);
}
else
break;
new_type_definition_node
(&first_type_node_ptr, &pred_type_node_ptr, current_type_node_ptr);
}
if (current_symbol == SYMBOL_RECORD)
{
current_type_node_ptr = create_node (ICNM_RECORD);
next_symbol ();
RECORD_NODE (current_type_node_ptr)->scope = current_scope;
current_scope = current_type_node_ptr;
saved_current_scope_is_open = current_scope_is_open;
ADD_STOP_SYMBOL (SYMBOL_END);
RECORD_NODE (current_type_node_ptr)->record_element_list
= field_list_sequence (current_type_node_ptr);
REMOVE_STOP_SYMBOL (SYMBOL_END);
current_scope = RECORD_NODE (current_type_node_ptr)->scope;
current_scope_is_open = saved_current_scope_is_open;
match_symbol (ERR_in_field_declaration, SYMBOL_END);
}
else if (current_symbol == SYMBOL_PROCEDURE)
{
current_type_node_ptr = create_node (ICNM_PROCEDURE_TYPE);
next_symbol ();
first_parameter_type_ptr = last_parameter_type_ptr = NULL;
if (current_symbol == SYMBOL_LEFT_PARENTHESIS)
{
if (next_symbol () != SYMBOL_RIGHT_PARENTHESIS)
for (;;)
{
parameter_type_ptr
= create_node (ICNM_PROCEDURE_PARAMETER_TYPE);
TEST_CURRENT_SYMBOL
(SYMBOL_VAR OR SYMBOL_ARRAY OR SYMBOL_IDENTIFIER,
ERR_in_formal_parameter_declaration);
if (last_parameter_type_ptr != NULL)
NEXT_DECLARATION_ELEMENT (last_parameter_type_ptr)
= parameter_type_ptr;
last_parameter_type_ptr = parameter_type_ptr;
if (first_parameter_type_ptr == NULL)
first_parameter_type_ptr = last_parameter_type_ptr;
if (current_symbol == SYMBOL_VAR)
{
next_symbol ();
VAR_FORMAL_PARAMETER (last_parameter_type_ptr) = TRUE;
}
TEST_CURRENT_SYMBOL (SYMBOL_ARRAY OR SYMBOL_IDENTIFIER,
ERR_in_formal_parameter_declaration);
if (current_symbol == SYMBOL_ARRAY)
{
next_symbol ();
match_symbol (ERR_keyword_of_expectation, SYMBOL_OF);
ARRAY_FORMAL_PARAMETER (last_parameter_type_ptr) = TRUE;
}
FORMAL_PARAMETER_TYPE (last_parameter_type_ptr) = qualident ();
if (current_symbol == SYMBOL_COMMA)
next_symbol ();
else if (current_symbol == SYMBOL_RIGHT_PARENTHESIS
|| it_is_stop_symbol[(int) current_symbol])
break;
}
match_symbol (ERR_in_formal_parameter_declaration,
SYMBOL_RIGHT_PARENTHESIS);
TEST_CURRENT_SYMBOL (SYMBOL_COLON OR SYMBOL_SEMICOLON, ERR_in_type);
if (current_symbol == SYMBOL_COLON)
{
next_symbol ();
PROCEDURE_TYPE_NODE (current_type_node_ptr)
->procedure_result_type = qualident ();
}
}
NEXT_DECLARATION_ELEMENT (current_type_node_ptr)
= first_parameter_type_ptr;
}
else
{
if (current_symbol == SYMBOL_SET)
{
current_type_node_ptr = create_node (ICNM_SET_TYPE);
next_symbol ();
match_symbol (ERR_keyword_of_expectation, SYMBOL_OF);
new_type_definition_node (&first_type_node_ptr, &pred_type_node_ptr,
current_type_node_ptr);
}
current_type_node_ptr = simple_type ();
}
new_type_definition_node (&first_type_node_ptr, &pred_type_node_ptr,
current_type_node_ptr);
return first_type_node_ptr;
}
/* The following function is used in function field_list_sequence for forming
list on member next_case_variant. The function adds node ADDED_NODE to
the list and sets up correspondingly variable *FIRST_CASE_VARIANT_NODE_PTR
and *PRED_CASE_VARIANT_NODE_PTR. Member next_case_variant of added node is
set up to RECORD_CASE_PART_NODE_PTR. */
static void
new_case_variant_node (first_case_variant_node_ptr, pred_case_variant_node_ptr,
added_node, record_case_part_node_ptr)
register ICN_pointer *first_case_variant_node_ptr;
register ICN_pointer *pred_case_variant_node_ptr;
register ICN_pointer added_node, record_case_part_node_ptr;
{
if (*first_case_variant_node_ptr == NULL)
*first_case_variant_node_ptr = added_node;
if (*pred_case_variant_node_ptr != NULL)
RECORD_CASE_VARIANT_NODE (*pred_case_variant_node_ptr)->next_case_variant
= added_node;
*pred_case_variant_node_ptr = added_node;
RECORD_CASE_VARIANT_NODE (added_node)->next_case_variant
= record_case_part_node_ptr;
}
/* The following function is used in function field_list_sequence for forming
list on member next_field. The function adds node ADDED_NODE to
the list and sets up correspondingly variable *FIRST_FIELD_PTR
and *PRED_FIELD_PTR. Member next_field or record_element_after_case_part
of added node is set up to HEAD (it is to be record node or
case variant node) for forming cyclic list. */
static void
new_field_or_case_part_node (first_field_ptr, pred_field_ptr, added_node, head)
register ICN_pointer *first_field_ptr, *pred_field_ptr;
register ICN_pointer added_node, head;
{
if (added_node != NULL)
{
if (*first_field_ptr == NULL)
*first_field_ptr = added_node;
if (*pred_field_ptr != NULL)
{
if (MODE (*pred_field_ptr) == ICNM_FIELD)
FIELD_NODE (*pred_field_ptr)->next_field = added_node;
else
RECORD_CASE_PART_NODE (*pred_field_ptr)
->record_element_after_case_part = added_node;
}
*pred_field_ptr = added_node;
if (MODE (added_node) == ICNM_FIELD)
FIELD_NODE (added_node)->next_field = head;
else
RECORD_CASE_PART_NODE (added_node)->record_element_after_case_part
= head;
}
}
/* field_list_sequence =
{ [ "CASE" [IDENTIFIER] ":" qualident "OF"
{ [case_label_list ":" field_list_sequence] / "|"}
[ "ELSE" field_list_sequence] "END" |
{IDENTIFIER/ ","} ":" type
]
/ ";"}
HEAD is used for forming cyclic list (it is to be record node or
case variant node).
*/
static ICN_pointer
field_list_sequence (head)
ICN_pointer head;
{
int tag_is_present, presense_flag;
register ICN_pointer current_field_or_case_part, case_variant_node_ptr;
register ICN_pointer node_ptr, field_node_list, case_part_ptr;
ICN_pointer pred_field_ptr, first_field_ptr;
ICN_pointer pred_case_variant_node_ptr, first_case_variant_node_ptr;
for (first_field_ptr = pred_field_ptr = NULL;;)
{
TEST_CURRENT_SYMBOL
(SYMBOL_CASE OR SYMBOL_IDENTIFIER OR SYMBOL_SEMICOLON
OR SYMBOL_BAR OR SYMBOL_END, ERR_in_field_declaration);
if (current_symbol == SYMBOL_CASE)
{
case_part_ptr = create_node (ICNM_RECORD_CASE_PART);
next_symbol ();
TEST_CURRENT_SYMBOL (SYMBOL_IDENTIFIER OR SYMBOL_COLON,
ERR_in_case_tag_type);
if (current_symbol == SYMBOL_IDENTIFIER)
{
tag_is_present = TRUE;
current_field_or_case_part
= create_and_include_declaration_node
(ICNM_FIELD, FALSE, NULL);
if (current_field_or_case_part != NULL)
new_field_or_case_part_node (&first_field_ptr, &pred_field_ptr,
current_field_or_case_part, head);
next_symbol ();
}
else
tag_is_present = FALSE;
match_symbol (ERR_in_case_tag_type, SYMBOL_COLON);
node_ptr = qualident ();
if (tag_is_present && current_field_or_case_part != NULL)
FIELD_NODE (current_field_or_case_part)->field_type = node_ptr;
current_field_or_case_part = case_part_ptr;
RECORD_CASE_PART_NODE (current_field_or_case_part)->case_tag_type
= node_ptr;
new_field_or_case_part_node (&first_field_ptr, &pred_field_ptr,
current_field_or_case_part, head);
match_symbol (ERR_in_case_tag_type, SYMBOL_OF);
ADD_STOP_SYMBOL (SYMBOL_ELSE);
ADD_STOP_SYMBOL (SYMBOL_END);
for (first_case_variant_node_ptr = pred_case_variant_node_ptr = NULL;
;)
{
SET_PRESENCE_FLAG_AND_TEST_CURRENT_SYMBOL
(presense_flag, SYMBOL_ADDITION OR SYMBOL_SUBTRACTION
OR SYMBOL_NOT OR SYMBOL_INTEGER OR SYMBOL_REAL OR SYMBOL_CHAR
OR SYMBOL_STRING OR SYMBOL_LEFT_PARENTHESIS
OR SYMBOL_IDENTIFIER OR SYMBOL_ELSE OR SYMBOL_BAR
OR SYMBOL_END, ERR_in_record_case_part);
if (current_symbol == SYMBOL_BAR)
next_symbol ();
else if (current_symbol == SYMBOL_ELSE
|| current_symbol == SYMBOL_END
|| (!presense_flag
&& it_is_stop_symbol[(int) current_symbol]))
break;
else
{
case_variant_node_ptr = case_label_list (TRUE);
new_case_variant_node
(&first_case_variant_node_ptr, &pred_case_variant_node_ptr,
case_variant_node_ptr, current_field_or_case_part);
match_symbol (ERR_in_case_label_list, SYMBOL_COLON);
RECORD_CASE_VARIANT_NODE (case_variant_node_ptr)
->case_variant_elements
= field_list_sequence (case_variant_node_ptr);
}
}
REMOVE_STOP_SYMBOL (SYMBOL_ELSE);
if (current_symbol == SYMBOL_ELSE)
{
case_variant_node_ptr = create_node (ICNM_RECORD_CASE_VARIANT);
next_symbol ();
RECORD_CASE_VARIANT_NODE (case_variant_node_ptr)
->case_variant_elements
= field_list_sequence (case_variant_node_ptr);
new_case_variant_node
(&first_case_variant_node_ptr, &pred_case_variant_node_ptr,
case_variant_node_ptr, current_field_or_case_part);
}
if (first_case_variant_node_ptr != NULL)
RECORD_CASE_PART_NODE (current_field_or_case_part)
->record_case_variant_list = first_case_variant_node_ptr;
else
RECORD_CASE_PART_NODE (current_field_or_case_part)
->record_case_variant_list = current_field_or_case_part;
REMOVE_STOP_SYMBOL (SYMBOL_END);
match_symbol (ERR_in_record_case_part, SYMBOL_END);
}
else if (current_symbol == SYMBOL_IDENTIFIER)
{
for (field_node_list = NULL;;)
{
current_field_or_case_part
= create_and_include_declaration_node
(ICNM_FIELD, FALSE, NULL);
/* Test is needed because error may be fixed
in create_and_include_declaration_node. */
if (current_field_or_case_part != NULL)
{
if (field_node_list == NULL)
field_node_list = current_field_or_case_part;
new_field_or_case_part_node
(&first_field_ptr, &pred_field_ptr,
current_field_or_case_part, head);
}
match_symbol (ERR_in_field_identifier_list, SYMBOL_IDENTIFIER);
TEST_CURRENT_SYMBOL (SYMBOL_COMMA OR SYMBOL_COLON,
ERR_in_field_identifier_list);
if (current_symbol == SYMBOL_COMMA)
next_symbol ();
else if (current_symbol == SYMBOL_COLON
|| it_is_stop_symbol[(int) current_symbol])
break;
}
match_symbol (ERR_in_field_identifier_list, SYMBOL_COLON);
node_ptr = type ();
for (; field_node_list != NULL
&& MODE (field_node_list) == ICNM_FIELD;
field_node_list = FIELD_NODE (field_node_list)->next_field)
FIELD_NODE (field_node_list)->field_type = node_ptr;
}
if (current_symbol == SYMBOL_SEMICOLON)
next_symbol ();
else if (current_symbol == SYMBOL_END
|| current_symbol == SYMBOL_BAR
|| it_is_stop_symbol[(int) current_symbol])
break;
}
if (first_field_ptr != NULL)
return first_field_ptr;
else
return head;
}
/* simple_type =
"(" {IDENTIFIER/ ","} ")" |
qualident | [qualident] "[" expression ".." expression "]"
*/
static ICN_pointer
simple_type ()
{
int identifier_number, range_has_qualident;
register ICN_pointer simple_type_ptr, node_ptr;
register ICN_pointer first_enumeration_constant_ptr;
register ICN_pointer enumeration_constant_value_ptr, expression_ptr;
TEST_CURRENT_SYMBOL
(SYMBOL_LEFT_PARENTHESIS OR SYMBOL_IDENTIFIER OR SYMBOL_LEFT_BRACKET,
ERR_in_simple_type);
if (current_symbol == SYMBOL_LEFT_PARENTHESIS)
{
next_symbol ();
simple_type_ptr = create_node (ICNM_ENUMERATION_TYPE);
identifier_number = 0;
ADD_STOP_SYMBOL (SYMBOL_LEFT_PARENTHESIS);
for (first_enumeration_constant_ptr = NULL;;)
{
node_ptr
= create_and_include_declaration_node
(ICNM_CONSTANT_DECLARATION, it_is_definition_module, NULL);
if (node_ptr != NULL)
{
if (first_enumeration_constant_ptr == NULL)
first_enumeration_constant_ptr = node_ptr;
enumeration_constant_value_ptr = create_node (ICNM_CARDINAL);
CARDINAL_NODE (enumeration_constant_value_ptr)->cardinal_value
= identifier_number;
identifier_number++;
CARDINAL_NODE (enumeration_constant_value_ptr)->value_type
= simple_type_ptr;
CONSTANT_DECLARATION_NODE (node_ptr)->constant_expression
= find_in_or_else_include_to_table
(enumeration_constant_value_ptr);
}
match_symbol (ERR_in_enumeration_type, SYMBOL_IDENTIFIER);
TEST_CURRENT_SYMBOL (SYMBOL_COMMA OR SYMBOL_RIGHT_PARENTHESIS,
ERR_in_enumeration_type);
if (current_symbol == SYMBOL_COMMA)
next_symbol ();
if (current_symbol == SYMBOL_RIGHT_PARENTHESIS
|| it_is_stop_symbol[(int) current_symbol])
break;
}
ENUMERATION_TYPE_NODE (simple_type_ptr)->first_enumeration_constant
= first_enumeration_constant_ptr;
REMOVE_STOP_SYMBOL (SYMBOL_LEFT_PARENTHESIS);
match_symbol (ERR_in_enumeration_type, SYMBOL_RIGHT_PARENTHESIS);
}
else
{
if (current_symbol == SYMBOL_IDENTIFIER)
{
range_has_qualident = TRUE;
simple_type_ptr = qualident ();
}
else
range_has_qualident = FALSE;
if (!range_has_qualident || current_symbol == SYMBOL_LEFT_BRACKET)
{
match_symbol (ERR_in_simple_type, SYMBOL_LEFT_BRACKET);
node_ptr = simple_type_ptr;
expression_ptr = expression ();
simple_type_ptr = create_node (ICNM_RANGE_TYPE);
if (range_has_qualident)
RANGE_TYPE_NODE (simple_type_ptr)->base_type = node_ptr;
RANGE_TYPE_NODE (simple_type_ptr)->left_range_bound = expression_ptr;
match_symbol (ERR_in_range_type, SYMBOL_RANGE);
RANGE_TYPE_NODE (simple_type_ptr)->right_range_bound = expression ();
match_symbol (ERR_in_range_type, SYMBOL_RIGHT_BRACKET);
}
}
return simple_type_ptr;
}
/* {variable_declaration = {IDENTIFIER/ "," } ":" type ";" | CTEXT} */
static void
variable_declaration_list ()
{
register ICN_pointer variable_declaration_node_ptr;
register ICN_pointer variable_declaration_list, variable_type_ptr;
for (;;)
{
TEST_CURRENT_SYMBOL
(SYMBOL_IDENTIFIER OR SYMBOL_C_TEXT OR SYMBOL_CONST
OR SYMBOL_TYPE OR SYMBOL_VAR OR SYMBOL_PROCEDURE OR SYMBOL_MODULE
OR SYMBOL_BEGIN OR SYMBOL_END, ERR_in_variable_declaration_part);
if (current_symbol == SYMBOL_IDENTIFIER)
{
ADD_STOP_SYMBOL (SYMBOL_COLON);
for (variable_declaration_list = NULL;;)
{
variable_declaration_node_ptr
= create_and_include_declaration_node
(ICNM_VARIABLE_DECLARATION, it_is_definition_module, NULL);
if (variable_declaration_list == NULL)
variable_declaration_list = variable_declaration_node_ptr;
match_symbol (ERR_in_variable_list, SYMBOL_IDENTIFIER);
if (current_symbol == SYMBOL_COMMA)
next_symbol ();
else if (current_symbol == SYMBOL_COLON
|| it_is_stop_symbol[(int) current_symbol])
break;
}
REMOVE_STOP_SYMBOL (SYMBOL_COLON);
match_symbol (ERR_in_variable_list, SYMBOL_COLON);
new_error_flag = FALSE;
variable_type_ptr = type ();
if (!new_error_flag)
for (; variable_declaration_list != NULL;
variable_declaration_list
= NEXT_DECLARATION_ELEMENT (variable_declaration_list))
if (MODE (variable_declaration_list)
== ICNM_VARIABLE_DECLARATION)
VARIABLE_DECLARATION_NODE (variable_declaration_list)
->variable_type = variable_type_ptr;
match_symbol (ERR_in_type, SYMBOL_SEMICOLON);
}
else if (!test_and_process_C_text ())
break;
}
}
/* If current symbol is identifier and is not equal to identifier of current
scope than error ERR is fixed. */
static void
test_identifier_after_block (err)
char *err;
{
if (current_symbol == SYMBOL_IDENTIFIER
&& IDENTIFIER (current_scope) != NULL
&& IDENTIFIER (current_scope) != icode_symbol_presentation)
error (err);
}
/* The following function creates declaration node MODE initiates its
members scope by current_scope, in_definition_module by IN_DEFINITION_MODULE
and identifier by current identifier (if current symbol is identifier) and
returns pointer to the node. */
static ICN_pointer
create_and_initiate_declaration_node (mode, in_definition_module)
int mode, in_definition_module;
{
register ICN_pointer declaration_node_ptr;
declaration_node_ptr = create_node (mode);
SCOPE (declaration_node_ptr) = current_scope;
IN_DEFINITION_MODULE (declaration_node_ptr) = in_definition_module;
if (current_symbol == SYMBOL_IDENTIFIER)
IDENTIFIER (declaration_node_ptr) = icode_symbol_presentation;
return declaration_node_ptr;
}
/* The following variable is used for forming list of all block begin node
in current compilation unit (member next_block_begin is used for this). */
static ICN_pointer last_block_begin_node_ptr;
/* block = {"CONST" constant_declaration_list |
"TYPE" {IDENTIFIER "=" type ";" | CTEXT} |
"VAR" variable_declaration_list |
procedure_heading ";" block IDENTIFIER ";" |
"MODULE" IDENTIFIER optional_priority ";" import_list
[ "EXPORT" [ "QUALIFIED" ] {IDENTIFIER/","} ";" ]
block IDENTIFIER ";" |
CTEXT
}
[ "BEGIN" statement_sequence] "END" */
static void
block ()
{
int it_is_qualified_export;
register ICN_pointer declaration_ptr, node_ptr;
register ICN_pointer pred_local_module_ptr, first_local_module_ptr;
ADD_STOP_SYMBOL (SYMBOL_BEGIN);
ADD_STOP_SYMBOL (SYMBOL_END);
ADD_STOP_SYMBOL (SYMBOL_CONST);
ADD_STOP_SYMBOL (SYMBOL_TYPE);
ADD_STOP_SYMBOL (SYMBOL_VAR);
ADD_STOP_SYMBOL (SYMBOL_PROCEDURE);
ADD_STOP_SYMBOL (SYMBOL_MODULE);
ADD_STOP_SYMBOL (SYMBOL_C_TEXT);
for (pred_local_module_ptr = first_local_module_ptr = NULL;;)
{
TEST_CURRENT_SYMBOL
(SYMBOL_C_TEXT OR SYMBOL_CONST OR SYMBOL_TYPE OR SYMBOL_VAR
OR SYMBOL_PROCEDURE OR SYMBOL_MODULE OR SYMBOL_BEGIN OR SYMBOL_END,
ERR_in_block);
if (current_symbol == SYMBOL_CONST)
{
next_symbol ();
constant_declaration_list ();
}
else if (current_symbol == SYMBOL_TYPE)
{
next_symbol ();
for (;;)
{
TEST_CURRENT_SYMBOL
(SYMBOL_IDENTIFIER OR SYMBOL_C_TEXT OR SYMBOL_CONST
OR SYMBOL_TYPE OR SYMBOL_VAR OR SYMBOL_PROCEDURE
OR SYMBOL_MODULE OR SYMBOL_BEGIN OR SYMBOL_END,
ERR_in_type_declaration_part);
if (current_symbol == SYMBOL_IDENTIFIER)
{
declaration_ptr
= create_and_include_declaration_node
(ICNM_TYPE_DECLARATION, FALSE, NULL);
next_symbol ();
match_symbol (ERR_symbol_equal_expectation, SYMBOL_EQUAL);
new_error_flag = FALSE;
node_ptr = type ();
if (declaration_ptr != NULL && !new_error_flag)
{
TYPE_DECLARATION_NODE (declaration_ptr)->type_definition
= node_ptr;
if (MODE (node_ptr) == ICNM_RECORD)
RECORD_NODE (node_ptr)->record_type_identifier
= declaration_ptr;
}
match_symbol (ERR_semicolon_expectation, SYMBOL_SEMICOLON);
}
else if (!test_and_process_C_text ())
break;
}
}
else if (current_symbol == SYMBOL_VAR)
{
next_symbol ();
variable_declaration_list ();
}
else if (current_symbol == SYMBOL_PROCEDURE)
{
procedure_heading ();
match_symbol (ERR_semicolon_expectation, SYMBOL_SEMICOLON);
block ();
test_identifier_after_block (ERR_procedure_name_after_end);
current_scope = PROCEDURE_NODE (current_scope)->scope;
current_scope_is_open = MODE (current_scope) == ICNM_PROCEDURE;
match_symbol (ERR_identifier_expectation, SYMBOL_IDENTIFIER);
match_symbol (ERR_semicolon_expectation, SYMBOL_SEMICOLON);
}
else if (current_symbol == SYMBOL_MODULE)
{
next_symbol ();
declaration_ptr
= create_and_include_declaration_node (ICNM_MODULE, FALSE, NULL);
if (declaration_ptr == NULL)
{
declaration_ptr = create_node (ICNM_MODULE);
MODULE_NODE (declaration_ptr)->scope = current_scope;
if (current_symbol == SYMBOL_IDENTIFIER)
MODULE_NODE (declaration_ptr)->identifier
= icode_symbol_presentation;
}
if (first_local_module_ptr == NULL)
first_local_module_ptr = declaration_ptr;
if (pred_local_module_ptr != NULL)
MODULE_NODE (pred_local_module_ptr)->module_brother
= declaration_ptr;
pred_local_module_ptr = declaration_ptr;
MODULE_NODE (declaration_ptr)->module_mode = (char) MM_LOCAL_MODULE;
current_scope = declaration_ptr;
current_scope_is_open = FALSE;
match_symbol (ERR_identifier_expectation, SYMBOL_IDENTIFIER);
optional_priority ();
match_symbol (ERR_semicolon_expectation, SYMBOL_SEMICOLON);
ADD_STOP_SYMBOL (SYMBOL_EXPORT);
import_list ();
REMOVE_STOP_SYMBOL (SYMBOL_EXPORT);
TEST_CURRENT_SYMBOL
(SYMBOL_EXPORT OR SYMBOL_C_TEXT OR SYMBOL_CONST OR SYMBOL_TYPE
OR SYMBOL_VAR OR SYMBOL_PROCEDURE OR SYMBOL_MODULE
OR SYMBOL_BEGIN OR SYMBOL_END, ERR_in_block);
if (current_symbol == SYMBOL_EXPORT)
{
next_symbol ();
TEST_CURRENT_SYMBOL (SYMBOL_QUALIFIED OR SYMBOL_IDENTIFIER,
ERR_in_export_list);
if (current_symbol == SYMBOL_QUALIFIED)
{
next_symbol ();
it_is_qualified_export = TRUE;
}
else
it_is_qualified_export = FALSE;
for (pred_export_ptr = current_scope;;)
{
if (current_symbol == SYMBOL_IDENTIFIER)
{
if (it_is_qualified_export)
create_and_include_qualified_export_node (FALSE);
else
{
/* It is may be procedure which is also declared
in corresponding definition module. */
current_scope = MODULE_NODE (current_scope)->scope;
current_scope_is_open
= MODE (current_scope) == ICNM_PROCEDURE;
if (current_symbol == SYMBOL_IDENTIFIER
&& !it_is_definition_module
&& SCOPE (current_scope) == NULL)
node_ptr
= find_denotation (current_scope,
icode_symbol_presentation);
if (current_symbol == SYMBOL_IDENTIFIER
&& !it_is_definition_module
&& SCOPE (current_scope) == NULL
&& node_ptr != NULL
&& MODE (node_ptr) == ICNM_PROCEDURE
&& IN_DEFINITION_MODULE (node_ptr))
{
node_ptr
= create_and_initiate_declaration_node
(ICNM_EXPORT, FALSE);
include_to_table (node_ptr);
add_declaration_to_list (node_ptr);
}
else
node_ptr
= create_and_include_declaration_node
(ICNM_EXPORT, FALSE, declaration_ptr);
if (node_ptr != NULL)
{
ADD_EXPORT_TO_LIST (node_ptr);
EXPORT_NODE (node_ptr)->module_exporter
= declaration_ptr;
}
current_scope = declaration_ptr;
current_scope_is_open = FALSE;
}
match_symbol (ERR_in_export_list, SYMBOL_IDENTIFIER);
TEST_CURRENT_SYMBOL (SYMBOL_COMMA OR SYMBOL_SEMICOLON,
ERR_in_export_list);
if (current_symbol == SYMBOL_COMMA)
next_symbol ();
else if (current_symbol == SYMBOL_SEMICOLON ||
it_is_stop_symbol[(int) current_symbol])
break;
}
}
match_symbol (ERR_in_export_list, SYMBOL_SEMICOLON);
}
block ();
test_identifier_after_block (ERR_module_name_after_end);
current_scope = MODULE_NODE (current_scope)->scope;
current_scope_is_open = MODE (current_scope) == ICNM_PROCEDURE;
match_symbol (ERR_identifier_expectation, SYMBOL_IDENTIFIER);
match_symbol (ERR_semicolon_expectation, SYMBOL_SEMICOLON);
}
else if (!test_and_process_C_text ()
&& (current_symbol == SYMBOL_BEGIN || current_symbol == SYMBOL_END
|| it_is_stop_symbol[(int) current_symbol]))
break;
}
LOCAL_MODULE_LIST (current_scope) = first_local_module_ptr;
node_ptr = create_node (ICNM_BLOCK_BEGIN);
BLOCK_BEGIN_NODE (node_ptr)->block_scope = current_scope;
if (last_block_begin_node_ptr != NULL)
BLOCK_BEGIN_NODE (last_block_begin_node_ptr)->next_block_begin = node_ptr;
last_block_begin_node_ptr = node_ptr;
REMOVE_STOP_SYMBOL (SYMBOL_BEGIN);
REMOVE_STOP_SYMBOL (SYMBOL_CONST);
REMOVE_STOP_SYMBOL (SYMBOL_TYPE);
REMOVE_STOP_SYMBOL (SYMBOL_VAR);
REMOVE_STOP_SYMBOL (SYMBOL_PROCEDURE);
REMOVE_STOP_SYMBOL (SYMBOL_MODULE);
REMOVE_STOP_SYMBOL (SYMBOL_C_TEXT);
if (current_symbol == SYMBOL_BEGIN)
{
next_symbol ();
BLOCK_BEGIN_NODE (node_ptr)->next_statement = statement_sequence ();
}
REMOVE_STOP_SYMBOL (SYMBOL_END);
match_symbol (ERR_in_block, SYMBOL_END);
}
/* optional_priority = [ ["const_expression"]" ] */
static void
optional_priority ()
{
register ICN_pointer expression_ptr;
TEST_CURRENT_SYMBOL (SYMBOL_LEFT_BRACKET OR SYMBOL_SEMICOLON,
ERR_in_priority);
if (current_symbol == SYMBOL_LEFT_BRACKET)
{
next_symbol ();
new_error_flag = FALSE;
expression_ptr = expression ();
if (!new_error_flag)
MODULE_NODE (current_scope)->module_priority = expression_ptr;
match_symbol (ERR_in_priority, SYMBOL_RIGHT_BRACKET);
}
}
/* procedure_heading =
"PROCEDURE" IDENTIFIER
[ "(" [ { ["VAR"] {IDENTIFIER/","} ":"
[ "ARRAY" "OF" ] qualident/";"}
]
")" [ ":" qualident ]
]
*/
static void
procedure_heading ()
{
int it_is_var_parameter, it_is_array_parameter;
register ICN_pointer node_ptr, list_of_parameters_with_the_same_type;
register ICN_pointer formal_parameter_list;
ICN_pointer procedure_ptr, procedure_type_ptr;
struct stdid *stdid_ptr;
match_symbol (ERR_in_declaration_part, SYMBOL_PROCEDURE);
procedure_ptr
= create_and_initiate_declaration_node (ICNM_PROCEDURE,
it_is_definition_module);
if (current_symbol != SYMBOL_IDENTIFIER)
{
add_declaration_to_list (procedure_ptr);
}
else
{
if (!current_scope_is_open)
stdid_ptr
= find_stdid
(IDENTIFIER_NODE (icode_symbol_presentation)->identifier_string,
strlen (IDENTIFIER_NODE (icode_symbol_presentation)
->identifier_string));
if (!current_scope_is_open && stdid_ptr != 0
&& (!stdid_ptr->lower_case_stdid || !only_upper_case_flag))
{
add_declaration_to_list (procedure_ptr);
error (ERR_standard_indentifier_declaration);
}
else
{
node_ptr = find_in_or_else_include_to_table (procedure_ptr);
if (node_ptr == procedure_ptr)
{
add_declaration_to_list (procedure_ptr);
}
/* Corresponding procedure from definition module may be in the
hash table. */
else if (MODE (node_ptr) == ICNM_PROCEDURE
&& !it_is_definition_module
&& SCOPE (current_scope) == NULL
&& IN_DEFINITION_MODULE (node_ptr))
{
procedure_ptr
= create_and_initiate_declaration_node (ICNM_PROCEDURE, FALSE);
include_to_table (procedure_ptr);
add_declaration_to_list (procedure_ptr);
}
else
{
error_with_parameter (ERR_repeated_identifier_declaration,
IDENTIFIER_NODE (icode_symbol_presentation)
->identifier_string);
procedure_ptr
= create_and_initiate_declaration_node (ICNM_PROCEDURE, FALSE);
add_declaration_to_list (procedure_ptr);
}
}
}
procedure_type_ptr = create_node (ICNM_PROCEDURE_TYPE);
formal_parameter_list = NULL;
current_scope = procedure_ptr;
current_scope_is_open = TRUE;
match_symbol (ERR_identifier_expectation, SYMBOL_IDENTIFIER);
TEST_CURRENT_SYMBOL (SYMBOL_LEFT_PARENTHESIS OR SYMBOL_SEMICOLON,
ERR_in_procedure_head);
if (current_symbol == SYMBOL_LEFT_PARENTHESIS)
{
next_symbol ();
ADD_STOP_SYMBOL (SYMBOL_RIGHT_PARENTHESIS);
if (current_symbol != SYMBOL_RIGHT_PARENTHESIS)
for (;;)
{
TEST_CURRENT_SYMBOL (SYMBOL_VAR OR SYMBOL_IDENTIFIER,
ERR_in_declaration_of_formal_parameters);
if (current_symbol == SYMBOL_VAR)
{
next_symbol ();
it_is_var_parameter = TRUE;
}
else
it_is_var_parameter = FALSE;
for (list_of_parameters_with_the_same_type = NULL;;)
{
node_ptr
= create_and_include_declaration_node (ICNM_FORMAL_PARAMETER,
FALSE, NULL);
if (formal_parameter_list == NULL)
formal_parameter_list = node_ptr;
if (list_of_parameters_with_the_same_type == NULL)
list_of_parameters_with_the_same_type = node_ptr;
match_symbol (ERR_in_formal_parameter_list, SYMBOL_IDENTIFIER);
TEST_CURRENT_SYMBOL (SYMBOL_COMMA OR SYMBOL_COLON,
ERR_in_declaration_of_formal_parameters);
if (current_symbol == SYMBOL_COMMA)
next_symbol ();
else if (current_symbol == SYMBOL_COLON
|| it_is_stop_symbol[(int) current_symbol])
break;
}
match_symbol (ERR_in_formal_parameter_list, SYMBOL_COLON);
TEST_CURRENT_SYMBOL (SYMBOL_ARRAY OR SYMBOL_IDENTIFIER,
ERR_in_declaration_of_formal_parameters);
if (current_symbol == SYMBOL_ARRAY)
{
next_symbol ();
match_symbol (ERR_keyword_of_expectation, SYMBOL_OF);
it_is_array_parameter = TRUE;
}
else
it_is_array_parameter = FALSE;
new_error_flag = FALSE;
node_ptr = qualident ();
for (; list_of_parameters_with_the_same_type != NULL;
list_of_parameters_with_the_same_type
= NEXT_DECLARATION_ELEMENT
(list_of_parameters_with_the_same_type))
{
if (!new_error_flag)
FORMAL_PARAMETER_TYPE (list_of_parameters_with_the_same_type)
= node_ptr;
VAR_FORMAL_PARAMETER (list_of_parameters_with_the_same_type)
= it_is_var_parameter;
ARRAY_FORMAL_PARAMETER (list_of_parameters_with_the_same_type)
= it_is_array_parameter;
}
TEST_CURRENT_SYMBOL (SYMBOL_SEMICOLON OR SYMBOL_RIGHT_PARENTHESIS,
ERR_in_declaration_of_formal_parameters);
if (current_symbol == SYMBOL_SEMICOLON)
next_symbol ();
else if (current_symbol == SYMBOL_RIGHT_PARENTHESIS
|| it_is_stop_symbol[(int) current_symbol])
break;
}
REMOVE_STOP_SYMBOL (SYMBOL_RIGHT_PARENTHESIS);
match_symbol (ERR_in_declaration_of_formal_parameters,
SYMBOL_RIGHT_PARENTHESIS);
TEST_CURRENT_SYMBOL (SYMBOL_COLON OR SYMBOL_SEMICOLON,
ERR_in_procedure_head);
if (current_symbol == SYMBOL_COLON)
{
next_symbol ();
new_error_flag = FALSE;
node_ptr = qualident ();
if (!new_error_flag)
PROCEDURE_TYPE_NODE (procedure_type_ptr)->procedure_result_type
= node_ptr;
}
}
NEXT_DECLARATION_ELEMENT (procedure_type_ptr) = formal_parameter_list;
PROCEDURE_NODE (procedure_ptr)->procedure_type = procedure_type_ptr;
}
/* The following function is used in function import_list for forming
list of import nodes (on member next_declaration). The function sets up
variable *FIRST_IMPORT_PTR if it is needed and initiates member
module_exporter in ADDED_NODE by IDENTIFIER_AFTER_FROM. */
static void
new_import_node (first_import_ptr, added_node, identifier_after_from)
register ICN_pointer *first_import_ptr;
ICN_pointer added_node, identifier_after_from;
{
if (*first_import_ptr == NULL)
*first_import_ptr = added_node;
IMPORT_NODE (added_node)->module_exporter = identifier_after_from;
}
/* import_list = { [ "FROM" IDENTIFIER] "IMPORT" [ {IDENTIFIER/","} ";" ] } */
static void
import_list ()
{
register ICN_pointer import_ptr, from_identifier_ptr;
register int flag_presence;
ICN_pointer first_import_ptr;
for (first_import_ptr = NULL;;)
{
from_identifier_ptr = NULL;
SET_PRESENCE_FLAG_AND_TEST_CURRENT_SYMBOL
(flag_presence, SYMBOL_FROM OR SYMBOL_IMPORT OR SYMBOL_EXPORT
OR SYMBOL_CONST OR SYMBOL_TYPE OR SYMBOL_VAR OR SYMBOL_C_TEXT
OR SYMBOL_PROCEDURE OR SYMBOL_MODULE OR SYMBOL_BEGIN OR SYMBOL_END,
ERR_in_declaration_part);
if (current_symbol == SYMBOL_FROM)
{
next_symbol ();
if (current_symbol == SYMBOL_IDENTIFIER)
from_identifier_ptr = icode_symbol_presentation;
match_symbol (ERR_identifier_expectation, SYMBOL_IDENTIFIER);
}
else if (current_symbol != SYMBOL_IMPORT
&& (flag_presence || it_is_stop_symbol[(int) current_symbol]))
break;
match_symbol (ERR_keyword_import_expectation, SYMBOL_IMPORT);
TEST_CURRENT_SYMBOL (SYMBOL_IDENTIFIER OR SYMBOL_SEMICOLON,
ERR_in_import_list);
if (current_symbol == SYMBOL_IDENTIFIER)
for (;;)
{
import_ptr
= create_and_include_declaration_node
(ICNM_IMPORT, FALSE, from_identifier_ptr);
if (import_ptr != NULL)
new_import_node (&first_import_ptr, import_ptr,
from_identifier_ptr);
match_symbol (ERR_in_import_list, SYMBOL_IDENTIFIER);
TEST_CURRENT_SYMBOL (SYMBOL_COMMA OR SYMBOL_SEMICOLON,
ERR_in_import_list);
if (current_symbol == SYMBOL_COMMA)
next_symbol ();
else if (current_symbol == SYMBOL_SEMICOLON
|| it_is_stop_symbol[(int) current_symbol])
break;
}
else
{
import_ptr
= create_and_initiate_declaration_node (ICNM_IMPORT, FALSE);
add_declaration_to_list (import_ptr);
new_import_node (&first_import_ptr, import_ptr, from_identifier_ptr);
}
match_symbol (ERR_in_import_list, SYMBOL_SEMICOLON);
}
MODULE_NODE (current_scope)->import_list = first_import_ptr;
}
/* compilation_unit =
"DEFINITION" "MODULE" IDENTIFIER ";" import_list
{ "CONST" constant_declaration_list |
"TYPE" { IDENTIFIER[ "=" type ]; | CTEXT } |
CTEXT |
"VAR" variable_declaration_list |
procedure_heading ";"
}"END" IDENTIFIER "." |
[ "IMPLEMENTATION" ] "MODULE" IDENTIFIER optional_priority ";"
import_list block IDENTIFIER "."
The function returns TRUE if processed file has suffix of implementation
module, and is an implementation module itself, and corresponding
definition module has not been processed yet. It means that only first
keyword in the source file was processed and that it is necessary to
process corresponding definition module and after that to repeat
processing the source file. */
int
compilation_unit ()
{
enum symbol saved_current_symbol;
register ICN_pointer identifier_icode_presentation, type_declaration_ptr;
register ICN_pointer type_definition_ptr, saved_icode_symbol_presentation;
register int presence_flag;
enum module_mode module_mode;
start_scanner ();
current_scope = last_block_begin_node_ptr = NULL;
current_scope_is_open = FALSE;
ADD_STOP_SYMBOL (SYMBOL_END_OF_FILE);
TEST_CURRENT_SYMBOL (SYMBOL_DEFINITION OR SYMBOL_IMPLEMENTATION
OR SYMBOL_MODULE, ERR_in_compilation_unit_begin);
it_is_main_module = (current_symbol == SYMBOL_MODULE);
it_is_definition_module = (current_symbol == SYMBOL_DEFINITION);
if (!testing_main_module)
{
if (current_symbol == SYMBOL_DEFINITION)
{
next_symbol ();
match_symbol (ERR_in_compilation_unit_begin, SYMBOL_MODULE);
current_compilation_unit
= create_and_initiate_declaration_node (ICNM_MODULE, FALSE);
if (current_symbol == SYMBOL_IDENTIFIER
&& (current_compilation_unit
!= find_in_or_else_include_to_table (current_compilation_unit)))
{
current_compilation_unit
= create_and_initiate_declaration_node (ICNM_MODULE, FALSE);
error_with_parameter
(ERR_repeated_identifier_declaration,
IDENTIFIER_NODE (icode_symbol_presentation)
->identifier_string);
}
MODULE_NODE (current_compilation_unit)->module_mode
= (char) MM_DEFINITION_MODULE;
pred_declaration_ptr
= pred_export_ptr = current_scope = current_compilation_unit;
test_input_file_name (current_compilation_unit);
match_symbol (ERR_identifier_expectation, SYMBOL_IDENTIFIER);
match_symbol (ERR_semicolon_expectation, SYMBOL_SEMICOLON);
ADD_STOP_SYMBOL (SYMBOL_CONST);
ADD_STOP_SYMBOL (SYMBOL_TYPE);
ADD_STOP_SYMBOL (SYMBOL_VAR);
ADD_STOP_SYMBOL (SYMBOL_PROCEDURE);
ADD_STOP_SYMBOL (SYMBOL_C_TEXT);
ADD_STOP_SYMBOL (SYMBOL_END);
import_list ();
if (!picking_names_of_imported_modules)
for (;;)
{
TEST_CURRENT_SYMBOL
(SYMBOL_CONST OR SYMBOL_TYPE OR SYMBOL_C_TEXT OR SYMBOL_VAR
OR SYMBOL_PROCEDURE OR SYMBOL_END, ERR_in_declaration_part);
if (current_symbol == SYMBOL_CONST)
{
next_symbol ();
constant_declaration_list ();
}
else if (current_symbol == SYMBOL_TYPE)
{
next_symbol ();
for (;;)
{
TEST_CURRENT_SYMBOL
(SYMBOL_IDENTIFIER OR SYMBOL_CONST OR SYMBOL_TYPE
OR SYMBOL_C_TEXT OR SYMBOL_VAR OR SYMBOL_PROCEDURE
OR SYMBOL_END, ERR_in_type_declaration_part);
if (current_symbol == SYMBOL_IDENTIFIER)
{
identifier_icode_presentation
= icode_symbol_presentation;
next_symbol ();
TEST_CURRENT_SYMBOL (SYMBOL_EQUAL
OR SYMBOL_SEMICOLON,
ERR_in_type_declaration_part);
saved_current_symbol = current_symbol;
saved_icode_symbol_presentation
= icode_symbol_presentation;
current_symbol = SYMBOL_IDENTIFIER;
icode_symbol_presentation
= identifier_icode_presentation;
if (saved_current_symbol != SYMBOL_EQUAL)
{
create_and_include_qualified_export_node
(TRUE);
current_symbol = saved_current_symbol;
icode_symbol_presentation
= saved_icode_symbol_presentation;
}
else
{
type_declaration_ptr
= create_and_include_declaration_node
(ICNM_TYPE_DECLARATION,
it_is_definition_module, NULL);
next_symbol ();
new_error_flag = FALSE;
type_definition_ptr = type ();
if (!new_error_flag
&& type_declaration_ptr != NULL)
{
TYPE_DECLARATION_NODE
(type_declaration_ptr)
->type_definition
= type_definition_ptr;
if (MODE (type_definition_ptr)
== ICNM_RECORD)
RECORD_NODE (type_definition_ptr)
->record_type_identifier
= type_declaration_ptr;
}
}
match_symbol (ERR_in_type, SYMBOL_SEMICOLON);
}
else if (!test_and_process_C_text ())
break;
}
}
else if (current_symbol == SYMBOL_VAR)
{
next_symbol ();
variable_declaration_list ();
}
else if (current_symbol == SYMBOL_PROCEDURE)
{
procedure_heading ();
current_scope = PROCEDURE_NODE (current_scope)->scope;
current_scope_is_open = FALSE;
match_symbol (ERR_semicolon_expectation, SYMBOL_SEMICOLON);
}
else if (!test_and_process_C_text ()
&& (current_symbol == SYMBOL_END
|| it_is_stop_symbol[(int) current_symbol]))
{
match_symbol (ERR_in_declaration_part, SYMBOL_END);
test_identifier_after_block (ERR_module_name_after_end);
match_symbol (ERR_identifier_expectation,
SYMBOL_IDENTIFIER);
match_symbol (ERR_symbol_colon_expectation, SYMBOL_PERIOD);
break;
}
}
REMOVE_STOP_SYMBOL (SYMBOL_CONST);
REMOVE_STOP_SYMBOL (SYMBOL_TYPE);
REMOVE_STOP_SYMBOL (SYMBOL_VAR);
REMOVE_STOP_SYMBOL (SYMBOL_PROCEDURE);
REMOVE_STOP_SYMBOL (SYMBOL_C_TEXT);
REMOVE_STOP_SYMBOL (SYMBOL_END);
}
else
{
if (current_symbol == SYMBOL_IMPLEMENTATION)
{
register char *name_without_suffix;
name_without_suffix = file_name_without_suffix (input_file_name);
if (strcmp (file_name_suffix (input_file_name),
IMPLEMENTATION_MODULE_SUFFIX) == 0
&& (find_denotation
(ICN_POINTER (NULL),
create_identifier_node (base_file_name
(name_without_suffix)))
== NULL))
{
M2C_FREE (name_without_suffix);
return TRUE;
}
M2C_FREE (name_without_suffix);
next_symbol ();
module_mode = MM_DEFINITION_WITH_IMPLEMENTATION_MODULE;
}
else
module_mode = MM_MAIN_MODULE;
match_symbol (ERR_in_compilation_unit_begin, SYMBOL_MODULE);
current_compilation_unit
= create_and_initiate_declaration_node (ICNM_MODULE, FALSE);
if (current_symbol == SYMBOL_IDENTIFIER
&& module_mode == MM_DEFINITION_WITH_IMPLEMENTATION_MODULE)
{
current_compilation_unit
= find_in_or_else_include_to_table (current_compilation_unit);
for (pred_declaration_ptr = current_compilation_unit;
NEXT_DECLARATION_ELEMENT (pred_declaration_ptr) != NULL;
pred_declaration_ptr
= NEXT_DECLARATION_ELEMENT (pred_declaration_ptr));
}
else
{
if (current_symbol == SYMBOL_IDENTIFIER
&& (find_in_or_else_include_to_table (current_compilation_unit)
!= current_compilation_unit))
{
current_compilation_unit
= create_and_initiate_declaration_node (ICNM_MODULE,
FALSE);
error_with_parameter (ERR_repeated_identifier_declaration,
IDENTIFIER_NODE (icode_symbol_presentation)
->identifier_string);
}
pred_declaration_ptr = current_compilation_unit;
}
MODULE_NODE (current_compilation_unit)->module_mode
= (char) module_mode;
current_scope = current_compilation_unit;
test_input_file_name (current_compilation_unit);
match_symbol (ERR_identifier_expectation, SYMBOL_IDENTIFIER);
optional_priority ();
match_symbol (ERR_semicolon_expectation, SYMBOL_SEMICOLON);
import_list ();
if (!picking_names_of_imported_modules)
{
block ();
test_identifier_after_block (ERR_module_name_after_end);
match_symbol (ERR_identifier_expectation, SYMBOL_IDENTIFIER);
match_symbol (ERR_symbol_colon_expectation, SYMBOL_PERIOD);
}
}
}
REMOVE_STOP_SYMBOL (SYMBOL_END_OF_FILE);
if (!testing_main_module && !picking_names_of_imported_modules)
match_symbol (ERR_end_of_file_expectation, SYMBOL_END_OF_FILE);
return FALSE;
}
/* The following function is to be called only one for the translator
run time. */
void
initiate_analyzer_data ()
{
initiate_scanner_data ();
}
|