After some research and a few questions, I ended up exploring the libclang library to parse C ++ source files in Python.
Based on C ++ source
int fac(int n) { return (n>1) ? n∗fac(n−1) : 1; } for (int i = 0; i < linecount; i++) { sum += array[i]; } double mean = sum/linecount;
I am trying to identify fac tokens as a function name, n as a variable name, i as a variable name, mean as a variable name, and also each one position. I was interested in eventually tokenizing them.
I read some very useful articles ( eli , Gaetan's ), as well as some questions 35113197 , 13236500 .
However, given that I am new to Python and struggling to understand the basics of libclang, I would really appreciate some sample code that implements the above for me to understand and understand.
c ++ python parsing libclang
nk-fford
source share