In the previous part we talked about viable prefixes and handles. Today we will do a bit of background to ensure your concepts are clear.
When we started LR parsing I assumed that you know LL parsing. LL means scan input from left to right and do a left-most derivation. This is less powerful than LR – why?
Now, when we say “power of a parser” it is with respect to the GRAMMARS it can parse- not the language where as when we say “power of a grammar” it is with respect to the languages it can generate. So, what will be the language of LL(1) – that is the languages which can be generated by the set of all LL(1) grammars?
Actually the power of LL(k) grammar strictly increases with an increase in ‘k’. i.e., language of LL(k) is a strict subset of the langauge of LL(k+1).
What about LR(k)?
Power of LR(0) grammar is lower than power of LR(1).
Language of LR(0) (set of all LR(0) grammars) is same as DCFL having prefix property or the set of languages accepted by a DPDA with empty stack – this is neither a super set nor a subset of the set of regular languages.
Since any LL(k) grammar is also an LR(k) grammar, language of any LL(k) grammar is guaranteed to be a DCFL. But since language of LL(k) is a strict subset of the langauge of LL(k+1), for any finite $k$, there exist SOME DCFL which cannot be generated by ANY LL(k) grammar.
For sake of completeness we can see the languages of LL(0) and LL(1).
So, now we can come back to LR parsing. I wont be discussing LL or Top down parsing. For that please see here. But we can see the definitions of FIRST and FOLLOW which are useful even for LR parsing.
(Greek letters means a sequence of terminals or non-terminals)
$FIRST(\alpha)$ is the set of terminals that begins strings derivable from $\alpha$ ($\alpha$ itself can be starting with a terminal). (How does it help in parsing?)
$FOLLOW(A)$ (see capital English alphabet A, so a single non-terminal only) is the set of terminals that can appear immediately to the right of $A$ in some sentential form. (So, should $FOLLOW(S)$ have $\$$ – the end marker for string?)
We can now see the condition for a grammar to be LL(1). A grammar $G$ is LL(1) only if
SLR(1), LALR and CLR parsing to be continued in next part…
This page shows all details regarding GATE CSE 2022 Admissions including results, admission offers and…
Source Add your Response Rank Predictor for GATE CSE 2021 Result Responses: GATE CSE 2021…
Best Books for GATE CSE with Relevant Chapters to Read Heads Up! These GATE CSE…
Indian Statistical Institute(ISI) offers M Tech in Computer Science with the Admission Test Codes MMA/PCA…
Indian Statistical Institute(ISI) offers Junior Research Fellowships (JRF) in Computer Science, Statistics, Mathematics, Quantitative Economics,…
Indian Statistical Institute(ISI) conduct the admission test for Postgraduate Diploma in Computer Applications(PGDCA) with the…