

Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Canonical collection, The closure procedure, Look ahead symbol, Set of LR, Parser state, Eventual parser DFA, Parser intial state, Grammar and production, Core of state are the points from this lecture. You can find series of lecture notes for compiler construction here.
Typology: Study notes
1 / 2
This page cannot be seen from the preview
Don't miss anything!


Sohail Aslam Compiler Construction Notes Set:2-
An LR(1) item is a pair [X → α•β, a] where X → αβ is a production and a∈ T (terminals) is look-ahead symbol. The model uses a set of LR(1) items to represent each
Canonical Collection
begins by building a model of parser’s initial state. The initial state consists of the set of LR(1) items that represent the parser’s initial state, along with any items that must also hold in the initial state. To simplify the task of building this initial state, the construction requires that the grammar have a unique goal symbol. The convention is to add a new start symbol S to grammar and a production
This leads to the augmented grammar
S → E E → E + (E) | int
The Closure Procedure
The item [S → • E, $] describes the parser’s initial state. It represents a configuration in which recognizing S followed by $ would be a valid parse. This item, i.e., [S → • E, $]
becomes the core of the first state in CC, labeled I 0. If the grammar has several distinct productions for the start symbol, each of them generates an item in this initial core of I 0. The procedure closure does this.
closure( s ) = repeat for each [X → α•Yβ, a] ∈ s for each production Y → α for each b ∈ FIRST(βa) s ← s ∪ [Y → • γ, b] until s is unchanged
Let’s apply this procedure to the augmented grammar.
The first set is I 0 = closure ({[S → • E, $] }). Equating the terms in the procedure, s = {[S → • E, $]}, [X → α • Yβ, a ] ⇔ [S → • E, $], X = S, α = ε, Y = E, β = ε, a = $, Y → γ ⇔ E → E + (E) and E → int FIRST(βa) = FIRST($) = $.
Sohail Aslam Compiler Construction Notes Set:2-
s = { [S → • E, $] } ∪ { [E → • E + (E), $] } ∪ { [E → • int, $] } = { [S → • E, $] , [E → • E + (E), $] , [E → • int, $] }
The set s changed so we repeat. The item [S → • E, $] is already processed. The for loop considers [X → α•Yβ, a] ⇔ [E→•E+(E),$], which leads to the match up X = E, α = ε, Y = E, β = +(E), a = $, Y → γ ⇔ E → E + (E), ⇔ E → int FIRST(βa) = FIRST(+(E)$) = +. The set s is extended
s = s ∪ { [E → • E+(E), +] } ∪ { [E → • int, +] }