import java.util.*;
import java.io.*;

public class Parser
{
    public static final char DELIMITER = ',';
    public static final String PRODUCES = "=>";
    public static final char SPACE = ' ';

    public Parser (boolean debug)
    {
        _debug = debug;
    }

    public void loadData (String fileName)
    {
        /*
         * Open the data file and read it in.
         */

        BufferedReader reader = null;
        String[] values = null;

        try
        {
            reader = new BufferedReader(new FileReader(fileName));
            String line = null;

            while ((line = reader.readLine()) != null)
            {
                System.out.println("**read "+line);
                
                /*
                 * Line format:
                 * 
                 * - ALWAYS start with a number
                 * - ALWAYS follow with a String
                 * - Then EITHER a comma if more than one chemical OR => to denote end of reactants
                 * - ALWAYS end in a number and a String
                 */

                 Vector<Integer> quantities = new Vector<Integer>();
                 Vector<Chemical> chemicals = new Vector<Chemical>();
                 boolean allReactants = false;
                 int ptr = 0;

                 do
                 {
                    int quantitySpace = line.indexOf(ptr, SPACE);

                    if (quantitySpace != -1)
                    {
                        int quantity = Integer.parseInt(line.substring(ptr, quantitySpace));
                        int chemDelim = line.indexOf(DELIMITER, quantitySpace);
                        String chem = null;

                        if (chemDelim == -1)  // no more chemicals, but we do have a rogue quantity!
                            allReactants = true;
                        else
                        {
                            chem = line.substring(quantitySpace, chemDelim-1);

                            ptr += chemDelim;
                        }

                        System.out.println("**got "+quantity+" and "+chem);
                    }
                    else
                        allReactants = true;

                } while (!allReactants);
            }
        }
        catch (Throwable ex)
        {
            ex.printStackTrace();
        }
        finally
        {
            try
            {
                reader.close();
            }
            catch (Throwable ex)
            {
            }
        }
    }

    private boolean _debug;
}
@@ -78,20 +78,22 @@
 c final 
-char
+String
  DELIMIT
@@ -101,11 +101,11 @@
 R = 
-','
+%22,%22
 ;%0A  
@@ -178,12 +178,14 @@
 nal 
-char
+String
  SPA
@@ -193,11 +193,55 @@
 E = 
-' '
+%22 %22;%0A    public static final String ORE = %22ORE%22
 ;%0A%0A 
@@ -743,32 +743,16 @@
 +line);%0A
-                
 %0A       
@@ -1403,18 +1403,88 @@
 xOf(
-ptr, 
 SPACE
+, ptr);%0A%0A                    System.out.println(%22**space at %22+quantitySpace
 );%0A%0A
@@ -1796,134 +1796,231 @@
     
-if (chemDelim == -1)  // no more chemicals, but we do have a rogue quantity!%0A                            allReactants = true;%0A
+System.out.println(%22**chemDelim %22+chemDelim);%0A%0A                        if (chemDelim == -1)  // no more chemicals%0A                        %7B%0A                            chemDelim = line.indexOf(PRODUCES, quantitySpace);%0A    
     
@@ -2031,36 +2031,52 @@
                 
-else
+allReactants = true;
 %0A               
@@ -2076,38 +2076,35 @@
                 
-%7B%0A    
+%7D%0A%0A
                 
@@ -2146,16 +2146,18 @@
 itySpace
++1
 , chemDe
@@ -2189,20 +2189,16 @@
         
-  
-  
 ptr += c
@@ -2210,34 +2210,8 @@
 lim;
-%0A                        %7D
 %0A%0A  

Update Parser.java