index.html 3.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. <!doctype html>
  2. <title>CodeMirror: Brainfuck mode</title>
  3. <meta charset="utf-8"/>
  4. <link rel=stylesheet href="../../doc/docs.css">
  5. <link rel="stylesheet" href="../../lib/codemirror.css">
  6. <script src="../../lib/codemirror.js"></script>
  7. <script src="../../addon/edit/matchbrackets.js"></script>
  8. <script src="./brainfuck.js"></script>
  9. <style>
  10. .CodeMirror { border: 2px inset #dee; }
  11. </style>
  12. <div id=nav>
  13. <a href="http://codemirror.net"><h1>CodeMirror</h1><img id=logo src="../../doc/logo.png"></a>
  14. <ul>
  15. <li><a href="../../index.html">Home</a>
  16. <li><a href="../../doc/manual.html">Manual</a>
  17. <li><a href="https://github.com/codemirror/codemirror">Code</a>
  18. </ul>
  19. <ul>
  20. <li><a href="../index.html">Language modes</a>
  21. <li><a class=active href="#"></a>
  22. </ul>
  23. </div>
  24. <article>
  25. <h2>Brainfuck mode</h2>
  26. <form><textarea id="code" name="code">
  27. [ This program prints "Hello World!" and a newline to the screen, its
  28. length is 106 active command characters [it is not the shortest.]
  29. This loop is a "comment loop", it's a simple way of adding a comment
  30. to a BF program such that you don't have to worry about any command
  31. characters. Any ".", ",", "+", "-", "&lt;" and "&gt;" characters are simply
  32. ignored, the "[" and "]" characters just have to be balanced.
  33. ]
  34. +++++ +++ Set Cell #0 to 8
  35. [
  36. &gt;++++ Add 4 to Cell #1; this will always set Cell #1 to 4
  37. [ as the cell will be cleared by the loop
  38. &gt;++ Add 2 to Cell #2
  39. &gt;+++ Add 3 to Cell #3
  40. &gt;+++ Add 3 to Cell #4
  41. &gt;+ Add 1 to Cell #5
  42. &lt;&lt;&lt;&lt;- Decrement the loop counter in Cell #1
  43. ] Loop till Cell #1 is zero; number of iterations is 4
  44. &gt;+ Add 1 to Cell #2
  45. &gt;+ Add 1 to Cell #3
  46. &gt;- Subtract 1 from Cell #4
  47. &gt;&gt;+ Add 1 to Cell #6
  48. [&lt;] Move back to the first zero cell you find; this will
  49. be Cell #1 which was cleared by the previous loop
  50. &lt;- Decrement the loop Counter in Cell #0
  51. ] Loop till Cell #0 is zero; number of iterations is 8
  52. The result of this is:
  53. Cell No : 0 1 2 3 4 5 6
  54. Contents: 0 0 72 104 88 32 8
  55. Pointer : ^
  56. &gt;&gt;. Cell #2 has value 72 which is 'H'
  57. &gt;---. Subtract 3 from Cell #3 to get 101 which is 'e'
  58. +++++++..+++. Likewise for 'llo' from Cell #3
  59. &gt;&gt;. Cell #5 is 32 for the space
  60. &lt;-. Subtract 1 from Cell #4 for 87 to give a 'W'
  61. &lt;. Cell #3 was set to 'o' from the end of 'Hello'
  62. +++.------.--------. Cell #3 for 'rl' and 'd'
  63. &gt;&gt;+. Add 1 to Cell #5 gives us an exclamation point
  64. &gt;++. And finally a newline from Cell #6
  65. </textarea></form>
  66. <script>
  67. var editor = CodeMirror.fromTextArea(document.getElementById("code"), {
  68. lineNumbers: true,
  69. matchBrackets: true,
  70. mode: "text/x-brainfuck"
  71. });
  72. </script>
  73. <p>A mode for Brainfuck</p>
  74. <p><strong>MIME types defined:</strong> <code>text/x-brainfuck</code></p>
  75. </article>