Commits

Joey E  committed 7e7d33f Merge

Merge remote-tracking branch 'origin/master'

  • Participants
  • Parent commits e7f6f9b, 236801b

Comments (0)

Files changed (102)

File src/ca/usask/cs/giraffe/CompilerController.java

  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  * GNU General Public License for more details.
- *
+ * 
  * You should have received a copy of the GNU General Public License
  * along with Giraffe.  If not, see <http://www.gnu.org/licenses/>.
  */
 	 * Sends a valid AnimationStrip, the result of compiling the most recently
 	 * given C program, to the controller.
 	 * 
-	 * @param as the AnimationStrip
+	 * @param as
+	 *            the AnimationStrip
 	 */
 	void createdStrip(AnimationStrip as);
-
+	
 	/**
 	 * Passes an error message to the GUI indicating that an error was caused by
 	 * one of the following:
 	 * <ul>
-	 *     <li>Unsupported C language features</li>
-	 * 	   <li>A parse error (probably weird syntax)</li>
-	 *     <li>A general animation strip error (possibly more border cases)</li>
+	 * <li>Unsupported C language features</li>
+	 * <li>A parse error (probably weird syntax)</li>
+	 * <li>A general animation strip error (possibly more border cases)</li>
 	 * </ul>
 	 * The GUI should highlight the part of the program file in between
 	 * {@code startIndex} and {@code endIndex}, or if either of them are -1, no
-	 * highlighting should occur (and any previous highlighting should be cleared)
+	 * highlighting should occur (and any previous highlighting should be
+	 * cleared)
 	 * 
-	 * @param message A user-friendly error message indicating the error that
-	 *                occurred.
-	 *                <p>
-	 *                FIXME - If the above error conditions are disjoint and
-	 *                comprehensive it may make more sense to have fixed error
-	 *                messages for each of the above cases.
-	 * @param startIndex The start character index of the loaded source file that caused the error, or -1 if there is no reasonable location.
-	 * @param endIndex The end character index of the loaded source file that caused the error, or -1 if there is no reasonable location.
+	 * @param message
+	 *            A user-friendly error message indicating the error that
+	 *            occurred.
+	 *            <p>
+	 *            FIXME - If the above error conditions are disjoint and
+	 *            comprehensive it may make more sense to have fixed error
+	 *            messages for each of the above cases.
+	 * @param startIndex
+	 *            The start character index of the loaded source file that
+	 *            caused the error, or -1 if there is no reasonable location.
+	 * @param endIndex
+	 *            The end character index of the loaded source file that caused
+	 *            the error, or -1 if there is no reasonable location.
 	 */
 	void errorCreatingStrip(String message, int startIndex, int endIndex);
-
+	
 	/**
 	 * Sends the result of one output call to the GUI.
 	 * <p>
 	/**
 	 * Returns a string of input obtained from the GUI.
 	 * <p>
-	 * <b>WARNING: </b> This function blocks until the string is actually 
+	 * <b>WARNING: </b> This function blocks until the string is actually
 	 * obtained. It also represents a serious roundabout around the message
-	 * passing we use in GIRAFFE. However, this is required as we currently 
+	 * passing we use in GIRAFFE. However, this is required as we currently
 	 * don't have callbacks, blocking message delivery, or the ability to return
 	 * values from messages send.
-	 * @return The string of input the user provided, or the empty string if and only if
-	 *         the backend should bail on its attempt to compile the source file.
-	 *         (the user might want to load a different source file, for example)'
+	 * 
+	 * @return The string of input the user provided, or the empty string if and
+	 *         only if
+	 *         the backend should bail on its attempt to compile the source
+	 *         file.
+	 *         (the user might want to load a different source file, for
+	 *         example)'
 	 * @throws InterruptedException
 	 */
 	String requestInputAndWait() throws InterruptedException;

File src/ca/usask/cs/giraffe/Giraffe.java

  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  * GNU General Public License for more details.
- *
+ * 
  * You should have received a copy of the GNU General Public License
  * along with Giraffe.  If not, see <http://www.gnu.org/licenses/>.
  */
 
 /**
  * Entryway class.
+ * 
  * @author Alex Mair (ajm513@mail.usask.ca)
  */
 public class Giraffe {
 	/**
 	 * Entryway.
-	 * @param args not used, for now. Will be utilised eventually.
+	 * 
+	 * @param args
+	 *            not used, for now. Will be utilised eventually.
 	 */
 	public static void main(String args[]) {
 		try {
 			GiraffeLogger.info("Starting up...");
 			Controller c = new Controller();
 			GiraffeLogger.info("Done controller.");
-
+			
 			GiraffeLogger.info("Setting up UI...");
 			UI ui = new UI(c);
 			c.setViewDelegate(ui);
 			GiraffeLogger.info("Done.");
-
+			
 			GiraffeLogger.info("Setting up backend...");
 			CompilerReceiver cr = new CompilerReceiver(c);
 			c.setBackendDelegate(cr);
 			 * FIXME(alex): The threading seriously breaks this - if some random
 			 * thread throws an exception we have no way to encounter it here.
 			 */
-			GiraffeLogger.error("Giraffe has encountered an error it does not "+
-					"know how to handle and will now close.");
+			GiraffeLogger.error("Giraffe has encountered an error it does not "
+					+ "know how to handle and will now close.");
 		}
 	}
 }

File src/ca/usask/cs/giraffe/UIController.java

  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  * GNU General Public License for more details.
- *
+ * 
  * You should have received a copy of the GNU General Public License
  * along with Giraffe.  If not, see <http://www.gnu.org/licenses/>.
  */
  * Controller class should implement this interface)
  * 
  * @author isv452
