package org.segin.bfinterpreter;

/*
 * Copyright 2014 Kirn Gill II <segin2005@gmail.com>
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

public class Tape {
    private char[] tape;
    private int position;
    
    /* You may change this to implement larger tapes. */
    final static int size = 0x10000;

    public Tape() {
        tape = new char[size];
        position = 0;
    }

    public char get() {
        return tape[position];
    }

    public void set(char value) {
        tape[position] = value;
    }

    public void inc() {
        if (tape[position] >= 255) {
            tape[position] = 0;
        } else {
            tape[position]++;
        }
    }

    public void dec() {
        if (tape[position] <= 0) {
            tape[position] = 255;
        } else {
            tape[position]--;
        }
    }

    public void forward() {
        if (position >= (size - 1)) {
            position = 0;
        } else {
            position++;
        }
    }

    public void reverse() {
        if (position <= 0) {
            position = (size - 1);
        } else {
            position--;
        }
    }
}

@@ -713,20 +713,73 @@
 sition;%0A
+%0A
     
+/* User-defined tape size */%0A    private int usize;%0A
 %0A    /* 
@@ -882,24 +882,228 @@
 ic Tape() %7B%0A
+        usize = size;%0A        initTape();%0A    %7D%0A%0A    public Tape(int usize) %7B%0A        if((this.usize = usize) == 0)%0A            this.usize = size;%0A        initTape();%0A    %7D%0A%0A    private void initTape() %7B%0A
         tape
@@ -1114,16 +1114,17 @@
 ew char%5B
+u
 size%5D;%0A 
@@ -1653,16 +1653,17 @@
 ion %3E= (
+u
 size - 1
@@ -1800,32 +1800,32 @@
 osition %3C= 0) %7B%0A
-
             posi
@@ -1832,16 +1832,17 @@
 tion = (
+u
 size - 1

Make tape more extensible.