• Keine Ergebnisse gefunden

Properties of LR-DFA Construction

N/A
N/A
Protected

Academic year: 2022

Aktie "Properties of LR-DFA Construction"

Copied!
4
0
0

Wird geladen.... (Jetzt Volltext ansehen)

Volltext

(1)

Properties of LR-DFA Construction

Lemma 1

(a) Each path leading to a state q with item

[A α.β]

ends with

α

. (b) If q is a state with items

[A α.δ]

and

[B β.γ],

then

α

is a postfix of

β

or

β

a postfix of

α.

(c) If there is a transition marked with H from state p to state q , then p contains an item of form

[C γ.Hδ].

Proof.

The properties hold for LR-NFA by construction and can be transferred to LR-DFA.

Ina Schaefer Context-Free Analysis 1

Properties of LR-DFA Construction (2)

Lemma 2

For any A,

ψ,α,β, it holds that, the item [A α.β]

is contained in a state that is reached by

ψα

iff there exists a right derivation

S

rm ψAu rm ψαβ

u Proof.

cf. Wilhelm, Maurer, Thm. 8.4.3, p. 363.

Ina Schaefer Context-Free Analysis 2

(2)

LR(0) Characterization Theorem

Theorem

Let

Γ

be a reduced CFG.

Γ

is an LR(0) grammar iff LR-DFA(Γ) does not contain any conflicts.

Proof:

Left-to-Right-Direction: LR(0) property implies that LR-DFA has no conflicts.

Let q be a state of LR-DEA(Γ) with two items [A α.] and[B β.γ].

We show that these items do not cause a conflict.

By Lemma 1(b), there are µ,ν with µα =νβ and with µ =εor ν = ε.

Let ψ be a path leading toq, then according to Lemma 1(a), there exists ϕ with ψ = ϕµα =ϕνβ.

Ina Schaefer Context-Free Analysis 3

LR(0) Characterization Theorem (2)

By Lemma 2, there are the following right derivations S rm ϕµAu rm ϕµαu S rm ϕνBv rm ϕνβγv

Case 1: Suppose, the items[A α.] and [B β.γ] are different and cause a reduce/reduce-conflict, i.e. γ = ε.

We show that then it has to holds that A= B and α= β,

i.e. both items are identical which is a contradiction to the assumption.

Since γ = εand ϕµα = ϕνβ, it holds that ϕµα= ϕνβγ.

By the LR(0) property, it holds ϕµ = ϕν and A= B (and v =γv).

Fromϕν =ϕµ and ϕµα = ϕνβ, it follows thatα = β, i.e. both items are identical.

Ina Schaefer Context-Free Analysis 4

(3)

LR(0) Characterization Theorem (3)

Case 2: Suppose the items [A α.]and [B β.γ]cause a

shift/reduce-conflict, i.e. γ #=εand γ starts with a terminal symbol.

We consider the cases γ T+ and γ =zDρ, where in the first caseγ contains no non-terminal, while in the second it contains at least one non-terminal.

If γ T+, forw =γ, we obtain the derivation

S rm ϕνBv rm ϕνβwv = ϕµαwv The LR(0) property yields ϕν =ϕµ,A =B and v = wv.

Thus, it has to hold that w = εwhich contradicts the assumption γ #= ε.

If γ = zDρ, we can extend the above right derivation

S rm ϕνBv rm ϕνβγv =ϕµαzDρv

rm ϕµαzxEyv rm ϕµαzxwyv

Ina Schaefer Context-Free Analysis 5

LR(0) Characterization Theorem (4)

Then we have the right derivations

S rm ϕµAu rm ϕµαu S rm ϕµαzxEyv rm ϕµαzxwyv The LR(0) property yields in particular that ϕµαzx = ϕµ.

Thus, it has to hold that z = εwhich contradicts the assumption that γ starts with a terminal.

Ina Schaefer Context-Free Analysis 6

(4)

LR(0) Characterization Theorem (5)

Right-to-Left Direction: Conflict-Freedom implies LR(0) Property.

According to the LR(0) Definition, we consider two right derivations S rm ψAu rm ψαu

S rm ϕBx rm ψαy In derivation 2, we assume a production B δ such that ϕδx =ψαy.

By Lemma 2, [A α.] belongs to a state reached byψα and [B δ.] to a state reached byϕδ.

Since ϕδx =ψαy, it holds ϕδ is prefix ofψα or vice versa.

Ina Schaefer Context-Free Analysis 7

LR(0) Characterization Theorem (6)

Case Distinction on relation betweenϕδ und ψα:

(a) ϕδ =ψα:

[A α.] and[B δ.] belong to the same state.

Since LR-DFA has no conflicts, it holds that α= δ andA =B, thus alsoϕ = ψ andx = y. This yields the LR(0) property.

(b) ϕδ is a real prefix ofψα:

Since ϕδx =ψαy, there exists b T undz ∈T such thatx = bzy and hence ϕδbz = ψα.

By Lemma 1(c), the state reached byϕδ has to contain a transition marked with b and an item [C µ.bν].

But this would cause a conflict with[B δ.]which contradicts the conflict-freeness of LR-DFA such that this cases cannot occur.

(c) ψα is a real prefix ofϕδ: analog to case (b).

Ina Schaefer Context-Free Analysis 8

Referenzen

ÄHNLICHE DOKUMENTE

• Non-consecutive Master Course Applied Computer Science with Specialization in Software Engineering.. •

String → Token Stream (or Symbol String) Context-free Analysis:.. Token Stream → Tree

If there are more than one token matching the longest input prefix, one of these tokens is returned by the function symbol. Ina Schaefer Syntax and Type

Recursive Descent LL(k) Parsing Theory LL Parser Generation.. Bottom-Up

Ina Schaefer Context-Free Analysis 60.. Implementation of Parsers Bottom-Up Syntax Analysis.. Principles of

Ina Schaefer Context-Free Analysis 60.. Implementation of Parsers Bottom-Up Syntax Analysis.. Principles of

For sequential access to the symbol table, almost all types of the abstract syntax get an inherited attribute symin of type SymTab and an synthesized attribute symout.

• GlobDeclList, GlobDecl, LocVarList, LocVar, Stat, Exp, ExpList get inherited attribute envin of type Env. • GlobDecl gets synthesized