summaryrefslogtreecommitdiff
path: root/boot/stage15.elna
blob: d317c5cabfb079710c92c7b6d2d92bdf79e6deb0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880
2881
2882
2883
2884
2885
2886
2887
2888
2889
2890
2891
2892
2893
2894
2895
2896
2897
2898
2899
2900
2901
2902
2903
2904
2905
2906
2907
2908
2909
2910
2911
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
2923
2924
2925
2926
2927
2928
2929
2930
2931
2932
2933
2934
2935
2936
2937
2938
2939
2940
2941
2942
2943
2944
2945
2946
2947
2948
2949
2950
2951
2952
2953
2954
2955
2956
2957
2958
2959
2960
2961
2962
2963
2964
2965
2966
2967
2968
2969
2970
2971
2972
2973
2974
2975
2976
2977
2978
2979
2980
2981
2982
2983
2984
2985
2986
2987
2988
2989
2990
2991
2992
2993
2994
2995
2996
2997
2998
2999
3000
3001
3002
3003
3004
3005
3006
3007
3008
3009
3010
3011
3012
3013
3014
3015
3016
3017
3018
3019
3020
3021
3022
3023
3024
3025
3026
3027
3028
3029
3030
3031
3032
3033
3034
3035
3036
3037
3038
3039
3040
3041
3042
3043
3044
3045
3046
3047
3048
3049
3050
3051
3052
3053
3054
3055
3056
3057
3058
3059
3060
3061
3062
3063
3064
3065
3066
3067
3068
3069
3070
3071
3072
3073
3074
3075
3076
3077
3078
3079
3080
3081
3082
3083
3084
3085
3086
3087
3088
3089
3090
3091
3092
3093
3094
3095
3096
3097
3098
3099
3100
3101
3102
3103
3104
3105
3106
3107
3108
3109
3110
3111
3112
3113
3114
3115
3116
3117
3118
3119
3120
3121
3122
3123
3124
3125
3126
3127
3128
3129
3130
3131
3132
3133
3134
3135
3136
3137
3138
3139
3140
3141
3142
3143
3144
3145
3146
3147
3148
3149
3150
3151
3152
3153
3154
3155
3156
3157
3158
3159
3160
3161
3162
3163
3164
3165
3166
3167
3168
3169
3170
3171
3172
3173
3174
3175
3176
3177
3178
3179
3180
3181
3182
3183
3184
3185
3186
3187
3188
3189
3190
3191
3192
3193
3194
3195
3196
3197
3198
3199
3200
3201
3202
3203
3204
3205
3206
3207
3208
3209
3210
3211
3212
3213
3214
3215
3216
3217
3218
3219
3220
3221
3222
3223
3224
3225
3226
3227
3228
3229
3230
3231
3232
3233
3234
3235
3236
3237
3238
3239
3240
3241
3242
3243
3244
3245
3246
3247
3248
3249
3250
3251
3252
3253
3254
3255
3256
3257
3258
3259
3260
3261
3262
3263
3264
3265
3266
3267
3268
3269
3270
3271
3272
3273
3274
3275
3276
3277
3278
3279
3280
3281
3282
3283
3284
3285
3286
3287
3288
3289
3290
3291
3292
3293
3294
3295
3296
3297
3298
3299
3300
3301
3302
3303
3304
3305
3306
3307
3308
3309
3310
3311
3312
3313
3314
3315
3316
3317
3318
3319
3320
3321
3322
3323
3324
3325
3326
3327
3328
3329
3330
3331
3332
3333
3334
3335
3336
3337
3338
3339
3340
3341
3342
3343
3344
3345
3346
3347
3348
3349
3350
3351
3352
3353
3354
3355
3356
3357
3358
3359
3360
3361
3362
3363
3364
3365
3366
3367
3368
3369
3370
3371
3372
3373
3374
3375
3376
3377
3378
3379
3380
3381
3382
3383
3384
3385
3386
3387
3388
3389
3390
3391
3392
3393
3394
3395
3396
3397
3398
3399
3400
3401
3402
3403
3404
3405
3406
3407
3408
3409
3410
3411
3412
3413
3414
3415
3416
3417
3418
3419
3420
3421
3422
3423
3424
3425
3426
3427
3428
3429
3430
3431
3432
3433
3434
3435
3436
3437
3438
3439
3440
3441
3442
3443
3444
3445
3446
3447
3448
3449
3450
3451
3452
3453
3454
3455
3456
3457
3458
3459
3460
3461
3462
3463
3464
3465
3466
3467
3468
3469
3470
3471
3472
3473
3474
3475
3476
3477
3478
3479
3480
3481
3482
3483
3484
3485
3486
3487
3488
3489
3490
3491
3492
3493
3494
3495
3496
3497
3498
3499
3500
3501
3502
3503
3504
3505
3506
3507
3508
3509
3510
3511
3512
3513
3514
3515
3516
3517
3518
3519
3520
3521
3522
3523
3524
3525
3526
3527
3528
3529
3530
3531
3532
3533
3534
3535
3536
3537
3538
3539
3540
3541
3542
3543
3544
3545
3546
3547
3548
3549
3550
3551
3552
3553
3554
3555
3556
3557
3558
3559
3560
3561
3562
3563
3564
3565
3566
3567
3568
3569
3570
3571
3572
3573
3574
3575
3576
3577
3578
3579
3580
3581
3582
3583
3584
3585
3586
3587
3588
3589
3590
3591
3592
3593
3594
3595
3596
3597
3598
3599
3600
3601
3602
3603
3604
3605
3606
3607
3608
3609
3610
3611
3612
3613
3614
3615
3616
3617
3618
3619
3620
3621
3622
3623
3624
3625
3626
3627
3628
3629
3630
3631
3632
3633
3634
3635
3636
3637
3638
3639
3640
3641
3642
3643
3644
3645
3646
3647
3648
3649
3650
3651
3652
3653
3654
3655
3656
3657
3658
3659
3660
3661
3662
3663
3664
3665
3666
3667
3668
3669
3670
3671
3672
3673
3674
3675
3676
3677
3678
3679
3680
3681
3682
3683
3684
3685
3686
3687
3688
3689
3690
3691
3692
3693
3694
3695
3696
3697
3698
3699
3700
3701
3702
3703
3704
3705
3706
3707
3708
3709
3710
3711
3712
3713
3714
3715
3716
3717
3718
3719
3720
3721
3722
3723
3724
3725
3726
3727
3728
3729
3730
3731
3732
3733
3734
3735
3736
3737
3738
3739
3740
3741
3742
3743
3744
3745
3746
3747
3748
3749
3750
3751
3752
3753
3754
3755
3756
3757
3758
3759
3760
3761
3762
3763
3764
3765
3766
3767
3768
3769
3770
3771
3772
3773
3774
3775
3776
3777
3778
3779
3780
3781
3782
3783
3784
3785
3786
3787
3788
3789
3790
3791
3792
3793
3794
3795
3796
3797
3798
3799
3800
3801
3802
3803
3804
3805
3806
3807
3808
3809
3810
3811
3812
3813
3814
3815
3816
3817
3818
3819
3820
3821
3822
3823
3824
3825
3826
3827
3828
3829
3830
3831
3832
3833
3834
3835
3836
3837
3838
3839
3840
3841
3842
3843
3844
3845
3846
3847
3848
3849
3850
3851
3852
3853
3854
3855
3856
3857
3858
3859
3860
3861
3862
3863
3864
3865
3866
3867
3868
3869
3870
3871
3872
3873
3874
3875
3876
3877
3878
3879
3880
3881
3882
3883
3884
3885
3886
3887
3888
3889
3890
3891
3892
3893
3894
3895
3896
3897
3898
3899
3900
3901
3902
3903
3904
3905
3906
3907
3908
3909
3910
3911
3912
3913
3914
3915
3916
3917
3918
3919
3920
3921
3922
3923
3924
3925
3926
3927
3928
3929
3930
3931
3932
3933
3934
3935
3936
3937
3938
3939
3940
3941
3942
3943
3944
3945
3946
3947
3948
3949
3950
3951
3952
3953
(*
 * This Source Code Form is subject to the terms of the Mozilla Public License,
 * v. 2.0. If a copy of the MPL was not distributed with this file, You can
 * obtain one at https://mozilla.org/MPL/2.0/.
 *)

(* Stage 15 compiler. *)

type
	LexerAction = (none, accumulate, skip, single, eof, finalize, composite, key_id, integer, delimited);

	(**
	 * Classification table assigns each possible character to a group (class). All
	 * characters of the same group a handled equivalently.
	 *
	 * Transition = record
	 *   action: TransitionAction;
	 *   next_state: TransitionState
	 * end;
	 *)
	LexerClass = (
		invalid,
		digit,
		alpha,
		space,
		colon,
		equals,
		left_paren,
		right_paren,
		asterisk,
		backslash,
		single,
		hex,
		zero,
		x,
		eof,
		dot,
		minus,
		single_quote,
		double_quote,
		greater,
		less,
		other
	);
	LexerState = (
		start,
		colon,
		identifier,
		decimal,
		leading_zero,
		greater,
		minus,
		left_paren,
		less,
		dot,
		comment,
		closing_comment,
		character,
		character_escape,
		string,
		string_escape,
		finish
	);
	LexerTokenKind = (
		identifier,
		_const,
		_var,
		_proc,
		_type,
		_begin,
		_end,
		_if,
		_then,
		_else,
		_elsif,
		_while,
		_do,
		_extern,
		_record,
		_union,
		_true,
		_false,
		null,
		and,
		_or,
		_xor,
		pipe,
		not,
		_return,
		_module,
		_program,
		_import,
		_cast,
		_defer,
		_case,
		_of,
		trait,
		left_paren,
		right_paren,
		left_square,
		right_square,
		shift_left,
		shift_right,
		greater_equal,
		less_equal,
		greater_than,
		less_than,
		not_equal,
		equals,
		semicolon,
		dot,
		comma,
		plus,
		arrow,
		minus,
		multiplication,
		division,
		remainder,
		assignment,
		colon,
		hat,
		at,
		comment,
		string,
		character,
		integer,
		word,
		_goto,
		eof
	);
	NodeKind = (
		integer_literal,
		string_literal,
		character_literal,
		variable_expression,
		field_access_expression,
		dereference_expression,
		unary_expression,
		binary_expression,
		call,
		goto_statement,
		label_declaration,
		return_statement,
		assign_statement,
		if_statement,
		procedure_declaration,
		variable_declaration,
		enumeration_type_expression,
		named_type_expression,
		type_declaration,
		module_declaration
	);
	InfoKind = (type_info, parameter_info, temporary_info);
	TypeKind = (primitive, enumeration);

var
	source_code: Array;
	compiler_strings: Array;
	symbol_table_global: Array;
	symbol_table_local: Array;
	classification: Array;

	(* To reserve memory just add the value of needed bytes to the memory_free_pointer variable. *)
	memory: Array;

	compiler_strings_position: Word;
	compiler_strings_length: Word;
	label_counter: Word;

	(* Points to a segment of free memory. *)
	memory_free_pointer: Word;

(**
 * Calculates and returns the string token length between quotes, including the
 * escaping slash characters.
 *
 * Parameters:
 * string - String token pointer.
 *
 * Returns the length in a0.
 *)
proc _string_length(string: Word);
var
	counter: Word;
	current_byte: Word;
begin
	(* Reset the counter. *)
	counter := 0;

	.string_length_loop;
	string := string + 1;

	current_byte := _load_byte(string);
	if current_byte <> '"' then
		counter := counter + 1;
		goto string_length_loop
	end;

	return counter
end;

(**
 * Adds a string to the global, read-only string storage.
 *
 * Parameters:
 * string - String token.
 *
 * Returns the offset from the beginning of the storage to the new string in a0.
 *)
proc _add_string(string: Word);
var
	contents: Word;
	result: Word;
	current_byte: Word;
begin
	contents := string + 1;
	result := compiler_strings_length;

	.add_string_loop;
	current_byte := _load_byte(contents);
	if current_byte <> '"' then
		_store_byte(current_byte, compiler_strings_position);
		compiler_strings_position := compiler_strings_position + 1;
		contents := contents + 1;

		if current_byte <> '\\' then
			compiler_strings_length := compiler_strings_length + 1
		end;
		goto add_string_loop
	end;

	return result
end;

(**
 * Reads standard input into a buffer.
 *
 * Parameters:
 * buffer - Buffer pointer.
 * size - Buffer size.
 *
 * Returns the amount of bytes written in a0.
 *)
proc _read_file(buffer: Word, size: Word);
	return _syscall(0, buffer, size, 0, 0, 0, 63)
end;

(**
 * Writes to the standard output.
 *
 * Parameters:
 * buffer - Buffer.
 * size - Buffer length.
 *)
proc _write_s(buffer: Word, size: Word);
begin
	_syscall(1, buffer, size, 0, 0, 0, 64)
end;

(**
 * Writes a number to a string buffer.
 *
 * Parameters:
 * number - Whole number.
 * output_buffer - Buffer pointer.
 *
 * Sets a0 to the length of the written number.
 *)
proc _print_i(number: Word, output_buffer: Word);
var
	local_buffer: Word;
	is_negative: Word;
	current_character: Word;
	result: Word;
begin
	local_buffer := @result + 11;

	if number >= 0 then
		is_negative := 0
	else
		number = -number;
		is_negative := 1
	end;

	.print_i_digit10;
	current_character := number % 10;
	_store_byte(current_character + '0', local_buffer);

	number := number / 10;
	local_buffer := local_buffer - 1;

	if number <> 0 then
		goto print_i_digit10
	end;
	if is_negative = 1 then
		_store_byte('-', local_buffer);
		local_buffer := local_buffer - 1
	end;
	result := @result + 11;
	result := result - local_buffer;
	_memcpy(output_buffer, local_buffer + 1, result);

	return result
end;

(**
 * Writes a number to the standard output.
 *
 * Parameters:
 * number - Whole number.
 *)
proc _write_i(number: Word);
var
	local_buffer: Word;
	length: Word;
begin
	length := _print_i(number, @local_buffer);
	_write_s(@local_buffer, length)
end;

(**
 * Writes a character from a0 into the standard output.
 *
 * Parameters:
 * character - Character to write.
 *)
proc _write_c(character: Word);
begin
	_write_s(@character, 1)
