SPR uses short command prefixes and variables such as $$SUM. These native examples combine explicit values, calculations and output.
SPR uses short command prefixes and variables such as $$SUM. These native examples combine explicit values, calculations and output. Open full-size diagram

SPR: examples explained

Maturity and boundaries: experimental

Implemented scope: The existing command set plus 73 selected new roots and selected bitmap, queue, process, registry and Windows helpers are documented.

Boundary: 60 roots remain unfinished; there is no MiniRobot comparison qualification, SAP and SPR Browser are deferred, and many selectors/providers remain open.

Back to the PBXB64 V9 overview Deutsch

SPR supported command roots and scope

Browse the language-specific supported-command and scope reference, with searchable categories and explicit boundaries.

Open scope reference

SPR uses short command prefixes and variables such as $$SUM. These native examples combine explicit values, calculations and output.

Twelve short examples and one larger program. Choose a topic or work through the examples in order.

1. 1 + 2 + 3 + 4 + 5 = 15

The numbers 1 through 5 are added to 15. The program prints 15 and ends with exit code 0.

VAR.$$SUM=0
FOR.$$III|1|5|1
    VIC.$$SUM|$$III
NEX.
OUT.$$SUM
ENR.

Expected exit code: 0; output verification pattern (regex): '15'

PBXB64.exe sum15-spr.spr -O2 -o example.exe
.\example.exe
$LASTEXITCODE

Download source

Executed natively with the V22 candidate from 2026-09-30; final-compiler verification pending.

2. Arithmetic with CAL. and CAX.

VAR. sets up 1 and 2. CAL. calculates 1 + 2 * 3 as 7; CAX. uses sqrt(16). This case has no explicit output and checks successful program completion.

' Minimal SPR math-coverage fixture.
VAR.$$AAA=1
VAR.$$BBB=2
CAL.$$CCC=$$AAA+$$BBB*3
CAX.$$DDD=sqrt(16)
END.

Expected exit code: 0

PBXB64.exe math.spr -O2 -o example.exe
.\example.exe
$LASTEXITCODE

Download source

Canonical test case with an expected result; no new native V22 check here. Final execution pending.

3. Extend and print a string value

VAR. creates the text, VAS. extends it and OUT. prints the variable. Exact composition follows the SPR command contract; the canonical output test expects helloworld.

' SPR string-coverage fixture.
VAR.$$MSG=hello
VAS.$$MSG+ world
VAU.$$INP=test
OUT.$$MSG
END.

Expected exit code: 0; output verification pattern (regex): 'helloworld'

PBXB64.exe strings.spr -O2 -o example.exe
.\example.exe
$LASTEXITCODE

Download source

Canonical test case with an expected result; no new native V22 check here. Final execution pending.

4. FOR and a post-test loop

Step-by-step flow

  1. VAR. creates SUM; FOR. and NEX. form a counted loop over 1 through 5.
  2. The body updates SUM using the existing VAR. command contract.
  3. DOL./OOP. then demonstrates a post-test. The canonical case expects completion without explicit console output.
' SPR loop fixture
VAR.$$SUM=0
FOR.$$CTR|1|5
VAR.$$SUM=$$SUM+$$CTR
NEX.
DOL.
OOP.$$SUM>10
END.

Expected exit code: 0

PBXB64.exe spr-loop.spr -O2 -o example.exe
.\example.exe
$LASTEXITCODE

Download source

Expected-result contract from tests/validate.toml. This website expansion adds no new native compiler verification. Execution with the qualified final compiler remains pending.

5. A subroutine with one argument

Step-by-step flow

  1. GSB. with target :add5 and argument 10 passes a value to the subroutine.
  2. The body uses legacy argument alias $$000 in its assignment and returns with RET.
  3. JMP.:done prevents normal flow from entering the body again. This case checks completion rather than a printed numeric result.
' SPR subroutine fixture
VAR.$$AAA=0
GSB.:add5|10
JMP.:done
:add5
VAR.$$AAA=$$000+5
RET.
:done
END.

