Execute SNUSP: Difference between revisions

Added FreeBASIC
m (→‎{{header|Wren}}: Changed to Wren S/H)
(Added FreeBASIC)
 
(3 intermediate revisions by 2 users not shown)
Line 48:
ds[dp] = Byte(:stdin.read(1).code)
‘/’
id = (-)~id
‘\’
id (+)= 1
Line 84:
=={{header|D}}==
See [[RCSNUSP/D]].
 
=={{header|EasyLang}}==
{{trans|Go}}
<syntaxhighlight>
proc snusp dlen raw$ . .
len ds[] dlen
is$[] = strsplit raw$ "\n"
for s$ in is$[]
is$[][] &= strchars s$
.
for ipr to len is$[][]
for ipc to len is$[ipr][]
if is$[ipr][ipc] = "$"
break 2
.
.
.
dp = 1
id = 0
#
subr step
if id mod 2 = 0
ipc += 1 - bitand id 2
else
ipr += 1 - bitand id 2
.
.
while ipr >= 1 and ipr <= len is$[][] and ipc >= 1 and ipc <= len is$[ipr][]
c$ = is$[ipr][ipc]
if c$ = ">"
dp += 1
elif c$ = "<"
dp -= 1
elif c$ = "+"
ds[dp] += 1
elif c$ = "-"
ds[dp] -= 1
elif c$ = "."
write strchar ds[dp]
elif c$ = ","
# ds[dp] = strcode input
elif c$ = "/"
id = bitxor id 3
elif c$ = "\\"
id = bitxor id 1
elif c$ = "!"
step
elif c$ = "?"
if ds[dp] = 0
step
.
.
step
.
.
s$ = input
while s$ <> ""
cod$ &= "\n" & s$
s$ = input
.
snusp 5 cod$
#
input_data
/++++!/===========?\>++.>+.+++++++..+++\
\+++\ | /+>+++++++>/ /++++++++++<<.++>./
$+++/ | \+++++++++>\ \+++++.>.+++.-----\
\==-<<<<+>+++/ /=.>.+>.--------.-/
 
</syntaxhighlight>
 
=={{header|F_Sharp|F#}}==
Line 90 ⟶ 159:
=={{header|Factor}}==
See [[RCSNUSP/Factor]].
 
=={{header|FreeBASIC}}==
<syntaxhighlight lang="vbnet">' Rosetta Code problem: https://rosettacode.org/wiki/Execute_SNUSP
' by Jjuanhdez, 05/2024
' The interpreter below implements Core SNUSP:
 
Const HW = "/++++!/===========?\>++.>+.+++++++..+++" & Chr(10) & _
"\+++\ | /+>+++++++>/ /++++++++++<<.++>./" & Chr(10) & _
"$+++/ | \+++++++++>\ \+++++.>.+++.-----\" & Chr(10) & _
" \==-<<<<+>+++/ /=.>.+>.--------.-/"
 
Dim Shared As Integer ipf, ipc ' instruction pointers in row and column
Dim Shared As Integer direcc ' direction (0 = right, 1 = down, 2 = left, 3 = up)
 
Sub Paso()
If direcc And 1 Then
ipf += 1 - (direcc And 2)
Else
ipc += 1 - (direcc And 2)
End If
End Sub
 
Sub SNUSP (dsLen As Integer, SNUSPcode As String)
Dim As Ubyte ad(dsLen - 1) ' data store
Dim As Integer dp ' data pointer
Dim As String cb(dsLen) ' two-way code storage
Dim As String fila, op, linea
Dim As Integer r, i, j
dp = 0
i = 1
j = 1
ipf = 0
ipc = 0
direcc = 0
While i <= Len(SNUSPcode)
If Mid(SNUSPcode, i, 1) = Chr(10) Then
cb(j) = linea
linea = ""
j += 1
Else
linea &= Mid(SNUSPcode, i, 1)
End If
i += 1
Wend
cb(j) = linea
For r = 0 To Ubound(cb)
fila = cb(r)
ipc = Instr(fila, "$") - 1
If ipc >= 0 Then
ipf = r
Exit For
End If
Next r
While ipf >= 0 And ipf <= Ubound(cb) And ipc >= 0 And ipc < Len(cb(ipf))
op = Mid(cb(ipf), ipc + 1, 1)
Select Case op
Case ">": dp += 1 ' RIGTH
Case "<": dp -= 1 ' LEFT
Case "+": ad(dp) += 1 ' INCR
Case "-": ad(dp) -= 1 ' DECR
Case ",": Input ad(dp) ' READ
Case ".": Print Chr(ad(dp)); ' WRITE
Case "/": direcc = Not direcc ' RULD
Case "\": direcc Xor= 1 ' LURD
Case "!": Paso ' SKIP
Case "?": If ad(dp) = 0 Then Paso ' SKIPZ
End Select
Paso
Wend
Print Chr(ad(dp));
End Sub
 
SNUSP(5, HW)
 
Sleep</syntaxhighlight>
 
=={{header|Go}}==
2,169

edits