package cal;

import java.io.File;

public class ParserFactory {

    /*
     * Classify whether the user input are: 1. expression 2. equation 3.
     * input file path Read the user input from input file path
     */
	public Parser createParser(String str) {
	    String input = str;
		if (isExpression(input)) {
			return new ExpressionTree();
		} else if (isEquation(input)) {
			// TODO: create equation tree for calculation
			return new NullParser();
		} else if (isFilePath(input)) {
			// TODO: read user input from file path
		      // check input isEquation/isExpression again
			return new NullParser();
		} else
			return new NullParser();
	}
	
	// XXX move to BasicMathMethod
	public boolean isExpression(String str) {
		str = str.replace(" ", "");
		if (str.isEmpty())
		  return false;
		
		String num = "[\\-\\+]?[0-9]*\\.?[0-9]+";
		String op = "([\\/\\+\\-\\*\\^])";
	    String exp = "\\(*" + num + "\\)*("+op+"\\(*"+num+"\\)*)*";
		
		return str.matches(exp);
	}

	private boolean isEquation(String str) {
		// TODO check equation
		str = str.replace(" ", "");
		if (str.isEmpty())
			return false;
		else
			return false; 
	}

	private boolean isFilePath(String str) {
		return new File(str).exists();
	}
}

@@ -58,16 +58,180 @@
 ctory %7B%0A
+%09/**%0A%09 * To determine the input string whether %0A%09 * it is expression, equation and file path.%0A%09 * %0A%09 * @param str accept string input%0A%09 * @return Parser object%0A%09 */
 %0A    /*%0A

Add comment java doc into the class of ParserFactory