Review for Quiz 0
One-page version suitable for
printing.
Question 0-1
Consider the following grammar.
S -> (no tokens)
| a S b S
| b S a S
- a. Give a derivation for
the sentence b a a b.
The tree at right is to prove to you that it is possible.
- b. Give a derivation for the sentence
a b a a b b.
- c. Draw a parse tree for the sentence a b a b.
(See part (a) for an example of how to indicate a derivation to the
empty sentence.)
- d. Give a succinct English description of the language
that this grammar describes. This description should not
simply describe the grammar, but instead the properties of the
sentences in the language.
Solution
Question 0-2
Consider the following C code.
#include <stdio.h>
int p = 5;
void f(int a, int b) {
a = 2;
b = 5;
p = a + p;
}
int main() {
int a = 3;
f(a, p);
printf("%d %d\n", p, a);
return 0;
}
- a. C++ uses pass-by-value parameters by default. What
does this program print?
- b. What would it print if it used pass-by-reference
parameters by default instead?
- c. What about pass-by-value-result
parameters?
Solution