end;

(**
 * Write null terminated string.
 *
 * Parameters:
 * string - String.
 *)
proc _write_z(string: Word);
var
	next_byte: Word;
begin
	(* Check for 0 character. *)
	next_byte := _load_byte(string);

	if next_byte <> 0 then
		(* Print a character. *)
		_write_c(next_byte);

		(* Advance the input string by one byte. *)
		_write_z(string + 1)
	end
end;

(**
 * Detects if a0 is an uppercase character. Sets a0 to 1 if so, otherwise to 0.
 *)
proc _is_upper(character: Word);
var
	lhs: Word;
	rhs: Word;
begin
	lhs := character >= 'A';
	rhs := character <= 'Z';

	return lhs & rhs

end;

(**
 * Detects if a0 is an lowercase character. Sets a0 to 1 if so, otherwise to 0.
 *)
proc _is_lower(character: Word);
var
	lhs: Word;
	rhs: Word;
begin
	lhs := character >= 'a';
	rhs := character <= 'z';

	return lhs & rhs
end;

(**
 * Detects if the passed character is a 7-bit alpha character or an underscore.
 *
 * Paramters:
 * character - Tested character.
 *
 * Sets a0 to 1 if the character is an alpha character or underscore, sets it to 0 otherwise.
 *)
proc _is_alpha(character: Word);
var
	is_upper_result: Word;
	is_lower_result: Word;
	is_alpha_result: Word;
	is_underscore: Word;
begin
	is_upper_result := _is_upper(character);
	is_lower_result := _is_lower(character);
	is_underscore := character = '_';

	is_alpha_result := is_lower_result or is_upper_result;
	return is_alpha_result or is_underscore
end;

(**
 * Detects whether the passed character is a digit (a value between 0 and 9).
 *
 * Parameters:
 * character - Exemined value.
 *
 * Sets a0 to 1 if it is a digit, to 0 otherwise.
 *)
proc _is_digit(character: Word);
var
	lhs: Word;
	rhs: Word;
begin
	lhs := character >= '0';
	rhs := character <= '9';

	return lhs & rhs
end;

proc _is_alnum(character: Word);
var
	lhs: Word;
	rhs: Word;
begin
	lhs := _is_alpha(character);
	rhs := _is_digit(character);

	return lhs or rhs
end;

(**
 * Parameters:
 * lhs - First pointer.
 * rhs - Second pointer.
 * count - The length to compare.
 *
 * Returns 0 if memory regions are equal.
 *)
proc _memcmp(lhs: Word, rhs: Word, count: Word);
var
	lhs_byte: Word;
	rhs_byte: Word;
	result: Word;
begin
	result := 0;

	.memcmp_loop;
	if count <> 0 then
		lhs_byte := _load_byte(lhs);
		rhs_byte := _load_byte(rhs);
		result := lhs_byte - rhs_byte;

		lhs := lhs + 1;
		rhs := rhs + 1;
		count := count - 1;

		if result = 0 then
			goto memcmp_loop
		end
	end;

	return result
end;

(**
 * Copies memory.
 *
 * Parameters:
 * destination - Destination.
 * source - Source.
 * count - Size.
 *
 * Returns the destination.
 *)
proc _memcpy(destination: Word, source: Word, count: Word);
var
	current_byte: Word;
begin
	.memcpy_loop;
	if count <> 0 then
		current_byte := _load_byte(source);
		_store_byte(current_byte, destination);

		destination := destination + 1;
		source := source + 1;
		count := count - 1;
		goto memcpy_loop
	end;

	return destination
end;

proc _node_get_kind(this: Word);
	return this^
end;

proc _node_set_kind(this: Word, kind: Word);
begin
	this^ := kind
end;

proc _integer_literal_node_size();
	return 12
end;

proc _integer_literal_node_get_value(this: Word);
begin
	this := this + 4;
	return this^
end;

proc _integer_literal_node_set_value(this: Word, value: Word);
begin
	this := this + 4;
	this^ := value
end;

proc _integer_literal_node_get_length(this: Word);
begin
	this := this + 8;
	return this^
end;

proc _integer_literal_node_set_length(this: Word, value: Word);
begin
	this := this + 8;
	this^ := value
end;

proc _parse_integer_literal();
var
	integer_token: Word;
	integer_length: Word;
	result: Word;
begin
	result := memory_free_pointer;
	memory_free_pointer := memory_free_pointer + 12;

	integer_token := _lexer_global_get_start();
	integer_length := _lexer_global_get_end();
	integer_length := integer_length -  integer_token;
	_lexer_skip_token();

	_node_set_kind(result, NodeKind.integer_literal);
	_integer_literal_node_set_value(result, integer_token);
	_integer_literal_node_set_length(result, integer_length);

	return result
end;

proc _compile_integer_literal(integer_literal_node: Word);
var
	integer_token: Word;
	integer_length: Word;
	token_kind: Word;
begin
	_write_z("\tli t0, \0");

	integer_token := _integer_literal_node_get_value(integer_literal_node);
	integer_length := _integer_literal_node_get_length(integer_literal_node);

	_write_s(integer_token, integer_length);
	_write_c('\n')
end;

proc _character_literal_node_get_value(this: Word);
begin
	this := this + 4;
	return this^
end;

proc _character_literal_node_set_value(this: Word, value: Word);
begin
	this := this + 4;
	this^ := value
end;

proc _character_literal_node_get_length(this: Word);
begin
	this := this + 8;
	return this^
end;

proc _character_literal_node_set_length(this: Word, value: Word);
begin
	this := this + 8;
	this^ := value
end;

proc _parse_character_literal();
var
	character: Word;
	character_length: Word;
	result: Word;
begin
	result := memory_free_pointer;
	memory_free_pointer := memory_free_pointer + 12;

	character := _lexer_global_get_start();
	character_length := _lexer_global_get_end();
	character_length := character_length - character;
	_lexer_skip_token();

	_node_set_kind(result, NodeKind.character_literal);
	_integer_literal_node_set_value(result, character);
	_integer_literal_node_set_length(result, character_length);

	return result
end;

proc _compile_character_literal(character_literal_node: Word);
var
	character: Word;
	character_length: Word;
begin
	character := _character_literal_node_get_value(character_literal_node);
	character_length := _character_literal_node_get_length(character_literal_node);

	_write_z("\tli t0, \0");
	_write_s(character, character_length);
	_write_c('\n')
end;

proc _variable_expression_size();
	return 12
end;

proc _variable_expression_get_name(this: Word);
begin
	this := this + 4;
	return this^
end;

proc _variable_expression_set_name(this: Word, value: Word);
begin
	this := this + 4;
	this^ := value
end;

proc _variable_expression_get_length(this: Word);
begin
	this := this + 8;
	return this^
end;

proc _variable_expression_set_length(this: Word, value: Word);
begin
	this := this + 8;
	this^ := value
end;

proc _allocate(size: Word);
var
	result: Word;
begin
	result := memory_free_pointer;
	memory_free_pointer := memory_free_pointer + size;
	return result
end;

proc _parse_variable_expression();
var
	name: Word;
	name_token: Word;
	result: Word;
	memory_size: Word;
begin
	name := _lexer_global_get_start();
	name_token := _lexer_global_get_end();
	name_token := name_token - name;
	_lexer_skip_token();

	memory_size := _variable_expression_size();
	result := _allocate(memory_size);

	_node_set_kind(result, NodeKind.variable_expression);
	_variable_expression_set_name(result, name);
	_variable_expression_set_length(result, name_token);

	return result
end;

proc _compile_variable_expression(variable_expression: Word);
var
	name: Word;
	name_token: Word;
	lookup_result: Word;
begin
	name := _variable_expression_get_name(variable_expression);
	name_token := _variable_expression_get_length(variable_expression);

	lookup_result := _symbol_table_lookup(@symbol_table_local, name, name_token);
	if lookup_result <> 0 then
		_compile_local_designator(lookup_result)
	else
		_compile_global_designator(variable_expression)
	end
end;

proc _string_literal_node_size();
	return 12
end;

proc _string_literal_node_get_value(this: Word);
begin
	this := this + 4;
	return this^
end;

proc _string_literal_node_set_value(this: Word, value: Word);
begin
	this := this + 4;
	this^ := value
end;

proc _string_literal_node_get_length(this: Word);
begin
	this := this + 8;
	return this^
end;

proc _string_literal_node_set_length(this: Word, value: Word);
begin
	this := this + 8;
	this^ := value
end;

proc _parse_string_literal();
var
	length: Word;
	token_start: Word;
	result: Word;
	memory_size: Word;
begin
	memory_size := _string_literal_node_size();
	result := _allocate(memory_size);

	token_start := _lexer_global_get_start();
	length := _string_length(token_start);
	_lexer_skip_token();

	_node_set_kind(result, NodeKind.string_literal);
	_string_literal_node_set_value(result, token_start);
	_string_literal_node_set_length(result, length);

	return result
end;

proc _compile_string_literal(string_literal_node: Word);
var
	token_start: Word;
	length: Word;
	offset: Word;
begin
	token_start := _string_literal_node_get_value(string_literal_node);
	length := _string_literal_node_get_length(string_literal_node);
	offset := _add_string(token_start);

	_write_z("\tla t0, strings\n\0");

	_write_z("\tli t1, \0");
	_write_i(offset);
	_write_c('\n');

	_write_z("\tadd t0, t0, t1\n\0")
end;

proc _parse_simple_expression();
var
	current_character: Word;
	parser_node: Word;
	token_kind: Word;
begin
	parser_node := 0;
	_lexer_read_token(@token_kind);

	if token_kind = LexerTokenKind.character then
		parser_node := _parse_character_literal()
	elsif token_kind = LexerTokenKind.integer then
		parser_node := _parse_integer_literal()
	elsif token_kind = LexerTokenKind.string then
		parser_node := _parse_string_literal()
	elsif token_kind = LexerTokenKind.identifier then
		parser_node := _parse_variable_expression()
	end;
	return parser_node
end;

proc _dereference_expression_size();
	return 8
end;

proc _dereference_expression_get_pointer(this: Word);
begin
	this := this + 4;
	return this^
end;

proc _dereference_expression_set_pointer(this: Word, value: Word);
begin
	this := this + 4;
	this^ := value
end;

proc _parse_dereference_expression(simple_expression: Word);
var
	result: Word;
	memory_size: Word;
begin
	memory_size := _dereference_expression_size();
	result := _allocate(memory_size);

	_node_set_kind(result, NodeKind.dereference_expression);
	_dereference_expression_set_pointer(result, simple_expression);
	_lexer_skip_token();

	return result
end;

proc _parse_designator();
var
	simple_expression: Word;
	token_kind: Word;
begin
	simple_expression := _parse_simple_expression();

	_lexer_read_token(@token_kind);

	if token_kind = LexerTokenKind.hat then
		simple_expression := _parse_dereference_expression(simple_expression)
	elsif token_kind = LexerTokenKind.dot then
		simple_expression := _parse_field_access_expression(simple_expression)
	elsif token_kind = LexerTokenKind.left_paren then
		simple_expression := _parse_call(simple_expression)
	end;
	return simple_expression
end;

proc _compile_simple_expression(parser_node: Word);
var
	is_address: Word;
	node_kind: Word;
begin
	is_address := 0;
	node_kind := _node_get_kind(parser_node);

	if node_kind = NodeKind.character_literal then
		_compile_character_literal(parser_node)
	elsif node_kind = NodeKind.string_literal then
		_compile_string_literal(parser_node)
	elsif node_kind = NodeKind.integer_literal then
		_compile_integer_literal(parser_node)
	else
		_compile_variable_expression(parser_node);
		is_address := 1
	end;
	return is_address
end;

proc _unary_expression_size();
	return 12
end;

proc _unary_expression_get_operand(this: Word);
begin
	this := this + 4;
	return this^
end;

proc _unary_expression_set_operand(this: Word, value: Word);
begin
	this := this + 4;
	this^ := value
end;

proc _unary_expression_get_operator(this: Word);
begin
	this := this + 8;
	return this^
end;

proc _unary_expression_set_operator(this: Word, value: Word);
begin
	this := this + 8;
	this^ := value
end;

proc _parse_unary_expression();
var
	token_kind: Word;
	result: Word;
	memory_size: Word;
	operand: Word;
	operator: Word;
begin
	_lexer_read_token(@token_kind);
	operator := 0;

	if token_kind = LexerTokenKind.at then
		operator := '@'
	elsif token_kind = LexerTokenKind.minus then
		operator := '-'
	elsif token_kind = LexerTokenKind.not then
		operator := '~'
	end;
	if operator <> 0 then
		_lexer_skip_token()
	end;
	result := _parse_designator();

	if operator <> 0 then
		operand := result;
		memory_size := _unary_expression_size();
		result := _allocate(memory_size);

		_node_set_kind(result, NodeKind.unary_expression);
		_unary_expression_set_operand(result, operand);
		_unary_expression_set_operator(result, operator)
	end;

	return result
end;

proc _compile_unary_expression(parser_node: Word);
var
	current_character: Word;
	token_kind: Word;
	expression_kind: Word;
	operator: Word;
	operand: Word;
begin
	operator := 0;
	operand := 0;

	expression_kind := _node_get_kind(parser_node);

	if expression_kind = NodeKind.unary_expression then
		operator := _unary_expression_get_operator(parser_node);
		operand := _unary_expression_get_operand(parser_node)
	else
		operand := parser_node
	end;

	if operator = '@' then
		_compile_designator(operand)
	elsif _compile_designator(operand) then
		_write_z("\tlw t0, (t0) # Designator is an address.\n\0")
	end;
	if operator = '-' then
		_write_z("\tneg t0, t0\n\0")
	elsif operator = '~' then
		_write_z("\tnot t0, t0\n\0")
	end
end;

proc _binary_expression_size();
	return 16
end;

proc _binary_expression_get_lhs(this: Word);
begin
	this := this + 4;
	return this^
end;

proc _binary_expression_set_lhs(this: Word, value: Word);
begin
	this := this + 4;
	this^ := value
end;

proc _binary_expression_get_rhs(this: Word);
begin
	this := this + 8;
	return this^
end;

proc _binary_expression_set_rhs(this: Word, value: Word);
begin
	this := this + 8;
	this^ := value
end;

