- Type
- Quiz
- Course
- CS606 Compiler Construction
- Size
- PDF 3.8 MB
- Updated
- 23 Oct 2026
You get 3 free files a day on the website. Add the Chrome extensionSign in with the extension for 30 a day.
Preview text
Text from pages 4, 6, 7 of 144. Download the file for all 144 pages.
The following procedure encodes this strategy.
Let’s apply the algorithm to the expression grammar.
Put $ in FOLLOW(E ). By rule (2) applied to production ? ( E ), ‘)’ is also in FOLLOW(E ). Thus, FOLLOW(E ) = { ), $}. By rule (3) applied to production E ? T E' , $ and ‘)’ are in FOLLOW(E' ). Thus, FOLLOW(E ) = FOLLOW (E' ) = { ), $ }. Similarly, FOLLOW(T ) = FOLLOW (T' ) = { +, ), $ } and FOLLOW(F ) = { +, is not clear how to predict; the two productions start with the non-terminal T. A grammar must be left factored before use for predictive parsing. The procedure to left-factor a grammar is as follows:
A graphical explanation:
Example: consider following fragment of expression grammar
Factor ?
id id [ ExprList ] id ( ExprList )
After left factoring, the grammar becomes
Factor ? id Args Args ? [ ExprList ] | ( ExprList )
| ε
Given a CFG that does not meet the LL(1) condition, it is un-decidable whether or not an equivalent LL(1) grammar exists.
Lecture 20
Bottom-up Parsing
Bottom-up parsing is more general than top-down parsing. Bottom-up parsers handle a large class of grammars. It is the preferred method in practice. It is also called LR parsing; L means that tokens are read left to right and R means that the parser constructs a rightmost derivation. LR parsers do not need left-factored grammars. LR parsers can handle left-recursive grammars.
LR parsing reduces a string to the start symbol by inverting productions. A derivation consists of a series of rewrite steps
Each γi is a sentential form. If γ contains only terminals, γ is a sentence in L(G). If γ contains ≥ 1 nonterminals, γ is a sentential form. A bottom-up parser builds a derivation by working from input sentence back towards the start symbol S.
S → aABe A → Abc | b B → d
The sentence abbcde can be reduced to S:
abbcde aAbcd e aAde aABe S
These reductions, in fact, trace out the following right-most derivation in reverse:
S aABe aAde aAbcde abbcde
S aBy aγy xy
Related CS606 files
All CS606 files →- CS606 Final Term Quiz 4 Jan 2024 by Miss Mehwish Quiz PDF 429 KB
- CS606 Final Term Quiz 3 by Team Aiza Quiz PDF 899 KB
- CS606 Final Term Subjective 2013 Final term PDF 510 KB
- CS606 Final Term Solved Quizzes and MCQs with References Final term PDF 117 KB
- CS606 Final Term Highlighted Handouts Lectures 19-45 by Masters Highlighted PDF 1.4 MB
- CS606 Final Term Solved File 2 by Team Hadi Final term PDF 515 KB
Get more out of VUBuddy, for free
- Unlimited downloads
- The explanation behind every MCQ answer
- Study offline on slow data
- 30 downloads a day instead of 3
- Sign in and buy Pro Semester here
One Pro Semester membership works in both the extension and the app.