Command Based Scripting Language

Started by
25 comments, last by choffstein 19 years, 3 months ago
Does anybody know of any tutorials for COMMAND BASED SCRIPTING LANGUAGES.... I know Game Scripting Mastery has one in it however i lost the cd for it and well.... The book just shows the scope of the source code not the full source :S..... so if anybody knows of any simple implementations or tutorials i'd very VERY much appreciate it.... After i implement this im going to do a command based language with a compiler then a full scripting language that has a c syntax. But i want to start simple then work my way up, doing it the right way. Btw... Im a C/C++ programmer so i'd appreciate it if there was no VB tutorials and all. and i know about tghe scripting tutorial on this site and flipcode EDIT: I wanna do this for experience, NOT to use instead of a existing one
Advertisement
You can probably contact the publisher for a replacement of the cd for a small charge. I'd try it at least.

Also, the language that the scripting language is implemented in shouldn't matter if you're only trying to get a feel as to how it's done. If anything it's better because you can't directly copy anything and must exercise your mind a little in converting the various aspects.
Ill do that however i dont know if your familiar with a command based language its a language that really doesnt have a lexer or anything it just opens up a file and parses it and comares it to hardcoded commands example:


print "hello"
print_line
get_key



like that

that way it just compares it to something like this


if(currline == CMD_PRINT)
{
char param = get_params(currline);
print("%s", param);
}


however im not familiar with file io and parsing and such so thats where it gets me

[Edited by - Machlana on December 31, 2004 2:53:25 PM]
Is the example that you've given me as complex as your engine gets? If so, it's relatively straightforward.

Read a line in from file.
Parse instruction (assuming that instuction is always first, which seems to be the case).

Here, parsing is a simple as reading until you encounter whitespace or the end of the string. Then simply compare this segment of the string to expected commands. Handle it if it passes, otherwise throw an exception (or whatever you want to handle errors).

If the command has arguments, and you haven't reached the end of the string, parse the next "word", or, in the event of a quotation, read until you encounter end of string (error) or the next quotation and you have the string substring.

I'm not sure, specifically, what else you'd need pointed out. If you can't think it through, then give me a solid example of what you want to do and perhaps I or another can get you moving.
Right, lemme explain a little more

a function like
LoadScript()
That will load the script

a function like
RunScript()
That runs the script (like my above example)

a function like
GetCommand()
That gets the next command

a function like
GetParam()
That gets the paramater after the command

I know what i need but my problem is i have NEVER programmed file I/O in my life so im completley confused in it
Then do a quick google or msdn search for it. All you need is something to read a line of text.

Here's a good one.

So, learn how to read a line of text into a string. After that it's largely common sense and thinking it out. Grab a line. Break off the first chunk (probably "someFunc("), see if there are parameters to apply, process it.
Thanks i'll take a look and see if i can figure it out otherwise i'll post again
So would i do something like this?


for( int CurrLineIndex = 0;
CurrLineIndex < ScriptSize;
++CurrLineIndex )
{
// Allocate space for the line and a null terminator
strScript[ CurrLineIndex ] = ( char * ) malloc ( MAX_SOURCE_LINE_SIZE + 1 );

// Load the line
fgets( strScript[ CurrLineIndex ], MAX_SOURCE_LINE_SIZE, ScriptFile );
}



Im still so confused what to do after that is there any examples?
Try it out. Does it read in lines?

To test it, have it echo the lines out. Or run it through a debugger.

Anyway, next, read characters until you run into a space, end of string or a '('. You then have the first function.

Check the next character, if it's not whitespace or a ')', then you have a parameter. Read it until you encounter a space, a comma, end of string or ')'.

Is it starting to come into focus?
Yea, it is i'll try that out thanks

This topic is closed to new replies.

Advertisement