CS 651 Compilers
Sample Midterm Examination
Bill Campbell
This is a closed book examination. Write your solutions in your blue examination
booklets.
- Consider
the regular expression (a* | b*)*
- Use Thompson's
algorithm to produce a non-deterministic finite state automaton to
recognize the language described by this expression. [10]
- Use
subset construction to produce a deterministic FSA recognizing the same
language. [15]
- Show
that the following grammar is ambiguous. [10]
E -> E + E | E * E | ( E ) | i
- Explain
why, or why not, Java is a context free language. An example might help. [10]
- Consider
the following grammar.
S -> A a
S -> a
A -> c
A-> b A
- Compute
first and follow for S and A. [10]
- Construct
an LL(1) parsing table for this grammar. [10]
- Is
follow necessary for constructing this table? Why or why not? [5]
- Show
the stack and parsing actions for parsing the input string: bbca [5]
- Write
a recursive descent parser for this grammar, using the tools you were
given for parsing Java by recursive descent. [10]
- Say
you wanted to add an until statement to Java. For example, one might write
until ( i >= j )
System.out.print( i++ );
- What
changes would one have to make to the Lexer in
our compiler? [5]
- Write
a method for Parser that would parse the until
statement by recursive descent, making use of any methods available in
Parser. Produce an ast node for it using the
constructor with header
UntilStatement(int line, Expression e, Statement s) [10]