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

Published on 12 May 2024 09:40 PM

How to resolve the algorithm Execute HQ9+ step by step in the Ceylon 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 Ceylon programming language

Source code in the ceylon programming language

shared void run() {
	
	void eval(String code) {

		variable value accumulator = 0;

		for(c in code.trimmed.lowercased) {
			switch(c)
			case('h') {
				print("Hello, world!");
			}
			case('q') {
				print(code);
			}
			case('9') {
				function bottles(Integer i) =>
						switch(i)
						case(0) "No bottles"
						case(1) "One bottle"
						else "``i`` bottles";
				for(i in 99..1) {
					print("``bottles(i)`` of beer on the wall,
					       ``bottles(i)`` of beer,
					       take one down and pass it around,
					       ``bottles(i - 1)`` of beer on the wall!");
				}
			}
			case('+') {
				accumulator++;
			}
			else {
				print("syntax error");
			}
		}
	}
	
	eval("hq9+");
}


  

You may also check:How to resolve the algorithm Date format step by step in the NewLISP programming language
You may also check:How to resolve the algorithm N-queens problem step by step in the BBC BASIC programming language
You may also check:How to resolve the algorithm Create an HTML table step by step in the C++ programming language
You may also check:How to resolve the algorithm Parsing/RPN calculator algorithm step by step in the MiniScript programming language
You may also check:How to resolve the algorithm Rare numbers step by step in the Julia programming language