Code Comments
Programming Forum and web based access to our favorite programming groups.Hi, I wish to scan C/C++ code and detect any hard coded statements in it, like the '1000' in: char str[1000]; or the '10' in: int i = 10; I don't have the slighest idea about how to do it. (I have never worked with compiler stuff) Any idea what options I have? Thanks. [You could practically do that with grep, with a prepass to get rid of the comments. -John]
Post Follow-up to this messagenatkhatbandar@yahoo.com (Zombie) wrote
> Hi,
> I wish to scan C/C++ code and detect any hard coded statements in it,
> like the '1000' in:
> char str[1000];
>
> or the '10' in:
> int i = 10;
> [You could practically do that with grep, with a prepass to get rid
> of the comments. -John]
If you want to extract integer constants from your C/C++ file, you can
type this piece of code, written in CodeWorker, and save it in
"integers.cwp" :
integers ::=
// ignore C++-like comments between BNF symbols,
// so that it doesn't read integers into comments
#ignore(C++)
[
// jump to the next integer, and consume it
->[
#readInteger:iValue
// trace the integer on the console
=> traceLine(iValue);
|
// if a string is encountered, consume it
// to not take into account the integers,
// which are perhaps into
#readCString
]
]* // search again
;
Then, download CodeWorker at "http://www.codeworker.org" and type the
command line:
codeworker -parsebnf integers.cwp <your-C-file.c>
If you have more than one file to process, write the following lines
in the file "iterateSources.cws":
forfile i in "*.c" {
parseAsBNF("integers.cwp", project, i);
}
and execute :
codeworker iterateSources.cws
As CodeWorker is also a source code generator, you can choose to save
the integers in a file, following a template-based script, instead of
writing them on the console. You can also write the filename
(getInputFilename()), the line (countInputLines()) and column
(countInputCols()) where they were located.
Post Follow-up to this message
Show a Printable Version
Email This Page to Someone!
Receive updates to this thread
Powered by vBulletin
Copyright 2000-2006 Jelsoft Enterprises Limited.