Midterm 1, CSCI 3155
September 28th, 2004
You have 70 minutes to answer these questions. Please read all
questions before you start. This is a closed-book exam. The points
for a question are split evenly between its parts. Please
remember that you are bound by the CU honor code.
- (20 points) This question covers the topic: Syntax and Semantics, BNF.
- [Skill 2.2] Describe in your own words the language that this BNF
grammar generates
<S> -> <A> a <B> b
<A> -> <A> b | b
<B> -> a <B> | a
- [Skill 2.5] Write a BNF grammar for a language that contains all
sentences that contain one or more 'a' and one 'b'. For example,
aaabaa, baaa, and aab are in the language but b or
a or aaaa are not in the language.
- (20 points) This question covers the topic: Type checking and equality
- [Skill 5.2] Let's suppose you are designing a programming
language and need to pick whether the language will use name equality or
structural equality. Give one advantage of name equality over
structural equality and one advantage of structural equality over name
equality. Support your points with examples.
- [Skill 5.3] Consider the types
class C1 {
int i;
C1 *x;
}
class C2 {
C2 *x;
int i;
}
class C3 {
int i;
C1 *x;
}
- Are types C1 and C2 the same by
structural equality? Explain.
- Are types C1 and C3 the same by
structural equality? Explain.
- (30 points) This question covers the topic: Data types
- Give an example program that uses an enumeration type. Argue why
integers or named integer constants would be less appropriate than the enumeration type.
- Give an example program that uses a subrange type. Argue why
integers would be less appropriate than the subrange type.
- (20 points) This question covers the topics: Bindings and Scoping
- [Synthesis] Write a program that demonstrates the difference
between the scope of a variable and its lifetime. Explain your
example.
- [Synthesis] How are the storage binding and lifetime of a
variable related to each other? Explain.