|
CS 3723
Programming Languages
Spring 2013 |
Questions and Corrections,
with Responses
|
- Question (Mon, Jan 14, 2013 at 9:41 PM):
I had a question with regard to
Recitation 1. I see that in your
instructions you specifically say use one while and one switch.
Here is what that would look like:
[Student gives what looks like a correct solution to part 1
of Recitation 1.]
That being said, wouldn't it be more logical to use a double
while loop.
[Student gives what looks like a close-to-correct solution
to part 5 of Recitation 1. Slight technical problem,
not important.]
I agree that the complexity would be O(n^2),
but I'm somehow not too convinced with the while-switch solution.
Could you reason for me why you were looking for while-switch solution?
Answer: The idea behind this recitation: Start
with a sequence of straight-line code inside a main
function, with no functions or function calls, no loop constructs,
no structured if-then-else, but only using gotos, ifs
with a goto as target, and so forth, to carry out a computation.
Even the "mystery" program is a fairly simple example
that will cause students a lot of grief (sorry!).
The first method of translation (using a single while and
a single switch, or a single while and
a single extended if-the-else) shows that
such a program can always be rewritten without gotos.
This is mostly of theoretical interest, because the gotoless
program is even more complex than the original. You
talk about a double while loop, but a double loop is
implicit in the original code with gotos.
Clearly, recovering the original stuctured form (if there
was such an original stuctured form) would be preferable,
but in general this cannot be done. Just defining this problem
(what might "the original structured form" mean?) seems
difficult or impossible. The "mystery" program shows that
even for a simple example (one that did come from a well-structured
original program) it can be difficult to recover anything
like the original.
Restating: When you are faced with a program with
gotos, and you don't want or can't have the gotos, you have
two basic choices:
- You can always use a while and switch to
simulate execution of the original program, but this
doesn't make a fundamental change and is no help in understanding
the original program.
- You can try to recover the original loops and other
structures. You will not always be able to do that.
- Question (Tue, Jan 15, 2013 at 1:41 PM):
I have a question about our first recitation. In the mystery program
there are multiple loops in the code right? just want to make
sure im solving it correctly without gotos.
Answer: The hint that goes along with item 7 in the recitation
is a pretty big hint. First identify simple (small) loops that
you can find, while eliminating some labels and gotos. Make sure
you keep compiling and running the code (because you will inevitably
make mistakes), and finally be aware that the code you see comes
from an original program that had a function call and the body
of that function. This is a pretty tough exercise.
- Question (Fri, Jan 18, 2013 at 1:34 PM):
I was a confused about what to submit for recitation 1. Are we going to need two versions of section 4 and two versions of section 5? I have fixed section 4 and section 5 replacing all the goto's, using a single while and switch statement in each program. If we do need two versions, what are we supposed to do for the second version? Also, are we supposed to send everything in one big text file?
Answer: To answer the last question first, yes, everything should be concatenated into one big text file (be sure to save it as "text"), and the result submitted. Please arrange things in the order given and number them as in the recitation.
First, you should have the two programms, rewritten with a single while and a single switch, and with no gotos or labels. Each of these programs should be followed by the result of a run.
Next, you should have the same two programs, rewritten so as to recover the original form (if possible), that includes loops and if-the-else's. No labels, no gotos, no switch statements. Again include the output of each program. The first program is relatively simple (just a loop within a loop), while the second program is quite hard. (You shouldn't invest too much time in it.)
- Question (Sun, Jan 27, 2013 at 7:47 PM):
In Recitation 2
I'm confused and concerned about the last three entries for
floating point constants: ".e-2", "e-2", and "1.2e".
Answer:I should have left these off. These are examples
of illegal floating point constants. The compiler will flail
away at them in different ways, but there will always be an error message.
Revision date: 2013-01-19.
(Please use ISO
8601, the International Standard.)
|