0

I am just find magic of batch and have a idea that if I could make a stack system,then I would be able to make something into assembly like function.

but there`s a problem,I don`t know part of my code how to implement,it is dereference

:pop
    set zpop=%zstack%zbase%% ::this line should be interpret twice
    set zstack%zbase%=
    set /A zbase=%zbase%-1
    set
    goto start

yes,that line is necessary to be interpret more than once, and I think this problem is important because if I have a ability to dereference twice, I would be able to dereference any value for any countable time I want if it is existed.

below is in case of a need of full code shown:

setlocal EnableDelayedExpansion

:start
set zgoto=start


REM given a target label
set /P target=


if %target%==push (
    REM given a push value
    set /P zpush=
)


goto %target%




    :constructor
        set zpush=start
        set /A zbase=0
        set zstack%zbase%=start
        set
        goto start

    :destructor
        for /L %num in (%zbase%,-1,0) do (
        set zstack%num%=
        )
        set zbase=
        set
        goto start

    :push
        set /A zbase=%zbase%+1
        set zstack%zbase%=%zpush%
        set
        goto %zgoto%
    :pop
        set zpop=%zstack%zbase%%
        set zstack%zbase%=
        set /A zbase=%zbase%-1
        set
        goto start ::change to "goto %zpop%" after this is complete
:end
pause
endlocal
exit




REM call:
:: set zpush=label_name_after_these_line
:: set zgoto=function_name
:: goto push

REM ret:
:: goto pop
AiDSl
  • 25
  • 6
  • 3
    You are looking for the `For` Command, `For /?` in cmd to get usage, and Delayed Expansion [See this question for more](https://stackoverflow.com/questions/10166386/arrays-linked-lists-and-other-data-structures-in-cmd-exe-batch-script) – T3RR0R Jun 02 '20 at 23:25
  • 1
    This `%zstack%zbase%%` is not doing what you think it is doing. That is not how you reference a pseudo array variable. – Squashman Jun 03 '20 at 04:57
  • 1
    The command line `set zpop=%zstack%zbase%%` should read `call set zpop=%%zstack%zbase%%%`; `call` introduces another parsing phase, so, assuming `zbase` is `1`, firstly it is parsed to `call set zpop=%zstack1%` (since `%%` are interpreted as one literal `%`), and secondly `zstack1` becomes expanded… – aschipfl Jun 03 '20 at 10:41

0 Answers0