New games every week!
JSE - The Triad
25th April 2021  
Definitely going to have to cut out a huge chunk of code, I reckon.


The lexer and parser both seem to be doing their parts well enough, but once the third section of code gets going, it's tying itself up in knots.
I think the main issue is my reliance on two variables to account for everything within a line of code.
One part says which parameter the value/variable/command/etc belongs to, and the other part says which part of the stack that parameter is part of.
For most simple things that works fine, but as soon as you start asking for more complex things, like printing random numbers based on sines of random numbers based on milliseconds, then having just two variables to keep track of that really isn't enough.

I've backed up what I have and will today be going DELETE on a huge swath of code, and rewriting a ton of it.
Not going to be easy, seeing the entire project take several leaps back in time, but as with all things, it's better to do this now than to have to deal with it later.


More Complex

What I'm writing is a sort of mini-compiler, turning the whole thing into a set of simple single commands, which can be parsed easily by javascript during runtime.

It's currently taking something like this..
Print "Hello World "+Rand(1,100)
and turning it into..
[0] _s01="Hello World "
[1] _v0100=n1
[2] _v0101=n100
[3] _v0000=i_s1
[4] _v0001=iRand_xb01
[5] _v0002=m+
[6] iPrint
Hello World is stored as string 1.
The number 1 is stored as value 0 of set 1. 100 is stored as value 1 of set 1.
For set 0, the 0'th value becomes the string, and then at 0,1 the result of the command Rand based on the values of set 1 (which are, of course, 1 and 100)
Then a plus is called for set 0, which takes value 0, and the previous value (0 = String, 1 = Rand result) adds them together, then places the result back into value 0.
Maths commands always place their values back at value 0 of their set, which acts as the accumulator for anything going on.

Note that Strings can be added to, subtracted from ("Armless"-"les" = "Arms") or multiplied ("Arm"*3 = "ArmArmArm")
I'm eventually going to add divide, too, to act like Split/Explode, but that first needs variables so that the result can be placed into an array..

Finally a simple Print is called, (without a specific set thereby defaulting to set 0) which will take the result of our "maths", adding together the string and the value, then place it at the current CursorX and CursorY value. (Reminder to self : You need to add a Locate command!)

This works perfectly fine.. It really does!! But once you start adding sub-stacks, it all starts to break up, simply because I'm just not giving myself enough values to work with.
Print Rand(Rand(1,4)) works, but Print Rand(9,Rand(1,4)+10) doesn't, as it starts to get the parameters confused.

Two variables just aren't enough to keep control of all this.
So, a redux..
Scrap a whole chunk of code, and rewrite it with three variables in mind.
Stack, Parameter, and .. let's call it SubStack Parameter, or something.

Big job ahead.

Views 54, Upvotes 1
Daily Blog , Jse
New games every week!
Site credits : Jayenkai put all his heart and soul into everything you can see on this site.
(c) Jayenkai 2017 and onwards, site design Rychan. RSS feed
Blog - JSE - The Triad - AGameAWeek