Find function names from C
Josiah Carlson
jcarlson at nospam.uci.edu
Mon Feb 2 21:04:56 EST 2004
Berlin Brown wrote:
> I am parsing a C file and want to find the function names, is this
> python worthy or is Emacs-Lisp better for this. I have searched for
> some libraries but coming up null. I just need the function names, no
> args or anything else. I would probably have to run a regular
> expression pattern looking for int,void,static, etc and then the
> enclosing { }.
>
That sounds like something a recursive descent (sp?) parser could do
very well (or really any other programming language parser). In
general, a regular expression would not be sufficient, due to nested
blocks of {} like the following:
int main () {
if (1) {
return 4;
} else {
return 3;
}
return 2;
}
FYI: regular expressions are those languages that can be recognized by
finite state automata. Because most modern programming languages are
context-free grammars, they are not recognized by regular expressions
and thusly finite state automata.
I would be willing to bet that someone has already implemented a parser
for C/C++ in Python. If not, talk to someone taking a compilers class,
they'll be able to help you.
- Josiah
More information about the Python-list
mailing list