Administrator approval is now required for registering new accounts. If you are registering a new account, and are external to the University, please ask the repository owner to contact ServiceLine to request your account be approved. Repository owners must include the newly registered email address, and specific repository in the request for approval.

Verified Commit 4d8d17c6 authored by Emily Rowlands's avatar Emily Rowlands
Browse files

Cleaned up

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