#1 21 Mar 2021 09:59

From: Cracow, Poland
Registered: 18 Mar 2021
Posts: 13

Fixed and improved Deadfish interpreter

Because the original Batch version of Deadfish interpreter from Esolangs.org had bugs, I fixed all of these and improved the interpreter:

@echo off
set acc=0
set /p cmd=^>^>
if "%cmd%"=="" goto start
set okay=0
if "%cmd:~0,1%"=="i" set /a acc=acc+1&set okay=1
if "%cmd:~0,1%"=="d" set /a acc=acc-1&set okay=1
if "%cmd:~0,1%"=="s" set /a acc=acc*acc&set okay=1
if "%cmd:~0,1%"=="o" echo %acc%&set okay=1
if %okay%==0 goto start
if %acc%==256 set acc=0
if %acc%==-1 set acc=0
set cmd=%cmd:~1%
goto run

Fixed bugs:
- Changed syntax error set %acc%=... to set acc=...
- Added accumulator initialization (what if the first command will be o? - the originall will print %acc% in that case)
- Made ifs comparing the command (lines 7-10) space safe
- As mentioned in Esolangs.org article, program (but not interpreter) terminates on an invalid command instead of ignoring it
- Accepts more than one instruction per line
It interprets all test programs from Esolangs.org, but it still do not mean that there are not any bugs. If you see any, please tell me about it.


Board footer

Powered by FluxBB