Removing comments from program code
In this recipe, we will see how we can use the replace
statement in conjunction with a suitable regex in order to remove comments from a program. For the sake of this recipe, we assume that the program whose comments are to be removed is syntactically correct. Similar to program created for the Dynamic program generation recipe in Chapter 2, Dynamic Programming, the program for this recipe will remove all statements beginning with a asterisk (*
) or all parts following a line after an inverted comma ("
).
Getting ready
For this recipe, we will make a copy of the program created in Chapter 2, Dynamic Programming, that reads the source code of a program specified by user input. In the previous program, we used two internal tables and used a loop at the first table itab
to delete comments. For this recipe, we will replace the loop with one replace
statement and use only one table that is the first internal table itab
. The code of the original program is read...