I want to parse an input file that has syntax similar to c++ source. The file will have components such as these:
//It will have comments.
//It will be able to recursively open other files.
include OtherInputFile.txt
//It will resolve scope
ObjectName::MemberVariable = 0.0;
OtherObjectName
{
MemberVariable1 = 1.0;
MemberVariable2 = 2.0;
}
The trouble is, I have no idea what I'm doing. I suppose what I need is a textbook chapter on parsing to orient myself to what technologies or algorithms are available.
I want to parse an input file that has syntax similar to c++ source
Pray it doesn't have templates, preprocessor, operator overloading and multiple inheritance. Otherwise you're in trouble.
I have no idea what I'm doing
Investigate Lex/Yacc. Read book about the parsing or google the subject ("how to make a language"). Some of those tools have tutorials and documentation links. I could swear I saw either bison or yacc or lexx tutorial that had mentioned book that was called "how to write a compiler" or something like that, but that was so long ago, that I don't remember what tool was that, or what was the book called.
The principle is basically the same: you define language grammar (C++ standard has language grammar example in one of appendices), split input file into tokens (throwing errors if tokens don't match grammar), then classify tokens (what is it? opening bracket, identifier, function name ?) and build a tree out of those tokens which is then converted into corresponding language objects/function calls etc. Depending on complexity of your language, you might skip most of the steps and wrestle input file into submission using bunch of regexps.