Using libclang to parse in C++ in Python
<p>After some research and a few questions, I ended up exploring <a href="https://pypi.python.org/pypi/clang/3.5" rel="nofollow noreferrer">libclang</a> library in order to parse C++ source files in Python.</p>

<p>Given a C++ source </p>

<pre><code>int fac(int n) {
    return (n&gt;1) ? n∗fac(n−1) : 1;
}

for (int i = 0; i &lt; linecount; i++) {
   sum += array[i];
}

double mean = sum/linecount;
</code></pre>

<p>I am trying to <strong>identify the tokens</strong> <code>fac</code> as a function name, <code>n</code> as variable name, <code>i</code> as a variable name, <code>mean</code> as variable name, along with each ones position. I interested in eventually <strong>tokenizing</strong> them.</p>

<p>I have read some very useful articles (<a href="http://eli.thegreenplace.net/2011/07/03/parsing-c-in-python-with-clang/" rel="nofollow noreferrer">eli's</a>, <a href="http://blog.glehmann.net/2014/12/29/Playing-with-libclang/" rel="nofollow noreferrer">Gaetan's</a>) as well as some stack overflow questions <a href="https://stackoverflow.com/questions/35113197/finding-anonymous-enums-with-libclang">35113197</a>, <a href="https://stackoverflow.com/questions/13236500/how-to-parse-single-file-using-python-bindings-to-clang">13236500</a>.</p>

<p>However, given I am new in Python and struggling to understand the basics of  libclang, I would very much appreciate some example chunk of code which implements the above for me to pick up and understand from.</p>