Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Fixed an error reporting issue in the parse() function, still not com…

…plete. Everything is back where I like it for now.
  • Loading branch information...
commit 4629657330f6a2f35b854403303d98a094c6d817 1 parent 41efba2
@JoshDreamland JoshDreamland authored
View
35 src/assemblernator/Instruction.java
@@ -206,18 +206,23 @@ public static final Instruction parse(String line) throws Exception,
i += label.length(); // Skip the label
instruction = label;
label = null;
- } else {
- if (i != 0)
- throw new Exception(
- "URBAN specification says labels must start at column 0 ("
- + label
- + " is "
- + (IOFormat.isAlpha(label) ? "not an"
- : "an invalid")
- + " instruction, starts at column" + i + ")");
- i += label.length(); // Skip the label we read earlier
- while (Character.isWhitespace(line.charAt(i)))
- ++i; // Skip whitespace between label and instruction
+ }
+ else {
+ if (i != 0)// @formatter:off
+ throw new Exception("URBAN specification says labels must start at column 0 ("
+ + label + " is " + (IOFormat.isAlpha(label) ? "not an" : "an invalid")
+ + " instruction, starts at column" + i + ")");
+ // @formatter:on
+
+ // Skip the label we read earlier
+ i += label.length();
+
+ do
+ // Skip whitespace between label and instruction
+ if (++i > line.length())
+ throw new IOException("RAL");
+ while (Character.isWhitespace(line.charAt(i)));
+
instruction = IOFormat.readLabel(line, i); // Read instruction now
if (!Assembler.instructions.containsKey(instruction)) {
if (IOFormat.isAlpha(instruction))
@@ -302,8 +307,7 @@ public static final Instruction parse(String line) throws Exception,
* @return Returns a semantic match to the original instruction code string.
* @specRef N/A
*/
- @Override
- public String toString() {
+ @Override public String toString() {
String res = (label.length() > 0 ? label + "\t" : "") + getOpId();
for (Entry<String, String> op : operands.entrySet()) {
res += "\t" + op.getKey() + ":" + op.getValue();
@@ -315,8 +319,7 @@ public String toString() {
* Default constructor. The constructor is protected so that the parse()
* method must be used externally to obtain an Instruction.
*/
- protected Instruction() {
- }
+ protected Instruction() {}
/**
* Default constructor. The constructor is protected so that the parse()
View
13 src/assemblernator/Main.java
@@ -1,9 +1,12 @@
package assemblernator;
+import java.io.IOException;
+
import instructions.MOVD_Instruction;
+
/**
* @author Ratul Khosla, Eric Smith, Noah Torrance, Josh Ventura
- *
+ *
*/
/**
@@ -18,17 +21,19 @@
*/
public static void main(String[] args) {
System.out.println("Hello World\n");
-
+
MOVD_Instruction.getInstance();
-
+
try {
- Instruction i = Instruction.parse("lolol MOVD EX:'For great justice';");
+ Instruction i = Instruction.parse("lolol");
if (i != null) {
System.out.println("Success!");
System.out.println(i);
}
else
System.out.println("More info requested.");
+ } catch (IOException e) {
+ System.out.println("Requested another line (" + e.getMessage() + ")");
} catch (Exception e) {
System.out.println("CRITICAL FAILURE. HAHAHAHAHAHAHAHA");
e.printStackTrace();
View
7 src/instructions/MOVD_Instruction.java
@@ -4,6 +4,7 @@
/**
* The MOVD instruction.
+ *
* @author Josh Ventura
* @date Apr 6, 2012; 6:15:36 PM
*/
@@ -31,19 +32,19 @@ public int getWordCount() {
/** @see assemblernator.Instruction#check() */
@Override
public boolean check() {
- return false; //TODO: IMPLEMENT
+ return false; // TODO: IMPLEMENT
}
/** @see assemblernator.Instruction#assemble() */
@Override
public int[] assemble() {
- return null; //TODO: IMPLEMENT
+ return null; // TODO: IMPLEMENT
}
/** @see assemblernator.Instruction#execute(int) */
@Override
public void execute(int instruction) {
- //TODO: IMPLEMENT
+ // TODO: IMPLEMENT
}
/** @see assemblernator.Instruction#getNewInstance() */
Please sign in to comment.
Something went wrong with that request. Please try again.