Execute HQ9+: Difference between revisions

Content added Content deleted
m (Added Sidef)
m (→‎{{header|Sidef}}: minor code fixes)
Line 1,247: Line 1,247:


method run (code) {
method run (code) {
code = code.chars;
var chars = code.chars;
accumulator = 0;
accumulator = 0;
pointer = 0;
pointer = 0;
while (pointer < code.len) {
while (pointer < chars.len) {
given (code[pointer].lc) {
given (chars[pointer].lc) {
when ('h') { say 'Hello world!' }
when ('h') { say 'Hello world!' }
when ('q') { say code.join(' ') }
when ('q') { say code }
when ('9') { bob(99) }
when ('9') { bob(99) }
when ('+') { accumulator++ }
when ('+') { accumulator++ }
default { warn %Q(Syntax error: Unknown command "#{code[pointer]}") }
default { warn %Q(Syntax error: Unknown command "#{chars[pointer]}") }
}
}
pointer++;
pointer++;
Line 1,271: Line 1,271:
Hello world!
Hello world!
Hello world!
Hello world!
hHq+++Qq
h H q + + + Q q
hHq+++Qq
h H q + + + Q q
hHq+++Qq
h H q + + + Q q
</pre>
</pre>