[plug] Using YACC
Peter Wright
pete at akira.apana.org.au
Mon Aug 5 11:01:43 WST 2002
Hi Dave,
On 02/08 19:45:39, Buddrige, David wrote:
> Hi all,
>
> This may be moderately off-topic (it is actually a linux problem - albeit a
> programming problem 8-) ); I am teaching myself to use LEX and YACC in
> order to solve a problem we have here. We have a bunch of source-code with
> in-line comments all through it.
[ ... ]
> Basically, rather than manually going through the 1-2 million lines of code
> we have here and re-arranging the comments for DOC++,
YIKES. See below - I think you don't want to use DOC++. :)
> we would like to get a program to do that for us....
Sounds perfectly reasonable.
> To do this, I have begun writing a very simple grammer using lex and yacc.
AAaaggggh!!!
Wrong tool for the job, I think Dave. This looks like the sort of job designed
for a Perl script.
---- example Perl -----
#!/usr/bin/perl
my $filename = "example.cpp";
open(SOURCE, $filename) or die "Couldn't open file $filename";
# Pick a number larger than the number of bytes in the
# largest source file you've got...
my $MAX_FILE_SIZE = 131072;
my $source;
read(SOURCE, $source, $MAX_FILE_SIZE) or die "Couldn't read in file
$filename";
# Remove multiple line comments
$source =~ s/\/\*.*?\*\///sg;
# Remove single line comments
$source =~ s/\/\/.*$//mg;
print $source;
---- example Perl -----
This will strip out all C/C++-style comments from a source file... you should
be able to extend that fairly easily to do interesting things with the
comments themselves - assuming the current comments follow a reasonably
consistent pattern that you can use a regex to identify.
Well, it depends on precisely how complex are the change(s) you want...
Email me if you need a hand.
> David Buddrige
BTW, you might also find that Doxygen is a better option than DOC++. Doxygen
looks better (IMO) and also can use GraphViz to generate pretty hyperlinked
class diagrams. It also has a nice GUI wizard to help configure a processing
run, though DOC++ might have that too.
http://www.doxygen.org/
An example of Doxygen output on a particular project:
http://xml.apache.org/xalan-c/apidocs/index.html
See http://www.stack.nl/~dimitri/doxygen/projects.html for a list of other
projects that use Doxygen.
Not to mention, Doxygen is an actively developed project (last update 3 weeks
ago), while it appears that DOC++ was last updated in (holy crap) 1998(!!!!):
http://www.zib.de/Visual/software/doc++/ChangeLog.html
Yikes. *wry grin*
Pete.
--
http://akira.apana.org.au/~pete/
Klingon programmer sayings:
4. "I have challenged the entire quality assurance team to a
Bat-Leth contest. (pause) They will not concern us again."
More information about the plug
mailing list