Execute Brain****/JavaScript: Difference between revisions

m
Fixed syntax highlighting.
(New page: {{implementation|Brainf***}}{{collection|RCBF}}Category:JavaScript Presented here is the core of a Brainf*** interpreter/debugger designed to run within a web page. The full source can...)
 
m (Fixed syntax highlighting.)
 
(8 intermediate revisions by 6 users not shown)
Line 1:
{{implementation|Brainf***}}{{collection|RCBF}}[[Category:JavaScript]]
Presented here is the core of a Brainf*** interpreter/debugger written in [[JavaScript]] that is designed to run within a web page. The full source can be found at http://www.quirkster.com/iano/js/bf.html by viewing the page source.
 
<syntaxhighlight lang="javascript">var code; // formatted code
<pre>
var code; // formatted code
var ip = 0; // current instruction within code
var nest = 0; // current bracket nesting (for Out button)
Line 22 ⟶ 21:
']':function() { if ( data[dp]) ip = ahead[ip]; else --nest },
',':function() {
data[dp]var c = document.getElementById("input").value.charCodeAt(inp++);
if (isNaN(data[dp]) = isNaN(c) {? data[dp]=0; quit++: c; } // EOF: other options are -1 or no change
},
'.':function() {
var s = document.getElementById("output").innerHTML
+ String.fromCharCode(data[dp]);
s = s.replace(/\n/g,"<br>").replace(/ /g,"&amp;nbsp;");
document.getElementById("output").innerHTML = s;
},
Line 64 ⟶ 63:
 
function encode(s) {
var e = s.replace(/&/g, "&amp;amp;");
e = e.replace(/</g, "&amp;lt;");
e = e.replace(/>/g, "&amp;gt;");
e = e.replace(/ /g, "&amp;nbsp;");
return e.replace(/\n/g, "<br>");
}
Line 136 ⟶ 135:
body();
dump();
}</syntaxhighlight>
}
</pre>
9,476

edits