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)
-
Open the CUP User Manual
for quick reference.
- Open eclipse and carefully follow the following steps. If these
steps do not work for you, switch to a new workspace and try again.
- 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.
- 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. You should
also arrange for the workspace to be refreshed after the build.
- The build should work and you should see the output from running
all of the parsers in the console window.
Hereafter, you can run this build by clicking on the arrow with the red
toolbox.
-
This should produce some output in the console window.
The parse of problem 1a should be fine, but the rest will have
various problems -- don't worry about that yet.
- 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 problems to be solved by bottom-up parsing.
The nature of this studio is to study syntax-directed parsing, which
means that we will be translating inputs into some form as we parse.
Your work will be done in the various cup files found in the root
directory for this studio.
Part 1 (20 minutes)
- cup1a parses a comma-separated list of numerals.
The semantic actions are already in place to translate the numerals into
a numeric value.
Each
numeral is parsed as a sequence of digits.
- Draw a parse tree for the numeral
431 and study how the bottom up parse computes the numeric value of the
digits from left to right. The semantic type used for the values is
the java.lang.Integer object.
- Be prepared to show (to a suitably curious observer)
when reductions take place. Be prepared to explain when the
semantic actions are performed and what they do.
- cup1b is the same problem, but uses a local class
in the action code block to carry the value up the parse tree.
-
Fill in your group's members' names.
-
You have to fill in the semantic actions.
Note to C++ programmars: declaring a variable in Java does not instantiate
it. Thus, RESULT is null unless you do something
about it.
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.
- cup2 This grammar looks like the cup1 grammars.
This time, instead of producing the numeric value of the numerals, you are
to produce the count of the number of digits in the numeral.
Part 2 (20 minutes)
- cup3 Each sequence of numerals will now either be
interpreted base 10, as before, or
preceded by an x (terminal) and then interpreted base 16.
See the test files, both
good and bad, to get a better idea of how this works.
In your group, and with help from others as needed, develop a grammar to
parse and translate decimal and hexadecimal numerals into their numeric
value.
Part 3 (20 minutes)
- cup4 An ordinary sequence of numerals is
still interpreted base 10.
Howeve, this time, if an x appears before the sequence,
the next numeral (d) value is one less than the base in which
the rest of the numerals should be interpreted. See the test files for
examples and counterexamples.
Part 4 (20 minutes)
- Work in groups on your bottom-up portion of Lab 2.
Finally
Be sure to mail yourself a copy of the work you did on lab 2 in studio,
so you can submit it with the rest of your lab 2 work.
Be sure to submit the following before leaving studio:
- A printed copy of your cup files
- A printed copy of the console run on all the grammars and test
files.
Last modified 10:46:52 CST 17 February 2008
by Ron K. Cytron