src/main/java/PrefixDiff.java
/**
         * Populate the Function from the next part of the rest.
         * Return the unused part of rest.
         * @param rest characters to process
         * @return remaining characters to process
         */
Populate the Function from the next part of the rest.
Return the unused part of rest.
@param rest characters to process
@return remaining characters to process
Populate the Function from the next part of the rest . Return the unused part of rest . @param rest characters to process @return remaining characters to process
public static List<Character>  parse(Function toPopulate, List<Character> rest) {
            Character test = getNextNoneBlank(rest);
            if (test == '(') { 
                test = getLastNoneBlank(rest); 
                if (test != ')')
                    throw new Error("Expression does not have matching brackets");
                String name = getNextWord(rest);
                toPopulate.setName(name);
                if (toPopulate.functionName == FunctionName.o) {
                    test = getNextNoneBlank(rest);
                    if (test != ',')
                        throw new Error("Missing comma between operator and first argument");
                    toPopulate.left = new Function();
                    rest = parse(toPopulate.left, rest);
                    test = getNextNoneBlank(rest);
                    if (test != ',')
                        throw new Error("Missing comma between first and second arguments");
                    toPopulate.right = new Function();
                    rest = parse(toPopulate.right, rest);
                } else if (toPopulate.functionName == FunctionName.x) {
                    test = getNextNoneBlank(rest);
                    if (test != ',')
                        throw new Error("Missing comma between operator and argument");
                    toPopulate.left = new Function();
                    rest = parse(toPopulate.left, rest);
                } 
            } else {
                String name = getNextWord(rest);
                toPopulate.setName(name);
                if (toPopulate.functionName != FunctionName.x && toPopulate.functionName != FunctionName.n)
                    throw new Error("Function or operator without brackets");
            }
            return rest;
        }
public static List < Character > parse ( Function toPopulate , List < Character > rest ) { Character test = getNextNoneBlank ( rest ) ; if ( test == '(' ) { test = getLastNoneBlank ( rest ) ; if ( test != ')' ) throw new Error ( "Expression does not have matching brackets" ) ; String name = getNextWord ( rest ) ; toPopulate . setName ( name ) ; if ( toPopulate . functionName == FunctionName . o ) { test = getNextNoneBlank ( rest ) ; if ( test != ',' ) throw new Error ( "Missing comma between operator and first argument" ) ; toPopulate . left = new Function ( ) ; rest = parse ( toPopulate . left , rest ) ; test = getNextNoneBlank ( rest ) ; if ( test != ',' ) throw new Error ( "Missing comma between first and second arguments" ) ; toPopulate . right = new Function ( ) ; rest = parse ( toPopulate . right , rest ) ; } else if ( toPopulate . functionName == FunctionName . x ) { test = getNextNoneBlank ( rest ) ; if ( test != ',' ) throw new Error ( "Missing comma between operator and argument" ) ; toPopulate . left = new Function ( ) ; rest = parse ( toPopulate . left , rest ) ; } } else { String name = getNextWord ( rest ) ; toPopulate . setName ( name ) ; if ( toPopulate . functionName != FunctionName . x && toPopulate . functionName != FunctionName . n ) throw new Error ( "Function or operator without brackets" ) ; } return rest ; }
Populate the Function from the next part of the rest.
Populate the Function from the next part of the rest .
// start with a bra then: // must be matching closing ket // starting an expression // has two arguments // has one argument // otherwise, it is a constant or variable // can only be a variable or constant