I'm trying to learn about parsers, for Python, C and C++ source (on my own, not for a school project). Here is a summary of what i want to do: 1) read .c/.cpp/.py source files in Python 2) get a list of all the functions in the source files, and the span of their definitions in terms of line numbers.
So to illustrate my question, consider the following code in a file "helloWorld.cpp" (read this in python):
//start
#include <iostream>
#include <string>
using namespace std;
int main(int argc, char** argv)
{
string str = "Hello World";
cout << str << endl;
return 0;
}
//end
What i want to get is something along: list of functions: int main(int argc, char** argv) start: line 7 end: line 12
Any ideas on how to achieve this (some code examples would be greatly appreciated)?