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

Published on 12 May 2024 09:40 PM

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

Source code in the tuscript programming language

$$ MODE DATA
$$ script=*
  /**
   * Some comments
   * longer comments here that we can parse.
   *
   * Rahoo
   */
   function subroutine() {
    a = /* inline comment */ b + c ;
   }
   /*/ <-- tricky comments  */

   /**
    * Another comment.
    */
    function something() {
    }
$$ MODE TUSCRIPT
ERROR/STOP CREATE ("testfile",SEQ-E,-std-)
ERROR/STOP CREATE ("destfile",SEQ-E,-std-)
FILE "testfile" = script
BUILD S_TABLE commentbeg=":/*:"
BUILD S_TABLE commentend=":*/:"

ACCESS t: READ/STREAM "testfile" s.z/u,a/commentbeg+t+e/commentend,typ
ACCESS d: WRITE/STREAM "destfile" s.z/u,a+t+e
LOOP
READ/EXIT t
IF (typ==3) CYCLE
t=SQUEEZE(t)
WRITE/ADJUST d
ENDLOOP
ENDACCESS/PRINT t
ENDACCESS/PRINT d
d=FILE("destfile")
TRACE *d

  

You may also check:How to resolve the algorithm Sailors, coconuts and a monkey problem step by step in the REXX programming language
You may also check:How to resolve the algorithm Assertions step by step in the MATLAB / Octave programming language
You may also check:How to resolve the algorithm Hello world/Graphical step by step in the Ol programming language
You may also check:How to resolve the algorithm Weird numbers step by step in the Nim programming language
You may also check:How to resolve the algorithm Classes step by step in the Nemerle programming language