0% found this document useful (0 votes)
16 views

Ejemplo LR0

The document describes the step-by-step construction of an LR(0) automaton for a context-free grammar. It starts with the initial state S0 and closure and uses the GOTO and CLOSURE operations to derive new states. The resulting automaton has 6 states (S0-S6) that can recognize strings defined by the grammar.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
16 views

Ejemplo LR0

The document describes the step-by-step construction of an LR(0) automaton for a context-free grammar. It starts with the initial state S0 and closure and uses the GOTO and CLOSURE operations to derive new states. The resulting automaton has 6 states (S0-S6) that can recognize strings defined by the grammar.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 31

Ejemplo de

construccion de un
automata LR(0)
Gramatica

s → e

e → e+v
| v

v → x
| y
CLOSURE( { s → ∙ e } )

S0
s→∙e
e→∙e+v
e→∙v
v→∙x
v→∙y
?
S0 e
s→∙e
e→∙e+v v ?
e→∙v
v→∙x x
v→∙y
y ?
?
GOTO(S0 , e)
S1

S0 e
s→∙e
e→∙e+v
e→∙v
v→∙x
v→∙y
GOTO(S0 , e)
S1
s → e∙
S0 e
s→∙e
e→∙e+v
e→∙v
v→∙x
v→∙y
GOTO(S0 , e)
S1
s → e∙
e → e∙ + v
S0 e
s→∙e
e→∙e+v
e→∙v
v→∙x
v→∙y
GOTO(S0 , e)
S1
s → e∙
e → e∙ + v
S0 e
s→∙e
e→∙e+v
e→∙v
v→∙x
v→∙y
CLOSURE(S1) = S1
entonces no se agregan
nuevos elementos a
S1
GOTO(S0 , v)
S1
s → e∙
e → e∙ + v
S0 e
s→∙e S4
e→∙e+v
e→∙v v
v→∙x
v→∙y
GOTO(S0 , v)
S1
s → e∙
e → e∙ + v
S0 e
s→∙e S4
e→∙e+v
e → v∙
e→∙v v
v→∙x
v→∙y
GOTO(S0 , v)
S1
s → e∙
e → e∙ + v
S0 e
s→∙e S4
e→∙e+v
e → v∙
e→∙v v
v→∙x
v→∙y

CLOSURE(S4) = S4
GOTO(S0 , x)
S1
s → e∙
e → e∙ + v
S0 e
s→∙e S4
e→∙e+v
e → v∙
e→∙v v
v→∙x
v→∙y
x S5
GOTO(S0 , x)
S1
s → e∙
e → e∙ + v
S0 e
s→∙e S4
e→∙e+v
e → v∙
e→∙v v
v→∙x
v→∙y
x S5
v → x∙
GOTO(S0 , x)
S1
s → e∙
e → e∙ + v
S0 e
s→∙e S4
e→∙e+v
e → v∙
e→∙v v
v→∙x
v→∙y
x S5
v → x∙

CLOSURE(S5) = S5
GOTO(S0 , y)
S1
s → e∙
e → e∙ + v
S0 e
s→∙e S4
e→∙e+v
e → v∙
e→∙v v
v→∙x
v→∙y
x S5
v → x∙
y
S6
GOTO(S0 , y)
S1
s → e∙
e → e∙ + v
S0 e
s→∙e S4
e→∙e+v
e → v∙
e→∙v v
v→∙x
v→∙y
x S5
v → x∙
y
S6
v → y∙
GOTO(S0 , y)
S1
s → e∙
e → e∙ + v
S0 e
s→∙e S4
e→∙e+v
e → v∙
e→∙v v
v→∙x
v→∙y
x S5
v → x∙
y
S6
v → y∙
CLOSURE(S6) = S6
GOTO(S0 , y)
S1
s → e∙
e → e∙ + v
S0 e
s→∙e S4
e→∙e+v
e → v∙
e→∙v v
v→∙x
v→∙y
x S5
v → x∙
y
S6
v → y∙
Todos los estados alcanzables de S0
S1
s → e∙
e → e∙ + v
S0 e
s→∙e S4
e→∙e+v
e → v∙
e→∙v v
v→∙x
v→∙y
x S5
v → x∙
y
S6
v → y∙
S1
s → e∙
+ ?
e → e∙ + v
GOTO(S1 , +)
S2

S1 +
s → e∙
e → e∙ + v
GOTO(S1 , +)
S2
e → e +∙ v
S1 +
s → e∙
e → e∙ + v
GOTO(S1 , +)
S2
e → e +∙ v
S1 +
s → e∙
e → e∙ + v

CLOSURE(S2) =
{v→∙x,v→∙y}
GOTO(S1 , +)
S2
e → e +∙ v
S1 + v→∙x
s → e∙ v→∙y
e → e∙ + v
Todos los estados alcanzables de S1
S2
e → e +∙ v
S1 + v→∙x
s → e∙ v→∙y
e → e∙ + v
S1
S2
s → e∙
e → e∙ + v e → e +∙ v
S0 e + v→∙x
s→∙e S4 v→∙y
e→∙e+v
e → v∙ x
e→∙v v v
v→∙x y
v→∙y
x S5 ? ?
y
v → x∙ ?
S6
v → y∙
GOTO(S2 , v)
S1
S2
s → e∙
e → e∙ + v e → e +∙ v
S0 e + v→∙x
s→∙e S4 v→∙y
e→∙e+v
e → v∙ x v
e→∙v v
v→∙x y
v→∙y
x S5 ? S3

y
v → x∙ ?
S6
v → y∙
GOTO(S2 , v)
S1
S2
s → e∙
e → e∙ + v e → e +∙ v
S0 e + v→∙x
s→∙e S4 v→∙y
e→∙e+v
e → v∙ x v
e→∙v v
v→∙x y
v→∙y
x S5 ? S3

y
v → x∙ ? e → e + v∙

S6
v → y∙
GOTO(S2 , x)
S1
S2
s → e∙
e → e∙ + v e → e +∙ v
S0 e + v→∙x
s→∙e S4 v→∙y
e→∙e+v
e → v∙ v
e→∙v v
v→∙x x y
x S3
v→∙y S5

y
v → x∙ ? e → e + v∙

S6
v → y∙
GOTO(S2 , y)
S1
S2
s → e∙
e → e∙ + v e → e +∙ v
S0 e + v→∙x
s→∙e S4 v→∙y
e→∙e+v
e → v∙ v
e→∙v v
v→∙x x
x S3
v→∙y S5
v → x∙ e → e + v∙
y
y
S6
v → y∙
automata LR(0) resultante
S1
aceptar $ S2
s → e∙
e → e∙ + v e → e +∙ v
S0 e + v→∙x
s→∙e S4 v→∙y
e→∙e+v
e → v∙ v
e→∙v v
v→∙x x
x S3
v→∙y S5
v → x∙ e → e + v∙
y
y
inicio S6
v → y∙

You might also like