math.cmd: a math expression parser written in native WinNT batch script

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Message
Author
CirothUngol
Posts: 46
Joined: 13 Sep 2017 18:37

Re: math.cmd: a math expression parser written in native WinNT batch script

#16 Post by CirothUngol » 21 Sep 2017 23:46

Compo wrote:Version 2.1 from December 2016!
Got it, Thanks!
...pastebin, huh? Seems convenient for larger scripts, I'll have to remember that. ^_^

Ha! It's news-guy Brian Williams... but no of course (unless it is?). You can view the original scripts here. Short, simple, integer-only Add, Multiply, and Compare... good stuff.

*1 hour later*
I just read through Judago's whole script, lots of stuff we do almost exactly the same. His procedures are shorter, but spend much more time in loops. The script divides using multiple subtraction, and he's using '1s borrow' style subtraction (the hard way, look for 'Austrian subtraction'... you'll never do it the other way again). He stopped where I was originally going to, just consider everything between :math_bas and :math_fnc as a unit, and it's essentially the same, and could be used as such (:math_bas num1|numVar1 num2|numVar2 opCode [returnVar]), I only decided to add the parser after seeing the pseudo-code for 'shunting yard' and it looked fairly easy to implement. I should set up a timing test... there's probably a thread about timing scripts here, right (maybe even with pre-made scripts)?

I'm looking into creating separate macro versions of the main functions (+-*/^) to see if it's possible to eliminate all of the CALLs... for fun, really. It spends so much time in loops that I don't see it really speeding things up much, but it might be nice to be able to insert a division or multiplication directly in a script where it's needed. Which brings a question...

Is there a practical limit to the size of a code block in batch scripts? I understand the 8192 limit for strings (8191?) so the macros can't exceed that, but how about the actual code block (everything inside the outer-most set of parenthesis)... as I understand it the whole thing is parsed at once (which is why %var% remains static) and if I install macros into the parser that thing's gonna get HUGE!

Anyhow, little update to v0.2. Thanks for the links guys, looks like I have some fun reading to do.

Squashman
Expert
Posts: 4465
Joined: 23 Dec 2011 13:59

Re: math.cmd: a math expression parser written in native WinNT batch script

#17 Post by Squashman » 22 Sep 2017 10:34

CirothUngol wrote:I should set up a timing test... there's probably a thread about timing scripts here, right (maybe even with pre-made scripts)?

viewtopic.php?f=3&t=7523&p=49958#p50908

einstein1969
Expert
Posts: 941
Joined: 15 Jun 2012 13:16
Location: Italy, Rome

Re: math.cmd: a math expression parser written in native WinNT batch script

#18 Post by einstein1969 » 01 Oct 2017 08:48

simple code for elpsed milliseconds:

Code: Select all

  setlocal EnableDelayedExpansion
 
  set t0=!time!
  math .....
  set t1=!time!

  for /F "tokens=1-8 delims=:.," %%a in ("!t0: =0!:!t1: =0!") do set /a "a=(((1%%e-1%%a)*60)+1%%f-1%%b)*6000+1%%g%%h-1%%c%%d, a+=(a>>31) & 8640000, a*=10"

  echo start at !t0!, stop at !t1! , elapsed !a! ms


einstein1969

Post Reply