Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Page 1 of 2 12 LastLast
Results 1 to 15 of 18
  1. #1
    Regular Coder
    Join Date
    Apr 2007
    Location
    Griffith. Australia
    Posts
    138
    Thanks
    4
    Thanked 4 Times in 4 Posts

    Question Making your own scripting language in VB6

    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.

  • #2
    Rockstar Coder
    Join Date
    Jun 2002
    Location
    USA
    Posts
    9,074
    Thanks
    1
    Thanked 328 Times in 324 Posts
    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.

    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.
    OracleGuy

  • #3
    Senior Coder TheShaner's Avatar
    Join Date
    Sep 2005
    Location
    Orlando, FL
    Posts
    1,126
    Thanks
    2
    Thanked 40 Times in 40 Posts
    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

  • #4
    Rockstar Coder
    Join Date
    Jun 2002
    Location
    USA
    Posts
    9,074
    Thanks
    1
    Thanked 328 Times in 324 Posts
    Quote Originally Posted by TheShaner View Post
    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.
    OracleGuy

  • #5
    Regular Coder
    Join Date
    Apr 2007
    Location
    Griffith. Australia
    Posts
    138
    Thanks
    4
    Thanked 4 Times in 4 Posts
    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...

    Code:
    //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.

  • #6
    Senior Coder TheShaner's Avatar
    Join Date
    Sep 2005
    Location
    Orlando, FL
    Posts
    1,126
    Thanks
    2
    Thanked 40 Times in 40 Posts
    Quote Originally Posted by knightcon View Post
    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

  • #7
    Rockstar Coder
    Join Date
    Jun 2002
    Location
    USA
    Posts
    9,074
    Thanks
    1
    Thanked 328 Times in 324 Posts
    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. 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 (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.
    OracleGuy

  • #8
    New Coder
    Join Date
    Aug 2007
    Posts
    13
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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.

  • #9
    Regular Coder
    Join Date
    Apr 2007
    Location
    Griffith. Australia
    Posts
    138
    Thanks
    4
    Thanked 4 Times in 4 Posts
    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.

  • #10
    New Coder
    Join Date
    Aug 2007
    Posts
    13
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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.

  • #11
    Rockstar Coder
    Join Date
    Jun 2002
    Location
    USA
    Posts
    9,074
    Thanks
    1
    Thanked 328 Times in 324 Posts
    Quote Originally Posted by altie View Post
    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:

    Code:
    foo = "hello world"
    
    foo2 = foo + 7
    OracleGuy

  • #12
    New Coder
    Join Date
    Aug 2007
    Posts
    13
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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.

  • #13
    Regular Coder
    Join Date
    Apr 2007
    Location
    Griffith. Australia
    Posts
    138
    Thanks
    4
    Thanked 4 Times in 4 Posts
    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.

  • #14
    Rockstar Coder
    Join Date
    Jun 2002
    Location
    USA
    Posts
    9,074
    Thanks
    1
    Thanked 328 Times in 324 Posts
    Quote Originally Posted by knightcon View Post
    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.
    OracleGuy

  • #15
    Regular Coder
    Join Date
    Apr 2007
    Location
    Griffith. Australia
    Posts
    138
    Thanks
    4
    Thanked 4 Times in 4 Posts
    Quote Originally Posted by oracleguy View Post
    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.


  •  
    Page 1 of 2 12 LastLast

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •