Commits

Steven! Ragnarök committed f59edd9

Cleans up the error messages some.

  • Participants
  • Parent commits 57224fb

Comments (0)

Files changed (2)

src/A1Grammar.java

 		else if (isIn(lookAhead(), first("ds")))
 			return ds();
 		else
-			syntaxError(lookAhead(), TokenType.SET);
-		return null;
+			throw new IllegalArgumentException("[SYNTAX ERROR] " +
+					lookAhead().getToken() + " does not begin a valid " +
+				 "NonReturnStatement");
 	}
 
 	/**
 			return new OrderedTree<Token>(match(TokenType.IDENT), null);
 		else if (lookAhead().getType() == TokenType.INT_LIT)
 			return new OrderedTree<Token>(match(TokenType.INT_LIT), null);
-		else syntaxError(lookAhead(), TokenType.IDENT);
-		return null;
+		else
+			throw new IllegalArgumentException("[SYNTAX ERROR] " +
+					lookAhead().getToken() + " does not begin a valid " +
+					"Expression");
 	}
 
 	/**
 			fname = match(TokenType.IDENT);
 		else if (lookAhead().getType() == TokenType.MATH_OP)
 			fname = match(TokenType.MATH_OP);
-		else syntaxError(lookAhead(), TokenType.IDENT);
+		else
+			throw new IllegalArgumentException("[SYNTAX ERROR] " +
+					lookAhead().getToken() + " is not a valid Function Name");
 
 		LinkedList<OrderedTree<Token>> kids =
 			new LinkedList<OrderedTree<Token>>();
 	{
 		if (lookAhead().getType() == tt)
 			return tokenStream.poll();
-		else { syntaxError(lookAhead(), tt); }
-		return null;
+		else
+		{
+			throw new IllegalArgumentException("[SYNTAX ERROR] " +
+				"Expected Token of Type: " + tt + " Got: " +
+				lookAhead().getToken() + " of Type: " +
+				lookAhead().getType().toString());
+		}
 	}
 
 	/**
 	private Token lookAhead() { return tokenStream.peek(); }
 
 	/**
-	   Construct a common exception when an invalid match occurs.
-		 @throws IllegalArgumentException
-	*/
-	private void syntaxError(Token tk, TokenType tt)
-	{
-		throw new IllegalArgumentException("[SYNTAX ERROR] " +
-			"Expected Type: " + tt + " Got: " + tk.getToken() +
-			" of Type: " + tk.getType().toString());
-	}
-
-	/**
 	   Tells if the token is contained within the array of types
 		 given.
 		 @param tk The token to check for.
 			if (tt.matches(tk))
 				return new Token(tk, tt);
 		throw new
-			IllegalArgumentException("[SYNTAX ERROR] Unknown token: " + tk);
+			IllegalArgumentException("[SYNTAX ERROR] Invalid token: " +
+					tk + " is of an unknown type");
 	}
 
 }