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