Module 3 Exercises

  1. Write regular expressions for:
  2. The driver algorithm in Section 3.2 is missing many details. For example, the issue of blanks needs to be addressed. Extend the algorithm to ignore blanks and to:
  3.  
  4. Example 3 shows a partial table for recognizing an identifier consisting of letters and digits beginning with a letter. Since neither letter nor digit is a single character, more details need to be provided. Traditionally there have been two methods. Discuss what these might be (and then check the answers to selected exercises).

  5.  
  6. Show a CASE statement equivalent to the table in Example 3.

  7.  
  8. Write the details of the four actions GetChar, Accept, Retract, and Return from Section 2.

  9.  
  10. From the method described in Section 3.3.1 write an algorithm to convert from an from a regular expression to a NFA. Describe the NFA as an abstract data type, rather than deciding upon a particular implementation such as a table or CASE statement.

  11.  
  12. Using the method described in step 2 of Section 3.3.2 , write an algorithm to convert from an NFA to a DFA, again describing each of the NFA's as an abstract data type.

  13.  
  14. Using the method described in step 2 of Section 3.3.3 , write an algorthm to convert from DFA to a minimal DFA, again describing each of the DFA's as an abstract data type.

  15.  
  16. Implement an NFA (as described in Exercises 6 and 7) as (a) a table and (b) a CASE statement.

  17.  
  18. Name some applications where it would be better to do the extensive work required to write a lexical analyzer generator, rather that writing a lexical analyzer and then making changes to it when needed.

  19.  
  20. Is the LEX grammar unstratified? You will need a LEX manual to answer this.

  21.  
  22. The table in Section 3.3.1 1 step (d) is incomplete. Add the missing information.

  23.  
  24. Convert the following to a DFA.
    1. Solution
       
  25. Convert the following to a minimal DFA.

  26.  
     
     
    a
    b
    >A 
    B
     A,D,F
     
    C,F 
     C 
    A
    G,D
    E
    E,D,H
     
    F
    *F 
     
    D,H
    B
    G,D,H
    *H 
     
     
     
      Solution
Send questions and comment to: Karen Lemone