views:

136

answers:

5

I've got a game in VB6 and it works great and all, but I have been toying with the idea of creating a scripting engine. Ii'm thinking I'd like VB6 to read in flat text script files for me and then lex/parse/execute them.

I have good programming experience, and I've built a simple C compiler, as well as a LOGO emulator before.

My question is: Are there any tools that I can use, like Lexx/Yakk/Bison to help me? How should I approach this problem in regards to lexing, parsing, and feeding the commands back to VB6 so I can handle them? Is this idea a BAD IDEA in the sense that there are too many obstacles in the way (For example, building minesweeper in assembly, though not impossible, is very difficult, and a bad idea.)?

+2  A: 

If you're willing to use VBScript rather than VB6 you might be able to just use the MSScriptControl to run the commands rather than creating your own. Here's an article discussing using it from a .Net app, though it's an ActiveX control so should give you quite a bit of flexibility.

The control can be downloaded from here.

ho1
I have used the ScriptControl in four projects and it works extremely well. Very easy to integrate. I wish Microsoft would have given us a replacement in .NET, and made it as easy to use.
AMissico
+1 I've used this too, it works nicely. I too wish there was an equivalent in .NET. One word of warning, be aware it's not officially supported on Vista or Windows 7. Francesco Balena wrote a nice article on using this from VB6 in the *Visual Basic Programmers Journal* November 2000 issue, unfortunately the issue doesn't seem to be available online any more.
MarkJ
- *Designing a Calculator* at http://msdn.microsoft.com/en-us/library/aa227421(VS.60).aspx (Balena may have been inspired by this topic.)
AMissico
@MarkJ: but there **is** an equivalent in .NET. Apart from the obvious fact that you can still use the scripting control, you can just compile VB code on the fly using the `VBCodeProvider`. In practice, this amounts to much the same as using the scripting control and is very powerful and easy to use. .NET 4 possibly makes this even easier by providing the DLR, a scripting runtime.
Konrad Rudolph
+2  A: 

I've actually seen some quite reasonable implementations of compilers/interpreters in VB6[1] - It's not the language I would choose (few functional features, insufficent static type system), but with experience, you can outweigh these drawbacks and be quite productive - So why not.

You can use the GOLD parser generator that supports VB6 as a start.

[1]: Somewhere on PSC or in this download repository I think ...

Note that there is the MSScriptControl too.

Dario
+3  A: 

Unless you're doing it for your own instruction, you may want to try using Lua: http://stackoverflow.com/questions/1209313/vb6-lua-integration

lhf
+3  A: 
AMissico
"Make your .Net application support scripting - a practical approach" at http://weblogs.asp.net/rosherove/articles/dotnetscripting.aspx
AMissico
+1 Fantastic list of links!
MarkJ
A: 

There also appears to be an additonal alternative for VB6:

SadScript is an variant of VB6 most prominently used for VB6 as an scripting engine in MMORPGS .

See here for more : http://stackoverflow.com/questions/1415949/what-is-sadscript-can-i-use-it-in-vb-net-why-hasnt-anyone-i-have-asked-heard-o/3017372#3017372

rlb.usa