Results 1 to 10 of 10

Thread: My Scripting Language

  1. #1

    Thread Starter
    G&G Moderator chemicalNova's Avatar
    Join Date
    Jun 2002
    Location
    Victoria, Australia
    Posts
    4,246

    My Scripting Language

    Howdy all,

    I wasn't sure where to put this, so Moderators, please move it if required It IS written in VB6.

    I'm just posting this here, because I want a few of you to possibly come up with some more types.

    My Scripting language (at present) is called CScript. Right now, its pretty basic, but it has the following features:
    • 3 Default types. Byte, Long and String (no error reporting for their values yet, but there will be). Public and Private variables (to an extent). Variables declared within #DECL and #EDECL are public, usable anywhere. Variables declared within a function, are only usable in that function (error reporting for this still to come also).
    • Console
    • cout() function for output to console
    • cin() function for user input (not the best yet, will get better)
    • PHP style variable output. cout("$variablename") prints the value of a variable to the console
  2. Non-Console. The #EXEC 1 flag removes the console from startup.
  3. UDT's. This is what I want you guys to create. I'll give you an example of a script below, which shows an Information and OKOnly messagebox:
    Code:
    #EXEC 1
    
    #DECL
    typedef MessageBox_t
    {
    	long MB_OK=0,
    	long MB_OKCANCEL=1,
    	long MB_ABORTRETRYIGNORE=2,
    	long MB_YESNOCANCEL=3,
    	long MB_YESNO=4,
    	long MB_RETRYCANCEL=5,
    	long MB_NO=6,
    	long MB_INFORMATION=64,
    	long MB_CRITICAL=16,
    	long MB_EXCLAMATION=48
    }
    var MessageBox_t MessageBox;
    #EDECL
    
    void main()
    {
    	MessageBox("Basic MessageBox", MessageBox.MB_OK + MessageBox.MB_INFORMATION, "Title");
    	ExitProcess;
    }
    I want you guys to write some other types which can be in the basic include file, added to every script (so they are kinda global).
  4. Comments, both // 1 liners and /* */ comment blocks.
  5. Callable user made functions using the Call command. Return values are going to be implemented aswell.


  6. I plan on using the API to create controls (including windows) instead of using a control array and creating a new instance of an already existing form. I figure it'd be less of a drag on memory if I did it this way.

    I've attached the source to the parser. If you guys want to improve on it, give me suggestions, or compliments up to this point, please do

    chem
Attached Files Attached Files

