Skip to main content
gamedev.net
🔒 Locked

Simple Scripting Engine

Started by Dismantler Aug 15, 2001 at 9:29 AM 5 replies 1.6k views
Original Post
Dismantler
Dismantler
I''ve noticed in the game programming forums, almost everyone refers to the flip code scripting engine tutorials. However, I think that it''s too powerful for something I need (possibly others need too). So if anyone could write something simple enough for the advanced beginner to understand, I would be more than happy. Thanks.
Kylotan
Kylotan
I''ve also remarked in the past that the Flipcode tutorial is actually very vague when it comes to using the tools they describe. The tools they want are perfectly suited to producing simple scripting languages as well as complex ones, but they are hard to use and understand.

What programming language are you hoping to use? C, C++? Maybe it''s time for my first GameDev article.
vissing
vissing
Yes, I think this is a great idea, I could also use some info about a simple Script Engine that i can hookup to C and C++.

If you would write an article that would be cool.

-Vissing-
Dog_Food
Dog_Food
look on the internet for bison and flex. bison comes with some examples of simple scripting tools like calculators. the syntax and such can look unwieldy at first, but you can just copy the examples without worry of underlying concepts. If you are really into scripting languages I suggest reading the java virtual machine specification, somewhere at java.sun.com, and the small language manual appendix which has much information about fast language design.
If you want the simplest language possible, just do some simple string parsing.

ie (this is your script)
display opengl
width 640
height 480

(this is your parser)

char* firstpart = strtok( string, " ");
char* secondpart = strtokn( null, " ");
if (strcmp(firstpart, "display") == 0)
setdisplay(secondpart);
else if (strcmpy(firstpart,"width") == 0)
setwidth( atoi( secondpart, number, 10));
else if (strcmpy(firstpart,"height") == 0)
setheight( atoi( secondpart, number, 10));


Edited by - Dog_Food on August 17, 2001 7:33:05 PM
Kylotan
Kylotan
quote:
Original post by Dog_Food
look on the internet for bison and flex. bison comes with some examples of simple scripting tools like calculators. the syntax and such can look unwieldy at first, but you can just copy the examples without worry of underlying concepts.

And if you want to do anything other than what is in the examples, the documentation is way too complex and not much help...

Staffan
Staffan
The documentation for flex is no problem, it''s rather easy and after flex is a rather easy program. Bison is a little worse but if you actually take time to read "info bison" and/or "man bison", so to say, and play around a little you should be able to figure out most of it after a not-too-long amount of time. Then of course, I''m sure there''s always some shift/reduce conflicts that remain unsolved


"This album was written, recorded and edited at Gröndal, Stockholm in the year of 2000. At this point in time money still ruled the world. Capitalistic thoughts were wide spread. From the sky filled with the fumes of a billionarie''s cigar to the deepest abyss drenched in nuclear waste. A rich kid was a happy kid, oh..dirty, filthy times. Let this be a reminder."
- Fireside, taken from back of the Elite album
Kylotan
Kylotan
quote:
Original post by Staffan
The documentation for flex is no problem, it''s rather easy and after flex is a rather easy program. Bison is a little worse but if you actually take time to read "info bison" and/or "man bison", so to say, and play around a little you should be able to figure out most of it after a not-too-long amount of time. Then of course, I''m sure there''s always some shift/reduce conflicts that remain unsolved

What about the interesting issue that, to use them together, you really need to run Bison first to produce the header file for Flex? Otherwise your tokens may or may not match. So you really need to understand Bison in order to know what your tokens are going to be, in order to run it and then set up Flex...

And how is someone who''s never studied languages able to appreciate the finer points of grammar construction? I mean, even I don''t find those tools too intuitive, and I have a good academic background in both computing and linguistics. The Man pages, as for any other GNU tool, are dry and are 100% information, 0% explanation. If you know what you''re looking for and what it''s called, Man pages give you exactly what you need. If you don''t really know where to begin, Man pages just overwhelm you with detail.

I mean... a compiler for an ASM-style scripting language, such as:
<command> --> <operator> <operand list>
<operator> --> "move" | "stop" | "die" (etc...)
<operand list> --> <operand> | <operand list> <operand>
<operand> --> NUMBER | STRING | IDENTIFIER

Is pretty easy to do... assuming you know enough to know that only half of your grammar is done in Bison and half in Flex (somewhat counter-intuitive to anyone familiar with BNF). For example, should you hard code the operators in Bison as I did above, with rules for each? Or make a general operator token, expecting Flex to read them in properly? Or use Flex to read in anything that looks like it could be an operator ([:alpha:]* or whatever it would be) and hope that your system can catch the error? To someone skilled in compiler construction, you''d probably think that hard-coding them in Bison was the right idea, since you''d have come up with the BNF I showed above. But someone who knew more about Bison and less about theory would probably have just used an operator token. So it even makes it awkward for those who have an academic background in language construction.

Too many options, not enough guidance, that''s the problem, and why there needs to be a decent tutorial on using these tools somewhere. Sadly, I am hardly an expert myself, and perhaps that is why I am finding the shortcomings in the ''documentation'' that I''ve seen so far.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.