I am interested in creating a scripting language. I only want to do it for fun and if all goes well maybe use it for future projects. I understand some of the elements that make a scripting language possible like parsing and translators , but I don't really know how it all should work. Does anyone have any links to tutorials or websites that give information about creating a scripting language? Thanks for the help!
Creating a Scripting Language
Miscellaneous Forums/General Discussion/Creating a Scripting Language Only having given it a few seconds thought, you'll need to consider the following: -
A tokeniser: translates your program into a binary format. e.g. "Let A = 1" will convert to a string of bytes where "Let" becomes a certain value.
Stacks: To implement possibly recursive scripts. Also, a stack can be used as the single point of data storage from within scripts, if you so desire.
My advice would be to perhaps come up with something like LOGO. I did this back in the days of AMOS on the Amiga. As I recall, it was quite an easy task.
A tokeniser: translates your program into a binary format. e.g. "Let A = 1" will convert to a string of bytes where "Let" becomes a certain value.
Stacks: To implement possibly recursive scripts. Also, a stack can be used as the single point of data storage from within scripts, if you so desire.
My advice would be to perhaps come up with something like LOGO. I did this back in the days of AMOS on the Amiga. As I recall, it was quite an easy task.
there's a pretty good text on making a recursive decent parser by Jack W Crenshaw kicking around on the net. It's a little old, but it's straightforward and free. (It's in pascal, but easily translatable).
*EDIT*
in fact, here it is
*EDIT*
in fact, here it is
Consider a state machine where you have commands that set state like setting the current color or the current output etc, as then you can do things pretty procedurally.
If you're new to writing a language you might want to start with something similar to lisp since it is mostly syntaxless. All you have to do is read in s-expressions and figure out how to Evaluate( ) it. But for all that, you get dynamic typing, ability to modify code/macros (code that writes code at runtime) etc.
I wrote one recently that could execute the code at the end of this post (it calculates x^y). You could write game scripts that are event based with a system like that... say:
Then from your game you can just do:
The only hard thing about creating a lisp interpreter is getting your head around when to bind anything, or what to do when you stray from the purely functional path (which will get tricky fast). Oh, and it won't be fast! But more than fast enough for simple in game scripts. Maybe 1/10th to 1/100th the speed of blitzmax code depending on what you're doing.
I wrote one recently that could execute the code at the end of this post (it calculates x^y). You could write game scripts that are event based with a system like that... say:
(defun playergun player (if (= player Michael) biggun smallgun ) )
Then from your game you can just do:
PlayerGun$ = Execute( "playergun", PlayerName$ )
The only hard thing about creating a lisp interpreter is getting your head around when to bind anything, or what to do when you stray from the purely functional path (which will get tricky fast). Oh, and it won't be fast! But more than fast enough for simple in game scripts. Maybe 1/10th to 1/100th the speed of blitzmax code depending on what you're doing.
(defun exp x (_exp x 1 1 1)) (defun _exp x accumx accumf n (if (= n 100) 0 (+ (/ accumx accumf) (_exp x (* x accumx) (* accumf n) (+ n 1)) ) ) ) (defun ln x (if (> x 2) (+ 0.693147 (ln ((/ x 2)))) (_ln ((- x 1))) ) ) (defun _ln x (__ln x x 1 1)) (defun __ln x accumx divide neg (if (= divide 100) 0 (+ (* (/ accumx divide) neg) (__ln x (* x accumx) (+ divide 1) (* neg -1)) ) ) ) (defun pow x y (exp ((* y (ln x)))) ) (round ((pow 10 2))) (pow 2 3) (exp 2.72) (exp (ln 100))
danielwooden
I had fun and learned a lot about programming in developing BlitzScript3D which was based on Mark Sibly's Basic Compiler code. It was a very challenging project.
I would recommend you determine if the scripting language is to be interpreted on the fly or compiled. The route you take will effect the entire design of your scripting engine.
I had fun and learned a lot about programming in developing BlitzScript3D which was based on Mark Sibly's Basic Compiler code. It was a very challenging project.
I would recommend you determine if the scripting language is to be interpreted on the fly or compiled. The route you take will effect the entire design of your scripting engine.
Here's a trick to be able to create exe's. You make the interpreter exe read the code from the end of its own exe. The compiler has pasted all the code in encrypted form after all the normal binary stuff in the executable file. I made couple scripting languages this way.
[url]http://mythofguera.com/nawi/blitz/nawibasic.PNG[/url]
Just copy this url to browser, I'm too lazy to read about codes again.
[url]http://mythofguera.com/nawi/blitz/nawibasic.PNG[/url]
Just copy this url to browser, I'm too lazy to read about codes again.