Will this regex be enough to remove C++ multiline comments? -
I need to parse some C ++ files, and to make things easier for me, I thought about removing the following regesx: / (\ / \ *. *? \ * \ /) /
, using multiline modifier, and it starts working Do you think there will be such a case where it will fail?
The following is hurting you:
std :: Cout & lt; & Lt; "Some / * source code printing /
This is a perfect example. Imagine what you could do if the string made a comment Started and did not finish it? You can eliminate the huge amounts of your code.
A regex can give you a good "quick and dirty" solution, and can work in your special case (I want to make sure you have a pass before "remove all matches" before "all in Remove and print "), but in the general case, you will need a more sophisticated parser. You may be able to account for this situation with a regex, but it will become ugly.
EDIT: Thanks to @Mimeters in comments, I have realized that your problem is a bit more involved than just source files, although speaking strictly if you have an embedded tip If you use macros with macros, then you are asking for trouble, after some tests, it has been found that most machines have a device installed with the C ++ compiler, which will leave the comments, and all the nimble for you String and macro issues will be handled. To get output without comment (single or multi-line), use it on file.cpp
:
cpp file.cpp
Sure, it will expand all macros and #include
s, and you may not have such a very well organized formatting, but it's easy to read all the macros, strings and other related If you do not know with a comment, you can not solve the problem, CPP
is a standalone person There is no C preprocessor as inefficient (theoretically you have the same code-similar syntax as in #include
s and #define
s and in any language), so if If you do not have this, you can get similar effects with GCC:
gcc -E file.cpp
( GCC
to G ++
If you really care, you can handle it; it is better to have #include & lt; iostream & gt;
)
Removing a comment, where As far as I know, the preprocessor is not strictly part of it, but most preprocessor does the actual level of parser (well, in the stage of simplifying the syntax of the preprocessor of GCC, to be tried). So if your compiler's preprocessor option does this for you, and this is what you want to do then stop your own rolling.
I am sorry to think about this. I do not know how it got saved.
Comments
Post a Comment