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

Published on 12 May 2024 09:40 PM

How to resolve the algorithm Strip block comments step by step in the Liberty BASIC 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 Liberty BASIC programming language

Source code in the liberty programming language

global CRLF$
CRLF$ =chr$( 13) +chr$( 10)

sample$ ="  /**"+CRLF$+_
"   * Some comments"+CRLF$+_
"   * longer comments here that we can parse."+CRLF$+_
"   *"+CRLF$+_
"   * Rahoo "+CRLF$+_
"   */"+CRLF$+_
"   function subroutine() {"+CRLF$+_
"    a = /* inline comment */ b + c ;"+CRLF$+_
"   }"+CRLF$+_
"   /*/ <-- tricky comments */"+CRLF$+_
""+CRLF$+_
"   /**"+CRLF$+_
"    * Another comment."+CRLF$+_
"    */"+CRLF$+_
"    function something() {"+CRLF$+_
"    }"+CRLF$

startDelim$  ="/*"
finishDelim$ ="*/"

print "________________________________"
print sample$
print "________________________________"
print blockStripped$( sample$, startDelim$, finishDelim$)
print "________________________________"

end

function blockStripped$( in$, s$, f$)
    for i =1 to len( in$) -len( s$)
        if mid$( in$, i, len( s$)) =s$ then
            i =i +len( s$)
            do
                if mid$( in$, i, 2) =CRLF$ then blockStripped$ =blockStripped$ +CRLF$
                i =i +1
            loop until ( mid$( in$, i, len( f$)) =f$) or ( i =len( in$) -len( f$))
            i =i +len( f$) -1
        else
            blockStripped$ =blockStripped$ +mid$( in$, i, 1)
        end if
    next i
end function

  

You may also check:How to resolve the algorithm Fibonacci word/fractal step by step in the C programming language
You may also check:How to resolve the algorithm Arbitrary-precision integers (included) step by step in the Frink programming language
You may also check:How to resolve the algorithm Department numbers step by step in the Go programming language
You may also check:How to resolve the algorithm Averages/Root mean square step by step in the Picat programming language
You may also check:How to resolve the algorithm Roman numerals/Decode step by step in the Maple programming language