- Type
- Quiz
- Course
- CS606 Compiler Construction
- Size
- PDF 33 KB
- 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 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
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.
- X = a = $, the parser halts and annouces successful completion.
- 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.
Example: let’s parse the input string
id+id∗id
using the non-recursive LL(1) parser
Related CS606 files
All CS606 files →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.