In three paragraphs or so, discuss why one cannot build a predictive
parsing table for a grammar that does not terminate using the
recursive descent parsing method.
Explain the difference in text as well as code fragments between
inheritance of interface and inheritance of implementation. Show the
mechanisms for each in Java and C++ where they exist. What
mechanism(s) in C++ and Java may be used when you want to have a
class that uses both inheritance of interface and inheritance of
implementation.?
Is it always possible to compute the FIRST and FOLLOW sets with one
pass through a grammar, possibly rearranging productions? If so
explain why. If not produce a grammar that illustrates why it can?t be
done.
Consider the HashMap class in Java (similar to HashTable we spoke
about in class) with methods :
Object
get(Object key)
Object
put(Object key, Object value)
a) Give a rationale for the signatures of get and put
b) Suppose I want to put something that is not an Object into a
HashMap instance, how would that be done? Briefly explain and
illustrate with an original code fragment.
Consider the HashMap question above. Consider the following code fragment
public interface Rabbit{
void eat ( );
void hop( )}
class Bunny {
public Bunny() { } // does nothing for now
public void eat ( ) {
// does whatever
}
public void hop ( ) {
// does whatever else
}
public Boolean isCute () {
returns true;
}
}
class KillerRabbit {
public KillerRabit() { }
public void eat ( ) {
// does whatever
}
public void hop ( ) {
// does whatever else
}
public Boolean isCute () {
returns false;
}
}
HashMap rabbits= new HashMap(); // make the
Bunny pinky = new Bunny ();
Bunny killer = new KillerRabbit ();
// put them in the hash table
rabbits.put(?pinky?, pink);
rabbits.put(?killa?, killer);
// What?s wrong with the line below ? if anything? - part a
Bunny b = rabbits.get(?pinky?);
// What?s wrong with these lines ? if anything? - part b
Rabbit kr = (Rabbit)rabbits.get(?killa?);
kr.isCute();
a)
b)
List five or more differences between arrays in Java and arrays in C++
with a brief explanation and very short fragment to illustrate. Hint:
for one of the five differences:
This code fragment is completely legal in Java
Object o = new int[10];
a)
b)
c)
d)
e)
a) What is the BNF for an even length sentence containing only a?s and
b?s, that oscillates between a and b (e.g first a then b then a then b
??, or first b , then a , then b then a ?)
Examples: abab ba babababa |