This file explains the exact format of saved files in JFLAP, so that they can be edited or 
generated manually or by other programs. JFLAP will read saved files generated by older versions 
properly, but older versions may not be able to load the new JFLAP saved files.

Note that each line should be exactly as specified below, without blank or extra lines at the 
beginning or between lines. Words can be separated by 1 or more spaces or even tabs if desired. 
Trailing data (except spaces) like comments at the end of lines should NOT be used, since on 
some lines it actually won't be ignored. If data on a line is larger than your screen it should 
still be on 1 line only. (beware of editors like pico that will automaticly break up your lines)

The first line of the file contains a string corresponding to the type of the machine. 
-for FSAs : "One-Way-FSA"
-for PDAs : "PDAP"
-for TMs  : "REGTM" , with the word "TAPE" on the following line, and the number "1" or "2" on 
	    the third line to indicate if it is a one tape or two tape TM.

The following line should contain a single integer indicating the number of states in the 
machine.

The next line should contain only a "#". The only purpose of this line is to maintain 
compatibility with older JFLAP files which had the alphabet stored on this line. It can actually
be used to put a comment in the file if you so desire since it isn't even read in.
PDAs and Turing machines require a second line with a "#" on it.

The next line contains the number of the initial state  (so if the initial state was the third
state  it would be 3) or a "0" if there is no initial state. Note that this number is the 
position of the initial state in the list, NOT the number on its label. For example if your 
machine has 3 states "q0" "q5" and "q8" and "q5" is the initial state then the number would be 2.

The next line contains a list of the final states, indicated by their position, and terminated 
by a "0". Note that if there are no final states the "0" should still be present.
Example: "3 5 0" would mean states 3 and 5 are final, or just "0" would mean there are 
no final states

The next X lines represent the transitions leaving from each state, where X is the number of 
states (indicated on the second or 4th line of the file depending on the type of machine)
The format for transitions is different for each machine, but for all machines all transitions 
are stored one after the other on the line, terminated by the string "EOL":

  for FSAs, the line should contain the transitions's label, followed by the number of the 
state that the transition leads to.
Example: a transition labeled "ab" going to state 5 would be: "ab 5"

  for PDAs, the line should contain the input to read followed by the string to pop from stack, 
followed by the string null, followed by the state this transition leads to, followed by the 
string to push on the stack.
Example: a transition labeled "a;b;c" going to state 4 would be:  "a b null 4 c" 

  for 1 tape TMs, the line should contain the symbol to read, followed by the state this 
transition leads to, followed by the symbol to write, followed by the direction (R, L or S).
Example: a transition labeled "a;b,c" leading to state 5 would be: "a 5 b c"

  for 2 tape TMs, the line should contain (on one line separated by spaces)
symbol to read from tape 1
number of the state the transition leads to 
symbol to write on tape 1
direction (R, L or S) on tape 1 
symbol to read from tape 2
symbol to write on tape 2
direction (R, L or S) on tape 2
Example: a transition labeled "a;b,c|d;e,f" leading to state 5 would be: "a 5 b c d e f" 

So for example in an FSA if a state had two transitions labeled "abc" and "d" leading 
respectively to states 3 and 4 the whole line would be: "abc 3 d 4 EOL"

A state with no transitions should just have a line containing "EOL".
Note that if any part of a transition's label is empty, treat it as if it contained the string 
"null".
Example: a lambda transition in an FSA has no label. A lambda transition to state 5 would
be represented with: "null 5"  

This can get rather long with a 2 tape TM that has several transitions, so make sure your editor
wraps the line and doesn't add a new one!


The following X lines (where X is the number of states) represent the states. They should 
contain the state's name "q5" followed by the state's coordinates on the machine's display 
(x and y). Note that (0,0) is in the upper left corner of the display and the default size is 
700 by 409 pixels.
Example: if state "q5" is located at x:200 and y:300 then its line would be: "q5 200 300"

Note that state names always have to be made of the letter "q" followed by a positive integer.


Here is an example of a simple FSA saved file, with added comments (do not add comments to your 
files, this is just for making the example easier to understand)

One-Way-FSA		//name of the machine type
4			//number of states
#			//stub line 
1			//initial state is "q0"
2 0			//"q1" is the only final state
a 2 b 3 EOL		// two transitions from first state. One leading to state "q1" with label
			// "a" and one leading to state "q2" with label "b"
EOL			
EOL			//no transitions from the third state
EOL
q0 30 206
q1 243 91		//the second state is called "q1" and is located at (243, 91)
q2 202 312
q3 489 122


Here's an example of a simple 2 tape TM with added comments:

REGTM			//name of machine type: TM
TAPE			//TAPE keyword
2			// 2 tape TM
4			//number of states	
#			
#			// 2 stub lines
2			//initial state is "q1"
0			//no final states
a 4 b c null e f EOL	//transition from first state labeled "a;b,c|;e,f" leading to state "q3"
EOL		
EOL			//no transitions from this state
EOL
q0 47 275
q1 244 140
q7 507 149		//the third state is labeled q8	
q8 274 321


Here's an example of a simple PDA without comments:

PDAP
3
#
#
1
0
a b null 2 c EOL
EOL
EOL
q0 148 214
q1 336 90
q2 393 222
