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
Non-Console. The #EXEC 1 flag removes the console from startup.
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).
Comments, both // 1 liners and /* */ comment blocks.
Callable user made functions using the Call command. Return values are going to be implemented aswell.
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
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
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],
};
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.
Originally Posted by chemicalNova
You've inspired me to keep going with this penagate, and for that, I thank you
..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:
Type tPosition
Top As Long
Left As Long
End Type
Type Character
Name As String
[b]Position As tPosition[/b]
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;
}
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:
Type tPosition
Top As Long
Left As Long
End Type
Type Character
Name As String
[b]Position As tPosition[/b]
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.
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?
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
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].
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.