proc _binary_expression_get_operator(this: Word);
begin
	this := this + 12;
	return this^
end;

proc _binary_expression_set_operator(this: Word, value: Word);
begin
	this := this + 12;
	this^ := value
end;

proc _parse_binary_expression();
var
	lhs_node: Word;
	rhs_node: Word;
	token_kind: Word;
	memory_size: Word;
	result: Word;
begin
	lhs_node := _parse_unary_expression();
	rhs_node := 0;
	_lexer_read_token(@token_kind);

	if token_kind = LexerTokenKind.plus then
		_lexer_skip_token();
		rhs_node := _parse_unary_expression()
	elsif token_kind = LexerTokenKind.minus then
		_lexer_skip_token();
		rhs_node := _parse_unary_expression()
	elsif token_kind = LexerTokenKind.multiplication then
		_lexer_skip_token();
		rhs_node := _parse_unary_expression()
	elsif token_kind = LexerTokenKind.and then
		_lexer_skip_token();
		rhs_node := _parse_unary_expression()
	elsif token_kind = LexerTokenKind._or then
		_lexer_skip_token();
		rhs_node := _parse_unary_expression()
	elsif token_kind = LexerTokenKind._xor then
		_lexer_skip_token();
		rhs_node := _parse_unary_expression()
	elsif token_kind = LexerTokenKind.equals then
		_lexer_skip_token();
		rhs_node := _parse_unary_expression()
	elsif token_kind = LexerTokenKind.remainder then
		_lexer_skip_token();
		rhs_node := _parse_unary_expression()
	elsif token_kind = LexerTokenKind.division then
		_lexer_skip_token();
		rhs_node := _parse_unary_expression()
	elsif token_kind = LexerTokenKind.less_than then
		_lexer_skip_token();
		rhs_node := _parse_unary_expression()
	elsif token_kind = LexerTokenKind.greater_than then
		_lexer_skip_token();
		rhs_node := _parse_unary_expression()
	elsif token_kind = LexerTokenKind.less_equal then
		_lexer_skip_token();
		rhs_node := _parse_unary_expression()
	elsif token_kind = LexerTokenKind.not_equal then
		_lexer_skip_token();
		rhs_node := _parse_unary_expression()
	elsif token_kind = LexerTokenKind.greater_equal then
		_lexer_skip_token();
		rhs_node := _parse_unary_expression()
	end;
	if rhs_node <> 0 then
		memory_size := _binary_expression_size();
		result := _allocate(memory_size);

		_node_set_kind(result, NodeKind.binary_expression);
		_binary_expression_set_lhs(result, lhs_node);
		_binary_expression_set_rhs(result, rhs_node);
		_binary_expression_set_operator(result, token_kind)
	else
		result := lhs_node
	end;
	return result
end;

proc _compile_binary_expression(parser_node: Word);
var
	token_kind: Word;
	expression_kind: Word;
	operand_node: Word;
begin
	expression_kind := _node_get_kind(parser_node);

	if expression_kind <> NodeKind.binary_expression then
		_compile_unary_expression(parser_node)
	else
		token_kind := _binary_expression_get_operator(parser_node);

		operand_node := _binary_expression_get_lhs(parser_node);
		_compile_unary_expression(operand_node);
		(* Save the value of the left expression on the stack. *)
		_write_z("\tsw t0, 64(sp)\n\0");

		operand_node := _binary_expression_get_rhs(parser_node);
		_compile_unary_expression(operand_node);
		(* Load the left expression from the stack; *)
		_write_z("\tlw t1, 64(sp)\n\0");

		if token_kind = LexerTokenKind.plus then
			_write_z("\tadd t0, t0, t1\n\0")
		elsif token_kind = LexerTokenKind.minus then
			_write_z("\tsub t0, t1, t0\n\0");
		elsif token_kind = LexerTokenKind.multiplication then
			_write_z("\tmul t0, t0, t1\n\0")
		elsif token_kind = LexerTokenKind.and then
			_write_z("\tand t0, t0, t1\n\0")
		elsif token_kind = LexerTokenKind._or then
			_write_z("\tor t0, t0, t1\n\0")
		elsif token_kind = LexerTokenKind._xor then
			_write_z("\txor t0, t0, t1\n\0")
		elsif token_kind = LexerTokenKind.equals then
			_write_z("\txor t0, t0, t1\n\tseqz t0, t0\n\0")
		elsif token_kind = LexerTokenKind.remainder then
			_write_z("\trem t0, t1, t0\n\0")
		elsif token_kind = LexerTokenKind.division then
			_write_z("\tdiv t0, t1, t0\n\0")
		elsif token_kind = LexerTokenKind.less_than then
			_write_z("\tslt t0, t1, t0\n\0")
		elsif token_kind = LexerTokenKind.greater_than then
			_write_z("\tslt t0, t0, t1\n\0")
		elsif token_kind = LexerTokenKind.less_equal then
			_write_z("\tslt t0, t0, t1\n\txori t0, t0, 1\n\0")
		elsif token_kind = LexerTokenKind.not_equal then
			_write_z("\txor t0, t0, t1\n\tsnez t0, t0\n\0")
		elsif token_kind = LexerTokenKind.greater_equal then
			_write_z("\tslt t0, t1, t0\n\txori t0, t0, 1\n\0")
		end
	end
end;

proc _compile_expression();
var
	parser_node: Word;
begin
	parser_node := _parse_binary_expression();
	_compile_binary_expression(parser_node)
end;

(* 4 bytes node kind + 4 byte pointer to variable expression + 4 * 7 for arguments. *)
proc _call_size();
	return 44
end;

proc _call_get_name(this: Word);
begin
	this := this + 8;
	return this^
end;

proc _call_set_name(this: Word, value: Word);
begin
	this := this + 8;
	this^ := value
end;

proc _call_get_argument(this: Word, n: Word);
begin
	n := n * 4;
	this := this + 8;
	this := this + n;
	return this^
end;

proc _call_set_argument(this: Word, n: Word, value: Word);
begin
	n := n * 4;
	this := this + 8;
	this := this + n;
	this^ := value
end;

proc _parse_call(callee: Word);
var
	parsed_expression: Word;
	result: Word;
	argument_number: Word;
	token_kind: Word;
	call_size: Word;
begin
	call_size := _call_size();
	result := _allocate(call_size);
	_node_set_kind(result, NodeKind.call);
	_statement_set_next(result, 0);

	argument_number := 1;
	_call_set_name(result, callee);

	_lexer_read_token(@token_kind);
	_lexer_skip_token();
	_lexer_read_token(@token_kind);

	if token_kind = LexerTokenKind.right_paren then
		_lexer_skip_token();
		goto parse_call_end
	end;

	.parse_call_loop;
	parsed_expression := _parse_binary_expression();
	_call_set_argument(result, argument_number, parsed_expression);
	argument_number := argument_number + 1;
	_lexer_read_token(@token_kind);
	_lexer_skip_token();

	if token_kind = LexerTokenKind.comma then
		goto parse_call_loop
	end;

	.parse_call_end;
	(* Set the trailing argument to nil. *)
	_call_set_argument(result, argument_number, 0);

	return result
end;

proc _compile_call(parsed_call: Word);
var
	name_length: Word;
	name: Word;
	argument_count: Word;
	stack_offset: Word;
	parsed_expression: Word;
begin
	parsed_expression := _call_get_name(parsed_call);
	name := _variable_expression_get_name(parsed_expression);
	name_length := _variable_expression_get_length(parsed_expression);
	argument_count := 0;

	.compile_call_loop;

	parsed_expression := _call_get_argument(parsed_call, argument_count + 1);
	if parsed_expression = 0 then
		goto compile_call_finalize
	else
		_compile_binary_expression(parsed_expression);

		(* Save the argument on the stack. *)
		_write_z("\tsw t0, \0");

		stack_offset := argument_count * 4;
		_write_i(116 - stack_offset);
		_write_z("(sp)\n\0");

		argument_count := argument_count + 1;
		goto compile_call_loop
	end;

	.compile_call_finalize;

	(* Load the argument from the stack. *)
	if argument_count <> 0 then
		(* Decrement the argument counter. *)
		argument_count := argument_count - 1;

		_write_z("\tlw a\0");
		_write_i(argument_count);

		_write_z(", \0");

		(* Calculate the stack offset: 116 - (4 * argument_counter) *)
		stack_offset := argument_count * 4;
		_write_i(116 - stack_offset);

		_write_z("(sp)\n\0");

		goto compile_call_finalize
	end;

	_write_z("\tcall \0");
	_write_s(name, name_length);
	_write_c('\n')
end;

(**
 * All statements are chained into a list. Next contains a pointer to the next
 * statement in the statement list.
 *)
proc _statement_get_next(this: Word);
begin
	this := this + 4;
	return this^
end;

proc _statement_set_next(this: Word, value: Word);
begin
	this := this + 4;
	this^ := value
end;

proc _goto_statement_size();
	return 16
end;

proc _goto_statement_get_label(this: Word);
begin
	this := this + 8;
	return this^
end;

proc _goto_statement_set_label(this: Word, value: Word);
begin
	this := this + 8;
	this^ := value
end;

proc _goto_statement_get_length(this: Word);
begin
	this := this + 12;
	return this^
end;

proc _goto_statement_set_length(this: Word, value: Word);
begin
	this := this + 12;
	this^ := value
end;

proc _parse_goto_statement();
var
	token_kind: Word;
	label_name: Word;
	label_length: Word;
	statement_size: Word;
	result: Word;
begin
	_lexer_skip_token();
	_lexer_read_token(@token_kind);

	label_name := _lexer_global_get_start();
	label_length := _lexer_global_get_end() - label_name;
	_lexer_skip_token();

	statement_size := _goto_statement_size();
	result := _allocate(statement_size);

	_node_set_kind(result, NodeKind.goto_statement);
	_statement_set_next(result, 0);
	_goto_statement_set_label(result, label_name);
	_goto_statement_set_length(result, label_length);

	return result
end;

proc _compile_goto_statement(parser_node: Word);
var
	label_name: Word;
	label_length: Word;
begin
	label_name := _goto_statement_get_label(parser_node);
	label_length := _goto_statement_get_length(parser_node);

	_write_z("\tj .\0");
	_write_s(label_name, label_length);
	_write_c('\n')
end;

proc _label_declaration_size();
	return 16
end;

proc _label_declaration_get_label(this: Word);
begin
	this := this + 8;
	return this^
end;

proc _label_declaration_set_label(this: Word, value: Word);
begin
	this := this + 8;
	this^ := value
end;

proc _label_declaration_get_length(this: Word);
begin
	this := this + 12;
	return this^
end;

proc _label_declaration_set_length(this: Word, value: Word);
begin
	this := this + 12;
	this^ := value
end;

proc _parse_label_declaration();
var
	token_kind: Word;
	label_name: Word;
	label_length: Word;
	statement_size: Word;
	result: Word;
begin
	_lexer_skip_token();
	_lexer_read_token(@token_kind);

	label_name := _lexer_global_get_start();
	label_length := _lexer_global_get_end() - label_name;
	_lexer_skip_token();

	statement_size := _label_declaration_size();
	result := _allocate(statement_size);

	_node_set_kind(result, NodeKind.label_declaration);
	_statement_set_next(result, 0);
	_goto_statement_set_label(result, label_name);
	_goto_statement_set_length(result, label_length);

	return result
end;

proc _compile_label_declaration(parser_node: Word);
var
	label_name: Word;
	label_length: Word;
begin
	label_name := _label_declaration_get_label(parser_node);
	label_length := _label_declaration_get_length(parser_node);

	_write_c('.');
	_write_s(label_name, label_length);
	_write_z(":\n\0")
end;

proc _compile_local_designator(symbol: Word);
var
	variable_offset: Word;
begin
	_write_z("\taddi t0, sp, \0");
	variable_offset := _parameter_info_get_offset(symbol);
	_write_i(variable_offset);
	_write_c('\n')
end;

proc _compile_global_designator(variable_expression: Word);
var
	name: Word;
	token_length: Word;
begin
	_write_z("\tla t0, \0");

	name := _variable_expression_get_name(variable_expression);
	token_length := _variable_expression_get_length(variable_expression);

	_write_s(name, token_length);
	_write_c('\n')
end;

proc _field_access_expression_size();
	return 16
end;

proc _field_access_expression_get_aggregate(this: Word);
begin
	this := this + 4;
	return this^
end;

proc _field_access_expression_set_aggregate(this: Word, value: Word);
begin
	this := this + 4;
	this^ := value
end;

proc _field_access_expression_get_field(this: Word);
begin
	this := this + 8;
	return this^
end;

proc _field_access_expression_set_field(this: Word, value: Word);
begin
	this := this + 8;
	this^ := value
end;

proc _field_access_expression_get_length(this: Word);
begin
	this := this + 12;
	return this^
end;

proc _field_access_expression_set_length(this: Word, value: Word);
begin
	this := this + 12;
	this^ := value
end;

proc _compile_enumeration_value(field_access_expression: Word);
var
	enumeration_type: Word;
	members: Word;
	members_length: Word;
	token_type: Word;
	value_name: Word;
	name_length: Word;
	member_name: Word;
	member_length: Word;
	counter: Word;
	symbol: Word;
begin
	symbol := _field_access_expression_get_aggregate(field_access_expression);
	value_name := _variable_expression_get_name(symbol);
	name_length := _variable_expression_get_length(symbol);

	symbol := _symbol_table_lookup(@symbol_table_global, value_name, name_length);

	enumeration_type := _type_info_get_type(symbol);
	members := _enumeration_type_get_members(enumeration_type);
	members_length := _enumeration_type_get_length(enumeration_type);

	_lexer_read_token(@token_type);

	value_name := _field_access_expression_get_field(field_access_expression);
	name_length := _field_access_expression_get_length(field_access_expression);
	counter := 1;

	.compile_enumeration_value_members;
	if members_length > 0 then
		member_name := members^;
		member_length := members + 4;
		member_length := member_length^;

		if _lexer_compare_keyword(value_name, name_length, member_name, member_length) then
		else
			members_length := members_length - 1;
			members := members + 8;
			counter := counter + 1;
			goto compile_enumeration_value_members
		end;
		_write_z("\tli t0, \0");
		_write_i(counter);
		_write_c('\n')
	end
end;