Expected exit code: 0

PBXB64.exe spr-subroutine.spr -O2 -o example.exe
.\example.exe
$LASTEXITCODE

Download source

Expected-result contract from tests/validate.toml. This website expansion adds no new native compiler verification. Execution with the qualified final compiler remains pending.

6. Subroutine argument count and values

Step-by-step flow

  1. GSB. supplies two arguments, 42 and hello.
  2. $$_00 denotes argument count 2 in this documented contract.
  3. $$_01 and $$_02 contain the two arguments. PRT. therefore prints 2, 42 and hello.
' SPR reference contract: documented subroutine parameter aliases.
GSB.:SHOW|42|hello
END.

:SHOW
PRT.$$_00
PRT.$$_01
PRT.$$_02
RET.

Expected exit code: 0

Canonical output verification pattern (regex)
2
42
hello
PBXB64.exe spr-spr_subroutine_documented_params.spr -O2 -o example.exe
.\example.exe
$LASTEXITCODE

Download source

Expected-result contract from tests/validate.toml. This website expansion adds no new native compiler verification. Execution with the qualified final compiler remains pending.

7. Branch on a collection entry

Step-by-step flow

  1. ATC. stores alpha in collection 7.
  2. JNU. branches to seen when alpha is present.
  3. OUT.bad is skipped; the reached output command writes seen.
ATC.7|alpha
JNU.7|alpha|seen
OUT.bad
END.
:seen
OUT.seen
END.
END.

Expected exit code: 0

Canonical output verification pattern (regex)
^seen\n$
PBXB64.exe spr-spr_reference_collection.spr -O2 -o example.exe
.\example.exe
$LASTEXITCODE

Download source

Expected-result contract from tests/validate.toml. This website expansion adds no new native compiler verification. Execution with the qualified final compiler remains pending.

8. Enumerate collection elements with FEC.

Step-by-step flow

  1. CLC. clears collection 9; ATA. adds alpha and beta.
  2. FEC. and FEN. surround iteration; $$ITM holds the current element.
  3. OUT. displays both texts in the concrete test contract's order, separated by whitespace.
' Source-backed FEC collection enumerator contract.
VAR.$$OUT=
CLC.9
ATA.9|alpha
ATA.9|beta
FEC.LAB|$$ITM|9
OUT.$$ITM
OUT.$sp$
FEN.
END.

Expected exit code: 0

Canonical output verification pattern (regex)
alpha\s+beta
PBXB64.exe spr-spr_fec_collection_contract.spr -O2 -o example.exe
.\example.exe
$LASTEXITCODE

Download source

Expected-result contract from tests/validate.toml. This website expansion adds no new native compiler verification. Execution with the qualified final compiler remains pending.

9. Several stack-push variants

Step-by-step flow

  1. PUS. pushes literal text; PUV., PVS., PSS. and PNS. demonstrate variable-oriented variants.
  2. POV. retrieves five values in reverse push order: 42, alpha, alpha, alpha, lit.
  3. STV.DUPL is then checked through two popped results. This concrete contract produces 1 and zzz; it does not assert general Forth stack semantics.
' Source-backed stack push variants and POV compatibility pop.
VAR.$$S00=alpha
VAN.$$N00=42
PUS.lit
PUV.$$S00
PVS.$$S00
PSS.$$S00
PNS.$$N00
POV.$$A00|$$A01|$$A02|$$A03|$$A04
OUT.$$A00
OUT.$sp$
OUT.$$A01
OUT.$sp$
OUT.$$A02
OUT.$sp$
OUT.$$A03
OUT.$sp$
OUT.$$A04
PUS.zzz
STV.DUPL
POV.$$B00|$$B01
OUT.$sp$
OUT.$$B00
OUT.$sp$
OUT.$$B01
END.

Expected exit code: 0

