...

View Full Version : Making your own scripting language in VB6



knightcon
08-15-2007, 09:35 PM
I am writing an application in VB6 where I want the administrator to customize certain events by scripting it into an extension file. I want to create my own scripting language, or better yet, my own programming languafe for it, where the administrator can enter various control structures (If, Then, Else, Switch, etc) as well as execute functions (email_send(), file_open(), socket_open(), etc) and perform other suck programming. I want it to closely resemble a commonly understood language like javascript in syntax alone, it will have entirely my own functions and variables, and will also need to have access to variables and configuration options set by the main application code, these variables and configuration options should be accessible as super-global arrays. Does anyone have any ideas on how I could do this or does anyone know where I can look to learn how to do this? Examples and/or website URL's would be appreciated. Thanks.

oracleguy
08-15-2007, 10:12 PM
I've never done something like that in VB6.

The first thing you'll have to do before you execute your script file is verify the syntax in it is correct. There are several ways you to approach doing this, a couple examples: a combination of regular expressions or building a DFA (http://en.wikipedia.org/wiki/Deterministic_finite_state_machine).

What you want to do is most certainly possible it just might be more difficult than you are expecting. And while you can probably do it in VB6, that choice of language might not be the best tool for the job. If the rest of the application is already in VB6, you could easily write a DLL that does all the stuff with the scripts in another language that your VB app talks to.

TheShaner
08-15-2007, 10:21 PM
No offense, but you're attempting to reinvent the wheel, no less using an inferior language like VB6. If a system administrator needs a scripting language on a Windows server, they'd just use VBScript. It has access to anything you need on Windows with similar syntax to VB6.

However, if this is still something you want to do, I would really look into .vbs scripts already out there used for system administration and see what works nicely and what doesn't. This will give you an idea on what you can improve upon this already existing scripting language.

Sorry, I don't have any resources for you, but there seems to be a freeware program that has already done what you want to do, but also took it one step farther. Take a look -> http://www.autoitscript.com/autoit3/

-Shane

oracleguy
08-15-2007, 10:27 PM
No offense, but you're attempting to reinvent the wheel

That is a point I didn't think about; TheShaner is right, unless there is a specific reason you need your own scripting language, it isn't worth doing it. And thinking about it more, it'd be kind of a (major) pain to implement the needed functionality to parse and interpret a scripting language in VB6. C++ would be a much better choice to do it in.

knightcon
08-16-2007, 02:48 AM
I don't want to make my own scripting language to interact with the server or desktop environment, I want to create my own scripting or programming language to interact with my software package only.

For example...



//This code runs when a new user account is created
BEGIN
set username as string
set name as string

//Set Permission Information
set admin as array
set user as array
set dashboard as array
set novell as array
set Administrator as array

admin = ("read"=>true, "write"=>true, "delete"=>true, "take_ownership"=>true);
user = ("read"=>true, "write"=>true, "delete"=>true, "take_ownership"=>false);
dashboard = ("read"=>true, "write"=>false, "delete"=>false, "take_ownership"=>false);

