Docsity

Identifying LL(1) Parsability & Parse Tables for Given Grammars, Study notes of Computer Science

Toggle sidebar
bg1
Discussion #3: Top-Down Parsing
1 LL(1) parsing
Directions: For each of the following grammars,
1. Identify the kfor which the grammar is LL(k) parsable. If itโ€™s not LL parsable, then explain why.
2. Rewrite the grammar (if needed) so that it is LL(1) parsable.
3. Provide the LL(1) parse table, first using you intuitive understanding of how a predictive parser works,
and then using the more formal method of FIRST and FOLLOW sets. Identify the relationship between
the two approaches.
4. Provide the parse stack for some non-trivial input.
(a)
Eโ†’T+E|T
Tโ†’int |int โˆ—T|(E)
(b)
Sโ†’(L)|a
Lโ†’L, S |S
(c)
Eโ†’T E0
E0โ†’+T E0|๎˜
Tโ†’F T 0
T0โ†’ โˆ—F T 0|๎˜
Fโ†’(E)|id
(d)
Sโ†’iEtS S0|a
S0โ†’eS |๎˜
Eโ†’b
1

Partial preview of the text

Download Identifying LL(1) Parsability & Parse Tables for Given Grammars and more Study notes Computer Science in PDF only on Docsity!

Discussion #3: Top-Down Parsing

1 LL(1) parsing

Directions: For each of the following grammars,

  1. Identify the k for which the grammar is LL(k) parsable. If itโ€™s not LL parsable, then explain why.
  2. Rewrite the grammar (if needed) so that it is LL(1) parsable.
  3. Provide the LL(1) parse table, first using you intuitive understanding of how a predictive parser works, and then using the more formal method of FIRST and FOLLOW sets. Identify the relationship between the two approaches.
  4. Provide the parse stack for some non-trivial input. (a) E โ†’ T + E | T T โ†’ int | int โˆ— T | (E)

(b) S โ†’ (L) | a L โ†’ L, S | S

(c) E โ†’ T Eโ€ฒ Eโ€ฒ^ โ†’ +T Eโ€ฒ^ |  T โ†’ F T โ€ฒ T โ€ฒ^ โ†’ โˆ—F T โ€ฒ^ |  F โ†’ (E) | id

(d) S โ†’ iEtSSโ€ฒ^ | a Sโ€ฒ^ โ†’ eS |  E โ†’ b