C++ Learning Community Forum
September 11, 2010, 12:40:13 AM *
Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
News: Hello. Smiley
 
   Home   Help Search Login Register  
Pages: [1]
  Print  
Author Topic: Another script engine I'm working on... again...  (Read 705 times)
PiedotTaste
Nerd
****
Posts: 78


View Profile
« on: September 24, 2009, 12:11:58 AM »

Hello, look at me making another script engine, again, for the 123870123th time. This time with object support! Finally! You'd think after so many attempts I'd have bothered finishing one with object support by now but no, I haven't.

Currently have the parser and sort-of-compiler done, writing the actual sort-of-virtual-machine bit now. I doubt this will be particularly efficient as I'm making "good" use of strings... clearly not the best solution... but I'm more interested in finishing it and learning and taking such considerations into account next time than getting it all perfect.

So, the syntax may not be to your tastes, but here is an example input script file:

Code:
Import comparison

Object Dog {
    String colour;
    String name;
    Bool crazy;
    Int age;
}

Function Bark(Dog d) Returns Nothing {
Int i = 2 * 4 - 15;
if(comparison.Between(5, 0, 10)) {
PrintLine("<" + d.name + ">: Woof!");
}
}

Function WhileTest(Int counter) Returns Nothing {
while(counter > 0) {
counter = counter - 1;
}
}

Function Main(List<String> Args) Returns Int {
    Dog Rover;
    Rover.colour = "Brown";
    Rover.name = "Rover";
    Rover.crazy = Rover.colour == "Brown";
    Rover.age = 4;
    Bark(Rover);
    Return 0;
}

So, yeah...

I'll attach a .zip (I don't have winrar installed on my new laptop yet) which contains the following files:

Source Code:
Bytecode.h /.cpp
CompileParsed.h /.cpp
Engine.h /.cpp              <-- kinda empty/redundant right now, ignore it
ParseException.h /.cpp
ParseSource.h /.cpp
ParseText.h /.cpp
RuntimeException.h /.cpp
ScriptObject.h /.cpp

Data Files:
asm.txt               <-- contains a mock-up of the bytecode i wanted my compiler to generate, redundant as the compiler is finished
comparison.txt     <-- used for testing the import feature, is imported by test.txt and contains a single comparison function (Between)
test.txt              <-- the main test source file (contains the code shown above)

I don't know if anybody will find this interesting/impressive/lame but you know, I love making script engines and getting slowly better at them haha, plus the Work in Progress and Finished Product categories are kinda slow ;)!

* ScriptEngineSrc.zip (14.12 KB - downloaded 28 times.)
Logged
PiedotTaste
Nerd
****
Posts: 78


View Profile
« Reply #1 on: September 24, 2009, 04:32:23 PM »

A little update, I've essentially finished the main guts of this thing now, so parsing, compilation and execution are now done.

Now all that's left is to wrap up the interface neatly for standard use and implement an Engine object that can sort of manage scripts for you and act as a kind of scheduler :).

Attaching a new zip of the source, file list is now:

Source Code:

Source Code:
Bytecode.h /.cpp
CompileParsed.h /.cpp
Engine.h /.cpp              <-- STILL kinda empty/redundant right now, continue ignoring it :P
ParseException.h /.cpp
ParseSource.h /.cpp
ParseText.h /.cpp
RuntimeException.h /.cpp
ScriptObject.h /.cpp

Data Files (just example script files, the code is currently set to execute test3.txt):

comparison.txt
test.txt
test2.txt
test3.txt

So yeah :)

* ScriptEngineSrc2.zip (16.89 KB - downloaded 22 times.)
Logged
ih8censorship
Megalomaniac!!!
Administrator
C++ guru
*****
Posts: 1241



View Profile
« Reply #2 on: September 25, 2009, 02:12:13 AM »

Any time I think about creating a language, it always turns into something very very Perl like.  Roll Eyes Ill look at your sourcecode in a bit, and maybe have something to say about it Smiley
Logged

PC==perfect_companion

Knowledge cannot come packaged and predigested; it must be chewed over carefully before swallowed.

What have you tried?
ih8censorship
Megalomaniac!!!
Administrator
C++ guru
*****
Posts: 1241



View Profile
« Reply #3 on: September 25, 2009, 05:14:03 AM »

It would have been nice if you commented more  Roll Eyes

I didn't notice any regular expressions. What's the reasoning behind that choice?
Logged

PC==perfect_companion

Knowledge cannot come packaged and predigested; it must be chewed over carefully before swallowed.

What have you tried?
PiedotTaste
Nerd
****
Posts: 78


View Profile
« Reply #4 on: September 25, 2009, 09:28:17 AM »

You mean regular expressions in my parsing? Firstly because I don't really know regular expressions, and secondly I can't be bothered to find a good one and install/setup, the final most important reason is I prefer doing it all myself.

I keep making them with the intention of eventually making a good scripting engine that is entirely my code (with the exception of the standard library I guess Tongue). It's more fun Smiley.

I guess I should comment more, it's just I usually have very little need as my projects are usually little investigations which take no more than a couple of days to program, so I don't have to remember them in the long term.

Bad habits die hard Tongue I'll have to up the comments. I have to write an interface for it anyway, so I might add in a load of comments when I do that perhaps.

Other than that, any other comments? :3

Edit: fixed two typos >_>
Logged
C-Man
Does anyone even read this ?
Global Moderator
Dr. of C++ology
*****
Posts: 988



View Profile WWW
« Reply #5 on: September 25, 2009, 10:12:50 AM »

good programmers need no commetes  Angry
Logged

PiedotTaste
Nerd
****
Posts: 78


View Profile
« Reply #6 on: September 25, 2009, 11:35:51 AM »

>:C ommmm. No seriously any comments? Cry

C-MAN GIVE COMMENTY GOODNESS! >:
Logged
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.11 | SMF © 2006-2009, Simple Machines LLC Valid XHTML 1.0! Valid CSS!