## ~sircmpwn/hare-specification unlisted

ref: c29ec1ad33d6cef3a6c55c493814d35c914bde59 hare-specification/language/expressions.tex -rw-r--r-- 83.8 KiB

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
\specsection{Expressions}

\specsubitem
An expression is a procedure which the implementation may perform to obtain a
\textit{result}, and possibly cause side-effects (see
\subsubitemref{Program execution}{1}).

\specsubitem
Expression types are organized into a number of classes and subclasses of
expressions which define the contexts in which each expression type is
applicable.

\specsubitem
All expressions have a defined \textit{result type}. It may be \terminal{void}.

\specsubitem
Some expressions \textit{terminate}. The semantics of terminating expressions
vary between different expression types, and will be detailed as appropriate.
If unspecified, expressions described by this expression are presumed to be
non-terminating. Expression classes inherit their termination qualities from the
more specific sub-expressions which they classify.

\specsubitem
Some expressions may provide a \textit{type hint} to other expressions which
appear in their grammar, which those expressions may take advantage of to
refine their behavior.

\specsubsection{Constants}

\begin{grammar}
\nonterminaldef{constant} \\
\nonterminal{integer-constant} \\
\nonterminal{floating-constant} \\
\nonterminal{rune-constant} \\
\nonterminal{string-constant} \\
\terminal{true} \\
\terminal{false} \\
\terminal{null} \\
\terminal{void} \\
\end{grammar}

\specsubsubitem
Constants (also known as literals) shall describe a specific value of an
unambiguous type. The result of the expression is the constant value.

\specsubsubitem
The keywords \terminal{true} and \terminal{false} respectively represent
the constants of the \terminal{bool} type.

\specsubsubitem
The representation of \terminal{true} as an \terminal{uint}-equivalent (ref
\subsubitemref{Other primitive types}{2}) shall be one.

\specsubsubitem
The \terminal{null} keyword represents the \terminal{null} value of the
\terminal{null} type.

\specsubsubitem
The \terminal{void} keyword represents the \terminal{void} value of the
\terminal{void} type.

\specsubsection{Floating constants}

\begin{grammar}
\nonterminaldef{floating-constant} \exactly \\
\nonterminal{decimal-digits} \terminal{.} \nonterminal{decimal-digits} \optional{\nonterminal{exponent}} \optional{\nonterminal{floating-suffix}} \\
\nonterminal{decimal-digits} \optional{\nonterminal{exponent}} \nonterminal{floating-suffix} \\

\nonterminaldef{floating-suffix} \oneof \\
\terminal{f32}
\terminal{f64} \\

\nonterminaldef{decimal-digits} \exactly \\
\nonterminal{decimal-digit} \optional{\nonterminal{decimal-digits}} \\

\nonterminaldef{decimal-digit} \oneof \\
\terminal{0}
\terminal{1}
\terminal{2}
\terminal{3}
\terminal{4}
\terminal{5}
\terminal{6}
\terminal{7}
\terminal{8}
\terminal{9} \\

\nonterminaldef{exponent} \exactly \\
\terminal{e} \nonterminal{decimal-digits} \\
\end{grammar}

Floating constants represent an IEEE 754-compatible floating-point
number in either the binary32 or binary64 format.

\specsubitem
If the \nonterminal{floating-suffix} is not provided and a type hint is
provided, the type shall be the type hint. If the \nonterminal{floating-suffix}
is not provided and a type hint is not provided, the type shall be
\terminal{f64}. Otherwise, the type shall refer to the type named by the suffix.

\specsubitem
If the \nonterminal{exponent} is provided, the value of the
constant shall be multiplied by 10 to the power of
\nonterminal{decimal-digits}.

\specsubsection{Integer constants}

\begin{grammar}
\nonterminaldef{integer-constant} \exactly \\
\terminal{0x} \nonterminal{hex-digits} \optional{\nonterminal{integer-suffix}} \\
\terminal{0o} \nonterminal{octal-digits} \optional{\nonterminal{integer-suffix}} \\
\terminal{0b} \nonterminal{binary-digits} \optional{\nonterminal{integer-suffix}} \\
\nonterminal{decimal-digits} \optional{\nonterminal{exponent}}
\optional{\nonterminal{integer-suffix}} \\

\nonterminaldef{hex-digits} \exactly \\
\nonterminal{hex-digit} \optional{\nonterminal{hex-digits}} \\

\nonterminaldef{hex-digit} \oneof \\
\terminal{0}
\terminal{1}
\terminal{2}
\terminal{3}
\terminal{4}
\terminal{5}
\terminal{6}
\terminal{7}
\terminal{8}
\terminal{9}
\terminal{A}
\terminal{B}
\terminal{C}
\terminal{D}
\terminal{E}
\terminal{F}
\terminal{a}
\terminal{b}
\terminal{c}
\terminal{d}
\terminal{e}
\terminal{f} \\

\nonterminaldef{octal-digits} \exactly \\
\nonterminal{octal-digit} \optional{\nonterminal{octal-digits}} \\

\nonterminaldef{octal-digit} \oneof \\
\terminal{0}
\terminal{1}
\terminal{2}
\terminal{3}
\terminal{4}
\terminal{5}
\terminal{6}
\terminal{7} \\

\nonterminaldef{binary-digits} \exactly \\
\nonterminal{binary-digit} \optional{\nonterminal{binary-digits}} \\

\nonterminaldef{binary-digit} \oneof \\
\terminal{0}
\terminal{1} \\

\nonterminaldef{integer-suffix} \oneof \\
\terminal{i}
\terminal{u}
\terminal{z}
\terminal{i8}
\terminal{i16}
\terminal{i32}
\terminal{i64}
\terminal{u8}
\terminal{u16}
\terminal{u32}
\terminal{u64} \\
\end{grammar}

Integer constants represent an integer value at a specific precision.

\specsubitem
If the \nonterminal{integer-suffix} is not provided and a type hint is provided,
the type shall be the type hint. If the \nonterminal{integer-suffix} is not
provided and a type hint is not provided, the type shall be \terminal{int}. If
the \nonterminal{integer-suffix} is provided, the type is specified by the
suffix. Suffixes \terminal{i}, \terminal{u},  and \terminal{z} shall
respectively refer to the \terminal{int}, \terminal{uint}, and \terminal{size}
types; the remainder shall refer to the type named by the suffix.

\specsubitem
If the number provided is not within the limits of the precision of the
constant type, a diagnostic message shall be printed and the translation phase
shall fail.

\specsubitem
The prefixes \terminal{0x}, \terminal{0o}, and \terminal{0b} shall respectively
cause the number to be interpreted with a hexadecimal, octal, or binary base.
If no prefix is used, the number shall be interpreted with a decimal base.

\specsubitem
If the \nonterminal{exponent} is provided, the value of the
integer shall be multiplied by 10 to the power of \nonterminal{decimal-digits}.

\specsubsection{Rune constants}
\begin{grammar}
\nonterminaldef{rune-constant} \\
\terminal{'} \nonterminal{rune} \terminal{'} \\

