[dlldl*+sl%.=/llls1+>>]s>[q]s3[.*dss]s/[pl%1-s%]s<23s%3d1-ps*p[ddvss3sll>x_<3l-x]ds-x
#-----------------------------------------#
# 2020-10-07 EG Giessmann (CC-BY) #
## remove the comments for a POSIX input ##
#-----------------------------------------#
[ # the factor lookup macro ">"
dll # double top of the stack, load the factor register 'l' for testing
dl*+ # double the factor value, add 2 from the "*" register
sl # and store the next factor l+2 in the factor register 'l'
%.=/ # if the top modulo factor is equal to "." (zero!), call the composite found macro "/"
llls1+ # load the the next factor "l" and the square root "s", add 1 to s
>> # if s+1 is greater yet than factor "l" then call the factor lookup macro ">" again
]s>
[ # the quit macro "3"
q # leave dc if all the primes are printed out
]s3
[ # the found composite macro "/"
.*dss # multiply the top with zero (aka "."), double it and store 0 in register "s"
]s/
[ # the prime printing macro "<"
p # print the prime on the top of the stack
l%1-s% # load the counter register "%", subtract 1 and store it again
]s<
23s% # store 23 in the counter register "%" (23 primes are in [5..97] and 1227 in [5..10000])
3d1- # push 3 on the stack, double it and subtract 1
ps*p # print the top (it is 2), store it in register "*" to be used later, print the top (now 3)
[ # main macro "-"
ddvss # triple the top, store the square root of the top in register "s"
3sl # store the initial factor 3 in the factor register "l"
l>x # execute the factor lookup macro ">" until top of the stack has a factor or is a prime
_<< # call the prime printing macro if top is greater than "_" (also zero), i.e. top is a prime
l*+ # add 2 (aka register "*") to the top
l%1>3 # load the counter register "%", if it is less than 1 then execute the quit macro "3"
l-x # if not yet finished load the main macro "-" and execute it again
]ds-x # double the main macro, store and run