git @ Cat's Eye Technologies SixtyPical / 0.12 tests / SixtyPical Syntax.md
0.12

Tree @0.12 (Download .tar.gz)

SixtyPical Syntax.md @0.12

feb5729
 
49d90df
 
 
 
2dc4dd9
 
 
49d90df
 
feb5729
ed1ed3e
49d90df
feb5729
49d90df
 
 
 
 
 
 
 
 
9235c6e
 
 
 
 
 
 
 
 
 
a933c81
 
 
 
 
 
 
 
 
49d90df
 
 
 
 
 
 
a933c81
522c771
 
 
 
 
 
 
 
49d90df
 
 
 
 
 
 
 
 
 
 
 
f7eb0d4
c7861d3
 
 
 
 
 
 
 
f7eb0d4
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
49e42af
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
f7eb0d4
 
522c771
42438dd
 
 
 
0be7216
42438dd
 
 
 
 
 
 
0be7216
 
70ecd52
 
 
0be7216
 
 
 
 
74f8675
 
 
70ecd52
74f8675
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
7b1ee60
522c771
 
 
 
 
 
 
 
41432b5
6cf8b5f
 
7b1ee60
6cf8b5f
 
 
 
 
 
 
9d6ca0b
 
 
 
 
 
 
 
 
 
fc8c85e
 
70ecd52
fc8c85e
 
 
 
 
 
 
 
f87bcf5
 
70ecd52
f87bcf5
 
 
 
 
 
 
 
 
 
 
 
 
41432b5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
a12a44e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
41432b5
19dd089
 
 
 
 
 
 
 
 
 
 
 
 
41432b5
 
 
 
 
 
 
 
 
 
 
4287bf8
689ed37
4287bf8
70ecd52
4287bf8
 
 
 
 
 
 
 
c98e446
689ed37
70ecd52
689ed37
 
 
 
 
 
 
 
 
2dc4dd9
c98e446
0be7216
f0b8942
 
 
0be7216
c98e446
 
 
 
 
645079f
 
 
2dc4dd9
c98e446
 
f0b8942
 
 
bbd3a84
f0b8942
 
 
bbd3a84
f0b8942
 
 
 
be76b9a
ec2e051
 
0be7216
ec2e051
 
 
0be7216
ec2e051
 
 
 
 
 
 
 
 
 
 
 
2a71c7e
 
0be7216
2a71c7e
 
 
0be7216
2a71c7e
 
 
 
 
 
 
 
 
 
 
 
f6fa1ec
 
 
b7b2883
0be7216
b29716f
 
 
0be7216
0194d37
 
 
 
 
 
 
 
 
b7b2883
 
be76b9a
 
 
 
 
 
 
 
 
 
19dd089
 
 
 
 
 
 
 
0be7216
be76b9a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
c915741
 
 
 
 
d84566a
c915741
 
32389e4
c915741
d84566a
c915741
 
9778e08
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
b829836
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
  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
SixtyPical Syntax
=================

This is a test suite, written in [Falderal][] format, for the syntax of
the Sixtypical language, disgregarding execution, static analysis, etc.

Note that these example programs are intended to be syntactically correct,
but not necessarily sensible programs.

[Falderal]:     http://catseye.tc/node/Falderal

    -> Functionality "Check syntax of SixtyPical program" is implemented by
    -> shell command "bin/sixtypical --parse-only --traceback %(test-body-file) && echo ok"

    -> Tests for functionality "Check syntax of SixtyPical program"

Rudimentary program.

    | routine main {
    |     ld a, 0
    |     add a, 1
    | }
    = ok

Program with comments.

    | // Welcome to my program.
    | 
    | routine main {
    |     ld a, 0
    |     add a, 1    // We are adding the thing.
    | }
    = ok

Hex literals.

    | routine main {
    |     ld a, $ff
    |     add a, $01
    | }
    = ok

Syntax error.

    | routine foo (
    |     ld a, 0
    |     add a, 1
    | )
    ? SyntaxError

Another syntax error.

    | byte glee
    | {
    |     ld a, 0
    |     add a, 1
    | }
    ? SyntaxError

Extern routines

    | routine chrout
    |   inputs a
    |   trashes a
    |   @ 65490
    | 
    | routine chrin
    |   outputs a
    |   trashes x
    |   @ 65487
    = ok

Trash.

    | routine main {
    |     trash a
    |     trash n
    | }
    = ok

