The code below is to create a deterministic finite automata. It just builds the logic of a dfa. The gui can be created very easily.
 
import javax.swing.JOptionPane;
import javax.swing.*;
import java.util.*;
public class dfa {
	static String alphabet,son,retrn; 
	static int comma=0;
	static int acomma=0;
	static int number=0;
	static String[][] st=new String[50][50];
   public static void main(String args[]){
      	
	alphabet=JOptionPane.showInputDialog(null,"Alphabet?");
			
			   for( int i=0; i
                                 comma++;
                           }
			
	String states=JOptionPane.showInputDialog(null,"# of states");
	number=Integer.parseInt(states);
        for(int i=0; i
		for(int j=0; j<(alphabet.length()-comma);j++)
        {
	
        st[i][j]=JOptionPane.showInputDialog(null,"q"+i+","+alphabet.charAt(k));
					
							
	System.out.print("q"+i+"--"+alphabet.charAt(k)+"-->"+"q"+st[i][j]+"\n");
	
        k=k+2;
	}
					
}
				
	String start = JOptionPane.showInputDialog(null,"starts state?");
	int start1=Integer.parseInt(start);
	String accept = JOptionPane.showInputDialog(null,"accept states?");
	for( int i=0; i
                acomma++;
        }
        		
	int[] accepts= new int[(accept.length()-acomma)];
				
	int l=0;
	for(int i=0; i<(accept.length()-acomma); i++){
	        accepts[i]=Integer.parseInt(Character.toString(accept.charAt(l)));
		l=l+2;
		System.out.print(accepts[i]);
	}
				
	System.out.println("start state"+start);
	System.out.println("Accept state"+accept);
				
	String strng=JOptionPane.showInputDialog(null,"String?");
	System.out.println(strng);
				
	int[] durums=new int[strng.length()];
				
	for(int i=0; i
		        durums[i]=dfa(start1,strng.charAt(i));
		}
		else{
		        durums[i]=dfa(durums[i-1],strng.charAt(i));
		}
	System.out.println(durums[i]);
	}
				
	int kontrol=durums[(strng.length()-1)];
			
	int kabuluzun=accepts.length;
	      for(int i=0; i
				System.out.println("ACCEPTED!!!");
				break;
			}
			else if(kontrol!=accepts[i]){
				System.out.println(" NOT ACCEPTED!!!");
				break;
					}
				}
//DFA METHOD!!!
public static int dfa(int durum, char deger ){
	
	int deger1=0;
	int sondurum=0;
	for(int i=0;i
			
			if(deger==alphabet.charAt(i)){
				deger1=i;}
			
			else{
				for(int j=0; j<(alphabet.length()-comma-1);j++){
				
				i=i+2;
				if(deger==alphabet.charAt(i)){
					deger1=i-1;
					break;
				}
			}
		}
	sondurum=Integer.parseInt(st[durum][deger1]);
	
}
return sondurum;
}
}
Monday, May 26, 2008
DFA logic - Dterministic Finite Automata
Thursday, May 8, 2008
Little Holiday
since i got a problem with my PC it take too much time to add a new article. Also my exams has taken my to much time as well. So by tomorrow i will add everyday again. Soryy about that holiday :))
Subscribe to:
Comments (Atom)
