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 JFlex Documentation
page in a browser window.
- Open eclipse and import (File..Import) this zip file as an
existing project into your workspace.
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
- studio1.jflex -- the scanner specification
- TestFiles/input -- the sample input
- report.txt -- the file you will print and hand in at the end
of the session
as you'll be modifying them throughout the
session.
- Fill in the group's members' names in the report.txt file.
- 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.
This should produce some output in the console window.
- Look at the output. What do you see and how does it relate to
the scanner specification and sample input files? Spend a few
minutes discussing and documenting (in report.txt) what you see.
If you have time, glance at the build.xml file. Discuss and document how
it controls the build process you witnessed.
Main Problems
For each of the following languages, add an appropriate pattern
to the studio1.jflex file and have the action call found to
respond to the pattern. Also, add whatever strings you need to the
TestFiles/input file so that you can verify that your
pattern works as you expect. Be sure to add some counterexamples, to make
certain your pattern catches only what you expect.
As much as possible, accumulate the patterns, examples, and
counterexamples as you move from
one exercise to the next, so that you can continue
to test that each pattern behaves as it should.
In other words, add to your studio1.jflex file a new pattern
for each exercise while keeping all the old patterns.
At the same time, add to the TestFiles/input file so you can
properly test that the patterns you specified work as you expect. Be sure
to include examples and counterexcamples of the patterns in the input file.
Also, note that the effects of the patterns you add may be unexpected
and may cause you to change things a bit. Document and report what you
learn and how you go about getting JFlex to do your bidding.
Part 1 (20 minutes)
- On seeing the string goodbye, cause the program
to terminate (call System.exit(0))
- For each of your first names, have the scanner
react or respond to your name in some interesting way.
- Look at Yylex.java
(in the default package, you may have to refresh the workspace to see it) and find where the actions appear that
you arranged for the above strings. Document your findings, and compare
what you to see to what you code for actions in Lab 1.
For patterns you don't match, you see output in the console window.
What is producing that output? Try modifying the Yylex.java
action for unmatched patterns and see if it works.
- Find binary integers that are even (end with a 0)
- Find binary integers that have at least 2 1s in them
- Find strings that begin with an h and continue as a binary integer with
- a 1, 2 digits from the end
- a 1, 3 digits from the end
- a 1, 5 digits from the end
- a 1, 10 digits from the end
Report the effects of the above strings on the size of the FSA
generated by JFlex.
- Using the alphabet {a,b,c} find identifiers (strings) of at least
length 2 that end with
a letter other than the one with which they begin.
- Same as above, but extend the alphabet to {a,b,c,d,e}
- Find strings of decimal digits
- Same as above, but now distinguish
- Strings of decimal digits preceded by "0x"
- Strings of decimal digits that begin with a "0"
- All other strings of decimal digits
- Look at Yylex.java and report where you see the
code using a GOTO table to realize the FSA.
Part 2 (15 minutes)
- Come up with two simple regular expressions for the same language.
Try each separately. What do you notice about the number of
states in the FSA that results from each expression? What do you
expect to happen for regular expressions that denote exactly the
same set?
- Find comments using the regular expression
/- a* -/
where a can be any character at all. What do you expect this
pattern to do? What kind of behavior do you see?
- Now find comments using the regular expression developed in
class. You can find the expression on page 12 (slide 24) of
this part of my tutorial.
- Try to simplify the regular expression. What is the result on
the number of states produced by JFlex?
Part 3 (20 minutes)
We next develop a sequence of expressions that build up components of
a programming language such as Java. Develop patterns, examples, and
counterexamples for the following:
- Java identifiers (begin with a letter, continue with letters or
digits)
- The keyword if. I want you to try interchanging the
patterns for this and the previous pattern in your JFlex file.
What behavior do you see?
- Add 5 or so more keywords and test that it works for you.
- Now try some Java punctuation:
- +
- ++
- +=
- 3 more of your choosing
- Java (quoted) strings
- Comments of both varieties (// and /*... */)
Part 4 (time permitting)
One or both of the following
-
Develop an FSA that recognizes binary numbers that are evenly divisible by 5.
- Examples: 00, 101, 1010, 1111
- Counterexamples: 01, 1, 100, 11
Turn the FSA into a regular expression, and get JFlex to find such patterns.
- Work on the FSA for homework 1 if you have not done so already.
Finally
Be sure to submit before leaving studio:
- A printed copy of your findings report. Each student should sign this
and make sure his or her name appears in the text at the top.
- A printed copy of your studio1.jflex file
- A printed copy of your TestFiles/input file.
Last modified 11:29:34 CST 04 February 2008
by Ron K. Cytron