CS 3723-001 Programming Languages
Spring 2003 -- Mid-term Exam
Directions: Use your own paper for answers. When you are done
you may keep this exam sheet. The answers will be posted.
- Consider the following finite automaton.
- Give a regular expression describing the language recognized
by this automaton. (You haven't been given an algorithm to do this,
though such algorithms exist, but you should just intuitively try to
figure it out. If you can't do the regular expression, then give any kind
of description of the language.)
- Write a regular grammar that recognizes the same language
as this automaton. (Recall that a regular grammar
has all grammar rules in one of two forms:
A ---> a B
A ---> a
where A and B are any non-terminals
and a is any terminal. You can rename the three
states in the automaton A,
B. and C.)
- Consider the formal Grammar
P ---> E '$'
E ---> E '+' T | E '-' T | T
T ---> T '*' S | T '/' S | S
S ---> F '^' S | F
F ---> 'a' | 'b' | 'c' | '(' E ')'
- Give the relative precedence of each of the five operators.
- What is the associativity of '+'.
What is the associativity of '^'?
- Is this grammar ambiguous? (Just Yes or No.)
- Construct the parse tree for the sentence:
(a + b^c)*a $
- What prevents this grammar from being parsed with a
recursive descent parser?
- Consider a shift-reduce parser as we had in a recitation.
Suppose the following grammar rule is being used for a reduction.
E ---> E '+' T
- What is being reduced?
- Where is the thing being reduced to be found?
- What is it being reduced to?
- What happens to the thing it is reduced to?
- Consider the following grammar rule from the parser assignment:
W ---> '{' E '?' { S } '}'
- What construct is this rule describing?
- How does the recursive descent parser know that it is
encountering this particular construct on input?
- What does the portion { S } mean on the right side?
- Give the small part of your recursive descent parser
that handles the { S }.
- Think about the MIPS code that is used to translate
this construct. What comes first in this code?
What are the last two parts of the MIPS code used to
translate this construct?
- Consider the recitation that involved translating
while and if-then-else
statements. As part of the translation process, labels
would be inserted into the assembly code. In order to handle
nested and repeated instances of these constructs, what trick
was needed (or if you like, how did you manage to translate these
so that the constructs could be nested or repeated)?
- This is a question about passing an array to a function
as a paramter.
- In C, C++, and Java, when an array is passed to a function
as a parameter using only its name, what is actually passed?
- Give a way in C and C++ that would allow one to pass an array to
a function by value, that is, a copy of the
array would be passed, leaving the original array unchangeable
from inside the function.
Points for each problem: 1-20, 2-20, 3-13, 4-20, 5-13, 6-14.