By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,767 Members | 1,995 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,767 IT Pros & Developers. It's quick & easy.

Find function names from C

P: n/a
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 { }.

Jul 18 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
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
Jul 18 '05 #2

P: n/a
"Berlin Brown" <bi******************@comcast.net> wrote in message
news:za********************@comcast.com...
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 { }.


Look into www.gcc-xml.org or there's an ANSI-C parser at
http://www.lysator.liu.se/c/ANSI-C-grammar-y.html that could easily be
adapted for your needs. (Yes, that's with C and yacc, not python. sorry.)

-Jey Kottalam
Jul 18 '05 #3

P: n/a
Jey Kottalam wrote:
"Berlin Brown" <bi******************@comcast.net> wrote in message
news:za********************@comcast.com...
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 { }.

Look into www.gcc-xml.org or there's an ANSI-C parser at
http://www.lysator.liu.se/c/ANSI-C-grammar-y.html that could easily be
adapted for your needs. (Yes, that's with C and yacc, not python. sorry.)

-Jey Kottalam


I have to go back to the books, dont know python or lisp very well,
yacc,lex, for one thing, that is exactly what lisp does in emacs
anyway, the way it matches one { with another }

Jul 18 '05 #4

P: n/a
Berlin Brown <bi******************@comcast.net> writes:
I have to go back to the books, dont know python or lisp very well,
yacc,lex, for one thing, that is exactly what lisp does in emacs
anyway, the way it matches one { with another }


Well, how about etags in Emacs or ctags in vi? I don't know if this is
exactly what you want, but typing "etags *.c" will generate a "TAGS"
file, which contains all function names in those c source files. And
then you can use Emacs to do function name searching. Take a look for
the functionality in Emacs, maybe you don't have to write it by your
own.

Good luck!

--
Chun-Chieh Huang, aka Albert E-mail: jjhuang AT cm.nctu.edu.tw
T
Department of Computer Science
National Tsing Hua University MIME/ASCII/PDF/PostScript are welcome!
HsinChu, Taiwan NO MS WORD DOC FILE, PLEASE!
Jul 18 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.