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

Answer:

Yes.


Almost Practical Problem

Here is the automaton from chapter 1 that recognizes Java identifiers. Assume that the reject state is q2.

FSA to recognize Identifiers

Here is the recognize method. In order to make the logic of the else if statements easier, transitions labeled with several groups of characters are implemented as one else if per group.

  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++ ) ;

      // State 0
      if      ( state==  && current == ) 
        state = ;

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

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

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

      // State 1
      else    ( state==  && current == ) 
        state = ;

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

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

      else if ( state==  && current >=  && 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;
  }

QUESTION 16:

Fill in the blanks so that recoginze() accepts Java identifiers.