Studio 5: Real grammar, real ambiguities, real fun

Studio Sessions Overview:

The results of your studio session are to be reported and documented in a file that you save in your workspace. You are to print and turn in one copy of that report for your group. In the descriptions of the studio exercises, verbs like report and document are indications of activities you should summarize and discuss in your report.

In your groups, take turns documenting results, looking over shoulders, and staffing the keyboard.

It is unacceptable to copy anything without understanding it. At any point, the TA or instructor can point to something you've done and ask you why it works, or change it and ask what would happen with the modification.


In each of the following sections, go as far as you can in the time allotted, but move on to the next section so you'll have a chance to work on each section while in studio.

Warm Up: (10 minutes)

  1. Open up some kind of document you can print later that has your group's findings. In that document be sure to include: You will turn in just one document per group.
  2. Open the lab 3 page
  3. Get an instance of Lab3 installed on the computer you and your group are using in Studio.
  4. Run the ant target testClassSolution to make sure you've installed it correctly.
  5. Run the ant target testMySolution and verify that some output is produced.

Main Problems

All of your work will be done in the jmm.cup file. Work carefully, in groups as usual, but feel free to bounce ideas off others around you. For each of the situations below:

  1. [ 35 minutes ] Around line 384 of jmm.cup, you will see the following productions for a SelectionStatement:
    SelectionStatement
            ::= IF LPAREN Expression RPAREN Statement ELSE Statement
    /*      |   IF LPAREN Expression RPAREN Statement
     */
            ;
    
    Leave the first production alone, but uncomment the second one, so that both are considered by CUP. Address the resulting ambiguity.

  2. [ 20 minutes ] Below the productions you considered above, Around line 405 of the jmm.cup as originally give to you, you will see the productions for PrimaryExpression:
    PrimaryExpression
            ::= QualifiedName:t
            |   NotJustName:rhs
    /*
     *  You will eventually have to explain the conflicts that arise when the rule below
     *       is uncommented.
     *  This rule lets a block ( { .... }  ) serve anywhere a primary expression could.
     *  So you could write  a = { while (h>5) h = h -k; };
     *
     *      |   Block:rhs
     */
            ;
    
    Uncomment the last production so it can be considered by CUP. Address the resulting ambiguity.

  3. [ 20 minutes ] Work together on the rest of Lab 3 by constructing and linking in portions of the AST.

Finally

Be sure to submit the following before leaving studio:

You are welcome to use the work done in studio for this portion of your Lab 3 assignment. Just be sure to credit the group for the work done for these parts.



Last modified 11:46:15 CST 03 March 2008 by Ron K. Cytron