473,662 Members | 2,352 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Find function names from C

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
4 1678
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
"Berlin Brown" <bi************ ******@comcast. net> wrote in message
news:za******** ************@co mcast.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
Jey Kottalam wrote:
"Berlin Brown" <bi************ ******@comcast. net> wrote in message
news:za******** ************@co mcast.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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
6999
by: Greg Yasko | last post by:
Hi. Does anyone know if there's an equivalent of Perl's file::find module in Python? It traverses a directory. I've googled extensively and checked this newsgroup and can't find anything like it for Python. I'd be using it in Linux to regularly search for files with a script. Is this a good application for Python or does Perl have more functionality for quick & simple scripting in Linux? Thanks.
9
2181
by: JimO | last post by:
I'm a newbie at this and I can't seem to find a list properties names to change styles on the fly. So far I've been lucky and managed to guess the names such as BodyElement.style.marginTop = 0; BodyElement.style.paddingTop = 0; Can anybody direct me to a list of CSS properties available in javascript?
6
17956
by: Prashant Bhuptani | last post by:
Hi Guys, I am trying to use a C++ dll in VB.NET code. I have imported the dll in the following manner: <code> Imports System.Runtime.InteropServices
2
5037
by: John Regan | last post by:
Hello All I am trying to find the owner of a file or folder on our network (Windows 2000 Server) using VB.Net and/or API. so I can search for Folders that don't follow our company's specified folder structure and naming conventions and then send a Net send message to those users telling them to rectify. The information I want to get is when you select the file/folder and then: Properties -> Security Tab -> Advanced Button -> Owner Tab ->...
0
8432
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8762
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8545
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
6185
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5653
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4179
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4347
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2762
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1747
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.