CS606 Final Term Highlighted Handouts Lectures 19-45 Set 2 by Masters
- Type
- Highlighted handout
- Course
- CS606 Compiler Construction
- Size
- PDF 1.4 MB
- Updated
- 23 Oct 2026
You get 3 free files a day on the website. Add the Chrome extension for 30 a day.
Preview text
Text from pages 2, 3, 4 of 78. Download the file for all 78 pages.
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 S rule: B → γ
B α
γ
x y
Terminals only
1. E → E + (E) 2. | int
The bottom-up parse of the string int + (int) + (int) would be
int + (int) + (int) E + (int) + (int) E + (E) + (int) E + (int) E + (E) E
The consequence of an LR parser tracing a rightmost derivation in reverse is that given αβγ be a step of a bottom-up parse, assuming that next reduction is A → β τhen γ is a string of terminals. The reason is that αAγ → αβγ is a step in a rightmost derivation. This observation provides a strategy for building bottom up parsers: split the input string into two substrings. Right substring (a string of terminals) is as yet unexamined by parser and left substring has terminals and non-terminals. The dividing point is marked by a ► (the ► is not part of the string). Initially, all input is unexamined: ►x1 x1 . . . xn.
Shift-Reduce Parsing
Bottom-up parsing uses only two kinds of actions:
- Shift
- Reduce
Related CS606 files
All CS606 files →- CS606 Final Term Highlighted Handouts Lectures 19-45 by Masters Highlighted PDF 1.4 MB
- CS606 Final Term Lectures 19-45 by Masters Final term PDF 2.4 MB
- 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 Solved MCQs by Junaid Final term PDF 1.7 MB
- CS606 Quiz 4 Jan 2026 Set 2 Quiz PDF 35 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.