From 9c4250e95c816276c54945dc3f184cf639a3147f Mon Sep 17 00:00:00 2001 From: Guido Tack Date: Tue, 12 Nov 2024 14:45:52 +1100 Subject: [PATCH] Fix operator precedences for `intersect` and unary plus/minus. Update the grammar and spec to make sure they're consistent with the implemented parser. --- changes.rst | 1 + docs/en/grammar.mzn | 3 +- docs/en/spec.rst | 81 +++-- lib/cached/md5_cached.cmake | 2 +- lib/cached/parser.tab.cpp | 316 +++++++++--------- lib/parser.yxx | 7 +- .../spec/unit/compilation/op_precedences.mzn | 16 + 7 files changed, 226 insertions(+), 200 deletions(-) create mode 100644 tests/spec/unit/compilation/op_precedences.mzn diff --git a/changes.rst b/changes.rst index 2f011e85d..4656de237 100644 --- a/changes.rst +++ b/changes.rst @@ -31,6 +31,7 @@ Bug fixes: - Fix defines_var annotation for cyclic definitions (:bugref:`863`). - Fix assertion failures when using arrays as argument to bin packing constraints (:bugref:`865`). +- Fix operator precedences for ``intersect`` and unary plus/minus. .. _v2.8.7: diff --git a/docs/en/grammar.mzn b/docs/en/grammar.mzn index 20e570454..b6122f8a2 100644 --- a/docs/en/grammar.mzn +++ b/docs/en/grammar.mzn @@ -90,8 +90,7 @@ | | | "ann" - | "{" "," ... "}" - | ".." + | % Type-inst variables ::= $[A-Za-z$][A-Za-z0-9_]* diff --git a/docs/en/spec.rst b/docs/en/spec.rst index 247e4ce30..d9ddb8734 100644 --- a/docs/en/spec.rst +++ b/docs/en/spec.rst @@ -1447,53 +1447,57 @@ Note that the last entry in the table, :mzn:`^-1`, is a combination of the binar =============================== ====== ====== Symbol(s) Assoc. Prec. =============================== ====== ====== - :mzn:`<->` left 1200 + :mzn:`<->` left 1600 - :mzn:`->` left 1100 - :mzn:`<-` left 1100 + :mzn:`->` left 1500 + :mzn:`<-` left 1500 - ``\/`` left 1000 - :mzn:`xor` left 1000 + ``\/`` left 1400 + :mzn:`xor` left 1400 - ``/\`` left 900 + ``/\`` left 1300 - :mzn:`<` none 800 - :mzn:`>` none 800 - :mzn:`<=` none 800 - :mzn:`>=` none 800 - :mzn:`==`, - :mzn:`=` none 800 - :mzn:`!=` none 800 - - :mzn:`in` none 700 - :mzn:`subset` none 700 - :mzn:`superset` none 700 + :mzn:`<` none 1200 + :mzn:`>` none 1200 + :mzn:`<=` none 1200 + :mzn:`>=` none 1200 + + :mzn:`==` none 1100 + :mzn:`=` none 1100 + :mzn:`!=` none 1100 - :mzn:`union` left 600 - :mzn:`diff` left 600 - :mzn:`symdiff` left 600 + :mzn:`in` none 1000 + :mzn:`subset` none 1000 + :mzn:`superset` none 1000 + + :mzn:`union` left 900 + :mzn:`diff` left 900 + :mzn:`symdiff` left 900 + + :mzn:`intersect` left 800 + + :mzn:`..` none 700 + :mzn:`<..` none 700 + :mzn:`..<` none 700 + :mzn:`<..<` none 700 - :mzn:`..` none 500 - :mzn:`<..` none 500 - :mzn:`..<` none 500 - :mzn:`<..<` none 500 + :mzn:`+` left 600 + :mzn:`-` left 600 - :mzn:`+` left 400 - :mzn:`-` left 400 + :mzn:`*` left 500 + :mzn:`div` left 500 + :mzn:`mod` left 500 + :mzn:`/` left 500 + + :mzn:`^` left 400 - :mzn:`*` left 300 - :mzn:`div` left 300 - :mzn:`mod` left 300 - :mzn:`/` left 300 - :mzn:`intersect` left 300 + :mzn:`++` right 300 - :mzn:`^` left 200 - - :mzn:`++` right 100 + :mzn:`default` left 200 - :mzn:`default` left 70 + ````` :mzndef:`` ````` left 100 - ````` :mzndef:`` ````` left 50 + :mzn:`::` left 0 =============================== ====== ====== @@ -1508,6 +1512,11 @@ This is a static error if the identifier is not the name of a binary function or predicate. The unary operators are: :mzn:`+`, :mzn:`-` and :mzn:`not`. +Unary :mzn:`+` and :mzn:`-` have the same precedence as the binary +multiplication operator :mzn:`*`. The logic :mzn:`not` operator +has precedence 350, i.e., it binds more tightly than all other +Boolean and numeric operators. + User-defined unary operators are not possible. As :ref:`spec-Identifiers` explains, any built-in operator can be used as diff --git a/lib/cached/md5_cached.cmake b/lib/cached/md5_cached.cmake index b846b0729..9f73b41bd 100644 --- a/lib/cached/md5_cached.cmake +++ b/lib/cached/md5_cached.cmake @@ -1,4 +1,4 @@ set(lexer_lxx_md5_cached "1fd3518993d57146c38066eda73e9506") -set(parser_yxx_md5_cached "081f1fce960fc4a2d7eaa9dc1f363092") +set(parser_yxx_md5_cached "6762414c9408775ded333ad703b75b77") set(regex_lexer_lxx_md5_cached "8906a52bfa0c5ae26354cb272348e656") set(regex_parser_yxx_md5_cached "68ec070becef5e161c3b97d085b0810e") \ No newline at end of file diff --git a/lib/cached/parser.tab.cpp b/lib/cached/parser.tab.cpp index 980207aeb..b246719ba 100644 --- a/lib/cached/parser.tab.cpp +++ b/lib/cached/parser.tab.cpp @@ -906,52 +906,52 @@ static const yytype_uint8 yytranslate[] = /* YYRLINE[YYN] -- Source line where rule number YYN was defined. */ static const yytype_int16 yyrline[] = { - 0, 373, 373, 375, 377, 380, 389, 398, 407, 416, - 418, 421, 429, 438, 438, 440, 456, 460, 462, 464, - 465, 467, 469, 471, 473, 475, 478, 478, 478, 479, - 479, 479, 479, 479, 480, 483, 506, 515, 522, 532, - 550, 564, 576, 580, 589, 594, 600, 607, 608, 612, - 620, 621, 625, 629, 635, 637, 644, 649, 654, 661, - 663, 671, 673, 675, 677, 681, 692, 703, 714, 727, - 741, 757, 770, 780, 781, 791, 792, 797, 798, 800, - 805, 806, 810, 821, 833, 833, 834, 834, 837, 839, - 843, 853, 857, 859, 862, 866, 868, 872, 873, 881, - 890, 904, 907, 916, 928, 941, 949, 959, 972, 986, - 990, 995, 996, 1000, 1002, 1004, 1006, 1008, 1010, 1017, - 1027, 1029, 1034, 1040, 1043, 1045, 1049, 1051, 1053, 1055, - 1057, 1060, 1063, 1065, 1071, 1072, 1074, 1076, 1078, 1080, - 1089, 1091, 1093, 1095, 1097, 1099, 1101, 1103, 1105, 1107, - 1109, 1111, 1113, 1115, 1117, 1126, 1128, 1130, 1132, 1134, - 1136, 1138, 1140, 1142, 1144, 1146, 1148, 1150, 1155, 1160, - 1165, 1170, 1175, 1180, 1185, 1191, 1197, 1199, 1208, 1214, - 1215, 1217, 1219, 1221, 1223, 1225, 1227, 1229, 1231, 1233, - 1235, 1237, 1239, 1241, 1243, 1245, 1247, 1249, 1251, 1253, - 1262, 1264, 1266, 1268, 1270, 1272, 1274, 1276, 1278, 1280, - 1282, 1284, 1286, 1288, 1290, 1299, 1301, 1303, 1305, 1307, - 1309, 1311, 1313, 1315, 1317, 1319, 1321, 1323, 1325, 1330, - 1335, 1340, 1345, 1350, 1355, 1360, 1365, 1371, 1373, 1380, - 1389, 1394, 1396, 1400, 1402, 1404, 1406, 1408, 1410, 1413, - 1415, 1418, 1420, 1423, 1425, 1428, 1430, 1432, 1434, 1436, - 1438, 1440, 1442, 1444, 1446, 1448, 1450, 1451, 1454, 1456, - 1459, 1460, 1463, 1465, 1468, 1469, 1472, 1474, 1477, 1478, - 1481, 1483, 1486, 1487, 1490, 1492, 1495, 1496, 1499, 1501, - 1504, 1505, 1506, 1509, 1510, 1513, 1514, 1517, 1519, 1522, - 1523, 1526, 1528, 1533, 1535, 1541, 1546, 1554, 1563, 1569, - 1578, 1587, 1589, 1594, 1599, 1613, 1621, 1623, 1627, 1634, - 1640, 1643, 1646, 1648, 1650, 1656, 1658, 1660, 1668, 1670, - 1673, 1676, 1679, 1681, 1683, 1685, 1689, 1691, 1738, 1740, - 1801, 1841, 1844, 1849, 1856, 1861, 1864, 1867, 1877, 1889, - 1900, 1903, 1907, 1918, 1929, 1948, 1955, 1959, 1962, 1966, - 1977, 1997, 2011, 2027, 2028, 2032, 2034, 2036, 2038, 2040, - 2042, 2044, 2046, 2048, 2050, 2052, 2054, 2056, 2058, 2060, - 2062, 2064, 2066, 2068, 2070, 2072, 2074, 2076, 2078, 2080, - 2082, 2084, 2086, 2090, 2098, 2130, 2132, 2134, 2135, 2155, - 2209, 2229, 2284, 2287, 2293, 2299, 2301, 2305, 2307, 2314, - 2323, 2325, 2333, 2335, 2344, 2344, 2347, 2355, 2366, 2367, - 2370, 2372, 2374, 2378, 2382, 2386, 2388, 2390, 2392, 2394, - 2396, 2398, 2400, 2402, 2404, 2406, 2408, 2410, 2412, 2414, - 2416, 2418, 2420, 2422, 2424, 2426, 2428, 2430, 2432, 2434, - 2436, 2438, 2440, 2442, 2444, 2446, 2448, 2450, 2452 + 0, 374, 374, 376, 378, 381, 390, 399, 408, 417, + 419, 422, 430, 439, 439, 441, 457, 461, 463, 465, + 466, 468, 470, 472, 474, 476, 479, 479, 479, 480, + 480, 480, 480, 480, 481, 484, 507, 516, 523, 533, + 551, 565, 577, 581, 590, 595, 601, 608, 609, 613, + 621, 622, 626, 630, 636, 638, 645, 650, 655, 662, + 664, 672, 674, 676, 678, 682, 693, 704, 715, 728, + 742, 758, 771, 781, 782, 792, 793, 798, 799, 801, + 806, 807, 811, 822, 834, 834, 835, 835, 838, 840, + 844, 854, 858, 860, 863, 867, 869, 873, 874, 882, + 891, 905, 908, 917, 929, 942, 950, 960, 973, 987, + 991, 996, 997, 1001, 1003, 1005, 1007, 1009, 1011, 1018, + 1028, 1030, 1035, 1041, 1044, 1046, 1050, 1052, 1054, 1056, + 1058, 1061, 1064, 1066, 1072, 1073, 1075, 1077, 1079, 1081, + 1090, 1092, 1094, 1096, 1098, 1100, 1102, 1104, 1106, 1108, + 1110, 1112, 1114, 1116, 1118, 1127, 1129, 1131, 1133, 1135, + 1137, 1139, 1141, 1143, 1145, 1147, 1149, 1151, 1156, 1161, + 1166, 1171, 1176, 1181, 1186, 1192, 1198, 1200, 1209, 1215, + 1216, 1218, 1220, 1222, 1224, 1226, 1228, 1230, 1232, 1234, + 1236, 1238, 1240, 1242, 1244, 1246, 1248, 1250, 1252, 1254, + 1263, 1265, 1267, 1269, 1271, 1273, 1275, 1277, 1279, 1281, + 1283, 1285, 1287, 1289, 1291, 1300, 1302, 1304, 1306, 1308, + 1310, 1312, 1314, 1316, 1318, 1320, 1322, 1324, 1326, 1331, + 1336, 1341, 1346, 1351, 1356, 1361, 1366, 1372, 1374, 1381, + 1390, 1395, 1397, 1401, 1403, 1405, 1407, 1409, 1411, 1414, + 1416, 1419, 1421, 1424, 1426, 1429, 1431, 1433, 1435, 1437, + 1439, 1441, 1443, 1445, 1447, 1449, 1451, 1452, 1455, 1457, + 1460, 1461, 1464, 1466, 1469, 1470, 1473, 1475, 1478, 1479, + 1482, 1484, 1487, 1488, 1491, 1493, 1496, 1497, 1500, 1502, + 1505, 1506, 1507, 1510, 1511, 1514, 1515, 1518, 1520, 1523, + 1524, 1527, 1529, 1534, 1536, 1542, 1547, 1555, 1564, 1570, + 1579, 1588, 1590, 1595, 1600, 1614, 1622, 1624, 1628, 1635, + 1641, 1644, 1647, 1649, 1651, 1657, 1659, 1661, 1669, 1671, + 1674, 1677, 1680, 1682, 1684, 1686, 1690, 1692, 1739, 1741, + 1802, 1842, 1845, 1850, 1857, 1862, 1865, 1868, 1878, 1890, + 1901, 1904, 1908, 1919, 1930, 1949, 1956, 1960, 1963, 1967, + 1978, 1998, 2012, 2028, 2029, 2033, 2035, 2037, 2039, 2041, + 2043, 2045, 2047, 2049, 2051, 2053, 2055, 2057, 2059, 2061, + 2063, 2065, 2067, 2069, 2071, 2073, 2075, 2077, 2079, 2081, + 2083, 2085, 2087, 2091, 2099, 2131, 2133, 2135, 2136, 2156, + 2210, 2230, 2285, 2288, 2294, 2300, 2302, 2306, 2308, 2315, + 2324, 2326, 2334, 2336, 2345, 2345, 2348, 2356, 2367, 2368, + 2371, 2373, 2375, 2379, 2383, 2387, 2389, 2391, 2393, 2395, + 2397, 2399, 2401, 2403, 2405, 2407, 2409, 2411, 2413, 2415, + 2417, 2419, 2421, 2423, 2425, 2427, 2429, 2431, 2433, 2435, + 2437, 2439, 2441, 2443, 2445, 2447, 2449, 2451, 2453 }; #endif @@ -1068,18 +1068,18 @@ static const yytype_int16 yypact[] = -634, 2948, 56, 8254, 83, -43, 7713, -634, -634, 2656, 3094, 220, -634, 8, 8254, -53, 2948, 3678, 5472, 121, 155, -32, 2948, 83, -634, 4554, 335, -634, 5575, 202, - 114, -634, 968, 8254, -2, 205, 116, -634, 36, 7736, - 7736, 7736, 7736, 49, -634, 49, 4554, 5284, 5284, 5284, + 114, -634, 968, 8254, -2, 205, 116, -634, 36, 7951, + 7951, 7951, 7951, 49, -634, 49, 4554, 5284, 5284, 5284, -634, 122, 120, 5675, 15, 5916, 124, -634, -634, 2218, -634, -634, -634, -634, -634, -634, -634, -634, -634, -634, -634, -634, -634, 4554, 3094, 266, 5284, 5284, 5284, 5284, 5284, 5284, 5284, 5430, 5430, 5430, 5430, 5284, 5284, 5284, 5284, 5284, 5284, 5284, 5284, 5284, 5284, 5284, 5284, 5284, - 5472, -634, 337, -634, 354, -634, 387, -634, 449, -634, - 462, -634, 463, -634, 464, -634, 467, 4554, -634, 469, + 5472, -634, 337, -634, 387, -634, 449, -634, 462, -634, + 463, -634, 464, -634, 467, -634, 469, 4554, -634, 471, -634, 4554, 4554, 4554, 4554, 214, 176, -634, 8254, 8254, - 1631, -634, 7813, 179, 182, -634, 4992, -634, 357, 357, - 357, 357, 32, -634, 32, 32, 4554, 4554, 4554, 4554, + 1631, -634, 7813, 179, 182, -634, 4992, -634, 5598, 5598, + 5598, 5598, 90, -634, 90, 32, 4554, 4554, 4554, 4554, 4554, -634, 4554, 4554, 4554, 4554, 4554, 4554, 4554, 4554, 4554, 4554, 4554, 4554, 4554, 4554, 4554, 4554, 4554, 4554, 4554, 4554, 4554, 4554, 4554, 5138, 5138, 5138, 5138, 4554, @@ -1091,44 +1091,44 @@ static const yytype_int16 yypact[] = 4554, -634, 5472, 111, 330, 212, 282, 6604, -634, 4554, 45, -634, 4554, -634, -634, -634, 211, -634, 213, -634, 4554, -634, 4554, 4554, -634, 5958, 6379, 6479, 6504, -634, - 4554, -634, 45, 4554, 471, 1778, 360, 218, 2072, -634, - 8254, -634, -11, 258, 16, 5858, 5858, 7836, 7836, 7836, - 7736, 7736, 7736, 7736, 371, 371, 371, 371, 13, 13, - 13, 13, 13, 13, 7836, 13, 49, -634, -634, -634, + 4554, -634, 45, 4554, 472, 1778, 360, 218, 2072, -634, + 8254, -634, -11, 258, 16, 5858, 5858, 7751, 7751, 7751, + 7951, 7951, 7951, 7951, 371, 371, 371, 371, 13, 13, + 13, 13, 13, 13, 8055, 13, 49, -634, -634, -634, -634, -634, -634, -634, -634, -634, 6062, -634, -634, 4992, - -634, -634, 226, 4554, 228, 4554, -634, 320, 6104, 6208, + -634, -634, 221, 4554, 227, 4554, -634, 320, 6104, 6208, 6250, 6354, -634, 8254, 269, 40, 8354, 8392, 8392, 8492, 8492, 8527, 8627, 8627, 8627, 8627, 8627, 8627, 8627, 8627, - 8654, 8654, 8654, 5598, 5598, 5598, 357, 357, 357, 357, + 8654, 8654, 8654, 357, 357, 357, 5598, 5598, 5598, 5598, 331, 331, 331, 331, 90, 90, 90, 90, 90, 90, - 5598, 90, 32, 91, -634, 3678, 3678, 236, 239, 241, - -634, -634, -18, 4554, 347, 2948, -634, 8254, 12, 285, + 7851, 90, 32, 91, -634, 3678, 3678, 236, 239, 226, + -634, -634, -18, 4554, 347, 2948, -634, 8254, 12, 284, -634, -634, -634, -634, -634, -634, -634, -634, -634, -634, -634, -634, -634, -634, -634, -634, -634, -634, -634, -634, -634, -634, -634, -634, -634, -634, -634, -634, -634, -634, - -634, -634, 111, 8254, 4554, 4554, 389, -634, 313, -634, - 2802, -634, 1925, 6645, 8254, 330, 248, 83, -634, 2948, + -634, -634, 111, 8254, 4554, 4554, 386, -634, 311, -634, + 2802, -634, 1925, 6645, 8254, 330, 246, 83, -634, 2948, -634, 8254, 8254, -634, 330, 83, -634, 2948, -634, 5716, - 321, -634, 339, -634, 252, -634, 348, 322, 254, 5816, + 319, -634, 339, -634, 251, -634, 345, 321, 254, 5816, 4554, 4554, -634, 54, 8254, 8254, -634, 4554, -634, 5284, - -634, 5284, -634, 5284, 262, 8254, -634, 472, -634, 261, - 265, -634, -634, -634, 2948, -634, -634, 4554, -634, 263, + -634, 5284, -634, 5284, 259, 8254, -634, 473, -634, 261, + 262, -634, -634, -634, 2948, -634, -634, 4554, -634, 263, 8254, 4554, 7913, -634, -634, 4554, -634, 4554, -634, 4554, -634, 4554, -634, -634, -634, -634, 2948, -634, 8254, 3094, - 233, 267, 271, 404, 411, 311, -634, -634, 330, 154, - 8254, 8254, 83, 4554, 340, -634, -634, -634, 277, -634, - 83, 422, 358, -634, 83, 358, 233, 45, 4554, -634, - 45, -634, 4554, 4554, 66, -634, 4554, -634, 312, 4554, - 6745, 7450, 7475, 7575, -634, -634, -634, 326, 6786, 4554, + 233, 267, 271, 401, 406, 307, -634, -634, 330, 154, + 8254, 8254, 83, 4554, 333, -634, -634, -634, 275, -634, + 83, 414, 346, -634, 83, 346, 233, 45, 4554, -634, + 45, -634, 4554, 4554, 66, -634, 4554, -634, 276, 4554, + 6745, 7450, 7475, 7575, -634, -634, -634, 289, 6786, 4554, 6886, 4554, 6927, 7027, 7068, 7168, -634, -634, 4554, 4554, - -634, -23, -634, 334, 3, 83, 4554, 4554, -634, 8254, - 4554, -634, 358, -634, 4554, -634, 358, -634, 428, 8254, - -634, 434, 8254, 8013, -634, -634, 8254, 4554, -634, -634, + -634, -23, -634, 325, 3, 83, 4554, 4554, -634, 8254, + 4554, -634, 346, -634, 4554, -634, 346, -634, 403, 8254, + -634, 427, 8254, 8013, -634, -634, 8254, 4554, -634, -634, -634, -634, 330, -634, 7209, -634, 8254, -634, -634, -634, - -634, 7309, 7350, -634, 485, 490, 350, -634, 358, 8113, + -634, 7309, 7350, -634, 483, 487, 349, -634, 346, 8113, 8213, 8254, -634, 8254, -634, -634, 4554, 4554, 83, -634, -634, -634, -634, -634, -634, -634, -634, 4554, 8254, 8254, - 358, 8254, -634 + 346, 8254, -634 }; /* YYDEFACT[STATE-NUM] -- Default reduction number in state STATE-NUM. @@ -1220,15 +1220,15 @@ static const yytype_int16 yydefact[] = /* YYPGOTO[NTERM-NUM]. */ static const yytype_int16 yypgoto[] = { - -634, -634, -634, -634, 289, -634, -73, 489, -634, -634, + -634, -634, -634, -634, 288, -634, -73, 488, -634, -634, -634, -634, -212, -634, -634, -634, -152, -634, -634, -634, - -634, -634, -634, -334, -633, -135, -119, -634, -112, -634, - -140, -156, -634, -634, 338, -634, -21, -154, 494, -15, - 223, -634, 52, -80, 25, -19, -20, 552, -149, -111, + -634, -634, -634, -334, -633, -135, -125, -634, -112, -634, + -141, -156, -634, -634, 334, -634, -21, -154, 494, -15, + 223, -634, 51, -80, 25, -19, -20, 552, -149, -111, 215, -28, -634, -634, -634, -634, 100, -634, -404, -634, - -634, -168, -167, -634, -634, -634, -634, -634, -87, -634, + -634, -169, -168, -634, -634, -634, -634, -634, -88, -634, -634, 118, 119, -634, -634, -634, -634, -634, -634, -634, - -634, 237, -634, -634, -634, -634, -45, -30, -215, -634, + -634, 234, -634, -634, -634, -634, -45, -30, -215, -634, -634 }; @@ -1289,28 +1289,28 @@ static const yytype_int16 yytable[] = 523, 524, 224, 525, 285, 623, 573, 574, 528, 571, 576, 285, 565, 285, 564, 572, 579, 578, 304, 581, 582, 586, 587, 600, 303, 601, 620, 622, 250, 589, - 285, 261, 599, 123, 123, 629, 631, 123, 226, 343, + 629, 261, 599, 123, 123, 631, 646, 123, 226, 343, 183, 633, 604, 605, 304, 644, 617, 286, 645, 649, - 473, 646, 657, 615, 286, 662, 286, 663, 227, 671, - 679, 678, 680, 285, 684, 682, 683, 647, 768, 694, - 696, 699, 710, 286, 359, 708, 413, 712, 665, 709, - 714, 263, 265, 673, 720, 268, 721, 658, 723, 333, - 334, 335, 336, 337, 338, 287, 340, 341, 724, 278, - 342, 343, 388, 630, 448, 632, 286, -81, -81, -81, - -81, 329, 330, 331, 332, 333, 334, 335, 336, 337, - 338, 449, 340, 341, 737, 285, 342, 343, 521, 241, - 242, 243, 244, 245, 246, 742, 248, 249, 285, 285, - 285, 250, 681, 285, 755, 285, 685, 122, 285, 765, - 521, 766, 668, 772, 450, 707, 773, 774, 418, 144, - 642, 643, 757, 648, 650, 697, 706, 147, 286, 467, - 385, 628, 730, 731, 688, 472, 621, 462, 602, 603, + 473, 657, 662, 615, 286, 663, 286, 671, 227, 678, + 679, 680, 682, 285, 684, 683, 694, 647, 768, 710, + 696, 699, 712, 413, 359, 708, 714, 720, 665, 709, + 723, 263, 265, 673, 721, 268, 724, 658, 737, 333, + 334, 335, 336, 337, 338, 287, 340, 341, 742, 278, + 342, 343, 388, 630, 448, 632, 286, 325, 326, 327, + 328, 329, 330, 331, 332, 333, 334, 335, 336, 337, + 338, 339, 340, 341, 765, 285, 342, 343, 521, 241, + 242, 243, 244, 245, 246, 755, 248, 249, 285, 285, + 285, 250, 681, 285, 766, 285, 685, 285, 122, 285, + 521, 772, 668, 773, 449, 707, 774, 418, 144, 697, + 642, 643, 757, 648, 650, 706, 385, 147, 286, 467, + 628, 730, 731, 688, 462, 472, 621, 0, 602, 603, 687, 286, 286, 286, 0, 666, 286, 0, 286, 213, - 123, 286, 0, 0, 214, 0, 0, 0, 0, 215, + 286, 123, 286, 0, 214, 0, 0, 0, 0, 215, 0, 216, 0, 217, 660, 661, 0, 672, 0, 360, - 0, 0, 103, 218, 219, 675, 451, 220, 360, 221, - 0, 0, 103, 0, 0, 0, 676, 0, 0, 452, - 453, 454, 0, 0, 455, 103, 457, 0, 616, 695, - 0, 0, 103, 0, 0, 0, 0, 690, 0, 0, + 0, 0, 103, 218, 219, 675, 450, 220, 360, 221, + 0, 0, 103, 0, 0, 0, 676, 0, 0, 451, + 452, 453, 0, 0, 454, 103, 455, 0, 457, 616, + 695, 0, 103, 0, 0, 0, 0, 690, 0, 0, 691, 0, 692, 0, 693, 103, 103, 103, 103, 103, 103, 756, 0, 522, 0, 0, 0, 698, 0, 0, 0, 700, 0, 0, 0, 702, 0, 703, 0, 704, @@ -1820,8 +1820,8 @@ static const yytype_int16 yytable[] = 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, 303, 0, 342, 343, 0, 0, 325, 326, - 327, 328, 329, 330, 331, 332, 333, 334, 335, 336, + 340, 341, 303, 0, 342, 343, 0, 0, -81, -81, + -81, -81, 329, 330, 331, 332, 333, 334, 335, 336, 337, 338, 304, 340, 341, 0, 0, 342, 343, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 303, 0, 0, 389, 390, 0, 0, @@ -2026,49 +2026,49 @@ static const yytype_int16 yytable[] = 551, 552, 553, 554, 555, 556, 557, 558, 559, 560, 303, 561, 0, 0, 741, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 304, 0, 0, 226, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 227, 0, 356, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 304, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 226, 0, + 0, 0, 0, 0, 0, 356, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 227, 0, 0, 0, 0, 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, - 303, 0, 342, 343, 0, 0, -81, -81, -81, -81, - 237, 238, 239, 240, 241, 242, 243, 244, 245, 246, - 304, 248, 249, 226, 0, 0, 250, 0, 0, 0, + 303, 0, 342, 343, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 227, 0, 0, 0, 0, 0, 0, - 463, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 304, 233, 234, 235, 236, 237, 238, 239, 240, 241, + 242, 243, 244, 245, 246, 247, 248, 249, 303, 0, + 0, 250, 0, 0, 0, 0, 0, 0, 0, 0, + 463, 0, 0, 0, 0, 0, 0, 0, 304, 0, 0, 0, 0, 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, - 303, 0, 342, 343, 0, 0, 233, 234, 235, 236, - 237, 238, 239, 240, 241, 242, 243, 244, 245, 246, - 304, 248, 249, 0, 0, 0, 250, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 303, 0, 342, 343, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 701, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 304, 325, 326, 327, 328, 329, 330, 331, 332, 333, + 334, 335, 336, 337, 338, 0, 340, 341, 226, 0, + 342, 343, 0, 0, 0, 0, 0, 0, 0, 0, + 701, 0, 0, 0, 0, 0, 0, 0, 227, 0, 0, 0, 0, 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, 303, 0, 342, 343, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 304, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 304, -81, -81, -81, -81, 237, 238, 239, 240, 241, + 242, 243, 244, 245, 246, 0, 248, 249, 0, 0, + 0, 250, 226, 0, 0, 0, 0, 0, 0, 0, 767, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 305, 306, 307, 308, 309, 310, 311, + 0, 0, 227, 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, 303, 0, 342, 343, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 304, 0, 0, 776, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 304, 0, 0, 776, 0, 233, 234, 235, 236, 237, + 238, 239, 240, 241, 242, 243, 244, 245, 246, 0, + 248, 249, 0, 0, 0, 250, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 305, 306, 307, 308, 309, 310, 311, 312, 313, 314, 315, 316, 317, 318, 319, 320, 321, @@ -2170,28 +2170,28 @@ static const yytype_int16 yycheck[] = 80, 61, 109, 150, 16, 418, 366, 367, 80, 364, 20, 16, 80, 16, 84, 148, 150, 149, 27, 379, 380, 149, 80, 152, 7, 152, 6, 149, 110, 389, - 16, 107, 392, 59, 59, 149, 148, 59, 7, 110, + 149, 107, 392, 59, 59, 148, 150, 59, 7, 110, 400, 61, 402, 403, 27, 149, 414, 59, 149, 42, - 410, 150, 107, 413, 59, 6, 59, 84, 27, 151, - 61, 80, 150, 16, 150, 57, 84, 519, 742, 147, - 149, 148, 8, 59, 570, 148, 151, 6, 570, 148, - 109, 107, 107, 579, 84, 107, 149, 562, 6, 98, - 99, 100, 101, 102, 103, 107, 105, 106, 80, 459, + 410, 107, 6, 413, 59, 84, 59, 151, 27, 80, + 61, 150, 57, 16, 150, 84, 147, 519, 742, 8, + 149, 148, 6, 151, 570, 148, 109, 84, 570, 148, + 6, 107, 107, 579, 149, 107, 80, 562, 152, 98, + 99, 100, 101, 102, 103, 107, 105, 106, 149, 459, 109, 110, 107, 463, 107, 465, 59, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100, 101, 102, - 103, 107, 105, 106, 152, 16, 109, 110, 624, 98, - 99, 100, 101, 102, 103, 149, 105, 106, 16, 16, - 16, 110, 594, 16, 150, 16, 598, 16, 16, 61, - 646, 57, 572, 8, 107, 649, 6, 147, 209, 10, - 515, 516, 714, 523, 525, 624, 646, 13, 59, 286, - 172, 459, 680, 680, 601, 300, 416, 280, 400, 400, + 103, 104, 105, 106, 61, 16, 109, 110, 624, 98, + 99, 100, 101, 102, 103, 150, 105, 106, 16, 16, + 16, 110, 594, 16, 57, 16, 598, 16, 16, 16, + 646, 8, 572, 6, 107, 649, 147, 209, 10, 624, + 515, 516, 714, 523, 525, 646, 172, 13, 59, 286, + 459, 680, 680, 601, 280, 300, 416, -1, 400, 400, 600, 59, 59, 59, -1, 570, 59, -1, 59, 21, - 59, 59, -1, -1, 26, -1, -1, -1, -1, 31, + 59, 59, 59, -1, 26, -1, -1, -1, -1, 31, -1, 33, -1, 35, 564, 565, -1, 577, -1, 570, -1, -1, 0, 45, 46, 585, 107, 49, 579, 51, -1, -1, 10, -1, -1, -1, 587, -1, -1, 107, 107, 107, -1, -1, 107, 23, 107, -1, 107, 107, - -1, -1, 30, -1, -1, -1, -1, 607, -1, -1, + 107, -1, 30, -1, -1, -1, -1, 607, -1, -1, 609, -1, 611, -1, 613, 43, 44, 45, 46, 47, 48, 713, -1, 624, -1, -1, -1, 627, -1, -1, -1, 631, -1, -1, -1, 635, -1, 637, -1, 639, @@ -2907,49 +2907,49 @@ static const yytype_int16 yycheck[] = 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 7, 144, -1, -1, 149, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - 27, -1, -1, 7, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, 27, -1, 52, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + 27, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, 7, -1, + -1, -1, -1, -1, -1, 52, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, 27, -1, -1, -1, -1, 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, - 7, -1, 109, 110, -1, -1, 90, 91, 92, 93, - 94, 95, 96, 97, 98, 99, 100, 101, 102, 103, - 27, 105, 106, 7, -1, -1, 110, -1, -1, -1, + 7, -1, 109, 110, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, 27, -1, -1, -1, -1, -1, -1, - 57, -1, -1, -1, -1, -1, -1, -1, -1, -1, + 27, 90, 91, 92, 93, 94, 95, 96, 97, 98, + 99, 100, 101, 102, 103, 104, 105, 106, 7, -1, + -1, 110, -1, -1, -1, -1, -1, -1, -1, -1, + 57, -1, -1, -1, -1, -1, -1, -1, 27, -1, -1, -1, -1, 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, - 7, -1, 109, 110, -1, -1, 90, 91, 92, 93, - 94, 95, 96, 97, 98, 99, 100, 101, 102, 103, - 27, 105, 106, -1, -1, -1, 110, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + 7, -1, 109, 110, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - 57, -1, -1, -1, -1, -1, -1, -1, -1, -1, + 27, 90, 91, 92, 93, 94, 95, 96, 97, 98, + 99, 100, 101, 102, 103, -1, 105, 106, 7, -1, + 109, 110, -1, -1, -1, -1, -1, -1, -1, -1, + 57, -1, -1, -1, -1, -1, -1, -1, 27, -1, -1, -1, -1, 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, 7, -1, 109, 110, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - 27, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + 27, 90, 91, 92, 93, 94, 95, 96, 97, 98, + 99, 100, 101, 102, 103, -1, 105, 106, -1, -1, + -1, 110, 7, -1, -1, -1, -1, -1, -1, -1, 57, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, 70, 71, 72, 73, 74, 75, 76, + -1, -1, 27, 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, 7, -1, 109, 110, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - 27, -1, -1, 30, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + 27, -1, -1, 30, -1, 90, 91, 92, 93, 94, + 95, 96, 97, 98, 99, 100, 101, 102, 103, -1, + 105, 106, -1, -1, -1, 110, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, diff --git a/lib/parser.yxx b/lib/parser.yxx index b06e51c5e..07e6e5b4c 100644 --- a/lib/parser.yxx +++ b/lib/parser.yxx @@ -301,7 +301,8 @@ void parseFieldTail(const ParserLocation& loc, std::vector& parsed, %left MZN_AND %nonassoc MZN_LE MZN_GR MZN_LQ MZN_GQ MZN_EQ MZN_NQ MZN_WEAK_EQ MZN_WEAK_NQ %nonassoc MZN_IN MZN_SUBSET MZN_SUPERSET -%left MZN_UNION MZN_DIFF MZN_SYMDIFF MZN_INTERSECT +%left MZN_UNION MZN_DIFF MZN_SYMDIFF +%left MZN_INTERSECT %nonassoc MZN_DOTDOT MZN_DOTDOT_LE MZN_LE_DOTDOT MZN_LE_DOTDOT_LE %left MZN_PLUS MZN_MINUS MZN_WEAK_PLUS MZN_WEAK_MINUS %left MZN_MULT MZN_DIV MZN_IDIV MZN_MOD MZN_WEAK_MULT MZN_WEAK_DIV MZN_WEAK_IDIV @@ -1370,14 +1371,14 @@ expr : } | MZN_NOT expr %prec MZN_NOT { $$=new UnOp(@$, UOT_NOT, $2); } - | MZN_PLUS expr %prec MZN_NOT + | MZN_PLUS expr %prec MZN_MULT { if (($2 && Expression::isa($2)) || ($2 && Expression::isa($2))) { $$ = $2; } else { $$=new UnOp(@$, UOT_PLUS, $2); } } - | MZN_MINUS expr %prec MZN_NOT + | MZN_MINUS expr %prec MZN_MULT { if ($2 && Expression::isa($2)) { $$ = IntLit::a(-IntLit::v(Expression::cast($2))); } else if ($2 && Expression::isa($2)) { diff --git a/tests/spec/unit/compilation/op_precedences.mzn b/tests/spec/unit/compilation/op_precedences.mzn new file mode 100644 index 000000000..058d01380 --- /dev/null +++ b/tests/spec/unit/compilation/op_precedences.mzn @@ -0,0 +1,16 @@ +/*** +!Test +check_against: [] +expected: +- !Result + status: SATISFIED +solvers: +- gecode +type: solve +***/ +set of int: x = 1..3; +set of int: y = 2..4; +set of int: z = 3..5; + +constraint (x union y intersect z) = (x union (y intersect z)); +constraint -2^2 = -4;