Re: Lacing C/C++ code

Prashant V Hedaoo <>
Tue, 16 Nov 1993 17:51:17 GMT

          From comp.compilers

Related articles
Lacing C/C++ code (1993-11-14)
Re: Lacing C/C++ code (1993-11-15)
Re: Lacing C/C++ code (Prashant V Hedaoo) (1993-11-16)
Re: Lacing C/C++ code (1993-11-29)
| List of all articles for this month |

Newsgroups: comp.compilers
From: Prashant V Hedaoo <>
Keywords: C, C++, parse, comment
Organization: Compilers Central
References: 93-11-092
Date: Tue, 16 Nov 1993 17:51:17 GMT

Elan Feingold writes :
> All I need to recognize are functions. It would be nice to
> recognize C++ type functions too. I was thinking of hacking up the C/C++
> grammar available for ftp at places, but does anyone know of a better
> (read easier) way to do it?

About a year ago, I developed same type of tool for slightly different
requirement only using Lexical Analyzer. Given C source code, the tool
extracts called function names from a function definition.

All you have to do is to write a regular expression identifying function
name followed by '(' , optional argument list, ')' and '{'. After this you
have to skip data definition & search for first executable statement to
instrument the code with FUNC_START( "xxx"); OR just create a block
enveloping the function body and put FUNC_START("xxx"); as a first
statement. Two more regular expressions are required for identification
of function termination, i.e. '{' & '}' with corresponding action to
update counter and at the last '}' it should insert one more '}' to close
the block and FUNC_END("xxx");

The first regular expression to identify function start will also match
with "if", "switch", "while". So, the first string should be compared with
these keywords.

This approach works well for C source, not sure with C++.

Contact for further details.
Prashant V Hedaoo E-mail:
Centre for Development Of Telematics (C-DOT), Voice : 91-11-677525 Ext. 327
9th Floor, Akbar Bhawan, Fax : 91-11-6885558
Chanakyapuri, New Delhi - 110021
[I'd be concerned that this approach could be confused by declartions of
pointers to functions. -John]

Post a followup to this message

Return to the comp.compilers page.
Search the comp.compilers archives again.