go to previous page   go to home page   go to next page

Answer:

Yes.


Prototype Program

Here is the program with the lines specific to a particular automaton removed.

class FSA
{

  public boolean recognize(String str)
  {
    final int reject =  ;  // rejection state
    int  state = 0;        // the current state
    char current;          // the current character
    int  index = 0 ;       // index of the current character

    // continue while there are input characters
    // and the reject state has not been reached
    while ( index < str.length() && state != reject  )
    {
      current = str.charAt( index++ ) ;

      // Model State --- copy and paste as needed
      if      ( state== && current== )
        state = ;

      else if ( state== && current== )
        state = ;

      else if ( state==  && current >=  && current <= )
        state = ;

      else
        state = reject ;

    }

  // if the final state was reached with the last character,
  // the string is accepted.
  if ( index == str.length() && state ==  )
    return true;
  else
    return false;
  }

}

class FSAtester
{
  public static void main (String[] args)
  {
    String str = null;
    FSA    fsa = new FSA();

    str = args[0];

    if ( fsa.recognize( str ) )
      System.out.println("The string is recognized.");
    else
      System.out.println("The string is rejected.");
  }
}

The state transition statements in the body of the while loop need to be modified for the specific finite state automaton you wish to implement. Recall that there will be an if or else if for each state transition of the automaton.


QUESTION 15:

Is Big_AL a legal Java identifier?