PDA

View Full Version : BCScript


BC_Programming
01-08-2009, 05:15 PM
had to put this somewhere-

After finally fixing a few show-stopping bugs in my expression evaluation library, I realized that I could actually use it as the engine for a Custom script language.

In it's first iteration, code such as this:

STORE(X,50);
BCSH@WriteLn("WRITTEN!" + X);



would output:

BASeCamp Commandline BCScript Interpreter.
Copyright 2008-2009 BASeCamp Corporation. All rights reserved.
WRITTEN!50
***Script terminated.***


Which is actually kind of a surprise to me even, since adding the Semicolon as a "statement separator" was a after-thought.

The question will inevitably arise, "what does this language have that VBS or JScript don't?"

quite simple.

intrinsic support for arrays and operations on them. For example, the engine let's you directly specify an array:


STORE(X,{1,2,3,4,5});
BCSH@WriteLn(X);

will store a five element array in X, and then display it. It will be displayed as "{1,2,3,4,5}", which is exactly the same as the way it was input. More amazing, Operations can be performed directly on the array that in other languages would require a loop to perform:


STORE(X,{1,2,3,4,5});
STORE(Y,{5,6,2,4,1});
STORE(Z,(X+Y)*(X-Y));
BCSH@WriteLn("Z=");
BCSH@WriteLn(X);
BCSH@WriteLn(Z);


the output- quite extensive. See, by default, the operations are not scalar on arrays, but rather iterative. For example, {1,2}*{3,4} will be another two elements array, but get this: both items will themselves be arrays, facilitating a matrix: {{1*3,1*4},{2*3,2*4}}


BASeCamp Commandline BCScript Interpreter.
Copyright 2008-2009 BASeCamp Corporation. All rights reserved.
"Z="
{1,2,3,4,5}
{{{{-24,-30,-6,-18,0},{-28,-35,-7,-21,0},{-12,-15,-3,-9,0},{-20,-25,-5,-15,0},{-
8,-10,-2,-6,0}},{{-18,-24,0,-12,6},{-21,-28,0,-14,7},{-9,-12,0,-6,3},{-15,-20,0,
-10,5},{-6,-8,0,-4,2}},{{-12,-18,6,-6,12},{-14,-21,7,-7,14},{-6,-9,3,-3,6},{-10,
-15,5,-5,10},{-4,-6,2,-2,4}},{{-6,-12,12,0,18},{-7,-14,14,0,21},{-3,-6,6,0,9},{-
5,-10,10,0,15},{-2,-4,4,0,6}},{{0,-6,18,6,24},{0,-7,21,7,28},{0,-3,9,3,12},{0,-5
,15,5,20},{0,-2,6,2,8}}},{{{-28,-35,-7,-21,0},{-32,-40,-8,-24,0},{-16,-20,-4,-12
,0},{-24,-30,-6,-18,0},{-12,-15,-3,-9,0}},{{-21,-28,0,-14,7},{-24,-32,0,-16,8},{
-12,-16,0,-8,4},{-18,-24,0,-12,6},{-9,-12,0,-6,3}},{{-14,-21,7,-7,14},{-16,-24,8
,-8,16},{-8,-12,4,-4,8},{-12,-18,6,-6,12},{-6,-9,3,-3,6}},{{-7,-14,14,0,21},{-8,
-16,16,0,24},{-4,-8,8,0,12},{-6,-12,12,0,18},{-3,-6,6,0,9}},{{0,-7,21,7,28},{0,-
8,24,8,32},{0,-4,12,4,16},{0,-6,18,6,24},{0,-3,9,3,12}}},{{{-32,-40,-8,-24,0},{-
36,-45,-9,-27,0},{-20,-25,-5,-15,0},{-28,-35,-7,-21,0},{-16,-20,-4,-12,0}},{{-24
,-32,0,-16,8},{-27,-36,0,-18,9},{-15,-20,0,-10,5},{-21,-28,0,-14,7},{-12,-16,0,-
8,4}},{{-16,-24,8,-8,16},{-18,-27,9,-9,18},{-10,-15,5,-5,10},{-14,-21,7,-7,14},{
-8,-12,4,-4,8}},{{-8,-16,16,0,24},{-9,-18,18,0,27},{-5,-10,10,0,15},{-7,-14,14,0
,21},{-4,-8,8,0,12}},{{0,-8,24,8,32},{0,-9,27,9,36},{0,-5,15,5,20},{0,-7,21,7,28
},{0,-4,12,4,16}}},{{{-36,-45,-9,-27,0},{-40,-50,-10,-30,0},{-24,-30,-6,-18,0},{
-32,-40,-8,-24,0},{-20,-25,-5,-15,0}},{{-27,-36,0,-18,9},{-30,-40,0,-20,10},{-18
,-24,0,-12,6},{-24,-32,0,-16,8},{-15,-20,0,-10,5}},{{-18,-27,9,-9,18},{-20,-30,1
0,-10,20},{-12,-18,6,-6,12},{-16,-24,8,-8,16},{-10,-15,5,-5,10}},{{-9,-18,18,0,2
7},{-10,-20,20,0,30},{-6,-12,12,0,18},{-8,-16,16,0,24},{-5,-10,10,0,15}},{{0,-9,
27,9,36},{0,-10,30,10,40},{0,-6,18,6,24},{0,-8,24,8,32},{0,-5,15,5,20}}},{{{-40,
-50,-10,-30,0},{-44,-55,-11,-33,0},{-28,-35,-7,-21,0},{-36,-45,-9,-27,0},{-24,-3
0,-6,-18,0}},{{-30,-40,0,-20,10},{-33,-44,0,-22,11},{-21,-28,0,-14,7},{-27,-36,0
,-18,9},{-18,-24,0,-12,6}},{{-20,-30,10,-10,20},{-22,-33,11,-11,22},{-14,-21,7,-
7,14},{-18,-27,9,-9,18},{-12,-18,6,-6,12}},{{-10,-20,20,0,30},{-11,-22,22,0,33},
{-7,-14,14,0,21},{-9,-18,18,0,27},{-6,-12,12,0,18}},{{0,-10,30,10,40},{0,-11,33,
11,44},{0,-7,21,7,28},{0,-9,27,9,36},{0,-6,18,6,24}}}}
***Script terminated.***



