CS250      Lab6 - Grammars

Objectives:

  1. The Grammar button in JFLAP brings you to an editor where you can enter a grammar.  The brute force parse option under the Input menu simply  repeatedly replaces symbols starting with the start symbol of the grammar until it just happens to stumble on the string the user entered.

    Download the lab6 files and open ex6.1 in the grammar editor.  Test it out with the brute force parser or multiple brute force parser.
     
    List three strings accepted by the grammar and three strings rejected.  Clearly and succinctly describe in words the language it represents.

     

  2. You can type in your own grammars in a new editor window.
     
    Create and thoroughly test grammars for p28 11a,b,c

     

  3. The grammar in ex6.2 is more complex then any we have seen so far. Test it out.
     
    Give three strings accepted by the grammar and give a conjecture about what language it might represent.

     

  4. Section 3.3 of your text defines a special form of grammar called a Regular Grammar.  As you might expect, Regular grammars precisely describe the regular languages.  We can show this by showing that all regular grammars have an equivalent FA.  And all FAs have an equivalent regular grammar.

    Open grammar ex6.1 and use the convert to FA option to do the conversion. 
     
    Briefly describe the algorithm for converting a regular right-linear grammar to an FA

    How would we convert from a FA to a regular grammar?  Briefly describe this algorithm. ( Trying out some conversions in JFLAP with the convert from FA to grammar option will probably help you see this simple algorithm).

     

  5. A context free grammar (CFG) is another special form of a grammar.  A CFG must have a single non-terminal on the left side of productions and the right side can contain any combination of terminals and non-terminals.

    Open grammar ex6.3 and test it out.  What language does it accept?  It should be clear that CFGs can accept languages which are non-regular.
     
    Create and test a CFG for the grammar on p134 8c.

     

  6. When you do a brute force parse in JFLAP you have the option of viewing the parse tree which illustrates how a derivation may be done.  Open the file ex6.4 and test it with the input a-b-a.  Look at the parse tree.

     
    Draw another possible parse tree for the input a-b-a with the grammar in ex6.4


    A grammar for which there is a string which may have two distinct parse trees is said to be ambiguous.  Some ambiguous grammars can be rewritten so as to recognize the same language but no longer be ambiguous.  Other languages are inherently ambiguous so that all grammars accepting them are ambiguous.  The grammar in ex6.4 can be rewritten.  Open ex6.5 and test it out.