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) { |
||
var chars = code.chars; |
|||
accumulator = 0; |
accumulator = 0; |
||
pointer = 0; |
pointer = 0; |
||
while (pointer < |
while (pointer < chars.len) { |
||
given ( |
given (chars[pointer].lc) { |
||
when ('h') { say 'Hello world!' } |
when ('h') { say 'Hello world!' } |
||
when ('q') { say code |
when ('q') { say code } |
||
when ('9') { bob(99) } |
when ('9') { bob(99) } |
||
when ('+') { accumulator++ } |
when ('+') { accumulator++ } |
||
default { warn %Q(Syntax error: Unknown command "#{ |
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> |
||