Thread: How to design/implement object(s) model for toy scripting language?

  1. #1
    Registered User
    Join Date
    Apr 2007
    india->tamil nadu

    Exclamation How to design/implement object(s) model for toy scripting language?

    I am trying to make a toy scripting language in c++. I have used boost spirit for the grammar, and hopefully for parser / lexer. The idea is - a language where 'everything is an object' like javascript and some support of prototype based inheritance. I want to know how to design and implement the 'object' and inheritance for it using c++. I saw source codes of engine spidermonkey but mostly it is done using structures, also getting more complex at later stages. I hope I could manage with the stdlib itself. I don't want to think about any optimization at this stage. All I want is a solid idea of how the basic objects have to be implemented and how their properties are created/modified/destroyed at runtime. I tried to take a look at V8, but its really confusing me a lot!

    I would like to design four primitive objects -> string, number (double would do), function, list. The list can be a recursive of all four. I had ideas of using templates but pointers would be simple I hope. Any ideas/pointers/links really appreciated, thanx in advance.
    "Quotes don't make a man great- deeds do..."

  2. #2
    Registered User C_ntua's Avatar
    Join Date
    Jun 2008
    C++ alreayd has objects. No need to do anything new. If you want everything to be an object, then everything can be derived from a base Object Class, like in Java.

    List and string objects already exist in C++. As a function you can use a Functor (Function Object). As a number wrap a double in a class, so it becomes an Object. Then wrap those classes inside a class that is derived from the basic Object Class you created.

    At runtime you destroy/create them with new/delete. Nothing new there either. You can use a garbage collector for C++ (google it) if you want the deletion to be done automatically.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Scripting language
    By Blizzarddog in forum C++ Programming
    Replies: 5
    Last Post: 09-17-2003, 11:47 AM
  2. C Language And A Scripting Language
    By DarkSpy in forum C Programming
    Replies: 9
    Last Post: 06-26-2003, 08:05 AM
  3. How would I go about making a scripting language...
    By gcn_zelda in forum C++ Programming
    Replies: 1
    Last Post: 06-19-2003, 11:43 AM
  4. Creating my own Scripting language in C++ for CGI
    By stovellpaul in forum C Programming
    Replies: 0
    Last Post: 10-01-2002, 03:41 AM
  5. Visual J#
    By mfc2themax in forum A Brief History of
    Replies: 0
    Last Post: 10-08-2001, 02:41 PM

Tags for this Thread