Skip to content
Snippets Groups Projects
Verified Commit 4d8d17c6 authored by Emily Rowlands's avatar Emily Rowlands
Browse files

Cleaned up

parent 601b0f76
No related branches found
No related tags found
No related merge requests found
...@@ -36,11 +36,6 @@ public class Interpreter { ...@@ -36,11 +36,6 @@ public class Interpreter {
INCR, DECR, CLEAR, WHILE, END, INCR, DECR, CLEAR, WHILE, END,
} }
@SuppressWarnings("unused")
private String instructionTypeToString(InstructionType it) {
return INSTRUCTION_NAMES.get(it);
}
private InstructionType stringToInstructionType(String instruction) { private InstructionType stringToInstructionType(String instruction) {
for(Entry<InstructionType, String> entry : INSTRUCTION_NAMES for(Entry<InstructionType, String> entry : INSTRUCTION_NAMES
.entrySet()) { .entrySet()) {
...@@ -73,23 +68,23 @@ public class Interpreter { ...@@ -73,23 +68,23 @@ public class Interpreter {
return m_code.get(line); return m_code.get(line);
} }
private String[] splitLine(String line) { private static String[] splitLine(String line) {
return stripWhitespace(line).split("\\s+"); return stripWhitespace(line).split("\\s+");
} }
private String[] getSplitLine(int line) {
return splitLine(getLine(line));
}
public static String stripWhitespace(String str) { public static String stripWhitespace(String str) {
return str.replaceAll("(^\\s+|\\s+$)", ""); return str.replaceAll("(^\\s+|\\s+$)", "");
} }
private String[] getSplitLine(int line) {
return splitLine(getLine(line));
}
private boolean isVariableNull(String name) { private boolean isVariableNull(String name) {
return m_vars.get(name) == null; return m_vars.get(name) == null;
} }
private void codeCheck() { private void validateCode() {
String line; String line;
String[] splitLine; String[] splitLine;
int whileDepth = 0; int whileDepth = 0;
...@@ -127,18 +122,14 @@ public class Interpreter { ...@@ -127,18 +122,14 @@ public class Interpreter {
switch (instruction) { switch (instruction) {
case WHILE: case WHILE:
whileDepth++; whileDepth++;
splitLine[4] = splitLine[1].replace( if(!splitLine[2].equals("not") || splitLine.length > 5) {
splitLine[1].substring(splitLine[1].length() - 1), "");
if(!splitLine[2].equals("not") || splitLine[4].equals("do")
|| splitLine.length > 5) {
System.err.println("Syntax error on line " + (idx + 1)); System.err.println("Syntax error on line " + (idx + 1));
System.exit(1); System.exit(1);
} }
break; break;
case END: case END:
whileDepth--; whileDepth--;
if(splitLine[0].equals("end;") && splitLine.length > 1) { if(splitLine.length > 1) {
System.err.println("Syntax error on line " + (idx + 1)); System.err.println("Syntax error on line " + (idx + 1));
System.exit(1); System.exit(1);
} }
...@@ -150,11 +141,9 @@ public class Interpreter { ...@@ -150,11 +141,9 @@ public class Interpreter {
} }
if(whileDepth > 0) { if(whileDepth > 0) {
System.err.println( System.err.println("Syntax error: unclosed while");
"There are more while statements than end statements");
} else if(whileDepth < 0) { } else if(whileDepth < 0) {
System.err.println( System.err.println("Syntax error: overclosed while");
"There are more end statements than while statements");
} }
} }
...@@ -172,7 +161,7 @@ public class Interpreter { ...@@ -172,7 +161,7 @@ public class Interpreter {
e.printStackTrace(); e.printStackTrace();
} }
codeCheck(); validateCode();
exec(); exec();
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment