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.