FormeleMethode/TestAutomata.cs
/// <summary>
/// Reads the file and set objects and returns an automata.
/// </summary>
/// <param name="fileName">Name of the file.</param>
Reads the file and set objects and returns an automata.
Reads the file and set objects and returns an automata .
public static Automata<string> ReadGraphFile(string fileName)
		{
			List<string> endStates = new List<string>();
			List<string> startStates = new List<string>();
			List<Transition<string>> transitions = new List<Transition<string>>();
			SortedSet<char> alphabet = new SortedSet<char>();
			string[] lines = System.IO.File.ReadAllLines(fileName + ".dot");
			foreach (string line in lines)
			{
				if (line.Contains("doublecircle"))
				{
					endStates.Add(line.Split('"')[1]);
				}
				if (line.Contains("->"))
				{
					if (line.Contains("label"))
					{
						string[] l = line.Split('"');
						transitions.Add(new Transition<string>(l[1], Convert.ToChar(l[5]), l[3]));
						alphabet.Add(Convert.ToChar(l[5]));
					}
					else
					{
						string[] l = line.Split('"');
						startStates.Add(l[3]);
					}
				}
			}
			Automata<string> m = new Automata<string>(alphabet);
			foreach (Transition<string> t in transitions) {
				m.AddTransition(t);
			}
			foreach (string end in endStates)
			{
				m.DefineAsFinalState(end);
			}
			foreach (string start in startStates)
			{
				m.DefineAsStartState(start);
			}
			return m;
		}
public static Automata < string > ReadGraphFile ( string fileName ) { List < string > endStates = new List < string > ( ) ; List < string > startStates = new List < string > ( ) ; List < Transition < string > > transitions = new List < Transition < string > > ( ) ; SortedSet < char > alphabet = new SortedSet < char > ( ) ; string [ ] lines = System . IO . File . ReadAllLines ( fileName + " " ) ; foreach ( string line in lines ) { if ( line . Contains ( " " ) ) { endStates . Add ( line . Split ( ' ' ) [ 1 ] ) ; } if ( line . Contains ( " " ) ) { if ( line . Contains ( " " ) ) { string [ ] l = line . Split ( ' ' ) ; transitions . Add ( new Transition < string > ( l [ 1 ] , Convert . ToChar ( l [ 5 ] ) , l [ 3 ] ) ) ; alphabet . Add ( Convert . ToChar ( l [ 5 ] ) ) ; } else { string [ ] l = line . Split ( ' ' ) ; startStates . Add ( l [ 3 ] ) ; } } } Automata < string > m = new Automata < string > ( alphabet ) ; foreach ( Transition < string > t in transitions ) { m . AddTransition ( t ) ; } foreach ( string end in endStates ) { m . DefineAsFinalState ( end ) ; } foreach ( string start in startStates ) { m . DefineAsStartState ( start ) ; } return m ; }
Reads the file and set objects and returns an automata.
Reads the file and set objects and returns an automata .
// Open file // Read lines // If endstate // Transitions // If normal transition or starttransition // l1 is from l5 is symbol l3 is tostate // Create automata
fileName
string
Name of the file.
Name of the file .