proc _parse_field_access_expression(aggregate: Word);
var
	token_kind: Word;
	name: Word;
	name_token: Word;
	result: Word;
	memory_size: Word;
begin
	(* Skip dot. Read the enumeration value. *)
	_lexer_skip_token();
	_lexer_read_token(@token_kind);

	name := _lexer_global_get_start();
	name_token := _lexer_global_get_end();
	name_token := name_token - name;
	_lexer_skip_token();
	memory_size := _field_access_expression_size();
	result := _allocate(memory_size);

	_node_set_kind(result, NodeKind.field_access_expression);
	_field_access_expression_set_aggregate(result, aggregate);
	_field_access_expression_set_field(result, name);
	_field_access_expression_set_length(result, name_token);

	return result
end;

proc _compile_designator(parser_node: Word);
var
	name_token: Word;
	lookup_result: Word;
	token_kind: Word;
	parser_node: Word;
	is_address: Word;
	node_kind: Word;
begin
	is_address := 1;
	node_kind := _node_get_kind(parser_node);

	if node_kind = NodeKind.dereference_expression then
		parser_node := _dereference_expression_get_pointer(parser_node);
		_compile_simple_expression(parser_node);
		_write_z("\tlw t0, (t0)\n\0")
	elsif node_kind = NodeKind.field_access_expression then
		_compile_enumeration_value(parser_node);
		is_address := 0
	elsif node_kind = NodeKind.call then
		_compile_call(parser_node);
		_write_z("\tmv t0, a0\n\0");
		is_address := 0
	else
		is_address := _compile_simple_expression(parser_node)
	end;
	return is_address
end;

proc _assignment_statement_size();
	return 16
end;

proc _assignment_statement_get_assignee(this: Word);
begin
	this := this + 8;
	return this^
end;

proc _assignment_statement_set_assignee(this: Word, value: Word);
begin
	this := this + 8;
	this^ := value
end;

proc _assignment_statement_get_assignment(this: Word);
begin
	this := this + 12;
	return this^
end;

proc _assignment_statement_set_assignment(this: Word, value: Word);
begin
	this := this + 12;
	this^ := value
end;

proc _parse_assignment_statement(assignee: Word);
var
	statement_size: Word;
	result: Word;
	token_kind: Word;
	assignment_node: Word;
begin
	statement_size := _assignment_statement_size();
	result := _allocate(statement_size);

	_node_set_kind(result, NodeKind.assignment_statement);
	_statement_set_next(result, 0);
	_assignment_statement_set_assignee(result, assignee);

	(* Skip the assignment sign (:=) with surrounding whitespaces. *)
	_lexer_read_token(@token_kind);
	_lexer_skip_token();

	assignment_node := _parse_binary_expression();
	_assignment_statement_set_assignment(result, assignment_node);

	return result
end;

proc _compile_assignment_statement(parser_tree: Word);
var
	current_expression: Word;
begin
	current_expression := _assignment_statement_get_assignee(parser_tree);
	_compile_designator(current_expression);

	(* Save the assignee address on the stack. *)
	_write_z("\tsw t0, 60(sp)\n\0");

	(* Compile the assignment. *)
	current_expression := _assignment_statement_get_assignment(parser_tree);
	_compile_binary_expression(current_expression);

	_write_z("\tlw t1, 60(sp)\n\tsw t0, (t1)\n\0")
end;

proc _return_statement_size();
	return 12
end;

proc _return_statement_get_returned(this: Word);
begin
	this := this + 8;
	return this^
end;

proc _return_statement_set_returned(this: Word, value: Word);
begin
	this := this + 8;
	this^ := value
end;

proc _parse_return_statement();
var
	token_kind: Word;
	returned: Word;
	label_length: Word;
	statement_size: Word;
	result: Word;
begin
	(* Skip "return" keyword and whitespace after it. *)
	_lexer_skip_token();
	_lexer_read_token(@token_kind);

	returned := _parse_binary_expression();

	statement_size := _return_statement_size();
	result := _allocate(statement_size);

	_node_set_kind(result, NodeKind.return_statement);
	_statement_set_next(result, 0);
	_return_statement_set_returned(result, returned);

	return result
end;

proc _compile_return_statement(parser_node: Word);
var
	return_expression: Word;
begin
	return_expression := _return_statement_get_returned(parser_node);
	_compile_binary_expression(return_expression);
	_write_z("\tmv a0, t0\n\0")
end;

(**
 * Writes a label, .Ln, where n is a unique number.
 *
 * Parameters:
 * counter - Label counter.
 *)
proc _write_label(counter: Word);
begin
	_write_z(".L\0");
	_write_i(counter)
end;

proc _parse_conditional_statements();
var
	conditional_size: Word;
	token_kind: Word;
	current_node: Word;
	result: Word;
begin
	conditional_size := _conditional_statements_size();
	result := _allocate(conditional_size);

	(* Skip "if", "while" or "elsif". *)
	_lexer_skip_token();

	current_node := _parse_binary_expression();
	_conditional_statements_set_condition(result, current_node);

	(* Skip "then" or "do". *)
	_lexer_read_token(@token_kind);
	_lexer_skip_token();

	current_node := _parse_statements();
	_conditional_statements_set_statements(result, current_node);

	_conditional_statements_set_next(result, 0);
	return result
end;

proc _compile_conditional_statements(parser_node: Word, after_end_label: Word);
var
	condition_label: Word;
	current_node: Word;
begin
	(* Compile condition. *)
	current_node := _conditional_statements_get_condition(parser_node);
	_compile_binary_expression(current_node);

	(* condition_label is the label in front of the next elsif condition or end. *)
	condition_label := label_counter;
	label_counter := label_counter + 1;

	_write_z("\tbeqz t0, \0");
	_write_label(condition_label);
	_write_c('\n');

	current_node := _conditional_statements_get_statements(parser_node);
	_compile_statements(current_node);

	_write_z("\tj \0");
	_write_label(after_end_label);
	_write_c('\n');

	_write_label(condition_label);
	_write_z(":\n\0")
end;

(**
 * Conditional statements is a list of pairs: condition and statements.
 * Used for example to represent if and elsif blocks with beloning statements.
 *)
proc _conditional_statements_size();
	return 12
end;

proc _conditional_statements_get_condition(this: Word);
	return this^
end;

proc _conditional_statements_set_condition(this: Word, value: Word);
begin
	this^ := value
end;

proc _conditional_statements_get_statements(this: Word);
begin
	this := this + 4;
	return this^
end;

proc _conditional_statements_set_statements(this: Word, value: Word);
begin
	this := this + 4;
	this^ := value
end;

proc _conditional_statements_get_next(this: Word);
begin
	this := this + 8;
	return this^
end;

proc _conditional_statements_set_next(this: Word, value: Word);
begin
	this := this + 8;
	this^ := value
end;

proc _if_statement_size();
	return 16
end;

proc _if_statement_get_conditionals(this: Word);
begin
	this := this + 8;
	return this^
end;

proc _if_statement_set_conditionals(this: Word, value: Word);
begin
	this := this + 8;
	this^ := value
end;

proc _if_statement_get_else(this: Word);
begin
	this := this + 12;
	return this^
end;

proc _if_statement_set_else(this: Word, value: Word);
begin
	this := this + 12;
	this^ := value
end;

proc _parse_if_statement();
var
	current_node: Word;
	result: Word;
	object_size: Word;
	token_kind: Word;
	previous_conditional: Word;
	next_conditional: Word;
begin
	object_size := _if_statement_size();
	result := _allocate(object_size);

	_node_set_kind(result, NodeKind.if_statement);
	_statement_set_next(result, 0);

	previous_conditional := _parse_conditional_statements();
	_if_statement_set_conditionals(result, previous_conditional);

	.parse_if_statement_loop;
	_lexer_read_token(@token_kind);

	if token_kind = LexerTokenKind._elsif then
		next_conditional := _parse_conditional_statements();
		_conditional_statements_set_next(previous_conditional, next_conditional);
		previous_conditional = next_conditional;

		goto parse_if_statement_loop
	elsif token_kind = LexerTokenKind._else then
		_lexer_skip_token();

		current_node := _parse_statements();
		_if_statement_set_else(result, current_node)
	else
		_if_statement_set_else(result, 0)
	end;
	_lexer_skip_token();

	return result
end;

proc _parse_statement();
var
	token_kind: Word;
	result : Word;
begin
	result := 0;
	_lexer_read_token(@token_kind);

	if token_kind = LexerTokenKind._goto then
		result := _parse_goto_statement()
	elsif token_kind = LexerTokenKind._if then
		result := _parse_if_statement()
	elsif token_kind = LexerTokenKind._return then
		result := _parse_return_statement()
	elsif token_kind = LexerTokenKind.dot then
		result := _parse_label_declaration()
	elsif token_kind = LexerTokenKind.identifier then
		result := _parse_designator();

		if _node_get_kind(result) <> NodeKind.call then
			result := _parse_assignment_statement(result)
		end
	end;
	return result
end;

proc _parse_statements();
var
	token_kind: Word;
	previous_statement: Word;
	next_statement: Word;
	first_statement: Word;
begin
	_skip_empty_lines();

	first_statement := _parse_statement();
	previous_statement := first_statement;
	if previous_statement = 0 then
		goto parse_statements_end
	end;

	.parse_statement_loop;
	_lexer_read_token(@token_kind);

	if token_kind = LexerTokenKind.semicolon then
		_lexer_skip_token();
		_skip_empty_lines();
		next_statement := _parse_statement();
		_statement_set_next(previous_statement, next_statement);
		previous_statement := next_statement;

		if previous_statement <> 0 then
			goto parse_statement_loop
		end
	end;
	.parse_statements_end;
	_skip_empty_lines();

	return first_statement
end;

proc _compile_statements(parser_node: Word);
var
	current_statement: Word;
begin
	current_statement := parser_node;

	.compile_statements_loop;
	if current_statement <> 0 then
		_compile_statement(current_statement);
		current_statement := _statement_get_next(current_statement);
		goto compile_statements_loop
	end
end;

proc _compile_if_statement(parser_node: Word);
var
	current_node: Word;
	after_end_label: Word;
	condition_label: Word;
begin
	after_end_label := label_counter;
	label_counter := label_counter + 1;

	current_node := _if_statement_get_conditionals(parser_node);
	_compile_conditional_statements(current_node, after_end_label);

	.compile_if_statement_loop;
	current_node := _conditional_statements_get_next(current_node);
	if current_node <> 0 then
		_compile_conditional_statements(current_node, after_end_label);
		goto compile_if_statement_loop
	end;
	current_node := _if_statement_get_else(parser_node);

	if current_node <> 0 then
		_compile_statements(current_node)
	end;

	_write_label(after_end_label);
	_write_z(":\n\0")
end;

proc _compile_statement(parser_node: Word);
var
	statement_kind: Word;
begin
	statement_kind := _node_get_kind(parser_node);

	if statement_kind = NodeKind.goto_statement then
		_compile_goto_statement(parser_node)
	elsif statement_kind = NodeKind.if_statement then
		_compile_if_statement(parser_node)
	elsif statement_kind = NodeKind.return_statement then
		_compile_return_statement(parser_node)
	elsif statement_kind = NodeKind.label_declaration then
		_compile_label_declaration(parser_node)
	elsif statement_kind = NodeKind.call then
		_compile_call(parser_node)
	elsif statement_kind = NodeKind.assignment_statement then
		_compile_assignment_statement(parser_node)
	end
end;

(**
 * Writes a regster name to the standard output.
 *
 * Parameters:
 * register_character - Register character.
 * register_number - Register number.
 *)
proc _write_register(register_character: Word, register_number: Word);
begin
	_write_c(register_character);
	_write_c(register_number + '0')
end;

proc _type_get_kind(this: Word);
	return this^
end;

proc _type_set_kind(this: Word, value: Word);
begin
	this^ := value
end;

proc _type_get_size(this: Word);
begin
	this := this + 4;
	return this^
end;

proc _type_set_size(this: Word, value: Word);
begin
	this := this + 4;
	this^ := value
end;

proc _enumeration_type_get_members(this: Word);
begin
	this := this + 8;
	return this^
end;

proc _enumeration_type_set_members(this: Word, value: Word);
begin
	this := this + 8;
	this^ := value
end;

proc _enumeration_type_get_length(this: Word);
begin
	this := this + 12;
	return this^
end;

proc _enumeration_type_set_length(this: Word, value: Word);
begin
	this := this + 12;
	this^ := value
end;

proc _enumeration_type_expression_size();
	return 12
end;

proc _enumeration_type_expression_get_members(this: Word);
begin
	this := this + 4;
	return this^
end;

proc _enumeration_type_expression_set_members(this: Word, value: Word);
begin
	this := this + 4;
	this^ := value
end;

proc _enumeration_type_expression_get_length(this: Word);
begin
	this := this + 8;
	return this^
end;

proc _enumeration_type_expression_set_length(this: Word, value: Word);
begin
	this := this + 8;
	this^ := value
end;

proc _named_type_expression_size();
	return 12
end;

proc _named_type_expression_get_name(this: Word);
begin
	this := this + 4;
	return this^
end;

proc _named_type_expression_set_name(this: Word, value: Word);
begin
	this := this + 4;
	this^ := value
end;

proc _named_type_expression_get_length(this: Word);
begin
	this := this + 8;
	return this^
end;

proc _named_type_expression_set_length(this: Word, value: Word);
begin
	this := this + 8;
	this^ := value
end;

proc _parse_enumeration_type_expression();
var
	token_kind: Word;
	enumeration_name: Word;
	name_length: Word;
	memory_start: Word;
	member_count: Word;
	result: Word;
	type_expression_size: Word;
begin
	_lexer_skip_token();
	memory_start := memory_free_pointer;
	member_count := 0;

	_lexer_read_token(@token_kind);
	if token_kind = LexerTokenKind.right_paren then
		goto parse_enumeration_type_expression_end
	end;
	.parse_enumeration_type_expression_loop;
	member_count := member_count + 1;

	enumeration_name := _lexer_global_get_start();
	name_length := _lexer_global_get_end() - enumeration_name;

	memory_free_pointer^ := enumeration_name;
	memory_free_pointer := memory_free_pointer + 4;

	memory_free_pointer^ := name_length;
	memory_free_pointer := memory_free_pointer + 4;

	(* Skip the identifier. *)
	_lexer_skip_token();

	_lexer_read_token(@token_kind);
	if token_kind = LexerTokenKind.comma then
		_lexer_skip_token();
		_lexer_read_token(@token_kind);
		goto parse_enumeration_type_expression_loop
	end;

	.parse_enumeration_type_expression_end;
	_lexer_skip_token();

	type_expression_size := _enumeration_type_expression_size();
	result := _allocate(type_expression_size);

	_node_set_kind(result, NodeKind.enumeration_type_expression);
	_enumeration_type_expression_set_members(result, memory_start);
	_enumeration_type_expression_set_length(result, member_count);

	return result