Canonical output verification pattern (regex)
42\s+alpha\s+alpha\s+alpha\s+lit\s+1\s+zzz
PBXB64.exe spr-spr_stack_push_variants.spr -O2 -o example.exe
.\example.exe
$LASTEXITCODE

Download source

Expected-result contract from tests/validate.toml. This website expansion adds no new native compiler verification. Execution with the qualified final compiler remains pending.

10. Text manipulation and XML decoding

Step-by-step flow

  1. CiSingleReplace replaces only the first case-insensitive match: Cat becomes dog.
  2. FindAny finds d at position 4; LTrim, RTrim and RetainAny produce left, right and 123.
  3. XML.unclean converts a&amp;&lt;b&gt; into a&<b>. This page presents both spellings as source text rather than executable markup.
' Source-backed STR/XML selectors not covered by the earlier text wave.
VAR.$$SRC=Cat cat CAt
VAR.$$CSR=
STR.CiSingleReplace|$$SRC|cat|dog|$$CSR
VAN.$$FAY=0
STR.FindAny|abcdef|xzdy|$$FAY
VAR.$$LTR=$sp$$sp$left
VAR.$$LTO=
STR.LTrim|$$LTR|$sp$|$$LTO
VAR.$$RTR=right$sp$$sp$
VAR.$$RTO=
STR.RTrim|$$RTR|$sp$|$$RTO
VAR.$$RTN=
STR.RetainAny|abc123xyz|123|$$RTN
VAR.$$XML=
XML.unclean|a&amp;&lt;b&gt;|$$XML
OUT.$$CSR
OUT.$sp$
OUT.$$FAY
OUT.$sp$
OUT.$$LTO
OUT.$sp$
OUT.$$RTO
OUT.$sp$
OUT.$$RTN
OUT.$sp$
OUT.$$XML
END.

Expected exit code: 0

Canonical output verification pattern (regex)
dog\s+cat\s+CAt\s+4\s+left\s+right\s+123\s+a&<b>
PBXB64.exe spr-spr_string_xml_gap_subcommands.spr -O2 -o example.exe
.\example.exe
$LASTEXITCODE

Download source

Expected-result contract from tests/validate.toml. This website expansion adds no new native compiler verification. Execution with the qualified final compiler remains pending.

11. FOR. with fractional steps

Step-by-step flow

  1. The first loop starts at 0.5, includes 2.5 and uses step 0.5.
  2. After NEX., its counter contains 3; the additional output shows the post-loop state.
  3. Later loops use a variable bound and step expression $$NNN+0.5. The output contract also records .5 without a leading zero.
' SPR FOR EXTENDED variant (A1.1): float literals, FLOAT var bounds, formula step.
CAL.$$FLT=0.25
VAR.$$NNN=1
FOR.$$AAA|0.5|2.5|0.5
OUT.$$AAA
NEX.
OUT.$$AAA
FOR.$$BBB|$$FLT|1.75|0.25
OUT.$$BBB
NEX.
FOR.$$CCC|$$NNN|3|$$NNN+0.5
OUT.$$CCC
NEX.
END.

Expected exit code: 0

Canonical output verification pattern (regex)
^\.5
1
1\.5
2
2\.5
3
\.25
\.5
\.75
1
1\.25
1\.5
1\.75
1
2\.5$
PBXB64.exe spr-spr_for_float.spr -O2 -o example.exe
.\example.exe
$LASTEXITCODE

Download source

Expected-result contract from tests/validate.toml. This website expansion adds no new native compiler verification. Execution with the qualified final compiler remains pending.

12. Conditional branches and error-state reads

Step-by-step flow

  1. JIU. and JNU. check missing and present collection entries here.
  2. The intentionally incomplete CAX. expression sets a soft error state read by JIT. or JNT.
  3. A read consumes that state. Consequently, two consecutive checks take different paths.
