Do this by showing the evolution of the stack and the
input, and whether shift or reduce actions are taken.

12. Consider the language 'X'*, i.e. sequences of
symbol X. Write two context-free grammars for it:
one left-recursive and one right-recursive. With both
grammars, trace the LR parsing of the string XXXX.
What can you say about the memory consumption of the
two processes?

13. Write a calculator for the four floating point
operations (+ - * /) by using the semantic actions
in one of the standard parser tools (Happy, CUP, Bison).
You can start by writing an expression grammar in BNFC
and then modify the generated parser file.

To make the usage of the calculator smooth, also
accept input without a decimal point, e.g. 3 * 3.14.
The usual operator precedences must of course be followed.

14. Semantic actions can be used to make the parser manage languages
that are not context-free. Write a Happy/JLex/Cup program that
implements a parser for a copy language, where valid expressions
are sequences of identifiers (Ident), with any such sequence
followed by itself:

{x x | x : Ident*}

For instance, foo bar foo foo bar foo is a valid expression, but
foo bar foo bar foo isn't. What is the time complexity of the parser?

Chapter 4: Type checking

15. Using the grammar of Question 11,
write a syntax-directed thanslator
that returns a symbol table indicating the number of occurrences of each
identifier that occurs in the program (i.e. a Stm). For instance, in
the program

{
x = 3 ;
x = 2 - x - y ;
if (x > y) {x = x-1 ;}
}

the identifier x occurs 6 times and y occurs 2 times.

16. Using the typing rules of Chapter 4,
write a derivation of the validity of the statement

while (x > 4) {x = x-1 ;}

You will need a context and a couple of extra typing rules.

17. Write typing rules for the following constructs of C/C++, which
are not covered by Lab 2.

conditional expressions e ? e : e

operator assignments x+=e, x-=e

assignment to an array position e[i] = e

Chapter 5: Interpreter

18. Trace the evolution of the state (the values of variables)
when executing the following program statement by statement.