If with not

    | routine foo {
    |     ld y, 0
    |     cmp y, 10
    |     if not z {
    |         inc y
    |         cmp y, 10
    |     }
    | }
    = ok

Repeat loop

    | routine foo {
    |     ld y, 0
    |     repeat {
    |         inc y
    |         cmp y, 10
    |     } until z
    | }
    = ok

"While" loop

    | routine foo inputs y {
    |     repeat {
    |         cmp y, 10
    |         if not z {
    |             inc y
    |         }
    |     } until z
    | }
    = ok

Repeat forever

    | routine foo inputs y {
    |     repeat {
    |         inc y
    |     } forever
    | }
    = ok

Repeat with not

    | routine foo inputs y {
    |     repeat {
    |         inc y
    |     } until not z
    | }
    = ok

User-defined memory addresses of different types.

    | byte byt
    | word wor
    | vector routine trashes a vec
    | buffer[2048] buf
    | pointer ptr
    | 
    | routine main {
    | }
    = ok

Tables of different types.

    | byte table[256] tab
    | word table[256] wtab
    | vector (routine trashes a) table[256] vtab
    | 
    | routine main {
    | }
    = ok

Typedefs of different types.

    | typedef byte octet
    | typedef octet table[256] twokay
    | typedef routine trashes a game_routine
    | vector game_routine start_game
    | 
    | routine main {
    | }
    = ok

Can't have two typedefs with the same name.

    | typedef byte frank
    | typedef word frank
    | 
    | routine main {
    | }
    ? SyntaxError

Explicit memory address.

    | byte screen @ 1024
    | 
    | routine main {
    |   ld a, 100
    |   st a, screen
    | }
    = ok

Initialized memory locations.

    | byte lives : 3
    | 
    | routine main {
    |   ld a, lives
    |   st a, lives
    | }
    = ok

Cannot have both initial value and explicit address.

    | byte screen : 3 @ 1024
    | 
    | routine main {
    |   ld a, lives
    |   st a, lives
    | }
    ? SyntaxError

User-defined locations of other types.

    | byte table[256] screen @ 1024
    | word r1
    | word r2 @ 60000
    | word r3 : 2000
    | 
    | routine main {
    | }
    = ok

Initialized byte table.

    | byte table[32] message : "WHAT DO YOU WANT TO DO NEXT?"
    | 
    | routine main {
    | }
    = ok

Can't initialize anything but a byte table with a string.

    | word message : "WHAT DO YOU WANT TO DO NEXT?"
    | 
    | routine main {
    | }
    ? SyntaxError

Can't access an undeclared memory location.

    | routine main {
    |     ld a, 0
    |     st a, lives
    | }
    ? SyntaxError

Can't define two memory locations with the same name.

    | byte lives
    | byte lives
    | 
    | routine main {
    |     ld a, 0
    |     st a, lives
    | }
    ? SyntaxError

Can't shadow the name of a register or a flag.

    | byte a
    | 
    | routine main {
    | }
    ? SyntaxError

    | byte z
    | 
    | routine main {
    | }
    ? SyntaxError

Can't call routine that hasn't been defined.

    | routine main {
    |     ld x, 0
    |     ld y, 1
    |     call up
    |     call up
    | }
    ? SyntaxError

And you can't call a non-routine.

    | byte up
    | 
    | routine main {
    |     ld x, 0
    |     ld y, 1
    |     call up
    | }
    ? SyntaxError

    | routine main {
    |     ld x, 0
    |     ld y, 1
    |     call x
    | }
    ? SyntaxError

But you can call a routine that is yet to be defined, further on.

    | routine main {
    |     ld x, 0
    |     ld y, 1
    |     call up
    |     call up
    | }
    | routine up {
    |     ld a, 0
    | }
    = ok

Can't define two routines with the same name.

    | routine main {
    |     inc x
    |     inc y
    | }
    | routine main {
    |     ld x, 0
    |     ld y, 1
    | }
    ? SyntaxError

Declaring byte and word table memory location.

    | byte table[256] tab
    | 
    | routine main {
    |     ld x, 0
    |     ld y, 0
    |     ld a, tab + x
    |     st a, tab + y
    | }
    = ok

    | word one
    | word table[256] many
    | 
    | routine main {
    |     ld x, 0
    |     copy one, many + x
    |     copy word 0, many + x
    |     copy many + x, one
    | }
    = ok

