How to resolve the algorithm Strip block comments step by step in the Seed7 programming language

Published on 12 May 2024 09:40 PM

How to resolve the algorithm Strip block comments step by step in the Seed7 programming language

Table of Contents

Problem Statement

A block comment begins with a   beginning delimiter   and ends with a   ending delimiter,   including the delimiters.   These delimiters are often multi-character sequences.

Strip block comments from program text (of a programming language much like classic C). Your demos should at least handle simple, non-nested and multi-line block comment delimiters.
The block comment delimiters are the two-character sequences:

Sample text for stripping: Ensure that the stripping code is not hard-coded to the particular delimiters described above, but instead allows the caller to specify them.   (If your language supports them,   optional parameters   may be useful for this.)

Let's start with the solution:

Step by Step solution about How to resolve the algorithm Strip block comments step by step in the Seed7 programming language

Source code in the seed7 programming language

$ include "seed7_05.s7i";

const proc: main is func
  local
    const string: stri is "\
        \  /**\n\
        \   * Some comments\n\
        \   * longer comments here that we can parse.\n\
        \   *\n\
        \   * Rahoo\n\
        \   */\n\
        \   function subroutine() {\n\
        \    a = /* inline comment */ b + c ;\n\
        \   }\n\
        \   /*/ <-- tricky comments */\n\
        \\n\
        \   /**\n\
        \    * Another comment.\n\
        \    */\n\
        \    function something() {\n\
        \    }";
  begin
    writeln(replace2(stri, "/*", "*/", " "));
  end func;

  

You may also check:How to resolve the algorithm Empty string step by step in the HolyC programming language
You may also check:How to resolve the algorithm Old Russian measure of length step by step in the Factor programming language
You may also check:How to resolve the algorithm Literals/Integer step by step in the COBOL programming language
You may also check:How to resolve the algorithm Mouse position step by step in the Logo programming language
You may also check:How to resolve the algorithm Zebra puzzle step by step in the Picat programming language