/usr/share/doc/polygen/HOWTO-Refman.en.html is in polygen 1.0.6.ds2-14build1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
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 | <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>HOWTO-grm</title>
<meta http-equiv="content-type"
content="text/html; charset=ISO-8859-3">
</head>
<body>
<h1 align="center">HOWTO-grm</h1>
<h1 align="center"> </h1>
<h1 align="center"><small>id est</small></h1>
<h1 align="center"> </h1>
<h1 align="center">How to write a PolyGen grammar</h1>
<h2><br>
</h2>
<h2>Index</h2>
<b>1.0</b> <a href="#1.0_Cos%E8_una_grammatica">What is
a grammar?</a><br>
<br>
<b> 1.0.1</b> <a
href="#1.0.1_Sottoproduzioni">Subproductions</a><br>
<b> 1.0.2</b> <a
href="#1.0.2_Sottoproduzioni_opzionali">Optional subproductions</a><br>
<b> 1.0.3</b> <a
href="#1.0.3_Commenti">Comments</a><br>
<br>
<br>
<b> 2.0</b> <a
href="#2.0_Caratteristiche_avanzate">Advanced features</a><br>
<b> </b><b><br>
</b><b> </b><b>2.0.1</b> <a
href="#2.0.1_Concatenazione">Concatenation</a><br>
<b> </b><b>2.0.2</b> <a href="#2.0.2_Epsilon">Epsilon</a><br>
<b> </b><b>2.0.3</b> <a
href="#2.0.3_Controllo_della_probabilit%E0_di_una">Controlling the probability
of a production</a><br>
<b> </b><b>2.0.4</b> <a
href="#2.0.4_Unfolding">Unfolding</a><br>
<br>
<b>2.0.4.1</b> <a
href="#2.0.4.1_Di_simboli_non_terminali">Non-terminal symbols</a><br>
<b> 2.0.4.2</b> <a
href="#2.0.4.2_Di_sottoproduzioni">Subproductions<br>
</a><b> </b><b>2.0.4.3</b> <a
href="#2.0.4.3_Di_sottoproduzioni_opzionali">Optional subproductions</a><br>
<b>2.0.4.4</b> <a
href="#2.0.4.4_Di_sottoproduzioni_permutabili">Permutable subproductions</a><br>
<b> 2.0.4.5</b> <a
href="#2.0.4.5_Di_sottoproduzioni_soggette">Deeply unfolded subproductions</a><br>
<b><br>
2.0.5</b> <a href="#2.0.5_Attributi">Attributes</a><br>
<b> <br>
2.0.5.1</b> <a href="#2.0.5.1_Etichette_e_selezione">Labels
and selection</a><br>
<b> 2.0.5.2</b> <a
href="#2.0.5.2_Selezione_multipla">Multiple selection</a><br>
<br>
<b>2.0.6</b> <a href="#2.0.6_Maiuscole">Capitalization</a><br>
<b>2.0.7</b> <a href="#2.0.7_Permutazioni">Permutation</a><br>
<b> 2.0.8 </b><a href="#2.0.8_Unfolding_in_profondit%E0">Deep unfolding</a><br>
<b> 2.0.9</b> <a href="#2.0.9_Folding">Folding</a><br>
<br>
<br>
<b>2.1</b> <a href="#2.1_Tecniche_avanzate">Advanced
techniques</a><br>
<br>
<b> </b><b>2.1.1</b> <a
href="#2.1.1_Ricorsione">Recursion</a><br>
<b> </b><b>2.1.2 </b><a
href="#2.1.2_Ragruppamento">Grouping</a><br>
<b> </b><b>2.1.3</b> <a
href="#2.1.3_Controllo_della_probabilt%E0_di_una">Controlling the probabilty
of an optional subproduction</a><br>
<b> </b><b>2.1.4</b> <a
href="#2.1.4_Reset_di_una_selezione">Selection reset</a><br>
<br>
<br>
<b>3.0</b> <a
href="#3.0_Controllo_statico_di_una_grammatica">Static checking of grammars</a><br>
<br>
<b> </b><b>3.0.1</b> <a
href="#3.0.1_Errori">Errors</a><br>
<br>
<b> </b><b> </b><b>
3.0.1.1</b> <a href="#3.0.1.1_Inesistenza_di_simboli_non">Undefined
non-terminal simbols</a><br>
<b> </b><b> </b><b>
</b><b>3.0.1.2</b> <a href="#3.0.1.2_Ricorsioni_cicliche_e">Cyclic
recursion and non-termination</a><br>
<b> </b><b> </b><b>
</b><b>3.0.1.3</b> <a href="#3.0.1.3_Unfolding_ricorsivi">Recursive
unfolding</a><br>
<b> </b><b> </b><b>
</b><b>3.0.1.4</b> <a href="#3.0.1.4_Epsilon-produzioni">Epsilon-productions</a><br>
<b> </b><b>3.0.1.5</b> <a
href="#3.0.1.5_Ridefinizione_di_simboli_non_terminali">Overriding of non-terminal
symbols</a><br>
<b> 3.0.1.6</b> <a href="#3.0.1.6_Carattere_sconosciuto">Illegal
character</a><br>
<b> 3.0.1.7</b> <a href="#3.0.1.7_Token_inaspettato">Unexpected
token</a><br>
<br>
<b> </b><b>3.0.2</b> <a href="#3.0.2_Warning">Warnings</a><br>
<br>
<b>3.0.2.0 </b><a href="#3.0.2.0_Livello_0">Level 0</a><br>
<br>
<b>3.0.2.1</b> <a href="#3.0.2.0_Livello_1">Level 1</a><br>
<br>
<b>
</b><b>3.0.2.1.1</b> <a
href="#3.0.2.1_Inesistenza_del_simbolo_I">Undefined symbol <code>I</code></a><br>
<b>
</b><b> </b><b> </b><b> 3.0.2.1.2</b> <a
href="#3.0.2.2_Potenziali_epsilon-produzioni">Potential epsilon-productions</a><br>
<br>
<b>3.0.2.2</b> <a href="#3.0.2.0_Livello_2">Level 2</a><br>
<b> <br>
3.0.2.2.1</b> <a
href="#3.0.2.2_Permutazione_inutile">Useless permutation</a><a
href="file:///home/manta/develop/polygen/0.8.1/ita/HOWTO-grm.html#3.0.2.2.1_Permutazione_inutile"></a><br>
<b> </b><b>3.0.2.2.2</b> <a
href="#3.0.2.2.2_Potenziale_ricorsione_ciclica">Potential cyclic recursion</a><b><br>
</b><br>
<br>
<b>4.0</b> <a href="#4.0_Appendice">Appendix</a><br>
<br>
<b> </b><b>4.1.1 </b><a
href="#4.1.1_Sintassi_concreta">Concrete syntax</a><br>
<b> 4.1.2 </b><a href="#4.1.2_Sintassi_astratta">Abstract syntax</a><br>
<b> </b><b>4.1.3</b> <a
href="#4.1.3_Regole_lessicali">Lexical rules</a><br>
<b> </b><b>4.1.4</b> <a
href="#4.1.4_Caratteri_escape">Escape sequences</a><br>
<b>4.1.5</b> <a href="#4.1.5_Regole_di_traduzione">Translation
rules</a><br>
<br>
<br>
<br>
<br>
<h2><a name="1.0_Cosè_una_grammatica"></a>1.0 What is a grammar?</h2>
A grammar is an ASCII text file providing the definition of the
syntactical structure and terms used by the program to build sentences.
<i>PolyGen</i> is able to interpret a language designed for defining
<i>type-2</i> grammars (according to Chomsky classification) consisting
in an extension of the <i>BNF (Backus Naur Form)</i> - a very simple and
common form for the description of the syntax of a language.<br>
<br>
A definition consists in specifying for a given symbol a set of
productions interleaved by a <b>pipe </b><font color="#cc0000"><code>|</code></font>
and followed by a <b>semicolon</b> <b><code><font color="#cc0000">;</font></code></b>
, which acts as terminator:<br>
<br>
<b><samp>EXAMPLE</samp><samp></samp></b><br>
<br>
<code> <font color="#996633">S</font> <font
color="#cc0000">::=</font> the apple <font color="#cc0000">|</font> an orange
<font color="#cc0000">;</font></code><br>
<br>
<br>
<b> <samp>PRODUCES<br>
</samp></b><code><br>
the apple<br>
an orange<br>
</code><br>
<br>
<br>
Such definition of symbol <code><font color="#996633">S</font></code>
(said <b>non-terminal</b>) allows the generation of symbols <code>the
apple</code> as well as <code>an orange</code> (said <b>terminal</b>).<br>
The probability for the output <code>the apple</code> to be generated
is equal to 1 every 3 times; and the same for <code>an orange</code>:
thus, when 2 productions occur, we have 1 in 2 chances each; when 5 occur,
we have 1 in 5, etc.<br>
<br>
You're allowed to define several non-terminal symbols and reference
them from any productions, in order to let more complex sentences be
generated:<br>
<br>
<b><samp>EXAMPLE</samp></b><br>
<br>
<code> <font color="#996633">S</font> <font
color="#cc0000">::=</font> the <font color="#996633">Animal</font> is eating
a <font color="#996633">Animal</font> <font color="#cc0000">;</font><br>
<br>
<font color="#996633">Animale</font> <font
color="#cc0000">::=</font> cat <font color="#cc0000">|</font> dog <font
color="#cc0000">;</font></code><br>
<br>
<br>
<b><samp>PRODUCES<br>
</samp></b><code><br>
the cat is eating a cat<br>
the cat is eating a dog<br>
the dog is eating a cat<br>
the dog is eating a dog</code><br>
<br>
ecc.<br>
<br>
<br>
<small><b> Note:</b> <i>PolyGen</i> uses by
default the non-terminal symbol <code><font color="#996633">S</font></code>
as the starting one: every grammar must therefore define it at least
unless another starting symbol has been specified as argument to the program.<br>
</small><br>
By default, a term beginning with a capital letter is considered
as non-terminal (thus bound to a definition) and a term beginning with
a non-capital letter as terminal (a simple word). If you need then to
specify a capital word you must quote it in order to get the program not
to mistake it for a non-terminal symbol:<br>
<br>
<b><samp>EXAMPLE</samp></b><br>
<br>
<code> <font color="#996633">S</font> <font
color="#cc0000">::=</font> a<font color="#996633"> Pet</font> called "Pet"
<font color="#cc0000">;</font><br>
<br>
<font color="#996633">Pet</font> <font
color="#cc0000">::=</font> cat <font color="#cc0000">|</font> pig <font
color="#cc0000">|</font> dog <font color="#cc0000">;</font></code><br>
<br>
<br>
<b><samp>PRODUCES<br>
</samp></b><code><br>
a cat called Pet<br>
a pig called Pet<br>
a dog called Pet</code><br>
<br>
<br>
Keep in mind that many characters (punctuation marks, parentheses,
etc), including those interpret as keywords by the program, must be
quoted to be output (see section <a href="#4.1.3_Regole_lessicali">4.1.3</a>
for complete lexical rules).<br>
<br>
<samp><b>EXAMPLE</b></samp><br>
<br>
<code> <font color="#996633">S</font> <font
color="#cc0000">::=</font> "(" <font color="#cc0000">(</font>apple <font
color="#cc0000">|</font> orange<font color="#cc0000">)</font> ")" <font
color="#cc0000">;</font></code><br>
<br>
<br>
<samp><b>PRODUCES<br>
</b></samp><code><br>
( apple )<br>
( orange )</code><br>
<br>
<br>
<br>
<h3><a name="1.0.1_Sottoproduzioni"></a> 1.0.1 Subproductions<br>
</h3>
After the keyword <font color="#cc0000"><code>::=</code></font>
in a definition, a subproduction of any form can be specified between
round brackets:<br>
<br>
<samp><b>EXAMPLE</b></samp><br>
<br>
<code><font color="#996633">S</font> <font
color="#cc0000">::=</font> an <font color="#cc0000">(</font></code><code>apple</code><code></code><code></code><code>
<font color="#cc0000">|</font> orange</code><code><font
color="#cc0000">)</font> is on the <font color="#cc0000">(</font></code><code>table</code><code><font
color="#cc0000"> | </font></code><code>desk</code><code><font
color="#cc0000">)</font> <font color="#cc0000">;</font><br>
<br>
</code> <br>
<samp><b>PRODUCES</b></samp><br>
<br>
<code>an apple is on the table<br>
an orange is on the table<br>
an apple is on the desk<br>
an orange is on the desk<br>
</code><br>
<br>
Subproductions are generated as standalone blocks, that is as they
were bound to a non-terminal symbol.<br>
<br>
<h3><a name="1.0.2_Sottoproduzioni_opzionali"></a> 1.0.2 Optional subproductions<br>
</h3>
A subproduction specified between square brakets is considered
as optional and is generated 1 every 2 times, i.e. 50% probability:<br>
<br>
<samp><b>EXAMPLE</b></samp><br>
<br>
<code><font color="#996633"> S</font> <font
color="#cc0000">::=</font> an <font color="#cc0000">(</font>apple <font
color="#cc0000">|</font> orange<font color="#cc0000">)</font> is on the
<font color="#cc0000">(</font>table <font color="#cc0000">|</font> desk<font
color="#cc0000">)</font> <font color="#cc0000">[</font>in the <font
color="#cc0000">(</font>living <font color="#cc0000">|</font> dining<font
color="#cc0000">)</font> room<font color="#cc0000">] ;</font><br>
<br>
</code> <br>
<samp><b>PRODUCES</b></samp><br>
<br>
<code>an apple is on the table<br>
an apple is on the table in the living room<br>
an apple is on the table in the dining room<br>
an orange is on the table<br>
an orange is on the table in the living room</code><code><br>
<br>
</code> ecc.<br>
<br>
<br>
Optional subproductions, apart from being generated once every two
times, behave as normal subproductions.<br>
<br>
<br>
<h3><a name="1.0.3_Commenti"></a> 1.0.3 Comments<br>
</h3>
You can write any kind of text within a pair of <font
color="#cc0000"><code>(*</code></font> and <font color="#cc0000"><code>*)</code></font>
keywords. Such text will be completely ignored by <i>PolyGen.</i><br>
<br>
<samp><b>EXAMPLE</b></samp><br>
<br>
<code><font color="#996633"> S</font> <font
color="#cc0000">::=</font> apple <font color="#cc0000">|</font> rainge
<font color="#666666">(* | banana *)</font> <font color="#cc0000">|</font>
mango <font color="#cc0000">;</font><br>
<font color="#666666"> (* this is comment
too *)</font><br>
<br>
</code> <br>
<samp><b>PRODUCES</b></samp><br>
<br>
<code>apple<br>
orange<br>
mango<br>
<br>
<br>
<br>
<br>
</code>
<h2><a name="2.0_Caratteristiche_avanzate"></a>2.0 Advanced features<br>
</h2>
<i>PolyGen</i> provides a set of keywords that raises the language
expressivity beyond <i>BNF.</i><br>
<br>
<br>
<h3><a name="2.0.1_Concatenazione"></a>2.0.1 Concatenation<br>
</h3>
The <b>cap</b> <font color="#cc0000"><code>^</code></font>
can be either prefixed or suffixed to as well as infixed in any point
within a production in order to make the program not insert a white space
character in the output string:<br>
<br>
<samp><b>EXAMPLE</b></samp><br>
<br>
<code><font color="#996633"> S</font> <font
color="#cc0000">::=</font> "(" <font color="#cc0000">^ (</font>apple <font
color="#cc0000">|</font> orange<font color="#cc0000">) ^</font> ")" <font
color="#cc0000">;</font><br>
<br>
</code> <br>
<samp><b>PRODUCES</b></samp><br>
<br>
<code> (apple)<br>
(orange)<br>
<br>
</code> <br>
Concatenation, as a feature, is particularly useful every time
you wish to generate words by assembling syllabes or letters coming from
different productions:<br>
<br>
<samp><b>EXAMPLE</b></samp><br>
<br>
<code><font color="#996633"> S</font> <font
color="#cc0000">::=</font> "I" <font color="#996633">Verb <font
color="#cc0000">^</font> </font>e<font color="#996633"> Verb <font
color="#cc0000">^</font> </font><font color="#996633">ing</font> <font
color="#cc0000">;</font><br>
<br>
<font color="#996633">Verb</font> <font
color="#cc0000">::=</font> lov <font color="#cc0000">| </font>hat <font
color="#cc0000">;</font><br>
<br>
</code> <br>
<samp><b>PRODUCES</b></samp><br>
<br>
<code>I love hating<br>
I love loving<br>
I hate hating<br>
I hate loving</code><code><br>
<br>
</code> <br>
Keep in mind that specifying many caps is perfectly equal to specifying
one only.<br>
<br>
<br>
<br>
<h3><a name="2.0.2_Epsilon"></a> 2.0.2 Epsilon<br>
</h3>
The <b>underscore</b> keyword <font color="#cc0000"><code>_</code></font>
stands for the empty production, formally called <i>epsilon</i>.<br>
<br>
<samp><b>EXAMPLE</b></samp><br>
<br>
<code><font color="#996633"> S</font> <font
color="#cc0000">::=</font> ball <font color="#cc0000">| _ ;</font><br>
<br>
</code> <br>
<samp><b>PRODUCES</b></samp><br>
<br>
<code> ball<br>
<font color="#cc0000"> _</font><br>
</code> <br>
<br>
Notice that an epsilon-production is neither the underscore character
itself nor the white space, rather it stands for no output at all - the
empty string, if you prefer. The former example is perfectly equivalent
to the following:<br>
<br>
<samp><b>EXAMPLE</b></samp><br>
<br>
<code><font color="#996633"> S</font> <font
color="#cc0000">::=</font> <font color="#cc0000">[</font>palla<font
color="#cc0000">] ;</font><br>
<br>
</code> <br>
<samp><b>PRODUCES</b></samp><br>
<br>
<code> palla<br>
<font color="#cc0000"> _</font><br>
</code> <br>
<br>
That is a grammar generating either <code>a</code> or nothing as
output.<br>
<br>
<br>
<br>
<h3><a name="2.0.3_Controllo_della_probabilità_di_una"></a> 2.0.3 Controlling
the probability of a production<br>
</h3>
The <b>plus</b> keyword <font color="#cc0000"><code>+</code></font>
, when prefixed to a (sub)production (however nested), raises the probability
for it to be generated, in respect to the others of that very series;
simmetrically, the <b>minus</b> keyword <font color="#cc0000"><code>-</code></font>
lowers it down. Any number of <font color="#cc0000"><code>+</code></font>
and <font color="#cc0000"><code>-</code></font> keywords may be specified:<br>
<br>
<samp><b>EXAMPLE</b></samp><br>
<br>
<code><font color="#996633"> S</font> <font
color="#cc0000">::=</font> the cat is eating <font color="#cc0000">(+</font>
an apple <font color="#cc0000">|-</font> an orange <font
color="#cc0000">|</font> some meat <font color="#cc0000">|--</font> a
lemon<font color="#cc0000">) ;</font><br>
</code> <br>
<br>
<samp><b>PRODUCES</b></samp><br>
<br>
<code>the cat is eating an apple<br>
the cat is eating an orange<br>
the cat is eating some meat<br>
the cat is eating a lemon</code><code> <br>
<br>
<br>
</code> <br>
The set of sentences that can be produced is as expected; indeed,
the definition for the non-terminal symbol <code><font
color="#996633">S</font></code> is internally interpretet as follows:<br>
<br>
<code><font color="#996633"> S</font> <font
color="#cc0000">::=</font> the cat is eating <font color="#cc0000">(</font>
an apple <font color="#cc0000">|</font> an apple <font
color="#cc0000">|</font> an apple <font color="#cc0000">|</font> an apple<br>
<font color="#cc0000">
|</font> an orange <font color="#cc0000">|</font> an orange<br>
<font color="#cc0000"> |</font>
some meat <font color="#cc0000">|</font> some meat <font
color="#cc0000">|</font> some meat<br>
<font color="#cc0000"> |</font>
a lemon<font color="#cc0000">) ;</font><br>
<br>
</code> <br>
as requested, proportion of probabilty raising and lowering holds:
the probability for <code>an apple</code> to be generated is higher than <code>an
orange</code>, which is higher that <code>some meat</code>, on its turn
higher than <code>a lemon</code>.<br>
<br>
<br>
<br>
<br>
<h3><a name="2.0.4_Unfolding"></a> 2.0.4 Unfolding</h3>
<i>PolyGen</i> provides a powerful unfolding system which, in general,
allows to take a series of productions (otherwise folded either by a subproduction
or a non-terminal symbol) to the level of the current sequence.<br>
Roughly, you may look at this operation as at the <i>flattening</i> of
a portion of grammar that is performed before the generation and that may
thus affect it just as far as the probability are concerned, since the
transformation does not alter the source grammar semantics - as the traslation
rules in section <a href="#4.1.5_Regole_di_traduzione">4.1.5</a> confirm.<br>
<br>
Not every atom though supports unfolding, rather only those which such
operation makes sense for: refer to section <a
href="#4.1.1_Sintassi_concreta">4.1.1</a> for a syntactical formalization
of such subset.<br>
<br>
<h4><a name="2.0.4.1_Di_simboli_non_terminali"></a> 2.0.4.1 Non-terminal
symbols</h4>
Consider the following scenario:<br>
<br>
<samp><b>EXAMPLE</b></samp><br>
<br>
<code><font color="#996633"> S</font> <font
color="#cc0000">::=</font> ugly cat <font color="#cc0000">|</font> nice
<font color="#996633">Animal</font> <font color="#cc0000">;</font><br>
<br>
<font color="#996633">Animal</font> <font
color="#cc0000">::=</font> dog <font color="#cc0000">|</font> bull <font
color="#cc0000">|</font> pig <font color="#cc0000">;</font><br>
<br>
<br>
</code> <samp><b>PRODUCES</b></samp><br>
<br>
<code> ugly cat<br>
nice dog<br>
nice bull<br>
nice pig<br>
<br>
</code> <br>
Produced output deserves no surprises, still the chance for <code>ugly
cat</code> to be generated is 1 every 2 times, but it is not the same
for <code>nice dog</code>, <code>nice bull</code> and <code>nice pig</code>,
even though a user may find it reasonable for all them to be generated
with the same probability.<br>
The problem is due to productions <code>ugly cat</code> and <code>nice
<font color="#996633">Animal</font></code> equally sharing the unit of
prabability of <code><font color="#996633">S</font></code>: thus the
chances for <code>ugly cat</code> to be generated is equal to the chances
for <code>nice <font color="#996633">Animal</font></code>, i.e. one among <code>nice
dog</code>, <code>nice bull</code> and <code>nice pig</code>. In the
example above the probability distribution appears as follows:<br>
<br>
<code></code>
<table border="1" width="30%" cellpadding="2" cellspacing="2"
bgcolor="#cccccc">
<tbody>
<tr>
<td><code>ugly cat</code><br>
</td>
<td> 1/2</td>
</tr>
<tr>
<td><code>nice dog</code><br>
</td>
<td> 1/2 * 1/3 = 1/6</td>
</tr>
<tr>
<td><code>nice bull</code><br>
</td>
<td> 1/2 * 1/3 = 1/6</td>
</tr>
<tr>
<td><code>nice pig</code><br>
</td>
<td> 1/2 * 1/3 = 1/6</td>
</tr>
</tbody>
</table>
<br>
<br>
As a proof, 1/2 + 1/6 + 1/6 + 1/6 = 1.<br>
<br>
In order to equally redistribute prababilities of subproductions,
the user should write <code><font color="#996633"> S</font></code> this
way:<br>
<br>
<code><font color="#996633"> S</font> <font color="#cc0000">::=</font>
ugly cat <font color="#cc0000">|</font> nice dog <font
color="#cc0000">|</font> nice bull <font color="#cc0000">|</font> nice
pig <font color="#cc0000">;</font></code><br>
<br>
though loosing the original architecture, which used to fold all animals
within a non-terminal symbol, and moreover dramatically increasing the
amount of editing duties.<br>
In order to solve this problem, itself an instance of the dishomogeneity
of probability distribution problem in case of subproductions, the language
offers an operator<font color="#cc0000"><code></code></font> for <b>unfolding</b>
non-terminal symbols:<br>
<br>
<samp><b>EXAMPLE</b></samp><br>
<br>
<code><font color="#996633"> S</font> <font
color="#cc0000">::=</font> ugly cat <font color="#cc0000">|</font> nice
</code><code><font color="#cc0000">></font></code><code><font
color="#996633">Animal</font> <font color="#cc0000">;</font><br>
<br>
<font color="#996633">Animal</font> <font
color="#cc0000">::=</font> dog <font color="#cc0000">|</font> bull <font
color="#cc0000">|</font> pig <font color="#cc0000">;</font></code><br>
<br>
<br>
Prefixing the <font color="#cc0000"><code>></code></font> keyword
to a non-terminal symbol, during the preprocessing phase the program performs
the translation above, changing the probability distribution as follows:<br>
<br>
<code></code>
<table border="1" width="30%" cellpadding="2" cellspacing="2"
bgcolor="#cccccc">
<tbody>
<tr>
<td><code>ugly cat</code><br>
</td>
<td>1/4</td>
</tr>
<tr>
<td><code>nice dog</code><br>
</td>
<td>1/4</td>
</tr>
<tr>
<td><code>nice bull</code><br>
</td>
<td>1/4</td>
</tr>
<tr>
<td><code>nice pig</code><br>
</td>
<td>1/4</td>
</tr>
</tbody>
</table>
<br>
<br>
<br>
<h4><a name="2.0.4.2_Di_sottoproduzioni"></a> 2.0.4.2 Subproductions<br>
</h4>
It is not uncommon to use subproductions in order
to decrease grammar verbosity, e.g. by collecting a set of phrasal verbs
according to the supported preposition.<br>
<br>
<samp><b>EXAMPLE</b></samp><br>
<br>
<code><font color="#996633"> S</font> <font
color="#cc0000">::=</font> <font color="#cc0000">(</font>walk </code><code><font
color="#cc0000">|</font></code><code> pass<font color="#cc0000">)</font>
through<br>
</code><code><font color="#cc0000">|</font></code><code> look at<br>
</code><code><font color="#cc0000">|</font></code><code> </code><code><font
color="#cc0000">(</font></code><code>go </code><code><font
color="#cc0000">|</font></code><code> come </code><code><font
color="#cc0000">|</font></code><code> move </code><code><font
color="#cc0000">|</font></code><code> link </code><code><font
color="#cc0000">|</font></code><code> run</code><code><font
color="#cc0000">)</font></code><code> to</code><code></code><code> <font
color="#cc0000">;</font></code><br>
<br>
<br>
Grammar architecture and scalability increase, on one side, while,
on the other side, output quality lowers down, since 1 every 3 times <code>look
at</code> will be generated for the same reason discussed in section <a
href="#2.0.4.1_Di_simboli_non_terminali">2.0.4.1</a>. In order to take output
etherogeneity to the desired level, that is where each single verb may
be produced with the same probability, the user should avoid round bracket
usage at all, so that there would be no more 3 macro-productions, and should
suffix the proper preposition to each verb.<br>
For this very purpose, any subproduction may be <b>unfolded</b> analogously
to what stated in section <a href="#2.0.4.1_Di_simboli_non_terminali">2.0.4.1</a>
regarding non-terminal symbols. The operator <font color="#cc0000"><code>></code></font>
makes the program delegate to the preprocessor the unfolding of the following
subproduction, allowing the user to keep the original source architecture
unchanged.<br>
<br>
<samp><b>EXAMPLE</b></samp><br>
<br>
<code><font color="#996633"> S</font> <font
color="#cc0000">::=</font> <font color="#cc0000">>(</font>walk </code><code><font
color="#cc0000">|</font></code><code> pass<font color="#cc0000">)</font>
through<br>
</code><code><font color="#cc0000">|</font></code><code> look
at<br>
</code><code><font color="#cc0000">|</font></code><code> </code><code><font
color="#cc0000">>(</font></code><code>go </code><code><font
color="#cc0000">|</font></code><code> come </code><code><font
color="#cc0000">|</font></code><code> move </code><code><font
color="#cc0000">|</font></code><code> link </code><code><font
color="#cc0000">|</font></code><code> run</code><code><font
color="#cc0000">)</font></code><code> to</code><code></code><code> <font
color="#cc0000">;</font></code><br>
<br>
<br>
is translated into:<br>
<br>
<code><font color="#996633"> S</font> <font color="#cc0000">::=</font>
walk through </code><code><font color="#cc0000">|</font></code><code>
pass through<br>
</code><code><font color="#cc0000">|</font></code><code> look
at<br>
</code><code><font color="#cc0000">|</font></code><code> </code><code></code><code>go
to </code><code><font color="#cc0000">|</font></code><code> come to </code><code><font
color="#cc0000">|</font></code><code> move to </code><code><font
color="#cc0000">|</font></code><code> link to </code><code><font
color="#cc0000">|</font></code><code> run</code><code></code><code> to</code><code></code><code>
<font color="#cc0000">;</font></code><br>
<br>
<br>
that is what one would expect: a flat series of productions.<br>
<br>
A more complex example could be:<br>
<br>
<code><font color="#996633">Digit</font> <font color="#cc0000">::=</font>
<font color="#3333ff">z:</font> 0 <font color="#cc0000">|</font> <font
color="#3333ff">nz:</font> <font color="#cc0000">>(</font></code><code>1
<font color="#cc0000">|</font> 2 <font color="#cc0000">|</font> 3 <font
color="#cc0000">|</font> 4 <font color="#cc0000">|</font> 5 <font
color="#cc0000">|</font> 6 <font color="#cc0000">|</font> 7 <font
color="#cc0000">|</font> 8 <font color="#cc0000">|</font> 9<font
color="#cc0000">) ;</font></code><br>
<br>
is translated into:<br>
<br>
<code><font color="#996633">Digit</font> <font color="#cc0000">::=</font>
<font color="#3333ff">z:</font> 0 <font color="#cc0000">|</font> <font
color="#3333ff">nz:</font> </code><code>1 <font color="#cc0000">|</font>
</code><code><font color="#3333ff">nz:</font> </code><code>2 <font
color="#cc0000">|</font> </code><code><font color="#3333ff">nz:</font> </code><code>3
<font color="#cc0000">|</font> </code><code><font color="#3333ff">nz:</font>
</code><code>4 <font color="#cc0000">|</font> </code><code><font
color="#3333ff">nz:</font> </code><code>5 <font color="#cc0000">|</font>
</code><code><font color="#3333ff">nz:</font> </code><code>6<br>
<font color="#cc0000">| </font> </code><code><font
color="#3333ff">nz:</font> </code><code>7 <font color="#cc0000">|</font>
</code><code><font color="#3333ff">nz:</font> </code><code>8 <font
color="#cc0000">|</font> </code><code><font color="#3333ff">nz:</font> </code><code>9<font
color="#cc0000"> ;</font></code><br>
<br>
<br>
<h4><a name="2.0.4.3_Di_sottoproduzioni_opzionali"></a> 2.0.4.3 Optional
subproductions</h4>
A subproduction in square brackets (see section <a
href="#1.0.2_Sottoproduzioni_opzionali">1.0.2</a>) is equal to a subproduction
in round brackets that produces either the original content or <b>epsilon</b>
(see the example in section <a
href="#2.1.3_Controllo_della_probabilt%E0_di_una">2.1.3</a>).<br>
Thus, <b>unfolding</b> an optional subproduction is perfectly legal and
the result is analogous to what said in section <a
href="#2.0.4.2_Di_sottoproduzioni">2.0.4.2</a>.<br>
<br>
<br>
<h4><a name="2.0.4.4_Di_sottoproduzioni_permutabili"></a> 2.0.4.4 Permutable
subproductions</h4>
As the translation rules in section <a
href="#4.1.5_Regole_di_traduzione">4.1.5</a> reveal, the unfolding is performed
by the preprocessor after all the permutations (see section <a
href="#2.0.7_Permutazioni">2.0.7</a>) occured: a permutable subproduction
bound to a <font color="#cc0000"><code>></code></font> operator is therefore
first permutated, while the <b>unfolding</b> holds and is then performed
at the new position within the sequence.<br>
<br>
<samp><b>EXAMPLE</b></samp><br>
<br>
<code><font color="#996633"> S</font> <font
color="#cc0000">::=</font> <font color="#cc0000">>{</font>the <font
color="#cc0000">>(</font>dog <font color="#cc0000">|</font> cat<font
color="#cc0000">)}</font> and </code><code><font color="#cc0000">{</font></code><code>a
</code><code><font color="#cc0000">(</font></code><code>fish </code><code><font
color="#cc0000">|</font></code><code> bull</code><code><font
color="#cc0000">)}</font></code><code> <font color="#cc0000">;</font></code><br>
<br>
<br>
Pay attention to how the two unfoldings, the former inside the curly
brackets and the latter outside, behave: the translation is as follows:<br>
<br>
<code><font color="#996633"> S</font> <font color="#cc0000">::=</font>
the dog and a </code><code><font color="#cc0000">(</font></code><code>fish
</code><code><font color="#cc0000">|</font></code><code> bull</code><code><font
color="#cc0000">)</font></code><br>
<code> </code><code><font color="#cc0000">|</font></code><code> the
cat and a </code><code><font color="#cc0000">(</font></code><code>fish </code><code><font
color="#cc0000">|</font></code><code> bull</code><code><font
color="#cc0000">)</font></code><br>
<code> </code><code><font color="#cc0000">|</font></code><code> <code>a </code><code><font
color="#cc0000">(</font></code><code>fish </code><code><font
color="#cc0000">|</font></code><code> bull</code><code><font
color="#cc0000">)</font></code></code><code><font color="#cc0000"></font></code><code>
and the dog<br>
</code><code><font color="#cc0000">|</font></code><code> <code>a </code><code><font
color="#cc0000">(</font></code><code>fish </code><code><font
color="#cc0000">|</font></code><code> bull</code><code><font
color="#cc0000">)</font></code></code><code><font color="#cc0000"></font></code><code>
and the cat </code><code><font color="#cc0000">;</font></code><code> </code><br>
<br>
<br>
<h4><a name="2.0.4.5_Di_sottoproduzioni_soggette"></a> 2.0.4.5 Deeply unfolded
subproductions</h4>
As stated in section <a href="#2.0.8_Unfolding_in_profondit%E0">2.0.8</a>,
deep unfolding leads to a subproduction where everything has been flattened
within.<br>
Though, one may sometimes wish to perform a further <b>unfolding</b>:
of that very subproduction.<br>
<br>
<samp><b>EXAMPLE</b></samp><br>
<br>
<code><font color="#996633"> S</font> <font
color="#cc0000">::=</font> </code><code></code><code> <font
color="#cc0000">> >></font> the </code><code><font
color="#cc0000">(</font></code><code>dog </code><code><font
color="#cc0000">|</font></code><code> cat</code><code><font
color="#cc0000">)</font></code><code><font color="#cc0000"> | </font>a<font
color="#cc0000"> (</font>fish<font color="#cc0000"> | </font>bull<font
color="#cc0000">) << | </font>an alligator<font color="#cc0000"> ;</font></code><br>
<br>
<br>
that is translated into:<br>
<br>
<code><font color="#996633"> S</font> <font color="#cc0000">::=</font>
the dog </code><code><font color="#cc0000">|</font></code><code> the cat
</code><code><font color="#cc0000">|</font></code><code> a fish </code><code><font
color="#cc0000">|</font></code><code> a bull </code><code><font
color="#cc0000">|</font></code><code> an alligator </code><code><font
color="#cc0000">;</font></code><br>
<br>
<br>
<br>
<br>
<h3><a name="2.0.5_Attributi"></a> 2.0.5 Attributes<br>
</h3>
<h4><a name="2.0.5.1_Etichette_e_selezione"></a> 2.0.5.1 Labels and selection<br>
</h4>
Any (sub)production, however nested, can be bound to a label and it
is eventually possible to limit generation to a subset of a series of productions
by using the <b>dot</b> operator.<br>
<br>
<samp><b>EXAMPLE</b></samp><br>
<br>
<code><font color="#996633"> S</font> <font
color="#cc0000">::=</font> <font color="#996633">Verb</font><font
color="#339999">.inf</font> <font color="#cc0000">| </font><font
color="#996633">Verb</font><font color="#339999">.ing</font> <font
color="#cc0000">;</font><br>
<br>
<font color="#996633">Verb</font><font
color="#cc0000"> ::=</font> <font color="#cc0000">(</font><font
color="#3333ff">inf:</font> to<font color="#cc0000">) (</font>eat <font
color="#cc0000">|</font> drink <font color="#cc0000">|</font> jump<font
color="#cc0000">) (</font><font color="#3333ff">ing:</font> <font
color="#cc0000">^</font>ing<font color="#cc0000">) ;</font><br>
<br>
</code> <br>
<samp><b>PRODUCES</b></samp><br>
<br>
<code>to eat<br>
to drink<br>
to jump<br>
eating<br>
drinking<br>
jumping<br>
</code><code><br>
</code> <br>
Selection simply deletes all (sub)productions bound to a label other
than the one selected. More precisely, a selection propagates the label
specified on the right hand of the dot operator for the whole generation
of what stands on the left of it; during the generation will be considered
as valid both those (sub)productions that are bound to no label and those
bound to a label that has been selected.<br>
Notice therefore that you're allowed to use selection many times
in order to enrich the list of selected labels: such a technique may be
useful for propagating some attributes that are wanted to affect generation.<br>
<br>
<samp><b>EXAMPLE</b></samp><br>
<br>
<code><font color="#996633"> S</font> <font
color="#cc0000">::=</font> <font color="#cc0000">(</font><font
color="#996633">Conjug</font><font color="#339999">.S</font> <font
color="#cc0000">|</font> <font color="#996633">Conjug</font><font
color="#339999">.P</font><font color="#cc0000">)</font><font
color="#339999">.sp</font> <font color="#cc0000">|</font> </code><code><font
color="#cc0000">(</font><font color="#996633">Conjug</font><font
color="#339999">.S</font> <font color="#cc0000">|</font> <font
color="#996633">Conjug</font><font color="#339999">.P</font><font
color="#cc0000">)</font><font color="#339999">.pp</font></code><code> <font
color="#cc0000">;</font><br>
<br>
<font color="#996633">Conjug</font> <font
color="#cc0000">::=</font> <font color="#cc0000">(</font><font
color="#996633">Pronoun</font> <font color="#996633">Verb</font><font
color="#cc0000">)</font><font color="#339999">.1</font> <font
color="#cc0000">|</font> </code><code><font color="#cc0000">(</font><font
color="#996633">Pronoun</font> <font color="#996633">Verb</font><font
color="#cc0000">)</font><font color="#339999">.2</font> <font
color="#cc0000">|</font></code> <code><font color="#cc0000">(</font><font
color="#996633">Pronoun</font> <font color="#996633">Verb</font><font
color="#cc0000">)</font><font color="#339999">.3 </font></code><code><font
color="#cc0000">;</font><br>
<br>
<font color="#996633">Pronoun</font> <font
color="#cc0000">::=</font> <font color="#3333ff">S:</font> <font
color="#cc0000">(</font><font color="#3333ff">1:</font> "I" <font
color="#cc0000">|</font> <font color="#3333ff">2:</font> you <font
color="#cc0000">|</font> <font color="#3333ff">3:</font> <font
color="#cc0000">(</font>he <font color="#cc0000">|</font> she <font
color="#cc0000">|</font> it<font color="#cc0000">)</font><font
color="#cc0000">)</font><br>
<font color="#cc0000"> | </font>
<font color="#3333ff">P:</font> </code><code><font color="#cc0000">(</font><font
color="#3333ff">1:</font> we <font color="#cc0000">|</font> <font
color="#3333ff">2:</font> you <font color="#cc0000">|</font> <font
color="#3333ff">3:</font> they<font color="#cc0000">)</font></code><code>
<font color="#cc0000">;</font><br>
<br>
<font color="#996633">Verb</font> <font
color="#cc0000">::=</font> <font color="#cc0000">(</font><font
color="#3333ff">pp:</font> <font color="#996633">Be</font><font
color="#cc0000">)</font><font color="#cc0000"> (</font>eat <font
color="#cc0000">|</font> drink<font color="#cc0000">) (</font><font
color="#3333ff">sp:</font> </code><code><font color="#cc0000">(</font><font
color="#3333ff">S:</font> (<font color="#3333ff">3:</font> <font
color="#cc0000">^</font>s<font color="#cc0000">))</font> <font
color="#cc0000">|</font> <font color="#3333ff">pp:</font> <font
color="#cc0000">^</font>ing<font color="#cc0000">) ;</font></code><code><font
color="#cc0000"></font><br>
<br>
<font color="#996633">Be</font> <font
color="#cc0000">::=</font> <font color="#3333ff">S:</font> <font
color="#cc0000">(</font><font color="#3333ff">1:</font> am <font
color="#cc0000">|</font> <font color="#3333ff">2:</font> are <font
color="#cc0000">|</font> <font color="#3333ff">3:</font> is<font
color="#cc0000">)</font> <font color="#cc0000">|</font> <font
color="#3333ff">P:</font> are <font color="#cc0000">;</font> </code>
<br>
<br>
<br>
<samp><b>PRODUCES</b></samp><br>
<br>
<code>I eat<br>
you eat<br>
he eats<br>
she eats<br>
it eats<br>
we eat<br>
they eat<br>
I am eating<br>
you are eating<br>
he is eating<br>
we are eating</code><code><br>
<br>
</code> etc.<br>
<br>
<br>
In the example above, assuming labels <font color="#3333ff"><code>1,2,3,S</code></font>
and <font color="#3333ff"><code>P</code></font> respectively identify
syntactical forms for the first, second and third persons, singular and
plural, we managed to correctly conjugate both simple present and present
progressive tenses according to a pronoun.<br>
Notice that whenever you decide to extend the set of verbs, you'll
just need to add more radixes in the proper subproduction of <font
color="#996633"><code>Verb</code></font>.<br>
<br>
<br>
<h4><a name="2.0.5.2_Selezione_multipla"></a> 2.0.5.2 Multiple selection<br>
</h4>
Reconsider the example in seciton <a
href="#2.0.5.1_Etichette_e_selezione">2.0.5.1</a>: the definition of the
non-terminal <code><font color="#996633">S</font> </code>simply activates
all combos of label pairs <code> <font color="#3333ff">S,P</font></code>
and <code><font color="#3333ff">sp,pp</font></code> for the production
of <font color="#996633"><code>Conjug</code></font>. In order to avoid
such frequent uncomfortable solutions you're allowed to specifiy, on the
right of the <b>dot</b> operator, a set of labels in round brackets interleaved
by the <b>pipe</b> keyword.<br>
Modifying the example above:<br>
<br>
<samp><b>EXAMPLE</b></samp><br>
<br>
<code><font color="#996633"> S</font> <font
color="#cc0000">::=</font> <font color="#996633">Conjug</font><font
color="#339999">.(S</font><font color="#339999">|P)</font><font
color="#339999">.(sp|pp)</font> <font color="#cc0000">;</font></code><br>
<br>
<br>
Analogously to what stated in section <a
href="#2.0.3_Controllo_della_probabilit%E0_di_una">2.0.3</a> for grammar
productions, it is possible to specify probablity modifiers for labels
too, by means of the <code><font color="#cc0000">+</font> </code>and<code>
<font color="#cc0000">-</font></code> keywords.<br>
<br>
<samp><b>EXAMPLE</b></samp><br>
<br>
<code><font color="#996633"> S</font> <font
color="#cc0000">::=</font> <font color="#996633">Ogg</font><font
color="#339999">.(+S</font><font color="#339999">|--P)</font><font
color="#339999">.(sp|-pp)</font> <font color="#cc0000">;</font></code><br>
<br>
<br>
That is internally treated as:<br>
<br>
<code><font color="#996633"> S</font> <font
color="#cc0000">::=</font> <font color="#cc0000">(</font><font
color="#996633">Conjug</font><font color="#339999">.S</font> <font
color="#cc0000">|</font> </code><code><font color="#996633">Conjug</font></code><code><font
color="#339999">.S</font> <font color="#cc0000">|</font></code><code> </code><code><font
color="#996633">Conjug</font></code><code><font color="#339999">.S</font>
<font color="#cc0000">|</font></code><code> <code><font
color="#996633">Conjug</font></code></code><code><font color="#339999">.S</font>
<font color="#cc0000">|</font></code><code> </code><code><font
color="#996633">Conjug</font></code><code><font color="#339999">.P</font><font
color="#cc0000">)</font><font color="#339999">.sp<br>
</font></code><code><font color="#cc0000"> </font></code><code><font
color="#cc0000">|</font></code><code><font color="#cc0000"> <code><font
color="#cc0000">(</font><font color="#996633">Conjug</font><font
color="#339999">.S</font> <font color="#cc0000">|</font> </code><code><font
color="#996633">Conjug</font></code><code><font color="#339999">.S</font>
<font color="#cc0000">|</font></code><code> </code><code><font
color="#996633">Conjug</font></code><code><font color="#339999">.S</font>
<font color="#cc0000">|</font></code><code> <code><font
color="#996633">Conjug</font></code></code><code><font color="#339999">.S</font>
<font color="#cc0000">|</font></code><code> </code><code><font
color="#996633">Conjug</font></code><code><font color="#339999">.P</font><font
color="#cc0000">)</font><font color="#339999">.sp</font></code></font></code><code><font
color="#339999"></font></code><br>
<code><font color="#cc0000"> |</font></code><code><font
color="#cc0000"> <code><font color="#cc0000">(</font><font
color="#996633">Conjug</font><font color="#339999">.S</font> <font
color="#cc0000">|</font> </code><code><font color="#996633">Conjug</font></code><code><font
color="#339999">.S</font> <font color="#cc0000">|</font></code><code> </code><code><font
color="#996633">Conjug</font></code><code><font color="#339999">.S</font>
<font color="#cc0000">|</font></code><code> <code><font
color="#996633">Conjug</font></code></code><code><font color="#339999">.S</font>
<font color="#cc0000">|</font></code><code> </code><code><font
color="#996633">Conjug</font></code><code><font color="#339999">.P</font><font
color="#cc0000">)</font><font color="#339999">.pp</font></code></font></code><code><font
color="#339999"></font></code><code> <font color="#cc0000">;</font></code><br>
<code><font color="#996633"> </font></code><br>
<br>
<br>
<h3><a name="2.0.6_Maiuscole"></a> 2.0.6 Capitalization</h3>
It is often needed, mainly for style purposes, to respect capitalization
rules, for instance after a point mark.<br>
Nevertheless, a complex grammar architecture, providing recursive productions
generating subclauses, may make such operation impossible, unless the user
rewrites part of the source.<br>
In order to solve this problem, the language provides the <b>backslash</b>
keyword <font color="#cc0000"><code>\</code></font>, which makes the program
perform the capitalization of the very following terminal symbol, i.e. switching
its first letter to uppercase.<br>
<br>
<samp><b>EXAMPLE</b></samp><br>
<br>
<code><font color="#996633"> S</font>
<font color="#cc0000">::=</font> <font color="#cc0000">\</font> smith <font
color="#cc0000">(</font>is <font color="#cc0000">|</font> "." <font
color="#cc0000">\)</font> <font color="#996633">Eulogy</font> </code><code><font
color="#cc0000">^</font> "."</code> <code><font color="#cc0000">;</font></code><br>
<code><br>
<font color="#996633">Eulogy </font></code><code><font
color="#cc0000">::=</font></code><code> rather a smart man <br>
</code><code><font color="#cc0000">|</font></code><code> really
a gentleman <font color="#cc0000">;</font></code><br>
<br>
<samp><b>PRODUCE</b></samp><br>
<br>
<code>Smith is rather a smart man.<br>
</code><code>Smith. Rather a smart man.</code><br>
<code>Smith is really a gentleman.<br>
</code><code>Smith. Really a gentleman.</code><br>
<code></code><br>
<br>
Keep in mind that capitalization is active until the following terminal
symbol resulting from the generation, therefore every other atom (epsilon,
concatenation or the capitalization operator itself) found in the middle
simply acts as usual.<br>
<br>
<samp><b>EXAMPLE</b></samp><br>
<br>
<code><font color="#996633"> S</font>
<font color="#cc0000">::=</font> a <font color="#cc0000">\ ^ \ _</font>
b</code><br>
<code><br>
<samp><b>PRODUCES</b></samp></code><code></code><br>
<br>
aB<br>
<br>
<br>
<br>
<h3><a name="2.0.7_Permutazioni"></a> 2.0.7 Permutation</h3>
Many spoken languages allow to change the order of some words (or groups
of words) in a sentence holding the original meaning; analogously, at a
macroscopic level, it sometimes makes sense to exchange the sentences of
a phrase.<br>
In order to avoid the user to rewrite the same sequence over and over
exchanging atom positions, specifying some subprodutions within <b>curly
brackets </b><code><font color="#cc0000">{</font> </code>and<code> <font
color="#cc0000">}</font></code>, the program automatically performs all
the permutations among them.<br>
<br>
<samp><b>EXAMPLE</b></samp><br>
<br>
<code><font color="#996633"> S</font>
<font color="#cc0000">::=</font> whether </code><code><font
color="#cc0000">{</font></code><code>is</code><code><font
color="#cc0000">}</font></code><code> </code><code><font
color="#cc0000">{</font></code><code>therefore</code><code><font
color="#cc0000">}</font></code><code> </code><code><font
color="#cc0000">{</font></code><code>he</code><code><font
color="#cc0000">}</font></code><code> <font color="#cc0000">;</font></code><br>
<code><br>
<samp><b>PRODUCES</b></samp></code><code></code><br>
<br>
whether is therefore he<br>
whether is he therefore<br>
whether therefore is he<br>
whether therefore he is<br>
whether he therefore is<br>
whether he is therefore<br>
<br>
<br>
Keep in mind that the permutability of a subproduction only holds within
the sequence containing it: no permutation occurs if permutable subproductions
are specified in different subsequences (or subprodutions - permutable
or not). See the difference in the two example that follow:<br>
<br>
<samp><b>EXAMPLE</b></samp><br>
<br>
<code><font color="#996633"> S</font>
<font color="#cc0000">::=</font> </code><code><font color="#cc0000">{</font></code><code>in
10 minutes</code><code><font color="#cc0000">}</font></code><code><font
color="#cc0000">^</font>, </code><code><font color="#cc0000">{</font></code><code>at
3 o'clock</code><code><font color="#cc0000">}^</font>,</code><code> </code><code><font
color="#cc0000">{</font>"I" <font color="#cc0000">{</font>will depart<font
color="#cc0000">} {</font></code><code>alone</code><code><font
color="#cc0000">}</font></code><code></code><code><font color="#cc0000">}</font></code><code>
<font color="#cc0000">;</font></code><br>
<code><br>
<samp><b>PRODUCES</b></samp></code><code></code><br>
<br>
in 10 minutes, at 3 o'clock, I will depart alone<br>
at 3 o'clock, in 10 minutes, I will depart alone<br>
in 10 minutes, I will depart alone, at 3 o'clock<br>
at 3 o'clock, I will depart alone, in 10 minutes<br>
I will depart alone, in 10 minutes, at 3 o'clock<br>
I will depart alone, at 3 o'clock, in 10 minutes<br>
in 10 minutes, at 3 o'clock, I alone will depart<br>
at 3 o'clock, in 10 minutes, I alone will depart<br>
in 10 minutes, I alone will depart, at 3 o'clock<br>
at 3 o'clock, I alone will depart, in 10 minutes<br>
I alone will depart, in 10 minutes, at 3 o'clock<br>
I alone will depart, at 3 o'clock, in 10 minutes<br>
<br>
<br>
<samp><b>EXAMPLE</b></samp><br>
<br>
<code><font color="#996633"> S</font>
<font color="#cc0000">::=</font> </code><code><font color="#cc0000">{</font></code><code>in
10 minutes</code><code><font color="#cc0000">}</font></code><code><font
color="#cc0000">^</font>, </code><code><font color="#cc0000">{</font></code><code>at
3 o'clock</code><code><font color="#cc0000">}^</font>,</code><code> </code><code><font
color="#cc0000">(</font><code>"I"</code><font color="#cc0000"><code> <font
color="#cc0000">{</font></code></font><code>will depart<font
color="#cc0000">}</font> <font color="#cc0000">{</font></code><font
color="#cc0000"><code></code></font><code>alone</code><code></code><font
color="#cc0000"><code><font color="#cc0000">}</font></code><code></code><code></code></font></code><code></code><code><font
color="#cc0000">)</font></code><code> <font color="#cc0000">;</font></code><br>
<code><br>
<samp><b>PRODUCES</b></samp></code><code></code><br>
<br>
in 10 minutes, at 3 o'clock, I will depart alone<br>
at 3 o'clock, in 10 minutes, I will depart alone<br>
in 10 minutes, at 3 o'clock, I alone will depart<br>
at 3 o'clock, in 10 minutes, I alone will depart<br>
<br>
<br>
<h3><a name="2.0.8_Unfolding_in_profondità"></a> 2.0.8 Deep unfolding</h3>
The language allows the deep unfolding of a subproduction specified in
reverse-doubleangle brackets <font color="#cc0000"><code>>></code></font>
and <font color="#cc0000"><code><<</code></font>: any atom, however
nested, for which the unfolding operation makes sense (see section <a
href="#2.0.4_Unfolding">2.0.4</a>) is unfolded. As a result, the complete
flattening of every subproduction and non-terminal symbol is done:<br>
<br>
<samp><b>EXAMPLE</b></samp><br>
<br>
<code><font color="#996633"> S</font>
<font color="#cc0000">::=</font> look at <font color="#cc0000">>></font>
</code><code><font color="#3333ff"><code></code><code></code></font><code>the</code><font
color="#3333ff"><code> </code><code><font color="#cc0000">(</font></code><code></code></font><code>dog</code><font
color="#3333ff"><code> <font color="#cc0000">|</font> </code><code><font
color="#cc0000">(</font></code></font><code></code><code></code><code>sorian</code><font
color="#3333ff"><code> </code><code><font color="#cc0000">|</font></code><code>
</code></font><code>persian</code><font color="#3333ff"><code><font
color="#cc0000">) </font></code></font><code></code><code>cat</code><font
color="#3333ff"><code></code><code></code><code></code><code><font
color="#cc0000">)</font></code><code></code><code></code><code></code></font></code><br>
<code> </code><code> </code><code><font color="#cc0000"> |</font></code><code>
a </code><code><font color="#cc0000">(</font></code><code></code><code>cow
</code><code><font color="#cc0000">|</font></code><code> bull </code><code><font
color="#cc0000">|</font></code><code> </code><code><font
color="#3333ff"><code></code></font></code><code><font color="#996633">Animal</font></code><code><font
color="#cc0000">)</font></code><code></code><code></code><code><br>
<font color="#cc0000"> <<</font> <font
color="#cc0000">;</font></code><br>
<code><br>
<font color="#996633">Animal</font> </code><code><font
color="#cc0000">::=</font></code><code> pig </code><code><font
color="#cc0000">|</font></code><code> </code><code></code><code></code><code></code><code></code><code></code><code></code><code><font
color="#cc0000">(</font></code><code>weird </code><code><font
color="#cc0000">|</font></code><code> ugly</code><code><font
color="#cc0000">)</font></code><code> chicken <font color="#cc0000">;</font></code><br>
<br>
<br>
<br>
The non-terminal <code><font color="#996633">S</font></code> is translated
into:<br>
<br>
<code><font color="#996633">S</font> <font color="#cc0000">::=</font>
look at </code><code><font color="#cc0000">(</font></code><code></code><code></code><code>
the dog<br>
</code><code><font color="#cc0000"> |</font></code><code> </code><code></code><code>the
</code><code><font color="#3333ff"><code></code></font><code></code><code>sorian</code><font
color="#3333ff"><code></code></font><font color="#3333ff"><code><font
color="#cc0000"> </font></code></font><code></code><code>cat</code></code><br>
<code><font color="#cc0000"> |</font></code><code> </code><code></code><code>the
persian</code><code><font color="#3333ff"><code></code></font><code></code><code></code><font
color="#3333ff"><code><font color="#cc0000"> </font></code></font><code></code><code>cat</code></code><br>
<code> </code><code><font color="#cc0000">|</font></code><code> </code><code></code><code>a
cow<br>
</code><code><font color="#cc0000"> |</font></code><code> </code><code></code><code>a
bull<br>
</code><code><font color="#cc0000"> |</font></code><code> </code><code></code><code>a
pig</code><code><font color="#3333ff"><code></code></font></code><code></code><br>
<code><font color="#cc0000"> |</font></code><code> </code><code></code><code>a
</code><code><font color="#3333ff"><code></code></font></code><code></code><code><font
color="#cc0000">(</font></code><code>weird </code><code><font
color="#cc0000">|</font></code><code> ugly</code><code><font
color="#cc0000">)</font></code><code> chicken</code><br>
<code></code> <code></code><code> </code><code></code><code><font
color="#cc0000">)</font></code><code> <font color="#cc0000">;</font></code><br>
<br>
<br>
Deeply unfolded subproductions are therefore translated into a subproduction
with everything has been recursively flattened in; exceptions are subproductions
bound to non-terminal symbols. The reason of this behaviour is dued to deep
unfolding being an operation which actually performs a simple unfolding of
every (sub)atom for which such operation makes sense: thus, while non-terminals
are unfolded, productions bound to them are left untouched. Even though such
a policy may seem unjustified at first, it rather allows the user to specify
any non-terminal symbol within a reverse-doubleangle subproduction without
unintentionally generating either a huge series of unfoldings or - even
worse - cyclic unfoldings (see section <a
href="#3.0.1.3_Unfolding_ricorsivi">3.0.1.3</a>).<br>
<br>
<br>
<br>
<h3><a name="2.0.9_Folding"></a> 2.0.9 Folding</h3>
Deep unfolding, as described in section <a
href="#2.0.8_Unfolding_in_profondit%E0">2.0.8</a>, may sometimes not be what
one wishes: on one hand, it would realistically be mostly used to avoid the
explicit specification of a <font color="#cc0000"><code>></code></font>
operator for every subproduction or non-terminal symbol within a given subproduction;
on the other hand, it still is sometimes impossible to perform a deep unfolding
of every (sub)atom without generating (unintentional) errors. The<i> PolyGen</i>
grammar definition language allows therefore the user to <b>lock</b> the
unfolding (of an atom for which such operation would make sense) by means
of the prefix operator <font color="#cc0000"><code><</code></font>.<br>
<br>
<samp><b>EXAMPLE</b></samp><br>
<br>
<code><font color="#996633"> S</font>
<font color="#cc0000">::=</font> look at <font color="#cc0000">>></font>
</code><code><font color="#3333ff"><code></code><code></code></font><code>the</code><font
color="#3333ff"><code> </code><code><font color="#cc0000">(</font></code><code></code></font><code>dog</code><font
color="#3333ff"><code> <font color="#cc0000">|</font> </code><code></code></font></code><font
color="#cc0000"><code><</code></font><code><font color="#3333ff"><code><font
color="#cc0000">(</font></code></font><code></code><code></code><code>sorian</code><font
color="#3333ff"><code> </code><code><font color="#cc0000">|</font></code><code>
</code></font><code>persian</code><font color="#3333ff"><code><font
color="#cc0000">) </font></code></font><code></code><code>cat</code><font
color="#3333ff"><code></code><code></code><code></code><code><font
color="#cc0000">)</font></code><code></code><code></code><code></code></font></code><br>
<code> </code><code> </code><code><font color="#cc0000"> |</font></code><code>
a </code><code><font color="#cc0000">(</font></code><code></code><code>cow
</code><code><font color="#cc0000">|</font></code><code> bull </code><code><font
color="#cc0000">| </font></code><font color="#cc0000"><code><</code></font><code><font
color="#3333ff"><code></code></font></code><code><font color="#996633">Animal</font></code><code><font
color="#cc0000">)</font></code><code></code><code></code><code><br>
<font color="#cc0000"> <<</font> <font
color="#cc0000">;</font></code><br>
<code><br>
<font color="#996633">Animal</font> </code><code><font
color="#cc0000">::=</font></code><code> pig </code><code><font
color="#cc0000">|</font></code><code> </code><code></code><code></code><code></code><code></code><code></code><code></code><code><font
color="#cc0000">(</font></code><code>weird </code><code><font
color="#cc0000">|</font></code><code> ugly</code><code><font
color="#cc0000">)</font></code><code> chicken <font color="#cc0000">;</font></code><br>
<br>
<br>
where the non-terminal <code><font color="#996633">S</font></code> is
translated into:<br>
<br>
<code><font color="#996633">S</font> <font color="#cc0000">::=</font>
look at </code><code><font color="#cc0000">(</font></code><code></code><code></code><code>
the dog<br>
</code><code><font color="#cc0000"> |</font></code><code> </code><code></code><code>the
</code><code><font color="#3333ff"><code><font color="#cc0000">(</font></code></font><code></code><code></code><code>sorian</code><font
color="#3333ff"><code> </code><code><font color="#cc0000">|</font></code><code>
</code></font><code>persian</code><font color="#3333ff"><code><font
color="#cc0000">)</font></code></font></code><code><code></code><font
color="#3333ff"><code></code></font><font color="#3333ff"><code><font
color="#cc0000"> </font></code></font><code></code><code>cat</code></code><code></code><br>
<code> </code><code><font color="#cc0000">|</font></code><code> </code><code></code><code>a
cow<br>
</code><code><font color="#cc0000"> |</font></code><code> </code><code></code><code>a
bull<br>
</code><code><font color="#cc0000"> |</font></code><code> </code><code></code><code>a </code><code><font
color="#996633">Animal</font></code><code><font color="#3333ff"><code></code></font></code><code></code><code></code><br>
<code></code> <code></code><code> </code><code></code><code><font
color="#cc0000">)</font></code><code> <font color="#cc0000">;</font></code><br>
<br>
Keep in mind that folding an unfolded atom and viceversa are syntax errors
- see section <a href="#4.1.1_Sintassi_concreta">4.1.1</a>.<br>
<br>
<br>
<br>
<br>
<br>
<h2><a name="2.1_Tecniche_avanzate"></a>2.1 Advanced techniques<br>
</h2>
<h3><a name="2.1.1_Ricorsione"></a>2.1.1 Recursion<br>
</h3>
It is perfectly legal for you to specify in a production the non-terminal
symbol you're defining, in order to make <i>PolyGen</i> recur:<br>
<br>
<samp><b>EXAMPLE</b></samp><br>
<br>
<code><font color="#996633"> S</font> <font
color="#cc0000">::=</font> <font color="#996633">Digit</font> <font
color="#cc0000">[^</font><font color="#996633"> S</font><font
color="#cc0000">] ;</font><br>
<br>
<font color="#996633">Digit</font> <font
color="#cc0000">::=</font> 0 <font color="#cc0000">|</font> 1 <font
color="#cc0000">|</font> 2 <font color="#cc0000">|</font> 3 <font
color="#cc0000">|</font> 4 <font color="#cc0000">|</font> 5 <font
color="#cc0000">|</font> 6 <font color="#cc0000">|</font> 7 <font
color="#cc0000">|</font> 8 <font color="#cc0000">|</font> 9 <font
color="#cc0000">;</font><br>
<br>
</code> <br>
<samp><b>PRODUCES</b></samp><br>
<br>
<code> 0 <br>
23<br>
853211<br>
000000<br>
00011122335<br>
<br>
</code> etc.<br>
<br>
<br>
i.e. any natural number made up by a random number of digits randomly
chosen between 0 and 9.<br>
Keep in mind then that it is up to you providing a non-recursive
production somewhere in order to let the program stop recurring sooner
or later, otherwise a cyclic recursion error will be generated by the grammar
checker (see section <a href="#3.0.1.2_Ricorsioni_cicliche_e">3.0.1.2</a>).<br>
<br>
As an exercize, try to define a grammar for generating variably-lengthened
sentences obtained by recursively linking clauses.<br>
<br>
<br>
<br>
<h3><a name="2.1.2_Ragruppamento"></a> 2.1.2 Grouping<br>
</h3>
In order to gain control over the probability distribution in even
a more flexible way than how described in sections <a
href="#2.0.3_Controllo_della_probabilit%E0_di_una">2.0.3</a> and <a
href="#2.0.4_Unfolding">2.0.4</a>, proper usage of round brakets should
be considered:<br>
<br>
<samp><b>EXAMPLE</b></samp><br>
<br>
<code> <font color="#996633">S1</font> <font
color="#cc0000">::=</font> canarin <font color="#cc0000">|</font> cow <font
color="#cc0000">|</font> camel <font color="#cc0000">;</font><br>
<br>
<font color="#996633">S2</font> <font
color="#cc0000">::=</font> canarin <font color="#cc0000">|</font> <font
color="#cc0000">(</font>cow <font color="#cc0000">|</font> camel<font
color="#cc0000">) ;</font><br>
<br>
</code> <br>
<samp><b>PRODUCES</b></samp><br>
<br>
<code> canarin<br>
cow<br>
camel<br>
<br>
</code> <br>
Although <code><font color="#996633">S1</font></code> and <code><font
color="#996633">S2</font></code> outputs are equal, the probability distribution
for the former is:<br>
<br>
<table border="1" width="30%" cellpadding="2" cellspacing="2"
bgcolor="#cccccc">
<tbody>
<tr>
<td><code>cat</code><br>
</td>
<td>1/3</td>
</tr>
<tr>
<td><code>cow</code><br>
</td>
<td>1/3</td>
</tr>
<tr>
<td><code>camel</code></td>
<td>1/3</td>
</tr>
</tbody>
</table>
<br>
<br>
while for the latter:<br>
<br>
<table border="1" width="30%" cellpadding="2" cellspacing="2"
bgcolor="#cccccc">
<tbody>
<tr>
<td><code>cat</code></td>
<td> 1/2</td>
</tr>
<tr>
<td><code>cow</code> </td>
<td> 1/2 * 1/2 = 1/4</td>
</tr>
<tr>
<td><code>camel</code></td>
<td> 1/2 * 1/2 = 1/4</td>
</tr>
</tbody>
</table>
<br>
<br>
All this because the subproduction <code><font
color="#cc0000">(</font>cow <font color="#cc0000">|</font> camel<font
color="#cc0000">)</font></code> is interpreted someway as a whole block by
the program.<br>
<br>
<br>
<br>
<h3><a name="2.1.3_Controllo_della_probabiltà_di_una"></a> 2.1.3 Controlling
the probability of an optional subproduction</h3>
The grammar definition language interpreted by <i>PolyGen</i> does
not allow any control over the probability for an optional subproduction
to occur. In other words, there is no <b>plus</b>- or <b>minus</b>-like
operator for subproductions in square brackets.<br>
Nevertheless there exists a simple technique to get this result:<br>
<br>
<samp><b>EXAMPLE</b></samp><br>
<br>
<code><font color="#996633"> S</font> <font
color="#cc0000">::=</font> a <font color="#cc0000">(+ _ |</font> beautiful<font
color="#cc0000">)</font> house <font color="#cc0000">;</font><br>
<br>
</code> <br>
<samp><b>PRODUCE</b></samp><br>
<br>
<code> a house<br>
a beautiful house<br>
<br>
</code> <br>
Being an optional subproduction equivalent to a non-optional one
generating either a given output or epsilon (see section <a
href="#2.0.2_Epsilon">2.0.2</a>), it is possible to make this translation
by hand and eventually put plus and minus operators.<br>
In the former example, the probability for nothing to be produced
is greater than the probability for <code>beautiful.</code><br>
<br>
<br>
<br>
<h3><a name="2.1.4_Reset_di_una_selezione"></a> 2.1.4 Selection reset<br>
</h3>
Keep in mind that the selection operator adds the specified label
to the set of already active ones; this leads to the need to someway
manually reset such set. For instance, let generate natural numbers (included
zero) of arbitrary length without any non-significative zero:<br>
<br>
<samp><b>EXAMPLE</b></samp><br>
<br>
<code><font color="#996633"> S</font> <font
color="#cc0000">::=</font> <font color="#996633">Digit</font> <font
color="#cc0000">|</font> <font color="#996633">S</font><font
color="#339999">.nz</font> <font color="#cc0000">[^ </font><font
color="#996633">S</font><font color="#339999">.</font><font
color="#cc0000">] ;</font><br>
<br>
<font color="#996633">Digit</font> <font
color="#cc0000">::=</font> <font color="#3333ff">z:</font> 0 <font
color="#cc0000">|</font> <font color="#3333ff">nz:</font> <font
color="#cc0000">{</font></code><code>1 <font color="#cc0000">|</font> 2
<font color="#cc0000">|</font> 3 <font color="#cc0000">|</font> 4 <font
color="#cc0000">|</font> 5 <font color="#cc0000">|</font> 6 <font
color="#cc0000">|</font> 7 <font color="#cc0000">|</font> 8 <font
color="#cc0000">|</font> 9<font color="#cc0000">} ;</font></code><br>
<code> <br>
</code> <br>
<samp><b>PRODUCES</b></samp><br>
<br>
<code> 0<br>
1<br>
23<br>
23081993<br>
112358<br>
20020723<br>
<br>
</code> ecc.<br>
<br>
The dot operator followed by no label resets the set of active selections
at the time it is encountered during generation; in other words, it stops
propagation of labels selected that far.<br>
<br>
<br>
<br>
<h2><a name="3.0_Controllo_statico_di_una_grammatica"></a> 3.0 Static checking
of grammars<br>
</h2>
<i>PolyGen</i> features a powerful algorithm performing a static
checking of a source file: it is therefore able to verify the correctness
of a whole grammar in finite time despite its complexity.<br>
A grammar source succeding the checking phase is guaranteed to always
generate a valid output - as kind of a soundness.<br>
Thus, since the checking phase always precedes generation, if the
program outputs with no error messages, then the grammar is entirely
correct.<br>
<br>
Where specified within the message generated by the program, warnings and
errors refer to a source text file area between two pairs of coordinates
showing a line number and a column number.<br>
<br>
<br>
<h3><a name="3.0.1_Errori"></a> 3.0.1 Errors<br>
</h3>
Errors are classified as cases that break the grammar correctness
definition.<br>
An error halts the program execution.<br>
<br>
<h4><a name="3.0.1.1_Inesistenza_di_simboli_non"></a> 3.0.1.1 Undefined non-terminal
symbols<br>
</h4>
Each non-terminal symbol appearing in the right-hand of a definition
is checked for actually existence in order to avoid usage of non-terminal
symbols that have not been defined.<br>
<br>
<samp><b>EXAMPLE</b></samp><br>
<br>
<code><font color="#996633"> S</font> <font
color="#cc0000">::=</font> <font color="#996633">A</font> <font
color="#cc0000">|</font> <font color="#996633">B</font> <font
color="#cc0000">;</font><br>
<font color="#996633"> A</font> <font
color="#cc0000">::=</font> a <font color="#cc0000">;</font><br>
<br>
</code> <br>
Such grammar generates an error message, since <font
color="#996633"><code>B</code></font> is not defined.<br>
<br>
<br>
<h4><a name="3.0.1.2_Ricorsioni_cicliche_e"></a> 3.0.1.2 Cyclic recursions
and non-termination<br>
</h4>
The checking algorithm is able to verify each non-terminal symbol
to possibly produce an output, i.e. - in other words - that the generation
will actually terminate without an infinite recursion.<br>
<br>
<samp><b>EXAMPLE</b></samp><br>
<br>
<code><font color="#996633"> S <font
color="#cc0000">::=</font> S <font color="#cc0000">|</font> A <font
color="#cc0000">;</font><br>
A <font color="#cc0000">::=</font> B <font
color="#cc0000">;</font><br>
B <font color="#cc0000">::=</font> S <font
color="#cc0000">| </font>A <font color="#cc0000">;</font></font><br>
<br>
</code> <br>
This grammar could never produce any output, since generation, despite
any starting non-terminal symbol, would loop forever.<br>
Other, more tricky, cases may lead to such a subcycle - kind of a circuit:<br>
<br>
<code><font color="#996633"> S <font color="#cc0000">::=</font> </font>a<font
color="#996633"> <font color="#cc0000">|</font> A <font color="#cc0000">;</font><br>
A <font color="#cc0000">::=</font> B
<font color="#cc0000">;</font><br>
B <font color="#cc0000">::=</font> A
<font color="#cc0000">;</font></font></code><br>
<br>
<br>
Although here generation may not lead to a cyclic recursion thanks to the
terminal <code>a</code>, it is still possible for a non-terminating path
to be entered: such cases are therefore signaled by an error message too.<br>
<br>
<br>
<h4><a name="3.0.1.3_Unfolding_ricorsivi"></a> 3.0.1.3 Recursive unfoldings</h4>
You're not allowed to prefix the unfolding operator <font
color="#cc0000"><code>></code></font> (see section <a
href="#2.0.4.1_Di_simboli_non_terminali">2.0.4.1</a>) to a non-terminal
symbol that would cause a cyclic recursion.<br>
<br>
<samp><b>EXAMPLE</b></samp><br>
<br>
<code><font color="#cc0000"><font color="#996633">
S</font> ::= ><font color="#996633">A</font> ;<br>
<font color="#996633"> A</font> ::= ><font
color="#996633">B</font> ;<br>
<font color="#996633"> B</font> ::= ><font
color="#996633">S</font> ;</font><br>
<br>
</code> <br>
Such grammar would lead to an unfolding loop that would expand it
infinitely and it therefore generates an error message.<br>
<br>
<br>
<h4><a name="3.0.1.4_Epsilon-produzioni"></a> 3.0.1.4 Epsilon-productions</h4>
A grammar may satisfy the termination clause thanks to an epsilon-production
(see section <a href="#2.0.2_Epsilon">2.0.2</a>). In such case the grammar
is considered to be correct, still it possibly produces an empty output.<br>
<br>
<samp><b>EXAMPLE</b></samp><br>
<br>
<code><font color="#996633"> S</font> <font
color="#cc0000">::=</font> <font color="#996633">A</font><font
color="#339999">.3</font> <font color="#cc0000">;</font><br>
<br>
<font color="#996633"> A</font> <font
color="#cc0000">::=</font> <font color="#3333ff">1:</font> a <font
color="#cc0000">|</font> <font color="#3333ff">2:</font> b <font
color="#cc0000">;</font><br>
<br>
</code> <br>
<samp><b>PRODUCES</b></samp><br>
<br>
<code><font color="#cc0000"> _</font><br>
<br>
</code> <br>
A destructive selection is not an error itself, since in some situations
it might be exactly one's will (see section <a
href="#3.0.2.2_Potenziali_epsilon-produzioni">3.0.2.2</a>); nevertheless
all cases where generation would lead to just epsilon-productions are
notified by an error message.<br>
<br>
<br>
<h4><a name="3.0.1.5_Ridefinizione_di_simboli_non_terminali"></a> 3.0.1.5
Overriding of non-terminal symbols<br>
</h4>
A grammar is verified to not define the same non-terminal symbol
more than once.<br>
<br>
<samp><b>EXAMPLE</b></samp><br>
<br>
<code><font color="#996633"> A</font> <font
color="#cc0000">::=</font> apple <font color="#cc0000">|</font> orange <font
color="#cc0000">|</font> banana <font color="#cc0000">;</font><br>
<font color="#996633"> <br>
A</font> <font color="#cc0000">::=</font> mandarin <font
color="#cc0000">|</font> melon <font color="#cc0000">;</font><br>
<br>
</code><br>
Such grammar leads to an error since <font color="#996633"><code>A</code></font>
is defined twice.<br>
<br>
<br>
<h4><a name="3.0.1.6_Carattere_sconosciuto"></a> 3.0.1.6 Illegal character</h4>
Properly an error generated by the lexer in case a character not belonging
to any known token (i.e. not defined by the lexical rules in section <a
href="#4.1.3_Regole_lessicali">4.1.3</a>) has been detected during the syntactical
analisis phase of a source file.<br>
<br>
<br>
<br>
<h4><a name="3.0.1.7_Token_inaspettato"></a> 3.0.1.7 Unexpected token</h4>
An error generated by the parser in case a valid token in a wrong position
has been detected during the syntactical analisis phase of a source file,
leading to the breaking of the syntactical rules in section <a
href="#4.1.1_Sintassi_concreta">4.1.1</a>.<br>
<br>
<br>
<br>
<br>
<h3><a name="3.0.2_Warning"></a> 3.0.2 Warnings<br>
</h3>
Warnings are classified as cases that do not break the grammar correctness
definition, still they may lead to unexpected results.<br>
Warning messages thus mean not the grammar source to be uncorrect,
indeed not robust.<br>
A warning does not halt the program execution.<br>
<br>
Warnings are divided into levels, depending on their gravity: the lower a
level, the more urgent the warnings grouped within; level 0 contains warnings
that cannot be ignored (still not being dangerous for the generation).<br>
<br>
<h4><a name="3.0.2.0_Livello_0"></a> 3.0.2.0 Level 0</h4>
There exists no warning within this group, by now.<br>
<br>
<h4><a name="3.0.2.0_Livello_1"></a> 3.0.2.1 Level 1</h4>
<h4><a name="3.0.2.1_Inesistenza_del_simbolo_I"></a> 3.0.2.1 Undefined symbol
<code>I</code><br>
</h4>
The lack of definition for the non-terminal symbol <code>I</code>
does not allow the usage of the program <code>-info</code> option.<br>
Such symbol typically specifies an information string for the grammar
(its author, title, etc.) and it is a good habit to follow such convention
by properly defining it, though it is actually not an error to omitt it.<br>
<br>
<h4> </h4>
<h4><a name="3.0.2.2_Potenziali_epsilon-produzioni"></a> 3.0.2.2 Potential
epsilon-productions<br>
</h4>
There exist cases of a grammar not always generating an epsilon
(see section <a href="#3.0.1.4_Epsilon-produzioni">3.0.1.4</a>), but
just possibly.<br>
<br>
<samp><b>EXAMPLE</b></samp><br>
<br>
<code><font color="#996633"> S</font> <font
color="#cc0000">::=</font> <font color="#996633">A</font><font
color="#339999">.3</font> <font color="#cc0000">|</font> c <font
color="#cc0000">;</font><br>
<br>
<font color="#996633"> A</font> <font
color="#cc0000">::=</font> <font color="#3333ff">1:</font> a <font
color="#cc0000">|</font> <font color="#3333ff">2:</font> b <font
color="#cc0000">;</font></code><code><br>
<br>
</code> <br>
<samp><b>PRODUCES</b></samp><br>
<br>
<code> c<br>
<font color="#cc0000"> _</font><br>
<br>
</code> <br>
Such case are not errors and are notified by a warning message.<br>
<br>
<br>
<h4><a name="3.0.2.0_Livello_2"></a> 3.0.2.1 Level 2</h4>
<h4><a name="3.0.2.2_Permutazione_inutile"></a> 3.0.2.3 Useless permutation</h4>
In case only one permutable subproduction appears within a sequence (see
section <a href="#2.0.7_Permutazioni">2.0.7</a>), no permutation is actually
performed for obvious reasons.<br>
<br>
<samp><b>EXAMPLE</b></samp><br>
<br>
<code><font color="#996633"> S</font>
<font color="#cc0000">::=</font> a <font color="#cc0000">{</font>b<font
color="#cc0000">}</font> c <font color="#cc0000">;</font></code><br>
<br>
<br>
Though such case actually is not an error, just a low-gravity warning
message is output.<br>
<br>
<br>
<h4><a name="3.0.2.2.2_Potenziale_ricorsione_ciclica"></a> 3.0.2.2.2 Potential
cyclic recursion</h4>
Recursion is rather a powerful and useful tool, probably quite frequently
used in complex grammars. Though all non-termination cases caused by a abuse
of recursion are trapped by the grammar checker (see section <a
href="#3.0.1.2_Ricorsioni_cicliche_e">3.0.1.2</a>), on the other hand, formally
legal recursions may be enough tangled to slow generation down for a sensible
amount.<br>
Every single recursion case may therefore be signaled a low-gravity warning,
somehow in order to aid the user at localizing unwanted recursions.<br>
<br>
<br>
<br>
<h2><a name="4.0_Appendice"></a> 4.0 Appendix</h2>
<h3><br>
</h3>
<h3><a name="4.1.1_Sintassi_concreta"></a> 4.1.1 Concrete syntax<br>
</h3>
<i>Type-2</i> syntax (in <i>BNF</i> notation) of the grammar definition
language interpreted by <i>PolyGen</i> and described in this document
follows below.<br>
Non-terminal symbols bound to productions are capitalized; non-terminal
symbols bound to regular expressions begin with a capital letter (see
section <a href="#4.1.3_Regole_lessicali">4.1.3</a>); terminal symbols
are quoted;<code> S</code> is the starting non-terminal symbol.<br>
<br>
<br>
<code> S ::= DEF<br>
| DEF S<br>
<br>
DEF ::= Nonterm "::=" PRODS ";"<br>
<br>
PRODS ::= PROD<br>
| PROD "|" PRODS<br>
<br>
PROD ::= SEQ<br>
| MODIF SEQ<br>
<br>
MODIF ::= "+"<br>
| "-"<br>
| "+" MODIF<br>
| "-" MODIF<br>
<br>
LABELS ::= LABEL<br>
| LABEL "|" LABELS<br>
<br>
LABEL ::= Label<br>
| MODIF Label<br>
<br>
SEQ ::= ATOMS<br>
| Label ":" ATOMS<br>
<br>
ATOMS ::= ATOM<br>
| ATOM ATOMS<br>
<br>
ATOM ::= Term<br>
| "^"<br>
| "_"<br>
| "\"<br>
| UNFOLDABLE<br>
| ">" UNFOLDABLE<br>
| "<" UNFOLDABLE<br>
| ATOM "."<br>
| ATOM DotLabel<br>
| ATOM ".(" LABELS ")"</code><code><br>
<br>
UNFOLDABLE ::= Nonterm<br>
</code><code>| "(" PRODS ")"<br>
| "[" PRODS "]"<br>
| "{" PRODS "}"<br>
| ">>" PRODS "<<"</code><code><br>
<br>
</code> <br>
<br>
<h3><a name="4.1.2_Sintassi_astratta"></a> 4.1.2 Abstract syntax<br>
</h3>
For the sake of completeness, the abstract syntax of the language
interpreted by <i>PolyGen</i> follows cleared from syntactical sugars
and terms involved in preprocessing only.<br>
<br>
<br>
<code> S ::= DEF<br>
| DEF S<br>
<br>
DEF ::= Nonterm "::=" PRODS ";"<br>
<br>
PRODS ::= SEQ<br>
| SEQ "|" PRODS<br>
<br>
SEQ ::= ATOMS<br>
| Label ":" ATOMS<br>
<br>
ATOMS ::= ATOM<br>
| ATOM ATOMS<br>
<br>
ATOM ::= Nonterm<br>
| Term<br>
| "^"<br>
| "_"<br>
| "(" PRODS ")"<br>
| ATOM "."<br>
| ATOM DotLabel</code><code><br>
</code><br>
<br>
<br>
<h3><a name="4.1.3_Regole_lessicali"></a> 4.1.3 Lexical rules<br>
</h3>
<i>Type-3</i> lexical rules (in regular expression notation) follow.<br>
<br>
<br>
<code> Term ::= [a-z 0-9 , '][a-z A-Z 0-9 , ']*<br>
| " [A-Z a-z 0-9 ( ) _ - ? . , ! : \ & # +
* / % $ � [ ] { } ~ @ ; : | < > = ^ ' \ "]* "<br>
<br>
Nonterm ::= [A-Z][A-Z a-z 0-9 _]*<br>
<br>
Label ::= [A-Z a-z 0-9 _]+<br>
<br>
DotLabel ::= . Label<br>
<br>
</code> <br>
Notice that the white space character can be quoted as a terminal
symbol too.<br>
<br>
<br>
<br>
<h3><a name="4.1.4_Caratteri_escape"></a> 4.1.4 Escape sequences<br>
</h3>
Regular expression <code>Nonterm</code> in section <a
href="#4.1.3_Regole_lessicali">4.1.3</a> recognizes the backslash character
within quotes. A terminal symbol is therefore allowed to contain any
escape sequence among the following:<br>
<br>
<br>
<table border="1" width="30%" cellpadding="2" cellspacing="2"
bgcolor="#cccccc">
<tbody>
<tr>
<td>\\</td>
<td>backslash</td>
</tr>
<tr>
<td>\"</td>
<td>quote<br>
</td>
</tr>
<tr>
<td>\n</td>
<td>new line</td>
</tr>
<tr>
<td>\r</td>
<td>carriage return</td>
</tr>
<tr>
<td>\b</td>
<td>backspace</td>
</tr>
<tr>
<td>\t</td>
<td>tab</td>
</tr>
<tr>
<td valign="top">\<i>xyz<code></code></i></td>
<td valign="top">ASCII decimal code<i> xyz<code></code></i><br>
</td>
</tr>
</tbody>
</table>
<br>
<br>
<br>
<br>
<h3><a name="4.1.5_Regole_di_traduzione"></a> 4.1.5 Translation rules</h3>
As a formal reference, translation rules from concrete syntax to abstract
syntax together with proper precedence (where the least number stands
for the highest priority) follow. They therefore refer to the operations
performed by either the parser (in case of syntactical sugars) or the preprocessor
(otherwise).<br>
<br>
<code><br>
</code>
<table cellpadding="2" cellspacing="2" border="1" width="100%">
<tbody>
<tr>
<td valign="top"><br>
</td>
<td valign="top" align="center"><b>concrete syntax</b><br>
</td>
<td valign="top" align="center"><b>abstract syntax</b><br>
</td>
</tr>
<tr>
<td valign="top"><br>
<b>1</b><br>
</td>
<td valign="top"><code><big>A<font color="#339999">.(</font></big></code><code><font
color="#cc0000">+</font></code><code><b><sup>(a<sub>1</sub>)</sup></b><font
color="#cc0000">-</font><b><sup>(b<sub>1</sub>)</sup></b></code><code></code><code><big><font
color="#339999">l<sub>1</sub>|...|</font></big></code><code><font
color="#cc0000">+</font><b><sup>(a<sub>n</sub>)</sup></b><font
color="#cc0000">-</font><b><sup>(b<sub>n</sub>)</sup></b></code><code></code><code><big><font
color="#339999">l<sub>n</sub>)</font></big></code><br>
</td>
<td valign="top"><code><big><font color="#cc0000">(</font>A<font
color="#339999">.l<sub>1</sub></font> </big></code><code><big><font
color="#cc0000">|</font></big></code><code><big><b><small><sub>(1)</sub></small></b>
... </big></code><code><big><font color="#cc0000">|</font></big></code><code><big><b><small><sub>(w</sub><sub>1)</sub></small></b></big></code><code><big>
</big></code><code><big>A<font color="#339999">.l<sub>1</sub></font></big></code><code><big>
</big></code><code><big><font color="#cc0000">|</font></big></code><code><big>
... <font color="#cc0000">|</font> A<font color="#339999">.l<sub>n</sub></font></big></code><code><big><font
color="#cc0000"> |</font></big></code><code><big><b><small><sub>(1)</sub></small></b>
... </big></code><code><big><font color="#cc0000">|</font></big></code><code><big><b><small><sub>(wn)</sub></small></b></big></code><code><big>
</big></code><code><big>A<font color="#339999">.l<sub>n</sub></font></big></code><code><big><font
color="#cc0000">)</font></big></code><br>
<br>
<code><big><i>where</i> <b>w<sub>i</sub> = a<sub>i</sub> -
b<sub>i</sub> - </b></big></code><code><big><b>min </b><b>{a<sub>1</sub>-b<sub>1</sub>
... </b></big></code><code><big><b>a<sub>n</sub>-b<sub>n</sub></b></big></code><code><big><b>}</b></big></code><br>
</td>
</tr>
<tr>
<td valign="top"><br>
<b>2</b><br>
</td>
<td valign="top"><code><font color="#cc0000">+</font><b><sup>(a<sub>1</sub>)</sup></b><font
color="#cc0000">-</font><b><sup>(b<sub>1</sub>) </sup></b></code><code></code><code><big>P<sub>1</sub></big><big><font
color="#cc0000"> |</font></big><big> ... </big><big><font
color="#cc0000">|</font></big></code><code><font color="#cc0000">+</font><b><sup>(a<sub>n</sub>)</sup></b><font
color="#cc0000">-</font><b><sup>(b<sub>n</sub>)</sup></b></code><code><big>
</big></code><code></code><code><big>P<sub>n</sub></big></code><br>
</td>
<td valign="top"><code><big>P<sub>1</sub> </big></code><code><big><font
color="#cc0000">|</font></big></code><code><big><b><small><sub>(1)</sub></small></b>
... </big></code><code><big><font color="#cc0000">|</font></big></code><code><big><b><small><sub>(w</sub><sub>1)</sub></small></b>
P<sub>1</sub> </big></code><code><big><font color="#cc0000">|</font></big></code><code><big>
... </big></code><code><big><font color="#cc0000">|</font></big></code><code><big>
P<sub>n</sub> </big></code><code><big><font color="#cc0000">|</font></big></code><code><big><b><small><sub>(1)</sub></small></b>
... </big></code><code><big><font color="#cc0000">|</font></big></code><code><big><b><small><sub>(wn)</sub></small></b>
P<sub>n</sub></big></code><code></code><br>
<br>
<code><big><i>where</i> <b>w<sub>i</sub> = a<sub>i</sub> -
b<sub>i</sub> - </b></big></code><code><big><b>min </b><b>{a<sub>1</sub>-b<sub>1</sub>
... </b></big></code><code><big><b>a<sub>n</sub>-b<sub>n</sub></b></big></code><code><big><b>}</b></big></code><br>
</td>
</tr>
<tr>
<td valign="top"><b>3</b><br>
</td>
<td valign="top"><code><big><font color="#cc0000">[</font></big></code><code><big>P</big></code><code></code><code><big><font
color="#cc0000">]</font></big></code><br>
</td>
<td valign="top"><code><big><font color="#cc0000">(</font><font
color="#cc0000">_ |</font> </big></code><code><big><font
color="#cc0000">(</font></big></code><code><big>P</big></code><code></code><code></code><code><big><font
color="#cc0000">))</font></big></code><br>
</td>
</tr>
<tr>
<td valign="top"><br>
<b>4</b><br>
</td>
<td valign="top"><code><big><font color="#cc0000">>></font></big></code><code></code><code></code><code><big>
P </big></code><code></code><code><big><font color="#cc0000"><<</font></big></code><code></code><code></code><code></code><br>
</td>
<td valign="top"><code><big><font color="#cc0000">(</font></big></code><code><big>P'</big></code><code></code><code></code><code><big><font
color="#cc0000">)</font></big></code><br>
<br>
<i><big><code>where P' is isomorph to P where <b>unfoldable</b>
atoms are unfolded</code></big></i> </td>
</tr>
<tr>
<td valign="top"><br>
<br>
<br>
<b>5</b><br>
</td>
<td valign="top"><code><big>P<sub>1</sub> <font
color="#cc0000">|</font> ...<font color="#cc0000"> |</font> </big></code><code><big>A<sub>1</sub></big></code><code><big>
<font color="#cc0000">{</font>Q<sub>1</sub><font color="#cc0000">}</font><font
color="#339999">.<small><code><big><font color="#339999"><small><code><big><font
color="#339999">l<sub>1</sub></font></big></code></small></font></big></code></small><code></code></font></big></code><code><big>
... </big></code><code><big>A<sub>n</sub></big></code><code><big> </big></code><code><big><font
color="#cc0000">{</font></big></code><code><big>Q</big></code><code><big><sub>n</sub></big></code><code><big><font
color="#cc0000">}</font><font color="#339999">.<code></code><small><code><big><font
color="#339999">l<sub>n</sub></font></big></code></small></font></big></code><code><big>
</big></code><code><big><font color="#cc0000">|</font></big></code><code><big>
... <font color="#cc0000">|</font> P<sub>n</sub></big></code><br>
</td>
<td valign="top"><code><big>P<sub>1</sub> <font
color="#cc0000">|</font> ...<font color="#cc0000"> |</font> A<sub>1</sub>
<font color="#cc0000">(</font>Q<sup>1</sup><sub>1</sub></big></code><code><big><font
color="#cc0000">)</font></big></code><code><big><font color="#339999">.<small><code><big><font
color="#339999">l<sub>1</sub></font></big></code></small></font></big></code><code><big>
... A<sub>n</sub> </big></code><code><big><font color="#cc0000">(</font></big></code><code><big>Q<sup>1</sup></big></code><code><big><sub>n</sub></big></code><code><big><font
color="#cc0000">)</font></big></code><code><big>.</big></code><code><big><font
color="#339999">l<sub>n</sub></font></big></code><code><big> </big></code><code></code><code></code><code></code><code><big><font
color="#cc0000"><br>
</font></big></code><code><big><font color="#cc0000">|</font> ...</big></code><code><big><font
color="#cc0000"> |</font> <small><code><big>A<sub>1</sub> <font
color="#cc0000">(</font>Q<sup>n!</sup><sub>n</sub></big></code><code><big><font
color="#cc0000">)</font></big></code><code><big><font color="#339999">.<small><code><big><font
color="#339999">l<sub>1</sub></font></big></code></small></font></big></code><code><big>
... A<sub>n</sub> </big></code><code><big><font color="#cc0000">(</font></big></code><code><big>Q<sup>n!</sup></big></code><code><big><sub>n</sub></big></code><code><big><font
color="#cc0000">)</font></big></code><code><big>.</big></code><code><big><font
color="#339999">l<sub>n</sub></font></big></code></small><code></code></big></code><code></code><code><big><font
color="#cc0000"> |</font></big></code><code><big> ... <font
color="#cc0000">|</font> P<sub>n</sub></big></code><br>
<br>
<big><code><i>where</i> </code><code><big>Q<sup>j</sup><sub>i</sub></big></code><code>
<i>is the </i></code><code>i-<i>th element of the </i></code><code>j-<i>th<b>
permutation<br>
</b>of</i> </code><code><big>Q<sub>1</sub></big>..</code><code></code><code><big>Q</big></code><code><big><sub>n</sub></big><i>(with
</i></code><code>i = 1..n, j = 1..n!<i>)</i></code></big> <br>
</td>
</tr>
<tr>
<td valign="top"><b>6</b><br>
</td>
<td valign="top"><code><big>P<sub>1</sub> <font
color="#cc0000">|</font> ... <font color="#cc0000">|</font> <font
color="#3333ff">L:</font> A <font color="#cc0000">>(</font>Q<sub>1</sub> <font
color="#cc0000">|</font> ... <font color="#cc0000">|</font> Q<sub>m</sub><font
color="#cc0000">)</font><font color="#339999">.l</font> B <font
color="#cc0000">|</font> ... <font color="#cc0000">|</font> P<sub>n</sub><br>
</big></code></td>
<td valign="top"><code><big>P<sub>1</sub> <font
color="#cc0000">|</font> ... <font color="#cc0000">|</font> <font
color="#3333ff">L:</font> A <font color="#cc0000">(</font>Q<sub>1</sub><font
color="#cc0000">)</font><font color="#339999">.l</font> B <font
color="#cc0000">|</font> ... <font color="#cc0000">|</font> <font
color="#3333ff">L:</font> A <font color="#cc0000">(</font>Q<sub>m</sub><font
color="#cc0000">)</font><font color="#339999">.l</font> B <font
color="#cc0000">|</font> ... <font color="#cc0000">|</font> P<sub>n</sub><br>
</big></code></td>
</tr>
<tr>
<td valign="top"><br>
<b>6</b><br>
</td>
<td valign="top"><code><big>P<sub>1</sub> <font
color="#cc0000">|</font> ... <font color="#cc0000">|</font> <font
color="#3333ff">L:</font> A <font color="#cc0000">></font><font
color="#996633">X</font><font color="#339999">.l</font> B <font
color="#cc0000">|</font> ... <font color="#cc0000">|</font> P<sub>n</sub><br>
<br>
<i>where</i> <font color="#996633">X</font> <font
color="#cc0000">::=</font> Q<sub>1</sub> <font color="#cc0000">|</font>
... <font color="#cc0000">|</font> Q<sub>m</sub><br>
</big></code></td>
<td valign="top"><code><big>P<sub>1</sub> <font
color="#cc0000">|</font> ... <font color="#cc0000">|</font> <font
color="#3333ff">L:</font> A <font color="#cc0000">(</font>Q<sub>1</sub><font
color="#cc0000">)</font><font color="#339999">.l</font> B <font
color="#cc0000">|</font> ... <font color="#cc0000">|</font> <font
color="#3333ff">L:</font> A <font color="#cc0000">(</font>Q<sub>m</sub><font
color="#cc0000">)</font><font color="#339999">.l</font> B <font
color="#cc0000">|</font> ... <font color="#cc0000">|</font> P<sub>n</sub><br>
</big></code></td>
</tr>
</tbody>
</table>
<code></code><br>
<br>
Where the following notational conventions hold:<br>
<br>
<br>
<code></code>
<table border="1" width="60%" cellpadding="2" cellspacing="2">
<tbody>
<tr>
<td><code><big>P</big></code><code>, </code><code><big>Q</big></code></td>
<td> productions or series of productions</td>
</tr>
<tr>
<td><big><code>A</code></big><code>,</code><big><code> B</code></big></td>
<td> atoms o atom (sub)sequences</td>
</tr>
<tr>
<td><code><big><font color="#3333ff">L</font></big></code><code>,</code><code><big><font
color="#339999"> l</font></big></code></td>
<td> labels</td>
</tr>
<tr>
<td valign="top"><code><big><font color="#996633">X</font></big></code><code>,</code><code><big><font
color="#996633"> Y</font></big></code><br>
</td>
<td valign="top">non-terminali symbols<br>
</td>
</tr>
<tr>
<td><code><font color="#cc0000">+</font><b><sup>(n)</sup></b><font
color="#cc0000">-</font><b><sup>(m)</sup></b></code> </td>
<td>juxtaposition of <b>n</b><code></code> and <b>m</b>, respectively<b>,</b>
<font color="#cc0000">+</font> and <code><font color="#cc0000">-</font></code>
operators<code></code></td>
</tr>
<tr>
<td><code><big>P</big></code><code><big><font
color="#cc0000"> |</font></big></code><code><big><b><small><sub>(1)</sub></small></b>
... </big></code><code><big><font color="#cc0000">|</font></big></code><code><big><b><small><sub>(n)</sub></small></b>
P</big></code> </td>
<td> <b>n</b>-lengthened series of productions P<code></code></td>
</tr>
</tbody>
</table>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
</body>
</html>
|