Declaring and calling a vector.

    | vector routine
    |   inputs a
    |   outputs x
    |   trashes a, x, z, n
    |   cinv @ 788
    | 
    | routine foo {
    |     ld a, 0
    | }
    | routine main {
    |     with interrupts off {
    |         copy foo, cinv
    |     }
    |     call cinv
    | }
    = ok

Only vectors can be decorated with constraints like that.

    | byte cinv
    |   inputs a
    |   outputs x
    |   trashes a, x, z, n
    |   @ 788
    | 
    | routine main {
    | }
    ? SyntaxError

Constraints set may only contain labels.

    | vector routine
    |   inputs a
    |   outputs 200
    |   trashes a, x, z, n
    |   cinv @ 788
    | 
    | routine foo {
    |     ld a, 0
    | }
    | routine main {
    |     with interrupts off {
    |         copy foo, cinv
    |     }
    |     call cinv
    | }
    ? SyntaxError

A vector can name itself in its inputs, outputs, and trashes.

    | vector routine
    |   inputs cinv, a
    |   outputs cinv, x
    |   trashes a, x, z, n
    |   cinv @ 788
    | 
    | routine foo {
    |     ld a, 0
    | }
    | routine main {
    |     with interrupts off {
    |         copy foo, cinv
    |     }
    |     call cinv
    | }
    = ok

A routine can be copied into a vector before the routine appears in the program.
This is known as a "forward reference".  You are only allowed to make forward
references in the source of a `copy` instruction.

    | vector routine
    |   inputs cinv, a
    |   outputs cinv, x
    |   trashes a, x, z, n
    |   cinv @ 788
    | routine main {
    |     with interrupts off {
    |         copy foo, cinv
    |     }
    |     call cinv
    | }
    | routine foo {
    |     ld a, 0
    | }
    = ok

goto.

    | routine foo {
    |     ld a, 0
    | }
    | routine main {
    |     goto foo
    | }
    = ok

    | routine main {
    |     goto foo
    | }
    | routine foo {
    |     ld a, 0
    | }
    = ok

    | vector routine foo
    | 
    | routine main {
    |     goto foo
    | }
    = ok

    | routine main {
    |     goto foo
    | }
    ? SyntaxError

    | byte foo
    | 
    | routine main {
    |     goto foo
    | }
    ? SyntaxError

Buffers and pointers.

    | buffer[2048] buf
    | pointer ptr
    | byte foo
    | 
    | routine main {
    |     copy ^buf, ptr
    |     copy 123, [ptr] + y
    |     copy [ptr] + y, foo
    | }
    = ok

Routines can be defined in a new style.

    | typedef routine
    |   inputs x
    |   outputs x
    |   trashes z, n
    |     routine_type
    | 
    | vector routine_type vec
    | 
    | define foo routine
    |   inputs x
    |   outputs x
    |   trashes z, n
    | {
    |   inc x
    | }
    | 
    | routine main
    |   outputs vec
    |   trashes a, z, n
    | {
    |     copy foo, vec
    | }
    = ok

Only routines can be defined in the new style.

    | define foo byte table[256]
    | 
    | routine main
    |   trashes a, z, n
    | {
    |     ld a, 0
    | }
    ? SyntaxError

Memory locations can be defined static to a routine.

    | define foo routine
    |   inputs x
    |   outputs x
    |   trashes z, n
    |   static byte t : 0
    | {
    |   st x, t
    |   inc t
    |   ld x, t
    | }
    | 
    | define main routine
    |   trashes a, x, z, n
    |   static byte t : 0
    | {
    |   ld x, t
    |   call foo
    | }
    = ok

Static memory locations must always be given an initial value.

    | define main routine
    |   inputs x
    |   outputs x
    |   trashes z, n
    |   static byte t
    | {
    |   st x, t
    |   inc t
    |   ld x, t
    | }
    ? SyntaxError

Name of a static cannot shadow an existing global or static.

    | byte t
    | 
    | define main routine
    |   inputs x
    |   outputs x
    |   trashes z, n
    |   static byte t
    | {
    |   st x, t
    |   inc t
    |   ld x, t
    | }
    ? SyntaxError

    | define main routine
    |   inputs x
    |   outputs x
    |   trashes z, n
    |   static byte t
    |   static byte t
    | {
    |   st x, t
    |   inc t
    |   ld x, t
    | }
    ? SyntaxError