














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
Community
Ask the community for help and clear up your study doubts
Discover the best universities in your country according to Docsity users
Free resources
Download our free guides on studying techniques, anxiety management strategies, and thesis advice from Docsity tutors
An overview of parsing algorithms, focusing on the lr(0) parsing algorithm for context-free grammars. It includes the lr(0) parsing algorithm outline, viable item updates, and examples of converting εnfa to dfa. The document also discusses lr(0) grammars and deterministic pdas.
Typology: Slides
1 / 22
This page cannot be seen from the preview
Don't miss anything!
CFG of the java programming language Identifier: IDENTIFIER QualifiedIdentifier:Identifier {. Identifier } Literal: IntegerLiteral FloatingPointLiteralCharacterLiteral StringLiteralBooleanLiteral NullLiteral Expression: Expression1 [AssignmentOperator Expression1]] AssignmentOperator:= +=-= *=/= &=|=
from http://java.sun.com/docs/books/jls /second_edition/html/syntax.doc.html#
exhaustive algorithm about^10 80 years (longer than life of universe)
CYK algorithm about^1 week!
Find an algorithm that can parse strings in any grammar
Design your grammar so it has a very fast parsing algorithm
S → •Tc S → T•c S → Tc•
A → •aTb A → a•Tb A → aT•b A → aTb•
A → •ab A → a•b A → ab•
S → Tc (1)^ T → TA (2)^ T → A (3) A → aTb(4)^ A → ab(5)
Stack (^) Input ε a ab A T Ta
abaabbc baabbc aabbc aabbc aabbc abbc
Action shift shift reduce (5) reduce (3) shift shift
S → Tc (1) T → TA (2)^ | A (3) A → aTb(4)^ | ab (5)
Stack (^) Input
ε a ab A T Ta Taa Taab TaA TaT TaTb TA T Tc S
abaabbc baabbc aabbc aabbc aabbc abbc bbc bc bc bc c c c ε ε
Action shift shift reduce (5) reduce (3) shift shift shift reduce (5) reduce (3) shift reduce (4) reduce (2) shift reduce (1)
handle
valid items: a•Tb, a•b
valid items: T•a, T•c, aT•b
Stack Input
ε a
aa
aab aA aAb A
aabb abb
bb
b b ε ε
A Valid Items
A → •aAb A → •ab A → a•Ab A → a•b A → •aAb A → •ab A → a•Ab A → a•b A → •aAb A → •ab A → ab• A → aA•b A → aAb•
Stack Input
ε a
aa
aab aA aAb A
aabb abb
bb
b b ε ε
A Valid Items
A → •aAb A → •ab A → a•Ab A → a•b A → •aAb A → •ab A → a•Ab A → a•b A → •aAb A → •ab A → ab• A → aA•b A → aAb•
A → α•Bβ is updated to A^ →^ αB•β A → α• X β disappears if^ X^ ≠ B
C → • δ is added for every valid item A → α•Cβ and production C → • δ
q 0 ε S → • α
A → α X • β
A → α• X β
A → α•Cβ^ ε C → • δ
A → •aAb A→ •ab
A → a•Ab A → a•b A → •aAb A → •ab
A → aA•b
A → aAb•
A → ab•
a
b
A b a
die
Stack Input
ε a
aa
aab aA
aabb abb
bb
b b
A DFA state A → •aAb A → •ab A → a•Ab A → a•b A → •aAb A → •ab A → a•Ab A → a•b A → •aAb A → •ab A → ab• A → aA•b