Feature #1: Remove Comments
Implementing the "Remove Comments" feature for our "Language Compiler" project.
We'll cover the following...
Description
The first functionality we will be building will remove comments from a piece of code prior to its compilation. There are two types of comments in the C++ language, inline comments and block comments.
- Inline comment: The string
//
is used for an inline comment, which means that the characters to the right of//
in the same line should be ignored. - Block comment: The block comment is enclosed between the non-overlapping occurrence of
/*
and*/
. Everything inside these delimiters is ignored. Here, occurrences happen in reading order, meaning line by line from left to right. Note that the string/*/
does not yet end the block comment because the ending would be overlapping the beginning.
Note: If two comments are nested, the first effective comment takes precedence over others. In other words, if the string
//
occurs in a block comment, it is ignored. Similarly, if the string/*
occurs in a line or block comment, it is also ignored. For example:
// this is an inline /* comment */
/* this is a /* // block comment */
When implementing this ...
Access this course and 1400+ top-rated courses and projects.