dir_create("path/to/folders/" + username);
dir_set_permissions("path/to/folders/" + username, admin);
dir_set_permissions("path/to/folders/" + username, user);
dir_set_permissions("path/to/folders/" + username, dashboard);
file_create("path/to/folders/" + username","conditions.txt");
file_edit("path/to/folders/" + username + "/conditions.txt","This file holds the conditions of use for this directory");
END


All the scripting language will do is provide a more powerful interface to customize the application. I do not want it to be executable outside of the application or on computers which don't have the application installed.

TheShaner
08-16-2007, 03:19 PM
All the scripting language will do is provide a more powerful interface to customize the application.
Ah ha! Now that makes more sense. I created a GUI application that simulated a simple processor and as input, it took in my own assembly code I developed specifically for the application. All this was written in Java.

What I first did was specify my keywords (command words) and the syntax I was going to use. I wrote it down on paper and wrote out simple, example programs that made use of my commands and syntax.

Next, based on your language model, you have to develop a parser in the language you're using. That's why both OG and I said that you may be looking at a bit of a challenge using VB6 to parse your scripting language, but it can be done as long as you keep your scripting language simple. In higher level languages, usually a program is first parsed and then compiled, but being on a simple level (like I did in my program), you'll most likely parse and compile at the same time. You may need to do two passes over your file, the first to resolve anything ahead of time before the second pass does the actual processing of the code, but this depends on what works best on the language you develop.

It will definitely be trial and error. I wish I had some resources off the top of my head, but I don't. When I created mine, I looked at some assembly languages, picked the features i liked, developed my language model, and then created my parser/compiler that executed my code.

-Shane

oracleguy
08-16-2007, 05:27 PM
When I did this before, what really helped me a long when I was writing my parser and compiler was having a context-free grammar (http://en.wikipedia.org/wiki/Context-free_grammar). That basically lays out the rules for your language. But at the very least writing out how it is going to work on paper is going to be a very useful thing.

I did it in two passes, first going through and making sure the syntax was correct by doing a lexical analysis (http://en.wikipedia.org/wiki/Lexical_analysis) (You can find more tutorials about this through google) and then the second pass is where I parsed the tokens. In my case it was more of a compiler than an interpreter because it eventually turned my language into IA-32 assembly code but instead of generating code, you'd be executing your script.

altie
08-16-2007, 07:20 PM
The wheel in this case is a general-purpose lightweight scripting language like Lua. I don't know any alternatives to Lua, but I've heard nothing but good things. There may be a dll or even VB source out there to interpret it already.

If you find that you really want to do it yourself and do it right, read up on parser and lexer generators, and compiler theory in general. The "dragon book" (http://www.amazon.com/gp/product/0321486811/) is one of the most often cited references. Also look into domain-specific languages. These are a big topic in the functional language community, of which VB6 is unfortunately not a member.

knightcon
08-17-2007, 01:32 AM
Thanks for all your help guy's, that's what i've been trying to find out. If it helps any think of my project as something similar to VBA, where it isn't used to write stand-alone applications or control the server environment it is on, rather it is used as a more advanced method of controlling the application that it is connected to. Also with what you have said will it allow me to perform if, else, switch, etc clauses and various programming structures or is it going to be scripted like HTML, no ability to pass through control structures and variable gateways.

altie
08-17-2007, 10:16 PM
It's your choice whether to include variables and control structures. Your language will obviously be simpler and less flexible without.

If you choose to develop your own language with variables and control structures, the lexer will have some extra cases. I don't think the parser will have much more to deal with. You can greatly simplify translation to the target language by making the control structures in the source language a strict subset of those in the target. For example, if you translate the source files to VB6, you already have If, While, Do, etc.

I would also strongly recommend either eliminating variables, using a single type, or ripping off a type system from an existing language. Variable typing is a whole other field that I only understand enough to know that its issues are subtle and deep.

oracleguy
08-17-2007, 11:34 PM
I would also strongly recommend either eliminating variables, using a single type, or ripping off a type system from an existing language. Variable typing is a whole other field that I only understand enough to know that its issues are subtle and deep.

I would disagree, making something strongly typed can have some good benefits. Like it reduces amount of logic you have to do when executing the code to see if a variable even has data that can be acted on. Like:



foo = "hello world"

foo2 = foo + 7

altie
08-18-2007, 12:13 AM
When I say single type, I mean one type that all operators accept and handle in a uniform way, such as treating every variable as a string.

knightcon
08-18-2007, 12:13 AM
This is all starting to warp my mind, does anyone know where I can look at a tutorial online or where I can download some VB6 source code that does the same, it doesn't need to be exactly what i'm wanting to do, just something close enough that I can use it to learn how to do what I want.

oracleguy
08-18-2007, 01:18 AM
This is all starting to warp my mind, does anyone know where I can look at a tutorial online or where I can download some VB6 source code that does the same, it doesn't need to be exactly what i'm wanting to do, just something close enough that I can use it to learn how to do what I want.

I did some Google searching but couldn't really find any code samples in VB. It just isn't a language that many people would do something like this in. (As we mentioned earlier)

Did you look at the wikipedia pages I linked to in one of my previous posts?

But the first thing you need to do is layout how the language is going to work, the variable types, if it supports user functions, how do those work? syntax wise and such. Things like that, that will be a solid first step.

knightcon
08-19-2007, 01:03 PM
I did some Google searching but couldn't really find any code samples in VB. It just isn't a language that many people would do something like this in. (As we mentioned earlier)

Did you look at the wikipedia pages I linked to in one of my previous posts?

But the first thing you need to do is layout how the language is going to work, the variable types, if it supports user functions, how do those work? syntax wise and such. Things like that, that will be a solid first step.

Yeah I did look at those links of yours but I found the information a bit confusing, that was why I was looking for examples that people have put online, I seem to be able to learn something better when I look at how someone else has done it. I'll look at the wikipedia links again and try to understand it again.

oracleguy
08-20-2007, 12:49 AM
Yeah, like I said I looked for VB code examples and couldn't find any. Are you proficient at any other programming languages? So at least you could see some code examples even if they are in another language.

knightcon
08-20-2007, 06:19 AM
Yeah, like I said I looked for VB code examples and couldn't find any. Are you proficient at any other programming languages? So at least you could see some code examples even if they are in another language.

Unfortunately not really, the only other language I can program in is PHP, i'll check out any samples in PHP, you never know, there may be something there, thanks for your help.

TheShaner
08-20-2007, 03:35 PM
I can guarantee you now that you will not find any examples in PHP. PHP is a language used for web development. It has no reason to be used to create a parser/compiler. Yes, I did say that people do use it occasionally as a scripting language, but that's about as far as PHP will be used in non-web development.

-Shane



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum