Studio Sessions Overview:
- We gather as a community in studio session to learn from each other.
Our community includes:
- Our community is egalitarian in terms of learning: all of us will
have questions
and all of us should try to provide answers.
- The idea is to challenge each other
and to share what we discover.
- You are free (downright encouraged) to collaborate in this
session:
- Primarily within your small group of 2-3 people
- Secondarily with any group in the class
- As much as you like with the instructor and TAs
- In studio, the instructor's mission is to observe, interact,
and work with groups.
- How you think, work, and arrive at a solution is
more important than getting the right answer. Thus, the instructor
and TAs will observe you throughout the exercise and offer
constructive feedback.
- The help you receive may be incomplete at any given time, so that
you can work through more of the solution on your own. Do not
hesitate to ask for more help.
- In studio, the student's mission is to acquire new knowledge
and skills by the collaborative solving of problems.
- You are not graded on whether you get wrong
or right answers on this exercise.
- You are graded on your level of participation in studio.
- Participation is defined as
- Asking questions, at any level, of any person in the studio
- Discussing possible solutions with people in the studio
- Helping somebody in the studio solve a problem
- Presenting or demonstrating your solution to people in the studio
- Documenting your group's experiences in studio
- Please eliminate external stimuli (cell phones, IM, Facebook)
during studio. Please devote yourself to learning, mastering, and
extending the material for the session.
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)
- Suggestion: one person in the group could be working ahead on
the analysis part of a grammar while somebody else is typing in the
recursive-descent methods. Switch up the roles throughout the studio
session.
-
Have handy your book or my pages on
computing
First and Follow sets.
- Open eclipse and import (File..Import) this zip file using the Existing projects into workspace method (Do not choose
the archive file method). After clicking on "Existing projects into
workspace" select as the archive file the file you downloaded earlier.
If this is your first time running eclipse, be sure your workspace is
situated in your CEC filesystem space so that it survives this session.
- Open the following files
- Main.java -- (in the default package)
the file has a succession of
classes you will be editing
to put in your recursive descent parsers.
You must print this out and turn it in at the end of studio.
- You will probably not want to look at these files, but they
are used to generate the scanner for this studio.
- terminalsymbols.cup -- a dummy CUP specification that
generates the sym.java file of terminal symbol
definitions.
- scanner.jflex -- the scanner specification
of the session. You should log into two computers, so that one
of you can edit and run the code while another of you types
in the report. You must switch roles equally in the session.
- Fill in the group's members' names in the Main.java file.
- You need to add the CUP runtime jar file to the build path for
this project in eclipse:
- Select the project
- Choose File...Properties
- Chose the Java Build Path
- Add an external jar file
- The jar you want to add is situated in the Tools subdirectory of
this project, and is called java-cup-11a.jar.
- Right-click on the build.xml file and run it as an
Ant Build...
- In the dialog for this, be sure that the JRE tab has the
build running in the same JRE as the workspace.
- Open the Refresh tab and be sure the workspace will
refresh after the build. This is necessary because the
ant build will generate some new files that need to be visible
and compiled.
- The build should work and you should see no compilation errors.
If something looks strange, ask for help.
Hereafter, you can run this build by clicking on the arrow with the red
toolbox.
- To run the program, right-click the Main class (found
in the default package) and
drag down to Run as....Java Application. No arguments need
to be supplied.
Hereafter, you can run the appolcation by clicking on the big arrow (without the red
toolbox).
You could also run it using the run target of the build.xml file. That target will make sure your project is built before it runs.
If you want to do it this way, keep using the arrow with the red toolbox,
and it will both build and run your program.
-
This should produce some output in the console window.
- Look at the output, and look at the Example class given
in Main.java
- Look at the method getTestFiles() and see how it
supplies the testfiles used for this grammar's parse.
- Look at the methods in this class (S() and B())
and see how they accurately
reflect the grammar.
- Look at how the terminal symbol a is referenced
as sym.a in the code. Open sym.java to see
where those symbols appear.
- Look at the use of int peek(), void expect(char),
and void oops(String) are used in the code.
- If you have time, glance at the build.xml file.
Discuss how it controls the build process you witnessed.
Main Problems
You will consider a success of grammars and use them to create
recursive-descent parsers. All of your work should be done in
Main.java, but you are welcome to create more test files
if you wish.
For each rule of each grammar, you are asked which symbols predict
that particular rule. Recall that the predict sets are computed
primarily from First sets, but if a rule's right-hand side can
derive the empty string, then the Follow set of the rule's left-hand
side must also be included.
All of your work is given and can be done in the Main.java
file. The information here is supplemental.
Before implementing any of these parsers,
check your Predict sets with a neighboring group or the professor or
TA.
Part 1 (20 minutes)
- MatchingParens A grammar that generates matching parentheses with an x in the middle.
You should be able to write a recursive-descent parser for this
grammar without changing the grammar at all.
- Problem1a Problem 1a from page 137 of the Crafting a Compiler text.
- Problem1d Problem 1d from page 137 of the Crafting a Compiler text.
Part 2 (20 minutes)
Do not comment out your work so far. Instead, keep it going
forward so that at the end, everything you've done is still in the run.
- Declarations This is a grammar that generates declaration statements
for a list of variables. Take a look at the test files to get
an idea of the language. To find out the names of the
terminal symbols, look in the sym.java file.
For example, the keyword "int" is represented by sym.INT.
This grammar has left recursiion, which you must eliminate
using the principled techniques for doing so.
- IfThenElseFi This grammar generates if-then-else-fi statements. The "fi"
terminal always ends and brackets the "if".
The grammar has problems you must address before you can
write a recursive-descent parser.
Part 3 (20 minutes)
-
Expressions There is just one grammar in this part -- an expression grammar with
left recursion.
- I already devoped a grammar suitable for Recursive Descent parsing.
- I implemented the methods for the parser.
- Your job: use parameter values and return values so that the
numerical computation is carried out by the parse.
Do not use any global varibles to do this, or the techinque
will fail when you get to Lab 2!
Part 4 (time permitting)
-
IfThenElse Do not implement a parser for this grammar, just try to make
the grammar suitable for top-down parsing.
Finally
Be sure to submit before leaving studio:
- A printed copy of your Main.java file.
- A printed copy of the console run on all the grammars and test
files you were able to handle.
Last modified 13:54:24 CST 12 February 2008
by Ron K. Cytron