What I am trying to do is parse a c++ sourcefile. Yes, it has to be c++ due to certain keywords (the different casts for one). Now, I am trying to do it as compactly as possible, but still readable.
Here's what I have so far:
a class that breaks a source file up into keyword tokens. I've identified all of my relevant keywords, focusing on identifying and classifying functions within the sourcecode as my next objective.
I plan on writing these codified sourcefiles to another file so that I can use them to work in a different program. I'm basically building a tool to perform some algorithm design and testing, and making my tool aware of the contents of a sourcefile helps out tremendously.
No, I'm not building an abstract symbols table, but it's along the same kind of idea I think. At least as I understand it, an AST is what a compiler uses to organize code and then optimize it.
Anyways, can anyone think of another way to implement this? It's taking forever to write out all of the keywords that I want to look for, and coming up with identifyers for each one. Is there a chart that shows all of the keywords used in c++ that is organized in some fashion? Say the keywords for program flow/control, the keywords for datatypes, and so on?
Here's the header for my class:
Code: Select all
class keywords
{
public:
keywords();
~keywords();
int isakeyword(string checkthisword); //Returns 1 if true, 0 if false
int getkeywordid(string keyword); //Returns keyword ID, 0 if an error
private:
int keywordid;
int keywordindex;
}
isakeyword just verifies that the string read in has a keyword. getkeywordid does just what it's name says. I think if I implement it this way, it will read the string to look for keywords, and start writing a string that is basically a keyword (but as a code like f1i1ixxxx for a function with one input and one output - both integers). I don't know if that's going to be very fast though. Any thoughts on this part?
[/code]