deterministic context-free languages haniel...
TRANSCRIPT
![Page 1: Deterministic Context-Free Languages Haniel Barbosahomepage.divms.uiowa.edu/~hbarbosa/teaching/cs4330/notes/...The class of DCFLs is closed under complementation. B We use the above](https://reader033.vdocuments.us/reader033/viewer/2022061003/60b1b01de0b6fa125f703ff4/html5/thumbnails/1.jpg)
CS:4330 Theory of ComputationSpring 2018
Context-Free LanguagesDeterministic Context-Free Languages
Haniel Barbosa
![Page 2: Deterministic Context-Free Languages Haniel Barbosahomepage.divms.uiowa.edu/~hbarbosa/teaching/cs4330/notes/...The class of DCFLs is closed under complementation. B We use the above](https://reader033.vdocuments.us/reader033/viewer/2022061003/60b1b01de0b6fa125f703ff4/html5/thumbnails/2.jpg)
Readings for this lecture
Chapter 2 of [Sipser 1996], 3rd edition. Section 2.4.
![Page 3: Deterministic Context-Free Languages Haniel Barbosahomepage.divms.uiowa.edu/~hbarbosa/teaching/cs4330/notes/...The class of DCFLs is closed under complementation. B We use the above](https://reader033.vdocuments.us/reader033/viewer/2022061003/60b1b01de0b6fa125f703ff4/html5/thumbnails/3.jpg)
Deterministic CFLs vs CFLs
B Nondeterministic and deterministic PDAs are not equivalent in expressivepower
B Deterministic Pushdown Automata (DPDAs) are strictly less expressive thanPDAs
B Context-free languages not recognizable by a DPDA are called DeterministicContext-Free Languages (DCFLs)
B An example of application is parsing programming languages, as DCFLs areeasier to parse than general CFLs
1 / 12
![Page 4: Deterministic Context-Free Languages Haniel Barbosahomepage.divms.uiowa.edu/~hbarbosa/teaching/cs4330/notes/...The class of DCFLs is closed under complementation. B We use the above](https://reader033.vdocuments.us/reader033/viewer/2022061003/60b1b01de0b6fa125f703ff4/html5/thumbnails/4.jpg)
DPDA
Differently from DFAs, DPDAs may have ε-transitions
B At any moment, at most one transition is possible
For a ∈ Σ, b ∈ Γ, and c ∈ Γε
q1 q2a,b→ c
or
q1 q2ε,b→ c
or
q1 q2a, ε→ c
or
q1 q2ε, ε→ c
but only one of them is possible2 / 12
![Page 5: Deterministic Context-Free Languages Haniel Barbosahomepage.divms.uiowa.edu/~hbarbosa/teaching/cs4330/notes/...The class of DCFLs is closed under complementation. B We use the above](https://reader033.vdocuments.us/reader033/viewer/2022061003/60b1b01de0b6fa125f703ff4/html5/thumbnails/5.jpg)
Allowed transitions
q1
q2
q3
a,b→ c1
a,c→ c2
q1
q2
q3
ε,b→ c1
ε,c→ c2
Deterministic choices
3 / 12
![Page 6: Deterministic Context-Free Languages Haniel Barbosahomepage.divms.uiowa.edu/~hbarbosa/teaching/cs4330/notes/...The class of DCFLs is closed under complementation. B We use the above](https://reader033.vdocuments.us/reader033/viewer/2022061003/60b1b01de0b6fa125f703ff4/html5/thumbnails/6.jpg)
Disallowed transitions
q1
q2
q3
a,b→ c1
a,b→ c2
q1
q2
q3
ε,b→ c1
a,b→ c2
Nondeterministic choices
4 / 12
![Page 7: Deterministic Context-Free Languages Haniel Barbosahomepage.divms.uiowa.edu/~hbarbosa/teaching/cs4330/notes/...The class of DCFLs is closed under complementation. B We use the above](https://reader033.vdocuments.us/reader033/viewer/2022061003/60b1b01de0b6fa125f703ff4/html5/thumbnails/7.jpg)
Defintion of DPDA
A DPDA is a 6-tuple (Q, Σ, Γ, δ, q0, F), in which Q is its set of states, Σ its inputalphabet, Γ its stack alphabet, δ its transition function, q0 the start state, andF ⊆ Q the set of accept states.
B δ : Q×Σε×Γε → (Q×Γε)∪∅B In which δ satisfies the following condition:
I For every q ∈ Q, a ∈ Σ and x ∈ Γ, exactly one of the values
δ(q,a,x), δ(q,a, ε), δ(q, ε,x), and δ(q, ε, ε)
is not ∅
5 / 12
![Page 8: Deterministic Context-Free Languages Haniel Barbosahomepage.divms.uiowa.edu/~hbarbosa/teaching/cs4330/notes/...The class of DCFLs is closed under complementation. B We use the above](https://reader033.vdocuments.us/reader033/viewer/2022061003/60b1b01de0b6fa125f703ff4/html5/thumbnails/8.jpg)
DPDA example
Consider the language {0n1n | n≥ 0}
q1start q2
q3q4
ε, ε→ $0, ε→ 0
1,0→ ε
1,0→ εε,$→ ε
6 / 12
![Page 9: Deterministic Context-Free Languages Haniel Barbosahomepage.divms.uiowa.edu/~hbarbosa/teaching/cs4330/notes/...The class of DCFLs is closed under complementation. B We use the above](https://reader033.vdocuments.us/reader033/viewer/2022061003/60b1b01de0b6fa125f703ff4/html5/thumbnails/9.jpg)
DPDA example
Consider the language {0n1n | n≥ 0}
q1start q2
q3q4
q5
ε, ε→ $0, ε→ 0
1,0→ ε
ε,$→ εε,1→ ε
1,0→ εε,$→ ε
0, ε→ ε
1,1→ ε
0, ε→ ε1, ε→ ε
0, ε→ ε
1, ε→ ε
6 / 12
![Page 10: Deterministic Context-Free Languages Haniel Barbosahomepage.divms.uiowa.edu/~hbarbosa/teaching/cs4330/notes/...The class of DCFLs is closed under complementation. B We use the above](https://reader033.vdocuments.us/reader033/viewer/2022061003/60b1b01de0b6fa125f703ff4/html5/thumbnails/10.jpg)
Deterministic Context-free Languages
DefinitionA language L is deterministic context-free (DCFL) if there exists a DPDA thataccepts it.
Example
The language {0n1n | n≥ 0} is deterministic context-free.
There are, however, CFLs that are not DCFLs. For example:
A = {aibjck | i, j,k ≥ 0∧ i 6= j∨ j 6= k}
is a CFL but not a DCFL. How can we show this?
7 / 12
![Page 11: Deterministic Context-Free Languages Haniel Barbosahomepage.divms.uiowa.edu/~hbarbosa/teaching/cs4330/notes/...The class of DCFLs is closed under complementation. B We use the above](https://reader033.vdocuments.us/reader033/viewer/2022061003/60b1b01de0b6fa125f703ff4/html5/thumbnails/11.jpg)
CFL but not DCFL
TheoremThe class of DCFLs is closed under complementation.
B We use the above theorem and the fact that CFLs are not closed undercomplementation, i.e. the complement of a CFL may not be a CFL, to showthat A = {aibjck | i, j,k ≥ 0∧ i 6= j∨ j 6= k} is not a DCFL.
B If A were a DCFL, A would also be a DCFL, which means that A would alsobe a CFL.
B A = {anbncn | n≥ 0} is not a CFL, therefore A is an example of a CFL thatis not a DCFL.
8 / 12
![Page 12: Deterministic Context-Free Languages Haniel Barbosahomepage.divms.uiowa.edu/~hbarbosa/teaching/cs4330/notes/...The class of DCFLs is closed under complementation. B We use the above](https://reader033.vdocuments.us/reader033/viewer/2022061003/60b1b01de0b6fa125f703ff4/html5/thumbnails/12.jpg)
CFL but not DCFL
TheoremThe class of DCFLs is closed under complementation.
B We use the above theorem and the fact that CFLs are not closed undercomplementation, i.e. the complement of a CFL may not be a CFL, to showthat A = {aibjck | i, j,k ≥ 0∧ i 6= j∨ j 6= k} is not a DCFL.
B If A were a DCFL, A would also be a DCFL, which means that A would alsobe a CFL.
B A = {anbncn | n≥ 0} is not a CFL, therefore A is an example of a CFL thatis not a DCFL.
8 / 12
![Page 13: Deterministic Context-Free Languages Haniel Barbosahomepage.divms.uiowa.edu/~hbarbosa/teaching/cs4330/notes/...The class of DCFLs is closed under complementation. B We use the above](https://reader033.vdocuments.us/reader033/viewer/2022061003/60b1b01de0b6fa125f703ff4/html5/thumbnails/13.jpg)
DCFL in practice
B LR(k) grammar: it generates a DCFL, with ‘L’ meaning “the input is read fromLeft to right” and ‘R(k)’ meaning “Right most derivation decided by the first kinput symbols”
B Backtracking and guessing is avoided by the parser being allowed tolookahead at k input symbols before deciding how to parse earlier symbols.
B Most programming languages are specified by LR(k) grammars, with k ≤ 2
B LR(k) parser: an efficient algorithm to decide, in linear time, if a word is inL (G), in which G is an LR(k) grammar.
9 / 12
![Page 14: Deterministic Context-Free Languages Haniel Barbosahomepage.divms.uiowa.edu/~hbarbosa/teaching/cs4330/notes/...The class of DCFLs is closed under complementation. B We use the above](https://reader033.vdocuments.us/reader033/viewer/2022061003/60b1b01de0b6fa125f703ff4/html5/thumbnails/14.jpg)
Example: an LR(1) grammar
E → E+T | TT → T×F | FF → (E) | a
Rightmost derivation
E ⇒ E+T⇒ E+F⇒ E+ a⇒ T + a⇒ T×F+ a⇒ T× a+ a⇒ F× a+ a⇒ a× a+ a
10 / 12
![Page 15: Deterministic Context-Free Languages Haniel Barbosahomepage.divms.uiowa.edu/~hbarbosa/teaching/cs4330/notes/...The class of DCFLs is closed under complementation. B We use the above](https://reader033.vdocuments.us/reader033/viewer/2022061003/60b1b01de0b6fa125f703ff4/html5/thumbnails/15.jpg)
LR(k) parser
A stack is used to store the derivation steps backward. Two actions on stack:1. shift: move a symbol from input to the stack;2. reduce: replace the rhs of a rule in the top of the stack by its lhs
The actions of an LR(1) parser for the previous derivation
stack input actiona× a+ a$
shifta ×a+ a$ reduce by F→ aF ×a+ a$ reduce by T→ FT ×a+ a$ shiftT× a+ a$ shiftT× a +a$ reduce by F→ aT×F +a$ reduce by T→ T×FT +a$ reduce by E→ TE +a$ shiftE+ a$ shiftE+ a $ reduce by F→ aE+F $ reduce by T→ FE+T $ reduce by E→ E+TE $ accept
11 / 12
![Page 16: Deterministic Context-Free Languages Haniel Barbosahomepage.divms.uiowa.edu/~hbarbosa/teaching/cs4330/notes/...The class of DCFLs is closed under complementation. B We use the above](https://reader033.vdocuments.us/reader033/viewer/2022061003/60b1b01de0b6fa125f703ff4/html5/thumbnails/16.jpg)
LR(k) parser
A stack is used to store the derivation steps backward. Two actions on stack:1. shift: move a symbol from input to the stack;2. reduce: replace the rhs of a rule in the top of the stack by its lhs
The actions of an LR(1) parser for the previous derivation
stack input actiona× a+ a$ shift
a ×a+ a$
reduce by F→ aF ×a+ a$ reduce by T→ FT ×a+ a$ shiftT× a+ a$ shiftT× a +a$ reduce by F→ aT×F +a$ reduce by T→ T×FT +a$ reduce by E→ TE +a$ shiftE+ a$ shiftE+ a $ reduce by F→ aE+F $ reduce by T→ FE+T $ reduce by E→ E+TE $ accept
11 / 12
![Page 17: Deterministic Context-Free Languages Haniel Barbosahomepage.divms.uiowa.edu/~hbarbosa/teaching/cs4330/notes/...The class of DCFLs is closed under complementation. B We use the above](https://reader033.vdocuments.us/reader033/viewer/2022061003/60b1b01de0b6fa125f703ff4/html5/thumbnails/17.jpg)
LR(k) parser
A stack is used to store the derivation steps backward. Two actions on stack:1. shift: move a symbol from input to the stack;2. reduce: replace the rhs of a rule in the top of the stack by its lhs
The actions of an LR(1) parser for the previous derivation
stack input actiona× a+ a$ shift
a ×a+ a$ reduce by F→ aF ×a+ a$
reduce by T→ FT ×a+ a$ shiftT× a+ a$ shiftT× a +a$ reduce by F→ aT×F +a$ reduce by T→ T×FT +a$ reduce by E→ TE +a$ shiftE+ a$ shiftE+ a $ reduce by F→ aE+F $ reduce by T→ FE+T $ reduce by E→ E+TE $ accept
11 / 12
![Page 18: Deterministic Context-Free Languages Haniel Barbosahomepage.divms.uiowa.edu/~hbarbosa/teaching/cs4330/notes/...The class of DCFLs is closed under complementation. B We use the above](https://reader033.vdocuments.us/reader033/viewer/2022061003/60b1b01de0b6fa125f703ff4/html5/thumbnails/18.jpg)
LR(k) parser
A stack is used to store the derivation steps backward. Two actions on stack:1. shift: move a symbol from input to the stack;2. reduce: replace the rhs of a rule in the top of the stack by its lhs
The actions of an LR(1) parser for the previous derivation
stack input actiona× a+ a$ shift
a ×a+ a$ reduce by F→ aF ×a+ a$ reduce by T→ FT ×a+ a$
shiftT× a+ a$ shiftT× a +a$ reduce by F→ aT×F +a$ reduce by T→ T×FT +a$ reduce by E→ TE +a$ shiftE+ a$ shiftE+ a $ reduce by F→ aE+F $ reduce by T→ FE+T $ reduce by E→ E+TE $ accept
11 / 12
![Page 19: Deterministic Context-Free Languages Haniel Barbosahomepage.divms.uiowa.edu/~hbarbosa/teaching/cs4330/notes/...The class of DCFLs is closed under complementation. B We use the above](https://reader033.vdocuments.us/reader033/viewer/2022061003/60b1b01de0b6fa125f703ff4/html5/thumbnails/19.jpg)
LR(k) parser
A stack is used to store the derivation steps backward. Two actions on stack:1. shift: move a symbol from input to the stack;2. reduce: replace the rhs of a rule in the top of the stack by its lhs
The actions of an LR(1) parser for the previous derivation
stack input actiona× a+ a$ shift
a ×a+ a$ reduce by F→ aF ×a+ a$ reduce by T→ FT ×a+ a$ shiftT× a+ a$
shiftT× a +a$ reduce by F→ aT×F +a$ reduce by T→ T×FT +a$ reduce by E→ TE +a$ shiftE+ a$ shiftE+ a $ reduce by F→ aE+F $ reduce by T→ FE+T $ reduce by E→ E+TE $ accept
11 / 12
![Page 20: Deterministic Context-Free Languages Haniel Barbosahomepage.divms.uiowa.edu/~hbarbosa/teaching/cs4330/notes/...The class of DCFLs is closed under complementation. B We use the above](https://reader033.vdocuments.us/reader033/viewer/2022061003/60b1b01de0b6fa125f703ff4/html5/thumbnails/20.jpg)
LR(k) parser
A stack is used to store the derivation steps backward. Two actions on stack:1. shift: move a symbol from input to the stack;2. reduce: replace the rhs of a rule in the top of the stack by its lhs
The actions of an LR(1) parser for the previous derivation
stack input actiona× a+ a$ shift
a ×a+ a$ reduce by F→ aF ×a+ a$ reduce by T→ FT ×a+ a$ shiftT× a+ a$ shiftT× a +a$
reduce by F→ aT×F +a$ reduce by T→ T×FT +a$ reduce by E→ TE +a$ shiftE+ a$ shiftE+ a $ reduce by F→ aE+F $ reduce by T→ FE+T $ reduce by E→ E+TE $ accept
11 / 12
![Page 21: Deterministic Context-Free Languages Haniel Barbosahomepage.divms.uiowa.edu/~hbarbosa/teaching/cs4330/notes/...The class of DCFLs is closed under complementation. B We use the above](https://reader033.vdocuments.us/reader033/viewer/2022061003/60b1b01de0b6fa125f703ff4/html5/thumbnails/21.jpg)
LR(k) parser
A stack is used to store the derivation steps backward. Two actions on stack:1. shift: move a symbol from input to the stack;2. reduce: replace the rhs of a rule in the top of the stack by its lhs
The actions of an LR(1) parser for the previous derivation
stack input actiona× a+ a$ shift
a ×a+ a$ reduce by F→ aF ×a+ a$ reduce by T→ FT ×a+ a$ shiftT× a+ a$ shiftT× a +a$ reduce by F→ aT×F +a$
reduce by T→ T×FT +a$ reduce by E→ TE +a$ shiftE+ a$ shiftE+ a $ reduce by F→ aE+F $ reduce by T→ FE+T $ reduce by E→ E+TE $ accept
11 / 12
![Page 22: Deterministic Context-Free Languages Haniel Barbosahomepage.divms.uiowa.edu/~hbarbosa/teaching/cs4330/notes/...The class of DCFLs is closed under complementation. B We use the above](https://reader033.vdocuments.us/reader033/viewer/2022061003/60b1b01de0b6fa125f703ff4/html5/thumbnails/22.jpg)
LR(k) parser
A stack is used to store the derivation steps backward. Two actions on stack:1. shift: move a symbol from input to the stack;2. reduce: replace the rhs of a rule in the top of the stack by its lhs
The actions of an LR(1) parser for the previous derivation
stack input actiona× a+ a$ shift
a ×a+ a$ reduce by F→ aF ×a+ a$ reduce by T→ FT ×a+ a$ shiftT× a+ a$ shiftT× a +a$ reduce by F→ aT×F +a$ reduce by T→ T×FT +a$
reduce by E→ TE +a$ shiftE+ a$ shiftE+ a $ reduce by F→ aE+F $ reduce by T→ FE+T $ reduce by E→ E+TE $ accept
11 / 12
![Page 23: Deterministic Context-Free Languages Haniel Barbosahomepage.divms.uiowa.edu/~hbarbosa/teaching/cs4330/notes/...The class of DCFLs is closed under complementation. B We use the above](https://reader033.vdocuments.us/reader033/viewer/2022061003/60b1b01de0b6fa125f703ff4/html5/thumbnails/23.jpg)
LR(k) parser
A stack is used to store the derivation steps backward. Two actions on stack:1. shift: move a symbol from input to the stack;2. reduce: replace the rhs of a rule in the top of the stack by its lhs
The actions of an LR(1) parser for the previous derivation
stack input actiona× a+ a$ shift
a ×a+ a$ reduce by F→ aF ×a+ a$ reduce by T→ FT ×a+ a$ shiftT× a+ a$ shiftT× a +a$ reduce by F→ aT×F +a$ reduce by T→ T×FT +a$ reduce by E→ TE +a$
shiftE+ a$ shiftE+ a $ reduce by F→ aE+F $ reduce by T→ FE+T $ reduce by E→ E+TE $ accept
11 / 12
![Page 24: Deterministic Context-Free Languages Haniel Barbosahomepage.divms.uiowa.edu/~hbarbosa/teaching/cs4330/notes/...The class of DCFLs is closed under complementation. B We use the above](https://reader033.vdocuments.us/reader033/viewer/2022061003/60b1b01de0b6fa125f703ff4/html5/thumbnails/24.jpg)
LR(k) parser
A stack is used to store the derivation steps backward. Two actions on stack:1. shift: move a symbol from input to the stack;2. reduce: replace the rhs of a rule in the top of the stack by its lhs
The actions of an LR(1) parser for the previous derivation
stack input actiona× a+ a$ shift
a ×a+ a$ reduce by F→ aF ×a+ a$ reduce by T→ FT ×a+ a$ shiftT× a+ a$ shiftT× a +a$ reduce by F→ aT×F +a$ reduce by T→ T×FT +a$ reduce by E→ TE +a$ shiftE+ a$
shiftE+ a $ reduce by F→ aE+F $ reduce by T→ FE+T $ reduce by E→ E+TE $ accept
11 / 12
![Page 25: Deterministic Context-Free Languages Haniel Barbosahomepage.divms.uiowa.edu/~hbarbosa/teaching/cs4330/notes/...The class of DCFLs is closed under complementation. B We use the above](https://reader033.vdocuments.us/reader033/viewer/2022061003/60b1b01de0b6fa125f703ff4/html5/thumbnails/25.jpg)
LR(k) parser
A stack is used to store the derivation steps backward. Two actions on stack:1. shift: move a symbol from input to the stack;2. reduce: replace the rhs of a rule in the top of the stack by its lhs
The actions of an LR(1) parser for the previous derivation
stack input actiona× a+ a$ shift
a ×a+ a$ reduce by F→ aF ×a+ a$ reduce by T→ FT ×a+ a$ shiftT× a+ a$ shiftT× a +a$ reduce by F→ aT×F +a$ reduce by T→ T×FT +a$ reduce by E→ TE +a$ shiftE+ a$ shiftE+ a $
reduce by F→ aE+F $ reduce by T→ FE+T $ reduce by E→ E+TE $ accept
11 / 12
![Page 26: Deterministic Context-Free Languages Haniel Barbosahomepage.divms.uiowa.edu/~hbarbosa/teaching/cs4330/notes/...The class of DCFLs is closed under complementation. B We use the above](https://reader033.vdocuments.us/reader033/viewer/2022061003/60b1b01de0b6fa125f703ff4/html5/thumbnails/26.jpg)
LR(k) parser
A stack is used to store the derivation steps backward. Two actions on stack:1. shift: move a symbol from input to the stack;2. reduce: replace the rhs of a rule in the top of the stack by its lhs
The actions of an LR(1) parser for the previous derivation
stack input actiona× a+ a$ shift
a ×a+ a$ reduce by F→ aF ×a+ a$ reduce by T→ FT ×a+ a$ shiftT× a+ a$ shiftT× a +a$ reduce by F→ aT×F +a$ reduce by T→ T×FT +a$ reduce by E→ TE +a$ shiftE+ a$ shiftE+ a $ reduce by F→ aE+F $
reduce by T→ FE+T $ reduce by E→ E+TE $ accept
11 / 12
![Page 27: Deterministic Context-Free Languages Haniel Barbosahomepage.divms.uiowa.edu/~hbarbosa/teaching/cs4330/notes/...The class of DCFLs is closed under complementation. B We use the above](https://reader033.vdocuments.us/reader033/viewer/2022061003/60b1b01de0b6fa125f703ff4/html5/thumbnails/27.jpg)
LR(k) parser
A stack is used to store the derivation steps backward. Two actions on stack:1. shift: move a symbol from input to the stack;2. reduce: replace the rhs of a rule in the top of the stack by its lhs
The actions of an LR(1) parser for the previous derivation
stack input actiona× a+ a$ shift
a ×a+ a$ reduce by F→ aF ×a+ a$ reduce by T→ FT ×a+ a$ shiftT× a+ a$ shiftT× a +a$ reduce by F→ aT×F +a$ reduce by T→ T×FT +a$ reduce by E→ TE +a$ shiftE+ a$ shiftE+ a $ reduce by F→ aE+F $ reduce by T→ FE+T $
reduce by E→ E+TE $ accept
11 / 12
![Page 28: Deterministic Context-Free Languages Haniel Barbosahomepage.divms.uiowa.edu/~hbarbosa/teaching/cs4330/notes/...The class of DCFLs is closed under complementation. B We use the above](https://reader033.vdocuments.us/reader033/viewer/2022061003/60b1b01de0b6fa125f703ff4/html5/thumbnails/28.jpg)
LR(k) parser
A stack is used to store the derivation steps backward. Two actions on stack:1. shift: move a symbol from input to the stack;2. reduce: replace the rhs of a rule in the top of the stack by its lhs
The actions of an LR(1) parser for the previous derivation
stack input actiona× a+ a$ shift
a ×a+ a$ reduce by F→ aF ×a+ a$ reduce by T→ FT ×a+ a$ shiftT× a+ a$ shiftT× a +a$ reduce by F→ aT×F +a$ reduce by T→ T×FT +a$ reduce by E→ TE +a$ shiftE+ a$ shiftE+ a $ reduce by F→ aE+F $ reduce by T→ FE+T $ reduce by E→ E+TE $
accept
11 / 12
![Page 29: Deterministic Context-Free Languages Haniel Barbosahomepage.divms.uiowa.edu/~hbarbosa/teaching/cs4330/notes/...The class of DCFLs is closed under complementation. B We use the above](https://reader033.vdocuments.us/reader033/viewer/2022061003/60b1b01de0b6fa125f703ff4/html5/thumbnails/29.jpg)
LR(k) parser
A stack is used to store the derivation steps backward. Two actions on stack:1. shift: move a symbol from input to the stack;2. reduce: replace the rhs of a rule in the top of the stack by its lhs
The actions of an LR(1) parser for the previous derivation
stack input actiona× a+ a$ shift
a ×a+ a$ reduce by F→ aF ×a+ a$ reduce by T→ FT ×a+ a$ shiftT× a+ a$ shiftT× a +a$ reduce by F→ aT×F +a$ reduce by T→ T×FT +a$ reduce by E→ TE +a$ shiftE+ a$ shiftE+ a $ reduce by F→ aE+F $ reduce by T→ FE+T $ reduce by E→ E+TE $ accept
11 / 12
![Page 30: Deterministic Context-Free Languages Haniel Barbosahomepage.divms.uiowa.edu/~hbarbosa/teaching/cs4330/notes/...The class of DCFLs is closed under complementation. B We use the above](https://reader033.vdocuments.us/reader033/viewer/2022061003/60b1b01de0b6fa125f703ff4/html5/thumbnails/30.jpg)
A hierachy of languages
regular
context-free
context-sensitive
recursively enumerable
12 / 12