As usually half-@§§ed but seemingly working.
calc (or set /a /A) in grub4dos is a simple calculator from left to right, pcalc.g4b adds evaluation of parenthesis (brackets) which may be useful either in more complex formulas or for not needing to re-order an expression.
No instructions, no error control (make sure that opening and closing brackets match), no frills, you need to know where your towel is, more a POC than anything else.
!BAT setlocal set string=%* :begin set string set /a counter=0 > nul set /a open=0 > nul set /a close=0 > nul set /a length=0 > nul :loop call set char=%^string:~%counter%,1% if %char%.==(. set /a open=%counter% > nul if %char%.==). set /a close=%counter% > nul set /a length=%close%-%open% > nul if %length%>=1 goto :do_math set /a counter=%counter%+1 > nul if not "%char%."=="." goto :loop set /a result=%string% endlocal && set result=%result% goto :eof :do_math set /a start=%open%+1 > nul set /a end=%close%+1 > nul set /a length=%end%-%start%-1 > nul call set between=%^string:~%start%,%length%%% call set before=%^string:~0,%open%%% call set after=%^string:~%end%%% set /a result=%between% > nul set string= %before%%%result%%%after% goto :begin goto :eof
Wonko