' Wave 5 jump-if family: JIU./JNU. collection-membership jumps and
' JIT./JNT. branching on the CAX soft-error flag (read+clear semantics).
ATC.1|alpha
JIU.1|beta|jiu_hit
OUT.jiu_miss_beta
END.
:jiu_hit
OUT.jiu_hit
JIU.1|alpha|done
OUT.after_jiu_alpha
JNU.1|alpha|jnu_hit
OUT.jnu_miss_alpha
END.
:jnu_hit
OUT.jnu_hit
JNU.1|beta|done
OUT.after_jnu_beta
CAX.$$A01=(1+2
JIT.jit_hit
OUT.jit_miss
END.
:jit_hit
OUT.jit_hit
JIT.done
OUT.after_jit
CAX.$$B02=(1+2
JNT.done
OUT.after_jnt_set
JNT.jnt_hit
OUT.jnt_miss
END.
:jnt_hit
OUT.jnt_hit
:done
OUT.done
END.

Expected exit code: 0

Canonical output verification pattern (regex)
^jiu_hit
after_jiu_alpha
jnu_hit
after_jnu_beta
jit_hit
after_jit
after_jnt_set
jnt_hit
done$
PBXB64.exe spr-spr_jump_if_wave5.spr -O2 -o example.exe
.\example.exe
$LASTEXITCODE

Download source

Expected-result contract from tests/validate.toml. This website expansion adds no new native compiler verification. Execution with the qualified final compiler remains pending.

Larger example: Combine numeric and text case selection

Step-by-step flow

  1. SCN. selects numeric cases and SCS. selects text cases. The first numeric block matches CAN.14; gamma uses the default string branch.
  2. Two identical CAN.1 cases show that only the first match executes. The counter loop produces zero, one and many.
  3. ESC. ends each selection block. A block with no match and no default continues at after-select.
' SELECT-CASE (SCS./SCN. with CAS./CAN./CAE./ESC.) has no other coverage in
' this tree, and every select used to fault the compiler: an open frame left at
' end of input was closed by the IF auto-close path, which branched from the
' frame's null else block.  These cases pin the working behaviour.
' SCN. numeric select, multiple values and a formula in the case list.
VAR.$$NUM=14
SCN.$$NUM
CAN.12,45,(4*$$NUM)
PRT.wrong-case
CAN.14
PRT.formula-match
CAE.
PRT.numeric-default
ESC.
' SCS. string select falling through to the default.
VAR.$$TXT=gamma
SCS.$$TXT
CAS.alpha
PRT.alpha
CAS.beta
PRT.beta
CAE.
PRT.string-default
ESC.
' First matching case wins; the second case with the same value is skipped.
VAR.$$ONE=1
SCN.$$ONE
CAN.1
PRT.first-wins
CAN.1
PRT.second-case
ESC.
' Select inside a loop, so the merge block is revisited across iterations.
VAR.$$CNT=0
:LOOP
SCN.$$CNT
CAN.0
PRT.zero
CAN.1
PRT.one
CAE.
PRT.many
ESC.
CAL.$$CNT=$$CNT+1
IVV.$$CNT<3
GTO.LOOP
EIF.
' Select with no default and no match runs the code after ESC.
VAR.$$MIS=99
SCN.$$MIS
CAN.1,2,3
PRT.unreachable
ESC.
PRT.after-select
END.

Expected exit code: 0

Canonical output verification pattern (regex)
formula-match
string-default
first-wins
zero
one
many
after-select
PBXB64.exe spr-test_spr_select_case.spr -O2 -o example.exe
.\example.exe
$LASTEXITCODE

Download source

Expected-result contract from tests/validate.toml. This website expansion adds no new native compiler verification. Execution with the qualified final compiler remains pending.

All sources for this tutorial

Each example has its own folder; the README lists compiler commands. Included support files retain matching paths.

Download all 13 examples as ZIP

Bridging

VIP. binds an SPR variable to a BASIC GLOBAL variable in the concrete bridge contract. Numeric values and strings use different type contracts; the complete source pair is on the bridging page.

Explore complete source pairs