brainfuck.xsltSometimes it is fun to implement something using tools extremely unsuitable for the job. Especially if what is implemented is quite pointless in itself. When learning XSLT I decided that implementing a Brainfuck interpreter in pure XSLT would be non-trivial, fun, a good learning experience, and completely useless.Download The brainfuck.xslt stylesheet transforms a brainfuck
xml document to an output
brainfuck xml document, by running the Brainfuck program in the
/brainfuck/code element with /brainfuck/input as input. Be sure to
escape the brainfuck statements properly as XML requires. Characters
in the code element which are not brainfuck instructions are
ignored.
No xslt extensions are used, just plain xslt 1.0.
The array is dynamically resized on the right (>) side when needed
and can be considered to be of infinite size. To see the array for
every statement processed, pass parameter "debug" with a value
evaluating to true() to the stylesheet.
Be aware that, since the brainfuck.xslt stylesheet works with recursion, some xslt
processors will eat lots of memory and/or segfault when running
large complicated Brainfuck programs.
For example, the documents:
and:
both produce the document:
The document:
will produce:
The brainfuck.xslt stylesheet is available at
http://www.lysator.liu.se/~jc/hacks/brainfuck.xslt
|
|
Jörgen Cederlöf <jc@lysator.liu.se> |