문제

I know there are a few questions floating around here on the subject, but it was hard to find anything useful to what I'm after...

I also know it will probably end up being quite the task to complete, but I really want to make a simple scripting language for gaming engines... I want to use it in C++ and my Android Java game engines... but I don't know where to start... I've tried looking for tutorials online, but alot require converting things to byte code, virtual machines and such...

I really just want to create a simple scripting language which can be read from the engine, have some simple "if/else" logic... simple functions that can be called from other scripts and so on... Maybe even simpler for early versions... I really don't know where to start, but I do know this is something I need to start studying and understanding.

If anyone could point me in the right direction and point out some links to very simple "making a simple scripting language for games" kind of tutorial or even point out some key concepts that I should look into... I'd be really thankful.

I'd prefer a minimalist C based scripting language, but I guess the specifics will come into it once I've actually learnt more about it.

Thanks for any help anyone can give.

도움이 되었습니까?

해결책

I've tried looking for tutorials online, but alot require converting things to byte code, virtual machines and such

Yes. This is really the approach, even for a dead simple language. Executing the source code directly will be way more complicated, the way this is done is first you parse the source code and digest it into byte code, then have a virtual machine interpret the byte code.

You may want to look at existing languages to learn about their design.

This tutorial from flipcode builds a simple language and includes all the code, so it might be useful.

You can also take a look at the Lua source code.

다른 팁

Part of my job is maintaining a proprietary game scripting language. I'm not aware of any "How-to" books on the subject in its narrow sense. There is an interesting article by Bruce Wilcox on writing such languages. It doesn't discuss implementation detail, but goes into the design process somewhat.

http://www.gamasutra.com/view/feature/1570/reflections_on_building_three_.php

Writing a scripting language is like writing any language and involves all the same principles and design questions. You need to think about what concepts your language should revolve around, you need to define a grammar, then you need to write a compiler or translator and/or an interpreter. Which you choose and the details of their implementations are entirely up to you, and there is no one or best way to accomplish these things.

There are standard ways of thinking when it comes to parsing syntax and defining language grammars. Regular expressions are your friend here. Thankfully, C++11 includes the <regex> library (originally from boost). It might help to pick up a book on compilers to get you started on important concepts, if you really want to get into the subject in depth. When I was in university taking a compilers course, this was my textbook, which I've kept with me to this day, so I recommend it.

http://www.amazon.com/Compilers-Principles-Techniques-Alfred-Aho/dp/0201100886/ref=sr_1_2?ie=UTF8&qid=1326618572&sr=8-2

Writing a language is a wonderful exercise in computer science. However, if this is for a real project or product, then like others who have already commented, my professional advice is: Don't do it if you don't really have to. This is a huge potential time investment that you're considering, and you have you ask yourself: What benefits will I get out of my own language that I can't find in existing free-to-use languages like Lua and Python, and are those benefits worth the months of extra time it's going to take to implement?

And don't forget the tools. If you're writing a language that you intend others to use, you need lots of documentation and tools, tools, tools. You will almost certainly want a source level debugger at least, and writing a good debugger can take as long as writing the language itself!

If all you want is a language for fast-prototyping game logic, then Lua is likely more than suitable for your needs, and comes with lots of existing documentation, literature and tools.

A few old articles are still good read, if you can find them:

  • M. Abrash, D. Illowsky, "Roll your own minilanguages with mini-interpreters", Dr. Dobb's Journal 14 (9) (Sep 1989) 52–72.
  • J. Bentley, "Programming pearls: little languages", Communications of the ACM 29 (1986) 711–721.
  • D. Betz, "Embedded languages", Byte 13 #12 (Nov 1988) 409–416.
  • D. Betz, "Your own tiny object-oriented language", Dr. Dobb's Journal 16 (9) (Sep 1991) 26–33.
  • N. Franks, "Adding an extension language to your software", Dr. Dobb's Journal 16 (9) (Sep 1991) 34–43.
  • R. Valdés, "Little languages, big questions", Dr. Dobb's Journal 16 (9) (Sep 1991) 16–25.

See also Bob: A Tiny Object-Oriented Language by Betz. The latest sources for BOB are available at http://www.xlisp.org/.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top