- * 
  */
 public interface UIController extends GiraffeAction {
 	/**
 	 * Tell the controller to load a given file
 	 * 
-	 * @param filePath the absolute path to the file
+	 * @param filePath
+	 *            the absolute path to the file
 	 */
 	void loadFile(String filePath);
-
+	
 	/**
 	 * Tell the controller to compile the most recently loaded file
-	 * @deprecated The file should be automatically compiled upon successful load.
+	 * 
+	 * @deprecated The file should be automatically compiled upon successful
+	 *             load.
 	 */
 	void compile();
 	
 	 * Report to the controller that the user clicked "previous line"
 	 */
 	void stepBackward();
-
+	
 	/**
 	 * Report to the controller that the user clicked "next line"
 	 */
 	void stepForward();
-
+	
 	/**
 	 * Send a line of input that the user gave to the Controller (and
 	 * eventually, the backend)
 	 * 
-	 * @param input One line of input that was obtained via some input function
+	 * @param input
+	 *            One line of input that was obtained via some input function
 	 *            (such as <code>cin</code>, <code>scanf()</code>, etc).
 	 */
 	void sendInput(String input);
-
+	
 	/**
 	 * Resets the animation state: stops and clears all animations, sets the
 	 * currently highlighted line to the first line, ...
 	 */
 	void stop();
-
+	
 	/**
 	 * Suspends the automatic step forward.
 	 * <p>
 	 * again.
 	 */
 	void pause();
-
+	
 	/**
 	 * The controller will automatically step forward animations at a fixed
 	 * speed.

File src/ca/usask/cs/giraffe/compiler/AbstractValue.java

  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  * GNU General Public License for more details.
- *
+ * 
  * You should have received a copy of the GNU General Public License
  * along with Giraffe.  If not, see <http://www.gnu.org/licenses/>.
  */
  * for all operations on values
  * 
  * @author Joey Eremondi
- * 
  */
 public abstract class AbstractValue implements Value {
-
+	
 	// Functions for each operator
 	// Return invalid type exception by default
 	@Override
 	public Value plus(Value that) throws ExecutionErrorException {
-		throw new InvalidTypeException("Type error: cannot add " + this.type() + " and "
-				+ that.type());
+		throw new InvalidTypeException("Type error: cannot add " + this.type() +
+				" and " + that.type());
 	}
-
+	
 	@Override
 	public Value minus(Value that) throws ExecutionErrorException {
-		throw new InvalidTypeException("Type error: cannot subtract " + that.type()
-				+ " from " + this.type());
+		throw new InvalidTypeException("Type error: cannot subtract " +
+				that.type() + " from " + this.type());
 	}
-
+	
 	@Override
 	public Value negate() throws ExecutionErrorException {
-		throw new InvalidTypeException("Type error: cannot negate " + this.type());
+		throw new InvalidTypeException("Type error: cannot negate " +
+				this.type());
 	}
-
+	
 	@Override
 	public Value mult(Value that) throws ExecutionErrorException {
-		throw new InvalidTypeException("Type error: cannot multiply " + this.type()
-				+ " and " + that.type());
+		throw new InvalidTypeException("Type error: cannot multiply " +
+				this.type() + " and " + that.type());
 	}
-
+	
 	@Override
 	public Value div(Value that) throws ExecutionErrorException {
-		throw new InvalidTypeException("Type error: cannot divide " + this.type() + " by "
-				+ that.type());
+		throw new InvalidTypeException("Type error: cannot divide " +
+				this.type() + " by " + that.type());
 	}
-
+	
 	@Override
 	public Value mod(Value that) throws ExecutionErrorException {
-		throw new InvalidTypeException("Type error: cannot take remainder of "
-				+ this.type() + " divided by " + that.type());
+		throw new InvalidTypeException("Type error: cannot take remainder of " +
+				this.type() + " divided by " + that.type());
 	}
-
-
-
+	
 	@Override
 	public Value compEq(Value that) throws ExecutionErrorException {
-		throw new InvalidTypeException("Type error: cannot check equality between "
-				+ this.type() + " and " + that.type());
+		throw new InvalidTypeException(
+				"Type error: cannot check equality between " + this.type() +
+						" and " + that.type());
 	}
-
-
-
+	
 	@Override
 	public Value compLess(Value that) throws ExecutionErrorException {
-		throw new InvalidTypeException("Type error: cannot check if " + this.type()
-				+ " is less than " + that.type());
+		throw new InvalidTypeException("Type error: cannot check if " +
+				this.type() + " is less than " + that.type());
 	}
-
+	
 	@Override
 	public Value compGreater(Value that) throws ExecutionErrorException {
-		throw new InvalidTypeException("Type error: cannot check if " + this.type()
-				+ " is greater than " + that.type());
+		throw new InvalidTypeException("Type error: cannot check if " +
+				this.type() + " is greater than " + that.type());
 	}
-
+	
 	@Override
 	public Value compLeq(Value that) throws ExecutionErrorException {
-		throw new InvalidTypeException("Type error: cannot check if " + this.type()
-				+ " is less than or equal to " + that.type());
+		throw new InvalidTypeException("Type error: cannot check if " +
+				this.type() + " is less than or equal to " + that.type());
 	}
-
+	
 	@Override
 	public Value compGeq(Value that) throws ExecutionErrorException {
-		throw new InvalidTypeException("Type error: cannot check if " + this.type()
-				+ " is greater than or equal to " + that.type());
+		throw new InvalidTypeException("Type error: cannot check if " +
+				this.type() + " is greater than or equal to " + that.type());
 	}
-
+	
 	@Override
 	public Value and(Value that) throws ExecutionErrorException {
-		throw new InvalidTypeException("Type error: cannot take logical AND of "
-				+ this.type() + " and " + that.type());
+		throw new InvalidTypeException(
+				"Type error: cannot take logical AND of " + this.type() +
+						" and " + that.type());
 	}
-
+	
 	@Override
 	public Value or(Value that) throws ExecutionErrorException {
-		throw new InvalidTypeException("Type error: cannot take logical OR of "
-				+ this.type() + " and " + that.type());
+		throw new InvalidTypeException(
+				"Type error: cannot take logical OR of " + this.type() +
+						" and " + that.type());
 	}
-
+	
 	@Override
 	public Value not() throws ExecutionErrorException {
-		throw new InvalidTypeException("Type error: cannot take logical NOT of "
-				+ this.type());
+		throw new InvalidTypeException(
+				"Type error: cannot take logical NOT of " + this.type());
 	}
-
+	
 	@Override
 	public Value arrayElem(int that) throws ExecutionErrorException {
-		throw new InvalidTypeException("Type error: cannot access " + this.type()
-				+ " as an array");
+		throw new InvalidTypeException("Type error: cannot access " +
+				this.type() + " as an array");
 	}
-
+	
 	@Override
 	public Value structElem(String field) throws ExecutionErrorException {
-		throw new InvalidTypeException("Type error: cannot access " + this.type()
-				+ " as a struct or record");
+		throw new InvalidTypeException("Type error: cannot access " +
+				this.type() + " as a struct or record");
 	}
-
+	
 	@Override
 	public Value valueAt() throws ExecutionErrorException {
-		throw new InvalidTypeException("Type error: cannot access type " + this.type()
-				+ " as a pointer");
+		throw new InvalidTypeException("Type error: cannot access type " +
+				this.type() + " as a pointer");
 	}
-/*
-	@Override
-	public Value addressOf() throws ExecutionErrorException {
-		throw new InvalidTypeException("Type error: cannot get address of  " + this.type());
-	}*/
-
+	
+	/*
+	 * @Override
+	 * public Value addressOf() throws ExecutionErrorException {
+	 * throw new InvalidTypeException("Type error: cannot get address of  " +
+	 * this.type());
+	 * }
+	 */
+	
 	@Override
 	public char asChar() throws ExecutionErrorException {
-		throw new InvalidTypeException("Type error: cannot treat " + this.type() + " as a "
-				+ Type.Char());
+		throw new InvalidTypeException("Type error: cannot treat " +
+				this.type() + " as a " + Type.Char());
 	}
-
+	
 	@Override
 	public int asInt() throws ExecutionErrorException {
-		throw new InvalidTypeException("Type error: cannot treat " + this.type() + " as a "
-				+ Type.Int());
+		throw new InvalidTypeException("Type error: cannot treat " +
+				this.type() + " as a " + Type.Int());
 	}
-
+	
 	@Override
 	public double asFloat() throws ExecutionErrorException {
-		throw new InvalidTypeException("Type error: cannot treat " + this.type() + " as a "
-				+ Type.Float());
+		throw new InvalidTypeException("Type error: cannot treat " +
+				this.type() + " as a " + Type.Float());
 	}
-
+	
 	@Override
 	public boolean asBool() throws ExecutionErrorException {
-		throw new InvalidTypeException("Type error: cannot treat " + this.type() + " as a "
-				+ Type.Bool());
+		throw new InvalidTypeException("Type error: cannot treat " +
+				this.type() + " as a " + Type.Bool());
 	}
-
+	
 	@Override
 	public int arrayLength() throws ExecutionErrorException {
-		throw new InvalidTypeException("Type error: cannot treat " + this.type()
-				+ " as an array");
+		throw new InvalidTypeException("Type error: cannot treat " +
+				this.type() + " as an array");
 	}
-
+	
 	@Override
 	public Value call(Value[] args) throws ExecutionErrorException {
-		throw new InvalidTypeException("Type error: cannot treat " + this.type()
-				+ " as a function");
+		throw new InvalidTypeException("Type error: cannot treat " +
+				this.type() + " as a function");
 	}
-
+	
 	@Override
 	public void setArrayElement(int index, Value val)
 			throws ExecutionErrorException {
-		throw new InvalidTypeException("Type error: cannot treat " + this.type()
-				+ " as an array");
+		throw new InvalidTypeException("Type error: cannot treat " +
+				this.type() + " as an array");
 	}
 	
-
-	
 	@Override
-	public Value coerce(Type type)
-		throws ExecutionErrorException{
-		if (type.equals(this.type()))
-		{
+	public Value coerce(Type type) throws ExecutionErrorException {
+		if (type.equals(this.type())) {
 			return this;
-		}
-		else if (type.equals(Type.Int()))
-		{
+		} else if (type.equals(Type.Int())) {
 			return new IntValue(this.asInt());
-		}
-		else if (type.equals(Type.Bool()))
-		{
+		} else if (type.equals(Type.Bool())) {
 			return new BoolValue(this.asBool());
-		}
-		else if (type.equals(Type.Float()))
-		{
+		} else if (type.equals(Type.Float())) {
 			return new FloatValue(this.asFloat());
-		}
-		else if (type.equals(Type.Char()))
-		{
+		} else if (type.equals(Type.Char())) {
 			return new CharValue(this.asChar());
 		}
 		
-		else
-		{
-			throw new InvalidTypeException("Type error: cannot convert " + this.type()
-					+ " to the type " + type);
+		else {
+			throw new InvalidTypeException("Type error: cannot convert " +
+					this.type() + " to the type " + type);
 		}
 	}
 	
 	@Override
 	public abstract String toString();
-
+	
 }

File src/ca/usask/cs/giraffe/compiler/ArrayValue.java

  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  * GNU General Public License for more details.
- *
+ * 
  * You should have received a copy of the GNU General Public License
  * along with Giraffe.  If not, see <http://www.gnu.org/licenses/>.
  */
  * Class holding values stored as an array, which can be accessed by index
  * 
  * @author Joey Eremondi
- * 
  */
 public class ArrayValue extends AbstractValue {
-
+	
 	/**
 	 * The type of elements stored in the array
 	 */
 	private Type elementType;
-
+	
 	/**
 	 * Number of elements stored in the array
 	 */
 	int size;
-
+	
 	/**
 	 * The actual values stored in the array
 	 */
 	Value[] elements;
-
+	
 	/**
 	 * Return a new array value of the given size and element type with
 	 * uninitialized elements
 	 * 
-	 * @param size number of elements stored in the array
-	 * @param type the type of elements stored in the array
+	 * @param size
+	 *            number of elements stored in the array
+	 * @param type
+	 *            the type of elements stored in the array
 	 */
 	public ArrayValue(int size, Type type) {
 		this.size = size;
 		this.elementType = type;
 		this.elements = new Value[size];
-		for (int i = 0; i < elements.length; i++)
-		{
+		for (int i = 0; i < elements.length; i++) {
 			elements[i] = new UnInitValue();
 		}
 	}
-
+	
 	@Override
 	public Type type() {
 		// return array wrapper around element type
 		return Type.Array(elementType, this.size);
 	}
-
+	
 	@Override
 	public Value arrayElem(int that) throws ExecutionErrorException {
 		try {
 			return this.elements[that];
 		} catch (ArrayIndexOutOfBoundsException e) {
-			throw new ExecutionErrorException("" + that
-					+ " is not a valid index on an array of size " + this.size);
+			throw new ExecutionErrorException("" + that +
+					" is not a valid index on an array of size " + this.size);
 		}
 	}
-
+	
 	@Override
 	public void setArrayElement(int index, Value val)
 			throws ExecutionErrorException {
 		try {
 			this.elements[index] = val;
 		} catch (ArrayIndexOutOfBoundsException e) {
-			throw new ExecutionErrorException("Can't access index " + index
-					+ " for an array of size " + this.size);
+			throw new ExecutionErrorException("Can't access index " + index +
+					" for an array of size " + this.size);
 		}
 	}
-
+	
 	/**
 	 * Create a new array from a string
 	 * 
 		}
 		return charArray;
 	}
-
+	
 	@Override
 	public String toString() {
 		// Special case: treat array of chars as string
 				} catch (ExecutionErrorException e) {
 					break;
 				}
-
+				
 			}
 			return ret.toString();
 		}
-		//Otherwise, print ARRAY_VALUE, since would print as a pointer in C
+		// Otherwise, print ARRAY_VALUE, since would print as a pointer in C
 		return "**ARRAY_VALUE**";
 	}
-
+	
 }

File src/ca/usask/cs/giraffe/compiler/BoolValue.java

  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  * GNU General Public License for more details.
- *
+ * 
  * You should have received a copy of the GNU General Public License
  * along with Giraffe.  If not, see <http://www.gnu.org/licenses/>.
  */
  * Corresponds to true/false values
  * 
  * @author Joey Eremondi
- * 
  */
 public class BoolValue extends AbstractValue {
-
+	
 	/**
 	 * The java boolean corresponding to this value
 	 */
 	private final boolean value;
-
+	
 	/**
 	 * Return a new bool-value containing the given Java bool value
 	 * 
-	 * @param b java boolean to store
+	 * @param b
+	 *            java boolean to store
 	 */
 	public BoolValue(Boolean b) {
 		this.value = b;
 	}
-
+	
 	@Override
 	public Type type() {
 		return Type.Bool();
 	}
-
+	
 	@Override
 	public Value and(Value that) throws ExecutionErrorException {
-		if (that.type().equals(Type.Bool()) || that.type().equals(Type.Int())
-				|| that.type().equals(Type.Char())) {
+		if (that.type().equals(Type.Bool()) || that.type().equals(Type.Int()) ||
+				that.type().equals(Type.Char())) {
 			return new BoolValue(this.asBool() && that.asBool());
 		} else {
 			return super.and(that);
 		}
 	}
-
+	
 	@Override
 	public Value or(Value that) throws ExecutionErrorException {
-		if ((that.type().equals(Type.Bool()) || that.type().equals(Type.Int()))
-				|| that.type().equals(Type.Char())) {
+		if ((that.type().equals(Type.Bool()) || that.type().equals(Type.Int())) ||
+				that.type().equals(Type.Char())) {
 			return new BoolValue(this.asBool() || that.asBool());
 		} else {
 			return super.and(that);
 		}
 	}
-
+	
 	@Override
 	public BoolValue not() throws InvalidTypeException {
 		return new BoolValue(!this.asBool());
 	}
-
+	
 	@Override
 	public boolean asBool() {
 		return this.value;
 	}
-
+	
 	@Override
 	public String toString() {
 		return "" + this.value;
 	}
-
+	
 }

File src/ca/usask/cs/giraffe/compiler/CharValue.java

  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  * GNU General Public License for more details.
- *
+ * 
  * You should have received a copy of the GNU General Public License
  * along with Giraffe.  If not, see <http://www.gnu.org/licenses/>.
  */
  * Class holding a single character
  * 
  * @author Joey Eremondi
- * 
  */
 public class CharValue extends NumValue {
-
+	
 	/**
 	 * Java char corresponding to c char stored
 	 */
 	private final char value;
-
+	
 	/**
 	 * Create a new c char from a given java char
 	 * 
 	public CharValue(char c) {
 		this.value = c;
 	}
-
+	
 	@Override
 	public Type type() {
 		return Type.Char();
 	}
-
+	
 	@Override
 	public int asInt() {
 		return this.value;
 	}
-
+	
 	@Override
 	public boolean asBool() {
 		return (this.value != 0);
 	}
-
+	
 	@Override
 	public double asFloat() {
 		return this.value;
 	}
-
+	
 	@Override
 	public char asChar() {
 		return this.value;
 	}
-
-
+	
 	@Override
 	public Value plus(Value that) throws ExecutionErrorException {
 		if (that.type().equals(Type.Int()) || that.type().equals(Type.Char())) {
 			return new IntValue(this.asInt() + that.asInt());
 		} else if (that.type().equals(Type.Float())) {
 			return new FloatValue(this.asFloat() + that.asFloat());
-		}
-		else {
+		} else {
 			return super.plus(that);
 		}
 	}
-
+	
 	@Override
 	public Value minus(Value that) throws ExecutionErrorException {
 		if (that.type().equals(Type.Int()) || that.type().equals(Type.Char())) {
 			return new IntValue(this.asInt() - that.asInt());
 		} else if (that.type().equals(Type.Float())) {
 			return new FloatValue(this.asFloat() - that.asFloat());
-		}
-		else {
+		} else {
 			return super.minus(that);
 		}
 	}
-
+	
 	@Override
 	public Value mult(Value that) throws ExecutionErrorException {
 		if (that.type().equals(Type.Int()) || that.type().equals(Type.Char())) {
 			return new IntValue(this.asInt() * that.asInt());
 		} else if (that.type().equals(Type.Float())) {
 			return new FloatValue(this.asFloat() * that.asFloat());
-		}
-		else {
+		} else {
 			return super.mult(that);
 		}
 	}
-
+	
 	@Override
 	public Value div(Value that) throws ExecutionErrorException {
-		try{
-		if (that.type().equals(Type.Int()) || that.type().equals(Type.Char())) {
-			return new IntValue(this.asInt() / that.asInt());
-		} else if (that.type().equals(Type.Float())) {
-			return new FloatValue(this.asFloat() / that.asFloat());
-		}
-		else {
-			return super.div(that);
-		}
-		}catch (ArithmeticException e)
-		{
+		try {
+			if (that.type().equals(Type.Int()) ||
+					that.type().equals(Type.Char())) {
+				return new IntValue(this.asInt() / that.asInt());
+			} else if (that.type().equals(Type.Float())) {
+				return new FloatValue(this.asFloat() / that.asFloat());
+			} else {
+				return super.div(that);
+			}
+		} catch (ArithmeticException e) {
 			throw new ExecutionErrorException("Can't divide by 0!");
 		}
 	}
-
+	
 	@Override
 	public Value mod(Value that) throws ExecutionErrorException {
-		try{
-		if (that.type().equals(Type.Int()) || that.type().equals(Type.Char())) {
-			return new CharValue((char)(this.asChar() % that.asChar()));
-		}
-		else {
-			return super.mod(that);
-		}
-		}catch (ArithmeticException e)
-		{
+		try {
+			if (that.type().equals(Type.Int()) ||
+					that.type().equals(Type.Char())) {
+				return new CharValue((char)(this.asChar() % that.asChar()));
+			} else {
+				return super.mod(that);
+			}
+		} catch (ArithmeticException e) {
 			throw new ExecutionErrorException("Can't mod by 0!");
 		}
 	}
 		return b.not();
 		
 	}
-
-
+	
 	// Comparison operators
 	@Override
 	public Value compEq(Value that) throws ExecutionErrorException {
 		if (that.type().equals(Type.Int()) || that.type().equals(Type.Char())) {
 			return new BoolValue(this.asInt() == that.asInt());
-		}
-		else {
+		} else {
 			return super.compEq(that);
 		}
 	}
-
+	
 	@Override
 	public Value compLess(Value that) throws ExecutionErrorException {
 		if (that.type().equals(Type.Int()) || that.type().equals(Type.Char())) {
 			return super.compLess(that);
 		}
 	}
-
+	
 	@Override
 	public Value compGreater(Value that) throws ExecutionErrorException {
 		if (that.type().equals(Type.Int()) || that.type().equals(Type.Char())) {
 			return super.compGreater(that);
 		}
 	}
-
+	
 	@Override
 	public Value compLeq(Value that) throws ExecutionErrorException {
 		if (that.type().equals(Type.Int()) || that.type().equals(Type.Char())) {
 			return super.compLeq(that);
 		}
 	}
-
+	
 	@Override
 	public Value compGeq(Value that) throws ExecutionErrorException {
 		if (that.type().equals(Type.Int()) || that.type().equals(Type.Char())) {
 			return super.compGeq(that);
 		}
 	}
-
+	
 	@Override
 	public String toString() {
 		return "" + this.value;
 	}
-
+	
 }

File src/ca/usask/cs/giraffe/compiler/Compiler.java

  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  * GNU General Public License for more details.
- *
+ * 
  * You should have received a copy of the GNU General Public License
  * along with Giraffe.  If not, see <http://www.gnu.org/licenses/>.
  */
  * errors which the interpreter throws
  * 
  * @author Joey Eremondi
- * 
  */
 public class Compiler implements GiraffeCompiler {
 	/**
 	 * appropriate messages being passed to the Controller thread.
 	 */
 	private CompilerController controller;
-
+	
 	private ConcreteInterpreter conc;
-
+	
 	/**
 	 * Create a new Compiler Object which sends messages to a controlelr
+	 * 
 	 * @param c
 	 */
 	public Compiler(CompilerController c) {
 		controller = c;
-
+		
 		conc = null;
-
+		
 		// this is entry point for the compiler thread
-
+		
 	}
-
+	
 	/*
 	 * The ControllerCompiler methods (controller will call these)
 	 */
 	public void compile(String program) {
 		// Make fresh interpreter for this program
 		this.conc = new ConcreteInterpreter(this.controller);
-
+		
 		try {
 			conc.compileString(program);
 		} catch (ParseErrorException e) {
-			controller.errorCreatingStrip("Your program contains errors.\n" +
-					"It cannot be compiled.\n" +
-					"The compiler gave the following output: (this may not be helpful)\n\n" 
-		+ e.getMessage(), conc.currentStart(), conc.currentEnd());
+			controller
+					.errorCreatingStrip(
+							"Your program contains errors.\n" +
+									"It cannot be compiled.\n" +
+									"The compiler gave the following output: (this may not be helpful)\n\n" +
+									e.getMessage(), conc.currentStart(),
+							conc.currentEnd());
 			GiraffeLogger.dumpStackTrace(e);
 		} catch (ExecutionErrorException e) {
-			controller.errorCreatingStrip("There was a problem while trying to run your program:\n"+
-		 e.getMessage(), conc.currentStart(), conc.currentEnd());
+			controller.errorCreatingStrip(
+					"There was a problem while trying to run your program:\n" +
+							e.getMessage(), conc.currentStart(),
+					conc.currentEnd());
 			GiraffeLogger.dumpStackTrace(e);
 		} catch (Exception e) {
-			controller.errorCreatingStrip("Unknown Error: " + e.getMessage(), conc.currentStart(), conc.currentEnd());
+			controller.errorCreatingStrip("Unknown Error: " + e.getMessage(),
+					conc.currentStart(), conc.currentEnd());
 			GiraffeLogger.dumpStackTrace(e);
 		}
-
+		
 	}
-
+	
 	@Override
 	public void receiveInput(String in) {
 		throw new RuntimeException("Don't use this method!");
-
+		
 	}
-
+	
 }

File src/ca/usask/cs/giraffe/compiler/CompilerReceiver.java

  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  * GNU General Public License for more details.
- *
+ * 
  * You should have received a copy of the GNU General Public License
  * along with Giraffe.  If not, see <http://www.gnu.org/licenses/>.
  */
  * doing.
  * 
  * @author isv452
- * 
  */
 public class CompilerReceiver extends MsgObject implements GiraffeCompiler,
 		CompilerController {
 	 * The Controller object, as a MsgObject.
 	 */
 	private MsgObject control;
-
+	
 	/**
 	 * The actual UI entry point
 	 */
 	private GiraffeCompiler compiler;
-
+	
 	/**
 	 * Constructs the CompilerReceiver.
+	 * 
 	 * @precond c must be a subclass of MsgObject
-	 * @param c the controller's receiving object
+	 * @param c
+	 *            the controller's receiving object
 	 */
 	public CompilerReceiver(CompilerController c) {
 		super("Giraffe Compiler");
 		controller = c;
 		try {
-			control = (MsgObject) controller;
+			control = (MsgObject)controller;
 		} catch (ClassCastException e) {
-			GiraffeLogger.fatal("the CompilerReceiver object was passed a non-MsgObject as controller");
+			GiraffeLogger
+					.fatal("the CompilerReceiver object was passed a non-MsgObject as controller");
 		}
 		compiler = new Compiler(this);
 	}
-
+	
 	/*
 	 * ControllerCompiler interface methods (these methods are called by the
 	 * controller) Punt to the actual Compiler object
 	public void compile(String program) {
 		compiler.compile(program);
 	}
-
+	
 	/*
 	 * CompilerController methods (called by other Compiler components, these
 	 * methods send messages to the Controller
 		this.sendMessage(this.control, "createdStrip", new TypedValue(
 				AnimationStrip.class, as));
 	}
-
+	
 	@Override
 	public void errorCreatingStrip(String msg, int startIndex, int endIndex) {
-		this.sendMessage(this.control, "errorCreatingStrip",
-				new TypedValue(String.class, msg),
-				new TypedValue(int.class,startIndex),
-				new TypedValue(int.class,endIndex)
-		);
+		this.sendMessage(this.control, "errorCreatingStrip", new TypedValue(
+				String.class, msg), new TypedValue(int.class, startIndex),
+				new TypedValue(int.class, endIndex));
 	}
-
+	
 	@Override
 	public void sendOutput(String output) {
 		this.sendMessage(this.control, "sendOutput", new TypedValue(
 				String.class, output));
 	}
-
+	
 	@Override
 	public void receiveInput(String in) {
 		// Deprecated, do nothing.
 		GiraffeLogger.warn("Deprecated functionality receiveInput()!");
 	}
-
+	
 	@Override
 	public String requestInputAndWait() throws InterruptedException {
 		return controller.requestInputAndWait();

File src/ca/usask/cs/giraffe/compiler/ConcreteInterpreter.java

  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  * GNU General Public License for more details.
- *
+ * 
  * You should have received a copy of the GNU General Public License
  * along with Giraffe.  If not, see <http://www.gnu.org/licenses/>.
  */
 import ca.usask.cs.giraffe.compiler.parser.ParseException;
 import ca.usask.cs.giraffe.core.GiraffeLogger;
 import ca.usask.cs.giraffe.exception.*;
+
 /**
  * This class contains most of the implementation for the interpreter declaring
  * variables, accessing variables, etc. Note that most of the actual Abstract
  * Syntax Tree traversal happens in the NodeVisitor class
  * 
  * @author Joey Eremondi
- * 
  */
 public class ConcreteInterpreter implements Interpreter {
-
+	
 	/**
 	 * Object to store sequence of animation messages
 	 */
 	private DeltaStrip ds;
-
+	
 	/**
 	 * Name-body mapping of function definitions Also used to access the current
 	 * environment
 	 */
-	private HashMap<String, FunctionDef> funcDict;
-
+	private HashMap<String,FunctionDef> funcDict;
+	
 	/**
 	 * Stores the character-num offsets of each line in the loaded file Used to
 	 * convert line-column to character number
 	 */
 	private int[] lineOffsets;
-
+	
 	/**
 	 * Source code being analysed/run
 	 */
 	private String code;
-
+	
 	/**
 	 * Object to walk the AST Used internally, should never be directly accessed
 	 * by outside classes
 	 */
 	private NodeVisitor visitor;
-
+	
 	/**
 	 * Parser to generate an AST
 	 */
 	private CParser parser;
-
+	
 	/**
 	 * The environment containing name-value bindings for global variables
 	 */
 	private Environment globalEnv;
-
+	
 	/**
 	 * The stack of current functions which have been called
 	 */
 	private Stack<FunctionInstance> callStack;
-
+	
 	/**
 	 * Controller to send messages to
 	 */
 	private CompilerController controller;
-
 	
 	/**
 	 * Start of the last statement run in the program
 	/**
 	 * List of all variables in the scope of the last function that returned
 	 */
-	private List<Map.Entry<String, Type>> lastFuncNames;
+	private List<Map.Entry<String,Type>> lastFuncNames;
 	
 	/**
 	 * Environment of the last function to return
 	 * Used to read input from cin
 	 */
 	Scanner scanner;
-
+	
 	/**
 	 * Construct a new Concrete Interpreter, which will send its results to the
 	 * given compiler controller
 	 * 
-	 * @param controller object to which we send our completed animation strip,
+	 * @param controller
+	 *            object to which we send our completed animation strip,
 	 *            as well as any input/output requests
 	 */
 	public ConcreteInterpreter(CompilerController controller) {
 		this.controller = controller;
-		this.funcDict = new HashMap<String, FunctionDef>();
+		this.funcDict = new HashMap<String,FunctionDef>();
 		this.callStack = new Stack<FunctionInstance>();
 		this.globalEnv = new DictEnvironment();
 		this.ds = new DeltaStrip();
 		GiraffeLogger.debug("Created new interpreter");
 	}
-
+	
 	/**
 	 * For debugging purposes Print the current call stack to the Giraffe logger
 	 */
 			depth++;
 		}
 	}
-
+	
 	/**
 	 * Once we have received an input string, store the positions of its
 	 * newlines so that we can convert from line-column of a character to
 		this.lineOffsets[0] = 0;
 		for (int i = 1; i < segments.length; i++) {
 			// ith newline is 1 after i-1th plus length
-			this.lineOffsets[i] = this.lineOffsets[i - 1]
-					+ segments[i - 1].length() + 1;
-
+			this.lineOffsets[i] = this.lineOffsets[i - 1] +
+					segments[i - 1].length() + 1;
+			
 		}
-
+		
 	}
-
+	
 	@Override
 	public int charPos(int line, int col) {
 		// line i is after i-1th newline
-		try
-		{
-		return this.lineOffsets[line - 1] + col - 1;
+		try {
+			return this.lineOffsets[line - 1] + col - 1;
 		}
-		//If error, return the beginning of the file
-		catch (Exception e)
-		{
+		// If error, return the beginning of the file
+		catch (Exception e) {
 			return 0;
 		}
-
+		
 	}
 	
 	@Override
-	public void setCharStart(int start)
-	{
+	public void setCharStart(int start) {
 		this.currentStart = start;
 	}
 	
 	@Override
-	public void setCharEnd(int end)
-	{
+	public void setCharEnd(int end) {
 		this.currentEnd = end;
 	}
 	
 	/**
 	 * Get the character start of the current expression being evaluated
 	 * Useful if we crash
+	 * 
 	 * @return the char start of the current expression
 	 */
-	public int currentStart()
-	{
+	public int currentStart() {
 		return this.currentStart;
 	}
 	
 	/**
 	 * Get the character start of the current expression being evaluated
 	 * Useful if we crash
+	 * 
 	 * @return the char start of the current expression
 	 */
-	public int currentEnd()
-	{
+	public int currentEnd() {
 		return this.currentEnd;
 	}
-
+	
 	/**
 	 * Access the environment of the current function
 	 * 
 	 *         executed
 	 */
 	private Environment env() {
-		if (this.callStack.isEmpty())
-		{
+		if (this.callStack.isEmpty()) {
 			return this.globalEnv;
-		}
-		else
-		{
-		return this.currentFunc().env();
+		} else {
+			return this.currentFunc().env();
 		}
 	}
-
+	
 	@Override
 	public FunctionInstance currentFunc() {
 		// Return stack top as first element
 		return this.callStack.peek();
 	}
-
+	
 	/**
 	 * Given a string containing C source code, compile it into an abstract
 	 * syntax tree then run program, sending input and output (but not
 	 * displaying animation)
 	 * 
-	 * @param code the code to compile
+	 * @param code
+	 *            the code to compile
 	 * @return the program's return value from main
-	 * @throws ParseErrorException if the C syntax is invalid
-	 * @throws ExecutionErrorException if the program encounters any runtime
+	 * @throws ParseErrorException
+	 *             if the C syntax is invalid
+	 * @throws ExecutionErrorException
+	 *             if the program encounters any runtime
 	 *             error
-	 *             
 	 */
 	public Value compileString(String code) throws ParseErrorException,
 			ExecutionErrorException {
 		StringReader r = new StringReader(code);
 		this.parser = new CParser(r);
 		this.parser.setBuildTree(true);
-
+		
 		this.visitor = new NodeVisitor(this);
-
+		
 		// Generate the AST, then walk it
 		try {
 			parser.TranslationUnit();
 			GiraffeLogger.info("Successfully parsed file");
 			PrintTree.printNode(parser.rootNode(), 0);
-
+			
 		} catch (ParseException e1) {
 			GiraffeLogger.dumpStackTrace(e1);
 			
-			//Store location of parse exception
+			// Store location of parse exception
 			int cstart = this.charPos(e1.currentToken.getBeginLine(), 1);
 			this.setCharStart(cstart);
-			int cend = this.charPos(e1.currentToken.getEndLine(), e1.currentToken.getEndColumn());
+			int cend = this.charPos(e1.currentToken.getEndLine(),
+					e1.currentToken.getEndColumn());
 			this.setCharEnd(cend);
 			
 			// convert to our type of exception
 			// so that nobody needs the parser package
 			throw new ParseErrorException(e1.getMessage());
 			
-			
 		}
-
+		
 		// Walk to find different functions and globals declared
 		parser.rootNode().jjtAccept(this.visitor, new VoidValue());
-
+		
 		Value ret = this.run();
 		GiraffeLogger.info("Successfully ran file");
 		GiraffeLogger.debug(this.ds.toString());
 			// controller
 			this.controller.createdStrip(animStrip);
 		} else {
-			//do nothing, useful to test
+			// do nothing, useful to test
 		}
 		
 		return ret;
-
+		
 	}
-
+	
 	/**
 	 * Run the main method defined in the source file
 	 * 
 	public Value run() throws ExecutionErrorException {
 		return this.callFunction("main", null);
 	}
-
-
+	
 	/**
 	 * Access the current global environment
 	 * 
 	public Environment getGlobalEnv() {
 		return this.globalEnv;
 	}
-
+	
 	/**
 	 * Add a function definition to our definitions
 	 * 
 		// Also store as Function Value in our environment
 		this.globalEnv.extendEnv(name, Type.Function());
 		this.globalEnv.assignValue(name, new FunctionValue(name, this));
-
+		
 	}
-
+	
 	@Override
 	public Value callFunction(String name, Value[] args)
 			throws ExecutionErrorException {
 		FunctionDef def = this.funcDict.get(name);
-		GiraffeLogger.debug("Got function def " + name + " with body "
-				+ def.body());
+		GiraffeLogger.debug("Got function def " + name + " with body " +
+				def.body());
 		FunctionInstance inst = new FunctionInstance(def, args, this.visitor,
 				this.globalEnv, name);
 		this.callStack.push(inst);
 		this.printCallStack();
 		// Now that new function is on call stack, call it
 		Value ret = this.currentFunc().call();
-		//store variables from the returned function to delete
+		// store variables from the returned function to delete
 		this.lastFuncNames = this.env().nonGlobalVars();
-		//Store environment from last function, used to get types
+		// Store environment from last function, used to get types
 		this.lastEnv = this.currentFunc().lastEnv();
 		// take function off stack now
 		this.callStack.pop();
 		// return value
 		return ret;
-
+		
 	}
-
-
+	
 	@Override
 	public void pushScope() {
 		// Just create a new environment with the current one as its parent
 		this.currentFunc().pushScope();
-
+		
 	}
-
+	
 	@Override
-	public void popScope(int cstart, int cend)
-	throws ExecutionErrorException
-	{
-		//Store last environment to get old values
+	public void popScope(int cstart, int cend) throws ExecutionErrorException {
+		// Store last environment to get old values
 		Environment lastEnv = this.env();
 		// tell function to pop scope, stroing old names
-		Map<String, Type> toDelete = this.currentFunc().popScope();
+		Map<String,Type> toDelete = this.currentFunc().popScope();
 		// Delete each variable from the old environment
-		//Bundle into one multi-delta
+		// Bundle into one multi-delta
 		LinkedList<DeltaDescriptor> deletes = new LinkedList<DeltaDescriptor>();
-		for (Map.Entry<String, Type>entry : toDelete.entrySet()) {
+		for (Map.Entry<String,Type> entry : toDelete.entrySet()) {
 			String varName = entry.getKey();
 			Type varType = entry.getValue();
-			deletes.add(new DeleteVarDelta(new LValue(varName), varType, lastEnv.getValue(varName), cstart, cend));
+			deletes.add(new DeleteVarDelta(new LValue(varName), varType,
+					lastEnv.getValue(varName), cstart, cend));
 		}
 		this.appendDelta(new MultiDelta(deletes, cstart, cend));
-
+		
 	}
-
+	
 	@Override
 	public void decVar(Type type, String name) throws DuplicateNameException {
 		// declare variable in environment
 		this.env().extendEnv(name, type);
-
+		
 	}
-
+	
 	@Override
 	public Value getVar(LValue lv) throws ExecutionErrorException {
 		if (lv.isName()) {
 		else if (lv.isArray()) {
 			Value sub = this.getVar(lv.getSub());
 			return sub.arrayElem(lv.getIndex());
-		}
-		else {
+		} else {
 			throw new RuntimeException("Invalid LValue");
 		}
-			/*else {
-		}
-			Value sub = this.getVar(lv.getSub());
-			return sub.structElem(lv.getMember());
-		}*/
-
+		/*
+		 * else {
+		 * }
+		 * Value sub = this.getVar(lv.getSub());
+		 * return sub.structElem(lv.getMember());
+		 * }
+		 */
+		
 	}
-
+	
 	/**
 	 * Access the value stored in a simple variable (i.e. not array index or
 	 * struct member)
 	 * 
-	 * @param name the name of the variable to access
+	 * @param name
+	 *            the name of the variable to access
 	 */
 	private Value getSimpleVar(String name) throws NameNotFoundException {
 		return this.env().getValue(name);
 	}
-
+	
 	@Override
 	public void setVar(LValue lv, Value val) throws ExecutionErrorException {
 		if (lv.isName()) {
 			this.setArrayElement(sub, lv.getIndex(), val);
 		}
 		
-
 	}
-
+	
 	/**
 	 * Set a primitive variable (not an array) to a value
-	 * @param name variable to set
-	 * @param val value to set it to
+	 * 
+	 * @param name
+	 *            variable to set
+	 * @param val
+	 *            value to set it to
 	 * @throws ExecutionErrorException
 	 */
 	private void setSimpleVar(String name, Value val)
 			throws ExecutionErrorException {
 		// Just set value in current env
 		this.env().assignValue(name, val);
-
+		
 	}
-
+	
 	@Override
 	public void setArrayElement(Value arr, int index, Value val)
 			throws ExecutionErrorException {
 		arr.setArrayElement(index, val);
-
+		
 	}
-
-
-
-
+	
 	@Override
 	public void appendDelta(DeltaDescriptor d) {
 		this.ds.add(d);
-
+		
 	}
-
+	
 	@Override
 	public String[] argNames(String functionName)
 			throws ExecutionErrorException {
 		return this.funcDict.get(functionName).argNames();
 	}
-
+	
 	@Override
 	public void sendOutput(String s) {
-		if (this.controller != null){
-		this.controller.sendOutput(s);
+		if (this.controller != null) {
+			this.controller.sendOutput(s);
 		}
-
+		
 	}
 	
-	private void getNextLine()
-	{
-
-		//Make sure we've retrieved the right input from the controller
-				if (this.scanner == null || !this.scanner.hasNext())
-				{
-					//If null controller, get input from stdin
-					if (this.controller == null)
-					{
-						GiraffeLogger.info("No controller given, using STDIN for CIN");
-						this.scanner = new Scanner(System.in);
-					}
-					
-					String line;
-					try
-					{
-						line= this.controller.requestInputAndWait();
-					}
-					catch (Exception e)
-					{
-						line = null;
-					}
-					 
-					if (line == null)
-					{
-						//Make sure we don't send a delta strip to the controller
-						this.controller = null;
-						throw new RuntimeException("TODO fixme");
-					}
-					GiraffeLogger.debug("Got line \"" + line + "\" from controller");
-					this.scanner = new Scanner(line);
-				}
+	private void getNextLine() {
+		
+		// Make sure we've retrieved the right input from the controller
+		if (this.scanner == null || !this.scanner.hasNext()) {
+			// If null controller, get input from stdin
+			if (this.controller == null) {
+				GiraffeLogger.info("No controller given, using STDIN for CIN");
+				this.scanner = new Scanner(System.in);
+			}
+			
+			String line;
+			try {
+				line = this.controller.requestInputAndWait();
+			} catch (Exception e) {
+				line = null;
+			}
+			
+			if (line == null) {
+				// Make sure we don't send a delta strip to the controller
+				this.controller = null;
+				throw new RuntimeException("TODO fixme");
+			}
+			GiraffeLogger.debug("Got line \"" + line + "\" from controller");
+			this.scanner = new Scanner(line);
+		}
 	}
-
+	
 	@Override
 	public Value consumeInput(LValue lv) throws ExecutionErrorException {
 		
-		
-		//Make sure scanner is up to date	
+		// Make sure scanner is up to date
 		this.getNextLine();
 		Type lvType = this.getType(lv);
 		
-		try
-		{
-		
-		//Parse based on which type lv is
-		if (lvType.equals(Type.Int()))
-		{
-			Integer read = this.scanner.nextInt();
-			Value ret = new IntValue(read);
-			this.setVar(lv, ret);
-			return ret;
-		}
-		else if (lvType.equals(Type.Bool()))