Directions: Use your own paper for answers. When you are done you may keep this exam sheet and should pick up an answer sheet.

P ---> E '$'
E ---> E '+' T | E '-' T | T
T ---> T '*' S | T '/' S | S
S ---> F '^' S | F
F ---> 'a' | 'b' | 'c' | '(' E ')'
Construct the parse tree for the sentence: (a + b^c)*a $
ifstmt ----> "IF" "(" expr ")" stmt [ "ELSE" stmt ]
(Recall that the brackets [] mean an optional item.)
Write code or pseudo-code for a function ifstmt that could work as part of a recursive descent parser for a grammar including this grammar rule. You should assume that a scanner is given to return tokens, and that separate functions expr() and stmt() are available. Use any convenient notation or language. Do not try to supply I/O statements, header files or other details. Just give the bare code for the function ifstmt.
S ---> E ("S" is the start symbol)
E ---> E "+" T | T
T ---> T "*" F | F
F ---> "(" E ")" | id
Use the following shift-reduce table for this grammar:
| id | * | + | ( | ) | $ |
-----+-----+-----+-----+-----+-----+-----+
S | | | | | | acc | ( "s" means "shift")
E | | | s | | s | r |
T | | s | r | | r | r | ( "r" means "reduce")
F | | r | r | | r | r |
id | | r | r | | r | r | ( "acc" means "accept")
* | s | | | s | | |
+ | s | | | s | | |
( | s | | | s | | |
) | | r | r | | r | r |
$ | s | | | s | | |
-----+-----+-----+-----+-----+-----+-----+
Carry out the shift-reduce parse of the following sentence,
showing the stack, current symbol, remaining symbols,
and next action to take at each stage. (This sentence has the
extra artifical symbol $ stuck in at the beginning
and the end.)
$ id * ( id + id ) $
(Remember that you should initially shift the starting
$.)Points for each problem: 1-25, 2-25, 3-25, 4-25.