end;

(**
 * Reads and creates enumeration type representation.
 *
 * record
 *   type_kind: Word;
 *   size: Word;
 *   members: StringArray;
 *   length: Word
 * end;
 *
 * Returns enumeration type description.
 *)
proc _read_type_enumeration(parser_node: Word);
var
	result: Word;
	memory_start: Word;
	member_count: Word;
begin
	(* The resulting structure is 16 bytes long. *)
	result := _allocate(16);

	memory_start := _enumeration_type_expression_get_members(parser_node);
	member_count := _enumeration_type_expression_get_length(parser_node);

	_type_set_kind(result, TypeKind.enumeration);
	_type_set_size(result, 4);
	_enumeration_type_set_members(result, memory_start);
	_enumeration_type_set_length(result, member_count);

	return _type_info_create(result)
end;

proc _parse_named_type_expression();
var
	type_expression_size: Word;
	result: Word;
	type_name: Word;
	name_length: Word;
begin
	type_expression_size := _named_type_expression_size();
	result := _allocate(type_expression_size);

	_node_set_kind(result, NodeKind.named_type_expression);
	type_name := _lexer_global_get_start();
	name_length := _lexer_global_get_end() - type_name;
	_named_type_expression_set_name(result, type_name);
	_named_type_expression_set_length(result, name_length);
	_lexer_skip_token();

	return result
end;

proc _parse_type_expression();
var
	token_kind: Word;
	result: Word;
begin
	result := 0;
	_lexer_read_token(@token_kind);

	if token_kind = LexerTokenKind.identifier then
		result := _parse_named_type_expression()
	elsif token_kind = LexerTokenKind.left_paren then
		result := _parse_enumeration_type_expression()
	end;
	return result
end;

proc _read_type_expression(parser_node: Word);
var
	token_kind: Word;
	type_name: Word;
	name_length: Word;
	result: Word;
begin
	token_kind := _node_get_kind(parser_node);

	if token_kind = NodeKind.named_type_expression then
		type_name := _named_type_expression_get_name(parser_node);
		name_length := _named_type_expression_get_length(parser_node);

		result := _symbol_table_lookup(@symbol_table_global, type_name, name_length);
		result := _type_info_get_type(result)
	elsif token_kind = NodeKind.enumeration_type_expression then
		result := _read_type_enumeration(parser_node)
	end;

	return result
end;

proc _type_info_get_type(this: Word);
begin
	this := this + 4;
	return this^
end;

(**
 * Parameters:
 * parameter_index - Parameter index.
 *)
proc _parameter_info_create(parameter_index: Word);
var
	offset: Word;
	current_word: Word;
	result: Word;
begin
	result := memory_free_pointer;
	current_word := result;
	current_word^ := InfoKind.parameter_info;

	current_word := current_word + 4;

	(* Calculate the stack offset: 88 - (4 * parameter_counter) *)
	offset := parameter_index * 4;
	current_word^ := 88 - offset;

	memory_free_pointer := current_word + 4;

	return result
end;

proc _parameter_info_get_offset(this: Word);
begin
	this := this + 4;
	return this^
end;

proc _type_info_create(type_representation: Word);
var
	result: Word;
	current_word: Word;
begin
	result := memory_free_pointer;
	current_word := result;
	current_word^ := InfoKind.type_info;

	current_word := current_word + 4;
	current_word^ := type_representation;

	memory_free_pointer := current_word + 4;

	return result
end;

(**
 * Parameters:
 * temporary_index - Parameter index.
 *)
proc _temporary_info_create(temporary_index: Word);
var
	offset: Word;
	current_word: Word;
	result: Word;
begin
	result := memory_free_pointer;
	current_word := result;
	current_word^ := InfoKind.temporary_info;
	current_word := current_word + 4;

	(* Calculate the stack offset: 4 * variable_counter. *)
	current_word^ := temporary_index * 4;

	memory_free_pointer := current_word + 4;

	return result
end;

(**
 * Parameters:
 * parameter_index - Parameter index.
 *)
proc _read_procedure_parameter(parser_node: Word, parameter_index: Word);
var
	name_length: Word;
	info: Word;
	name_position: Word;
begin
	name_position := _declaration_get_name(parser_node);
	name_length := _declaration_get_length(parser_node);

	_write_z("\tsw a\0");
	_write_i(parameter_index);
	_write_z(", \0");

	info := _parameter_info_create(parameter_index);
	_symbol_table_enter(@symbol_table_local, name_position, name_length, info);

	info := _parameter_info_get_offset(info);
	_write_i(info);

	_write_z("(sp)\n\0")
end;

(**
 * Parameters:
 * variable_index - Variable index.
 *)
proc _read_procedure_temporary(parser_node: Word, variable_index: Word);
var
	name_length: Word;
	info: Word;
	name_position: Word;
begin
	name_position := _declaration_get_name(parser_node);
	name_length := _declaration_get_length(parser_node);

	info := _temporary_info_create(variable_index);
	_symbol_table_enter(@symbol_table_local, name_position, name_length, info)
end;

proc _read_procedure_temporaries(parser_node: Word);
var
	temporary_counter: Word;
begin
	temporary_counter := 0;

	.read_procedure_temporaries_loop;
	if parser_node = 0 then
		goto read_procedure_temporaries_end
	end;
	_read_procedure_temporary(parser_node, temporary_counter);

	temporary_counter := temporary_counter + 1;
	parser_node := _declaration_get_next(parser_node);
	goto read_procedure_temporaries_loop;

	.read_procedure_temporaries_end
end;

proc _declaration_get_next(this: Word);
begin
	this := this + 4;
	return this^
end;

proc _declaration_set_next(this: Word, value: Word);
begin
	this := this + 4;
	this^ := value
end;

proc _declaration_get_name(this: Word);
begin
	this := this + 8;
	return this^
end;

proc _declaration_set_name(this: Word, value: Word);
begin
	this := this + 8;
	this^ := value
end;

proc _declaration_get_length(this: Word);
begin
	this := this + 12;
	return this^
end;

proc _declaration_set_length(this: Word, value: Word);
begin
	this := this + 12;
	this^ := value
end;

(* Kind + next declaration pointer + argument list + procedure name + statement list pointer + temporary list pointer. *)
proc _procedure_declaration_size();
	return 28
end;

proc _procedure_declaration_get_body(this: Word);
begin
	this := this + 16;
	return this^
end;

proc _procedure_declaration_set_body(this: Word, value: Word);
begin
	this := this + 16;
	this^ := value
end;

proc _procedure_declaration_get_temporaries(this: Word);
begin
	this := this + 20;
	return this^
end;

proc _procedure_declaration_set_temporaries(this: Word, value: Word);
begin
	this := this + 20;
	this^ := value
end;

proc _procedure_declaration_get_parameters(this: Word);
begin
	this := this + 24;
	return this^
end;

proc _procedure_declaration_set_parameters(this: Word, value: Word);
begin
	this := this + 24;
	this^ := value
end;

proc _parse_procedure_declaration();
var
	name_pointer: Word;
	name_length: Word;
	token_kind: Word;
	result: Word;
	declaration_size: Word;
	parameter_head: Word;
begin
	declaration_size := _procedure_declaration_size();
	result := _allocate(declaration_size);

	_node_set_kind(result, NodeKind.procedure_declaration);
	_declaration_set_next(result, 0);

	(* Skip "proc ". *)
	_lexer_skip_token();

	_lexer_read_token(@token_kind);
	name_pointer := _lexer_global_get_start();
	name_length := _lexer_global_get_end() - name_pointer;

	_declaration_set_name(result, name_pointer);
	_declaration_set_length(result, name_length);
	(* Skip procedure name. *)
	_lexer_skip_token();

	(* Skip open paren. *)
	_lexer_read_token(@token_kind);
	_lexer_skip_token();
	parameter_head := 0;

	.parse_procedure_declaration_parameter;
	_lexer_read_token(@token_kind);

	if token_kind <> LexerTokenKind.right_paren then
		name_pointer := _parse_variable_declaration();
		if parameter_head = 0 then
			parameter_head := name_pointer
		else
			_declaration_set_next(name_length, name_pointer)
		end;
		name_length := name_pointer;

		_lexer_read_token(@token_kind);

		if token_kind = LexerTokenKind.comma then
			_lexer_skip_token();
			goto parse_procedure_declaration_parameter
		end
	end;
	(* Skip close paren. *)
	_lexer_skip_token();
	_procedure_declaration_set_parameters(result, parameter_head);

	(* Skip semicolon and newline. *)
	_lexer_read_token(@token_kind);
	_lexer_skip_token();

	parameter_head := _parse_var_part();
	_procedure_declaration_set_temporaries(result, parameter_head);

	(* Skip semicolon, "begin" and newline. *)
	_lexer_read_token(@token_kind);
	if token_kind = LexerTokenKind._begin then
		_lexer_skip_token();
		parameter_head := _parse_statements()
	elsif token_kind = LexerTokenKind._return then
		parameter_head := _parse_return_statement()
	end;
	_procedure_declaration_set_body(result, parameter_head);

	(* Skip the "end" keyword. *)
	_lexer_read_token(@token_kind);
	_lexer_skip_token();

	return result
end;

proc _compile_procedure_declaration(parser_node: Word);
var
	name_pointer: Word;
	name_length: Word;
	parameter_counter: Word;
	current_parameter: Word;
begin
	(* Clear local symbol table. *)
	symbol_table_local := 0;

	name_pointer := _declaration_get_name(parser_node);
	name_length := _declaration_get_length(parser_node);

	(* Write .type _procedure_name, @function. *)
	_write_z(".type \0");

	_write_s(name_pointer, name_length);
	_write_z(", @function\n\0");

	(* Write procedure label, _procedure_name: *)
	_write_s(name_pointer, name_length);
	_write_z(":\n\0");

	(* Write the prologue. *)
	_write_z("\taddi sp, sp, -128\n\tsw ra, 124(sp)\n\tsw s0, 120(sp)\n\taddi s0, sp, 128\n\0");

	current_parameter := _procedure_declaration_get_parameters(parser_node);
	parameter_counter := 0;
	.compile_procedure_declaration_parameter;
	if current_parameter = 0 then
		goto compile_procedure_declaration_end
	end;
	_read_procedure_parameter(current_parameter, parameter_counter);
	parameter_counter := parameter_counter + 1;

	current_parameter := _declaration_get_next(current_parameter);
	goto compile_procedure_declaration_parameter;

	.compile_procedure_declaration_end;

	current_parameter := _procedure_declaration_get_temporaries(parser_node);
	_read_procedure_temporaries(current_parameter);

	current_parameter := _procedure_declaration_get_body(parser_node);
	_compile_statements(current_parameter);

	(* Write the epilogue. *)
	_write_z("\tlw ra, 124(sp)\n\tlw s0, 120(sp)\n\taddi sp, sp, 128\n\tret\n\0")
end;

proc _parse_procedures();
var
	parser_node: Word;
	result: Word;
	current_declaration: Word;
	token_kind: Word;
begin
	result := 0;

	.parse_procedures_loop;
	_skip_empty_lines();
	_lexer_read_token(@token_kind);

	if token_kind = LexerTokenKind._proc then
		parser_node := _parse_procedure_declaration();
		if result = 0 then
			result := parser_node
		else
			_declaration_set_next(current_declaration, parser_node)
		end;
		current_declaration := parser_node;

		(* Skip semicolon. *)
		_lexer_read_token(@token_kind);
		_lexer_skip_token();

		goto parse_procedures_loop
	end;
	return result
end;

proc _compile_procedures(parser_node: Word);
var
	result: Word;
begin
	.compile_procedures_loop;
	if parser_node = 0 then
		goto compile_procedures_end
	end;
	_compile_procedure_declaration(parser_node);
	parser_node := _declaration_get_next(parser_node);
	goto compile_procedures_loop;

	.compile_procedures_end
end;

(**
 * Skips comments.
 *)
proc _skip_empty_lines();
var
	token_kind: Word;
begin
	.skip_empty_lines_rerun;

	_lexer_read_token(@token_kind);

	if token_kind = LexerTokenKind.comment then
		_lexer_skip_token();
		goto skip_empty_lines_rerun
	end
end;


proc _type_declaration_size();
	return 20
end;

proc _type_declaration_get_type(this: Word);
begin
	this := this + 16;
	return this^
end;

proc _type_declaration_set_type(this: Word, value: Word);
begin
	this := this + 16;
	this^ := value
end;

proc _parse_type_declaration();
var
	token_kind: Word;
	type_name: Word;
	name_length: Word;
	parser_node: Word;
	result: Word;
	declaration_size: Word;
begin
	_lexer_read_token(@token_kind);
	type_name := _lexer_global_get_start();
	name_length := _lexer_global_get_end() - type_name;

	_lexer_skip_token();
	_lexer_read_token(@token_kind);
	_lexer_skip_token();

	parser_node := _parse_type_expression();
	declaration_size := _type_declaration_size();
	result := _allocate(declaration_size);

	_node_set_kind(result, NodeKind.type_declaration);
	_declaration_set_next(result, 0);
	_declaration_set_name(result, type_name);
	_declaration_set_length(result, name_length);
	_type_declaration_set_type(result, parser_node);

	_lexer_read_token(@token_kind);
	_lexer_skip_token();

	return result
end;

proc _read_type_declaration(parser_node: Word);
var
	type_name: Word;
	name_length: Word;
	type_info: Word;
begin
	type_name := _declaration_get_name(parser_node);
	name_length := _declaration_get_length(parser_node);

	parser_node := _type_declaration_get_type(parser_node);
	type_info := _read_type_expression(parser_node);

	_symbol_table_enter(@symbol_table_global, type_name, name_length, type_info)
