Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Using enums now.

  • Loading branch information...
commit 7398c0004029f2b8a2fd1b12deb72961f2d767ab 2 parents 038e073 + 8723f86
@fabianm authored
Showing with 61 additions and 0 deletions.
  1. +61 −0 src/org/faabtech/brainfuck/impl/OokEngine.java
View
61 src/org/faabtech/brainfuck/impl/OokEngine.java
@@ -138,19 +138,30 @@ public void interpret(String str) throws Exception {
// Loop through all tokens.
for (int tokenPointer = 0; tokenPointer < tokens.size(); ) {
+<<<<<<< HEAD
Token token = tokens.get(tokenPointer);
switch(token) {
case NEXT:
+=======
+ String token = tokens.get(tokenPointer);
+ if (token.equals(Token.NEXT)) {
+>>>>>>> 8723f8655b1c5e2155a86b8bcc3b763ee484ab29
// increment the data pointer (to point to the next cell
// to the
// right).
dataPointer = (dataPointer == data.length - 1 ? 0 : dataPointer + 1);
+<<<<<<< HEAD
break;
case PREVIOUS:
+=======
+ }
+ if (token.equals(Token.PREVIOUS)) {
+>>>>>>> 8723f8655b1c5e2155a86b8bcc3b763ee484ab29
// decrement the data pointer (to point to the next cell
// to the
// left).
dataPointer = (dataPointer == 0 ? data.length - 1 : dataPointer - 1);
+<<<<<<< HEAD
break;
case PLUS:
// increment (increase by one) the byte at the data
@@ -174,6 +185,29 @@ public void interpret(String str) throws Exception {
data[dataPointer] = (byte) consoleReader.read();
break;
case BRACKET_LEFT:
+=======
+ }
+ if (token.equals(Token.PLUS)) {
+ // increment (increase by one) the byte at the data
+ // pointer.
+ data[dataPointer]++;
+ }
+ if (token.equals(Token.MINUS)) {
+ // decrement (decrease by one) the byte at the data
+ // pointer.
+ data[dataPointer]--;
+ }
+ if (token.equals(Token.OUTPUT)) {
+ // Output the byte at the current index in a character.
+ outWriter.write((char) data[dataPointer]);
+ }
+ if (token.equals(Token.INPUT)) {
+ // accept one byte of input, storing its value in the
+ // byte at the data pointer.
+ data[dataPointer] = (byte) consoleReader.read();
+ }
+ if (token.equals(Token.BRACKET_LEFT)) {
+>>>>>>> 8723f8655b1c5e2155a86b8bcc3b763ee484ab29
if (data[dataPointer] == 0) {
int level = 1;
while (level > 0) {
@@ -185,8 +219,13 @@ else if (tokens.get(tokenPointer).equals(Token.BRACKET_RIGHT))
level--;
}
}
+<<<<<<< HEAD
break;
case BRACKET_RIGHT:
+=======
+ }
+ if (token.equals(Token.BRACKET_RIGHT)) {
+>>>>>>> 8723f8655b1c5e2155a86b8bcc3b763ee484ab29
if (data[dataPointer] != 0) {
int level = 1;
while (level > 0) {
@@ -207,5 +246,27 @@ else if (tokens.get(tokenPointer).equals(Token.BRACKET_RIGHT))
initate(data.length);
}
+<<<<<<< HEAD
+=======
+ /**
+ * Is the given token a valid <code>Ook!</code> token.
+ *
+ * @param token
+ * The token to check.
+ * @return <code>true</code> if the given token is a valid
+ * <code>Ook!</code> token, <code>false</code> otherwise.
+ */
+ protected boolean isValidToken(String token) {
+ if (token.equals(Token.NEXT)
+ || token.equals(Token.PREVIOUS) || token.equals(Token.PLUS)
+ || token.equals(Token.MINUS) || token.equals(Token.OUTPUT)
+ || token.equals(Token.INPUT)
+ || token.equals(Token.BRACKET_LEFT)
+ || token.equals(Token.BRACKET_RIGHT)) {
+ return true;
+ }
+ return false;
+ }
+>>>>>>> 8723f8655b1c5e2155a86b8bcc3b763ee484ab29
}
Please sign in to comment.
Something went wrong with that request. Please try again.