Skip to content
VUBuddy

CS606 Short Notes Lecture 16

Compiler Construction PDF 33 KBUpdated 23 Oct 2026
Quiz CS606 Short Notes Lecture 16 PDF 33 KB
vubuddy.com
Type
Quiz
Course
CS606 Compiler Construction
Size
PDF 33 KB
Updated
23 Oct 2026
Free download 0 of 3 used today
Download free · 33 KB

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 1, 2, 3 of 4. Download the file for all 4 pages.

Lecture 16

Here is the output trace for the expression : 2+4*6

>> Expr::isPresent() >> Term::isPresent() >> Factor::isPresent() token: 2 (257) << Factor::isPresent() return true >> Tprime::isPresent() token: + (267) << Tprime::isPresent() return false << Term::isPresent() return true >> Eprime::isPresent() token: + (267) >> Term::isPresent() >> Factor::isPresent() token: 4 (257) << Factor::isPresent() return true >> Tprime::isPresent() token: * (269) >> Factor::isPresent() token: 6 (257) << Factor::isPresent() return true >> Tprime::isPresent() token: (0) << Tprime::isPresent() return false << Tprime::isPresent() return true << Term::isPresent() return true >> Eprime::isPresent() token: (0) << Eprime::isPresent() return false << Eprime::isPresent() return true << Expr::isPresent() return true

** AST ** · (2+(4*6)) · Non-recursive Predictive Parsing

It is possible to build a non-recursive predictive parser. This is done by maintaining an explicit stack and using a table. Such a parser is called a table-driven parser. The nonrecursive LL(1) parser looks up the production to apply by looking up a parsing table. The LL(1) table has one dimension for current non-terminal to expand and another dimension for next token. Each table cell contains one production.

Consider the expression grammar

1 E ?

T E' 2 E' ? + T E'

ε

4 T ?

F T' 5 T' ? * F T'

ε

7 F ?

( E ) id

Using the table construction algorithm that will be discussed later, we have the predictive parsing table

id E E ? TE' E ? TE'

E'

E' ? +TE' E' ? ε E' ? ε

T T ? FT' T ? FT'

T'

T' ? ε T ? *FT' T' ? ε T' ? ε F F ? id F ? (E )

The rows are non-terminals and the columns are the terminals of the expression grammar. The predictive parser uses an explicit stack to keep track of pending non-terminals. It can thus be implemented without recursion. a b

Predictive parser stack

X Y Z

Parsing table M input

output

LL(1) Parsing Algorithm

The input buffer contains the string to be parsed; $ is the end-of-input marker. The stack contains a sequence of grammar symbols. Initially, the stack contains the start symbol of the grammar on the top of $. The parser is controlled by a program that behaves as follows:

The program considers X, the symbol on top of the stack, and a, the current input symbol. These two symbols, X and a determine the action of the parser. There are three possibilities.

  1. X = a = $, the parser halts and annouces successful completion.
  2. X = a ≠ $ the parser pops X off the stack and advances input pointer to next input symbol.

Q3. If X is a nonterminal, the program consults entry M[X,a] of parsing table M.

  1. If the entry is a production M[X,a] = {X ? UVW }, the parser replaces X on top of the stack by WVU (with U on top). As output, the parser just prints the production used: X ? UVW. However, any other code could be executed here.
  2. If M[X,a] =error, the parser calls an error recovery routine

Example: let’s parse the input string

id+id∗id

using the non-recursive LL(1) parser

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.