end;

proc _parse_type_part();
var
	token_kind: Word;
	parser_node: Word;
	result: Word;
	current_declaration: Word;
begin
	result := 0;
	_skip_empty_lines();
	_lexer_read_token(@token_kind);

	if token_kind <> LexerTokenKind._type then
		goto parse_type_part_end
	end;
	_lexer_skip_token();

	.parse_type_part_loop;
	_skip_empty_lines();

	_lexer_read_token(@token_kind);
	if token_kind = LexerTokenKind.identifier then
		parser_node := _parse_type_declaration();

		if result = 0 then
			result := parser_node
		else
			_declaration_set_next(current_declaration, parser_node)
		end;
		current_declaration := parser_node;
		goto parse_type_part_loop
	end;

	.parse_type_part_end;
	return result
end;

proc _read_type_part(parser_node: Word);
begin
	.read_type_part_loop;
	if parser_node = 0 then
		goto read_type_part_end
	end;

	_read_type_declaration(parser_node);
	parser_node := _declaration_get_next(parser_node);

	goto read_type_part_loop;
	.read_type_part_end
end;

proc _variable_declaration_size();
	return 20
end;

proc _variable_declaration_get_type(this: Word);
begin
	this := this + 16;
	return this^
end;

proc _variable_declaration_set_type(this: Word, value: Word);
begin
	this := this + 16;
	this^ := value
end;

proc _parse_variable_declaration();
var
	token_kind: Word;
	name: Word;
	name_length: Word;
	variable_type: Word;
	result: Word;
	declaration_size: Word;
begin
	_lexer_read_token(@token_kind);

	name := _lexer_global_get_start();
	name_length := _lexer_global_get_end() - name;

	(* Skip the variable name and colon with the type. *)
	_lexer_skip_token();
	_lexer_read_token(@token_kind);
	_lexer_skip_token();
	variable_type := _parse_type_expression();

	declaration_size := _variable_declaration_size();
	result := _allocate(declaration_size);

	_node_set_kind(result, NodeKind.variable_declaration);
	_declaration_set_next(result, 0);
	_declaration_set_name(result, name);
	_declaration_set_length(result, name_length);
	_variable_declaration_set_type(result, variable_type);

	return result
end;

proc _compile_variable_declaration(parser_tree: Word);
var
	name: Word;
	name_length: Word;
	token_kind: Word;
	variable_type: Word;
begin
	name := _declaration_get_name(parser_tree);
	name_length := _declaration_get_length(parser_tree);
	variable_type := _variable_declaration_get_type(parser_tree);

	_write_z(".type \0");
	_write_s(name, name_length);
	_write_z(", @object\n\0");

	_write_s(name, name_length);
	_write_c(':');

	_lexer_read_token(@token_kind);
	name := _named_type_expression_get_name(variable_type);
	name_length := _named_type_expression_get_length(variable_type);

	if _lexer_compare_keyword("Array", 5, name, name_length) then
		(* Else we assume this is a zeroed 409600 bytes big array. *)
		_write_z(" .zero 409600\0")
	else
		_write_z(" .word 0\n\0")
	end;
	_write_c('\n')
end;

proc _parse_var_part();
var
	result: Word;
	token_kind: Word;
	variable_node: Word;
	current_declaration: Word;
begin
	result := 0;
	_lexer_read_token(@token_kind);

	if token_kind <> LexerTokenKind._var then
		goto parse_var_part_end
	end;
	(* Skip "var". *)
	_lexer_skip_token();

	.parse_var_part_loop;
	_skip_empty_lines();
	_lexer_read_token(@token_kind);

	if token_kind = LexerTokenKind.identifier then
		variable_node := _parse_variable_declaration();

		(* Skip semicolon. *)
		_lexer_read_token(@token_kind);
		_lexer_skip_token();

		if result = 0 then
			result := variable_node
		else
			_declaration_set_next(current_declaration, variable_node)
		end;
		current_declaration := variable_node;
		goto parse_var_part_loop
	end;

	.parse_var_part_end;
	return result
end;

proc _compile_var_part(parser_node: Word);
begin
	if parser_node = 0 then
		goto compile_var_part_end
	end;
	_write_z(".section .data\n\0");

	.compile_var_part_loop;
	_compile_variable_declaration(parser_node);

	parser_node := _declaration_get_next(parser_node);
	if parser_node <> 0 then
		goto compile_var_part_loop
	end;

	.compile_var_part_end
end;

proc _module_declaration_size();
	return 16
end;

proc _module_declaration_get_types(this: Word);
begin
	this := this + 4;
	return this^
end;

proc _module_declaration_set_types(this: Word, value: Word);
begin
	this := this + 4;
	this^ := value
end;

proc _module_declaration_get_globals(this: Word);
begin
	this := this + 8;
	return this^
end;

proc _module_declaration_set_globals(this: Word, value: Word);
begin
	this := this + 8;
	this^ := value
end;

proc _module_declaration_get_procedures(this: Word);
begin
	this := this + 12;
	return this^
end;

proc _module_declaration_set_procedures(this: Word, value: Word);
begin
	this := this + 12;
	this^ := value
end;

proc _parse_module_declaration();
var
	parser_node: Word;
	declaration_size: Word;
	result: Word;
begin
	declaration_size := _module_declaration_size();
	result := _allocate(declaration_size);

	_node_set_kind(result, NodeKind.module_declaration);

	parser_node := _parse_type_part();
	_module_declaration_set_types(result, parser_node);

	parser_node := _parse_var_part();
	_module_declaration_set_globals(result, parser_node);

	parser_node := _parse_procedures();
	_module_declaration_set_procedures(result, parser_node);

	return result
end;

(**
 * Process the source code and print the generated code.
 *)
proc _compile_module_declaration(parser_node: Word);
var
	current_part: Word;
	compiler_strings_copy: Word;
	compiler_strings_end: Word;
	current_byte: Word;
begin
	_write_z(".globl _start\n\n\0");

	current_part := _module_declaration_get_types(parser_node);
	_read_type_part(current_part);

	current_part := _module_declaration_get_globals(parser_node);
	_compile_var_part(current_part);

	_write_z(".section .text\n\n\0");
	_write_z(".type _syscall, @function\n_syscall:\n\tmv a7, a6\n\tecall\n\tret\n\n\0");
	_write_z(".type _load_byte, @function\n_load_byte:\n\tlb a0, (a0)\nret\n\n\0");
	_write_z(".type _store_byte, @function\n_store_byte:\n\tsb a0, (a1)\nret\n\n\0");

	current_part := _module_declaration_get_procedures(parser_node);
	_compile_procedures(current_part);

	_write_z(".section .rodata\n.type strings, @object\nstrings: .ascii \0");
	_write_c('"');

	compiler_strings_copy := @compiler_strings;
	compiler_strings_end := compiler_strings_position;

	.compile_module_declaration_loop;
	if compiler_strings_copy < compiler_strings_end then
		current_byte := _load_byte(compiler_strings_copy);
		compiler_strings_copy := compiler_strings_copy + 1;
		_write_c(current_byte);

		goto compile_module_declaration_loop
	end;
	_write_c('"');
	_write_c('\n')
end;

proc _compile();
var
	parser_node: Word;
begin
	parser_node := _parse_module_declaration();
	_compile_module_declaration(parser_node)
end;

(**
 * Terminates the program. a0 contains the return code.
 *
 * Parameters:
 * a0 - Status code.
 *)
proc _exit(status: Word);
begin
	_syscall(status, 0, 0, 0, 0, 0, 93)
end;

(**
 * Looks for a symbol in the given symbol table.
 *
 * Parameters:
 * symbol_table - Symbol table.
 * symbol_name - Symbol name pointer.
 * name_length - Symbol name length.
 *
 * Returns the symbol pointer or 0 in a0.
 *)
proc _symbol_table_lookup(symbol_table: Word, symbol_name: Word, name_length: Word);
var
	result: Word;
	symbol_table_length: Word;
	current_name: Word;
	current_length: Word;
