🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

Implementing an open-ended scripting engine

Started by
4 comments, last by Jejor 20 years, 2 months ago
Hi, I''m attempting to design a scripting engine. The scripting itself will be C-style, since the only people who will ever use it will be C++ programmers. Anyways, I am having trouble with the high-level design. My first thought was to make it class based, so anytime someone wants to add new syntax, they would just derive from a SYNTAX class. So when I''m parsing a line (i.e. "ADD x,y"), I want to take the first word I find and create a derived SYNTAX object from it (i.e. SYNTAX* new_statement = new SYNTAX_ADD). Ideally, this would happen: cin >> first_word; SYNTAX* new_statement = new GetClassName(first_word); ... GetClassName(char* key) { if(key == "ADD") return SYNTAX_ADD; } So what I really need is just some way to do this: x = int; int* y = new x; //Creates a new int Is there any way to do this in C++? Can it be simulated with precompiler directives or VBScripts? I''ve only been looking at the topic for a couple days now, so if anyone has any suggestions (Articles, Books, other games) please let me know. The real question is: Is there any good way to make a scripting engine that is independent of its syntax? (And by syntax, I mean generic functions, not +,*,{},etc.) Thanks.
Advertisement
quote: Original post by Jejor
The real question is: Is there any good way to make a scripting engine that is independent of its syntax?
It''s called a virtual machine that interprets/JITs bytecode. Microsoft''s .NET (MSIL) and Sun''s Java work exactly that way, the former supporting several languages and the latter supporting Java and Python (Jython), with probably others I don''t know about.
Emacs lisp uses bytecode and predates both examples mentioned by Oluseyi.

Also of interest is Guile (an implementation of Scheme) - Gnu use Guile in all new GNU software that calls for extensibility. Obviously these do not fall into your need to have C-style syntax, but for bytecode design reference purposes they may be useful.


[edited by - flangazor on May 4, 2004 3:11:43 AM]
quote: My first thought was to make it class based, so anytime someone wants to add new syntax, they would just derive from a SYNTAX class. So when I'm parsing a line (i.e. "ADD x,y"), I want to take the first word I find and create a derived SYNTAX object from it (i.e. SYNTAX* new_statement = new SYNTAX_ADD).
.
.
.
I am boggling a little from what you said. It looks like you want to do something like this [Article on Meta-Object Protocol Impleneted in C++] but you want to do it at a syntax level, akin to this [Revised^5 Report on the Algorithmic Language Scheme section 5.3].

If the actual syntax style is important, I suggest implementing something akin to a meta-object protocol rather than syntax extensions (since the syntax will change and can quickly be very un-C-stylish).

[edited by - flangazor on May 4, 2004 3:40:27 AM]
Thanks to everyone. It looks like meta-object protocol is exactly what I want.
More bytecode resources: Parrot, the bytecode format for Perl6.

[edited by - flangazor on May 5, 2004 6:19:30 AM]

This topic is closed to new replies.

Advertisement