Docsity

Left most Derivation - Compiler Construction - Lecture Notes, Study notes of Compiler Construction

Toggle sidebar
bg1
L
Le
ec
ct
tu
ur
re
e
1
17
7
Note that productions output are tracing out a lefmost derivation. The grammar symbols
on the stack make up left-sentential forms.
LL(1) Table Construction
Top-down parsing expands a parse tree from the start symbol to the leaves. It always
expand the leftmost non-terminal. Consider the state
S ?∗ βAγ
with b the next token and we are trying to match βbγ. There are two possibilities
1. b belongs to an expansion of A.
Any A ? α can be used if b can start a string derived from α. In this case we say
that b ∈ FIRST(α)
2. b does not belong to an expansion of A. Expansion of A is empty, i.e., A ? ε
and b belongs an expansion of γ, e.g., bω. which means that b can appear after A
in a derivation of the form S ?∗ βAbω. We say that b ∈ FOLLOW(A).
Any A ? α can be used if α expands to ε. We say that ε ∈ FIRST(A) in this case.
Definition
FIRST(X) = { b | X ?∗ ba } ∪ { ε | X ?∗ ε }

Partial preview of the text

Download Left most Derivation - Compiler Construction - Lecture Notes and more Study notes Compiler Construction in PDF only on Docsity!

LeLeccttuurree 1 177

Note that productions output are tracing out a lefmost derivation. The grammar symbols on the stack make up left-sentential forms.

LL(1) Table Construction

Top-down parsing expands a parse tree from the start symbol to the leaves. It always expand the leftmost non-terminal. Consider the state

S? ∗^ β A γ

with b the next token and we are trying to match β b γ. There are two possibilities

  1. b belongs to an expansion of A. Any A? α can be used if b can start a string derived from α. In this case we say that b ∈ FIRST( α )
  2. b does not belong to an expansion of A. Expansion of A is empty, i.e., A? ε and b belongs an expansion of γ , e.g., b ω. which means that b can appear after A in a derivation of the form S? ∗^ β Ab ω. W e say that b ∈ FOLLOW(A).

Any A? α can be used if α expands to ε. We say that ε ∈ FIRST(A) in this case.

Definition

FIRST(X) = { b | X? ∗^ ba } ∪ { ε | X? ∗^ ε }