Is there any reliable tool for removing comments in ASM / C / C ++ code?

I know this question was asked earlier (for example, see Remove comments from C / C ++ code ), but I did not find a satisfactory result.

I am analyzing a set of complex C / C ++ code that must first be normalized, including removing comments from the input source code.

All of the decomposition tools I tried to a certain extent failed, and this includes:

  • decomposition
  • stripcmt
  • Cloc

Note: I also tried "gcc -fpreprocessed -E", but this does not produce the perfect result; the output contains some weird macro annotations for tracking specific lines of code.

To illustrate the problem with a particular tool (cloc), deleting comments from this header file also removes non-comments, such as all inclusions at the beginning of this file.

However, is there a reliable comment removal tool that can be used to remove comments in extremely complex code?

Very grateful.

+4
source share
2 answers
#!/bin/bash if [[ "$#" != 1 ]] ; then echo "Usage: stripcomments input-file" > /dev/stderr exit fi gcc -fpreprocessed -dD -E -P "$1" 2> /dev/null 
+2
source

You can delete everything after // to EOL and /* to */ with two regular expressions if you want ...

For single line comments, you can use: \/\/(.*)

For multi-line comments, this is: \/\*(.*)\*\/

-one
source

Source: https://habr.com/ru/post/1496682/


All Articles