\nonterminaldef{rune} \\
\norm{Any character other than \terminal{\textbackslash} or \terminal{'}} \\
\nonterminal{escape-sequence} \\

\nonterminaldef{escape-sequence} \exactly \\
\nonterminal{named-escape} \\
\terminal{\textbackslash{}x} \nonterminal{hex-digit} \nonterminal{hex-digit} \\
\terminal{\textbackslash{}u} \nonterminal{fourbyte} \\
\terminal{\textbackslash{}U} \nonterminal{eightbyte} \\

\nonterminaldef{fourbyte} \exactly \\
\nonterminal{hex-digit} \nonterminal{hex-digit} \nonterminal{hex-digit} \nonterminal{hex-digit} \\

\nonterminaldef{eightbyte} \exactly \\
\nonterminal{fourbyte} \nonterminal{fourbyte} \\

\nonterminaldef{named-escape} \oneof \\
\terminal{\textbackslash0}
\terminal{\textbackslash{}a}
\terminal{\textbackslash{}b}
\terminal{\textbackslash{}f}
\terminal{\textbackslash{}n}
\terminal{\textbackslash{}r}
\terminal{\textbackslash{}t}
\terminal{\textbackslash{}v}
\terminal{\textbackslash\textbackslash}
\terminal{\textbackslash'}
\terminal{\textbackslash"} \\
\end{grammar}

\specsubsubitem
If the \nonterminal{rune-constant} is not an \nonterminal{escape-sequence}, the
value of the rune shall be the Unicode codepoint representing
\nonterminal{rune}.

\specsubsubitem
A \nonterminal{rune-constant} beginning with \terminal{\textbackslash{}x},
\terminal{\textbackslash{}u}, or \terminal{\textbackslash{}U} shall interpet
its value as a Unicode codepoint specified in its hexadecimal representation by
\nonterminal{hex-digit}s.

\specsubsubitem
A \nonterminal{rune-constant} containing a \nonterminal{named-escape} shall have
a value based on the following chart:

\begin{tabular}{r | l | r | l}
Escape sequence & Unicode codepoint & Escape sequence & Unicode codepoint \\
\hline
\terminal{\textbackslash0} & \code{U+0000} &
\terminal{\textbackslash{}a} & \code{U+0007} \\
\terminal{\textbackslash{}b} & \code{U+0008} &
\terminal{\textbackslash{}f} & \code{U+000C} \\
\terminal{\textbackslash{}n} & \code{U+000A} &
\terminal{\textbackslash{}r} & \code{U+000D} \\
\terminal{\textbackslash{}t} & \code{U+0009} &
\terminal{\textbackslash{}v} & \code{U+000B} \\
\terminal{\textbackslash\textbackslash} & \code{U+005C} &
\terminal{\textbackslash'} & \code{U+002C} \\
\terminal{\textbackslash"} & \code{U+0022} \\
\end{tabular}

\specsubsection{String constants}

\begin{grammar}
\nonterminaldef{string-constant} \\
\terminal{"} \nonterminal{string-chars} \terminal{"} \\
\nonterminal{string-constant} \nonterminal{string-constant} \\

\nonterminaldef{string-chars} \\
\nonterminal{string-char} \optional{\nonterminal{string-chars}} \\

\nonterminaldef{string-char} \\
\norm{Any character other than \terminal{\textbackslash} or \terminal{"}} \\
\nonterminal{escape-sequence} \\
\end{grammar}

\specsubsubitem
A \nonterminal{string-constant} expression shall have a result type of
\terminal{const} \terminal{str}.

\specsubsubitem
If the first form of \nonterminal{string-constant} is used, the string's
\textit{data} field shall refer to a UTF-8 encoded sequence of Unicode
codepoints, ascertained by encoding the sequence of \nonterminal{string-char}s
given in order, after interpreting escape codes per
\subsubitemref{Rune constants}{17}.

\specsubsubitem
If the second form of \nonterminal{string-constant} is used, the string's
\textit{data} field shall refer to a UTF-8 encoded sequence of Unicode
codepoints, ascertained by concatenating the \textit{data} field of the first
\nonterminal{string-constant} and the \textit{data} field of the second
\nonterminal{string-constant}.

\specsubsubitem
The \textit{length} and \textit{capacity} fields shall be set to the length in
octets of the encoded UTF-8 data.

\specsubsection{Array literals}

\begin{grammar}
\nonterminaldef{array-literal} \\
\terminal{[} \optional{\nonterminal{array-members}} \terminal{]} \\

\nonterminaldef{array-members} \\
\nonterminal{expression} \optional{\terminal{,}} \\
\nonterminal{expression} \terminal{...} \optional{\terminal{,}} \\
\nonterminal{expression} \terminal{,} \nonterminal{array-members} \\
\end{grammar}

Forward references: \subsecref{Simple, complex, and compound expressions}

\specsubsubitem
An \nonterminal{array-literal} expression produces a value of an array type.
The type of each \nonterminal{expression} shall be uniform and shall
determine the member type of the array value, and the length of the array type
shall be defined by the number of members.

\specsubsubitem
If a type hint has been provided to an array literal which is an array type (or
a type alias which represents an array type), the member type will be inferred
from this array type. The initializer expressions for each value among
\nonterminal{array-members} shall receive this member type as a type hint. If
the \nonterminal{array-members} is not specified, a type hint must be provided.

\specsubsubitem
The execution environment shall evaluate the \nonterminal{array-members},
ordered such that any side-effects of evaluating the arguments occur in the
order that the members are listed, such that the \textit{N}th member provides
the value for the \textit{N}th array member.

\specsubsubitem
If the \terminal{...} form is used, the result's array type shall be expandable.
If a type hint is available, it shall not be of a context-defined array type.

\specsubsection{Enum literals}

\begin{grammar}
\nonterminaldef{enum-literal} \exactly \\
\nonterminal{identifier} \terminal{::} \nonterminal{name} \\
\end{grammar}

\specsubsubitem
An \nonterminal{enum-literal} expression produces a value of an enum type. The
\nonterminal{identifier} shall be a type alias (see \subsecref{Type aliases})
which refers to an enum type. The result type shall be the type alias to which
the \nonterminal{identifier} refers.

\specsubsubitem
The enum type to which the type alias refers shall have an
\nonterminal{enum-value} whose name is the \nonterminal{enum-literal}'s
\nonterminal{name}. The result of the \nonterminal{enum-literal}
shall be the value assigned to this \nonterminal{enum-value}. If there is no
such \nonterminal{enum-value}, a diagnostic message shall be printed and the
translation phase shall abort.

\specsubsection{Struct literals}

\begin{grammar}
\nonterminaldef{struct-literal} \\
\terminal{struct} \terminal{\{} \nonterminal{field-values} \optional{\terminal{,}} \terminal{\}} \\
\nonterminal{identifier} \terminal{\{} \nonterminal{struct-initializer} \optional{\terminal{,}} \terminal{\}} \\

\nonterminaldef{struct-initializer} \\
\nonterminal{field-values} \\
\nonterminal{field-values} \terminal{,} \terminal{...} \\
\terminal{...} \\

\nonterminaldef{field-values} \\
\nonterminal{field-value} \\
\nonterminal{field-values} \terminal{,} \nonterminal{field-value} \\

\nonterminaldef{field-value} \\
\nonterminal{name} \terminal{=} \nonterminal{expression} \\
\nonterminal{name} \terminal{:} \nonterminal{type} \terminal{=} \nonterminal{expression} \\
\nonterminal{struct-literal} \\
\end{grammar}

\specsubsubitem
A \nonterminal{struct-literal} produces a value of a struct type. The first
form is the \textit{plain form}, and the second form is the \textit{named form}.

\specsubsubitem
If the plain form is given, the result type shall be a struct type defined by
the \nonterminal{field-value}s, in order, with their identifiers and types
explicitly specified. The first form of \nonterminal{field-value} shall not be
used in such a struct.

\specsubsubitem
If the named form is given, the \nonterminal{identifier} shall identify a type
alias (see \subsecref{Type aliases}) which refers to a struct type. The result
type shall be this alias type.

\specsubsubitem
Each \nonterminal{field-value} shall specify a field by its \nonterminal{name},
and assign that field in the result value to the result of the expression
given. The type of the named field, via the named type alias in the first form,
or the given type in the second form, shall be provided to the initializer
expression as a type hint.

\specsubsubitem
If \terminal{...} is not given, \nonterminal{field-values} shall be
\textit{exhaustive}, and include every field of the result type exactly once.
Otherwise, a diagnostic message shall be printed and the translation phase
shall abort.

\specsubsubitem
If \terminal{...} is given, any fields of the result type which are not
included in \nonterminal{field-values} shall be initialized to their default
values. Each included field shall only be named once. If a field is omitted
which does not have a default value, a diagnostic message shall be printed and
the translation phase shall abort.

\specsubsubitem
If the \nonterminal{struct-literal} form of the \nonterminal{field-value} is
given, its fields shall be interpreted as fields of the parent struct.

\informative{The following values are equivalent: \\
\code{struct \{ a: int = 10, b: int = 20 \}} \\
\code{struct \{ a: int = 10, struct \{ b: int = 20 \} \}}}

\specsubsection{Plain expressions}

\begin{grammar}
\nonterminaldef{plain-expression} \\
\nonterminal{identifier} \\
\nonterminal{constant} \\
\nonterminal{array-literal} \\
\nonterminal{enum-literal} \\
\nonterminal{struct-literal} \\

\nonterminaldef{nested-expression} \\
\nonterminal{plain-expression} \\
\terminal{(} \nonterminal{expression} \terminal{)} \\
\terminal{(} \nonterminal{tuple-items} \terminal{)} \\

\nonterminaldef{tuple-items} \\
\nonterminal{expression} \terminal{,} \nonterminal{expression} \optional{\terminal{,}} \\
\nonterminal{expression} \terminal{,} \nonterminal{tuple-items} \\
\end{grammar}

Forward references: \subsecref{Simple, complex, and compound expressions}

\specsubsubitem
\nonterminal{plain-expression} is an expression class which represents its
result value "plainly". In the case of constants and literals, the value is
represented by the result of those expressions. In the case of an
\nonterminal{identifier}, the expression produces the value of the identified
object.

\specsubsubitem
\nonterminal{nested-expression} is an expression class provided to allow the
programmer to overcome undesirable associativity between operators.

\specsubsubitem
The \nonterminal{tuple-items} form of \nonterminal{nested-expression} shall
describe a \textit{tuple expression}, and have a result type which is the tuple
described by the types of its \nonterminal{expression}s in the order that they
appear. If a type hint is available, the tuple items may be assigned to the
types of the respective tuple sub-types in the order that they appear. The
implementation shall cause the side-effects of each \nonterminal{expression} to
occur in the order that they appear.

\specsubsection{Allocations}

\begin{grammar}
\nonterminaldef{allocation-expression} \\
\terminal{alloc} \terminal{(} \nonterminal{expression} \terminal{)} \\
\terminal{alloc} \terminal{(} \nonterminal{expression} \terminal{,} \nonterminal{expression} \terminal{)} \\
\terminal{free} \terminal{(} \nonterminal{expression} \terminal{)} \\
\end{grammar}

\specsubsubitem
An \nonterminal{allocation-expression} is used to manipulate objects allocated
in the execution environment.

\specsubsubitem
In the \terminal{alloc} form, the \nonterminal{expression} is the initializer
for a new object whose type shall be inferred from the type hint. If this type
is a slice, the result type of \terminal{alloc} shall be that slice type, and
the initializer shall be provided that slice type as a type hint. If the type
hint is a pointer type, the result type shall be that type, and the initializer
provided the pointer type's secondary as its type hint. In the case of any other
type hint, or no type hint, the result type shall be a pointer type whose
secondary is the result type of the initializer, and the initializer shall not
be given a type hint.

\specsubsubitem
In the case of an \terminal{alloc} of a pointer type, the execution environment
shall allocate storage sufficient to store a value of the referent type, and
initialize it to the value provided by \nonterminal{expression}. The pointer's
referent type shall have a defined, nonzero size.

\specsubsubitem
In the case of an \terminal{alloc} of a slice type, the execution environment
shall choose a capacity which shall be greater than or equal to the number of
items in the initializer, then allocate an array of that capacity and set each
$N$th value to the $N$th value of the initializer, for each value of $N$
between $0$ (inclusive) and the length of the initializer (exclusive).  The
result shall be a slice whose data field refers to this array, whose length is
equal to the length of the initializer, and whose capacity is set to the
allocated capacity.

% TODO: Allow implementation to over-allocate with a given capacity
\specsubsubitem
If the second form of \terminal{alloc} is used, the \nonterminal{type} shall
specify a slice type, and the second term shall be assignable to
\terminal{size}.  The second term shall specify the capacity, which shall be
greater than or equal to the length of the initializer. The execution
environment shall use this capacity rather than one of its own choosing, and in
other respects the semantics shall be the same as the first form.

\specsubsubitem
In the \terminal{alloc} form, if the execution environment is unable to
allocate sufficient storage for the requested type, the execution environment
shall print a diagnostic message and abort. If the type is a nullable pointer
type, \terminal{null} shall be returned instead of aborting.

\specsubsection{Assertions}

\begin{grammar}
\nonterminaldef{assertion-expression} \\
\terminal{assert} \terminal{(} \nonterminal{expression} \terminal{)} \\
\terminal{assert} \terminal{(} \nonterminal{expression} \terminal{,} \nonterminal{string-constant} \terminal{)} \\
\terminal{static} \terminal{assert} \terminal{(} \nonterminal{expression} \terminal{)} \\
\terminal{static} \terminal{assert} \terminal{(} \nonterminal{expression} \terminal{,} \nonterminal{string-constant} \terminal{)} \\
\terminal{abort} \terminal{(} \optional{\nonterminal{string-constant}} \terminal{)} \\
\terminal{static} \terminal{abort} \terminal{(} \optional{\nonterminal{string-constant}} \terminal{)} \\
\end{grammar}
% TODO: Specify the calling semantics for sys::assert and sys::abort
% Blocked until we start specifying the runtime library details

Forward references: \subsecref{Simple, complex, and compound expressions}

\specsubsubitem
An \nonterminal{assertion-expression} is used to validate an assumption by the
programmer by \textit{asserting} its truth. The result type of a
\nonterminal{assertion-expression} is \terminal{void}.

\specsubsubitem
\nonterminal{expression} shall be an expression of type \terminal{bool}, which
shall be provided to it as a type hint.

\specsubsubitem
In the first two forms, this expression shall be evaluated
in the execution environment, and if false, a diagnostic message shall be
printed and the execution phase aborted. The programmer may provide the
\nonterminal{string-constant} to be included in the diagnostic message.

\specsubsubitem
In the \terminal{static} form, \nonterminal{expression} shall be limited to the
\secref{Translation compatible expression subset}, shall be evaluated in the
translation environment, and is otherwise equivalent to the other forms.

\specsubsubitem
The \terminal{abort} form shall cause the execution environment to print a
diagnostic message and abort. The programmer may provide the
\nonterminal{string-constant} to be included in the diagnostic message. An
abort is a terminating expression.

\specsubsection{Calls}

\begin{grammar}
\nonterminaldef{call-expression} \\
\nonterminal{postfix-expression} \terminal{(} \optional{\nonterminal{argument-list}} \terminal{)} \\

\nonterminaldef{argument-list} \\
\nonterminal{expression} \optional{\terminal{,}} \\
\nonterminal{expression} \terminal{...} \optional{\terminal{,}} \\
\nonterminal{expression} \terminal{,} \nonterminal{argument-list} \\
\end{grammar}

Forward references: \subsecref{Simple, complex, and compound expressions}

\specsubsubitem
A \nonterminal{call-expression} shall invoke a function in the execution
environment and its result shall be a value of the type specified by the
\nonterminal{postfix-expression}'s function result type. This evaluation shall
include any necessary side-effects per \subsubitemref{Program execution}{1}.

\specsubsubitem
The result type of the \nonterminal{postfix-expression} shall be restricted to a
set which includes all function types which do not have the \terminal{@init},
\terminal{@fini}, or \terminal{@test} attributes set, as well as non-nullable
pointers whose secondary type is included in the set.

\informative{The result type of the \nonterminal{postfix-expression} can be a
function, a pointer to a function, a pointer to a pointer to a function, and so
on.}

\specsubsubitem
The function invoked shall be the function object the
\nonterminal{postfix-expression} refers to, selecting that object indirectly via
any number of pointer types if appropriate.

\specsubsubitem
The \nonterminal{argument-list} shall be a list of expressions whose types
shall be assignable to the types of the invoked function's parameters, in the
order that they are declared in the invoked function's result type. The types
specified in the function's prototype shall be provided as type hints to each
argument expression as appropriate.

\specsubsubitem
The execution environment shall evaluate the \nonterminal{argument-list},
ordered such that any side-effects of evaluating the arguments occur in the
order that the arguments are listed, to obtain the parameter values required to
invoke the function.

\specsubsubitem
If the invoked function uses Hare-style variadism, the
\nonterminal{argument-list} shall provide zero or more arguments following the
last non-variadic parameter, all of which must be assignable to the type of the

\specsubsubitem
If the final argument uses the \terminal{...} form, it must occupy the position of a
variadic parameter and be of a slice or array type. The implementation shall
interpret this value as the list of variadic parameters.

\specsubsubitem
If the invoked function uses C-style variadism, the function may provide zero
or more arguments following the final parameter. These arguments shall be of a
type with a non-zero size, but are otherwise unconstrained.

\specsubsubitem
The specific means by which the invoked function assumes control of the
execution environment, and by which the arguments are provided to it, is
implementation-defined.

\informative{This is generally provided by the target's ABI specification.}

\specsubsubitem
If the invoked function's result type has the \terminal{@noreturn} attribute,
the call expression is considered to terminate.

\specsubsection{Measurements}

\begin{grammar}
\nonterminaldef{measurement-expression} \\
\nonterminal{size-expression} \\
\nonterminal{length-expression} \\
\nonterminal{offset-expression} \\

\nonterminaldef{size-expression} \\
\terminal{size} \terminal{(} \nonterminal{type} \terminal{)} \\

\nonterminaldef{length-expression} \\
\terminal{len} \terminal{(} \nonterminal{expression} \terminal{)} \\

\nonterminaldef{offset-expression} \\
\terminal{offset} \terminal{(} \nonterminal{field-access-expression} \terminal{)} \\
\end{grammar}

Forward references: \subsecref{Field access}

\specsubsubitem
A \nonterminal{measurement-expression} is used to measure objects. The result
type shall be \terminal{size}.

\specsubsubitem
The \terminal{size} expression shall compute the \textit{size} of the specified
\nonterminal{type}.

\specsubsubitem
The \terminal{len} expression shall compute the \textit{length} of a bounded
array, or the \code{length} field of a slice object, referred to by
\nonterminal{expression}. If an unbounded array object is given, the translation
environment shall print a diagnostic message and abort.

\specsubsubitem
The \terminal{offset} expression shall determine the struct or tuple field
which would be accessed by \nonterminal{field-access-expression} and compute
its \textit{offset}.

\specsubsection{Field access}

\begin{grammar}
\nonterminaldef{field-access-expression} \\
\nonterminal{postfix-expression} \terminal{.} \nonterminal{name} \\
\nonterminal{postfix-expression} \terminal{.} \nonterminal{integer-constant} \\
\end{grammar}

\specsubsubitem
A \nonterminal{field-access-expression} is used to access fields of
\subsecref{Struct and union types} and \subsecref{Tuple types}. The result type
of the \nonterminal{postfix-expression} shall be constrained to a set which
includes all struct, union, and tuple types, as well as non-nullable pointers
whose secondary type is included in the set.

\informative{The result type of the \nonterminal{postfix-expression} can be a
struct or union or tuple, a pointer to a struct or union or tuple, a pointer to
a pointer to a struct or union or tuple, and so on.}

\specsubsubitem
The object from which the field is selected shall be the struct or union object
the \nonterminal{postfix-expression} refers to, selecting that object indirectly
via any number of pointer types if appropriate.

\specsubsubitem
If the \nonterminal{postfix-expression}'s result type is a union type, the
first form shall be used. The result of the
\nonterminal{field-access-expression} shall be the union's storage area
interpreted as the type of the field named by \nonterminal{name}, and the
result type of the expression shall be the type of the named field.

\specsubsubitem
If the \nonterminal{postfix-expression}'s result type is a struct type, the
first form shall be used. The result of the
\nonterminal{field-access-expression} shall be the value stored in the
\nonterminal{name} field of the result of the \nonterminal{postfix-expression},
and the result type of the expression shall be the type of the named field.

\specsubsubitem
If the \nonterminal{postfix-expression}'s result type is a tuple type,
the second form shall be used. The result of the
\nonterminal{field-access-expression} shall be the $N$th value stored in the
tuple which is the result of the \nonterminal{postfix-expression}, and the
result type of the expression shall be the type of the $N$th value.

\specsubsubitem
If the type of the struct object in the first term has the \terminal{const}
flag, the result type shall also have the \terminal{const} flag set, regardless
of the flag's value on the type of the named field.

\specsubsection{Indexing}

\begin{grammar}
\nonterminaldef{indexing-expression} \\
\nonterminal{postfix-expression} \terminal{[} \nonterminal{expression} \terminal{]} \\
\end{grammar}

\specsubsubitem
An \nonterminal{indexing-expression} shall access a specific value of a slice
or array type. The \nonterminal{expression} shall have an integer result type.
The result type of the \nonterminal{postfix-expression} shall be constrained to
a set which includes all slice and array types, as well as non-nullable pointers
whose secondary type is included in the set.

\informative{The result type of the \nonterminal{postfix-expression} can be a
slice or array, a pointer to a slice or array, a pointer to a pointer to a
slice or array, and so on.}

\specsubsubitem
The object from which the field is selected shall be the slice or array object
the \nonterminal{postfix-expression} refers to, selecting that object indirectly
via any number of pointer types if appropriate.

\specsubsubitem
The result type of an \nonterminal{indexing-expression} is the secondary type
of the slice or array type given by the \nonterminal{postfix-expression} result
type.

\specsubsubitem
If the type of the array or slice object in the first term has the
\terminal{const} flag, the result type shall also have the \terminal{const}
flag set, regardless of the flag's value on the secondary type.

\specsubsubitem
The execution environment shall compute the result of
\nonterminal{expression} to obtain $N$ for selecting the \textit{N} per the
algorithm given in \subsecref{Slice and array types}.

\specsubsubitem
The execution environment shall perform a \textit{bounds test} on the value of
$N$ to ensure it falls within the acceptable range for the given slice or array
type. It shall test that $N < Z$, where $Z$ is the length of the bounded array
type, or the \code{length} field of the slice, whichever is appropriate.  For
unbounded array types, the bounds test shall not occur. If the bounds test
fails, a diagnostic message shall be printed and the execution environment
shall abort.

The implementation may perform a bounds test in the translation environment if
is able, print a diagnostic message, and abort the translation environment if
it fails.

\specsubsection{Slicing}

\begin{grammar}
\nonterminaldef{slicing-expression} \\
\nonterminal{postfix-expression} \terminal{[} \optional{\nonterminal{expression}} \terminal{..} \optional{\nonterminal{expression}} \terminal{]} \\
\end{grammar}

\specsubsubitem
A \nonterminal{slicing-expression} shall have a result type of
\nonterminal{slice}, which is computed a subset of a slice or array object.
The optional \nonterminal{expression}s shall have an integer result type. The
result type of the \nonterminal{postfix-expression} shall be constrained to
a set which includes all slice and array types, as well as non-nullable pointers
whose secondary type is included in the set.

\informative{The result type of the \nonterminal{postfix-expression} can be a
slice or array, a pointer to a slice or array, a pointer to a pointer to a
slice or array, and so on.}

\specsubsubitem
The object from which the field is selected shall be the slice or array object
the \nonterminal{postfix-expression} refers to, selecting that object indirectly
via any number of pointer types if appropriate.

\specsubsubitem
The first \nonterminal{expression} shall compute value $L$, and the second shall
compute $H$. If absent, $L = 0$ and $H = \code{length}$, where \code{length}
shall be equal to the length of a bounded array type or the length of a slice
type, represented in either case by the result of
\nonterminal{postfix-expression}. If $H$ is not specified, and
\nonterminal{postfix-expression} is of an unbounded array type, the translation
environment shall abort.

\specsubsubitem
The resulting slice value shall have its \code{data} field set from, in the case
of an array type, the address of the array; or in the case of a slice type, the
\code{data} value of the source object; plus $L \times S$, where $S$ is the
size of the slice or array's secondary type.

\specsubsubitem
The resulting slice value shall have its \code{length} field set to $H - L$,
and its capacity field set to the \code{length} of the source object minus $L$.

\specsubsubitem
The secondary type of the resulting slice type shall be equivalent to the
secondary type of the slice or array type given by
\nonterminal{postfix-expression}. The resulting slice type shall inherit the
\nonterminal{const} attribute from this type.

\specsubsection{Slice mutation}

\begin{grammar}
\nonterminaldef{slice-mutation-expression} \\
\optional{\terminal{static}} \terminal{append} \terminal{(} \nonterminal{slice-reference} \terminal{,} \nonterminal{append-values} \terminal{)} \\
\optional{\terminal{static}} \terminal{delete} \terminal{(} \nonterminal{indexing-expression} \terminal{)} \\
\optional{\terminal{static}} \terminal{delete} \terminal{(} \nonterminal{slicing-expression} \terminal{)} \\
\optional{\terminal{static}} \terminal{insert} \terminal{(} \nonterminal{indexing-expression} \terminal{,} \nonterminal{append-values} \terminal{)} \\

\nonterminaldef{slice-reference} \\
\nonterminal{object-selector} \\
\terminal{*} \nonterminal{unary-expression} \\

\nonterminaldef{append-values} \\
\nonterminal{expression} \optional{\terminal{,}} \\
\nonterminal{expression} \terminal{...} \optional{\terminal{,}} \\
\nonterminal{expression} \terminal{,} \nonterminal{append-values} \\
\end{grammar}

\specsubsubitem
The \terminal{append} form shall append a new value, or values, to a slice
object specified by the first argument. The \nonterminal{expression}'s result
type shall be a mutable slice type. This slice type's member type shall be the
\terminal{append}'s \textit{member type}. The result of an \terminal{append}
shall be \terminal{void}.

\specsubsubitem
The \nonterminal{expression} of the first and third cases of
\nonterminal{append-values} shall have result types assignable to the
\terminal{append}'s member type. The \nonterminal{expression} of the second case
of \nonterminal{append-values} shall have a result type assignable to the result
type of the \terminal{append}'s \nonterminal{expression}.

\specsubsubitem
The \terminal{append} shall increase the slice object's capacity, and
potentially re-allocate its data field, in order to ensure that the capacity is
large enough to store the current contents of the slice as well as the values
appended by the \terminal{append}.

\specsubsubitem
The results of each \nonterminal{expression} in the \nonterminal{append-values}
shall be appended to the slice object in the order in which they appear. If the
second case of the \nonterminal{append-values} is specified, each of its members
shall be appended to the slice object in order.

\specsubsubitem
The side-effects of the \terminal{append}'s \nonterminal{expression} shall occur
before the side-effects of the \nonterminal{append-values}. The
side-effects of the \nonterminal{append-values}' \nonterminal{expression}s shall
occur in the order in which they appear.

\specsubsubitem
The \terminal{delete} form shall delete a section of a slice object specified by
the \nonterminal{slicing-expression} or \nonterminal{indexing-expression}'s
\nonterminal{postfix-expression}. The \nonterminal{postfix-expression} shall
have a slice result type.

\specsubsubitem
The \terminal{delete} form shall remove the members selected by the
\nonterminal{slicing-expression} or \nonterminal{indexing-expression} from the
data field of the slice object. If there is at least one member which follows
the selected members, they shall be moved such that the first member following
the selected members is moved to the index of the first selected member and each
member following it maintains its position relative to the first selected
member. The \nonterminal{delete} may decrease the slice object's capacity, and
potentially re-allocate its data field, so long as the new capacity is large
enough to store the new contents of the slice.

\specsubsubitem
The \terminal{insert} form shall ensure that the slice has sufficient capacity
to store the items from \nonterminal{append-values} by reallocating the slice
if necessary, then moving the items from the index specified by
\nonterminal{indexing-expression} (including the indexed item itself) forward
by the number of places required to insert the \nonterminal{append-values},
then inserting the appended values into the new space. The side-effects of the
\nonterminal{indexing-expression} shall occur first, followed by the side
effects of each appended value the order that they appear.

\specsubsubitem
The \terminal{static} forms of each of these expressions shall be equivalent to
the non-static forms except that they shall never cause the underlying slice to
be resized. In the static form, if an operation would require more space than
the current capacity of the slice provides, the implementation shall print a
diagnostic message and abort the execution environment.

\specsubsection{Error propagation}

\begin{grammar}
\nonterminaldef{error-propagation} \\
\nonterminal{postfix-expression} \terminal{?} \\
\nonterminal{postfix-expression} \terminal{!} \\
\end{grammar}

\specsubsubitem
\terminal{?} and \terminal{!} are the error propagation operators. The
\nonterminal{postfix-expression} shall have a result type which is either a
type with the error flag set, or a tagged union type which has a type with the
error flag set among its member types.

\specsubsubitem
The result type of an error propagation expression shall be the same as the
type of the \nonterminal{postfix-expression}, without its error cases, or
\terminal{void} if no non-error types remain. The result is a tagged union
whose member types are the subset of the original type which do not include the
error flag; or, if there is only one such type, that type without a tagged
union; or, if there are no such types, \terminal{void}. If the original type is
not a tagged union type, the translation phase shall abort with a diagnostic
message.

\specsubsubitem
An error propagation expression shall perform an \textit{error test} which
checks if the result value of the \nonterminal{postfix-expression} is of a
non-error type. If so, that value shall be the result of the error propagation
expression.

\specsubsubitem
In the \terminal{?} form, if the error test fails (i.e. an error is found), the
error type shall be assignable to the current function's return type, and that
value shall be returned from the function, causing the function to terminate.

\specsubsubitem
In the \terminal{!} form, if the error test fails (i.e. an error is found), the
execution environment shall print a diagnostic message and abort.

\specsubsubitem
If a type hint is provided to the error propagation expression, the same type
shall be provided to the \nonterminal{postfix-expression}.

\specsubsection{Postfix expressions}

\begin{grammar}
\nonterminaldef{postfix-expression} \\
\nonterminal{nested-expression} \\
\nonterminal{call-expression} \\
\nonterminal{field-access-expression} \\
\nonterminal{indexing-expression} \\
\nonterminal{slicing-expression} \\
\nonterminal{error-propagation} \\

\nonterminaldef{object-selector} \\
\nonterminal{identifier} \\
\nonterminal{indexing-expression} \\
\nonterminal{field-access-expression} \\
\end{grammar}

\specsubsubitem
\nonterminal{postfix-expression} is an expression class for expressions whose
operators use postfix notation.

\specsubsubitem
\nonterminal{object-selector} defines a subset of postfix expressions which
refer to objects, for use in other parts of the grammar.

\specsubsection{Builtin expressions}

\begin{grammar}
\nonterminaldef{builtin-expression} \\
\nonterminal{allocation-expression} \\
\nonterminal{assertion-expression} \\
\nonterminal{deferred-expression} \\
\nonterminal{measurement-expression} \\
\nonterminal{slice-mutation-expression} \\
\nonterminal{postfix-expression} \\
\end{grammar}

\specsubsection{Unary arithmetic}

\begin{grammar}
\nonterminaldef{unary-expression} \\
\nonterminal{builtin-expression} \\
\nonterminal{unary-operator} \nonterminal{unary-expression} \\
\terminal{\&} \nonterminal{object-selector} \\

\nonterminaldef{unary-operator} \oneof \\
\terminal{+}
\terminal{-}
\terminal{\textasciitilde}
\terminal{!}
\terminal{*}
\end{grammar}

\specsubsubitem
A unary expression applies a \nonterminal{unary-operator} to a single value.

\specsubsubitem
The \terminal{+} and \terminal{-} operators shall respectively perform unary
positive and unary negation operations. The result type shall be equivalent to
the type of \nonterminal{unary-expression}, which shall be of a signed numeric
type.

\specsubsubitem
The \terminal{\textasciitilde} operator shall perform a binary NOT operation,
inverting each bit of the value. Its result type shall be equivalent to the
type of \nonterminal{unary-expression}, which shall be of an unsigned integer
type.

\specsubsubitem
The \terminal{!} operator shall perform a logical NOT operation. The result
type, and the type of \nonterminal{unary-expression}, shall both be
\terminal{bool}. If the \nonterminal{unary-expression} is \terminal{true}, the
result shall be \terminal{false}, and vice-versa.

\specsubsubitem
The \terminal{*} operator shall dereference a pointer, and return the object it
references.  The type of \nonterminal{unary-expression} shall be a pointer
type, and the result type shall be the pointer's secondary type. The pointer
type shall not be \textit{nullable}.

\specsubsubitem
The \terminal{\&} operator shall take the address of an object. The result type
shall be a pointer whose secondary type is the type of the object selected by
\nonterminal{object-selector}.

\informative{The following table is informative.}

\begin{tabular}{r | l }
Operator & Meaning \\
\hline
\terminal{+} & Positive \\
\terminal{-} & Negation \\
\terminal{\textasciitilde} & Binary NOT \\
\terminal{!} & Logical NOT \\
\terminal{*} & Dereference pointer \\
\end{tabular}

\specsubsection{Casts and type assertions}

\begin{grammar}
\nonterminaldef{cast-expression} \\
\nonterminal{unary-expression} \\
\nonterminal{cast-expression} \terminal{:} \nonterminal{type} \\
\nonterminal{cast-expression} \terminal{as} \nonterminal{type} \\
\nonterminal{cast-expression} \terminal{is} \nonterminal{type} \\
\end{grammar}

\specsubsubitem
A cast expression interrogates or converts the type of an object. The first
form illustrates the precedence. The second and third forms (\terminal{:} and
\terminal{as}) have a result type specified by the \nonterminal{type}; and the
fourth form (\terminal{is}) has a result type of \terminal{bool}.

\specsubsubitem
Each form shall provide the specified \nonterminal{type} as a type hint to its
\nonterminal{cast-expression}.

\specsubsubitem
The second form is a \textit{type cast}, and shall not fail. It shall cause the
execution environment to convert or interpret the value as another type.

\specsubsubitem
A type which may be cast to another type is considered \textit{castable} to
that type.

\specsubsubitem
All types are castable to themselves. The set of other types which are castable
to a given type are given by the following table:

\begin{tabular}{r | l}
Source type & Casts to \\
\hline
Floating types & Any numeric type \\
Integer types & Any numeric type or enum type \\
\terminal{uintptr} & Any pointer type or \terminal{null} \\
Any pointer type & Any pointer type, \terminal{uintptr}, or \terminal{null} \\
Enum types & Any enum type or numeric type \\
Array and slice types & Any array or slice type \\
Slice types & Any pointer to an array type \\
Type alias & Any type the underlying type could cast to \\
Any type & Any type alias with an underlying type it may be cast to \\
\terminal{u8} & \terminal{char} \\
\terminal{char} & \terminal{u8} \\
\terminal{rune} & \terminal{u32} \\
\terminal{u32} & \terminal{rune} \\
\terminal{null} & Any pointer type or \terminal{uintptr} \\
Tagged unions & See below \\
\end{tabular}

\specsubsubitem
Tagged union types are mutually castable with any type which is found among its
members, including the otherwise non-castable types of \terminal{bool} and
\terminal{void}, as well as any other tagged union type.

\specsubsubitem
When an integer type is cast to an integer of less precision, it shall be
truncated towards the least significant bit.

\specsubsubitem
When a signed type is cast to a unsigned type, the sign bit shall be copied to
the most significant bit of the unsigned type, and vice versa.

\specsubsubitem
When a floating type is cast to an integer, the resulting value shall be equal
to $I = \lfloor F \rfloor$, where F is the source value. If the destination type
has insufficient precision to represent $I$, it shall be truncated towards the
least significant bit.

\specsubsubitem
When casting an integer to a floating point type, if the destination type
lacks the precision to represent the value, it shall be truncated towards zero.

\specsubsubitem
Casting a pointer type to \nonterminal{uintptr}, and then back to the pointer
type, shall yield the same pointer.

\informative{However, casting \nonterminal{uintptr} to any other integer type
and back again may truncate towards the least significant bit and is not
guaranteed to yield the same pointer.}

\specsubsubitem
The \terminal{const} flag shall not affect the rules for casting one type to
another. The same holds for the error flag as well.

\specsubsubitem
The third form is a \textit{type assertion}. In this form,
\nonterminal{cast-expression} shall be of a tagged union type, and
\nonterminal{type} shall be a constituent type of that tagged union. The
\nonterminal{cast-expression} shall be computed, and if the tag does not match
\nonterminal{type}, a diagnostic message shall be printed and the execution
environment shall abort. Otherwise, the result type is \nonterminal{type}.

\specsubsubitem
The fourth form is a \textit{type test}. In this form,
\nonterminal{cast-expression} shall be of a tagged union type, and
\nonterminal{type} shall be a constituent type of that tagged union. The result
type is \terminal{bool}, and shall be \terminal{true} if the selected tag of
\nonterminal{cast-expression} is \nonterminal{type}, or \terminal{false}
otherwise.

\specsubsection{Multiplicative arithmetic}

\begin{grammar}
\nonterminaldef{multiplicative-expression} \\
\nonterminal{cast-expression} \\
\nonterminal{multiplicative-expression} \terminal{*} \nonterminal{cast-expression} \\
\nonterminal{multiplicative-expression} \terminal{/} \nonterminal{cast-expression} \\
\nonterminal{multiplicative-expression} \terminal{\%} \nonterminal{cast-expression} \\
\end{grammar}

\specsubsubitem
A \nonterminal{multiplicative-expression} multiplies (\terminal{*}), divides
(\terminal{/}), or obtains the remainder between (\terminal{\%}) two
expressions. The first form illustrates the precedence. The operands and result
type shall be subject to the \secref{Type promotion} rules.

\specsubsubitem
In the case of division or modulus, the first term is the dividend, and the
second term is the divisor.

\specsubsubitem
A modulus (\terminal{\%}) operation shall be performed with operands of integer
types only.

\specsubsubitem
If an operation would cause the result to overflow the result type, it is
truncated towards the least significant bits in the case of integer types, and
towards zero in the case of float types. Integer divisions which would produce
a fractional part are floored.

\specsubsubitem
The implementation shall ensure that any side-effects of the first term shall
occur before side-effects of the second term.

\begin{grammar}
\nonterminal{multiplicative-expression} \\
\end{grammar}

\specsubsubitem
subtracts (\terminal{-}) one from another. The first form illustrates the
precedence. The operands and result type shall be subject to the \secref{Type
promotion} rules.

\specsubsubitem
In the case of subtraction, the first term is the minuend, and the second term
is the subtrahend.

\specsubsubitem
If an operation would cause the result to overflow or underflow the result
type, it is truncated towards the least significant bits in the case of integer
types, and towards zero in the case of float types. In the case of signed
types, this truncation will cause the sign bit to change.

\specsubsubitem
The implementation shall ensure that any side-effects of the first term shall
occur before side-effects of the second term.

\specsubsection{Bit shifting arithmetic}

\begin{grammar}
\nonterminaldef{shift-expression} \\
\end{grammar}

\specsubsubitem
A \nonterminal{shift-expression} performs a bitwise left-shift
(\terminal{\textless{}\textless{}}) or right-shift (\terminal{\textgreater{}\textgreater{}}). The first
form illustrates the precedence. The result type shall be the type of the first
operand. Both operands shall be of unsigned integer types.

\specsubsubitem
\code{\nonterminal{shift-expression} \terminal{\textless{}\textless{}} $N$} shall shift
each bit towards the most significant bit $N$ places, and set the least
significant $N$ bits to zero. The $N$ most significant bits shall be silently
discarded. If $N$ is greater than the size in bits of the type, the result shall
be zero.

\informative{This operation is equivalent to multiplying
\nonterminal{shift-expression} by $2^N$}

\specsubsubitem
\code{\nonterminal{shift-expression} \terminal{\textgreater{}\textgreater{}}
$N$} shall shift each bit towards the least significant bit $N$ places. The most
significant bits shall be set to either zero or one depending on the signedness
of \nonterminal{shift-expression}: If it is signed, then the $N$ most
significant bits shall be set to the value of the sign bit. If it unsigned, then
the $N$ most significant bits shall be set to zero. The $N$ least significant
bits shall be silently discarded. If $N$ is greater than the size in bits of the
type, the result shall be zero.

\informative{This operation is equivalent to dividing
\nonterminal{shift-expression} by $2^N$}

\specsubsubitem
The implementation shall ensure that any side-effects of the first term shall
occur before side-effects of the second term.

\specsubsection{Bitwise arithmetic}

\begin{grammar}
\nonterminaldef{and-expression} \\
\nonterminal{shift-expression} \\
\nonterminal{and-expression} \terminal{\&} \nonterminal{shift-expression} \\

\nonterminaldef{exclusive-or-expression} \\
\nonterminal{and-expression} \\
\nonterminal{exclusive-or-expression} \terminal{\^} \nonterminal{and-expression} \\

\nonterminaldef{inclusive-or-expression} \\
\nonterminal{exclusive-or-expression} \\
\nonterminal{inclusive-or-expression} \terminal{|} \nonterminal{exclusive-or-expression} \\
\end{grammar}

\specsubsubitem
The implementation shall ensure that any side-effects of the first term shall
occur before side-effects of the second term.

\specsubsection{Logical comparisons}

\begin{grammar}
\nonterminaldef{comparison-expression} \\
\nonterminal{inclusive-or-expression} \\
\nonterminal{comparison-expression} \terminal{<} \nonterminal{inclusive-or-expression} \\
\nonterminal{comparison-expression} \terminal{>} \nonterminal{inclusive-or-expression} \\
\nonterminal{comparison-expression} \terminal{<=} \nonterminal{inclusive-or-expression} \\
\nonterminal{comparison-expression} \terminal{>=} \nonterminal{inclusive-or-expression} \\

\nonterminaldef{equality-expression} \\
\nonterminal{comparison-expression} \\
\nonterminal{equality-expression} \terminal{==} \nonterminal{comparison-expression} \\
\nonterminal{equality-expression} \terminal{!=} \nonterminal{comparison-expression} \\
\end{grammar}

\specsubsubitem
A \nonterminal{comparison-expression} determines which operand is lesser than
(\terminal{<}), greater than (\terminal{>}), less than or equal to
(\terminal{<=}), or greater than or equal to (\terminal{>=}) the other. The
operands shall be numeric, and are subject to the \secref{Type promotion}
rules.  The result type shall be \terminal{bool}.

\specsubsubitem
The result of the \terminal{<} operator shall be \terminal{true} if the first
operand is mathematically less than the second operand and \terminal{false}
otherwise.

\specsubsubitem
The result of the \terminal{>} operator shall be \terminal{true} if the first
operand is mathematically greater than the second operand and \terminal{false}
otherwise.

\specsubsubitem
The result of the \terminal{<=} operator shall be \terminal{true} if the
first operand is mathematically less than or equal to second operand
and \terminal{false} otherwise.

\specsubsubitem
The result of the \terminal{>=} operator shall be \terminal{true} if the first
operand is mathematically greater than or equal to second operand
and \terminal{false} otherwise.

\specsubsubitem
An \nonterminal{equality-expression} determines if two operands are equal to one
another. The result type is \terminal{bool}. If the types of the \terminal{==}
or \terminal{!=} operators are numeric, they shall be subject to
\subsecref{Type promotion}. Otherwise, each operand must be of the same type.

\specsubsubitem
The result of the \terminal{==} operator shall be \terminal{true} if the first
operand is equal to second operand in value, and \terminal{false} otherwise.

\specsubsubitem
The result of the \terminal{!=} operator shall be \terminal{true} if the first
operand is not equal to second operand in value, and \terminal{false} otherwise.

\specsubsubitem
If the type is \terminal{str}, an \nonterminal{equality-expression} shall be
\terminal{true} if both strings have the same length and octets, and
\terminal{false} otherwise.

\specsubsubitem
The implementation shall ensure that any side-effects of the first term shall
occur before side-effects of the second term.

\specsubsection{Logical arithmetic}

\begin{grammar}
\nonterminaldef{logical-and-expression} \\
\nonterminal{equality-expression} \\
\nonterminal{logical-and-expression} \terminal{\&\&} \nonterminal{equality-expression} \\

\nonterminaldef{logical-xor-expression} \\
\nonterminal{logical-and-expression} \\
\nonterminal{logical-xor-expression} \terminal{\textasciicircum\textasciicircum} \nonterminal{logical-and-expression} \\

\nonterminaldef{logical-or-expression} \\
\nonterminal{logical-xor-expression} \\
\nonterminal{logical-or-expression} \terminal{||} \nonterminal{logical-xor-expression} \\
\end{grammar}

\specsubsubitem
For all cases of logical arithmetic, both terms shall be of the \terminal{bool}
type, and the result type shall be \terminal{bool}.

\specsubsubitem
\terminal{\&\&} shall compute a logical and operation, and shall be
\terminal{true} if both terms are \terminal{true}, and false otherwise.

\specsubsubitem
\terminal{\textasciicircum\textasciicircum} shall be a logical exclusive or
operation, and shall be \terminal{true} if the terms are not equal to each
other, and \terminal{false} otherwise.

\specsubsubitem
\terminal{||} shall be a logical or operation, and shall be \terminal{true} if
either term is \terminal{true}, and \terminal{false} otherwise.

\specsubsubitem
If the first term of \nonterminal{logical-and-expression} is \terminal{false},
or the first term of \nonterminal{logical-or-expression} is \terminal{true},
the implementation shall ensure that the side-effects of the second term do not
occur.

\specsubsection{If expressions}

\begin{grammar}
\nonterminaldef{if-expression} \\
\terminal{if} \nonterminal{conditional-branch} \\
\terminal{if} \nonterminal{conditional-branch} \terminal{else} \nonterminal{if-expression} \\
\terminal{if} \nonterminal{conditional-branch} \terminal{else} \nonterminal{expression} \\

\nonterminaldef{conditional-branch} \\
\terminal{(} \nonterminal{expression} \terminal{)} \nonterminal{expression} \\
\end{grammar}

\specsubsubitem
An \nonterminal{if-expression} chooses which, if any, expression to evaluate
based on a logical criteria. In all forms, the result type of
\nonterminal{expression} shall be \terminal{bool}. If a type hint is provided,
the \nonterminal{expression} shall receive it as a type hint.

\specsubsubitem
When executing a \nonterminal{conditional-branch}, the implementation shall
evaluate the \\ \nonterminal{expression} (the \textit{condition}), and if
\terminal{true}, the implementation shall execute the corresponding
\nonterminal{expression} (the \textit{branch}), ensuring that all side-effects
occur. If the condition is \terminal{false}, the branch shall not be executed
and shall not cause side-effects.

\specsubsubitem
In the second form, the first \nonterminal{conditional-branch} shall be
executed. If it was \terminal{false}, the second-order
\nonterminal{if-expression} shall be executed; otherwise not. In the latter
case, any side-effects of the second condition or branch shall not occur.

\specsubsubitem
In the third form, the \nonterminal{conditional-branch} shall be executed. If
it was \terminal{false}, the \nonterminal{expression} shall be executed, and all
of its side-effects shall occur.

\specsubsubitem
In the first form, the result type is \terminal{void}. In the second form, the
result type is \terminal{void} unless the third form is present in the
$N^{th}$-order sub-expression for any value of $N$. In this case, and in the
case of the third form used in the first order, if the result types of each
branch are uniform, the result type of the expression as a whole shall be of
that type. If the types are not uniform, the result type shall be a tagged
union of the set of possible result types. The result value shall be selected
from the result of the branch which is executed.

\specsubsubitem
If a type hint is provided and all non-terminating branches are assignable to
that type, the result type shall be the type given by the type hint. If the
result types of all non-terminating cases are equivalent, the result type of
the if expression shall be the result type of the cases. Otherwise, the
result type shall be a tagged union of the set of the result types of the
non-terminating cases.

If all cases terminate, the result type shall be \terminal{void} and the if
expression shall terminate.

\specsubsection{For loops}

\begin{grammar}
\nonterminaldef{for-loop} \\
\optional{\nonterminal{label}} \terminal{for} \terminal{(} \nonterminal{for-predicate} \terminal{)} \nonterminal{expression} \\

\nonterminaldef{for-predicate} \\
\nonterminal{expression} \\
\nonterminal{binding-list} \terminal{;} \nonterminal{expression} \\
\nonterminal{expression} \terminal{;} \nonterminal{expression} \\
\nonterminal{binding-list} \terminal{;} \nonterminal{expression} \terminal{;} \nonterminal{expression} \\

\nonterminaldef{label}\exactly \\
\terminal{:} \nonterminal{name} \\
\end{grammar}
% XXX: We may want to narrow the afterthought's expression class

\specsubsubitem
A \nonterminal{for-loop} executes its \nonterminal{expression} zero or more
times, so long as a condition is true. Its result type is \terminal{void}.
If the \nonterminal{label} is present, the expression is \textit{labelled}, and
the label must be unique among all anscestors of the for loop which are
labelled.

\specsubsubitem
In the first form, \nonterminal{for-predicate} specifies the \textit{condition}
with its \nonterminal{expression}. In the second form, the
\nonterminal{binding-list} is the \textit{binding} and the expression is the
condition. In the second form, the first expression is the condition, and the
second expression is the \textit{afterthought}. In the third form, the
\nonterminal{binding-list} is the binding, and the two expressions are
respectively the condition and afterthought. The result type of the condition
shall be \terminal{bool}, and this shall be provided as a type hint.

\specsubsubitem
The implementation shall establish a new scope for the
\nonterminal{expression}, then, if present, it shall evaluate the
\nonterminal{binding} in this scope. The implementation shall then evaluate the
condition. If it is \terminal{true}, the \nonterminal{expression} shall be
evaluated and all of its side-effects shall occur; this process is an
\textit{iteration}. When the iteration is complete, the implementation shall
evaluate the afterthought, if present, and then repeat the process, until the
condition evaluates to \terminal{false}.

\specsubsection{Switch expressions}

\begin{grammar}
\nonterminaldef{switch-expression} \\
\terminal{switch} \terminal{(} \nonterminal{expression} \terminal{)} \terminal{\{} \nonterminal{switch-cases} \terminal{\}} \\

\nonterminaldef{switch-cases} \\
\nonterminal{switch-case} \optional{\terminal{,}} \\
\nonterminal{switch-case} \terminal{,} \nonterminal{switch-cases} \\

\nonterminaldef{switch-case} \\
\nonterminal{case-options} \terminal{=>} \nonterminal{expression} \\
\terminal{*} \terminal{=>} \nonterminal{expression} \\

\nonterminaldef{case-options} \\
\nonterminal{expression} \optional{\terminal{,}} \\
\nonterminal{expression} \terminal{,} \nonterminal{case-options} \\
\end{grammar}

\specsubsubitem
A switch statement evaluates a value (\nonterminal{expression}, the
\textit{switching expression}), then compares it with a number of
\nonterminal{switch-cases}, taking whichever branch matches the value.

\specsubsubitem
Each of the \nonterminal{case-options} specifies a value to compare with, given
by \nonterminal{expression}. This expression shall be limited to the
\secref{Translation compatible expression subset}, and its result type shall be
equivalent to the result type of the switching expression. The implementation
shall evaluate the \nonterminal{expression} of the corresponding
\nonterminal{switch-case} if any of the \nonterminal{case-options} is equal to
the switching expression's result, setting the result of the overall switch
expression to the result of the selected \nonterminal{expression}.

\specsubsubitem
The \terminal{*} form of \nonterminal{switch-case} indicates any case which is
not selected by the other cases. Only one case of this form shall appear in the
switch expression.

\specsubsubitem
The switch cases shall be \textit{exhaustive}, meaning that every possible
value of the switching expression is accounted for by a
\nonterminal{switch-case}. It shall also be preicsely exhaustive: no two cases
shall select for the same value.

\specsubsubitem
The implementation shall ensure that side-effects of the switch value
expression occur before those of the selected case, and that side-effects of
non-selected cases do not occur.

\specsubsubitem
If a type hint is provided, each branch shall receive it as a type hint.

\specsubsubitem
If a type hint is provided and all non-terminating branches are assignable to
that type, the result type shall be the type given by the type hint. If the
result types of all non-terminating cases are equivalent, the result type of
the switch expression shall be the result type of the cases. Otherwise, the
result type shall be a tagged union of the set of the result types of the
non-terminating cases.

If all cases terminate, the result type shall be \terminal{void} and the switch
expression shall terminate.

\specsubsection{Match expressions}

\begin{grammar}
\nonterminaldef{match-expression} \\
\terminal{match} \terminal{(} \nonterminal{expression} \terminal{)} \terminal{\{} \nonterminal{match-cases} \terminal{\}} \\

\nonterminaldef{match-cases} \\
\nonterminal{match-case} \optional{\terminal{,}} \\
\nonterminal{match-case} \terminal{,} \nonterminal{match-cases} \\

\nonterminaldef{match-case} \\
\nonterminal{name} \terminal{:} \nonterminal{type} \terminal{=>} \nonterminal{expression} \\
\nonterminal{type} \terminal{=>} \nonterminal{expression} \\
\terminal{*} \terminal{=>} \nonterminal{expression} \\
\end{grammar}

\specsubsubitem
A match statement evaluates a value (\nonterminal{expression}, the
\textit{matching expression}), then selects and evaluates another expression
based on its result type. The result type of the matching expression must be a
tagged union or nullable pointer type, or an alias of either.

\specsubsubitem
If the matching expression has a tagged union type, each
\nonterminal{match-case} shall specify a type which is either a member of that
tagged union, or another tagged union which supports a subset of the matching
expression's type, or a type alias which refers to a qualifying type.

\specsubsubitem
If the matching expression has a nullable pointer type, one match case shall be
\terminal{null}, and another shall be the equivalent non-nullable pointer type,
or a type alias which refers to a qualifying type.

\specsubsubitem
The \terminal{*} form of \nonterminal{match-case} indicates any case which is
not selected by the other cases. Only one case of this form shall appear in the
match expression.

\specsubsubitem
The first form of \nonterminal{match-case}, if selected, shall cause the
implementation to cast the match expression to the selected type and assign the
resulting value to \nonterminal{name}. It shall insert this binding into a new
scope which applies to the \nonterminal{expression}.

\specsubsubitem
The match cases shall be \textit{exhaustive}, meaning that every possible type
of the matching expression is accounted for by a \nonterminal{match-case}. It
shall also be preicsely exhaustive: no two cases shall select for the same
type.

\specsubsubitem
The implementation shall ensure that side-effects of the match value
expression occur before those of the selected case, and that side-effects of
non-selected cases do not occur.

\specsubsubitem
If a type hint is provided, each branch shall receive it as a type hint.

\specsubsubitem
If a type hint is provided and all non-terminating branches are assignable to
that type, the result type shall be the type given by the type hint. If the
result types of all non-terminating cases are equivalent, the result type of
the match expression shall be the result type of the cases. Otherwise, the
result type shall be a tagged union of the set of the result types of the
non-terminating cases.

If all cases terminate, the result type shall be \terminal{void} and the match
expression shall terminate.

\specsubsection{Assignment}

\begin{grammar}
\nonterminaldef{assignment} \\
\nonterminal{object-selector} \nonterminal{assignment-op} \nonterminal{expression} \\
\terminal{*} \nonterminal{unary-expression} \nonterminal{assignment-op} \nonterminal{expression} \\
\nonterminal{slicing-expression} \terminal{=} \nonterminal{expression} \\

\nonterminaldef{assignment-op} \oneof \\
\terminal{=}
\terminal{+=}
\terminal{-=}
\terminal{*=}
\terminal{/=}
\terminal{\%=}
\terminal{\textless{}\textless{}=}
\terminal{\textgreater{}\textgreater{}=}
\terminal{\&=}
\terminal{|=}
\terminal{\textasciicircum=}
\end{grammar}

\specsubsubitem
An \nonterminal{assignment} expression shall cause the object given by the
first term to be assigned a new value based on the value given by the second
term. The type of the object shall be provided as a type hint to the secondary
expression(s).

\specsubsubitem
If the \nonterminal{assignment-op} is \terminal{=}, the first term shall be
assigned the value given by the second term. Otherwise, the assignment
\code{\nonterminal{e1} \nonterminal{op}\terminal{=} \nonterminal{e1}} shall be
equivalent to the assignment
\code{\nonterminal{e1} \terminal{=} \nonterminal{e1} \nonterminal{op} \nonterminal{e2}},
but the side effects of \nonterminal{e1} shall only occur once.

\specsubsubitem
In the first form, the \nonterminal{object-selector} selects the object to be
modified. The type of this object shall not be of a \terminal{const} type.

\specsubsubitem
In the second form, the \nonterminal{unary-expression} shall have a result type
of a non-nullable, non-const pointer type, and the object which is assigned
shall be the secondary object to which the pointer object refers. The second
term shall be assignable to the pointer's secondary type.

\specsubsubitem
In the third form, the \nonterminal{expression} shall be of a slice
type, and shall have a length equal to the slice given by
\nonterminal{slicing-expression}. The first term shall not be of a
\terminal{const} type, and the lengths of the two slices shall be equal. The
contents of the slice given by the second term shall be copied into the slice
given by the first term.

\specsubsubitem
The second term shall be \textit{assignable} to the object. Assignability rules
are stricter than castability rules. All types are assignable to themselves. The
set of other types which are assignable to a given type are given by the
following table:

\begin{tabular}{r | l}
Object type & May be assigned from \\
\hline
Mutable type & Constant types assignable to the object type \\
Signed integer types & Signed integer types of equal or higher precision \\
Unsigned integer types & Unsigned integer types of equal or higher precision \\
Floating-point types & Any floating-point type of equal or higher precision \\
Nullable pointer types & Non-nullable pointer type of the same secondary type \\
Nullable pointer types & \terminal{null} \\
Slice types & Array type of the same secondary type and definite length \\
Slice types & \terminal{[}\terminal{]}\terminal{void} \\
Array types of undefined size & Array types of defined size \\
Tagged union types & See notes \\
Type aliases & Any type assignable to the secondary type \\
\terminal{void} & Any type \\
\terminal{*} \terminal{void} & Any non-nullable pointer type \\
\terminal{nullable} \terminal{*} \terminal{void} & Any pointer type \\
\terminal{*} \terminal{const} \terminal{char} & \terminal{str} \\
\end{tabular}

The implementation shall perform any necessary conversion from the source type
to the destination type.

\specsubsubitem
Pointers to array types are mutually assignable if their secondary types are
mutually assignable.

\specsubsubitem
Tagged union types may be assigned from any of their constituent types. Tagged
unions may also be assigned from any type which is assignable to exactly one of
its constituent types. Additionally, tagged unions may be assigned from any
other tagged union type, provided that the set of constituent types of the
destination type is a superset of the set of constituent types of the source
type.

\specsubsubitem
\terminal{const} types have the same assignability rules as the equivalent
non-const type. Types with the error flag set have the same assignability rules
as the equivalent type with the flag unset.

\informative{In the context of an assignment expression,
\subsubitemref{Assignment}{2} prevents the modification of objects with a const
type. However, the \textit{assignability} rules are referred to in many other
contexts throughout the specification, and in these contexts, unless otherwise
specified, non-const types are assignable to const types. For example, a
\nonterminal{binding} which specifies a const \nonterminal{type} may use a
non-const type for its \nonterminal{expression}.}

\specsubsubitem
For assignment of \terminal{*} \terminal{const} \terminal{char} from
\terminal{str} types, see the notes on \subsecref{Casts and type assertions}.

\specsubsubitem
The implementation shall ensure that any side-effects of the first term shall
occur before side-effects of the second term.

\specsubsection{Variable binding}

\begin{grammar}
\nonterminaldef{binding-list} \\
\optional{\terminal{static}} \terminal{let} \nonterminal{bindings} \\
\optional{\terminal{static}} \terminal{const} \nonterminal{bindings} \\

\nonterminaldef{bindings} \\
\nonterminal{binding} \optional{\terminal{,}} \\
\nonterminal{binding} \terminal{,} \nonterminal{bindings} \\

\nonterminaldef{binding} \\
\nonterminal{name} \terminal{=} \nonterminal{expression} \\
\nonterminal{name} \terminal{:} \nonterminal{type} \terminal{=} \nonterminal{expression} \\
\terminal{(} \nonterminal{binding-names} \terminal{)}  \terminal{=} \nonterminal{expression} \\
\terminal{(} \nonterminal{binding-names} \terminal{)} \terminal{:} \nonterminal{type} \terminal{=} \nonterminal{expression} \\

\nonterminaldef{binding-names} \\
\nonterminal{name} \terminal{,} \nonterminal{name} \\
\nonterminal{name} \terminal{,} \nonterminal{binding-names} \\
\end{grammar}

\specsubsubitem
A \nonterminal{binding-list} shall cause one or more objects to become
available in the present scope. Each object shall be identified by its
\nonterminal{name}, and shall have its initial value set to the result of the
\nonterminal{expression} or \nonterminal{expression}. The result
type of a binding list expression is \terminal{void}.

\specsubsubitem
In the first form of \nonterminal{binding-list}, the type of the object shall
be equivalent to the result type of the \nonterminal{expression}. In the
second form, the type shall be as indicated, and the result type of the
\nonterminal{expression} shall be assignable to this type. In this second form,
the type specified is used as a type hint for the \nonterminal{expression}.

\specsubsubitem
The third and fourth forms of \nonterminal{binding} are the \textit{tuple
unpacking} form, and in this case, the \nonterminal{type} and
\nonterminal{expression} shall be of a tuple type with a number of values equal
to the number of times \nonterminal{name} is given. The implementation shall
create separate bindings for each name, of the type of the corresponding tuple
value, and initialize them to that value from the tuple.

\specsubsubitem
If any \nonterminal{name} is \terminal{\_} (an underscore), a binding shall not
be created, but any side-effects of the initializer shall still occur.

\specsubsubitem
If the \terminal{const} form is used, the type of each binding shall be
modified to \textit{include} the \terminal{const} flag. If the \terminal{let}
form is used, the type of each binding which uses the first form of
\nonterminal{binding} shall be modified to \textit{omit} the \terminal{const}
flag.

\specsubsubitem
If the \terminal{static} form is used, the variables shall be allocated
\textit{statically}, such that they are only initialized once and their
previous value, accounting for any later mutations, is preserved each time
the binding expression is encountered, including across repeated or recursive
calls to the enclosing function. In this case, the initializer must use the
\secref{Translation compatible expression subset}.

\specsubsubitem
If a \nonterminal{binding} gives a \nonterminal{name} which is already defined
in the current scope, the new binding shall \textit{shadow} the earlier
binding, causing any later references to this name to resolve to the newer
binding.

\specsubsubitem
If the second form of \nonterminal{binding} is used and the \nonterminal{name}
is not already in use in this scope, the name shall be bound prior to the
evaluation of the \nonterminal{expression}, and may be used in the
\nonterminal{expression} \textit{only} as the object of the unary addressing
operator (\terminal{\&}).

\specsubsubitem
The type of the binding shall not use a type which has a zero or undefined size.

\specsubsection{Deferred expressions}

\begin{grammar}
\nonterminaldef{deferred-expression} \\
\terminal{defer} \nonterminal{expression} \\
\end{grammar}

\specsubsubitem
A \nonterminal{deferred-expression} causes another expression to be
\textit{deferred} until the termination of the current scope. The result type
is \terminal{void}.

\specsubsubitem
The implementation shall cause the \nonterminal{expression} to be evaluated
upon the termination of the current scope, either due to normal program flow,
or due to encountering a terminating expression.

\specsubsubitem
If several expressions are deferred in a single scope, their side-effects shall
occur in the same order that they appear in the program source.

\specsubsubitem
If the current scope is terminated before a \nonterminal{deferred-expression}
(\informative{but not an expression which was already deferred}) would be
evaluated, the side-effects of the \nonterminal{expression} shall not occur.

\specsubsubitem
A \nonterminal{deferred-expression} shall not appear as a descendant of the
expression tree formed by \nonterminal{expression}.

\specsubsection{Expression lists}

\begin{grammar}
\nonterminaldef{expression-list} \\
\nonterminal{expression} \terminal{;} \\
\nonterminal{expression} \terminal{;} \nonterminal{expression-list} \\
\end{grammar}

\specsubsubitem
A \nonterminal{expression-list} evaluates any number of
\nonterminal{expression}s in sequence. The result of the
\nonterminal{expression-list} shall be the result of the final
\nonterminal{expression}.

\specsubsubitem
The expressions shall be evaluated such that the side-effects of each all occur
in the order that each expression appears.

\specsubsubitem
If any of the \nonterminal{expression}s terminate, the
\nonterminal{expression-list} is considered to terminate.

\specsubsubitem
The \nonterminal{expression-list} shall establish a new scope whose parent is
the scope in which the \nonterminal{expression-list} resides.

\specsubsubitem
If a type hint is provided, the last expression shall receive it as a type hint.

\specsubsection{Control statements}

\begin{grammar}
\nonterminaldef{control-expression} \\
\terminal{break} \optional{\nonterminal{label}} \\
\terminal{continue} \optional{\nonterminal{label}} \\
\terminal{return} \optional{\nonterminal{expression}} \\
\end{grammar}

\specsubsubitem
\nonterminal{control-expression} causes an \nonterminal{expression-list} to
terminate in a specific way. A control statement is a terminating expression
and its result type is \terminal{void}.

\specsubsubitem
The first and second forms shall be valid only if used within a
\nonterminal{for-loop}. The first form shall cause the loop to abort without
evaluating the \textit{condition} or the \textit{afterthought}. The second form
shall cause the loop to repeat immediately, running the \textit{afterthought},
re-testing the \textit{condition}, and repeating the loop if \terminal{true}.

\specsubsubitem
If the \nonterminal{label} is provided for either the first or second forms, it
shall be used to specify which \nonterminal{for-loop} the statement shall
influence, and shall match a labelled for loop which is an ancestor of the
statement. If the label is not specified, the control statement shall refer to
the most immediate anscestor of the control statement which is a
\nonterminal{for-loop}. If no qualifying loop can be identified, a diagnostic
message shall be shown and the translation phase shall abort.

\specsubsubitem
The third form shall terminate the function the expression is a descendant of.
If the function's result type is not \terminal{void}, the
\nonterminal{expression} shall be provided, and shall be assignable to the
function's result type. It shall provide the result for the function. The
result type of the enclosing function shall be provided as a type hint to the
\nonterminal{expression}.

\specsubsubitem
In any of these cases, the implementation shall ensure that side-effects do not
occur for any expressions which are lexically situated \textit{after} the
\nonterminal{control-expression} within the scope of the loop or function they
influence.

\specsubsection{High-level expression class}

\begin{grammar}
\nonterminaldef{expression} \\
\nonterminal{assignment} \\
\nonterminal{binding-list} \\
\nonterminal{logical-or-expression} \\
\nonterminal{if-expression} \\
\nonterminal{for-loop} \\
\nonterminal{switch-expression} \\
\nonterminal{match-expression} \\
\nonterminal{control-expression} \\
\nonterminal{compound-expression} \\

\nonterminaldef{compound-expression} \\
\terminal{\{} \nonterminal{expression-list} \terminal{\}} \\
\end{grammar}

\specsection{Type promotion}

\specsubitem
The operands of some arithmetic expressions are subject to \textit{type
promotion}, to allow for arithmetic between disjoint types. The operand of
lower precision may be \textit{promoted}, or implicitly cast, to the precision
of the more precise operand. Unless explicitly covered by the following cases,
operands shall not be promoted, and the translation environment shall print a
diagnostic message and abort for incompatible combinations of operand types.

\specsubitem
For expressions where the result type is determined by type promotion, the
result type shall be equivalent to the type of the operand which has the
highest precision.

\specsubitem
For expressions involving two integer types, the type of lower precision may be
promoted to the type of higher precision only if the signedness is the same for
each operand. A type cannot be promoted to \terminal{uintptr}.

\specsubitem
For expressions involving floating-point types, \terminal{f32} may be promoted
to \terminal{f64}.

\specsubitem
For expressions involving pointer types, \terminal{null} may be promoted to any
nullable pointer type, and a non-nullable pointer type may be promoted to
a nullable pointer type with the same secondary type.

\specsubitem
A mutable type may be promoted to a constant type which is otherwise equivalent
to the mutable type, or any other type which that constant type may promote to.

\specsubitem
A pointer type may be promoted to another pointer type if the secondary type of
the pointer may be promoted to the secondary type of the second pointer.

\specsubitem
An array type may promote to an array type with undefined size with an
equivalent member type.

\specsubitem
A non-aliased type A may promote to a type alias B if type A may promote to the
underlying type of type B.

% TODO: This is an awful edge case, fix harec first
% Ideally, constants wouldn't be lowered to int without a type hint, then we
% could specify promotion and assignability normally for them and lower them to
% int in bindings (and maybe some other places?)

\specsubitem
If one operand is a constant and the other is not, the constant shall receive
the result type of the other operand as a type hint and type promotion shall be
done between its result type and the other operand's result type.

\specsubitem
If both operands are constants, they shall both receive the lowest-precision
integer type which would hold both of them as a type hint.

\specsection{Translation compatible expression subset}

The translation-compatible expression subset is a subset of expression types
which the implementation must be able to evaluate during the translation phase.

\specsubitem
The following expression types are included:

\begin{minipage}[t][7cm][b]{\textwidth}
\begin{multicols}{2}
\begin{itemize}
\item \nonterminal{logical-or-expression}
\item \nonterminal{logical-xor-expression}
\item \nonterminal{logical-and-expression}
\item \nonterminal{equality-expression}
\item \nonterminal{comparison-expression}
\item \nonterminal{inclusive-or-expression}
\item \nonterminal{exclusive-or-expression}
\item \nonterminal{and-expression}
\item \nonterminal{shift-expression}
\item \nonterminal{multiplicative-expression}
\item \nonterminal{cast-expression}
\item \nonterminal{unary-expression}
\item \nonterminal{field-access-expression}
\item \nonterminal{indexing-expression}
\item \nonterminal{measurement-expression}
\item \nonterminal{nested-expression}
\item \nonterminal{plain-expression}
\end{itemize}
\end{multicols}
\end{minipage}

\vspace{0.25cm}
\specsubitem
All terminals which are descendants of any of the listed terminals are
included, and all non-terminals and terminals which are descendants of
\nonterminal{plain-expression} are included.

\specsubitem
The pointer dereference \nonterminal{unary-expression} (the \terminal{*}
operator) shall be excluded from the translation-compatible expression subset.
Additionally, the implicit pointer type dereference semantics of
\nonterminal{field-access-expression} and \nonterminal{indexing-expression} are
not available.

\specsubitem
The implementation is not required to use a conformant implementation of the
storage semantics of types in the translation environment, provided that there
are not observable side-effects in the execution environment as a result of any
differences.

\specsubitem
In a context where an expression is constrained to this subset, the use of an
expression type outside of this set shall cause the translation environment to
print a diagnostic message and abort.