Visual Studio 6, Visual Studio.NET 2005, MASM

  • #2
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    Re: My Scripting Language

    Can you clarify the difference between an Enum and a struct? That looks like an enum to me. or do you declare a struct using typedef struct?

  • #3

    Thread Starter
    G&G Moderator chemicalNova's Avatar
    Join Date
    Jun 2002
    Location
    Victoria, Australia
    Posts
    4,246

    Re: My Scripting Language

    Hey, I've spent 3 days on this with greater success than I thought I would up to this point. At the moment, it defaults to an enum (mainly because I haven't added the variable assignment yet (outside of the default value)).

    I just wanted a bit of feedback concerning the idea, possibly some suggestions on global types, etc.

    I'm a bit tired now. If something isn't clear, I'll be able to explain it better tomorrow

    chem

    Visual Studio 6, Visual Studio.NET 2005, MASM

  • #4
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    Re: My Scripting Language

    Suggestion: A Win API header file parser that converts types and API declares to your script language syntax, for use as include files

    have I got the idea:
    Code:
    typedef struct OSVERSIONINFO {
        long dwOSVersionInfoSize,
        long dwMajorVersion,
        long dwMinorVersion,
        long dwBuildNumber,
        long dwPlatformId,
        char szCSDVersion[128],
    };
    ?

  • #5

    Thread Starter
    G&G Moderator chemicalNova's Avatar
    Join Date
    Jun 2002
    Location
    Victoria, Australia
    Posts
    4,246

    Re: My Scripting Language

    Hey, that isn't a bad idea Although, it would take forever, some of them are

    Tomorrow, I'll start working on variable assignments, then I can create a proper typedef syntax (enum, struct, and possibly union ).

    Another idea I had, was to use LoadLibrary and FreeLibrary so the API can be used.
    Code:
    dlopen("user32");
    _api InvalidateRect([rect type here]);
    dlclose("user32");


    You've inspired me to keep going with this penagate, and for that, I thank you

    chem

    Visual Studio 6, Visual Studio.NET 2005, MASM

  • #6
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    Re: My Scripting Language

    Quote Originally Posted by chemicalNova
    Another idea I had, was to use LoadLibrary and FreeLibrary so the API can be used.
    Code:
    dlopen("user32");
    _api InvalidateRect([rect type here]);
    dlclose("user32");
    I haven't looked at your parser yet, will tommorow (you can probably guess the time in Adelaide right now, half hour diff) but that is an idea. The trouble you have then is calling it. The only way I have seen so far is to use CallWindowProc but that forces you to pass 4 Long parameters.

    Quote Originally Posted by chemicalNova
    You've inspired me to keep going with this penagate, and for that, I thank you
    Always like to see interesting projects

  • #7

    Thread Starter
    G&G Moderator chemicalNova's Avatar
    Join Date
    Jun 2002
    Location
    Victoria, Australia
    Posts
    4,246

    Re: My Scripting Language

    I think this might be best moved to the Project Communications area.

    I've got variable assignments happening. So a script like this:
    Code:
    void main()
    {
    	var string myString;
    	myString = "Hello World!";
    	MessageBox.MB_OKCANCEL = MessageBox.MB_RETRYCANCEL;
    	MessageBox(myString, MessageBox.MB_OKCANCEL + MessageBox.MB_EXCLAMATION, "Test");
    	ExitProcess;
    }
    ..will work. myString contains no string until the next line. I'll get Enums and Structs working, then I'll attach the updated code. I plan on have unions aswell. For an example of this in VB, its having a type with another type declared in it:
    VB Code:
    1. Type tPosition
    2.     Top As Long
    3.     Left As Long
    4. End Type
    5.  
    6. Type Character
    7.     Name As String
    8.     [b]Position As tPosition[/b]
    9. End Type
    Also on the agenda: classes. This will take alot longer than the above, but it will happen Then we could use this:
    Code:
    var class MyClass
    {
        var long MyNum=0;
        void Add(var long num1, var long num2)
        {
             return (num1+num2);
        }
    }
    
    void main()
    {
        var MyClass this;
        this.myNum = 4;
        MessageBox(this.Add(this.MyNum, 4), MessageBox.MB_OK, "Equals");
        ExitProcess;
    }
    Suggestions are welcome

    chem

    Visual Studio 6, Visual Studio.NET 2005, MASM

  • #8
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649

    Re: My Scripting Language

    Quote Originally Posted by chemicalNova
    I plan on have unions aswell. For an example of this in VB, its having a type with another type declared in it:
    VB Code:
    1. Type tPosition
    2.     Top As Long
    3.     Left As Long
    4. End Type
    5.  
    6. Type Character
    7.     Name As String
    8.     [b]Position As tPosition[/b]
    9. End Type
    I think you've misunderstood what a union is. It's kind of like a struct but can at any one time contain only one of it's members in memory.

    Take this C example:
    Code:
    union MyUnion
    {
        int i;
        char ch;
    }
    
    void main()
    {
        union MyUnion uni; //declaration of a union variable
        uni.i = 27; //assignment to one of the union members
        uni.ch = 'A'; //another assignment
        printf("%d", uni.i); //syntax error! The i member has been overwritten
    }
    The above code would probably cause an error or a very unsuspected result. Since the union can only hold one of the members in memory at one time, assigning a value to the ch member will overwrite the memory used by the i member.

  • #9
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    Re: My Scripting Language

    Can you get rid of the "var" keyword? It seems a bit unnecessary seeing as whenever you declare a type in C it follows the syntax [Typename] [Varname] anyway.

    Also, what about one-line declaration and assignment? e.g.
    Code:
    string MyString = "Hello World!";
    and how does class instantiation work?
    Code:
    MyClass this = new MyClass;
    // or
    MyClass this;  // gets instantiated here?

  • #10

    Thread Starter
    G&G Moderator chemicalNova's Avatar
    Join Date
    Jun 2002
    Location
    Victoria, Australia
    Posts
    4,246

    Re: My Scripting Language

    Quote Originally Posted by Joacim Andersson
    I think you've misunderstood what a union is. It's kind of like a struct but can at any one time contain only one of it's members in memory.

    Take this C example:
    Code:
    union MyUnion
    {
        int i;
        char ch;
    }
    
    void main()
    {
        union MyUnion uni; //declaration of a union variable
        uni.i = 27; //assignment to one of the union members
        uni.ch = 'A'; //another assignment
        printf("%d", uni.i); //syntax error! The i member has been overwritten
    }
    The above code would probably cause an error or a very unsuspected result. Since the union can only hold one of the members in memory at one time, assigning a value to the ch member will overwrite the memory used by the i member.
    Crickey. *gets old C++ books from shelf*. Think its best I read up on those, again. Ta Joacim

    Quote Originally Posted by penagate
    Can you get rid of the "var" keyword?
    It just makes parsing it alot easier Maybe soon I'll just make it [type][varname].
    Quote Originally Posted by penagate
    and how does class instantiation work?
    I think I'll end up making it..
    Code:
    MyClass this = new MyClass;
    I kinda wanted it to be different from C/C++, so I don't want it too much like them.

    Ta for the input guys

    chem

    Visual Studio 6, Visual Studio.NET 2005, MASM

  • Posting Permissions

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



    Click Here to Expand Forum to Full Width