2.0 Introduction

2.1 Grammars

2.2 Ambiguity

2.3 Summary

Web References

Exercises

Module 2 Exercises  

  1. Derive the string a + a * a using the various expression grammars in this module. (There are four).
  2. Solution
     

  3. For the string of exercise one, and the four grammars, show (a) a right derivation, and (b) a left derivation.

  4.  
  5. Study the first two exercises and devise an algorithm which will derive a given string automatically, looking at the next input symbol only. (You will be "inventing" top-down parsing.)

  6.  
  7. Find an another interpretation for the ambiguous sentence Time flies like an arrow.
  8. Solution
     

  9. Show that the grammar:
    •  
    is ambiguous. Write a grammar that will generate the same set of strings, but that is unambiguous.

    Solution
     

  10. Consider the following grammar:

  11.  

    • Describe the set of strings it generates.
    • Is it ambiguous?
    • Is it recursive?
      •