Skip to content
VUBuddy

CS606 Final Term Lectures 19-45 by Masters

Compiler Construction PDF 2.4 MBUpdated 23 Oct 2026
Final term past paper CS606 Final Term Lectures 19-45 by Masters PDF 2.4 MB
vubuddy.com
Type
Final term past paper
Course
CS606 Compiler Construction
Size
PDF 2.4 MB
Updated
23 Oct 2026
Free download 0 of 3 used today
Download free · 2.4 MB

You get 3 free files a day on the website. Add the Chrome extension for 30 a day.

Unlimited downloads in the Android app Get it free on Google Play

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:

  1. Shift
  2. Reduce
All CS606 files →
CS606 Compiler Construction All CS606 handouts, past papers, quizzes and MCQs in one place. Open course page

Get more out of VUBuddy, for free

Android app Free on Google Play
  • Unlimited downloads
  • The explanation behind every MCQ answer
  • Study offline on slow data
Get the Android app
Chrome extension Free on the Chrome Web Store
  • 30 downloads a day instead of 3
  • Sign in and buy Pro Semester here
Add to Chrome

One Pro Semester membership works in both the extension and the app.