How to resolve the algorithm Execute HQ9+ step by step in the Liberty BASIC programming language

Published on 12 May 2024 09:40 PM

How to resolve the algorithm Execute HQ9+ step by step in the Liberty BASIC programming language

Table of Contents

Problem Statement

Implement a   HQ9+   interpreter or compiler.

Let's start with the solution:

Step by Step solution about How to resolve the algorithm Execute HQ9+ step by step in the Liberty BASIC programming language

Source code in the liberty programming language

'Try this hq9+ program - "hq9+HqQ+Qq"
Prompt "Please input your hq9+ program."; code$
Print hq9plus$(code$)
End

Function hq9plus$(code$)
    For i = 1 to Len(code$)
        Select Case
            Case Upper$(Mid$(code$, i, 1)) = "H"
                hq9plus$ = hq9plus$ + "Hello, world!"
            Case Upper$(Mid$(code$, i, 1)) = "Q"
                hq9plus$ = hq9plus$ + code$
            Case Mid$(code$, i, 1) = "9"
                For bottles = 99 To 1 Step -1
                     hq9plus$ = hq9plus$ + str$(bottles) + " bottle"
                     If (bottles > 1) Then hq9plus$ = hq9plus$ + "s"
                     hq9plus$ = hq9plus$ + " of beer on the wall, " + str$(bottles) + " bottle"
                     If (bottles > 1) Then hq9plus$ = hq9plus$ + "s"
                     hq9plus$ = hq9plus$ + " of beer,"  + chr$(13) + chr$(10) + "Take one down, pass it around, " + str$(bottles - 1) + " bottle"
                     If (bottles > 2) Or (bottles = 1) Then hq9plus$ = hq9plus$ + "s"
                     hq9plus$ = hq9plus$ + " of beer on the wall." + chr$(13) + chr$(10)
                Next bottles
                hq9plus$ = hq9plus$ + "No more bottles of beer on the wall, no more bottles of beer." _
                                    + chr$(13) + chr$(10) + "Go to the store and buy some more, 99 bottles of beer on the wall."
            Case Mid$(code$, i, 1) = "+"
                accumulator = (accumulator + 1)
        End Select
        If Mid$(code$, i, 1) <> "+" Then
            hq9plus$ = hq9plus$ + chr$(13) + chr$(10)
        End If
    Next i
    hq9plus$ = Left$(hq9plus$, (Len(hq9plus$) - 2))
End Function

  

You may also check:How to resolve the algorithm Palindrome detection step by step in the Clojure programming language
You may also check:How to resolve the algorithm Linear congruential generator step by step in the Liberty BASIC programming language
You may also check:How to resolve the algorithm Attractive numbers step by step in the XPL0 programming language
You may also check:How to resolve the algorithm Primality by trial division step by step in the Picat programming language
You may also check:How to resolve the algorithm Vigenère cipher step by step in the R programming language