Download as pdf or txt
Download as pdf or txt
You are on page 1of 2

UE COMPILER CONSTRUCTION Summer Term 2024

2024
AAU Klagenfurt / ITEC Taschwer

_________________________________________________________
Homework Assignment 2

Learning goals:
Apply the concepts and methods presented in chapter “top-down parsing” of the lecture
to some exercise problems. These are related to LL(k) grammars and top-down parsers.

Presentation:
Please prepare the solutions for informal presentation in class, and fill in the online check
list in ZEUS.

Task 1 Left Factoring


Consider grammar G=(V,T,P,S) with V={A,B,S}, T={a,b,c} and P:

S -> aA | aB | b
A -> bB | bA
B -> cA | cb

a) Explain why a predictive LL(1) parser cannot be built for this grammar. What is the
minimal lookahead k for G being an LL(k) grammar?

b) Transform G to an equivalent LL(1) grammar G’ by left factoring and eliminating all


chain productions (i.e. productions of the form X -> Y, where X and Y are non-
terminals).

Task 2 Left Recursion


Consider grammar G = (V, T, P, S) with V={A, S}, T={a, b, c} and P:

S -> Aa | ac

A -> Sb | Ac | b

a) Identify all (direct and indirect) left recursions in G. Why is a top-down parser not able
to cope with these left recursions?

b) Transform G to an equivalent grammar G’ by eliminating all left recursions.

Task 3 LL(1) parser


Consider the LL(1) grammar G = (V, T, P, S) with V={A, B, S}, T={a, b, c, d, e} and
productions P:

S -> aAc | cS

A -> dB | bA | 

B -> eBa | b

a) Find the FIRST and FOLLOW sets of the non-terminals of grammar G.

b) Create a parsing table for a predictive non-recursive LL(1) parser for grammar G.

c) Visualize the process of parsing w = cadebac  L(G) in tabular form.

Page 1 of 2
Task 4 Panic mode error recovery

a) Outline the panic mode error recovery technique for LL(1) parsers and describe how
the set of synchronizing tokens of a non-terminal is determined.

b) Represent the process of parsing v = abdedac  L(G) in tabular form using the parser
of Task 3 with panic mode error recovery, and determine the corrected word of L(G)
derived by the error handling mechanism.

Page 2 of 2

You might also like