focht
January 18th, 2004, 12:54
Uhm well ...
usually i would point out a good lexical scanner/parser framework (including dynamic BNF) ...
But i know you dont have time and want results

If you still interested you might look into boost's "spirit" library at http://spirit.sourceforge.net/
("http://spirit.sourceforge.net/
")
Boost is IMHO the best OO framework around ... http://www.boost.org/
("http://www.boost.org/
")
I use it regularly in my projects (i code for a living).
For other suggestions .. well.
In every project turn compiler warn level to 4.
This catches most of the bugs usually encountered (uninit vars, control paths ...)
I even use "treat warnings as errors" in my projects (i disable too noisy ones with pragmas).
For the "processing" of commands itself i would simply use a function pointer table or map.
Not that i dont like if( command == xxx) .. else if( ...) ... approach but the more commands you implement the more the function will grow.
example (simplified version):
<pre>
// declare function ptr with one arg
typedef bool (*PFCOMMAND)(const std::string& arg1);
// prototype our command lookup map
typedef std::map< std::string, PFCOMMAND> command_map;
// instance of command map
command_map commands;
// insert entries into "commands"
void addCommand( const std::string& name, PFCOMMAND routine)
{
commands[name] = routine;
}
// call subroutines via "commands" lookup
bool callCommand( const std::string& name, const std::string& arg)
{
bool result( false);
// use the string to look up the pointer to subroutine
command_map::const_iterator citer = commands.find( name);
if( citer != commands.end())
{
// we found it, get function pointer
PFCOMMAND cmd = citer->second;
// call subroutine
result = cmd( arg);
}
else
{
// no match for given name, use error callback
....
}
return result;
}
You can now
addCommand( "cmp", &CompareHandler)
....
result = callCommand( command_str, arg1) ...
...
and so on..
</pre>
I hope you get the idea
Regards,
A. Focht
PS: remove REG

there arent that many scripts written to keep zombies alive forever...