Execute Brain****: Difference between revisions

Added dodo0 implementation
m ({{omit from|GUISS}})
(Added dodo0 implementation)
Line 230:
++++..+++.>++.<<+++++++++++++++.>.+++.------.--------.>+.>."));
}</lang>
 
=={{header|dodo0}}==
 
<lang dodo0>clojure('count', 1) -> count
clojure('nth', 2) -> charAt
clojure('inc', 1) -> inc
clojure('dec', 1) -> dec
clojure('char', 1) -> char
clojure('int', 1) -> int
charAt("\n", 0) -> newLine
charAt("@", 0) -> exitCommand
charAt("+", 0) -> incrCommand
charAt("-", 0) -> decrCommand
charAt("<", 0) -> shlCommand
charAt(">", 0) -> shrCommand
charAt(".", 0) -> printCommand
charAt(",", 0) -> readCommand
charAt("[", 0) -> repeatCommand
charAt("]", 0) -> endCommand
 
fun readChar -> return
(
'read-line'() -> line
count(line) -> length
fun nextFromLine -> i, return
(
'='(i, length) -> eol
if (eol) ->
(
return(newLine, readChar)
)
|
charAt(line, i) -> value
inc(i) -> i
fun next (-> return) nextFromLine(i, return) | next
return(value, next)
)
| nextFromLine
nextFromLine(0, return)
)
| readChar
 
fun empty (-> return, throw) throw("Error: out of bounds") | empty
fun fill (-> return, throw) return(0, fill) | fill
 
fun makeBuffer -> value, left, right, return
(
fun buffer (-> return) return(value, left, right) | buffer
return(buffer)
)
| makeBuffer
 
fun push -> value, stack, return
(
fun newStack (-> return, throw) return(value, stack) | newStack
return(newStack)
)
| push
 
fun increment -> buffer, input, return
(
buffer() -> value, left, right
inc(value) -> value
makeBuffer(value, left, right) -> buffer
return(buffer, input)
)
| increment
 
fun decrement -> buffer, input, return
(
buffer() -> value, left, right
dec(value) -> value
makeBuffer(value, left, right) -> buffer
return(buffer, input)
)
| decrement
 
fun shiftLeft -> buffer, input, return
(
buffer() -> value, left, right
push(value, right) -> right
left() -> value, left
(
makeBuffer(value, left, right) -> buffer
return(buffer, input)
)
| message
println(message) ->
exit()
)
| shiftLeft
 
fun shiftRight -> buffer, input, return
(
buffer() -> value, left, right
push(value, left) -> left
right() -> value, right
(
makeBuffer(value, left, right) -> buffer
return(buffer, input)
)
| message
println(message) ->
exit()
)
| shiftRight
 
fun putChar -> buffer, input, return
(
buffer() -> value, left, right
char(value) -> value
'print'(value) -> dummy
return(buffer, input)
)
| putChar
 
fun getChar -> buffer, input, return
(
input() -> letter, input
int(letter) -> letter
buffer() -> value, left, right
makeBuffer(letter, left, right) -> buffer
return(buffer, input)
)
| getChar
 
fun whileLoop -> buffer, input, continue, break
(
buffer() -> value, left, right
'='(value, 0) -> zero
if (zero) ->
(
break(buffer, input)
)
|
(
continue(buffer, input) -> buffer, input
whileLoop(buffer, input, continue, break)
)
)
| whileLoop
 
fun noop -> buffer, input, return
(
return(buffer, input)
)
| noop
 
fun compile -> input, endmark, return
(
input() -> command, input
'='(command, repeatCommand) -> opRepeat
'='(command, endmark) -> opEnd
 
if (opRepeat) ->
(
compile(input, endCommand) -> body, input
compile(input, endmark) -> program, input
fun repeat -> buffer, input, return
(
whileLoop(buffer, input, body) -> buffer, input
program(buffer, input, return)
)
| repeat
return(repeat, input)
)
|
if (opEnd) ->
(
return(noop, input)
)
|
(
fun select -> return
(
'='(command, incrCommand) -> y
if (y) ->
return(increment)
|
'='(command, decrCommand) -> y
if (y) ->
return(decrement)
|
'='(command, printCommand) -> y
if (y) ->
return(putChar)
|
'='(command, readCommand) -> y
if (y) ->
return(getChar)
|
'='(command, shlCommand) -> y
if (y) ->
return(shiftLeft)
|
'='(command, shrCommand) -> y
if(y) ->
return(shiftRight)
|
(
'str'("Unexpected input, skipping: ", command) -> message
println(message) ->
return(noop)
)
)
| select
 
select() -> op
compile(input, endmark) -> program, input
 
fun exec -> buffer, input, return
(
op(buffer, input) -> buffer, input
program(buffer, input, return)
)
| exec
return(exec, input)
)
)
| compile
 
compile(readChar, exitCommand) -> program, input
makeBuffer(0, empty, fill) -> buffer
 
program(buffer, input) -> buffer, input
exit()</lang>
Execution:
<pre>
$ java -classpath antlr-3.2.jar:clojure-1.2.0/clojure.jar:. clojure.main dodo/runner.clj bfc2.do0
++++++++++[>+++++++>++++++++++>+++>+<<<<-]>++.>+.+++++++..+++.>++.<<+++++++++++++++.>.+++.------.--------.>+.>.@
Hello World!
</pre>
 
=={{header|E}}==
Anonymous user