-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlanguage.html
More file actions
967 lines (819 loc) · 78.1 KB
/
Copy pathlanguage.html
File metadata and controls
967 lines (819 loc) · 78.1 KB
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Language Reference — macau</title>
<script src="https://cdn.tailwindcss.com"></script>
<style>
html { scroll-behavior: smooth; }
pre { font-size: 1rem; }
[id] { scroll-margin-top: 4rem; }
code { font-size: 1rem; }
.fn { margin-bottom: 2rem; border-bottom: 1px solid #f3f4f6; padding-bottom: 1.5rem; }
.fn:last-child { border-bottom: none; }
.fn h3 { font-size: 1.1rem; font-weight: 700; margin-bottom: 0.5rem; }
.fn .desc { color: #6b7280; font-size: 1rem; margin-bottom: 0.75rem; }
</style>
</head>
<body class="bg-gray-50 text-gray-900">
<nav class="bg-gray-900 text-white sticky top-0 z-50 shadow-lg">
<div class="max-w-[72rem] mx-auto px-8 py-3 flex items-center justify-between">
<a href="index.html" class="text-2xl font-bold tracking-tight hover:text-gray-400">macau</a>
<div class="flex gap-6 text-base">
<a href="index.html" class="hover:text-gray-400 transition">Home</a>
<a href="language.html" class="text-gray-400 font-medium">Language</a>
<a href="functions.html" class="hover:text-gray-400 transition">Functions</a>
<a href="https://github.com/AdrianSimionov/macau" target="_blank" rel="noopener noreferrer" class="hover:text-gray-400 transition">GitHub</a>
</div>
</div>
</nav>
<div class="max-w-[72rem] mx-auto px-8 py-10 flex gap-8">
<!-- Sidebar toggle (mobile) -->
<button onclick="document.getElementById('sidebar').classList.toggle('hidden');document.getElementById('sidebar').classList.toggle('lg:block')" class="lg:hidden fixed bottom-4 right-4 z-50 bg-gray-800 text-white w-12 h-12 rounded-full shadow-lg flex items-center justify-center text-xl hover:bg-gray-900">☰</button>
<!-- Sidebar -->
<aside id="sidebar" class="hidden lg:block w-80 flex-shrink-0">
<div class="sticky top-16 text-sm space-y-1 bg-white rounded-lg border border-gray-200 p-2 shadow-sm max-h-[calc(100vh-5rem)] overflow-y-auto">
<div class="font-bold text-gray-900 text-sm uppercase tracking-wider mb-2 px-3 pt-1">Data Types</div>
<a href="#types" class="block py-1.5 px-3 rounded hover:bg-gray-100 text-gray-500 text-sm">Overview</a>
<a href="#strings" class="block py-1.5 px-3 rounded hover:bg-gray-100 text-gray-500 text-sm">Strings</a>
<a href="#numbers" class="block py-1.5 px-3 rounded hover:bg-gray-100 text-gray-500 text-sm">Numbers</a>
<a href="#booleans" class="block py-1.5 px-3 rounded hover:bg-gray-100 text-gray-500 text-sm">Booleans</a>
<a href="#coercion" class="block py-1.5 px-3 rounded hover:bg-gray-100 text-gray-500 text-sm">Type Coercion</a>
<div class="font-bold text-gray-900 text-sm uppercase tracking-wider mb-2 mt-3 px-3 pt-1 border-t border-gray-100">Variables</div>
<a href="#basic-assign" class="block py-1.5 px-3 rounded hover:bg-gray-100 text-gray-500 text-sm">Basic Assignment</a>
<a href="#scope" class="block py-1.5 px-3 rounded hover:bg-gray-100 text-gray-500 text-sm">Local / Global / Static</a>
<a href="#constants" class="block py-1.5 px-3 rounded hover:bg-gray-100 text-gray-500 text-sm">Constants</a>
<a href="#enum" class="block py-1.5 px-3 rounded hover:bg-gray-100 text-gray-500 text-sm">Enum</a>
<a href="#multi-decl" class="block py-1.5 px-3 rounded hover:bg-gray-100 text-gray-500 text-sm">Multi-Declaration</a>
<div class="font-bold text-gray-900 text-sm uppercase tracking-wider mb-2 mt-3 px-3 pt-1 border-t border-gray-100">Operators</div>
<a href="#arithmetic" class="block py-1.5 px-3 rounded hover:bg-gray-100 text-gray-500 text-sm">Arithmetic</a>
<a href="#comparison" class="block py-1.5 px-3 rounded hover:bg-gray-100 text-gray-500 text-sm">Comparison</a>
<a href="#logical" class="block py-1.5 px-3 rounded hover:bg-gray-100 text-gray-500 text-sm">Logical</a>
<a href="#concat" class="block py-1.5 px-3 rounded hover:bg-gray-100 text-gray-500 text-sm">Concatenation</a>
<a href="#compound" class="block py-1.5 px-3 rounded hover:bg-gray-100 text-gray-500 text-sm">Compound Assignment</a>
<a href="#ternary" class="block py-1.5 px-3 rounded hover:bg-gray-100 text-gray-500 text-sm">Ternary</a>
<a href="#precedence" class="block py-1.5 px-3 rounded hover:bg-gray-100 text-gray-500 text-sm">Precedence</a>
<div class="font-bold text-gray-900 text-sm uppercase tracking-wider mb-2 mt-3 px-3 pt-1 border-t border-gray-100">Control Flow</div>
<a href="#if-else" class="block py-1.5 px-3 rounded hover:bg-gray-100 text-gray-500 text-sm">If...ElseIf...Else</a>
<a href="#select" class="block py-1.5 px-3 rounded hover:bg-gray-100 text-gray-500 text-sm">Select...Case</a>
<a href="#switch" class="block py-1.5 px-3 rounded hover:bg-gray-100 text-gray-500 text-sm">Switch...Case</a>
<a href="#continuecase" class="block py-1.5 px-3 rounded hover:bg-gray-100 text-gray-500 text-sm">ContinueCase</a>
<a href="#for-next" class="block py-1.5 px-3 rounded hover:bg-gray-100 text-gray-500 text-sm">For...Next</a>
<a href="#for-in" class="block py-1.5 px-3 rounded hover:bg-gray-100 text-gray-500 text-sm">For...In...Next</a>
<a href="#while" class="block py-1.5 px-3 rounded hover:bg-gray-100 text-gray-500 text-sm">While...WEnd</a>
<a href="#do-until" class="block py-1.5 px-3 rounded hover:bg-gray-100 text-gray-500 text-sm">Do...Until</a>
<a href="#exitloop" class="block py-1.5 px-3 rounded hover:bg-gray-100 text-gray-500 text-sm">ExitLoop</a>
<a href="#continueloop" class="block py-1.5 px-3 rounded hover:bg-gray-100 text-gray-500 text-sm">ContinueLoop</a>
<div class="font-bold text-gray-900 text-sm uppercase tracking-wider mb-2 mt-3 px-3 pt-1 border-t border-gray-100">Functions</div>
<a href="#func-basic" class="block py-1.5 px-3 rounded hover:bg-gray-100 text-gray-500 text-sm">Basic Function</a>
<a href="#func-default" class="block py-1.5 px-3 rounded hover:bg-gray-100 text-gray-500 text-sm">Default Parameters</a>
<a href="#func-recursion" class="block py-1.5 px-3 rounded hover:bg-gray-100 text-gray-500 text-sm">Recursion</a>
<a href="#func-nested" class="block py-1.5 px-3 rounded hover:bg-gray-100 text-gray-500 text-sm">Nested Calls</a>
<a href="#func-early" class="block py-1.5 px-3 rounded hover:bg-gray-100 text-gray-500 text-sm">Early Return</a>
<div class="font-bold text-gray-900 text-sm uppercase tracking-wider mb-2 mt-3 px-3 pt-1 border-t border-gray-100">Other</div>
<a href="#line-comments" class="block py-1.5 px-3 rounded hover:bg-gray-100 text-gray-500 text-sm">Line Comments</a>
<a href="#block-comments" class="block py-1.5 px-3 rounded hover:bg-gray-100 text-gray-500 text-sm">Block Comments</a>
<a href="#dir-include" class="block py-1.5 px-3 rounded hover:bg-gray-100 text-gray-500 text-sm">#include</a>
<a href="#dir-include-once" class="block py-1.5 px-3 rounded hover:bg-gray-100 text-gray-500 text-sm">#include-once</a>
<a href="#dir-requireadmin" class="block py-1.5 px-3 rounded hover:bg-gray-100 text-gray-500 text-sm">#RequireAdmin</a>
<a href="#dir-onstart" class="block py-1.5 px-3 rounded hover:bg-gray-100 text-gray-500 text-sm">#OnScriptStartRegister</a>
<a href="#macro-string" class="block py-1.5 px-3 rounded hover:bg-gray-100 text-gray-500 text-sm">String Macros</a>
<a href="#macro-script" class="block py-1.5 px-3 rounded hover:bg-gray-100 text-gray-500 text-sm">Script Context Macros</a>
<a href="#macro-system" class="block py-1.5 px-3 rounded hover:bg-gray-100 text-gray-500 text-sm">System Macros</a>
<a href="#macro-error" class="block py-1.5 px-3 rounded hover:bg-gray-100 text-gray-500 text-sm">Error State Macros</a>
<a href="#array-decl" class="block py-1.5 px-3 rounded hover:bg-gray-100 text-gray-500 text-sm">Array Declaration</a>
<a href="#array-access" class="block py-1.5 px-3 rounded hover:bg-gray-100 text-gray-500 text-sm">Array Access</a>
<a href="#array-iterate" class="block py-1.5 px-3 rounded hover:bg-gray-100 text-gray-500 text-sm">Array Iteration</a>
<a href="#array-2d" class="block py-1.5 px-3 rounded hover:bg-gray-100 text-gray-500 text-sm">2D Arrays</a>
<a href="#array-redim" class="block py-1.5 px-3 rounded hover:bg-gray-100 text-gray-500 text-sm">ReDim</a>
<a href="#array-varidx" class="block py-1.5 px-3 rounded hover:bg-gray-100 text-gray-500 text-sm">Variable-Indexed Access</a>
<a href="#map-decl" class="block py-1.5 px-3 rounded hover:bg-gray-100 text-gray-500 text-sm">Map Declaration</a>
<a href="#map-intkeys" class="block py-1.5 px-3 rounded hover:bg-gray-100 text-gray-500 text-sm">Integer Keys</a>
<a href="#map-with" class="block py-1.5 px-3 rounded hover:bg-gray-100 text-gray-500 text-sm">With...EndWith</a>
<a href="#bin-create" class="block py-1.5 px-3 rounded hover:bg-gray-100 text-gray-500 text-sm">Create & Convert</a>
<a href="#bin-bitwise" class="block py-1.5 px-3 rounded hover:bg-gray-100 text-gray-500 text-sm">Bitwise Operations</a>
</div>
</aside>
<!-- Content -->
<div class="flex-1 min-w-0">
<h1 class="text-3xl font-extrabold mb-8">Language Reference</h1>
<!-- ═══════════════════════════════════════════════════════════ -->
<!-- DATA TYPES -->
<!-- ═══════════════════════════════════════════════════════════ -->
<h2 id="types" class="text-xl font-bold mb-6 pb-2 border-b border-gray-200">Data Types</h2>
<p class="text-gray-600 mb-6">macau uses a variant type system. Variables automatically adapt their type based on context — numbers used in string operations become strings, and strings used in math become numbers.</p>
<div class="overflow-x-auto mb-8">
<table class="w-full text-sm border border-gray-200 rounded-lg overflow-hidden">
<thead class="bg-gray-100"><tr><th class="p-3 text-left">Type</th><th class="p-3 text-left">Example</th><th class="p-3 text-left">Description</th></tr></thead>
<tbody class="divide-y divide-gray-100">
<tr><td class="p-3 font-mono">String</td><td class="p-3 font-mono">"hello", 'world'</td><td class="p-3">Text. Double or single quotes.</td></tr>
<tr><td class="p-3 font-mono">Int32</td><td class="p-3 font-mono">42, -7, 0xFF</td><td class="p-3">32-bit integer. Hex with 0x prefix.</td></tr>
<tr><td class="p-3 font-mono">Int64</td><td class="p-3 font-mono">9999999999</td><td class="p-3">64-bit integer (auto-detected by magnitude).</td></tr>
<tr><td class="p-3 font-mono">Double</td><td class="p-3 font-mono">3.14, 1.5e3</td><td class="p-3">Floating point. Scientific notation supported.</td></tr>
<tr><td class="p-3 font-mono">Boolean</td><td class="p-3 font-mono">True, False</td><td class="p-3">Logical values. True=1, False=0.</td></tr>
<tr><td class="p-3 font-mono">Null</td><td class="p-3 font-mono">Null</td><td class="p-3">Unknown/empty value.</td></tr>
<tr><td class="p-3 font-mono">Default</td><td class="p-3 font-mono">Default</td><td class="p-3">Used for optional function parameters.</td></tr>
<tr><td class="p-3 font-mono">Array</td><td class="p-3 font-mono">[1, 2, 3]</td><td class="p-3">0-based indexed collection.</td></tr>
<tr><td class="p-3 font-mono">Map</td><td class="p-3 font-mono">$m[]</td><td class="p-3">Key/value dictionary.</td></tr>
<tr><td class="p-3 font-mono">Binary</td><td class="p-3 font-mono">0x414243</td><td class="p-3">Raw byte data in hex.</td></tr>
</tbody>
</table>
</div>
<div class="fn">
<h3 id="strings">Strings</h3>
<p class="desc">Strings are enclosed in double quotes or single quotes. To include a quote character, double it.</p>
<div class="bg-gray-900 rounded-lg p-4 mb-3"><pre class="text-gray-300"><span class="text-gray-300">$s1</span> = <span class="text-green-400">"Hello World"</span>
<span class="text-gray-300">$s2</span> = <span class="text-green-400">'Single quotes'</span>
<span class="text-gray-300">$s3</span> = <span class="text-green-400">"He said ""hello"""</span> <span class="text-gray-500">; double quotes inside</span>
<span class="text-gray-300">$s4</span> = <span class="text-green-400">'He said "hello"'</span> <span class="text-gray-500">; easier with single quotes outside</span>
<span class="text-gray-300">$s5</span> = <span class="text-green-400">""</span> <span class="text-gray-500">; empty string</span>
ConsoleWrite($s1 & @CRLF)
ConsoleWrite($s3 & @CRLF) <span class="text-gray-500">; He said "hello"</span></pre></div>
</div>
<div class="fn">
<h3 id="numbers">Numbers</h3>
<p class="desc">Integers and floating-point numbers. Supports decimal, hex (0x), and scientific notation (1.5e3).</p>
<div class="bg-gray-900 rounded-lg p-4 mb-3"><pre class="text-gray-300"><span class="text-gray-300">$i</span> = <span class="text-orange-400">42</span> <span class="text-gray-500">; integer</span>
<span class="text-gray-300">$f</span> = <span class="text-orange-400">3.14</span> <span class="text-gray-500">; float</span>
<span class="text-gray-300">$h</span> = <span class="text-orange-400">0xFF</span> <span class="text-gray-500">; hex = 255</span>
<span class="text-gray-300">$b</span> = <span class="text-orange-400">0b1010</span> <span class="text-gray-500">; binary = 10</span>
<span class="text-gray-300">$s</span> = <span class="text-orange-400">1.5e3</span> <span class="text-gray-500">; scientific = 1500</span>
<span class="text-gray-300">$n</span> = -<span class="text-orange-400">7</span> <span class="text-gray-500">; negative</span>
ConsoleWrite($h & @CRLF) <span class="text-gray-500">; 255</span></pre></div>
</div>
<div class="fn">
<h3 id="booleans">Booleans</h3>
<p class="desc">True and False are keywords. They can be used in logical operations and convert to 1 and 0 in math.</p>
<div class="bg-gray-900 rounded-lg p-4 mb-3"><pre class="text-gray-300"><span class="text-gray-300">$a</span> = <span class="text-gray-300">True</span>
<span class="text-gray-300">$b</span> = <span class="text-gray-300">False</span>
<span class="text-gray-500">; Boolean logic</span>
ConsoleWrite($a <span class="text-purple-400">And</span> $b & @CRLF) <span class="text-gray-500">; False</span>
ConsoleWrite($a <span class="text-purple-400">Or</span> $b & @CRLF) <span class="text-gray-500">; True</span>
ConsoleWrite(<span class="text-purple-400">Not</span> $b & @CRLF) <span class="text-gray-500">; True</span>
<span class="text-gray-500">; Booleans in math</span>
ConsoleWrite($a + <span class="text-orange-400">10</span> & @CRLF) <span class="text-gray-500">; 11 (True = 1)</span>
ConsoleWrite($b + <span class="text-orange-400">10</span> & @CRLF) <span class="text-gray-500">; 10 (False = 0)</span>
<span class="text-gray-500">; Strings as booleans</span>
ConsoleWrite(<span class="text-green-400">""</span> <span class="text-purple-400">And</span> <span class="text-gray-300">True</span> & @CRLF) <span class="text-gray-500">; False (empty = false)</span>
ConsoleWrite(<span class="text-green-400">"hello"</span> <span class="text-purple-400">And</span> <span class="text-gray-300">True</span> & @CRLF) <span class="text-gray-500">; True (non-empty = true)</span></pre></div>
</div>
<div class="fn">
<h3 id="coercion">Type Coercion</h3>
<p class="desc">When you mix types in an operation, macau converts automatically. Numbers become strings when concatenated, strings become numbers when used in math.</p>
<div class="bg-gray-900 rounded-lg p-4 mb-3"><pre class="text-gray-300"><span class="text-gray-500">; Number + Number = Number</span>
ConsoleWrite(<span class="text-orange-400">10</span> + <span class="text-orange-400">20</span> & @CRLF) <span class="text-gray-500">; 30</span>
<span class="text-gray-500">; String + Number = Number (string converted)</span>
ConsoleWrite(<span class="text-green-400">"10"</span> + <span class="text-orange-400">20</span> & @CRLF) <span class="text-gray-500">; 30</span>
<span class="text-gray-500">; Number & Number = String (concatenation)</span>
ConsoleWrite(<span class="text-orange-400">10</span> & <span class="text-orange-400">20</span> & @CRLF) <span class="text-gray-500">; "1020"</span>
<span class="text-gray-500">; Non-numeric string in math = 0</span>
ConsoleWrite(<span class="text-orange-400">10</span> * <span class="text-green-400">"abc"</span> & @CRLF) <span class="text-gray-500">; 0</span>
<span class="text-gray-500">; String comparison is alphabetical</span>
ConsoleWrite(<span class="text-green-400">"11"</span> < <span class="text-green-400">"2"</span> & @CRLF) <span class="text-gray-500">; True (alphabetically "11" < "2")</span>
<span class="text-gray-500">; Numeric comparison is numerical</span>
ConsoleWrite(<span class="text-orange-400">11</span> < <span class="text-orange-400">2</span> & @CRLF) <span class="text-gray-500">; False</span></pre></div>
</div>
<!-- ═══════════════════════════════════════════════════════════ -->
<!-- VARIABLES -->
<!-- ═══════════════════════════════════════════════════════════ -->
<h2 id="variables" class="text-xl font-bold mb-6 mt-10 pb-2 border-b border-gray-200">Variables</h2>
<div class="fn">
<h3 id="basic-assign">Basic Assignment</h3>
<p class="desc">Variables start with $ and are case-insensitive ($myVar is the same as $MYVAR).</p>
<div class="bg-gray-900 rounded-lg p-4 mb-3"><pre class="text-gray-300"><span class="text-gray-300">$name</span> = <span class="text-green-400">"Alice"</span>
<span class="text-gray-300">$age</span> = <span class="text-orange-400">30</span>
<span class="text-gray-300">$pi</span> = <span class="text-orange-400">3.14159</span>
<span class="text-gray-300">$active</span> = <span class="text-gray-300">True</span>
<span class="text-gray-500">; Case insensitive</span>
<span class="text-gray-300">$myVar</span> = <span class="text-orange-400">10</span>
ConsoleWrite($MYVAR & @CRLF) <span class="text-gray-500">; 10 (same variable)</span></pre></div>
</div>
<div class="fn">
<h3 id="scope">Scope: Local, Global, Static</h3>
<p class="desc">Local is function-scoped, Global is script-wide, Static persists between function calls.</p>
<div class="bg-gray-900 rounded-lg p-4 mb-3"><pre class="text-gray-300"><span class="text-purple-400">Local</span> <span class="text-gray-300">$x</span> = <span class="text-orange-400">1</span> <span class="text-gray-500">; only visible in current function</span>
<span class="text-purple-400">Global</span> <span class="text-gray-300">$y</span> = <span class="text-orange-400">2</span> <span class="text-gray-500">; visible everywhere</span>
<span class="text-purple-400">Static</span> <span class="text-gray-300">$count</span> = <span class="text-orange-400">0</span> <span class="text-gray-500">; retains value between function calls</span>
<span class="text-purple-400">Func</span> <span class="text-yellow-300">Counter</span>()
<span class="text-purple-400">Static</span> <span class="text-gray-300">$n</span> = <span class="text-orange-400">0</span>
$n += <span class="text-orange-400">1</span>
<span class="text-purple-400">Return</span> $n
<span class="text-purple-400">EndFunc</span>
ConsoleWrite(Counter() & @CRLF) <span class="text-gray-500">; 1</span>
ConsoleWrite(Counter() & @CRLF) <span class="text-gray-500">; 2</span>
ConsoleWrite(Counter() & @CRLF) <span class="text-gray-500">; 3</span></pre></div>
</div>
<div class="fn">
<h3 id="constants">Constants</h3>
<p class="desc">Const creates an immutable variable that cannot be changed after assignment.</p>
<div class="bg-gray-900 rounded-lg p-4 mb-3"><pre class="text-gray-300"><span class="text-purple-400">Const</span> <span class="text-gray-300">$PI</span> = <span class="text-orange-400">3.14159</span>
<span class="text-purple-400">Const</span> <span class="text-gray-300">$MAX_SIZE</span> = <span class="text-orange-400">1024</span>
ConsoleWrite($PI & @CRLF) <span class="text-gray-500">; 3.14159</span>
<span class="text-gray-500">; $PI = 3 ; Error! Cannot reassign const</span></pre></div>
</div>
<div class="fn">
<h3 id="enum">Enum</h3>
<p class="desc">Enum creates a series of auto-incrementing constants. Supports custom start values and Step.</p>
<div class="bg-gray-900 rounded-lg p-4 mb-3"><pre class="text-gray-300"><span class="text-gray-500">; Basic enum (starts at 0)</span>
<span class="text-purple-400">Enum</span> <span class="text-gray-300">$RED</span>, <span class="text-gray-300">$GREEN</span>, <span class="text-gray-300">$BLUE</span>
ConsoleWrite($RED & @CRLF) <span class="text-gray-500">; 0</span>
ConsoleWrite($GREEN & @CRLF) <span class="text-gray-500">; 1</span>
ConsoleWrite($BLUE & @CRLF) <span class="text-gray-500">; 2</span>
<span class="text-gray-500">; Enum with custom start</span>
<span class="text-purple-400">Enum</span> <span class="text-gray-300">$FIRST</span> = <span class="text-orange-400">1</span>, <span class="text-gray-300">$SECOND</span>, <span class="text-gray-300">$THIRD</span>
ConsoleWrite($FIRST & @CRLF) <span class="text-gray-500">; 1</span>
ConsoleWrite($SECOND & @CRLF) <span class="text-gray-500">; 2</span>
<span class="text-gray-500">; Enum with step + custom start</span>
<span class="text-purple-400">Enum</span> <span class="text-purple-400">Step</span> <span class="text-orange-400">5</span> <span class="text-gray-300">$A</span> = <span class="text-orange-400">10</span>, <span class="text-gray-300">$B</span>, <span class="text-gray-300">$C</span>
ConsoleWrite($A & @CRLF) <span class="text-gray-500">; 10</span>
ConsoleWrite($B & @CRLF) <span class="text-gray-500">; 15</span>
ConsoleWrite($C & @CRLF) <span class="text-gray-500">; 20</span>
<span class="text-gray-500">; Enum with additive step</span>
<span class="text-purple-400">Enum</span> <span class="text-purple-400">Step</span> <span class="text-orange-400">2</span> <span class="text-gray-300">$A</span>, <span class="text-gray-300">$B</span>, <span class="text-gray-300">$C</span>
ConsoleWrite($A & @CRLF) <span class="text-gray-500">; 0</span>
ConsoleWrite($B & @CRLF) <span class="text-gray-500">; 2</span>
ConsoleWrite($C & @CRLF) <span class="text-gray-500">; 4</span>
<span class="text-gray-500">; Enum with multiplicative step</span>
<span class="text-purple-400">Enum</span> <span class="text-purple-400">Step</span> *<span class="text-orange-400">2</span> <span class="text-gray-300">$X</span>, <span class="text-gray-300">$Y</span>, <span class="text-gray-300">$Z</span>
ConsoleWrite($X & @CRLF) <span class="text-gray-500">; 1</span>
ConsoleWrite($Y & @CRLF) <span class="text-gray-500">; 2</span>
ConsoleWrite($Z & @CRLF) <span class="text-gray-500">; 4</span></pre></div>
</div>
<div class="fn">
<h3 id="multi-decl">Multi-Declaration</h3>
<p class="desc">Multiple variables can be declared on a single line.</p>
<div class="bg-gray-900 rounded-lg p-4 mb-3"><pre class="text-gray-300"><span class="text-purple-400">Local</span> <span class="text-gray-300">$a</span> = <span class="text-orange-400">1</span>, <span class="text-gray-300">$b</span> = <span class="text-orange-400">2</span>, <span class="text-gray-300">$c</span> = <span class="text-orange-400">3</span>
<span class="text-purple-400">Const</span> <span class="text-gray-300">$X</span> = <span class="text-orange-400">10</span>, <span class="text-gray-300">$Y</span> = <span class="text-orange-400">20</span></pre></div>
</div>
<!-- ═══════════════════════════════════════════════════════════ -->
<!-- OPERATORS -->
<!-- ═══════════════════════════════════════════════════════════ -->
<h2 id="operators" class="text-xl font-bold mb-6 mt-10 pb-2 border-b border-gray-200">Operators</h2>
<div class="fn">
<h3 id="arithmetic">Arithmetic Operators</h3>
<p class="desc">Standard math operators for addition, subtraction, multiplication, division, power, and modulus.</p>
<div class="bg-gray-900 rounded-lg p-4 mb-3"><pre class="text-gray-300"><span class="text-gray-300">$a</span> = <span class="text-orange-400">10</span> + <span class="text-orange-400">3</span> <span class="text-gray-500">; Addition: 13</span>
<span class="text-gray-300">$b</span> = <span class="text-orange-400">10</span> - <span class="text-orange-400">3</span> <span class="text-gray-500">; Subtraction: 7</span>
<span class="text-gray-300">$c</span> = <span class="text-orange-400">10</span> * <span class="text-orange-400">3</span> <span class="text-gray-500">; Multiplication: 30</span>
<span class="text-gray-300">$d</span> = <span class="text-orange-400">10</span> / <span class="text-orange-400">3</span> <span class="text-gray-500">; Division: 3</span>
<span class="text-gray-300">$e</span> = <span class="text-orange-400">2</span> ^ <span class="text-orange-400">8</span> <span class="text-gray-500">; Power: 256</span>
<span class="text-gray-300">$f</span> = <span class="text-orange-400">10</span> <span class="text-purple-400">Mod</span> <span class="text-orange-400">3</span> <span class="text-gray-500">; Modulus: 1</span>
<span class="text-gray-500">; Unary operators</span>
<span class="text-gray-300">$g</span> = -<span class="text-orange-400">5</span> <span class="text-gray-500">; Negation</span>
<span class="text-gray-300">$h</span> = +<span class="text-orange-400">5</span> <span class="text-gray-500">; Positive (no-op)</span></pre></div>
</div>
<div class="fn">
<h3 id="comparison">Comparison Operators</h3>
<p class="desc">Returns True or False. The = operator is case-insensitive for strings, == is case-sensitive.</p>
<div class="bg-gray-900 rounded-lg p-4 mb-3"><pre class="text-gray-300">ConsoleWrite(<span class="text-orange-400">10</span> = <span class="text-orange-400">10</span> & @CRLF) <span class="text-gray-500">; True</span>
ConsoleWrite(<span class="text-orange-400">10</span> <> <span class="text-orange-400">5</span> & @CRLF) <span class="text-gray-500">; True (not equal)</span>
ConsoleWrite(<span class="text-orange-400">10</span> > <span class="text-orange-400">5</span> & @CRLF) <span class="text-gray-500">; True</span>
ConsoleWrite(<span class="text-orange-400">10</span> >= <span class="text-orange-400">10</span> & @CRLF) <span class="text-gray-500">; True</span>
ConsoleWrite(<span class="text-orange-400">5</span> < <span class="text-orange-400">10</span> & @CRLF) <span class="text-gray-500">; True</span>
ConsoleWrite(<span class="text-orange-400">5</span> <= <span class="text-orange-400">5</span> & @CRLF) <span class="text-gray-500">; True</span>
<span class="text-gray-500">; Case-insensitive string comparison (=)</span>
ConsoleWrite(<span class="text-green-400">"Hello"</span> = <span class="text-green-400">"hello"</span> & @CRLF) <span class="text-gray-500">; True</span>
<span class="text-gray-500">; Case-sensitive string comparison (==)</span>
ConsoleWrite(<span class="text-green-400">"Hello"</span> == <span class="text-green-400">"hello"</span> & @CRLF) <span class="text-gray-500">; False</span></pre></div>
</div>
<div class="fn">
<h3 id="logical">Logical Operators</h3>
<p class="desc">And, Or, Not. Short-circuit evaluation: if the first operand determines the result, the second is not evaluated.</p>
<div class="bg-gray-900 rounded-lg p-4 mb-3"><pre class="text-gray-300">ConsoleWrite(<span class="text-gray-300">True</span> <span class="text-purple-400">And</span> <span class="text-gray-300">True</span> & @CRLF) <span class="text-gray-500">; True</span>
ConsoleWrite(<span class="text-gray-300">True</span> <span class="text-purple-400">And</span> <span class="text-gray-300">False</span> & @CRLF) <span class="text-gray-500">; False</span>
ConsoleWrite(<span class="text-gray-300">True</span> <span class="text-purple-400">Or</span> <span class="text-gray-300">False</span> & @CRLF) <span class="text-gray-500">; True</span>
ConsoleWrite(<span class="text-gray-300">False</span> <span class="text-purple-400">Or</span> <span class="text-gray-300">False</span> & @CRLF) <span class="text-gray-500">; False</span>
ConsoleWrite(<span class="text-purple-400">Not</span> <span class="text-gray-300">True</span> & @CRLF) <span class="text-gray-500">; False</span>
ConsoleWrite(<span class="text-purple-400">Not</span> <span class="text-gray-300">False</span> & @CRLF) <span class="text-gray-500">; True</span>
<span class="text-gray-500">; Short-circuit: Func2() is NOT called if Func1() returns False</span>
<span class="text-purple-400">If</span> Func1() <span class="text-purple-400">And</span> Func2() <span class="text-purple-400">Then</span> ...</pre></div>
</div>
<div class="fn">
<h3 id="concat">String Concatenation</h3>
<p class="desc">The & operator joins strings. The &= operator appends to a variable.</p>
<div class="bg-gray-900 rounded-lg p-4 mb-3"><pre class="text-gray-300"><span class="text-gray-300">$s</span> = <span class="text-green-400">"Hello"</span> & <span class="text-green-400">" "</span> & <span class="text-green-400">"World"</span>
ConsoleWrite($s & @CRLF) <span class="text-gray-500">; "Hello World"</span>
<span class="text-gray-300">$s</span> = <span class="text-green-400">"Count: "</span> & <span class="text-orange-400">42</span>
ConsoleWrite($s & @CRLF) <span class="text-gray-500">; "Count: 42"</span>
<span class="text-gray-300">$s</span> &= <span class="text-green-400">"!"</span>
ConsoleWrite($s & @CRLF) <span class="text-gray-500">; "Count: 42!"</span></pre></div>
</div>
<div class="fn">
<h3 id="compound">Compound Assignment</h3>
<p class="desc">Shorthand operators that combine an arithmetic operation with assignment.</p>
<div class="bg-gray-900 rounded-lg p-4 mb-3"><pre class="text-gray-300"><span class="text-gray-300">$x</span> = <span class="text-orange-400">10</span>
$x += <span class="text-orange-400">5</span> <span class="text-gray-500">; $x = 15</span>
$x -= <span class="text-orange-400">3</span> <span class="text-gray-500">; $x = 12</span>
$x *= <span class="text-orange-400">2</span> <span class="text-gray-500">; $x = 24</span>
$x /= <span class="text-orange-400">4</span> <span class="text-gray-500">; $x = 6</span>
<span class="text-gray-300">$s</span> = <span class="text-green-400">"Hello"</span>
$s &= <span class="text-green-400">" World"</span> <span class="text-gray-500">; $s = "Hello World"</span></pre></div>
</div>
<div class="fn">
<h3 id="ternary">Ternary Operator</h3>
<p class="desc">condition ? valueIfTrue : valueIfFalse</p>
<div class="bg-gray-900 rounded-lg p-4 mb-3"><pre class="text-gray-300"><span class="text-gray-300">$age</span> = <span class="text-orange-400">20</span>
<span class="text-gray-300">$status</span> = ($age >= <span class="text-orange-400">18</span>) ? <span class="text-green-400">"adult"</span> : <span class="text-green-400">"minor"</span>
ConsoleWrite($status & @CRLF) <span class="text-gray-500">; "adult"</span>
<span class="text-gray-300">$max</span> = (<span class="text-orange-400">10</span> > <span class="text-orange-400">20</span>) ? <span class="text-orange-400">10</span> : <span class="text-orange-400">20</span>
ConsoleWrite($max & @CRLF) <span class="text-gray-500">; 20</span></pre></div>
</div>
<div class="fn">
<h3 id="precedence">Operator Precedence</h3>
<p class="desc">From highest (evaluated first) to lowest. Use parentheses to override.</p>
<div class="bg-gray-900 rounded-lg p-4 mb-3"><pre class="text-gray-300"><span class="text-gray-500">; Precedence order (highest to lowest):</span>
<span class="text-gray-500">; 1. Not</span>
<span class="text-gray-500">; 2. ^</span>
<span class="text-gray-500">; 3. *, /, Mod</span>
<span class="text-gray-500">; 4. +, -</span>
<span class="text-gray-500">; 5. &</span>
<span class="text-gray-500">; 6. <, >, <=, >=, =, <>, ==</span>
<span class="text-gray-500">; 7. ?:</span>
<span class="text-gray-500">; 8. And, Or</span>
<span class="text-gray-500">; * has higher precedence than +</span>
ConsoleWrite(<span class="text-orange-400">2</span> + <span class="text-orange-400">4</span> * <span class="text-orange-400">10</span> & @CRLF) <span class="text-gray-500">; 42 (not 60)</span>
<span class="text-gray-500">; Use parentheses to override</span>
ConsoleWrite((<span class="text-orange-400">2</span> + <span class="text-orange-400">4</span>) * <span class="text-orange-400">10</span> & @CRLF) <span class="text-gray-500">; 60</span></pre></div>
</div>
<!-- ═══════════════════════════════════════════════════════════ -->
<!-- CONTROL FLOW -->
<!-- ═══════════════════════════════════════════════════════════ -->
<h2 id="control" class="text-xl font-bold mb-6 mt-10 pb-2 border-b border-gray-200">Control Flow</h2>
<div class="fn">
<h3 id="if-else">If...ElseIf...Else...EndIf</h3>
<p class="desc">Conditional execution. Supports ElseIf and Else branches. Can also be used inline (single line).</p>
<div class="bg-gray-900 rounded-lg p-4 mb-3"><pre class="text-gray-300"><span class="text-gray-300">$x</span> = <span class="text-orange-400">42</span>
<span class="text-purple-400">If</span> $x > <span class="text-orange-400">0</span> <span class="text-purple-400">Then</span>
ConsoleWrite(<span class="text-green-400">"positive"</span> & @CRLF)
<span class="text-purple-400">ElseIf</span> $x < <span class="text-orange-400">0</span> <span class="text-purple-400">Then</span>
ConsoleWrite(<span class="text-green-400">"negative"</span> & @CRLF)
<span class="text-purple-400">Else</span>
ConsoleWrite(<span class="text-green-400">"zero"</span> & @CRLF)
<span class="text-purple-400">EndIf</span>
<span class="text-gray-500">; Nested If</span>
<span class="text-purple-400">If</span> $x > <span class="text-orange-400">0</span> <span class="text-purple-400">Then</span>
<span class="text-purple-400">If</span> $x > <span class="text-orange-400">100</span> <span class="text-purple-400">Then</span>
ConsoleWrite(<span class="text-green-400">"large positive"</span> & @CRLF)
<span class="text-purple-400">Else</span>
ConsoleWrite(<span class="text-green-400">"small positive"</span> & @CRLF)
<span class="text-purple-400">EndIf</span>
<span class="text-purple-400">EndIf</span>
<span class="text-gray-500">; Inline If (single statement)</span>
<span class="text-purple-400">If</span> $x > <span class="text-orange-400">0</span> <span class="text-purple-400">Then</span> ConsoleWrite(<span class="text-green-400">"positive"</span> & @CRLF)</pre></div>
</div>
<div class="fn">
<h3 id="select">Select...Case...EndSelect</h3>
<p class="desc">Multi-way conditional. Each Case has its own expression. First matching Case is executed.</p>
<div class="bg-gray-900 rounded-lg p-4 mb-3"><pre class="text-gray-300"><span class="text-gray-300">$day</span> = <span class="text-orange-400">3</span>
<span class="text-purple-400">Select</span>
<span class="text-purple-400">Case</span> $day = <span class="text-orange-400">1</span>
ConsoleWrite(<span class="text-green-400">"Monday"</span> & @CRLF)
<span class="text-purple-400">Case</span> $day = <span class="text-orange-400">2</span>
ConsoleWrite(<span class="text-green-400">"Tuesday"</span> & @CRLF)
<span class="text-purple-400">Case</span> $day = <span class="text-orange-400">3</span>
ConsoleWrite(<span class="text-green-400">"Wednesday"</span> & @CRLF)
<span class="text-purple-400">Case</span> $day = <span class="text-orange-400">4</span>
ConsoleWrite(<span class="text-green-400">"Thursday"</span> & @CRLF)
<span class="text-purple-400">Case</span> $day = <span class="text-orange-400">5</span>
ConsoleWrite(<span class="text-green-400">"Friday"</span> & @CRLF)
<span class="text-purple-400">Case</span> <span class="text-purple-400">Else</span>
ConsoleWrite(<span class="text-green-400">"Weekend"</span> & @CRLF)
<span class="text-purple-400">EndSelect</span></pre></div>
</div>
<div class="fn">
<h3 id="switch">Switch...Case...EndSwitch</h3>
<p class="desc">Matches a value against multiple cases. Supports ranges with To, multiple values with commas, and Case Else.</p>
<div class="bg-gray-900 rounded-lg p-4 mb-3"><pre class="text-gray-300"><span class="text-gray-300">$hour</span> = <span class="text-orange-400">14</span>
<span class="text-purple-400">Switch</span> $hour
<span class="text-purple-400">Case</span> <span class="text-orange-400">6</span> <span class="text-purple-400">To</span> <span class="text-orange-400">11</span>
ConsoleWrite(<span class="text-green-400">"Morning"</span> & @CRLF)
<span class="text-purple-400">Case</span> <span class="text-orange-400">12</span> <span class="text-purple-400">To</span> <span class="text-orange-400">17</span>
ConsoleWrite(<span class="text-green-400">"Afternoon"</span> & @CRLF)
<span class="text-purple-400">Case</span> <span class="text-orange-400">18</span> <span class="text-purple-400">To</span> <span class="text-orange-400">21</span>
ConsoleWrite(<span class="text-green-400">"Evening"</span> & @CRLF)
<span class="text-purple-400">Case</span> <span class="text-purple-400">Else</span>
ConsoleWrite(<span class="text-green-400">"Night"</span> & @CRLF)
<span class="text-purple-400">EndSwitch</span>
<span class="text-gray-500">; Multiple values per case</span>
<span class="text-purple-400">Switch</span> <span class="text-green-400">"a"</span>
<span class="text-purple-400">Case</span> <span class="text-green-400">"a"</span>, <span class="text-green-400">"e"</span>, <span class="text-green-400">"i"</span>, <span class="text-green-400">"o"</span>, <span class="text-green-400">"u"</span>
ConsoleWrite(<span class="text-green-400">"vowel"</span> & @CRLF)
<span class="text-purple-400">Case</span> <span class="text-purple-400">Else</span>
ConsoleWrite(<span class="text-green-400">"consonant"</span> & @CRLF)
<span class="text-purple-400">EndSwitch</span></pre></div>
</div>
<div class="fn">
<h3 id="continuecase">ContinueCase</h3>
<p class="desc">Fall through to the next Case in Select/Switch without evaluating its condition.</p>
<div class="bg-gray-900 rounded-lg p-4 mb-3"><pre class="text-gray-300"><span class="text-gray-300">$x</span> = <span class="text-orange-400">1</span>
<span class="text-purple-400">Switch</span> $x
<span class="text-purple-400">Case</span> <span class="text-orange-400">1</span>
ConsoleWrite(<span class="text-green-400">"one "</span>)
<span class="text-purple-400">ContinueCase</span> <span class="text-gray-500">; fall through to Case 2</span>
<span class="text-purple-400">Case</span> <span class="text-orange-400">2</span>
ConsoleWrite(<span class="text-green-400">"two"</span> & @CRLF)
<span class="text-purple-400">EndSwitch</span>
<span class="text-gray-500">; Output: "one two"</span></pre></div>
</div>
<div class="fn">
<h3 id="for-next">For...To...Step...Next</h3>
<p class="desc">Counted loop. Step defaults to 1. Supports fractional and negative steps.</p>
<div class="bg-gray-900 rounded-lg p-4 mb-3"><pre class="text-gray-300"><span class="text-gray-500">; Count 0 to 9</span>
<span class="text-purple-400">For</span> <span class="text-gray-300">$i</span> = <span class="text-orange-400">0</span> <span class="text-purple-400">To</span> <span class="text-orange-400">9</span>
ConsoleWrite($i & <span class="text-green-400">" "</span>)
<span class="text-purple-400">Next</span>
ConsoleWrite(@CRLF) <span class="text-gray-500">; "0 1 2 3 4 5 6 7 8 9"</span>
<span class="text-gray-500">; Count by 2</span>
<span class="text-purple-400">For</span> <span class="text-gray-300">$i</span> = <span class="text-orange-400">0</span> <span class="text-purple-400">To</span> <span class="text-orange-400">10</span> <span class="text-purple-400">Step</span> <span class="text-orange-400">2</span>
ConsoleWrite($i & <span class="text-green-400">" "</span>)
<span class="text-purple-400">Next</span>
ConsoleWrite(@CRLF) <span class="text-gray-500">; "0 2 4 6 8 10"</span>
<span class="text-gray-500">; Count down</span>
<span class="text-purple-400">For</span> <span class="text-gray-300">$i</span> = <span class="text-orange-400">10</span> <span class="text-purple-400">To</span> <span class="text-orange-400">0</span> <span class="text-purple-400">Step</span> -<span class="text-orange-400">1</span>
ConsoleWrite($i & <span class="text-green-400">" "</span>)
<span class="text-purple-400">Next</span>
ConsoleWrite(@CRLF) <span class="text-gray-500">; "10 9 8 7 6 5 4 3 2 1 0"</span>
<span class="text-gray-500">; Fractional step</span>
<span class="text-purple-400">For</span> <span class="text-gray-300">$f</span> = <span class="text-orange-400">0.0</span> <span class="text-purple-400">To</span> <span class="text-orange-400">1.0</span> <span class="text-purple-400">Step</span> <span class="text-orange-400">0.25</span>
ConsoleWrite($f & <span class="text-green-400">" "</span>)
<span class="text-purple-400">Next</span>
ConsoleWrite(@CRLF) <span class="text-gray-500">; "0 0.25 0.5 0.75 1"</span></pre></div>
</div>
<div class="fn">
<h3 id="for-in">For...In...Next</h3>
<p class="desc">Iterates over elements in an array or keys in a map.</p>
<div class="bg-gray-900 rounded-lg p-4 mb-3"><pre class="text-gray-300"><span class="text-gray-500">; Iterate array</span>
<span class="text-purple-400">Local</span> <span class="text-gray-300">$fruits</span>[] = [<span class="text-green-400">"apple"</span>, <span class="text-green-400">"banana"</span>, <span class="text-green-400">"cherry"</span>]
<span class="text-purple-400">For</span> <span class="text-gray-300">$fruit</span> <span class="text-purple-400">In</span> $fruits
ConsoleWrite($fruit & @CRLF)
<span class="text-purple-400">Next</span>
<span class="text-gray-500">; Output:</span>
<span class="text-gray-500">; apple</span>
<span class="text-gray-500">; banana</span>
<span class="text-gray-500">; cherry</span>
<span class="text-gray-500">; Iterate map keys</span>
<span class="text-purple-400">Local</span> <span class="text-gray-300">$config</span>[]
$config[<span class="text-green-400">"host"</span>] = <span class="text-green-400">"localhost"</span>
$config[<span class="text-green-400">"port"</span>] = <span class="text-green-400">"8080"</span>
<span class="text-purple-400">For</span> <span class="text-gray-300">$key</span> <span class="text-purple-400">In</span> MapKeys($config)
ConsoleWrite($key & <span class="text-green-400">" = "</span> & $config[$key] & @CRLF)
<span class="text-purple-400">Next</span></pre></div>
</div>
<div class="fn">
<h3 id="while">While...WEnd</h3>
<p class="desc">Loop while a condition is true. Condition is checked before each iteration.</p>
<div class="bg-gray-900 rounded-lg p-4 mb-3"><pre class="text-gray-300"><span class="text-gray-300">$count</span> = <span class="text-orange-400">0</span>
<span class="text-purple-400">While</span> $count < <span class="text-orange-400">5</span>
ConsoleWrite($count & <span class="text-green-400">" "</span>)
$count += <span class="text-orange-400">1</span>
<span class="text-purple-400">WEnd</span>
ConsoleWrite(@CRLF) <span class="text-gray-500">; "0 1 2 3 4"</span>
<span class="text-gray-500">; Infinite loop with exit</span>
<span class="text-purple-400">While</span> <span class="text-orange-400">1</span>
<span class="text-gray-300">$input</span> = ConsoleRead()
<span class="text-purple-400">If</span> $input = <span class="text-green-400">"quit"</span> <span class="text-purple-400">Then</span> <span class="text-purple-400">ExitLoop</span>
ConsoleWrite(<span class="text-green-400">"You said: "</span> & $input & @CRLF)
<span class="text-purple-400">WEnd</span></pre></div>
</div>
<div class="fn">
<h3 id="do-until">Do...Until</h3>
<p class="desc">Loop until a condition becomes true. Condition is checked after each iteration (runs at least once).</p>
<div class="bg-gray-900 rounded-lg p-4 mb-3"><pre class="text-gray-300"><span class="text-gray-300">$i</span> = <span class="text-orange-400">0</span>
<span class="text-purple-400">Do</span>
ConsoleWrite($i & <span class="text-green-400">" "</span>)
$i += <span class="text-orange-400">1</span>
<span class="text-purple-400">Until</span> $i >= <span class="text-orange-400">5</span>
ConsoleWrite(@CRLF) <span class="text-gray-500">; "0 1 2 3 4"</span></pre></div>
</div>
<div class="fn">
<h3 id="exitloop">ExitLoop</h3>
<p class="desc">Exits the innermost loop immediately. Accepts an optional level number to exit outer loops.</p>
<div class="bg-gray-900 rounded-lg p-4 mb-3"><pre class="text-gray-300"><span class="text-gray-500">; Exit innermost loop</span>
<span class="text-purple-400">For</span> <span class="text-gray-300">$i</span> = <span class="text-orange-400">0</span> <span class="text-purple-400">To</span> <span class="text-orange-400">9</span>
<span class="text-purple-400">If</span> $i = <span class="text-orange-400">5</span> <span class="text-purple-400">Then</span> <span class="text-purple-400">ExitLoop</span>
ConsoleWrite($i & <span class="text-green-400">" "</span>)
<span class="text-purple-400">Next</span>
ConsoleWrite(@CRLF) <span class="text-gray-500">; "0 1 2 3 4"</span>
<span class="text-gray-500">; ExitLoop 2 — exit both loops</span>
<span class="text-purple-400">For</span> <span class="text-gray-300">$i</span> = <span class="text-orange-400">0</span> <span class="text-purple-400">To</span> <span class="text-orange-400">9</span>
<span class="text-purple-400">For</span> <span class="text-gray-300">$j</span> = <span class="text-orange-400">0</span> <span class="text-purple-400">To</span> <span class="text-orange-400">9</span>
<span class="text-purple-400">If</span> $j = <span class="text-orange-400">3</span> <span class="text-purple-400">Then</span> <span class="text-purple-400">ExitLoop</span> <span class="text-orange-400">2</span>
<span class="text-purple-400">Next</span>
<span class="text-purple-400">Next</span></pre></div>
</div>
<div class="fn">
<h3 id="continueloop">ContinueLoop</h3>
<p class="desc">Skips the rest of the current loop iteration and jumps to the next one. Accepts an optional level number to target outer loops.</p>
<div class="bg-gray-900 rounded-lg p-4 mb-3"><pre class="text-gray-300"><span class="text-gray-500">; Skip even numbers</span>
<span class="text-purple-400">For</span> <span class="text-gray-300">$i</span> = <span class="text-orange-400">0</span> <span class="text-purple-400">To</span> <span class="text-orange-400">9</span>
<span class="text-purple-400">If</span> Mod($i, <span class="text-orange-400">2</span>) = <span class="text-orange-400">0</span> <span class="text-purple-400">Then</span> <span class="text-purple-400">ContinueLoop</span>
ConsoleWrite($i & <span class="text-green-400">" "</span>)
<span class="text-purple-400">Next</span>
ConsoleWrite(@CRLF) <span class="text-gray-500">; "1 3 5 7 9"</span></pre></div>
</div>
<!-- ═══════════════════════════════════════════════════════════ -->
<!-- FUNCTIONS -->
<!-- ═══════════════════════════════════════════════════════════ -->
<h2 id="functions" class="text-xl font-bold mb-6 mt-10 pb-2 border-b border-gray-200">Functions</h2>
<div class="fn">
<h3 id="func-basic">Basic Function</h3>
<p class="desc">Define with Func...EndFunc. Call by name with parentheses.</p>
<div class="bg-gray-900 rounded-lg p-4 mb-3"><pre class="text-gray-300"><span class="text-purple-400">Func</span> <span class="text-yellow-300">Greet</span>($name)
<span class="text-purple-400">Return</span> <span class="text-green-400">"Hello, "</span> & $name & <span class="text-green-400">"!"</span>
<span class="text-purple-400">EndFunc</span>
ConsoleWrite(Greet(<span class="text-green-400">"World"</span>) & @CRLF) <span class="text-gray-500">; "Hello, World!"</span></pre></div>
</div>
<div class="fn">
<h3 id="func-default">Default Parameters</h3>
<p class="desc">Parameters can have default values. They become optional when calling.</p>
<div class="bg-gray-900 rounded-lg p-4 mb-3"><pre class="text-gray-300"><span class="text-purple-400">Func</span> <span class="text-yellow-300">Greet</span>($name, $greeting = <span class="text-green-400">"Hello"</span>)
<span class="text-purple-400">Return</span> $greeting & <span class="text-green-400">", "</span> & $name & <span class="text-green-400">"!"</span>
<span class="text-purple-400">EndFunc</span>
ConsoleWrite(Greet(<span class="text-green-400">"World"</span>) & @CRLF) <span class="text-gray-500">; "Hello, World!"</span>
ConsoleWrite(Greet(<span class="text-green-400">"World"</span>, <span class="text-green-400">"Hi"</span>) & @CRLF) <span class="text-gray-500">; "Hi, World!"</span></pre></div>
</div>
<div class="fn">
<h3 id="func-recursion">Recursion</h3>
<p class="desc">Functions can call themselves.</p>
<div class="bg-gray-900 rounded-lg p-4 mb-3"><pre class="text-gray-300"><span class="text-purple-400">Func</span> <span class="text-yellow-300">Factorial</span>($n)
<span class="text-purple-400">If</span> $n <= <span class="text-orange-400">1</span> <span class="text-purple-400">Then</span> <span class="text-purple-400">Return</span> <span class="text-orange-400">1</span>
<span class="text-purple-400">Return</span> $n * Factorial($n - <span class="text-orange-400">1</span>)
<span class="text-purple-400">EndFunc</span>
ConsoleWrite(Factorial(<span class="text-orange-400">5</span>) & @CRLF) <span class="text-gray-500">; 120</span>
ConsoleWrite(Factorial(<span class="text-orange-400">10</span>) & @CRLF) <span class="text-gray-500">; 3628800</span></pre></div>
</div>
<div class="fn">
<h3 id="func-nested">Nested Function Calls</h3>
<p class="desc">Functions can call other functions, and return values from function calls.</p>
<div class="bg-gray-900 rounded-lg p-4 mb-3"><pre class="text-gray-300"><span class="text-purple-400">Func</span> <span class="text-yellow-300">Add</span>($a, $b)
<span class="text-purple-400">Return</span> $a + $b
<span class="text-purple-400">EndFunc</span>
<span class="text-purple-400">Func</span> <span class="text-yellow-300">Multiply</span>($a, $b)
<span class="text-purple-400">Return</span> $a * $b
<span class="text-purple-400">EndFunc</span>
<span class="text-gray-500">; Call a function in a return expression</span>
<span class="text-purple-400">Func</span> <span class="text-yellow-300">AddAndMultiply</span>($x, $y, $z)
<span class="text-purple-400">Return</span> Multiply(Add($x, $y), $z)
<span class="text-purple-400">EndFunc</span>
ConsoleWrite(AddAndMultiply(<span class="text-orange-400">2</span>, <span class="text-orange-400">3</span>, <span class="text-orange-400">4</span>) & @CRLF) <span class="text-gray-500">; 20</span></pre></div>
</div>
<div class="fn">
<h3 id="func-early">Early Return</h3>
<p class="desc">Return exits the function immediately. Useful for search patterns.</p>
<div class="bg-gray-900 rounded-lg p-4 mb-3"><pre class="text-gray-300"><span class="text-purple-400">Func</span> <span class="text-yellow-300">FindInArray</span>($arr, $target)
<span class="text-purple-400">For</span> <span class="text-gray-300">$i</span> = <span class="text-orange-400">0</span> <span class="text-purple-400">To</span> UBound($arr) - <span class="text-orange-400">1</span>
<span class="text-purple-400">If</span> $arr[$i] = $target <span class="text-purple-400">Then</span>
<span class="text-purple-400">Return</span> $i <span class="text-gray-500">; found: return index immediately</span>
<span class="text-purple-400">EndIf</span>
<span class="text-purple-400">Next</span>
<span class="text-purple-400">Return</span> -<span class="text-orange-400">1</span> <span class="text-gray-500">; not found</span>
<span class="text-purple-400">EndFunc</span>
<span class="text-purple-400">Local</span> <span class="text-gray-300">$arr</span>[] = [<span class="text-green-400">"a"</span>, <span class="text-green-400">"b"</span>, <span class="text-green-400">"c"</span>]
ConsoleWrite(FindInArray($arr, <span class="text-green-400">"b"</span>) & @CRLF) <span class="text-gray-500">; 1</span>
ConsoleWrite(FindInArray($arr, <span class="text-green-400">"z"</span>) & @CRLF) <span class="text-gray-500">; -1</span></pre></div>
</div>
<!-- ═══════════════════════════════════════════════════════════ -->
<!-- COMMENTS -->
<!-- ═══════════════════════════════════════════════════════════ -->
<h2 id="comments" class="text-xl font-bold mb-6 mt-10 pb-2 border-b border-gray-200">Comments</h2>
<div class="fn">
<h3 id="line-comments">Line Comments</h3>
<p class="desc">Semicolons start line comments. Everything after ; is ignored.</p>
<div class="bg-gray-900 rounded-lg p-4 mb-3"><pre class="text-gray-300"><span class="text-gray-300">$x</span> = <span class="text-orange-400">42</span> <span class="text-gray-500">; this is a comment</span>
<span class="text-gray-500">; this entire line is a comment</span>
ConsoleWrite($x) <span class="text-gray-500">; inline comment</span></pre></div>
</div>
<div class="fn">
<h3 id="block-comments">Block Comments</h3>
<p class="desc">Use #cs/#comments-start to start and #ce/#comments-end to end multi-line comments. Can be nested.</p>
<div class="bg-gray-900 rounded-lg p-4 mb-3"><pre class="text-gray-300"><span class="text-gray-500">#cs</span>
<span class="text-gray-500">This is a block comment.</span>
<span class="text-gray-500">It can span multiple lines.</span>
<span class="text-gray-500">#ce</span>
<span class="text-gray-500">#comments-start</span>
<span class="text-gray-500">Another form of block comment.</span>
<span class="text-gray-500">#comments-end</span>
<span class="text-gray-500">; #cs</span>
ConsoleWrite(<span class="text-green-400">"This runs if #cs is commented out"</span> & @CRLF)
<span class="text-gray-500">; #ce</span></pre></div>
</div>
<!-- ═══════════════════════════════════════════════════════════ -->
<!-- DIRECTIVES -->
<!-- ═══════════════════════════════════════════════════════════ -->
<h2 id="directives" class="text-xl font-bold mb-6 mt-10 pb-2 border-b border-gray-200">Directives</h2>
<div class="fn">
<h3 id="dir-include">#include</h3>
<p class="desc">Includes another .mcs file at the current position. The included file's content is inserted as if it were part of the current script.</p>
<div class="bg-gray-900 rounded-lg p-4 mb-3"><pre class="text-gray-300"><span class="text-gray-500">; Relative to current script</span>
<span class="text-purple-400">#include</span> <span class="text-green-400">"utils.mcs"</span>
<span class="text-gray-500">; From library path</span>
<span class="text-purple-400">#include</span> <span class="text-green-400"><stdlib.mcs></span></pre></div>
</div>
<div class="fn">
<h3 id="dir-include-once">#include-once</h3>
<p class="desc">Prevents a file from being included more than once. Place at the top of library files.</p>
<div class="bg-gray-900 rounded-lg p-4 mb-3"><pre class="text-gray-300"><span class="text-gray-500">; At the top of mylib.mcs:</span>
<span class="text-purple-400">#include-once</span>
<span class="text-purple-400">Func</span> <span class="text-yellow-300">MyHelper</span>()
<span class="text-purple-400">Return</span> <span class="text-orange-400">42</span>
<span class="text-purple-400">EndFunc</span></pre></div>
</div>
<div class="fn">
<h3 id="dir-requireadmin">#RequireAdmin</h3>
<p class="desc">Requests administrator privileges. If not running as root, re-launches the script with sudo.</p>
<div class="bg-gray-900 rounded-lg p-4 mb-3"><pre class="text-gray-300"><span class="text-purple-400">#RequireAdmin</span>
<span class="text-gray-500">; This script now runs with root privileges</span>
ConsoleWrite(<span class="text-green-400">"Admin: "</span> & IsAdmin() & @CRLF)</pre></div>
</div>
<div class="fn">
<h3 id="dir-onstart">#OnScriptStartRegister</h3>
<p class="desc">Registers a function to be called when the script starts, before any other code runs.</p>
<div class="bg-gray-900 rounded-lg p-4 mb-3"><pre class="text-gray-300"><span class="text-purple-400">#OnScriptStartRegister</span> <span class="text-green-400">"Init"</span>
<span class="text-purple-400">Func</span> <span class="text-yellow-300">Init</span>()
ConsoleWrite(<span class="text-green-400">"Initializing..."</span> & @CRLF)
<span class="text-purple-400">EndFunc</span>
ConsoleWrite(<span class="text-green-400">"Main script running"</span> & @CRLF)</pre></div>
</div>
<!-- ═══════════════════════════════════════════════════════════ -->
<!-- MACROS -->
<!-- ═══════════════════════════════════════════════════════════ -->
<h2 id="macros" class="text-xl font-bold mb-6 mt-10 pb-2 border-b border-gray-200">Macros</h2>
<p class="text-gray-600 mb-6">Macros are @-prefixed built-in values that return contextual information. They are read-only (except @Error and @Extended which are set by functions).</p>
<div class="fn">
<h3 id="macro-string">String Macros</h3>
<p class="desc">Built-in string constants for common whitespace characters.</p>
<div class="bg-gray-900 rounded-lg p-4 mb-3"><pre class="text-gray-300">ConsoleWrite(<span class="text-green-400">"Line1"</span> & @CRLF & <span class="text-green-400">"Line2"</span> & @CRLF)
ConsoleWrite(<span class="text-green-400">"Col1"</span> & @TAB & <span class="text-green-400">"Col2"</span> & @TAB & <span class="text-green-400">"Col3"</span> & @CRLF)</pre></div>
<div class="overflow-x-auto">
<table class="w-full text-sm border border-gray-200 rounded-lg overflow-hidden">
<thead class="bg-gray-100"><tr><th class="p-2 text-left">Macro</th><th class="p-2 text-left">Value</th></tr></thead>
<tbody class="divide-y divide-gray-100">
<tr><td class="p-2 font-mono">@CRLF</td><td class="p-2">Carriage return + line feed</td></tr>
<tr><td class="p-2 font-mono">@LF</td><td class="p-2">Line feed</td></tr>
<tr><td class="p-2 font-mono">@CR</td><td class="p-2">Carriage return</td></tr>
<tr><td class="p-2 font-mono">@TAB</td><td class="p-2">Tab character</td></tr>
</tbody>
</table>
</div>
</div>
<div class="fn">
<h3 id="macro-script">Script Context Macros</h3>
<p class="desc">Macros that return information about the current script and its environment.</p>
<div class="bg-gray-900 rounded-lg p-4 mb-3"><pre class="text-gray-300">ConsoleWrite(<span class="text-green-400">"Script: "</span> & @ScriptName & @CRLF)
ConsoleWrite(<span class="text-green-400">"Dir: "</span> & @ScriptDir & @CRLF)
ConsoleWrite(<span class="text-green-400">"Full: "</span> & @ScriptFullPath & @CRLF)
ConsoleWrite(<span class="text-green-400">"CWD: "</span> & @WorkingDir & @CRLF)
ConsoleWrite(<span class="text-green-400">"Version: "</span> & @ScriptVersion & @CRLF)
ConsoleWrite(<span class="text-green-400">"Exe: "</span> & @ScriptExe & @CRLF)</pre></div>
</div>
<div class="fn">
<h3 id="macro-system">System Macros</h3>
<p class="desc">Macros that return information about the operating system.</p>
<div class="bg-gray-900 rounded-lg p-4 mb-3"><pre class="text-gray-300">ConsoleWrite(<span class="text-green-400">"OS: "</span> & @OSVersion & @CRLF)
ConsoleWrite(<span class="text-green-400">"CPU: "</span> & @CPUArch & @CRLF)</pre></div>
</div>
<div class="fn">
<h3 id="macro-error">Error State Macros</h3>
<p class="desc">@Error and @Extended are set by functions (like FileOpen, StringReplace) to return status information.</p>
<div class="bg-gray-900 rounded-lg p-4 mb-3"><pre class="text-gray-300"><span class="text-gray-300">$h</span> = FileOpen(<span class="text-green-400">"/nonexistent.txt"</span>, <span class="text-orange-400">0</span>)
<span class="text-purple-400">If</span> @error <span class="text-purple-400">Then</span>
ConsoleWrite(<span class="text-green-400">"Failed to open file (error "</span> & @error & <span class="text-green-400">")"</span> & @CRLF)
<span class="text-purple-400">EndIf</span>
<span class="text-gray-300">$s</span> = StringReplace(<span class="text-green-400">"Hello World"</span>, <span class="text-green-400">"World"</span>, <span class="text-green-400">"Mac"</span>)
ConsoleWrite(<span class="text-green-400">"Replacements: "</span> & @Extended & @CRLF)</pre></div>
</div>
<!-- ═══════════════════════════════════════════════════════════ -->
<!-- ARRAYS -->
<!-- ═══════════════════════════════════════════════════════════ -->
<h2 id="arrays" class="text-xl font-bold mb-6 mt-10 pb-2 border-b border-gray-200">Arrays</h2>
<div class="fn">
<h3 id="array-decl">Declaration</h3>
<p class="desc">Arrays are 0-based. Declare with [] and optional initial values.</p>
<div class="bg-gray-900 rounded-lg p-4 mb-3"><pre class="text-gray-300"><span class="text-gray-500">; Empty array with fixed size</span>
<span class="text-purple-400">Local</span> <span class="text-gray-300">$arr</span>[<span class="text-orange-400">5</span>] <span class="text-gray-500">; 5 empty elements</span>
<span class="text-gray-500">; Array with values</span>
<span class="text-purple-400">Local</span> <span class="text-gray-300">$arr</span>[] = [<span class="text-green-400">"a"</span>, <span class="text-green-400">"b"</span>, <span class="text-green-400">"c"</span>]
<span class="text-gray-500">; Inline assignment</span>
<span class="text-purple-400">Local</span> <span class="text-gray-300">$arr</span> = [<span class="text-orange-400">1</span>, <span class="text-orange-400">2</span>, <span class="text-orange-400">3</span>]</pre></div>
</div>
<div class="fn">
<h3 id="array-access">Access and Modify</h3>
<p class="desc">Read and write array elements by index. Arrays are 0-based.</p>
<div class="bg-gray-900 rounded-lg p-4 mb-3"><pre class="text-gray-300"><span class="text-purple-400">Local</span> <span class="text-gray-300">$arr</span>[] = [<span class="text-green-400">"apple"</span>, <span class="text-green-400">"banana"</span>, <span class="text-green-400">"cherry"</span>]
<span class="text-gray-500">; Access by index</span>
ConsoleWrite($arr[<span class="text-orange-400">0</span>] & @CRLF) <span class="text-gray-500">; "apple"</span>
ConsoleWrite($arr[<span class="text-orange-400">2</span>] & @CRLF) <span class="text-gray-500">; "cherry"</span>
<span class="text-gray-500">; Modify</span>
$arr[<span class="text-orange-400">1</span>] = <span class="text-green-400">"blueberry"</span>
<span class="text-gray-500">; Size</span>
ConsoleWrite(UBound($arr) & @CRLF) <span class="text-gray-500">; 3</span></pre></div>
</div>
<div class="fn">
<h3 id="array-iterate">Iteration</h3>
<p class="desc">Loop through all elements in an array using For...In or For...Next.</p>
<div class="bg-gray-900 rounded-lg p-4 mb-3"><pre class="text-gray-300"><span class="text-purple-400">Local</span> <span class="text-gray-300">$arr</span>[] = [<span class="text-green-400">"a"</span>, <span class="text-green-400">"b"</span>, <span class="text-green-400">"c"</span>]
<span class="text-gray-500">; For...Next</span>
<span class="text-purple-400">For</span> <span class="text-gray-300">$i</span> = <span class="text-orange-400">0</span> <span class="text-purple-400">To</span> UBound($arr) - <span class="text-orange-400">1</span>
ConsoleWrite($arr[$i] & @CRLF)
<span class="text-purple-400">Next</span>
<span class="text-gray-500">; For...In</span>
<span class="text-purple-400">For</span> <span class="text-gray-300">$item</span> <span class="text-purple-400">In</span> $arr
ConsoleWrite($item & @CRLF)
<span class="text-purple-400">Next</span></pre></div>
</div>
<div class="fn">
<h3 id="array-2d">2D Arrays</h3>
<p class="desc">Two-dimensional arrays with rows and columns, declared with [rows][cols].</p>
<div class="bg-gray-900 rounded-lg p-4 mb-3"><pre class="text-gray-300"><span class="text-purple-400">Local</span> <span class="text-gray-300">$matrix</span>[<span class="text-orange-400">3</span>][<span class="text-orange-400">4</span>] <span class="text-gray-500">; 3 rows, 4 columns</span>
$matrix[<span class="text-orange-400">0</span>][<span class="text-orange-400">0</span>] = <span class="text-green-400">"top-left"</span>
$matrix[<span class="text-orange-400">2</span>][<span class="text-orange-400">3</span>] = <span class="text-green-400">"bottom-right"</span>
ConsoleWrite(UBound($matrix, <span class="text-orange-400">1</span>) & @CRLF) <span class="text-gray-500">; 3 (rows)</span>
ConsoleWrite(UBound($matrix, <span class="text-orange-400">2</span>) & @CRLF) <span class="text-gray-500">; 4 (columns)</span></pre></div>
</div>
<div class="fn">
<h3 id="array-redim">ReDim</h3>
<p class="desc">Resizes an array while preserving existing data.</p>
<div class="bg-gray-900 rounded-lg p-4 mb-3"><pre class="text-gray-300"><span class="text-purple-400">Local</span> <span class="text-gray-300">$arr</span>[<span class="text-orange-400">3</span>] = [<span class="text-green-400">"a"</span>, <span class="text-green-400">"b"</span>, <span class="text-green-400">"c"</span>]
<span class="text-purple-400">ReDim</span> <span class="text-gray-300">$arr</span>[<span class="text-orange-400">5</span>]
<span class="text-gray-500">; Now: ["a", "b", "c", "", ""]</span>
<span class="text-purple-400">ReDim</span> <span class="text-gray-300">$arr</span>[<span class="text-orange-400">2</span>]
<span class="text-gray-500">; Now: ["a", "b"]</span></pre></div>
</div>
<div class="fn">
<h3 id="array-varidx">Variable-Indexed Access</h3>
<p class="desc">Array indices can be variables or expressions.</p>
<div class="bg-gray-900 rounded-lg p-4 mb-3"><pre class="text-gray-300"><span class="text-purple-400">Local</span> <span class="text-gray-300">$arr</span>[] = [<span class="text-green-400">"a"</span>, <span class="text-green-400">"b"</span>, <span class="text-green-400">"c"</span>]
<span class="text-gray-300">$i</span> = <span class="text-orange-400">1</span>
ConsoleWrite($arr[$i] & @CRLF) <span class="text-gray-500">; "b"</span>
ConsoleWrite($arr[$i + <span class="text-orange-400">1</span>] & @CRLF) <span class="text-gray-500">; "c"</span></pre></div>
</div>
<!-- ═══════════════════════════════════════════════════════════ -->
<!-- MAPS -->
<!-- ═══════════════════════════════════════════════════════════ -->
<h2 id="maps" class="text-xl font-bold mb-6 mt-10 pb-2 border-b border-gray-200">Maps</h2>
<div class="fn">
<h3 id="map-decl">Declaration and Access</h3>
<p class="desc">Maps are key/value dictionaries. Keys can be strings or integers. Declare with empty [].</p>
<div class="bg-gray-900 rounded-lg p-4 mb-3"><pre class="text-gray-300"><span class="text-purple-400">Local</span> <span class="text-gray-300">$person</span>[]
<span class="text-gray-500">; Set values</span>
$person[<span class="text-green-400">"name"</span>] = <span class="text-green-400">"Alice"</span>
$person[<span class="text-green-400">"age"</span>] = <span class="text-orange-400">30</span>
$person[<span class="text-green-400">"email"</span>] = <span class="text-green-400">"alice@example.com"</span>
<span class="text-gray-500">; Access</span>
ConsoleWrite($person[<span class="text-green-400">"name"</span>] & @CRLF) <span class="text-gray-500">; "Alice"</span>
ConsoleWrite($person[<span class="text-green-400">"age"</span>] & @CRLF) <span class="text-gray-500">; "30"</span></pre></div>
</div>
<div class="fn">
<h3 id="map-intkeys">Integer Keys</h3>
<p class="desc">Maps support integer keys. They are separate from string keys.</p>
<div class="bg-gray-900 rounded-lg p-4 mb-3"><pre class="text-gray-300"><span class="text-purple-400">Local</span> <span class="text-gray-300">$m</span>[]
$m[<span class="text-orange-400">1</span>] = <span class="text-green-400">"integer key"</span>
$m[<span class="text-green-400">"1"</span>] = <span class="text-green-400">"string key"</span>
ConsoleWrite($m[<span class="text-orange-400">1</span>] & @CRLF) <span class="text-gray-500">; "integer key"</span>
ConsoleWrite($m[<span class="text-green-400">"1"</span>] & @CRLF) <span class="text-gray-500">; "string key"</span></pre></div>
</div>
<div class="fn">
<h3 id="map-with">With...EndWith</h3>
<p class="desc">Provides shorthand dot notation for accessing map properties.</p>
<div class="bg-gray-900 rounded-lg p-4 mb-3"><pre class="text-gray-300"><span class="text-purple-400">Local</span> <span class="text-gray-300">$point</span>[]
$point[<span class="text-green-400">"x"</span>] = <span class="text-orange-400">10</span>
$point[<span class="text-green-400">"y"</span>] = <span class="text-orange-400">20</span>
<span class="text-purple-400">With</span> $point
.x = <span class="text-orange-400">100</span>
.y = <span class="text-orange-400">200</span>
<span class="text-purple-400">EndWith</span>
ConsoleWrite($point[<span class="text-green-400">"x"</span>] & @CRLF) <span class="text-gray-500">; 100</span>
ConsoleWrite($point[<span class="text-green-400">"y"</span>] & @CRLF) <span class="text-gray-500">; 200</span></pre></div>
</div>
<!-- ═══════════════════════════════════════════════════════════ -->
<!-- BINARY -->
<!-- ═══════════════════════════════════════════════════════════ -->
<h2 id="binary" class="text-xl font-bold mb-6 mt-10 pb-2 border-b border-gray-200">Binary Data</h2>
<div class="fn">
<h3 id="bin-create">Create and Convert</h3>
<p class="desc">Binary data is represented as hex strings. Convert between strings and binary.</p>
<div class="bg-gray-900 rounded-lg p-4 mb-3"><pre class="text-gray-300"><span class="text-gray-300">$bin</span> = Binary(<span class="text-green-400">"Hello"</span>)
ConsoleWrite($bin & @CRLF) <span class="text-gray-500">; "0x48656C6C6F"</span>
<span class="text-gray-300">$str</span> = BinaryToString($bin)
ConsoleWrite($str & @CRLF) <span class="text-gray-500">; "Hello"</span>
<span class="text-gray-300">$len</span> = BinaryLen($bin)
ConsoleWrite($len & @CRLF) <span class="text-gray-500">; 5</span>
<span class="text-gray-300">$mid</span> = BinaryMid($bin, <span class="text-orange-400">2</span>, <span class="text-orange-400">3</span>)
ConsoleWrite($mid & @CRLF) <span class="text-gray-500">; "0x656C6C"</span></pre></div>
</div>
<div class="fn">
<h3 id="bin-bitwise">Bitwise Operations</h3>
<p class="desc">AND, OR, XOR, and NOT operations on binary data.</p>
<div class="bg-gray-900 rounded-lg p-4 mb-3"><pre class="text-gray-300">ConsoleWrite(BinaryAND(<span class="text-green-400">"0xFF00"</span>, <span class="text-green-400">"0x0FF0"</span>) & @CRLF) <span class="text-gray-500">; "0x0F00"</span>
ConsoleWrite(BinaryOR(<span class="text-green-400">"0xF000"</span>, <span class="text-green-400">"0x0F00"</span>) & @CRLF) <span class="text-gray-500">; "0xFF00"</span>
ConsoleWrite(BinaryXOR(<span class="text-green-400">"0xFF00"</span>, <span class="text-green-400">"0xFFFF"</span>) & @CRLF) <span class="text-gray-500">; "0x00FF"</span>
ConsoleWrite(BinaryNOT(<span class="text-green-400">"0xFF"</span>) & @CRLF) <span class="text-gray-500">; "0x00"</span></pre></div>
</div>
</div>
</div>
<footer class="border-t border-gray-200 py-6 text-center text-sm text-gray-500">
macau — macOS scripting engine · <a href="https://github.com/AdrianSimionov/macau" class="text-gray-500 hover:underline">GitHub</a> · MIT License
</footer>
</body>
</html>