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
|
####################################################
# #
# *** WARNING *** #
# #
# This test will try to parse a full C++ grammar, #
# so it will use a huge ammount of CPU and memory. #
# #
# So, be patient, specially for test #2... #
# #
####################################################
$^W=0;
# Before `make install' is performed this script should be runnable with
# `make test'. After `make install' it should work as `perl test.pl'
######################### We start with some black magic to print on failure.
# Change 1..1 below to 1..last_test_to_print .
# (It may become useful if the test is moved to ./t subdirectory.)
BEGIN { $| = 1; print "1..10\n"; }
END {print "not ok 1\n" unless $loaded;}
use Parse::Yapp;
$loaded = 1;
print "ok 1\n";
######################### End of black magic.
# Insert your test code below (better if it prints "ok 13"
# (correspondingly "not ok 13") depending on the success of chunk 13
# of the test code):
use Parse::Yapp;
my($testnum)=2;
my($parser,$grammar);
my($yapptxt);
#Test 2
eval {
$grammar=join('',<DATA>);
$parser=new Parse::Yapp(input => $grammar);
};
$@
and do {
print "not ok $testnum\n";
print "Object not created. Cannot continue test suite: aborting\n";
exit(1);
};
print "ok ", $testnum++, "\n";
#Test 3
keys(%{$parser->{GRAMMAR}{NULLABLE}}) == 43
or print "not ";
print "ok ", $testnum++, "\n";
#Test 4
keys(%{$parser->{GRAMMAR}{NTERM}}) == 233
or print "not ";
print "ok ", $testnum++, "\n";
#Test 5
@{$parser->{GRAMMAR}{UUTERM}} == 3
or print "not ";
print "ok ", $testnum++, "\n";
#Test 6
keys(%{$parser->{GRAMMAR}{TERM}}) == 108
or print "not ";
print "ok ", $testnum++, "\n";
#Test 7
@{$parser->{GRAMMAR}{RULES}} == 825
or print "not ";
print "ok ", $testnum++, "\n";
#Test 8
@{$parser->{STATES}} == 1611
or print "not ";
print "ok ", $testnum++, "\n";
#Test 9
keys(%{$parser->{CONFLICTS}{SOLVED}}) == 115
or print "not ";
print "ok ", $testnum++, "\n";
#Test 10
( $parser->{CONFLICTS}{FORCED}{TOTAL}[0] == 30
and $parser->{CONFLICTS}{FORCED}{TOTAL}[1] == 42 )
or print "not ";
print "ok ", $testnum++, "\n";
__DATA__
/*
This grammar is a stripped form of the original C++ grammar
from the GNU CC compiler :
YACC parser for C++ syntax.
Copyright (C) 1988, 89, 93-98, 1999 Free Software Foundation, Inc.
Hacked by Michael Tiemann (tiemann@cygnus.com)
The full gcc compiler an the original grammar file are freely
available under the GPL license at :
ftp://ftp.gnu.org/gnu/gcc/
*/
%{
$language_string = "GNU C++";
%}
%start program
/* All identifiers that are not reserved words
and are not declared typedefs in the current block */
%token IDENTIFIER
/* All identifiers that are declared typedefs in the current block.
In some contexts, they are treated just like IDENTIFIER,
but they can also serve as typespecs in declarations. */
%token TYPENAME
%token SELFNAME
/* A template function. */
%token PFUNCNAME
/* Reserved words that specify storage class.
yylval contains an IDENTIFIER_NODE which indicates which one. */
%token SCSPEC
/* Reserved words that specify type.
yylval contains an IDENTIFIER_NODE which indicates which one. */
%token TYPESPEC
/* Reserved words that qualify type: "const" or "volatile".
yylval contains an IDENTIFIER_NODE which indicates which one. */
%token CV_QUALIFIER
/* Character or numeric constants.
yylval is the node for the constant. */
%token CONSTANT
/* String constants in raw form.
yylval is a STRING_CST node. */
%token STRING
/* "...", used for functions with variable arglists. */
%token ELLIPSIS
/* the reserved words */
/* SCO include files test "ASM", so use something else. */
%token SIZEOF ENUM /* STRUCT UNION */ IF ELSE WHILE DO FOR SWITCH CASE DEFAULT
%token BREAK CONTINUE RETURN_KEYWORD GOTO ASM_KEYWORD TYPEOF ALIGNOF
%token SIGOF
%token ATTRIBUTE EXTENSION LABEL
%token REALPART IMAGPART
/* the reserved words... C++ extensions */
%token AGGR
%token VISSPEC
%token DELETE NEW THIS OPERATOR CXX_TRUE CXX_FALSE
%token NAMESPACE TYPENAME_KEYWORD USING
%token LEFT_RIGHT TEMPLATE
%token TYPEID DYNAMIC_CAST STATIC_CAST REINTERPRET_CAST CONST_CAST
%token SCOPE
/* Define the operator tokens and their precedences.
The value is an integer because, if used, it is the tree code
to use in the expression made from the operator. */
%left EMPTY /* used to resolve s/r with epsilon */
%left error
/* Add precedence rules to solve dangling else s/r conflict */
%nonassoc IF
%nonassoc ELSE
%left IDENTIFIER PFUNCNAME TYPENAME SELFNAME PTYPENAME SCSPEC TYPESPEC CV_QUALIFIER ENUM AGGR ELLIPSIS TYPEOF SIGOF OPERATOR NSNAME TYPENAME_KEYWORD
%left '{' ',' ';'
%nonassoc THROW
%right ':'
%right ASSIGN '='
%right '?'
%left OROR
%left ANDAND
%left '|'
%left '^'
%left '&'
%left MIN_MAX
%left EQCOMPARE
%left ARITHCOMPARE '<' '>'
%left LSHIFT RSHIFT
%left '+' '-'
%left '*' '/' '%'
%left POINTSAT_STAR DOT_STAR
%right UNARY PLUSPLUS MINUSMINUS '~'
%left HYPERUNARY
%left PAREN_STAR_PAREN LEFT_RIGHT
%left POINTSAT '.' '(' '['
%right SCOPE /* C++ extension */
%nonassoc NEW DELETE TRY CATCH
/* C++ extensions */
/* Not needed by yapp : already defined in the first %left directive */
/* %token PTYPENAME */
%token PRE_PARSED_FUNCTION_DECL EXTERN_LANG_STRING ALL
%token PRE_PARSED_CLASS_DECL DEFARG DEFARG_MARKER
/* in order to recognize aggr tags as defining and thus shadowing. */
%token TYPENAME_DEFN IDENTIFIER_DEFN PTYPENAME_DEFN
/* Not needed by yapp : already defined in the first %left directive */
/* %token NSNAME */
/* Used in lex.c for parsing pragmas. */
%token END_OF_LINE
/* lex.c and pt.c depend on this being the last token. Define
any new tokens before this one! */
%token END_OF_SAVED_INPUT
%{
/* Deleted everything */
%}
%%
program:
/* empty */
| extdefs
;
/* the reason for the strange actions in this rule
is so that notype_initdecls when reached via datadef
can find a valid list of type and sc specs in $0. */
extdefs:
lang_extdef
| extdefs lang_extdef
;
extdefs_opt:
extdefs
| /* empty */
;
dot_hush_warning:
;
dot_warning_ok:
;
extension:
EXTENSION
;
asm_keyword:
ASM_KEYWORD
;
lang_extdef:
extdef
;
extdef:
fndef eat_saved_input
| datadef
| template_def
| asm_keyword '(' string ')' ';'
| extern_lang_string '{' extdefs_opt '}'
| extern_lang_string dot_hush_warning fndef dot_warning_ok eat_saved_input
| extern_lang_string dot_hush_warning datadef dot_warning_ok
| NAMESPACE identifier '{'
extdefs_opt '}'
| NAMESPACE '{'
extdefs_opt '}'
| namespace_alias
| using_decl ';'
| using_directive
| extension extdef
;
namespace_alias:
NAMESPACE identifier '='
any_id ';'
;
using_decl:
USING qualified_id
| USING global_scope qualified_id
| USING global_scope unqualified_id
;
namespace_using_decl:
USING namespace_qualifier identifier
| USING global_scope identifier
| USING global_scope namespace_qualifier identifier
;
using_directive:
USING NAMESPACE
any_id ';'
;
namespace_qualifier:
NSNAME SCOPE
| namespace_qualifier NSNAME SCOPE
;
any_id:
unqualified_id
| qualified_id
| global_scope qualified_id
| global_scope unqualified_id
;
extern_lang_string:
EXTERN_LANG_STRING
| extern_lang_string EXTERN_LANG_STRING
;
template_header:
TEMPLATE '<'
template_parm_list '>'
| TEMPLATE '<' '>'
;
template_parm_list:
template_parm
| template_parm_list ',' template_parm
;
maybe_identifier:
identifier
| /* empty */
;
template_type_parm:
aggr maybe_identifier
| TYPENAME_KEYWORD maybe_identifier
;
template_template_parm:
template_header aggr maybe_identifier
;
template_parm:
/* The following rules introduce a new reduce/reduce
conflict on the ',' and '>' input tokens: they are valid
prefixes for a `structsp', which means they could match a
nameless parameter. See 14.6, paragraph 3.
By putting them before the `parm' rule, we get
their match before considering them nameless parameter
declarations. */
template_type_parm
| template_type_parm '=' type_id
| parm
| parm '=' expr_no_commas %prec ARITHCOMPARE
| template_template_parm
| template_template_parm '=' template_arg
;
template_def:
template_header template_extdef
| template_header error %prec EMPTY
;
template_extdef:
fndef eat_saved_input
| template_datadef
| template_def
| extern_lang_string dot_hush_warning fndef dot_warning_ok eat_saved_input
| extern_lang_string dot_hush_warning template_datadef dot_warning_ok
| extension template_extdef
;
template_datadef:
nomods_initdecls ';'
| declmods notype_initdecls ';'
| typed_declspecs initdecls ';'
| structsp ';'
;
datadef:
nomods_initdecls ';'
| declmods notype_initdecls ';'
| typed_declspecs initdecls ';'
| declmods ';'
| explicit_instantiation ';'
| typed_declspecs ';'
| error ';'
| error '}'
| ';'
;
ctor_initializer_opt:
nodecls
| base_init
;
maybe_return_init:
/* empty */
| return_init
| return_init ';'
;
eat_saved_input:
/* empty */
| END_OF_SAVED_INPUT
;
fndef:
fn_dot_def1 maybe_return_init ctor_initializer_opt compstmt_or_error
| fn_dot_def1 maybe_return_init function_try_block
| fn_dot_def1 maybe_return_init error
;
constructor_declarator:
nested_name_specifier SELFNAME '('
parmlist ')' cv_qualifiers exception_specification_opt
| nested_name_specifier SELFNAME LEFT_RIGHT cv_qualifiers exception_specification_opt
| global_scope nested_name_specifier SELFNAME '('
parmlist ')' cv_qualifiers exception_specification_opt
| global_scope nested_name_specifier SELFNAME LEFT_RIGHT cv_qualifiers exception_specification_opt
| nested_name_specifier self_template_type '('
parmlist ')' cv_qualifiers exception_specification_opt
| nested_name_specifier self_template_type LEFT_RIGHT cv_qualifiers exception_specification_opt
| global_scope nested_name_specifier self_template_type '('
parmlist ')' cv_qualifiers exception_specification_opt
| global_scope nested_name_specifier self_template_type LEFT_RIGHT cv_qualifiers exception_specification_opt
;
fn_dot_def1:
typed_declspecs declarator
| declmods notype_declarator
| notype_declarator
| declmods constructor_declarator
| constructor_declarator
;
component_constructor_declarator:
SELFNAME '(' parmlist ')' cv_qualifiers exception_specification_opt
| SELFNAME LEFT_RIGHT cv_qualifiers exception_specification_opt
| self_template_type '(' parmlist ')' cv_qualifiers exception_specification_opt
| self_template_type LEFT_RIGHT cv_qualifiers exception_specification_opt
;
/* more C++ complexity. See component_decl for a comment on the
reduce/reduce conflict introduced by these rules. */
fn_dot_def2:
declmods component_constructor_declarator
| component_constructor_declarator
| typed_declspecs declarator
| declmods notype_declarator
| notype_declarator
| declmods constructor_declarator
| constructor_declarator
;
return_id:
RETURN_KEYWORD IDENTIFIER
;
return_init:
return_id maybe_init
| return_id '(' nonnull_exprlist ')'
| return_id LEFT_RIGHT
;
base_init:
':' dot_set_base_init member_init_list
;
dot_set_base_init:
/* empty */
;
member_init_list:
/* empty */
| member_init
| member_init_list ',' member_init
| member_init_list error
;
member_init:
'(' nonnull_exprlist ')'
| LEFT_RIGHT
| notype_identifier '(' nonnull_exprlist ')'
| notype_identifier LEFT_RIGHT
| nonnested_type '(' nonnull_exprlist ')'
| nonnested_type LEFT_RIGHT
| typename_sub '(' nonnull_exprlist ')'
| typename_sub LEFT_RIGHT
;
identifier:
IDENTIFIER
| TYPENAME
| SELFNAME
| PTYPENAME
| NSNAME
;
notype_identifier:
IDENTIFIER
| PTYPENAME
| NSNAME %prec EMPTY
;
identifier_defn:
IDENTIFIER_DEFN
| TYPENAME_DEFN
| PTYPENAME_DEFN
;
explicit_instantiation:
TEMPLATE begin_explicit_instantiation typespec ';'
end_explicit_instantiation
| TEMPLATE begin_explicit_instantiation typed_declspecs declarator
end_explicit_instantiation
| TEMPLATE begin_explicit_instantiation notype_declarator
end_explicit_instantiation
| TEMPLATE begin_explicit_instantiation constructor_declarator
end_explicit_instantiation
| SCSPEC TEMPLATE begin_explicit_instantiation typespec ';'
end_explicit_instantiation
| SCSPEC TEMPLATE begin_explicit_instantiation typed_declspecs
declarator
end_explicit_instantiation
| SCSPEC TEMPLATE begin_explicit_instantiation notype_declarator
end_explicit_instantiation
| SCSPEC TEMPLATE begin_explicit_instantiation constructor_declarator
end_explicit_instantiation
;
begin_explicit_instantiation:
;
end_explicit_instantiation:
;
/* The TYPENAME expansions are to deal with use of a template class name as
a template within the class itself, where the template decl is hidden by
a type decl. Got all that? */
template_type:
PTYPENAME '<' template_arg_list_opt template_close_bracket
dot_finish_template_type
| TYPENAME '<' template_arg_list_opt template_close_bracket
dot_finish_template_type
| self_template_type
;
apparent_template_type:
template_type
| identifier '<' template_arg_list_opt '>'
dot_finish_template_type
;
self_template_type:
SELFNAME '<' template_arg_list_opt template_close_bracket
dot_finish_template_type
;
dot_finish_template_type:
;
template_close_bracket:
'>'
| RSHIFT
;
template_arg_list_opt:
/* empty */
| template_arg_list
;
template_arg_list:
template_arg
| template_arg_list ',' template_arg
;
template_arg:
type_id
| PTYPENAME
| expr_no_commas %prec ARITHCOMPARE
;
unop:
'-'
| '+'
| PLUSPLUS
| MINUSMINUS
| '!'
;
expr:
nontrivial_exprlist
| expr_no_commas
;
paren_expr_or_null:
LEFT_RIGHT
| '(' expr ')'
;
paren_cond_or_null:
LEFT_RIGHT
| '(' condition ')'
;
xcond:
/* empty */
| condition
| error
;
condition:
type_specifier_seq declarator maybeasm maybe_attribute '='
| expr
;
compstmtend:
'}'
| maybe_label_decls stmts '}'
| maybe_label_decls stmts error '}'
| maybe_label_decls error '}'
;
already_scoped_stmt:
'{'
compstmtend
| simple_stmt
;
nontrivial_exprlist:
expr_no_commas ',' expr_no_commas
| expr_no_commas ',' error
| nontrivial_exprlist ',' expr_no_commas
| nontrivial_exprlist ',' error
;
nonnull_exprlist:
expr_no_commas
| nontrivial_exprlist
;
unary_expr:
primary %prec UNARY
/* __extension__ turns off -pedantic for following primary. */
| extension cast_expr %prec UNARY
| '*' cast_expr %prec UNARY
| '&' cast_expr %prec UNARY
| '~' cast_expr
| unop cast_expr %prec UNARY
/* Refer to the address of a label as a pointer. */
| ANDAND identifier
| SIZEOF unary_expr %prec UNARY
| SIZEOF '(' type_id ')' %prec HYPERUNARY
| ALIGNOF unary_expr %prec UNARY
| ALIGNOF '(' type_id ')' %prec HYPERUNARY
/* The %prec EMPTY's here are required by the = init initializer
syntax extension; see below. */
| new new_type_id %prec EMPTY
| new new_type_id new_initializer
| new new_placement new_type_id %prec EMPTY
| new new_placement new_type_id new_initializer
/* The dot_begin_new_placement in the following rules is
necessary to avoid shift/reduce conflicts that lead to
mis-parsing some expressions. Of course, these constructs
are not really new-placement and it is bogus to call
begin_new_placement. But, the parser cannot always tell at this
point whether the next thing is an expression or a type-id,
so there is nothing we can do. Fortunately,
begin_new_placement does nothing harmful. When we rewrite
the parser, this lossage should be removed, of course. */
| new '(' dot_begin_new_placement type_id dot_finish_new_placement
%prec EMPTY
| new '(' dot_begin_new_placement type_id dot_finish_new_placement
new_initializer
| new new_placement '(' dot_begin_new_placement type_id
dot_finish_new_placement %prec EMPTY
| new new_placement '(' dot_begin_new_placement type_id
dot_finish_new_placement new_initializer
| delete cast_expr %prec UNARY
| delete '[' ']' cast_expr %prec UNARY
| delete '[' expr ']' cast_expr %prec UNARY
| REALPART cast_expr %prec UNARY
| IMAGPART cast_expr %prec UNARY
;
/* Note this rule is not suitable for use in new_placement
since it uses NULL_TREE as the argument to
finish_new_placement. This rule serves only to avoid
reduce/reduce conflicts in unary_expr. See the comments
there on the use of begin/finish_new_placement. */
dot_finish_new_placement:
')'
;
dot_begin_new_placement:
;
new_placement:
'(' dot_begin_new_placement nonnull_exprlist ')'
| '{' dot_begin_new_placement nonnull_exprlist '}'
;
new_initializer:
'(' nonnull_exprlist ')'
| LEFT_RIGHT
| '(' typespec ')'
/* GNU extension so people can use initializer lists. Note that
this alters the meaning of `new int = 1', which was previously
syntactically valid but semantically invalid. */
| '=' init
;
/* This is necessary to postpone reduction of `int ((int)(int)(int))'. */
regcast_or_absdcl:
'(' type_id ')' %prec EMPTY
| regcast_or_absdcl '(' type_id ')' %prec EMPTY
;
cast_expr:
unary_expr
| regcast_or_absdcl unary_expr %prec UNARY
| regcast_or_absdcl '{' initlist maybecomma '}' %prec UNARY
;
expr_no_commas:
cast_expr
/* Handle general members. */
| expr_no_commas POINTSAT_STAR expr_no_commas
| expr_no_commas DOT_STAR expr_no_commas
| expr_no_commas '+' expr_no_commas
| expr_no_commas '-' expr_no_commas
| expr_no_commas '*' expr_no_commas
| expr_no_commas '/' expr_no_commas
| expr_no_commas '%' expr_no_commas
| expr_no_commas LSHIFT expr_no_commas
| expr_no_commas RSHIFT expr_no_commas
| expr_no_commas ARITHCOMPARE expr_no_commas
| expr_no_commas '<' expr_no_commas
| expr_no_commas '>' expr_no_commas
| expr_no_commas EQCOMPARE expr_no_commas
| expr_no_commas MIN_MAX expr_no_commas
| expr_no_commas '&' expr_no_commas
| expr_no_commas '|' expr_no_commas
| expr_no_commas '^' expr_no_commas
| expr_no_commas ANDAND expr_no_commas
| expr_no_commas OROR expr_no_commas
| expr_no_commas '?' xexpr ':' expr_no_commas
| expr_no_commas '=' expr_no_commas
| expr_no_commas ASSIGN expr_no_commas
| THROW
| THROW expr_no_commas
/* These extensions are not defined. The second arg to build_m_component_ref
is old, build_m_component_ref now does an implicit
build_indirect_ref (x, NULL_PTR) on the second argument.
| object '&' expr_no_commas %prec UNARY
{ $$ = build_m_component_ref ($$, build_x_unary_op (ADDR_EXPR, $3)); }
| object unop expr_no_commas %prec UNARY
{ $$ = build_m_component_ref ($$, build_x_unary_op ($2, $3)); }
| object '(' type_id ')' expr_no_commas %prec UNARY
{ tree type = groktypename ($3.t);
$$ = build_m_component_ref ($$, build_c_cast (type, $5)); }
| object primary_no_id %prec UNARY
{ $$ = build_m_component_ref ($$, $2); }
*/
;
notype_unqualified_id:
'~' see_typename identifier
| '~' see_typename template_type
| template_id
| operator_name
| IDENTIFIER
| PTYPENAME
| NSNAME %prec EMPTY
;
do_id:
;
template_id:
PFUNCNAME '<' do_id template_arg_list_opt template_close_bracket
| operator_name '<' do_id template_arg_list_opt template_close_bracket
;
object_template_id:
TEMPLATE identifier '<' template_arg_list_opt template_close_bracket
| TEMPLATE PFUNCNAME '<' template_arg_list_opt template_close_bracket
| TEMPLATE operator_name '<' template_arg_list_opt
template_close_bracket
;
unqualified_id:
notype_unqualified_id
| TYPENAME
| SELFNAME
;
expr_or_declarator_intern:
expr_or_declarator
| attributes expr_or_declarator
;
expr_or_declarator:
notype_unqualified_id
| '*' expr_or_declarator_intern %prec UNARY
| '&' expr_or_declarator_intern %prec UNARY
| '(' expr_or_declarator_intern ')'
;
notype_template_declarator:
IDENTIFIER '<' template_arg_list_opt template_close_bracket
| NSNAME '<' template_arg_list template_close_bracket
;
direct_notype_declarator:
complex_direct_notype_declarator
/* This precedence declaration is to prefer this reduce
to the Koenig lookup shift in primary, below. I hate yacc. */
| notype_unqualified_id %prec '('
| notype_template_declarator
| '(' expr_or_declarator_intern ')'
;
primary:
notype_unqualified_id
| CONSTANT
| boolean_dot_literal
| string
| '(' expr ')'
| '(' expr_or_declarator_intern ')'
| '(' error ')'
| '('
compstmt ')'
/* Koenig lookup support
We could store lastiddecl in $1 to avoid another lookup,
but that would result in many additional reduce/reduce conflicts. */
| notype_unqualified_id '(' nonnull_exprlist ')'
| notype_unqualified_id LEFT_RIGHT
| primary '(' nonnull_exprlist ')'
| primary LEFT_RIGHT
| primary '[' expr ']'
| primary PLUSPLUS
| primary MINUSMINUS
/* C++ extensions */
| THIS
| CV_QUALIFIER '(' nonnull_exprlist ')'
| functional_cast
| DYNAMIC_CAST '<' type_id '>' '(' expr ')'
| STATIC_CAST '<' type_id '>' '(' expr ')'
| REINTERPRET_CAST '<' type_id '>' '(' expr ')'
| CONST_CAST '<' type_id '>' '(' expr ')'
| TYPEID '(' expr ')'
| TYPEID '(' type_id ')'
| global_scope IDENTIFIER
| global_scope template_id
| global_scope operator_name
| overqualified_id %prec HYPERUNARY
| overqualified_id '(' nonnull_exprlist ')'
| overqualified_id LEFT_RIGHT
| object object_template_id %prec UNARY
| object object_template_id '(' nonnull_exprlist ')'
| object object_template_id LEFT_RIGHT
| object unqualified_id %prec UNARY
| object overqualified_id %prec UNARY
| object unqualified_id '(' nonnull_exprlist ')'
| object unqualified_id LEFT_RIGHT
| object overqualified_id '(' nonnull_exprlist ')'
| object overqualified_id LEFT_RIGHT
/* p->int::~int() is valid -- 12.4 */
| object '~' TYPESPEC LEFT_RIGHT
| object TYPESPEC SCOPE '~' TYPESPEC LEFT_RIGHT
| object error
;
/* Not needed for now.
primary_no_id:
'(' expr ')'
| '(' error ')'
| '('
| primary_no_id '(' nonnull_exprlist ')'
| primary_no_id LEFT_RIGHT
| primary_no_id '[' expr ']'
| primary_no_id PLUSPLUS
| primary_no_id MINUSMINUS
| SCOPE IDENTIFIER
| SCOPE operator_name
;
*/
new:
NEW
| global_scope NEW
;
delete:
DELETE
| global_scope delete
;
boolean_dot_literal:
CXX_TRUE
| CXX_FALSE
;
/* Produces a STRING_CST with perhaps more STRING_CSTs chained onto it. */
string:
STRING
| string STRING
;
nodecls:
/* empty */
;
object:
primary '.'
| primary POINTSAT
;
decl:
typespec initdecls ';'
| typed_declspecs initdecls ';'
| declmods notype_initdecls ';'
| typed_declspecs ';'
| declmods ';'
| extension decl
;
/* Any kind of declarator (thus, all declarators allowed
after an explicit typespec). */
declarator:
after_type_declarator %prec EMPTY
| notype_declarator %prec EMPTY
;
/* This is necessary to postpone reduction of `int()()()()'. */
fcast_or_absdcl:
LEFT_RIGHT %prec EMPTY
| fcast_or_absdcl LEFT_RIGHT %prec EMPTY
;
/* ANSI type-id (8.1) */
type_id:
typed_typespecs absdcl
| nonempty_cv_qualifiers absdcl
| typespec absdcl
| typed_typespecs %prec EMPTY
| nonempty_cv_qualifiers %prec EMPTY
;
/* Declspecs which contain at least one type specifier or typedef name.
(Just `const' or `volatile' is not enough.)
A typedef'd name following these is taken as a name to be declared.
In the result, declspecs have a non-NULL TREE_VALUE, attributes do not. */
typed_declspecs:
typed_typespecs %prec EMPTY
| typed_declspecs1
;
typed_declspecs1:
declmods typespec
| typespec reserved_declspecs %prec HYPERUNARY
| typespec reserved_typespecquals reserved_declspecs
| declmods typespec reserved_declspecs
| declmods typespec reserved_typespecquals
| declmods typespec reserved_typespecquals reserved_declspecs
;
reserved_declspecs:
SCSPEC
| reserved_declspecs typespecqual_reserved
| reserved_declspecs SCSPEC
| reserved_declspecs attributes
| attributes
;
/* List of just storage classes and type modifiers.
A declaration can start with just this, but then it cannot be used
to redeclare a typedef-name.
In the result, declspecs have a non-NULL TREE_VALUE, attributes do not. */
/* We use hash_tree_cons for lists of typeless declspecs so that they end
up on a persistent obstack. Otherwise, they could appear at the
beginning of something like
static const struct { int foo () { } } b;
and would be discarded after we finish compiling foo. We don't need to
worry once we see a type. */
declmods:
nonempty_cv_qualifiers %prec EMPTY
{ $$ = $1.t; TREE_STATIC ($$) = 1; }
| SCSPEC
{ $$ = hash_tree_cons (NULL_TREE, $$, NULL_TREE); }
| declmods CV_QUALIFIER
{ $$ = hash_tree_cons (NULL_TREE, $2, $$);
TREE_STATIC ($$) = 1; }
| declmods SCSPEC
{ if (extra_warnings && TREE_STATIC ($$))
warning ("`%s' is not at beginning of declaration",
IDENTIFIER_POINTER ($2));
$$ = hash_tree_cons (NULL_TREE, $2, $$);
TREE_STATIC ($$) = TREE_STATIC ($1); }
| declmods attributes
{ $$ = hash_tree_cons ($2, NULL_TREE, $1); }
| attributes %prec EMPTY
{ $$ = hash_tree_cons ($1, NULL_TREE, NULL_TREE); }
;
/* Used instead of declspecs where storage classes are not allowed
(that is, for typenames and structure components).
C++ can takes storage classes for structure components.
Don't accept a typedef-name if anything but a modifier precedes it. */
typed_typespecs:
typespec %prec EMPTY
| nonempty_cv_qualifiers typespec
| typespec reserved_typespecquals
| nonempty_cv_qualifiers typespec reserved_typespecquals
;
reserved_typespecquals:
typespecqual_reserved
| reserved_typespecquals typespecqual_reserved
;
/* A typespec (but not a type qualifier).
Once we have seen one of these in a declaration,
if a typedef name appears then it is being redeclared. */
typespec:
structsp
| TYPESPEC %prec EMPTY
| complete_type_name
| TYPEOF '(' expr ')'
| TYPEOF '(' type_id ')'
| SIGOF '(' expr ')'
| SIGOF '(' type_id ')'
;
/* A typespec that is a reserved word, or a type qualifier. */
typespecqual_reserved:
TYPESPEC
| CV_QUALIFIER
| structsp
;
initdecls:
initdcl0
| initdecls ',' initdcl
;
notype_initdecls:
notype_initdcl0
| notype_initdecls ',' initdcl
;
nomods_initdecls:
nomods_initdcl0
| nomods_initdecls ',' initdcl
;
maybeasm:
/* empty */
| asm_keyword '(' string ')'
;
initdcl:
declarator maybeasm maybe_attribute '='
init
/* Note how the declaration of the variable is in effect while its init is parsed! */
| declarator maybeasm maybe_attribute
;
/* This rule assumes a certain configuration of the parser stack.
In particular, $0, the element directly before the beginning of
this rule on the stack, must be a maybeasm. $-1 must be a
declarator or notype_declarator. And $-2 must be some declmods
or declspecs. We can't move the maybeasm into this rule because
we need that reduce so we prefer fn_dot_def1 when appropriate. */
initdcl0_innards:
maybe_attribute '='
/* Note how the declaration of the variable is in effect
while its init is parsed! */
init
| maybe_attribute
;
initdcl0:
declarator maybeasm initdcl0_innards
;
notype_initdcl0:
notype_declarator maybeasm initdcl0_innards
;
nomods_initdcl0:
notype_declarator maybeasm
initdcl0_innards
| constructor_declarator maybeasm maybe_attribute
;
/* the * rules are dummies to accept the Apollo extended syntax
so that the header files compile. */
maybe_attribute:
/* empty */
| attributes
;
attributes:
attribute
| attributes attribute
;
attribute:
ATTRIBUTE '(' '(' attribute_list ')' ')'
;
attribute_list:
attrib
| attribute_list ',' attrib
;
attrib:
/* empty */
| any_word
| any_word '(' IDENTIFIER ')'
| any_word '(' IDENTIFIER ',' nonnull_exprlist ')'
| any_word '(' nonnull_exprlist ')'
;
/* This still leaves out most reserved keywords,
shouldn't we include them? */
any_word:
identifier
| SCSPEC
| TYPESPEC
| CV_QUALIFIER
;
/* A nonempty list of identifiers, including typenames. */
identifiers_or_typenames:
identifier
| identifiers_or_typenames ',' identifier
;
maybe_init:
/* empty */ %prec EMPTY
| '=' init
;
/* If we are processing a template, we don't want to expand this
initializer yet. */
init:
expr_no_commas %prec '='
| '{' '}'
| '{' initlist '}'
| '{' initlist ',' '}'
| error
;
/* This chain is built in reverse order,
and put in forward order where initlist is used. */
initlist:
init
| initlist ',' init
/* These are for labeled elements. */
| '[' expr_no_commas ']' init
| identifier ':' init
| initlist ',' identifier ':' init
;
fn_dot_defpen:
PRE_PARSED_FUNCTION_DECL
;
pending_inline:
fn_dot_defpen maybe_return_init ctor_initializer_opt compstmt_or_error
| fn_dot_defpen maybe_return_init function_try_block
| fn_dot_defpen maybe_return_init error
;
pending_inlines:
/* empty */
| pending_inlines pending_inline eat_saved_input
;
/* A regurgitated default argument. The value of DEFARG_MARKER will be
the TREE_LIST node for the parameter in question. */
defarg_again:
DEFARG_MARKER expr_no_commas END_OF_SAVED_INPUT
| DEFARG_MARKER error END_OF_SAVED_INPUT
;
pending_defargs:
/* empty */ %prec EMPTY
| pending_defargs defarg_again
| pending_defargs error
;
structsp:
ENUM identifier '{'
enumlist maybecomma_warn '}'
| ENUM identifier '{' '}'
| ENUM '{'
enumlist maybecomma_warn '}'
| ENUM '{' '}'
| ENUM identifier
| ENUM complex_type_name
| TYPENAME_KEYWORD typename_sub
/* C++ extensions, merged with C to avoid shift/reduce conflicts */
| class_head '{'
opt_dot_component_decl_list '}' maybe_attribute
pending_defargs
pending_inlines
| class_head %prec EMPTY
;
maybecomma:
/* empty */
| ','
;
maybecomma_warn:
/* empty */
| ','
;
aggr:
AGGR
| aggr SCSPEC
| aggr TYPESPEC
| aggr CV_QUALIFIER
| aggr AGGR
| aggr attributes
;
named_class_head_sans_basetype:
aggr identifier
;
named_class_head_sans_basetype_defn:
aggr identifier_defn %prec EMPTY
| named_class_head_sans_basetype '{'
| named_class_head_sans_basetype ':'
;
named_complex_class_head_sans_basetype:
aggr nested_name_specifier identifier
| aggr global_scope nested_name_specifier identifier
| aggr global_scope identifier
| aggr apparent_template_type
| aggr nested_name_specifier apparent_template_type
;
named_class_head:
named_class_head_sans_basetype %prec EMPTY
| named_class_head_sans_basetype_defn
/* Class name is unqualified, so we look for base classes
in the current scope. */
maybe_base_class_list %prec EMPTY
| named_complex_class_head_sans_basetype
maybe_base_class_list
;
unnamed_class_head:
aggr '{'
;
/* The tree output of this nonterminal a declarationf or the type
named. If NEW_TYPE_FLAG is set, then the name used in this
class-head was explicitly qualified, e.g.: `struct X::Y'. We have
already called push_scope for X. */
class_head:
unnamed_class_head
| named_class_head
;
maybe_base_class_list:
/* empty */ %prec EMPTY
| ':' see_typename %prec EMPTY
| ':' see_typename base_class_list %prec EMPTY
;
base_class_list:
base_class
| base_class_list ',' see_typename base_class
;
base_class:
base_class_dot_1
| base_class_access_list see_typename base_class_dot_1
;
base_class_dot_1:
typename_sub
| nonnested_type
| SIGOF '(' expr ')'
| SIGOF '(' type_id ')'
;
base_class_access_list:
VISSPEC see_typename
| SCSPEC see_typename
| base_class_access_list VISSPEC see_typename
| base_class_access_list SCSPEC see_typename
;
opt_dot_component_decl_list:
| component_decl_list
| opt_dot_component_decl_list access_specifier component_decl_list
| opt_dot_component_decl_list access_specifier
;
access_specifier:
VISSPEC ':'
;
/* Note: we no longer warn about the semicolon after a component_decl_list.
ARM $9.2 says that the semicolon is optional, and therefore allowed. */
component_decl_list:
component_decl
| component_decl_list component_decl
;
component_decl:
component_decl_1 ';'
| component_decl_1 '}'
/* C++: handle constructors, destructors and inline functions */
/* note that INLINE is like a TYPESPEC */
| fn_dot_def2 ':' /* base_init compstmt */
| fn_dot_def2 TRY /* base_init compstmt */
| fn_dot_def2 RETURN_KEYWORD /* base_init compstmt */
| fn_dot_def2 '{' /* nodecls compstmt */
| ';'
| extension component_decl
| template_header component_decl
| template_header typed_declspecs ';'
;
component_decl_1:
/* Do not add a "typed_declspecs declarator" rule here for
speed; we need to call grok_x_components for enums, so the
speedup would be insignificant. */
typed_declspecs components
| declmods notype_components
| notype_declarator maybeasm maybe_attribute maybe_init
| constructor_declarator maybeasm maybe_attribute maybe_init
| ':' expr_no_commas
| error
/* These rules introduce a reduce/reduce conflict; in
typedef int foo, bar;
class A {
foo (bar);
};
should "A::foo" be declared as a function or "A::bar" as a data
member? In other words, is "bar" an after_type_declarator or a
parmlist? */
| declmods component_constructor_declarator maybeasm maybe_attribute maybe_init
| component_constructor_declarator maybeasm maybe_attribute maybe_init
| using_decl
;
/* The case of exactly one component is handled directly by component_decl. */
/* ??? Huh? ^^^ */
components:
/* empty: possibly anonymous */
| component_declarator0
| components ',' component_declarator
;
notype_components:
/* empty: possibly anonymous */
| notype_component_declarator0
| notype_components ',' notype_component_declarator
;
component_declarator0:
after_type_component_declarator0
| notype_component_declarator0
;
component_declarator:
after_type_component_declarator
| notype_component_declarator
;
after_type_component_declarator0:
after_type_declarator maybeasm maybe_attribute maybe_init
| TYPENAME ':' expr_no_commas maybe_attribute
;
notype_component_declarator0:
notype_declarator maybeasm maybe_attribute maybe_init
| constructor_declarator maybeasm maybe_attribute maybe_init
| IDENTIFIER ':' expr_no_commas maybe_attribute
| ':' expr_no_commas maybe_attribute
;
after_type_component_declarator:
after_type_declarator maybeasm maybe_attribute maybe_init
| TYPENAME ':' expr_no_commas maybe_attribute
;
notype_component_declarator:
notype_declarator maybeasm maybe_attribute maybe_init
| IDENTIFIER ':' expr_no_commas maybe_attribute
| ':' expr_no_commas maybe_attribute
;
/* We chain the enumerators in reverse order.
Because of the way enums are built, the order is
insignificant. Take advantage of this fact. */
enumlist:
enumerator
| enumlist ',' enumerator
;
enumerator:
identifier
| identifier '=' expr_no_commas
;
/* ANSI new-type-id (5.3.4) */
new_type_id:
type_specifier_seq new_declarator
| type_specifier_seq %prec EMPTY
/* GNU extension to allow arrays of arbitrary types with
non-constant dimension. For the use of begin_new_placement
here, see the comments in unary_expr above. */
| '(' dot_begin_new_placement type_id dot_finish_new_placement
'[' expr ']'
;
cv_qualifiers:
/* empty */ %prec EMPTY
| cv_qualifiers CV_QUALIFIER
;
nonempty_cv_qualifiers:
CV_QUALIFIER
| nonempty_cv_qualifiers CV_QUALIFIER
;
/* These rules must follow the rules for function declarations
and component declarations. That way, longer rules are preferred. */
suspend_mom:
/* empty */
;
/* An expression which will not live on the momentary obstack. */
nonmomentary_expr:
suspend_mom expr
;
/* An expression which will not live on the momentary obstack. */
maybe_parmlist:
suspend_mom '(' nonnull_exprlist ')'
| suspend_mom '(' parmlist ')'
| suspend_mom LEFT_RIGHT
| suspend_mom '(' error ')'
;
/* A declarator that is allowed only after an explicit typespec. */
after_type_declarator_intern:
after_type_declarator
| attributes after_type_declarator
;
/* may all be followed by prec '.' */
after_type_declarator:
'*' nonempty_cv_qualifiers after_type_declarator_intern %prec UNARY
| '&' nonempty_cv_qualifiers after_type_declarator_intern %prec UNARY
| '*' after_type_declarator_intern %prec UNARY
| '&' after_type_declarator_intern %prec UNARY
| ptr_to_mem cv_qualifiers after_type_declarator_intern
| direct_after_type_declarator
;
direct_after_type_declarator:
direct_after_type_declarator maybe_parmlist cv_qualifiers exception_specification_opt %prec '.'
| direct_after_type_declarator '[' nonmomentary_expr ']'
| direct_after_type_declarator '[' ']'
| '(' after_type_declarator_intern ')'
| nested_name_specifier type_name %prec EMPTY
| type_name %prec EMPTY
;
nonnested_type:
type_name %prec EMPTY
| global_scope type_name
;
complete_type_name:
nonnested_type
| nested_type
| global_scope nested_type
;
nested_type:
nested_name_specifier type_name %prec EMPTY
;
/* A declarator allowed whether or not there has been
an explicit typespec. These cannot redeclare a typedef-name. */
notype_declarator_intern:
notype_declarator
| attributes notype_declarator
;
notype_declarator:
'*' nonempty_cv_qualifiers notype_declarator_intern %prec UNARY
| '&' nonempty_cv_qualifiers notype_declarator_intern %prec UNARY
| '*' notype_declarator_intern %prec UNARY
| '&' notype_declarator_intern %prec UNARY
| ptr_to_mem cv_qualifiers notype_declarator_intern
| direct_notype_declarator
;
complex_notype_declarator:
'*' nonempty_cv_qualifiers notype_declarator_intern %prec UNARY
| '&' nonempty_cv_qualifiers notype_declarator_intern %prec UNARY
| '*' complex_notype_declarator %prec UNARY
| '&' complex_notype_declarator %prec UNARY
| ptr_to_mem cv_qualifiers notype_declarator_intern
| complex_direct_notype_declarator
;
complex_direct_notype_declarator:
direct_notype_declarator maybe_parmlist cv_qualifiers exception_specification_opt %prec '.'
| '(' complex_notype_declarator ')'
| direct_notype_declarator '[' nonmomentary_expr ']'
| direct_notype_declarator '[' ']'
| notype_qualified_id
| nested_name_specifier notype_template_declarator
;
qualified_id:
nested_name_specifier unqualified_id
| nested_name_specifier object_template_id
;
notype_qualified_id:
nested_name_specifier notype_unqualified_id
| nested_name_specifier object_template_id
;
overqualified_id:
notype_qualified_id
| global_scope notype_qualified_id
;
functional_cast:
typespec '(' nonnull_exprlist ')'
| typespec '(' expr_or_declarator_intern ')'
| typespec fcast_or_absdcl %prec EMPTY
;
type_name:
TYPENAME
| SELFNAME
| template_type %prec EMPTY
;
nested_name_specifier:
nested_name_specifier_1
| nested_name_specifier nested_name_specifier_1
| nested_name_specifier TEMPLATE explicit_template_type SCOPE
;
/* Why the @#$%^& do type_name and notype_identifier need to be expanded
inline here?!? (jason) */
nested_name_specifier_1:
TYPENAME SCOPE
| SELFNAME SCOPE
| NSNAME SCOPE
| template_type SCOPE
/* These break 'const i;'
| IDENTIFIER SCOPE
{
failed_scope:
cp_error ("`%D' is not an aggregate typedef",
lastiddecl ? lastiddecl : $$);
$$ = error_mark_node;
}
| PTYPENAME SCOPE
{ goto failed_scope; } */
;
typename_sub:
typename_sub0
| global_scope typename_sub0
;
typename_sub0:
typename_sub1 identifier %prec EMPTY
| typename_sub1 template_type %prec EMPTY
| typename_sub1 explicit_template_type %prec EMPTY
| typename_sub1 TEMPLATE explicit_template_type %prec EMPTY
;
typename_sub1:
typename_sub2
| typename_sub1 typename_sub2
| typename_sub1 explicit_template_type SCOPE
| typename_sub1 TEMPLATE explicit_template_type SCOPE
;
typename_sub2:
TYPENAME SCOPE
| SELFNAME SCOPE
| template_type SCOPE
| PTYPENAME SCOPE
| IDENTIFIER SCOPE
| NSNAME SCOPE
;
explicit_template_type:
identifier '<' template_arg_list_opt template_close_bracket
;
complex_type_name:
global_scope type_name
| nested_type
| global_scope nested_type
;
ptr_to_mem:
nested_name_specifier '*'
| global_scope nested_name_specifier '*'
;
/* All uses of explicit global scope must go through this nonterminal so
that got_scope will be set before yylex is called to get the next token. */
global_scope:
SCOPE
;
/* ANSI new-declarator (5.3.4) */
new_declarator:
'*' cv_qualifiers new_declarator
| '*' cv_qualifiers %prec EMPTY
| '&' cv_qualifiers new_declarator %prec EMPTY
| '&' cv_qualifiers %prec EMPTY
| ptr_to_mem cv_qualifiers %prec EMPTY
| ptr_to_mem cv_qualifiers new_declarator
| direct_new_declarator %prec EMPTY
;
/* ANSI direct-new-declarator (5.3.4) */
direct_new_declarator:
'[' expr ']'
| direct_new_declarator '[' nonmomentary_expr ']'
;
absdcl_intern:
absdcl
| attributes absdcl
;
/* ANSI abstract-declarator (8.1) */
absdcl:
'*' nonempty_cv_qualifiers absdcl_intern
| '*' absdcl_intern
| '*' nonempty_cv_qualifiers %prec EMPTY
| '*' %prec EMPTY
| '&' nonempty_cv_qualifiers absdcl_intern
| '&' absdcl_intern
| '&' nonempty_cv_qualifiers %prec EMPTY
| '&' %prec EMPTY
| ptr_to_mem cv_qualifiers %prec EMPTY
| ptr_to_mem cv_qualifiers absdcl_intern
| direct_abstract_declarator %prec EMPTY
;
/* ANSI direct-abstract-declarator (8.1) */
direct_abstract_declarator:
'(' absdcl_intern ')'
/* `(typedef)1' is `int'. */
| PAREN_STAR_PAREN
| direct_abstract_declarator '(' parmlist ')' cv_qualifiers exception_specification_opt %prec '.'
| direct_abstract_declarator LEFT_RIGHT cv_qualifiers exception_specification_opt %prec '.'
| direct_abstract_declarator '[' nonmomentary_expr ']' %prec '.'
| direct_abstract_declarator '[' ']' %prec '.'
| '(' complex_parmlist ')' cv_qualifiers exception_specification_opt %prec '.'
| regcast_or_absdcl cv_qualifiers exception_specification_opt %prec '.'
| fcast_or_absdcl cv_qualifiers exception_specification_opt %prec '.'
| '[' nonmomentary_expr ']' %prec '.'
| '[' ']' %prec '.'
;
/* For C++, decls and stmts can be intermixed, so we don't need to
have a special rule that won't start parsing the stmt section
until we have a stmt that parses without errors. */
stmts:
stmt
| errstmt
| stmts stmt
| stmts errstmt
;
errstmt:
error ';'
;
/* Read zero or more forward-declarations for labels
that nested functions can jump to. */
maybe_label_decls:
/* empty */
| label_decls
;
label_decls:
label_decl
| label_decls label_decl
;
label_decl:
LABEL identifiers_or_typenames ';'
;
/* This is the body of a function definition.
It causes syntax errors to ignore to the next openbrace. */
compstmt_or_error:
compstmt
| error compstmt
;
compstmt:
'{'
compstmtend
;
simple_if:
IF
paren_cond_or_null
implicitly_scoped_stmt
;
implicitly_scoped_stmt:
compstmt
| simple_stmt
;
stmt:
compstmt
| simple_stmt
;
simple_stmt:
decl
| expr ';'
| simple_if ELSE
implicitly_scoped_stmt
| simple_if %prec IF
| WHILE
paren_cond_or_null
already_scoped_stmt
| DO
implicitly_scoped_stmt WHILE
paren_expr_or_null ';'
| FOR
'(' for_dot_init_dot_statement
xcond ';'
xexpr ')'
already_scoped_stmt
| SWITCH
'(' condition ')'
implicitly_scoped_stmt
| CASE expr_no_commas ':'
stmt
| CASE expr_no_commas ELLIPSIS expr_no_commas ':'
stmt
| DEFAULT ':'
stmt
| BREAK ';'
| CONTINUE ';'
| RETURN_KEYWORD ';'
| RETURN_KEYWORD expr ';'
| asm_keyword maybe_cv_qualifier '(' string ')' ';'
/* This is the case with just output operands. */
| asm_keyword maybe_cv_qualifier '(' string ':' asm_operands ')' ';'
/* This is the case with input operands as well. */
| asm_keyword maybe_cv_qualifier '(' string ':' asm_operands ':' asm_operands ')' ';'
/* This is the case with clobbered registers as well. */
| asm_keyword maybe_cv_qualifier '(' string ':' asm_operands ':'
asm_operands ':' asm_clobbers ')' ';'
| GOTO '*' expr ';'
| GOTO identifier ';'
| label_colon stmt
| label_colon '}'
| ';'
| try_block
| using_directive
| namespace_using_decl
| namespace_alias
;
function_try_block:
TRY
ctor_initializer_opt compstmt
handler_seq
;
try_block:
TRY
compstmt
handler_seq
;
handler_seq:
handler
| handler_seq handler
;
handler:
CATCH
handler_args
compstmt
;
type_specifier_seq:
typed_typespecs %prec EMPTY
| nonempty_cv_qualifiers %prec EMPTY
;
handler_args:
'(' ELLIPSIS ')'
/* This doesn't allow reference parameters, the below does.
| '(' type_specifier_seq absdcl ')'
| '(' type_specifier_seq ')'
| '(' type_specifier_seq notype_declarator ')'
| '(' typed_typespecs after_type_declarator ')'
This allows reference parameters... */
| '(' parm ')'
;
label_colon:
IDENTIFIER ':'
| PTYPENAME ':'
| TYPENAME ':'
| SELFNAME ':'
;
for_dot_init_dot_statement:
xexpr ';'
| decl
| '{' compstmtend
;
/* Either a type-qualifier or nothing. First thing in an `asm' statement. */
maybe_cv_qualifier:
/* empty */
| CV_QUALIFIER
;
xexpr:
/* empty */
| expr
| error
;
/* These are the operands other than the first string and colon
in asm ("addextend %2,%1": "=dm" (x), "0" (y), "g" (*x)) */
asm_operands:
/* empty */
| nonnull_asm_operands
;
nonnull_asm_operands:
asm_operand
| nonnull_asm_operands ',' asm_operand
;
asm_operand:
STRING '(' expr ')'
;
asm_clobbers:
STRING
| asm_clobbers ',' STRING
;
/* This is what appears inside the parens in a function declarator.
Its value is represented in the format that grokdeclarator expects.
In C++, declaring a function with no parameters
means that that function takes *no* parameters. */
parmlist:
/* empty */
| complex_parmlist
| type_id
;
/* This nonterminal does not include the common sequence '(' type_id ')',
as it is ambiguous and must be disambiguated elsewhere. */
complex_parmlist:
parms
| parms_comma ELLIPSIS
/* C++ allows an ellipsis without a separating ',' */
| parms ELLIPSIS
| type_id ELLIPSIS
| ELLIPSIS
| parms ':'
| type_id ':'
;
/* A default argument to a */
defarg:
'='
defarg1
;
defarg1:
DEFARG
| init
;
/* A nonempty list of parameter declarations or type names. */
parms:
named_parm
| parm defarg
| parms_comma full_parm
| parms_comma bad_parm
| parms_comma bad_parm '=' init
;
parms_comma:
parms ','
| type_id ','
;
/* A single parameter declaration or parameter type name,
as found in a parmlist. */
named_parm:
/* Here we expand typed_declspecs inline to avoid mis-parsing of
TYPESPEC IDENTIFIER. */
typed_declspecs1 declarator
| typed_typespecs declarator
| typespec declarator
| typed_declspecs1 absdcl
| typed_declspecs1 %prec EMPTY
| declmods notype_declarator
;
full_parm:
parm
| parm defarg
;
parm:
named_parm
| type_id
;
see_typename:
/* empty */ %prec EMPTY
;
bad_parm:
/* empty */ %prec EMPTY
| notype_declarator
;
exception_specification_opt:
/* empty */ %prec EMPTY
| THROW '(' ansi_raise_identifiers ')' %prec EMPTY
| THROW LEFT_RIGHT %prec EMPTY
;
ansi_raise_identifier:
type_id
;
ansi_raise_identifiers:
ansi_raise_identifier
| ansi_raise_identifiers ',' ansi_raise_identifier
;
conversion_declarator:
/* empty */ %prec EMPTY
| '*' cv_qualifiers conversion_declarator
| '&' cv_qualifiers conversion_declarator
| ptr_to_mem cv_qualifiers conversion_declarator
;
operator:
OPERATOR
;
operator_name:
operator '*'
| operator '/'
| operator '%'
| operator '+'
| operator '-'
| operator '&'
| operator '|'
| operator '^'
| operator '~'
| operator ','
| operator ARITHCOMPARE
| operator '<'
| operator '>'
| operator EQCOMPARE
| operator ASSIGN
| operator '='
| operator LSHIFT
| operator RSHIFT
| operator PLUSPLUS
| operator MINUSMINUS
| operator ANDAND
| operator OROR
| operator '!'
| operator '?' ':'
| operator MIN_MAX
| operator POINTSAT %prec EMPTY
| operator POINTSAT_STAR %prec EMPTY
| operator LEFT_RIGHT
| operator '[' ']'
| operator NEW %prec EMPTY
| operator DELETE %prec EMPTY
| operator NEW '[' ']'
| operator DELETE '[' ']'
/* Names here should be looked up in class scope ALSO. */
| operator type_specifier_seq conversion_declarator
| operator error
;
%%
|