It represents quite a lot of hard work with my parser, but now I can finally reap the benefits.

for example: BCScript took less then a day to construct; a few lines of code to initialize the parser, add the BCSH object to the Parser, load the file, basic stuff.

My weak point has always been distribution of my programs, they are so dependent on other components, and I always forget something. I'll see if I can create a Installer for it so anybody interested can try out it's capabilities. While I'm at it I might need to document the extensive feature set.

But it'll take a while for an installer. Last thing I want is to fill people's registries with the CLSID's of my components and have no real way of uninstalling them. So I'll have to do my own bench testing with any installer I create.

Once I figure out how, it will be integrated with CScript and WScript as a ActiveX Scripting Host Engine.

And the := operator is SUPPOSED to be working as an Assignment operator, but I'm having problems with that for some reason. Probably related to me having both a = and a : operator as well.

BC_Programming
02-03-2009, 04:33 PM
Alright! After over 6 hours of messing around with an installer, tweaking the code of the script interpreter to be a bit more portable and bullet-proof, I have finally managed to get it working on another machine right after the install (LOL).


Right now- it has been tested and worked on Windows 98,Windows XP, and Windows Vista (Windows vista's Security settings required a few changes to where I put the two sample scripts I included).

Please don't install it on an important machine. I did, and didn't have any ill effects, but I'd rather not cause any problems on anybody's machine, so I recommend, if possible, running it within a VM. (Really this is just me erring on the side of caution. The uninstaller seems to work fine, and deletes all the proper registry keys as well, so basically I'm saying- please don't yell at me if it messes anything up...


Download:

http://uploading.com/files/C23R87HZ/BASeparserXP.zip.html


I don't know how long the link will last...


How to use

Obviously- after the installer has run, it doesn't create any Icons or anything similar, which is kind of confusing I know (I have a GUI evaluator program that uses it, but frankly it sucks).

Instead- the installer places the BCScript.exe interpreter program in your windows directory, which allows it to be run anywhere. To run a Script, just run the command "BCScript scriptfile.bcs" preferably from the command-line so you can see the output.

Script Files

The two script files listed in my previous post reflect the same content as the two that I include. They are installed to the "My Documents" (XP) or "Document" (Vista) Folders, under a subfolder called "BCScripts". To give the Script Engine a whirl, run cmd (if it doesn't work at first, try again and run cmd as administrator. I'm currently in the process of getting it to work more smoothly with Vista,UAC and the increased security), navigate to the BCScripts Folder within the documents folder, and run the command

BCScript testscript.bcs


for a little test app. If it works, there should be a line in that output reading "WRITTEN!". If not- the installation likely failed and I wasted 5 hours :skeptical2:, because I was fighting with a similar failure when attempting to install on my Vista laptop.

*NOTES*

Right now, it's a lot slower then it could be, since the installer, while installing both debug and release versions of the parser, registers the debug version (which writes a large amount of debug data to a "Debug" folder in the same folder as that which holds "BASeParser.dll". (you can safely delete this data, it won't hurt anything). If you are willing to try- feel free to unregister the BASeParserDebug.dll library in the Debug Folder and instead register BASeParser.dll itself. If you encounter a problem using it, the debug version should have the same error, so if you like run the debug version, cause the error and then you can show me the debug logs and I can try to figure out what's going on.


Thanks to anybody who tries it out, it's a work in progress, but it's coming to fruition relatively quickly (given the time I've spent on it, that is).


Used Libraries

The Script Interpreter uses my BCCParser.dll CommandLine Parsing component and the BASeParser Library. all calls are late-bound calls using Objects, and proper errors are shown for errors creating the two main objects. BASeParser itself uses MSXML 3 for parsing of it's "Function Information" XML files (honestly, a dubious feature, but it's a bit late to remove it).

Using in your own applications

As of yet I have not provided any documentation or even sample code for using the BASeParser DLL in your own projects- If anybody is interested in using it in their own projects feel free to experiment- If enough people show interest in having some documentation- I might work a bit harder on making some. :spinny: