DFA logic - Dterministic Finite Automata - Computer engineering - C# php asp .Net SAP SQL

Monday, May 26, 2008

DFA logic - Dterministic Finite Automata

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 if( alphabet.charAt(i) == ',' )
comma++;
}

String states=JOptionPane.showInputDialog(null,"# of states");
number=Integer.parseInt(states);

for(int i=0; i int k=0;
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 if( accept.charAt(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 if(i==0){
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 if(kontrol==accepts[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;
}
}

4 comments:

ersin said...

perraa this code is not working..
there are some missing code parts such as: for(int i=0; i

i would like to use it for my lesson at school as automata bla bla :D
i would appreciate it if you give the full code correctly :)

Anonymous said...

Do you know the runescape power leveling, in the game you need the runescape gold. it can help you increase your level. My friends always asked me how to buy runescape accounts, i do not know he spend how much money to buy the runescape money, when i see him in order to play the game and search which the place can buy the cheap runescape power leveling. i also happy with him.

Anonymous said...

hmmm. thanks ....

simon said...

Thanks for providing such useful information.
personal injury lawyer in tampa