Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 6 of 6

Thread: Not sure how to work with multiple delimiters. Also, there is random tabbing.

  1. #1
    Banned
    Join Date
    May 2010
    Location
    North Central Illinois
    Posts
    1,631
    My Mood
    Sleepy
    Thanks
    390
    Thanked 112 Times in 110 Posts

    Default Not sure how to work with multiple delimiters. Also, there is random tabbing.

    The instructor sometimes has tabs in the input files at random places. To make things more annoying, it's on a UNIX thing which means I have to go get it from the Exceed on Demand 8 and somehow mail it to myself and then download it. Merely copying it might lose some of the formatting perhaps.

    Not quite sure. There was sometimes tabs that looked like spaces in there. That's why I had to tell it not to read in that second line if it was blank. It was coming across tabs and possibly a newline. Or something.

    The first line is the number of states.

    The next line, or what should have been the next line, should contain the alphabet. Again, I thought that using a toCharArray and filtering out the tab and space characters was the best idea.

    After that, it starts with a state number and then a bunch of input sets. It's a finite state machine. I want to say it's a Nondeterministic finite state machine. I'm to convert it to a deterministic finite state machine. However, I am trying to figure out how to filter out multiple unwanted characters like , { } and :

    Also, another thing I'd been wondering is, since Strings are immutable, i.e. not changeable, then how do setter methods with type String work then?

    How do you work with multiple delimiters?

    I want it to read in the number to the left of the ":" as a state, starting at 0. (They all do, though in theory they could start at some other state. The starting state is the second to last line in the file.

    I think the one to the left of the ":" was the first index for the 2D Array of the MySet class (which is basically an ArrayList).

    The stuff on the right are the sets of next states.

    See this page for more of an idea, I can't explain it that well. frame set of ITK 328, Spring 2008, Illinois State University, Introduction to the theory of computation

    The states are denoted by the { } and the individual values are separated by a ,. An empty state will simply not be added to the ArrayList.

    The character alphabet I think is going to have all the values there, plus one for an empty string. I'm using the index of each character, or where it's at in the ArrayList of Character as the second index in the 2D Array

    For instance, assuming I have MySet[][] ms, then

    a b
    0: {1} {} {1,2}

    Would have

    ms[0][0].add(1);
    don't add any for
    ms[0][1] since it's empty
    For the empty string, which I guess is index 2
    ms[0][2].add(1);
    ms[0][2].add(2);

    What I guess I'm after is:

    String str = reader.nextLine(); // assuming it's not empty or something, which was the case I've found already once before

    Ok, I'm not even sure how to pseudocode this, hence why I'm here. Here it goes though

    1.) Read in each line, perhaps as a whole entity
    2.) Go through and scan till it reaches a ":", or the scanner has reader end of file, need to check for that too possibly
    3.) Then scan from every { it finds and stop pushing into that part of the ArrayList when it meets a } and then go into the next ArrayList and push the same way and so on until all the alphabet plus the empty string part of it are all done. There is nothing there in between the { and } then don't push. Also, there might be like

    {1,2,3,4} so I need to push each number but not the commas
    4.) Read in starting state (Easy, assuming I can know that I'm done with the top part as its size will vary. Since the first line in the whole document is the number of states, that should make it easy to find where to read in the starting state.
    5.) Read in the final state which could be empty, though it probably isn't, or could have 1 or more parts, again with { } and some commas in between.

    import java.util.Scanner;
    import java.io.File;
    import java.io.FileNotFoundException;
    import java.util.ArrayList;
     
     
    public class fsm
    {
     
    private static class FileParser
    {
     
     
     
    }
     
    private static class MySet
    {
     
    private  ArrayList<Integer> intList;
     
     
    public  void add(Integer data)
    {
    intList.add(data);
     
    }
     
    public void remove()
    {
    intList.remove(0);
     
    }
     
     
     
     
     
     
    }
     
        public static void main(String[] args)
        {
    	Scanner s = null;
    	Scanner s2 = null;
    	ArrayList<Integer> stateList = new ArrayList<Integer>();
    	ArrayList<Character> alphabet = new ArrayList<Character>();
     
     
     
     
     
    	int numOfStates = 0;
     
    try
        {
       s  = new Scanner(new File(args[0]));
        }
     
        catch (ArrayIndexOutOfBoundsException aioobe)
        {
        System.out.println("Error!");
        System.exit(1);
     
        }
     
    catch (FileNotFoundException fnfe)
        {
    	System.out.println("Error!");
    	System.exit(1);
     
        }
    numOfStates = s.nextInt();
     
        System.out.println(numOfStates);
     
        String line = s.nextLine();
        if (line.equals(""))
        line = s.nextLine();
     
     
     
     
        System.out.println(line);
     
        char[] chars = line.toCharArray();
     
     
     
     
        char empty = ' ';
     
     
        String tab = "\t";
        char tab2 = tab.charAt(0);
     
        for (int i =0; i < chars.length; i++)
        {
        if (chars[i]!= empty && chars[i]!=tab2)
        {
        alphabet.add(chars[i]);
        }
        }
     
        alphabet.add('');
     
         System.out.println(alphabet.toString());
    try
        {
       s2  = new Scanner(new File(args[1]));
        }
     
        catch (ArrayIndexOutOfBoundsException aioobe)
        {
        System.out.println("Error!");
        System.exit(1);
     
        }
     
    catch (FileNotFoundException fnfe)
        {
    	System.out.println("Error!");
    	System.exit(1);
     
        }
     
     
     
     
     
        }
     
    }

    As I'm trying to figure out how to get all the delimiters for the same line, I'm not even sure how to start.

    [nfa2.nfa]
    6
    a b
    0: {1} {4} {2}
    1: {5} {2} {}
    2: {5} {} {}
    3: {} {} {0}
    4: {} {1} {3}
    5: {} {} {4}
    0
    {5}
    [/nfa2.nfa]

    That one didn't have commas and multiple states but this one does:

    [nfa4.nfa]
    5
    a b c d
    0: {} {} {} {} {1,2,3,4}
    1: {} {1} {1} {1} {}
    2: {2} {} {2} {2} {}
    3: {3} {3} {} {3} {}
    4: {4} {4} {4} {} {}
    0
    {1,2,3,4}
    [/nfa4.nfa]

    There's a bunch of text files and it should be able to work on them all.

    Once I can get this part, I'll try and see how to convert to a DFSM.

    ----Edit-----
    Ok, that didn't go directly to the program page. However, it's the one program mentioned there. It says 2008 on the line I posted above but it's for 2012.
    Last edited by javapenguin; April 7th, 2012 at 07:21 PM.


  2. #2
    Banned
    Join Date
    May 2010
    Location
    North Central Illinois
    Posts
    1,631
    My Mood
    Sleepy
    Thanks
    390
    Thanked 112 Times in 110 Posts

    Default Re: Not sure how to work with multiple delimiters. Also, there is random tabbing.

    I've tried to figure out how to do multiple regex but am not sure how yet.

    I tried the split method in String, but that would go wrong if it came across

    {1,2,3,4}, {1}

    though it would work with

    {1},{2},{}

    I'm trying to split it up around 4 different regex, one a sort of pair

    I want it to first split it to everything before it first encounters a ":" and everything after it first encounters a ":"

    The split method should be able to handle that, provided I don't have any more blank lines hidden, however, the , and the { } are still confusing me.

    I can't have it split around each {} as that's an illegal regex it said. If I could, then I'd have it split it yet again after that around commas.

    It would make a ton of smaller arrays but would get what I wanted done. But how to split it around { } if there's something in the middle, or even if there isn't for that matter? I don't want it splitting around only { or only } but around to check when it sees a { and then later when it sees a } to split after the }

    I can't just split around the } as I'd pick up the { as a token which I don't want to do.

    Also, I'd like to get it to know when it's removing a :, {} , or , as I'd need it to know where to insert it in the 2D array. Only the numbers will be inserted. If I could get the split to do what I'd wanted, I'd probably be able to use the indexes of each of these sub arrays to do that.
    Last edited by javapenguin; April 8th, 2012 at 06:25 PM.

  3. #3
    Super Moderator Sean4u's Avatar
    Join Date
    Jul 2011
    Location
    Tavistock, UK
    Posts
    637
    Thanks
    5
    Thanked 103 Times in 93 Posts

    Default Re: Not sure how to work with multiple delimiters. Also, there is random tabbing.

    For your lines with curly brackets in them, use java.util.text's Pattern and Matcher. You could use one Pattern for the whole line, but for cases such as your example I'd usually make one Pattern for the whole line, another Pattern for the stuff after the colon and another for data within the curly brackets. Read the API documentation for Pattern carefully: '{' and '}' are special characters so need escaping if you want to use them literally.

  4. The Following User Says Thank You to Sean4u For This Useful Post:

    javapenguin (April 16th, 2012)

  5. #4
    Banned
    Join Date
    May 2010
    Location
    North Central Illinois
    Posts
    1,631
    My Mood
    Sleepy
    Thanks
    390
    Thanked 112 Times in 110 Posts

    Default Re: Not sure how to work with multiple delimiters. Also, there is random tabbing.

    I was able to solve that part. However, now I kind of need help with a recursive part.

    import java.util.Scanner;
    import java.io.File;
    import java.io.FileNotFoundException;
    import java.util.ArrayList;
     
     
     
    public class fsm
    {
     
    private static class FileParser
    {
     
     
     
    }
     
    private static class MySet
    {
     
    private  ArrayList<Integer> intList;
     
    public MySet()
    {
    intList = new ArrayList<Integer>();
     
    }
     
    public  void add(Integer data)
    {
    intList.add(data);
     
    }
     
    public void remove()
    {
    intList.remove(0);
     
    }
     
    public int size()
    {
    return intList.size();
    }
     
    public Integer get(int index) throws NullPointerException
    {
    return intList.get(index);
     
    }
     
     
     
     
    }
     
        public static void main(String[] args)
        {
    	Scanner s = null;
    	Scanner s2 = null;
    	ArrayList<Integer> stateList = new ArrayList<Integer>();
    	ArrayList<Character> alphabet = new ArrayList<Character>();
     
    	ArrayList<String> transitionLines = new ArrayList<String>();
    	ArrayList<String[]> splitArray = new ArrayList<String[]>();
     
     
     
     
     
     
     
     
    	int numOfStates = 0;
     
    try
        {
       s  = new Scanner(new File(args[0]));
        }
     
        catch (ArrayIndexOutOfBoundsException aioobe)
        {
        System.out.println("Error!");
        System.exit(1);
     
        }
     
    catch (FileNotFoundException fnfe)
        {
    	System.out.println("Error!");
    	System.exit(1);
     
        }
    numOfStates = s.nextInt();
     
        System.out.println(numOfStates);
     
        String[][] splits = new String[numOfStates][2];
     
     
     
     
        String line = s.nextLine();
        if (line.equals(""))
        line = s.nextLine();
     
     
     
     
        System.out.println(line);
     
        char[] chars = line.toCharArray();
     
     
     
     
        char empty = ' ';
     
     
        String tab = "\t";
        char tab2 = tab.charAt(0);
     
        for (int i =0; i < chars.length; i++)
        {
        if (chars[i]!= empty && chars[i]!=tab2)
        {
        alphabet.add(chars[i]);
        }
        }
     
        alphabet.add('');
     
         System.out.println(alphabet.toString());
     
     
         for (int i=0; i < numOfStates; i++)
         {
         transitionLines.add(s.nextLine());
     
         }
     
         System.out.println(transitionLines.toString());
     
     
         for (int i =0; i < splits.length; i++)
         {
         splits[i] = transitionLines.get(i).split(":");
     
         }
     
     
         for (int i =0; i < splits.length; i++)
         {
         for (int j=0; j < splits[i].length; j++)
         {
         System.out.println(splits[i][j]);
     
         }
     
     
         }
     
       //  String[][] test = 
         ArrayList<String[]> fredBowling = new ArrayList<String[]>();
     
         for (int i =0; i < splits.length; i++)
         {
         fredBowling.add(splits[i][1].split("}"));
         }
         splits[0][1].split("}");
     
         ArrayList<Integer> state = new ArrayList<Integer>();
     
         for (int i=0; i < splits.length; i++)
         {
         state.add(Integer.parseInt(splits[i][0]));
     
         }
     
     
       //  System.out.println(java.util.Arrays.toString(test));
     
     
        // String smaller[] = new String[test.length];
     
        ArrayList<ArrayList<String>> smaller = new ArrayList<ArrayList<String>>();
     
         for (int i =0; i < fredBowling.size(); i++)
         {
         smaller.add(new ArrayList<String>());
         for (int j = 0; j < fredBowling.get(i).length; j++)
         {
         int temp = fredBowling.get(i)[j].indexOf("{");
     
         smaller.get(i).add(fredBowling.get(i)[j].substring(temp + 1));
         }
     
         }
     
       //  System.out.println(java.util.Arrays.toString(smaller));
     
        //  ArrayList<String[]> finale = new ArrayList<String[]>();
         ArrayList<ArrayList<String[]>> finale = new ArrayList<ArrayList<String[]>>();
     
         // for (int i =0; i < smaller.length; i++)
      //    {
       //   finale.add(smaller[i].split(","));
     
     //    }
     
         for (int i =0; i < smaller.size(); i++)
         {
         finale.add(new ArrayList<String[]>());
         for (int j =0; j < smaller.get(i).size(); j++)
         {
         finale.get(i).add(smaller.get(i).get(j).split(","));
     
         }
     
     
         }
     
         for (int i =0; i < finale.size(); i++)
         {
         for (int j =0; j < finale.get(i).size(); j++)
         {
         for (int k =0; k < finale.get(i).get(j).length; k++)
         {
         System.out.println("MySet[" + i + "]["+j +"].get(" + k + ") = " +finale.get(i).get(j)[k]);
         }
     
     
         }
     
         }
     
         MySet[][] ms = new MySet[finale.size()][finale.get(0).size()];
     
         for (int i =0; i < finale.size(); i++)
         {
     
         for (int j =0; j < finale.get(i).size(); j++)
         {
     
         ms[i][j] = new MySet();
         for (int k =0; k < finale.get(i).get(j).length; k++)
         {
         if (finale.get(i).get(j)[k] != null && !finale.get(i).get(j)[k].equals(""))
         {
         ms[i][j].add(Integer.parseInt(finale.get(i).get(j)[k]));
     
         }
     
         }
     
         }
     
     
         }
     
         for (int i =0; i < ms.length; i++)
         {
         for (int j =0; j < ms[i].length; j++)
         {
         for (int k =0; k < ms[i][j].size(); k++)
         {
         System.out.println("ms[" + i + "]["+j +"].get(" + k + ") = "+ ms[i][j].get(k));
     
         }
         }
     
         }
     
         int startingState = s.nextInt();
         System.out.println("s:" + startingState);
     
         String fs = s.nextLine();
     
         if (fs.equals("") || fs == null)
         fs = s.nextLine();
     
         String[] firstHalf = fs.split("}");
     
     
          int temp = firstHalf[0].indexOf("{");
     
          String secondHalf = firstHalf[0].substring(temp+1);
     
          String[] finalHalf = secondHalf.split(",");
     
     
         ArrayList<Integer> finalState = new ArrayList<Integer>();
     
         for (int i =0; i < finalHalf.length; i++)
    {
    if (finalHalf[i] != null && !finalHalf[i].equals(""))
    {
    finalState.add(Integer.parseInt(finalHalf[i]));
    }
     
    }
     
    System.out.println("Final state: " + finalState.toString());
     
    try
        {
       s2  = new Scanner(new File(args[1]));
        }
     
        catch (ArrayIndexOutOfBoundsException aioobe)
        {
        System.out.println("Error!");
        System.exit(1);
     
        }
     
    catch (FileNotFoundException fnfe)
        {
    	System.out.println("Error!");
    	System.exit(1);
     
        }
     
     
     
     
     
        }
     
        public static ArrayList<Integer>getFinalStateFrom(Integer state, Integer character)
        {
     
        ArrayList<Integer> al = new ArrayList<Integer>();
        return al;  // this is for now to get it to compile on all machines.  
     
     
     
     
     
     
        }
     
     
    }

    While I can find the next possible states without the lambda, i.e., the empty states, I need help with the lambda part. I'm going to show an output for a NFA and then show what the DFA conversion should look like. Actually, I might try it for at least two different files. However, this will take some time. I should be able to calculate them manually. Though it might take several minutes.

    Ok, I still am confused about how the instructor got {0,2} but I seem to have gotten the other ones right.

     

    6
    a b
    [a, b, ]
    [0: {1} {4} {2}, 1: {5} {2} {}, 2: {5} {} {}, 3: {} {} {0}, 4: {} {1} {3}, 5: {} {} {4}]
    0
    {1} {4} {2}
    1
    {5} {2} {}
    2
    {5} {} {}
    3
    {} {} {0}
    4
    {} {1} {3}
    5
    {} {} {4}
    MySet[0][0].get(0) = 1
    MySet[0][1].get(0) = 4
    MySet[0][2].get(0) = 2
    MySet[1][0].get(0) = 5
    MySet[1][1].get(0) = 2
    MySet[1][2].get(0) =
    MySet[2][0].get(0) = 5
    MySet[2][1].get(0) =
    MySet[2][2].get(0) =
    MySet[3][0].get(0) =
    MySet[3][1].get(0) =
    MySet[3][2].get(0) = 0
    MySet[4][0].get(0) =
    MySet[4][1].get(0) = 1
    MySet[4][2].get(0) = 3
    MySet[5][0].get(0) =
    MySet[5][1].get(0) =
    MySet[5][2].get(0) = 4
    ms[0][0].get(0) = 1
    ms[0][1].get(0) = 4
    ms[0][2].get(0) = 2
    ms[1][0].get(0) = 5
    ms[1][1].get(0) = 2
    ms[2][0].get(0) = 5
    ms[3][2].get(0) = 0
    ms[4][1].get(0) = 1
    ms[4][2].get(0) = 3
    ms[5][2].get(0) = 4
    s:0
    Final state: [5]




                 a     b      E
    0          1      4      2
    1          5      2      -
    2          5      -      -
    3          -      -      0
    4          -      1       3
    5          -      -       4
     
    {0,a} = {1, 5, 4, 3, 0, 2}
    {0,b} = {4, 3, 0, 2}
    {0,E} = {2}
    {1,a} = {5, 4, 3, 0, 2}
    {1,b} = {2}
    {1,E} = { }
    {2,a} = {5, 4, 3, 0, 2}
    {2,b} = { }
    {2,E} = { }
    {3,a} = { }
    {3,b} = { }
    {3,E} = {0, 2}
    {4,a} = { }
    {4,b} = {1}
    {4,E} = {3, 0, 2}
    {5,a}  = { }
    {5,b} = { }
    {5,E} = {4,3, 0, 2}
     
     
     
    So final states so far of
    {0,1,2,3,4,5}
    {4 , 3, 0 ,2}
     
    {{0,1,2,3,4,5},a} = {0, 1, 2, 3, 4, 5}
    {{0,1,2,3,4,5},b}  = {0,1,2,3,4}
    {{4,3,0,2}, a} = {0,1,2,3,4,5}
    {{4,3,0,2},b} = {0,1,2,3,4}
    {{0,1,2,3,4},a} = {0, 1, 2, 3, 4, 5}
    {{0,1,2,3,4}, b} = {0,1,2,3,4}
     
    final states so far:
    {0,1,2,3,4,5}
    {0,2,3,4}
    {0,1,2,3,4}
     
    {{0,1,2,3,4,5},E} = {2, 0, 3, 4}
    {{0,2,3,4},E} = {0,3,2}
    {{0,1,2,3,4|, E} = {0, 3, 2}
    {{0,3,2},E} = {0,2}
    {{0,2},E} = {2}
    {{2},E} = { }
    While I'm not again how to get the final state of {0,2}, I am thinking I'll need recursion in some places. Problem is, I'm not that great at recursion. I'll show the recursive steps to get that thing above. Just give me a bit.......

    Here's some of it:

    {0,a} = {1} Union (if Epsilon)  note 2 is skipped as there is no 'a' transition to it Union {5, through the a} Union {4} through Epsilon Union {3} through Epsilon Union {0} through Epsilon Union {2} through Epsilon.  = {1, 5, 4, 3, 0, 2}
    {0,b} = {4} Union {3} through Epsilon Union {0} through Epsilon Union {2} through Epsilon (There is no way to b through the Epsilon at 0}.  = {4,3,0,2}
    {1,a} = {5} Union {4} through Epsilon Union {3} through Epsilon Union {0} through Epsilon Union {2} through Epsilon = {5,4,3,0,2}
    {1,b} = {2}
    etc
    Last edited by javapenguin; April 16th, 2012 at 08:18 PM.

  6. #5
    Banned
    Join Date
    May 2010
    Location
    North Central Illinois
    Posts
    1,631
    My Mood
    Sleepy
    Thanks
    390
    Thanked 112 Times in 110 Posts

    Default Re: Not sure how to work with multiple delimiters. Also, there is random tabbing.

    Ok, I've tried some things, but it's causing errors left and right. I have tried to do this:

    if (state, character) = {} and (state, lambda) = {}) then it's {} so don't add it or something to that effect.
    if (state, character} = {} and {state,lambda} !={}) then check to see if the state lambda says to go to contains character, which is an index
    The first character read in is 0, the seconds is 1, though for one program with only 1 regular, non empty character, I needed to try and index out of bounds exception catcher to stop it from referring to an out of bounds index at the end part of the read in, but anyway, if it finds the character there, then it adds the state where that character links to, and once there, it can go and follow the lambdas and add a state that a lambda links to until it runs out of lambdas (or runs into a circle where it would just keep adding the same ones over and over.). On the other hand, if it didn't find the character at the first lambda, it goes and continues checking lambdas until either

    1.) It finds a link to the character and adds that link value to the set and then keeps checking lambdas and adding them as described above
    2.) It simply runs out of lambdas and never finds the character, which would simply be another empty set {}.

    In the end, I'm going to get a Set of Sets. And once I find a set, I try and get the lambda procedure on that one, for instance if I get a Set

    {1,2,3,4} then I do the procedure above for 1 union it with doing the procedure for 2, union it with doing the procedure for 3, and then union it with doing the procedure for 4.

    If it makes a new Set that isn't already in the Set of Sets, then it keeps going on it. (There might be some kind of limit there, but I can't figure out what it is.)

    If it finds that all are repeats, then it stops. It's a lot of recursion, Iterators, and all that fun stuff that I've never had much practice with and/or am not very good at.

    import java.util.Scanner;
    import java.io.File;
    import java.io.FileNotFoundException;
    import java.util.ArrayList;
    import java.util.HashSet;
    import java.util.Iterator;
     
     
    public class fsm
    {
     
    private static class FileParser
    {
     
     
     
    }
     
    private static class MySet
    {
     
    private  ArrayList<Integer> intList;
     
    public MySet()
    {
    intList = new ArrayList<Integer>();
     
    }
     
    public  void add(Integer data)
    {
    intList.add(data);
     
    }
     
    public void remove()
    {
    intList.remove(0);
     
    }
     
    public int size()
    {
    return intList.size();
    }
     
    public Integer get(int index) throws NullPointerException
    {
    return intList.get(index);
     
    }
     
    public ArrayList<Integer> getList()
    {
    return intList;
    }
     
     
     
    }
     
     static MySet[][] ms;
     static int characters;
        public static void main(String[] args)
        {
    	Scanner s = null;
    	Scanner s2 = null;
    	ArrayList<Integer> stateList = new ArrayList<Integer>();
    	ArrayList<Character> alphabet = new ArrayList<Character>();
     
    	ArrayList<String> transitionLines = new ArrayList<String>();
    	ArrayList<String[]> splitArray = new ArrayList<String[]>();
     
     
     
     
     
     
     
     
    	int numOfStates = 0;
     
    try
        {
       s  = new Scanner(new File(args[0]));
        }
     
        catch (ArrayIndexOutOfBoundsException aioobe)
        {
        System.out.println("Error!");
        System.exit(1);
     
        }
     
    catch (FileNotFoundException fnfe)
        {
    	System.out.println("Error!");
    	System.exit(1);
     
        }
    numOfStates = s.nextInt();
     
        System.out.println(numOfStates);
     
        String[][] splits = new String[numOfStates][2];
     
     
     
     
        String line = s.nextLine();
        if (line.equals(""))
        line = s.nextLine();
     
     
     
     
        System.out.println(line);
     
        char[] chars = line.toCharArray();
     
     
     
     
        char empty = ' ';
     
     
        String tab = "\t";
        char tab2 = tab.charAt(0);
     
        for (int i =0; i < chars.length; i++)
        {
        if (chars[i]!= empty && chars[i]!=tab2)
        {
        alphabet.add(chars[i]);
        }
        }
     
        alphabet.add('');
     
         System.out.println(alphabet.toString());
     
         characters = alphabet.size();
     
     
         for (int i=0; i < numOfStates; i++)
         {
         transitionLines.add(s.nextLine());
     
         }
     
         System.out.println(transitionLines.toString());
     
     
         for (int i =0; i < splits.length; i++)
         {
         splits[i] = transitionLines.get(i).split(":");
     
         }
     
     
         for (int i =0; i < splits.length; i++)
         {
         for (int j=0; j < splits[i].length; j++)
         {
         System.out.println(splits[i][j]);
     
         }
     
     
         }
     
       //  String[][] test = 
         ArrayList<String[]> fredBowling = new ArrayList<String[]>();
     
         for (int i =0; i < splits.length; i++)
         {
         fredBowling.add(splits[i][1].split("}"));
         }
         splits[0][1].split("}");
     
         ArrayList<Integer> state = new ArrayList<Integer>();
     
         for (int i=0; i < splits.length; i++)
         {
         state.add(Integer.parseInt(splits[i][0]));
     
         }
     
     
       //  System.out.println(java.util.Arrays.toString(test));
     
     
        // String smaller[] = new String[test.length];
     
        ArrayList<ArrayList<String>> smaller = new ArrayList<ArrayList<String>>();
     
         for (int i =0; i < fredBowling.size(); i++)
         {
         smaller.add(new ArrayList<String>());
         for (int j = 0; j < fredBowling.get(i).length; j++)
         {
         int temp = fredBowling.get(i)[j].indexOf("{");
     
         smaller.get(i).add(fredBowling.get(i)[j].substring(temp + 1));
         }
     
         }
     
       //  System.out.println(java.util.Arrays.toString(smaller));
     
        //  ArrayList<String[]> finale = new ArrayList<String[]>();
         ArrayList<ArrayList<String[]>> finale = new ArrayList<ArrayList<String[]>>();
     
         // for (int i =0; i < smaller.length; i++)
      //    {
       //   finale.add(smaller[i].split(","));
     
     //    }
     
         for (int i =0; i < smaller.size(); i++)
         {
         finale.add(new ArrayList<String[]>());
         for (int j =0; j < smaller.get(i).size(); j++)
         {
         finale.get(i).add(smaller.get(i).get(j).split(","));
     
         }
     
     
         }
     
         for (int i =0; i < finale.size(); i++)
         {
         for (int j =0; j < finale.get(i).size(); j++)
         {
         for (int k =0; k < finale.get(i).get(j).length; k++)
         {
         System.out.println("MySet[" + i + "]["+j +"].get(" + k + ") = " +finale.get(i).get(j)[k]);
         }
     
     
         }
     
         }
     
          ms = new MySet[finale.size()][finale.get(0).size()];
     
         for (int i =0; i < finale.size(); i++)
         { // begin for
     
         for (int j =0; j < finale.get(i).size(); j++)
         { // begin for 
         try{
     
         ms[i][j] = new MySet();
     
     
     
         for (int k =0; k < finale.get(i).get(j).length; k++)
         { // begin for
         if (finale.get(i).get(j)[k] != null && !finale.get(i).get(j)[k].equals(""))
         { // begin if 
         ms[i][j].add(Integer.parseInt(finale.get(i).get(j)[k]));
     
         } // end if
     
         } // end for
     
         } // end try
           catch(ArrayIndexOutOfBoundsException aioobe)
         {
         System.err.println("Index " + i + "," + j + " is out of bounds.");
         }
     
         } // end for
     
     
         } // end for
     
         for (int i =0; i < ms.length; i++)
         {
         for (int j =0; j < ms[i].length; j++)
         {
         for (int k =0; k < ms[i][j].size(); k++)
         {
         System.out.println("ms[" + i + "]["+j +"].get(" + k + ") = "+ ms[i][j].get(k));
     
         }
         }
     
         }
     
         int startingState = s.nextInt();
         System.out.println("s:" + startingState);
     
         String fs = s.nextLine();
     
         if (fs.equals("") || fs == null)
         fs = s.nextLine();
     
         String[] firstHalf = fs.split("}");
     
     
          int temp = firstHalf[0].indexOf("{");
     
          String secondHalf = firstHalf[0].substring(temp+1);
     
          String[] finalHalf = secondHalf.split(",");
     
     
         ArrayList<Integer> finalState = new ArrayList<Integer>();
     
         for (int i =0; i < finalHalf.length; i++)
    {
    if (finalHalf[i] != null && !finalHalf[i].equals(""))
    {
    finalState.add(Integer.parseInt(finalHalf[i]));
    }
     
    }
     
    System.out.println("Accepting state: " + finalState.toString());
     
    System.out.println(getFinalStateFrom(0, 0).toString());
     
    System.out.println(recursion1(0,0).toString());
     
    try
        {
       s2  = new Scanner(new File(args[1]));
        }
     
        catch (ArrayIndexOutOfBoundsException aioobe)
        {
        System.out.println("Error!");
        System.exit(1);
     
        }
     
    catch (FileNotFoundException fnfe)
        {
    	System.out.println("Error!");
    	System.exit(1);
     
        }
     
     
     
     
     
        }
     
        public static HashSet<Integer> getLambdas(Integer state)
        {
     
        HashSet<Integer> hs = new HashSet<Integer>();
     
       if (ms[state][characters - 1] != null)
        {
        for (int i =0; i < ms[state][characters - 1].size(); i++)
        {
        if (ms[state][characters - 1].get(i) != null)
        {
        hs.add(ms[state][characters -1].get(i));
        }
        }
        }
     
        return hs;
        }
     
     
        public static HashSet<Integer> getFinalStateFrom(Integer state, Integer character)
        {
     
        ArrayList<Integer> al = new ArrayList<Integer>();
     
        HashSet<Integer> hs = new HashSet<Integer>();
     
     
        if (ms[state][character] != null)
        {
        for (int i =0; i < ms[state][character].size(); i++)
        {
        if (ms[state][character].get(i) != null)
        {
        hs.add(ms[state][character].get(i));
        }
        }
        }
     
     
      //  hs.addAll(getFinalStateFrom(state, characters - 1);
     
      System.out.println("Added: " + hs.toString());
     
        hs.addAll(getLambdas(state));
     
        System.out.println("Added: " + hs.toString());
     
        return hs;
     
     
     
     
     
        }
     
        public static HashSet<Integer> recursion1(Integer state, Integer character)
        {
        HashSet<Integer> hs = new HashSet<Integer>();
        for (Iterator<Integer> it = getFinalStateFrom(state,character).iterator(); it.hasNext();)
        {
        try
        {
        hs.addAll(getFinalStateFrom(getFinalStateFrom(it.next(), characters -1).iterator().next(), character));
        }
     
        catch(java.util.NoSuchElementException nsee)
        {
        System.out.println("This element doesn't exist!");
        }
     
        }
        return hs;
        }
     
     
    }

    That was my crude attempt at recursion. Obviously I don't know how to start correctly and it's really adding nothing.

    nfa1.nfa
     

    7
    a
    [a, ]
    [0: {} {1,5}, 1: {2} {} , 2: {3} {}, 3: {4} {}, 4: {} {}, 5: {6} {}, 6: {5} {}]
    0
    {} {1,5}
    1
    {2} {}
    2
    {3} {}
    3
    {4} {}
    4
    {} {}
    5
    {6} {}
    6
    {5} {}
    MySet[0][0].get(0) =
    MySet[0][1].get(0) = 1
    MySet[0][1].get(1) = 5
    MySet[1][0].get(0) = 2
    MySet[1][1].get(0) =
    MySet[1][2].get(0) =
    MySet[2][0].get(0) = 3
    MySet[2][1].get(0) =
    MySet[3][0].get(0) = 4
    MySet[3][1].get(0) =
    MySet[4][0].get(0) =
    MySet[4][1].get(0) =
    MySet[5][0].get(0) = 6
    MySet[5][1].get(0) =
    MySet[6][0].get(0) = 5
    MySet[6][1].get(0) =
    Index 1,2 is out of bounds.
    ms[0][1].get(0) = 1
    ms[0][1].get(1) = 5
    ms[1][0].get(0) = 2
    ms[2][0].get(0) = 3
    ms[3][0].get(0) = 4
    ms[5][0].get(0) = 6
    ms[6][0].get(0) = 5
    s:0
    Accepting state: [4, 5]
    Added: []
    Added: [1, 5]
    [1, 5]
    Added: []
    Added: [1, 5]
    Added: []
    Added: []
    This element doesn't exist!
    Added: []
    Added: []
    This element doesn't exist!
    []




    nfa2.nfa:
     

    6
    a b
    [a, b, ]
    [0: {1} {4} {2}, 1: {5} {2} {}, 2: {5} {} {}, 3: {} {} {0}, 4: {} {1} {3}, 5: {} {} {4}]
    0
    {1} {4} {2}
    1
    {5} {2} {}
    2
    {5} {} {}
    3
    {} {} {0}
    4
    {} {1} {3}
    5
    {} {} {4}
    MySet[0][0].get(0) = 1
    MySet[0][1].get(0) = 4
    MySet[0][2].get(0) = 2
    MySet[1][0].get(0) = 5
    MySet[1][1].get(0) = 2
    MySet[1][2].get(0) =
    MySet[2][0].get(0) = 5
    MySet[2][1].get(0) =
    MySet[2][2].get(0) =
    MySet[3][0].get(0) =
    MySet[3][1].get(0) =
    MySet[3][2].get(0) = 0
    MySet[4][0].get(0) =
    MySet[4][1].get(0) = 1
    MySet[4][2].get(0) = 3
    MySet[5][0].get(0) =
    MySet[5][1].get(0) =
    MySet[5][2].get(0) = 4
    ms[0][0].get(0) = 1
    ms[0][1].get(0) = 4
    ms[0][2].get(0) = 2
    ms[1][0].get(0) = 5
    ms[1][1].get(0) = 2
    ms[2][0].get(0) = 5
    ms[3][2].get(0) = 0
    ms[4][1].get(0) = 1
    ms[4][2].get(0) = 3
    ms[5][2].get(0) = 4
    s:0
    Accepting state: [5]
    Added: [1]
    Added: [1, 2]
    [1, 2]
    Added: [1]
    Added: [1, 2]
    Added: []
    Added: []
    This element doesn't exist!
    Added: []
    Added: []
    This element doesn't exist!
    []




    nfa3.nfa:
     

    5
    a b
    [a, b, ]
    [0: {1} {} {}, 1: {} {2} {}, 2: {2,3} {2} {}, 3: {} {4} {}, 4: {} {} {}]
    0
    {1} {} {}
    1
    {} {2} {}
    2
    {2,3} {2} {}
    3
    {} {4} {}
    4
    {} {} {}
    MySet[0][0].get(0) = 1
    MySet[0][1].get(0) =
    MySet[0][2].get(0) =
    MySet[1][0].get(0) =
    MySet[1][1].get(0) = 2
    MySet[1][2].get(0) =
    MySet[2][0].get(0) = 2
    MySet[2][0].get(1) = 3
    MySet[2][1].get(0) = 2
    MySet[2][2].get(0) =
    MySet[3][0].get(0) =
    MySet[3][1].get(0) = 4
    MySet[3][2].get(0) =
    MySet[4][0].get(0) =
    MySet[4][1].get(0) =
    MySet[4][2].get(0) =
    ms[0][0].get(0) = 1
    ms[1][1].get(0) = 2
    ms[2][0].get(0) = 2
    ms[2][0].get(1) = 3
    ms[2][1].get(0) = 2
    ms[3][1].get(0) = 4
    s:0
    Accepting state: [4]
    Added: [1]
    Added: [1]
    [1]
    Added: [1]
    Added: [1]
    Added: []
    Added: []
    This element doesn't exist!
    []



  7. #6
    Banned
    Join Date
    May 2010
    Location
    North Central Illinois
    Posts
    1,631
    My Mood
    Sleepy
    Thanks
    390
    Thanked 112 Times in 110 Posts

    Default Re: Not sure how to work with multiple delimiters. Also, there is random tabbing.

    Ok, the original issue of reading in was resolved. I'm going to move this to another thread. It's now a recursion issue.

Similar Threads

  1. string tabbing problem
    By rhalliwell1 in forum What's Wrong With My Code?
    Replies: 11
    Last Post: March 9th, 2011, 01:47 PM
  2. [SOLVED] Splitting String by Multiple Delimiters
    By relixus in forum What's Wrong With My Code?
    Replies: 0
    Last Post: February 4th, 2011, 08:54 PM
  3. [SOLVED] Tabbing columns
    By SnarkKnuckle in forum What's Wrong With My Code?
    Replies: 4
    Last Post: January 24th, 2011, 10:50 PM
  4. Can a for loop work with random number?
    By humdinger in forum Loops & Control Statements
    Replies: 7
    Last Post: January 10th, 2010, 10:06 PM
  5. Generation of random number using random class
    By JavaPF in forum Java Code Snippets and Tutorials
    Replies: 0
    Last Post: April 16th, 2009, 07:10 AM