begin
	result := 0;

	(* The first word in the symbol table is its length, get it. *)
	symbol_table_length := symbol_table^;

	(* Go to the first symbol position. *)
	symbol_table := symbol_table + 4;

	.symbol_table_lookup_loop;
	if symbol_table_length = 0 then
		goto symbol_table_lookup_end
	end;

	(* Symbol name pointer and length. *)
	current_name := symbol_table^;
	current_length := symbol_table + 4;
	current_length := current_length^;

	(* If lengths don't match, exit and return nil. *)
	if name_length <> current_length then
		goto symbol_table_lookup_repeat
	end;
	(* If names don't match, exit and return nil. *)
	if _memcmp(symbol_name, current_name, name_length) then
		goto symbol_table_lookup_repeat
	end;
	(* Otherwise, the symbol is found. *)
	result := symbol_table + 8;
	result := result^;
	goto symbol_table_lookup_end;

	.symbol_table_lookup_repeat;
	symbol_table := symbol_table + 12;
	symbol_table_length := symbol_table_length - 1;
	goto symbol_table_lookup_loop;

	.symbol_table_lookup_end;
	return result
end;

(**
 * Inserts a symbol into the table.
 *
 * Parameters:
 * symbol_table - Symbol table.
 * symbol_name - Symbol name pointer.
 * name_length - Symbol name length.
 * symbol - Symbol pointer.
 *)
proc _symbol_table_enter(symbol_table: Word, symbol_name: Word, name_length: Word, symbol: Word);
var
	table_length: Word;
	symbol_pointer: Word;
begin
	(* The first word in the symbol table is its length, get it. *)
	table_length := symbol_table^;

	(* Calculate the offset for the new symbol. *)
	symbol_pointer := table_length * 12;
	symbol_pointer := symbol_pointer + 4;
	symbol_pointer := symbol_table + symbol_pointer;

	symbol_pointer^ := symbol_name;
	symbol_pointer := symbol_pointer + 4;
	symbol_pointer^ := name_length;
	symbol_pointer := symbol_pointer + 4;
	symbol_pointer^ := symbol;

	(* Increment the symbol table length. *)
	table_length := table_length + 1;
	symbol_table^ := table_length
end;

proc _symbol_table_build();
var
	current_info: Word;
	current_type: Word;
begin
	(* Set the table length to 0. *)
	symbol_table_global := 0;

	current_type := _allocate(8);
	_type_set_kind(current_type, TypeKind.primitive);
	_type_set_size(current_type, 4);

	(* Enter built-in symbols. *)
	current_info := _type_info_create(current_type);
	_symbol_table_enter(@symbol_table_global, "Word", 4, current_info);

	current_info := _type_info_create(current_type);
	_symbol_table_enter(@symbol_table_global, "Array", 5, current_info)
end;

(**
 * Assigns some value to at array index.
 *
 * Parameters:
 * array - Array pointer.
 * index - Index (word offset into the array).
 * data - Data to assign.
 *)
proc _assign_at(array: Word, index: Word, data: Word);
var
	target: Word;
begin
	target := index - 1;
	target := target * 4;
	target := array + target;

	target^ := data
end;

proc _get_at(array: Word, index: Word);
var
	target: Word;
begin
	target := index - 1;
	target := target * 4;
	target := array + target;

	return target^
end;

(**
 * Initializes the array with character classes.
 *)
proc _lexer_classifications();
var
	code: Word;
begin
	_assign_at(@classification, 1, LexerClass.eof);
	_assign_at(@classification, 2, LexerClass.invalid);
	_assign_at(@classification, 3, LexerClass.invalid);
	_assign_at(@classification, 4, LexerClass.invalid);
	_assign_at(@classification, 5, LexerClass.invalid);
	_assign_at(@classification, 6, LexerClass.invalid);
	_assign_at(@classification, 7, LexerClass.invalid);
	_assign_at(@classification, 8, LexerClass.invalid);
	_assign_at(@classification, 9, LexerClass.invalid);
	_assign_at(@classification, 10, LexerClass.space);
	_assign_at(@classification, 11, LexerClass.space);
	_assign_at(@classification, 12, LexerClass.invalid);
	_assign_at(@classification, 13, LexerClass.invalid);
	_assign_at(@classification, 14, LexerClass.space);
	_assign_at(@classification, 15, LexerClass.invalid);
	_assign_at(@classification, 16, LexerClass.invalid);
	_assign_at(@classification, 17, LexerClass.invalid);
	_assign_at(@classification, 18, LexerClass.invalid);
	_assign_at(@classification, 19, LexerClass.invalid);
	_assign_at(@classification, 20, LexerClass.invalid);
	_assign_at(@classification, 21, LexerClass.invalid);
	_assign_at(@classification, 22, LexerClass.invalid);
	_assign_at(@classification, 23, LexerClass.invalid);
	_assign_at(@classification, 24, LexerClass.invalid);
	_assign_at(@classification, 25, LexerClass.invalid);
	_assign_at(@classification, 26, LexerClass.invalid);
	_assign_at(@classification, 27, LexerClass.invalid);
	_assign_at(@classification, 28, LexerClass.invalid);
	_assign_at(@classification, 29, LexerClass.invalid);
	_assign_at(@classification, 30, LexerClass.invalid);
	_assign_at(@classification, 31, LexerClass.invalid);
	_assign_at(@classification, 32, LexerClass.invalid);
	_assign_at(@classification, 33, LexerClass.space);
	_assign_at(@classification, 34, LexerClass.single);
	_assign_at(@classification, 35, LexerClass.double_quote);
	_assign_at(@classification, 36, LexerClass.other);
	_assign_at(@classification, 37, LexerClass.other);
	_assign_at(@classification, 38, LexerClass.single);
	_assign_at(@classification, 39, LexerClass.single);
	_assign_at(@classification, 40, LexerClass.single_quote);
	_assign_at(@classification, 41, LexerClass.left_paren);
	_assign_at(@classification, 42, LexerClass.right_paren);
	_assign_at(@classification, 43, LexerClass.asterisk);
	_assign_at(@classification, 44, LexerClass.single);
	_assign_at(@classification, 45, LexerClass.single);
	_assign_at(@classification, 46, LexerClass.minus);
	_assign_at(@classification, 47, LexerClass.dot);
	_assign_at(@classification, 48, LexerClass.single);
	_assign_at(@classification, 49, LexerClass.zero);
	_assign_at(@classification, 50, LexerClass.digit);
	_assign_at(@classification, 51, LexerClass.digit);
	_assign_at(@classification, 52, LexerClass.digit);
	_assign_at(@classification, 53, LexerClass.digit);
	_assign_at(@classification, 54, LexerClass.digit);
	_assign_at(@classification, 55, LexerClass.digit);
	_assign_at(@classification, 56, LexerClass.digit);
	_assign_at(@classification, 57, LexerClass.digit);
	_assign_at(@classification, 58, LexerClass.digit);
	_assign_at(@classification, 59, LexerClass.colon);
	_assign_at(@classification, 60, LexerClass.single);
	_assign_at(@classification, 61, LexerClass.less);
	_assign_at(@classification, 62, LexerClass.equals);
	_assign_at(@classification, 63, LexerClass.greater);
	_assign_at(@classification, 64, LexerClass.other);
	_assign_at(@classification, 65, LexerClass.single);
	_assign_at(@classification, 66, LexerClass.alpha);
	_assign_at(@classification, 67, LexerClass.alpha);
	_assign_at(@classification, 68, LexerClass.alpha);
	_assign_at(@classification, 69, LexerClass.alpha);
	_assign_at(@classification, 70, LexerClass.alpha);
	_assign_at(@classification, 71, LexerClass.alpha);
	_assign_at(@classification, 72, LexerClass.alpha);
	_assign_at(@classification, 73, LexerClass.alpha);
	_assign_at(@classification, 74, LexerClass.alpha);
	_assign_at(@classification, 75, LexerClass.alpha);
	_assign_at(@classification, 76, LexerClass.alpha);
	_assign_at(@classification, 77, LexerClass.alpha);
	_assign_at(@classification, 78, LexerClass.alpha);
	_assign_at(@classification, 79, LexerClass.alpha);
	_assign_at(@classification, 80, LexerClass.alpha);
	_assign_at(@classification, 81, LexerClass.alpha);
	_assign_at(@classification, 82, LexerClass.alpha);
	_assign_at(@classification, 83, LexerClass.alpha);
	_assign_at(@classification, 84, LexerClass.alpha);
	_assign_at(@classification, 85, LexerClass.alpha);
	_assign_at(@classification, 86, LexerClass.alpha);
	_assign_at(@classification, 87, LexerClass.alpha);
	_assign_at(@classification, 88, LexerClass.alpha);
	_assign_at(@classification, 89, LexerClass.alpha);
	_assign_at(@classification, 90, LexerClass.alpha);
	_assign_at(@classification, 91, LexerClass.alpha);
	_assign_at(@classification, 92, LexerClass.single);
	_assign_at(@classification, 93, LexerClass.backslash);
	_assign_at(@classification, 94, LexerClass.single);
	_assign_at(@classification, 95, LexerClass.single);
	_assign_at(@classification, 96, LexerClass.alpha);
	_assign_at(@classification, 97, LexerClass.other);
	_assign_at(@classification, 98, LexerClass.hex);
	_assign_at(@classification, 99, LexerClass.hex);
	_assign_at(@classification, 100, LexerClass.hex);
	_assign_at(@classification, 101, LexerClass.hex);
	_assign_at(@classification, 102, LexerClass.hex);
	_assign_at(@classification, 103, LexerClass.hex);
	_assign_at(@classification, 104, LexerClass.alpha);
	_assign_at(@classification, 105, LexerClass.alpha);
	_assign_at(@classification, 106, LexerClass.alpha);
	_assign_at(@classification, 107, LexerClass.alpha);
	_assign_at(@classification, 108, LexerClass.alpha);
	_assign_at(@classification, 109, LexerClass.alpha);
	_assign_at(@classification, 110, LexerClass.alpha);
	_assign_at(@classification, 111, LexerClass.alpha);
	_assign_at(@classification, 112, LexerClass.alpha);
	_assign_at(@classification, 113, LexerClass.alpha);
	_assign_at(@classification, 114, LexerClass.alpha);
	_assign_at(@classification, 115, LexerClass.alpha);
	_assign_at(@classification, 116, LexerClass.alpha);
	_assign_at(@classification, 117, LexerClass.alpha);
	_assign_at(@classification, 118, LexerClass.alpha);
	_assign_at(@classification, 119, LexerClass.alpha);
	_assign_at(@classification, 120, LexerClass.alpha);
	_assign_at(@classification, 121, LexerClass.x);
	_assign_at(@classification, 122, LexerClass.alpha);
	_assign_at(@classification, 123, LexerClass.alpha);
	_assign_at(@classification, 124, LexerClass.other);
	_assign_at(@classification, 125, LexerClass.single);
	_assign_at(@classification, 126, LexerClass.other);
	_assign_at(@classification, 127, LexerClass.single);
	_assign_at(@classification, 128, LexerClass.invalid);

	code := 129;

	(* Set the remaining 129 - 256 bytes to transitionClassOther. *)
	.create_classification_loop;
	_assign_at(@classification, code, LexerClass.other);
	code := code + 1;

	if code < 257 then
		goto create_classification_loop
	end
end;

proc _lexer_get_transition(current_state: Word, character_class: Word);
var
	transition_table: Word;
	row_position: Word;
	column_position: Word;
	target: Word;
begin
	(* Each state is 8 bytes long (2 words: action and next state).
	There are 22 character classes, so a transition row 8 * 22 = 176 bytes long. *)
	row_position := current_state - 1;
	row_position := row_position * 176;

	column_position := character_class - 1;
	column_position := column_position * 8;

	target := _lexer_get_transition_table();
	target := target + row_position;

	return target + column_position
end;

(**
 * Parameters:
 * current_state - First index into transitions table.
 * character_class - Second index into transitions table.
 * action - Action to assign.
 * next_state - Next state to assign.
 *)
proc _lexer_set_transition(current_state: Word, character_class: Word, action: Word, next_state: Word);
var
	transition: Word;
begin
	transition := _lexer_get_transition(current_state, character_class);

	_lexer_transition_set_action(transition, action);
	_lexer_transition_set_state(transition, next_state)
end;

(* Sets same action and state transition for all character classes in one transition row. *)

(**
 * Parameters:
 * current_state - Current state (Transition state enumeration).
 * default_action - Default action (Callback).
 * next_state - Next state (Transition state enumeration).
 *)
proc _lexer_default_transition(current_state: Word, default_action: Word, next_state: Word);
begin
	_lexer_set_transition(current_state, LexerClass.invalid, default_action, next_state);
	_lexer_set_transition(current_state, LexerClass.digit, default_action, next_state);
	_lexer_set_transition(current_state, LexerClass.alpha, default_action, next_state);
	_lexer_set_transition(current_state, LexerClass.space, default_action, next_state);
	_lexer_set_transition(current_state, LexerClass.colon, default_action, next_state);
	_lexer_set_transition(current_state, LexerClass.equals, default_action, next_state);
	_lexer_set_transition(current_state, LexerClass.left_paren, default_action, next_state);
	_lexer_set_transition(current_state, LexerClass.right_paren, default_action, next_state);
	_lexer_set_transition(current_state, LexerClass.asterisk, default_action, next_state);
	_lexer_set_transition(current_state, LexerClass.backslash, default_action, next_state);
	_lexer_set_transition(current_state, LexerClass.single, default_action, next_state);
	_lexer_set_transition(current_state, LexerClass.hex, default_action, next_state);
	_lexer_set_transition(current_state, LexerClass.zero, default_action, next_state);
	_lexer_set_transition(current_state, LexerClass.x, default_action, next_state);
	_lexer_set_transition(current_state, LexerClass.eof, default_action, next_state);
	_lexer_set_transition(current_state, LexerClass.dot, default_action, next_state);
	_lexer_set_transition(current_state, LexerClass.minus, default_action, next_state);
	_lexer_set_transition(current_state, LexerClass.single_quote, default_action, next_state);
	_lexer_set_transition(current_state, LexerClass.double_quote, default_action, next_state);
	_lexer_set_transition(current_state, LexerClass.greater, default_action, next_state);
	_lexer_set_transition(current_state, LexerClass.less, default_action, next_state);
	_lexer_set_transition(current_state, LexerClass.other, default_action, next_state)
end;

(**
 * The transition table describes transitions from one state to another, given
 * a symbol (character class).
 *
 * The table has m rows and n columns, where m is the amount of states and n is
 * the amount of classes. So given the current state and a classified character
 * the table can be used to look up the next state.
 *)
proc _lexer_transitions();
begin
	(* Start state. *)
	_lexer_set_transition(LexerState.start, LexerClass.invalid, LexerAction.none, LexerState.finish);
	_lexer_set_transition(LexerState.start, LexerClass.digit, LexerAction.accumulate, LexerState.decimal);
	_lexer_set_transition(LexerState.start, LexerClass.alpha, LexerAction.accumulate, LexerState.identifier);
	_lexer_set_transition(LexerState.start, LexerClass.space, LexerAction.skip, LexerState.start);
	_lexer_set_transition(LexerState.start, LexerClass.colon, LexerAction.accumulate, LexerState.colon);
	_lexer_set_transition(LexerState.start, LexerClass.equals, LexerAction.single, LexerState.finish);
	_lexer_set_transition(LexerState.start, LexerClass.left_paren, LexerAction.accumulate, LexerState.left_paren);
	_lexer_set_transition(LexerState.start, LexerClass.right_paren, LexerAction.single, LexerState.finish);
	_lexer_set_transition(LexerState.start, LexerClass.asterisk, LexerAction.single, LexerState.finish);
	_lexer_set_transition(LexerState.start, LexerClass.backslash, LexerAction.none, LexerState.finish);
	_lexer_set_transition(LexerState.start, LexerClass.single, LexerAction.single, LexerState.finish);
	_lexer_set_transition(LexerState.start, LexerClass.hex, LexerAction.accumulate, LexerState.identifier);
	_lexer_set_transition(LexerState.start, LexerClass.zero, LexerAction.accumulate, LexerState.leading_zero);
	_lexer_set_transition(LexerState.start, LexerClass.x, LexerAction.accumulate, LexerState.identifier);
	_lexer_set_transition(LexerState.start, LexerClass.eof, LexerAction.eof, LexerState.finish);
	_lexer_set_transition(LexerState.start, LexerClass.dot, LexerAction.single, LexerState.finish);
	_lexer_set_transition(LexerState.start, LexerClass.minus, LexerAction.accumulate, LexerState.minus);
	_lexer_set_transition(LexerState.start, LexerClass.single_quote, LexerAction.accumulate, LexerState.character);
	_lexer_set_transition(LexerState.start, LexerClass.double_quote, LexerAction.accumulate, LexerState.string);
	_lexer_set_transition(LexerState.start, LexerClass.greater, LexerAction.accumulate, LexerState.greater);
	_lexer_set_transition(LexerState.start, LexerClass.less, LexerAction.accumulate, LexerState.less);
	_lexer_set_transition(LexerState.start, LexerClass.other, LexerAction.none, LexerState.finish);

	(* Colon state. *)
	_lexer_default_transition(LexerState.colon, LexerAction.finalize, LexerState.finish);
	_lexer_set_transition(LexerState.colon, LexerClass.equals, LexerAction.composite, LexerState.finish);

	(* Identifier state. *)
	_lexer_default_transition(LexerState.identifier, LexerAction.key_id, LexerState.finish);
	_lexer_set_transition(LexerState.identifier, LexerClass.digit, LexerAction.accumulate, LexerState.identifier);
	_lexer_set_transition(LexerState.identifier, LexerClass.alpha, LexerAction.accumulate, LexerState.identifier);
	_lexer_set_transition(LexerState.identifier, LexerClass.hex, LexerAction.accumulate, LexerState.identifier);
	_lexer_set_transition(LexerState.identifier, LexerClass.zero, LexerAction.accumulate, LexerState.identifier);
	_lexer_set_transition(LexerState.identifier, LexerClass.x, LexerAction.accumulate, LexerState.identifier);

	(* Decimal state. *)
	_lexer_default_transition(LexerState.decimal, LexerAction.integer, LexerState.finish);
	_lexer_set_transition(LexerState.decimal, LexerClass.digit, LexerAction.accumulate, LexerState.decimal);
	_lexer_set_transition(LexerState.decimal, LexerClass.alpha, LexerAction.none, LexerState.finish);
	_lexer_set_transition(LexerState.decimal, LexerClass.hex, LexerAction.none, LexerState.finish);
	_lexer_set_transition(LexerState.decimal, LexerClass.zero, LexerAction.accumulate, LexerState.decimal);
	_lexer_set_transition(LexerState.decimal, LexerClass.x, LexerAction.none, LexerState.finish);

	(* Leading zero. *)
	_lexer_default_transition(LexerState.leading_zero, LexerAction.integer, LexerState.finish);
	_lexer_set_transition(LexerState.leading_zero, LexerClass.digit, LexerAction.none, LexerState.finish);
	_lexer_set_transition(LexerState.leading_zero, LexerClass.alpha, LexerAction.none, LexerState.finish);
	_lexer_set_transition(LexerState.leading_zero, LexerClass.hex, LexerAction.none, LexerState.finish);
	_lexer_set_transition(LexerState.leading_zero, LexerClass.zero, LexerAction.none, LexerState.finish);
	_lexer_set_transition(LexerState.leading_zero, LexerClass.x, LexerAction.none, LexerState.dot);

	(* Greater state. *)
	_lexer_default_transition(LexerState.greater, LexerAction.finalize, LexerState.finish);
	_lexer_set_transition(LexerState.greater, LexerClass.equals, LexerAction.composite, LexerState.finish);

	(* Minus state. *)
	_lexer_default_transition(LexerState.minus, LexerAction.finalize, LexerState.finish);
	_lexer_set_transition(LexerState.minus, LexerClass.greater, LexerAction.composite, LexerState.finish);

	(* Left paren state. *)
	_lexer_default_transition(LexerState.left_paren, LexerAction.finalize, LexerState.finish);
	_lexer_set_transition(LexerState.left_paren, LexerClass.asterisk, LexerAction.accumulate, LexerState.comment);

	(* Less state. *)
	_lexer_default_transition(LexerState.less, LexerAction.finalize, LexerState.finish);
	_lexer_set_transition(LexerState.less, LexerClass.equals, LexerAction.composite, LexerState.finish);
	_lexer_set_transition(LexerState.less, LexerClass.greater, LexerAction.composite, LexerState.finish);

	(* Hexadecimal after 0x. *)
	_lexer_default_transition(LexerState.dot, LexerAction.finalize, LexerState.finish);
	_lexer_set_transition(LexerState.dot, LexerClass.dot, LexerAction.composite, LexerState.finish);

	(* Comment. *)
	_lexer_default_transition(LexerState.comment, LexerAction.accumulate, LexerState.comment);
	_lexer_set_transition(LexerState.comment, LexerClass.asterisk, LexerAction.accumulate, LexerState.closing_comment);
	_lexer_set_transition(LexerState.comment, LexerClass.eof, LexerAction.none, LexerState.finish);

	(* Closing comment. *)
	_lexer_default_transition(LexerState.closing_comment, LexerAction.accumulate, LexerState.comment);
	_lexer_set_transition(LexerState.closing_comment, LexerClass.invalid, LexerAction.none, LexerState.finish);
	_lexer_set_transition(LexerState.closing_comment, LexerClass.right_paren, LexerAction.delimited, LexerState.finish);
	_lexer_set_transition(LexerState.closing_comment, LexerClass.asterisk, LexerAction.accumulate, LexerState.closing_comment);
	_lexer_set_transition(LexerState.closing_comment, LexerClass.eof, LexerAction.none, LexerState.finish);

	(* Character. *)
	_lexer_default_transition(LexerState.character, LexerAction.accumulate, LexerState.character);
	_lexer_set_transition(LexerState.character, LexerClass.invalid, LexerAction.none, LexerState.finish);
	_lexer_set_transition(LexerState.character, LexerClass.eof, LexerAction.none, LexerState.finish);
	_lexer_set_transition(LexerState.character, LexerClass.single_quote, LexerAction.delimited, LexerState.finish);
	_lexer_set_transition(LexerState.character, LexerClass.backslash, LexerAction.accumulate, LexerState.character_escape);

	(* Escape sequence in a character. *)
	_lexer_default_transition(LexerState.character_escape, LexerAction.accumulate, LexerState.character);
	_lexer_set_transition(LexerState.character_escape, LexerClass.invalid, LexerAction.none, LexerState.finish);
	_lexer_set_transition(LexerState.character_escape, LexerClass.eof, LexerAction.none, LexerState.finish);

	(* String. *)
	_lexer_default_transition(LexerState.string, LexerAction.accumulate, LexerState.string);
	_lexer_set_transition(LexerState.string, LexerClass.invalid, LexerAction.none, LexerState.finish);
	_lexer_set_transition(LexerState.string, LexerClass.eof, LexerAction.none, LexerState.finish);
	_lexer_set_transition(LexerState.string, LexerClass.double_quote, LexerAction.delimited, LexerState.finish);
	_lexer_set_transition(LexerState.string, LexerClass.backslash, LexerAction.accumulate, LexerState.string_escape);

	(* Escape sequence in a string. *)
	_lexer_default_transition(LexerState.string_escape, LexerAction.accumulate, LexerState.string);
	_lexer_set_transition(LexerState.string_escape, LexerClass.invalid, LexerAction.none, LexerState.finish);
	_lexer_set_transition(LexerState.string_escape, LexerClass.eof, LexerAction.none, LexerState.finish)
end;

(**
 * Transition table is saved after character classification table.
 * Each character entry is 1 word long and there are 256 characters.
 * 1024 = 256 * 4
 *)
proc _lexer_get_transition_table();
	return @classification + 1024
end;

(**
 * Lexer state is saved after the transition tables.
 * Each transition table entry is 8 bytes long. The table has 16 rows (transition states)
 * and 22 columns (character classes), so 2992 = 8 * 17 * 22.
 *)
proc _lexer_global_state();
var
	result: Word;
begin
	result := _lexer_get_transition_table();
	return  result + 2992
end;

(**
 * Gets pointer to the token start.
 *)
proc _lexer_global_get_start();
var
	target: Word;
begin
	target := _lexer_global_state();
	target := target + 4;
	return target^
end;

(**
 * Sets pointer to the token start.
 *)
proc _lexer_global_set_start(new_start: Word);
var
	target: Word;
begin
	target := _lexer_global_state();
	target := target + 4;
	target^ := new_start
end;

(**
 * Gets pointer to the token end.
 *)
proc _lexer_global_get_end();
var
	target: Word;
begin
	target := _lexer_global_state();
	target := target + 8;
	return target^
end;

(**
 * Sets pointer to the token end.
 *)
proc _lexer_global_set_end(new_start: Word);
var
	target: Word;
begin
	target := _lexer_global_state();
	target := target + 8;
	target^ := new_start
end;

proc _lexer_transition_get_action(this: Word);
	return this^
end;

proc _lexer_transition_set_action(this: Word, value: Word);
begin
	this^ := value
end;

proc _lexer_transition_get_state(this: Word);
begin
	this := this + 4;
	return this^
end;

proc _lexer_transition_set_state(this: Word, value: Word);
begin
	this := this + 4;
	this^ := value
end;

(**
 * Resets the lexer state for reading the next token.
 *)
proc _lexer_reset();
var
	state: Word;
begin
	(* Transition start state is 1. *)
	state := _lexer_global_state();
	state^ := LexerState.start;

	state := _lexer_global_get_start();
	_lexer_global_set_end(state)
end;

(**
 * One time lexer initialization.
 *)
proc _lexer_initialize();
begin
	_lexer_classifications();
	_lexer_transitions();

	_lexer_global_set_start(@source_code);
	_lexer_global_set_end(@source_code)
end;

proc _lexer_next_transition();
var
	current_character: Word;
	character_class: Word;
	current_state: Word;
begin
	current_character := _lexer_global_get_end();
	current_character := _load_byte(current_character);

	character_class := _get_at(@classification, current_character + 1);

	current_state := _lexer_global_state();
	current_state := current_state^;

	return _lexer_get_transition(current_state, character_class)
end;

proc _lexer_compare_keyword(lhs_pointer: Word, lhs_length: Word, rhs_pointer: Word, rhs_length: Word);
var
	result: Word;
begin
	result := 0;

	if lhs_length = rhs_length then
		result := _memcmp(lhs_pointer, rhs_pointer, lhs_length);
		result := result = 0
	end;
	return result
end;

proc _lexer_classify_keyword(position_start: Word, position_end: Word);
var
	result: Word;
	token_length: Word;
begin
	result := LexerTokenKind.identifier;
	token_length := position_end - position_start;

	if _lexer_compare_keyword(position_start, token_length, "const", 5) then
		result := LexerTokenKind._const
	elsif _lexer_compare_keyword(position_start, token_length, "var", 3) then
		result := LexerTokenKind._var
	elsif _lexer_compare_keyword(position_start, token_length, "proc", 4) then
		result := LexerTokenKind._proc
	elsif _lexer_compare_keyword(position_start, token_length, "type", 4) then
		result := LexerTokenKind._type
	elsif _lexer_compare_keyword(position_start, token_length, "begin", 5) then
		result := LexerTokenKind._begin
	elsif _lexer_compare_keyword(position_start, token_length, "end", 3) then
		result := LexerTokenKind._end
	elsif _lexer_compare_keyword(position_start, token_length, "return", 6) then
		result := LexerTokenKind._return
	elsif _lexer_compare_keyword(position_start, token_length, "goto", 4) then
		result := LexerTokenKind._goto
	elsif _lexer_compare_keyword(position_start, token_length, "if", 2) then
		result := LexerTokenKind._if
	elsif _lexer_compare_keyword(position_start, token_length, "while", 5) then
		result := LexerTokenKind._while
	elsif _lexer_compare_keyword(position_start, token_length, "then", 4) then
		result := LexerTokenKind._then
	elsif _lexer_compare_keyword(position_start, token_length, "else", 4) then
		result := LexerTokenKind._else
	elsif _lexer_compare_keyword(position_start, token_length, "elsif", 5) then
		result := LexerTokenKind._elsif
	elsif _lexer_compare_keyword(position_start, token_length, "or", 2) then
		result := LexerTokenKind._or
	elsif _lexer_compare_keyword(position_start, token_length, "xor", 2) then
		result := LexerTokenKind._xor
	end;
	return result
end;

proc _lexer_classify_finalize(start_position: Word);
var
	character: Word;
	result: Word;
begin
	result := 0;
	character := _load_byte(start_position);

	if character = ':' then
		result := LexerTokenKind.colon
	elsif character = '.' then
		result := LexerTokenKind.dot
	elsif character = '(' then
		result := LexerTokenKind.left_paren
	elsif character = '-' then
		result := LexerTokenKind.minus
	elsif character = '<' then
		result := LexerTokenKind.less_than
	elsif character = '>' then
		result := LexerTokenKind.greater_than
	end;
	return result
end;

proc _lexer_classify_single(start_position: Word);
var
	character: Word;
	result: Word;
begin
	result := 0;
	character := _load_byte(start_position);

	if character = ';' then
		result := LexerTokenKind.semicolon
	elsif character = ',' then
		result := LexerTokenKind.comma
	elsif character = ')' then
		result := LexerTokenKind.right_paren
	elsif character = '@' then
		result := LexerTokenKind.at
	elsif character = '~' then
		result := LexerTokenKind.not
	elsif character = '&' then
		result := LexerTokenKind.and
	elsif character = '+' then
		result := LexerTokenKind.plus
	elsif character = '*' then
		result := LexerTokenKind.multiplication
	elsif character = '=' then
		result := LexerTokenKind.equals
	elsif character = '%' then
		result := LexerTokenKind.remainder
	elsif character = '/' then
		result := LexerTokenKind.division
	elsif character = '.' then
		result := LexerTokenKind.dot
	elsif character = '^' then
		result := LexerTokenKind.hat
	end;
	return result
end;

proc _lexer_classify_composite(start_position: Word, one_before_last: Word);
var
	first_character: Word;
	last_character: Word;
	result: Word;
begin
	first_character := _load_byte(start_position);
	last_character := _load_byte(one_before_last);

	if first_character = ':' then
		result := LexerTokenKind.assignment
	elsif first_character = '<' then
		if last_character = '=' then
			result := LexerTokenKind.less_equal
		elsif last_character = '>' then
			result := LexerTokenKind.not_equal
		end
	elsif first_character = '>' then
		if last_character = '=' then
			result := LexerTokenKind.greater_equal
		end
	end;

	return result
end;

proc _lexer_classify_delimited(start_position: Word, end_position: Word);
var
	token_length: Word;
	delimiter: Word;
	result: Word;
begin
	token_length := end_position - start_position;
	delimiter := _load_byte(start_position);

	if delimiter = '(' then
		result := LexerTokenKind.comment
	elsif delimiter = '\'' then
		result := LexerTokenKind.character
	elsif delimiter = '"' then
		result := LexerTokenKind.string
	end;
	return result
end;

proc _lexer_classify_integer(start_position: Word, end_position: Word);
begin
	return LexerTokenKind.integer
end;

proc _lexer_execute_action(action_to_perform: Word, kind: Word);
var
	position_start: Word;
	position_end: Word;
	intermediate: Word;
begin
	position_start := _lexer_global_get_start();
	position_end := _lexer_global_get_end();

	if action_to_perform = LexerAction.none then
	elsif action_to_perform = LexerAction.accumulate then
		_lexer_global_set_end(position_end + 1)
	elsif action_to_perform = LexerAction.skip then
		_lexer_global_set_start(position_start + 1);
		_lexer_global_set_end(position_end + 1)
	elsif action_to_perform = LexerAction.single then
		_lexer_global_set_end(position_end + 1);

		intermediate := _lexer_classify_single(position_start);
		kind^ := intermediate
	elsif action_to_perform = LexerAction.eof then
		intermediate := LexerTokenKind.eof;
		kind^ := intermediate
	elsif action_to_perform = LexerAction.finalize then
		intermediate := _lexer_classify_finalize(position_start);
		kind^ := intermediate
	elsif action_to_perform = LexerAction.composite then
		_lexer_global_set_end(position_end + 1);

		intermediate := _lexer_classify_composite(position_start, position_end);
		kind^ := intermediate
	elsif action_to_perform = LexerAction.key_id then
		intermediate := _lexer_classify_keyword(position_start, position_end);
		kind^ := intermediate
	elsif action_to_perform = LexerAction.integer then
		intermediate := _lexer_classify_integer(position_start, position_end);
		kind^ := intermediate
	elsif action_to_perform = LexerAction.delimited then
		_lexer_global_set_end(position_end + 1);

		intermediate := _lexer_classify_delimited(position_start, position_end + 1);
		kind^ := intermediate
	end;
end;

proc _lexer_execute_transition(kind: Word);
var
	next_transition: Word;
	next_state: Word;
	global_state: Word;
	action_to_perform: Word;
begin
	next_transition := _lexer_next_transition();
	next_state := _lexer_transition_get_state(next_transition);
	action_to_perform := _lexer_transition_get_action(next_transition);

	global_state := _lexer_global_state();

	global_state^ := next_state;
	_lexer_execute_action(action_to_perform, kind);

	return next_state
end;

proc _lexer_advance_token(kind: Word);
var
	result_state: Word;
begin
	result_state := _lexer_execute_transition(kind);
	if result_state <> LexerState.finish then
		_lexer_advance_token(kind)
	end
end;

(**
 * Reads the next token and writes its type into the address in the kind parameter.
 *)
proc _lexer_read_token(kind: Word);
begin
	_lexer_reset();
	_lexer_advance_token(kind)
end;

(**
 * Advances the token stream past the last read token.
 *)
proc _lexer_skip_token();
var
	old_end: Word;
begin
	old_end := _lexer_global_get_end();
	_lexer_global_set_start(old_end)
end;

proc _initialize_global_state();
begin
	compiler_strings_position := @compiler_strings;
	memory_free_pointer := @memory
end;

(*
 * Entry point.
 *)
proc _start();
var
	last_read: Word;
	offset: Word;
begin
	_initialize_global_state();
	_lexer_initialize();
	_symbol_table_build();

	(* Read the source from the standard input. *)
	offset := @source_code;

	.start_read;
	(* Second argument is buffer size. Modifying update the source_code definition. *)
	last_read := _read_file(offset, 409600);
	if last_read > 0 then
		offset := offset + last_read;
		goto start_read
	end;
	_compile();

	_exit(0)
end;