Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ add another resource

JavaScript

Babel is required to process package imports. If you need a different preprocessor remove all packages first.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Behavior

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <head><h1>MNNBFSL</h1></head>

<body onload="setAreas('start')" onresize="setAreas('start')" bgcolor="#8f8f8f">  
  <table>
    <tr>
      <br><b>User Code</b></br>
      <textarea id='userCodeArea' rows='8' cols='64'>[&lt;&quot;&gt;</textarea>
    </tr>
    <tr>
      <div id='traceArea'></div>
    </tr>
    <tr>
      <table>
        <td><input type='button' onclick='run()' value='run code'/></td>
        <td><INPUT id='timeInterval' TYPE="RANGE" MIN="1" MAX="2000" STEP="25" VALUE="25"></td>
        <td><div id='traceSpeed'></div></td>
        <td><input type='button' onclick='fastrun()' value='fast run'/></td>
        <td><textarea id='maxCycles' rows='1' cols='10'>1000000</textarea></td>
      </table>
    </tr>
    <tr>
      <br><b>Standard Input</b>
      <textarea id='stdInputArea' rows='1' cols='64'></textarea></br>
    </tr>
    <tr>
      <br><b>Standard Output</b>
      <textarea id='stdOutputArea' readonly rows='1' cols='64' bgcolor="#8f8f8f"></textarea></br>
    </tr>
    <tr>
      <br><b>Standard Error</b>
      <textarea id='stdErrorArea' readonly rows='1' cols='64'></textarea></br>
    </tr>
  </table>
              
            
!

CSS

              
                
              
            
!

JS

              
                  function setAreas(mode){
    //alert('hello')
    if(mode=='start'){
      nCols= document.body.clientWidth /7.15;

      document.getElementById('userCodeArea').cols = nCols;
      document.getElementById('stdInputArea').cols = nCols;
      document.getElementById('stdOutputArea').cols = nCols;
      document.getElementById('stdOutputArea').value = '';
      document.getElementById('stdOutputArea').style.backgroundColor = 'transparent';
      document.getElementById('stdErrorArea').cols = nCols;
      document.getElementById('stdErrorArea').value = '';
      document.getElementById('stdErrorArea').style.backgroundColor = 'transparent';
    }else if(mode=='end'){
      document.getElementById('stdErrorArea').rows = stdErrorRows;
      document.getElementById('stdOutputArea').style.backgroundColor = "#b9b9b9";
      document.getElementById('stdErrorArea').style.backgroundColor = '#b9b9b9';
    }
  };

  var ERASE = -1; 
  function setColors(txtObjectId, bg, fg) {
    var txtObject = document.getElementById(txtObjectId); 
    txtObject.style.backgroundColor = bg; 
    txtObject.style.color = fg; 
  }; 

  function getValueAs(txtObjectId, asType) {
    var txtObject = document.getElementById(txtObjectId);
    var txt = txtObject.value;
    if (asType == 'string'){
      return txt; 
    } else if (asType == 'array'){
      return txt.split('');
    } else if (asType=='number') {
      return parseInt(txt); 
    } else {
      return NaN; 
    };
  };

  function addText(txtObjectId, txt, mode) {
    var txtObject =  document.getElementById(txtObjectId);
    
    if (mode==ERASE){
      txtObject.value='';
      txtObject.value += txt;
    } else {
      txtObject.value += txt;
    };
    return true;
  };

  function errorMsg(type){
    switch(type){
      case 'du':
        addText('stdErrorArea','dStack Underflow at '+iPointer)
        break;
      case 'ru':
        addText('stdErrorArea','rStack Underflow at '+iPointer)
        break;
      case 'halt':
        addText('stdErrorArea','halt instructions at '+iPointer)
        break;
    };
    endFlag=true;
  };

  function repeat(c, n){
      if(n==0){return ''};
      rt=''
      for (var i = n; i > 0; i--) {
        rt+=c
      };
      return rt;
   }

  function format(match, p1,p2,offset,string){
    if(p2=='0'){
      return '[<[-"]'
    }else{
      return '[<[-"]' + repeat(p1, parseInt(p2,10));
    }
  }

  function init(){
    temp = document.getElementById("userCodeArea");
    original = getValueAs(temp.id, 'string');
    tempText=original
    tempText=tempText.replace(/([\+\-]*)(\d+)/g, format)
    document.getElementById('userCodeArea').value=tempText;
   // tempText=tempText.replace(/\*(\d+)/ , calcSmall)

    setAreas('start');
    stdErrorRows=0;
    endFlag=false;
    rStack=new Array();
    dStack=new Array();
    iPointer=0;
    cycles=0;

    userCode=getValueAs('userCodeArea','array');
    document.getElementById('userCodeArea').value=original;
    stdInputText=getValueAs('stdInputArea','string');

    stdInputPos=0;
  };

  function fastrun(){
    init();
    traceFlag=0;
    while(endFlag!=true && cycles<20000000){
      interpret();
      cycles++;
    };
    setAreas('end');

  }
  function run(){
    //alert('start')
    init();
    setColors('traceArea','black','white');
     
    traceFlag=1;
    interpret();
    setAreas('end');
  };

  function interpret(){
    if(endFlag!=true){
      if(traceFlag==1){
        var count = 0;
        var text='';
        var clen=userCode.length;
        var e=document.getElementById('traceArea');
        
        for (var ix=0; ix<clen; ix++) {
          var re = userCode[ix].replace("<","&lt;");
          re = re.replace(">","&gt;");
          re = re.replace("s","s("+ix.toString()+")")
          if (count==iPointer){
            text += '<span style="color: #FF0000; text-decoration: underline;">' + re + '</span>';
          }else{
            text += re;
          }
          count++;
        };
          stackState = '';
          dStack.reverse();
          stackState += dStack.toString() + ' / ';
          dStack.reverse();
          stackState += rStack.toString();
          tInterval=document.getElementById('timeInterval').value;
          e.innerHTML ="<pre>" + text + "\n\n"+ iPointer.toString()+': '+stackState+"\rtraceSpeed="+tInterval+" cycles: "+cycles+"</pre>";

          tInterval=document.getElementById('timeInterval').value;
          tspeed=document.getElementById('traceSpeed')
          tspeed.innerHTML='<pre>'+tInterval+'</pre>'
          setColors('traceSpeed','transparent','black')
        };        

      switch (userCode[iPointer]){
        case '+':
          //alert('+');
          if(dStack[0]==undefined){
            errorMsg('du');
          }else{
            dStack[0]++;
          }
          break;
        case '-':
          if(dStack[0]==undefined){
            errorMsg('du');
          }else{
            dStack[0]--;
          }
          break;
        case '>':
          if(dStack[0]==undefined){
            errorMsg('du');
          } else {
            rStack.unshift(dStack[0]);
            dStack.shift();
          };
          break;
        case '<':
          if(rStack[0]==undefined){
            errorMsg('ru');
          } else {
            dStack.unshift(rStack[0]);
            rStack.shift();
          };
          break;
        case '[':
          rStack.unshift(iPointer);
          break;
        case ']':
          if(dStack[0]==undefined){
            errorMsg('du');
          } else {
            if(dStack[0]==0){
              dStack.shift();
              rStack.shift();
            } else {
              if(rStack[0]==undefined){
                errorMsg('ru');
              }else{
                iPointer=rStack[0]-1;
                dStack.shift();
                rStack.shift();
              };
            };
          };
          break;
        case ',':
          if(stdInputPos<stdInputText.length){
            dStack.unshift(stdInputText[stdInputPos].charCodeAt(0));
            dStack.unshift(1);
            stdInputPos++;
          }else{
            dStack.unshift(0);
          }
          break;
        case '.':
          if(dStack[0]==undefined){
              errorMsg('du');
            } else {
              addText('stdOutputArea',String.fromCharCode(dStack[0]));
              dStack.shift();
            };
          break;
        case '"':
          if(dStack[0]==undefined){
            errorMsg('du');
          } else {
            dStack.unshift(dStack[0]);
          };
          break;
        case 's':
          var stackState = '';
          dStack.reverse();
          stackState += dStack.toString() + ' / ';
          dStack.reverse();
          stackState += rStack.toString();
          addText("stdErrorArea",stackState+'\r');
          stdErrorRows++;
          break;
        case 'h':
          errorMsg('halt')
          break;
      };
      iPointer++;
      if(iPointer>=userCode.length){endFlag=true};
      if(traceFlag==0){
        return;
      }else if(traceFlag==1 && endFlag!=true){
          setTimeout(function(){interpret()},tInterval);
        
      }else{

      };
    };
    return;
  };
              
            
!
999px

Console