There are multiple C++ files. I need to extract the body of for-loop from these files.
Is there an easy way to do this maybe using grep. Consider there are no nested for loops.
There are multiple C++ files. I need to extract the body of for-loop from these files.
Is there an easy way to do this maybe using grep. Consider there are no nested for loops.
Without parsing the entire file, the answer is no.
for-loops are comprised of a context-free grammar and, as such, cannot be matched by a regular expression.
A more involved approach is to use grep
to search for the beginning of a for-loop (for
follow by optional whitespace followed by a lpar) then manually find the closing curly.
Unfortunately parsing C++ is Turing Complete, so unless there's some cute flag to pass to your compiler, you're hosed.