SlideShare a Scribd company logo
Compiler Construction
AIM:
Implement the non-recursive
THEORY:
Top down parsing
Top-down parsing can be viewed as an attempt to find a leftmost derivation for an
input string. Equivalently, it can be viewed as an attempt to
for the input starting from the root and creating the nodes of the parse tree in
preorder.
Following are the examples of top
• Recursive decent parser
• Predictive parser
• Non-recursive predictive parser
Non- Recursive Predictive
Figure 1: Model of non
It is possible to build a non
explicitly. The key problem during predictive parsing is that of determining the
production to be applied for a nonterminal. The non
production to be applied in a parsing table.
Sunita M. Dol, CSE Dept
Assignment No.10
recursive predictive parser for the language.
down parsing can be viewed as an attempt to find a leftmost derivation for an
input string. Equivalently, it can be viewed as an attempt to construct a parse tree
for the input starting from the root and creating the nodes of the parse tree in
Following are the examples of top-down parser
Recursive decent parser
Predictive parser
recursive predictive parser
Recursive Predictive parser
: Model of non-recursive predictive parser
It is possible to build a non-recursive predictive parser by maintaining a stack
explicitly. The key problem during predictive parsing is that of determining the
production to be applied for a nonterminal. The non-recursive parser looks up the
production to be applied in a parsing table.
Sunita M. Dol, CSE Dept
Page 1
down parsing can be viewed as an attempt to find a leftmost derivation for an
construct a parse tree
for the input starting from the root and creating the nodes of the parse tree in
recursive predictive parser by maintaining a stack
explicitly. The key problem during predictive parsing is that of determining the
recursive parser looks up the
Compiler Construction Sunita M. Dol, CSE Dept
Page 2
A table-driven predictive parser has an input buffer, a stack, a parsing table, and an
output stream. The input buffer contains the string to be parsed, followed by $, a
symbol used as a right end-marker to indicate the end of the input string. The stack
contains a sequence of grammar symbols with $ on the bottom, indicating the
bottom of the stack. Initially, the stack contains the start symbol of the grammar on
top of $. The parsing table is a two dimensional array M[A, a], where capital A is a
nonterminal, and small a is a terminal or the symbol $.
In parsing table, each row is a non-terminal symbol, each column is a terminal
symbol or the special symbol $ and each entry holds a production rule.
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 determine the action of the parser. There are four possible parser
actions.
1. If X = a = $ then the parser halts and announces successful completion of
parsing
2. If X and a are the same terminal symbol (different from $) that is X = a
which is not equal to $ then parser pops X from the stack, and advances the
input pointer to the next input symbol,
3. If X is a non-terminal, the program consults the parsing table entry M[X,a].
If M[X,a] holds a production rule X→Y1Y2...Yk, it pops X from the stack
and pushes Yk,Yk-1,...,Y1 into the stack. The parser also outputs the
production rule X→Y1Y2...Yk to represent a step of the derivation.
4. If none of the above then error. All empty entries in the parsing table are
errors and the parser calls an error recovery routine. If X is a terminal
symbol different from a, this is also an error case.
Non- Recursive Predictive parser Algorithm
INPUT: A string w and a parsing table M for grammar G.
OUTPUT: If w is in L(G), a leftmost derivation of w; otherwise, an error
indication.
METHOD: Initially, the parser is in a configuration with w$ in the input buffer
and the start symbol S of grammar G on top of the stack, above $. The flowchart
shown below uses the predictive parsing table M to produce a predictive parse for
the input.
set ip to point to the first symbol of w;
Compiler Construction Sunita M. Dol, CSE Dept
Page 3
repeat
Let X be the top stack symbol and a the symbol pointed by ip;
if X is a terminal or $ then
if X=a then
pop X from the stack and advance ip
else error()
else /* X is a non-terminal */
if M[X,a] = X -> Y1Y2 •••Yk then
begin
pop X from the stack
push Yk, Yk-i,... ,Y1 onto the stack, with Y1 on top;
output the production X -> Y1 Y2 • • • Yk;
end
else error()
until X=$ /* stack is empty */
Consider the grammar given below. A predictive parsing table for this grammar is
shown in Fig. In parsing table, Blanks are error entries while non-blanks indicate a
production with which to expand the top nonterminal on the stack. The input string
is id+id.
With input id + id; the predictive parser makes the sequence of moves shown
below. Initially, the parser is in a configuration with w$ that is id+id$ in the input
buffer and the start symbol E of grammar G on top of the stack, above $. The input
pointer points to the leftmost symbol of the string in the INPUT column. The
parser traces out a Leftmost derivation for the Input, that is, the productions output
are those of a leftmost derivation. The input symbols that have already been
scanned, followed by the grammar symbol on the stack (from the top to bottom),
make up the left-sentential forms in the derivation.
Finally stack as well as input contains the $ hence the parser halts and announces
successful completion of parsing
Compiler Construction Sunita M. Dol, CSE Dept
Page 4
Example 1:
E → T E’
E’ → +T E’ | ε
T → F T’
T’ → *F T’ | ε
F → id | (E)
Input String : id + id
stack input output
$E id+id$ E → TE’
$E’T id+id$ T → FT’
$E’ T’F id+id$ F → id
$ E’ T’id id+id$
$ E’ T’ +id$ T’ → ε
$ E’ +id$ E’ → +TE’
$ E’ T+ +id$
$ E’ T id$ T → FT’
$ E’ T’ F id$ F → id
$ E’ T’id id$
$ E’ T’ $ T’ → ε
$ E’ $ E’ → ε
$ $ accept
Compiler Construction Sunita M. Dol, CSE Dept
Page 5
PROGRAM:
INPUT:
This parser has been made for the grammar given by
E --> Te
e --> +Te | N
T --> Ft
t --> *Ft | N
F --> (E) | i
E , F , T , t , e , N are nonterminals
* , + , i , ( , ) are terminals
OUTPUT:
Top down parsing using the TABLE DRIVEN/PREDICTIVE/LL(1) PARSER
============================================
First of E is given by (i
First of e is given by +N
First of T is given by (i
First of t is given by *N
First of F is given by (i
First of i is given by i
First of + is given by +
First of * is given by *
First of ( is given by (
First of ) is given by )
First of $ is given by $
Follow of E is given by )$
Follow of e is given by )$
Follow of T is given by +)$
Follow of t is given by +)$
Follow of F is given by *+)$
Compiler Construction Sunita M. Dol, CSE Dept
Page 6
Enter the string(Use i for an identifier) (i+i)*i
$E (i+i)*i$
$eT (i+i)*i$
$etF (i+i)*i$
$et)E( (i+i)*i$
$et)E i+i)*i$
$et)eT i+i)*i$
$et)etF i+i)*i$
$et)eti i+i)*i$
$et)et +i)*i$
$et)e +i)*i$
$et)eT+ +i)*i$
$et)eT i)*i$
$et)etF i)*i$
$et)eti i)*i$
$et)et )*i$
$et)e )*i$
$et) )*i$
$et *i$
$etF* *i$
$etF i$
$eti i$
$et $
$E (i+i)*i$
$eT (i+i)*i$
$etF (i+i)*i$
$et)E( (i+i)*i$
$et)E i+i)*i$
$et)eT i+i)*i$
$et)etF i+i)*i$
$et)eti i+i)*i$
$et)et +i)*i$
$et)e +i)*i$
$et)eT+ +i)*i$
Compiler Construction Sunita M. Dol, CSE Dept
Page 7
$et)eT i)*i$
$et)etF i)*i$
$et)eti i)*i$
$et)et )*i$
$et)e )*i$
$et) )*i$
$et *i$
$etF* *i$
$etF i$
$eti i$
$et $
$E (i+i)*i$
$eT (i+i)*i$
$etF (i+i)*i$
$et)E( (i+i)*i$
$et)E i+i)*i$
$et)eT i+i)*i$
$et)etF i+i)*i$
$et)eti i+i)*i$
$et)et +i)*i$
$et)e +i)*i$
$et)eT+ +i)*i$
$et)eT i)*i$
$et)etF i)*i$
$et)eti i)*i$
$et)et )*i$
$et)e )*i$
$et) )*i$
$et *i$
$etF* *i$
$etF i$
$eti i$
$et $
$e $
Accepted
Compiler Construction Sunita M. Dol, CSE Dept
Page 8
CONCLUSION:
Thus the non-recursive predictive parser for given grammar is implemented.
REFERENCES:
 Compilers - Principles, Techniques and Tools - A.V. Aho, R. Shethi and J. D.
Ullman (Pearson Education)

More Related Content

What's hot

Parsing
ParsingParsing
Parsing
Roohaali
 
Compiler Design QA
Compiler Design QACompiler Design QA
Compiler Design QA
Dr. C.V. Suresh Babu
 
Intermediate code generation
Intermediate code generationIntermediate code generation
Intermediate code generation
Akshaya Arunan
 
Mycasestudy
MycasestudyMycasestudy
Mycasestudy
Emmanuel college
 
Parsing
ParsingParsing
Getting Started with C++
Getting Started with C++Getting Started with C++
Getting Started with C++
Praveen M Jigajinni
 
Three address code In Compiler Design
Three address code In Compiler DesignThree address code In Compiler Design
Three address code In Compiler Design
Shine Raj
 
Chapter 6 intermediate code generation
Chapter 6   intermediate code generationChapter 6   intermediate code generation
Chapter 6 intermediate code generation
Vipul Naik
 
C fundamentals
C fundamentalsC fundamentals
Chapter 6 Intermediate Code Generation
Chapter 6   Intermediate Code GenerationChapter 6   Intermediate Code Generation
Chapter 6 Intermediate Code Generation
Radhakrishnan Chinnusamy
 
Intermediate code generation1
Intermediate code generation1Intermediate code generation1
Intermediate code generation1
Shashwat Shriparv
 
Top down parsing
Top down parsingTop down parsing
Top down parsing
Prankit Mishra
 
07 top-down-parsing
07 top-down-parsing07 top-down-parsing
07 top-down-parsing
Harish Khodke
 
Recognition-of-tokens
Recognition-of-tokensRecognition-of-tokens
Recognition-of-tokens
Dattatray Gandhmal
 
Unit ii ppt
Unit ii pptUnit ii ppt
Constants Variables Datatypes by Mrs. Sowmya Jyothi
Constants Variables Datatypes by Mrs. Sowmya JyothiConstants Variables Datatypes by Mrs. Sowmya Jyothi
Constants Variables Datatypes by Mrs. Sowmya Jyothi
SowmyaJyothi3
 
C Programming
C ProgrammingC Programming
C Programming
Adil Jafri
 
Compiler unit 2&3
Compiler unit 2&3Compiler unit 2&3
Compiler unit 2&3
BBDITM LUCKNOW
 
What is c
What is cWhat is c
What is c
Nitesh Saitwal
 
Getting started with c++
Getting started with c++Getting started with c++
Getting started with c++
Bussines man badhrinadh
 

What's hot (20)

Parsing
ParsingParsing
Parsing
 
Compiler Design QA
Compiler Design QACompiler Design QA
Compiler Design QA
 
Intermediate code generation
Intermediate code generationIntermediate code generation
Intermediate code generation
 
Mycasestudy
MycasestudyMycasestudy
Mycasestudy
 
Parsing
ParsingParsing
Parsing
 
Getting Started with C++
Getting Started with C++Getting Started with C++
Getting Started with C++
 
Three address code In Compiler Design
Three address code In Compiler DesignThree address code In Compiler Design
Three address code In Compiler Design
 
Chapter 6 intermediate code generation
Chapter 6   intermediate code generationChapter 6   intermediate code generation
Chapter 6 intermediate code generation
 
C fundamentals
C fundamentalsC fundamentals
C fundamentals
 
Chapter 6 Intermediate Code Generation
Chapter 6   Intermediate Code GenerationChapter 6   Intermediate Code Generation
Chapter 6 Intermediate Code Generation
 
Intermediate code generation1
Intermediate code generation1Intermediate code generation1
Intermediate code generation1
 
Top down parsing
Top down parsingTop down parsing
Top down parsing
 
07 top-down-parsing
07 top-down-parsing07 top-down-parsing
07 top-down-parsing
 
Recognition-of-tokens
Recognition-of-tokensRecognition-of-tokens
Recognition-of-tokens
 
Unit ii ppt
Unit ii pptUnit ii ppt
Unit ii ppt
 
Constants Variables Datatypes by Mrs. Sowmya Jyothi
Constants Variables Datatypes by Mrs. Sowmya JyothiConstants Variables Datatypes by Mrs. Sowmya Jyothi
Constants Variables Datatypes by Mrs. Sowmya Jyothi
 
C Programming
C ProgrammingC Programming
C Programming
 
Compiler unit 2&3
Compiler unit 2&3Compiler unit 2&3
Compiler unit 2&3
 
What is c
What is cWhat is c
What is c
 
Getting started with c++
Getting started with c++Getting started with c++
Getting started with c++
 

Similar to Assignment10

Theory of automata and formal language lab manual
Theory of automata and formal language lab manualTheory of automata and formal language lab manual
Theory of automata and formal language lab manual
Nitesh Dubey
 
Nonrecursive predictive parsing
Nonrecursive predictive parsingNonrecursive predictive parsing
Nonrecursive predictive parsing
alldesign
 
Cd2 [autosaved]
Cd2 [autosaved]Cd2 [autosaved]
Cd2 [autosaved]
BBDITM LUCKNOW
 
LL(1) parsing
LL(1) parsingLL(1) parsing
LL(1) parsing
KHYATI PATEL
 
Top down parsing
Top down parsingTop down parsing
Top down parsing
LakshmiSamivel
 
PARSING.ppt
PARSING.pptPARSING.ppt
PARSING.ppt
ayyankhanna6480086
 
Ch4_topdownparser_ngfjgh_ngjfhgfffdddf.PPT
Ch4_topdownparser_ngfjgh_ngjfhgfffdddf.PPTCh4_topdownparser_ngfjgh_ngjfhgfffdddf.PPT
Ch4_topdownparser_ngfjgh_ngjfhgfffdddf.PPT
FutureTechnologies3
 
11CS10033.pptx
11CS10033.pptx11CS10033.pptx
11CS10033.pptx
ssuser0be977
 
Syntax analysis
Syntax analysisSyntax analysis
Syntax analysis
Akshaya Arunan
 
Non- recusive
Non- recusiveNon- recusive
Non- recusive
alldesign
 
LL(1) Parsers
LL(1) ParsersLL(1) Parsers
Ch06
Ch06Ch06
Ch06
Hankyo
 
Parsing
ParsingParsing
Parsing
khush_boo31
 
3. Syntax Analyzer.pptx
3. Syntax Analyzer.pptx3. Syntax Analyzer.pptx
3. Syntax Analyzer.pptx
Mattupallipardhu
 
Ll(1) Parser in Compilers
Ll(1) Parser in CompilersLl(1) Parser in Compilers
Ll(1) Parser in Compilers
Mahbubur Rahman
 
CS17604_TOP Parser Compiler Design Techniques
CS17604_TOP Parser Compiler Design TechniquesCS17604_TOP Parser Compiler Design Techniques
CS17604_TOP Parser Compiler Design Techniques
d72994185
 
01 stack 20160908_jintaek_seo
01 stack 20160908_jintaek_seo01 stack 20160908_jintaek_seo
01 stack 20160908_jintaek_seo
JinTaek Seo
 
3b. LMD & RMD.pdf
3b. LMD & RMD.pdf3b. LMD & RMD.pdf
3b. LMD & RMD.pdf
TANZINTANZINA
 
Chapter-3 compiler.pptx course materials
Chapter-3 compiler.pptx course materialsChapter-3 compiler.pptx course materials
Chapter-3 compiler.pptx course materials
gadisaAdamu
 
12IRGeneration.pdf
12IRGeneration.pdf12IRGeneration.pdf
12IRGeneration.pdf
SHUJEHASSAN
 

Similar to Assignment10 (20)

Theory of automata and formal language lab manual
Theory of automata and formal language lab manualTheory of automata and formal language lab manual
Theory of automata and formal language lab manual
 
Nonrecursive predictive parsing
Nonrecursive predictive parsingNonrecursive predictive parsing
Nonrecursive predictive parsing
 
Cd2 [autosaved]
Cd2 [autosaved]Cd2 [autosaved]
Cd2 [autosaved]
 
LL(1) parsing
LL(1) parsingLL(1) parsing
LL(1) parsing
 
Top down parsing
Top down parsingTop down parsing
Top down parsing
 
PARSING.ppt
PARSING.pptPARSING.ppt
PARSING.ppt
 
Ch4_topdownparser_ngfjgh_ngjfhgfffdddf.PPT
Ch4_topdownparser_ngfjgh_ngjfhgfffdddf.PPTCh4_topdownparser_ngfjgh_ngjfhgfffdddf.PPT
Ch4_topdownparser_ngfjgh_ngjfhgfffdddf.PPT
 
11CS10033.pptx
11CS10033.pptx11CS10033.pptx
11CS10033.pptx
 
Syntax analysis
Syntax analysisSyntax analysis
Syntax analysis
 
Non- recusive
Non- recusiveNon- recusive
Non- recusive
 
LL(1) Parsers
LL(1) ParsersLL(1) Parsers
LL(1) Parsers
 
Ch06
Ch06Ch06
Ch06
 
Parsing
ParsingParsing
Parsing
 
3. Syntax Analyzer.pptx
3. Syntax Analyzer.pptx3. Syntax Analyzer.pptx
3. Syntax Analyzer.pptx
 
Ll(1) Parser in Compilers
Ll(1) Parser in CompilersLl(1) Parser in Compilers
Ll(1) Parser in Compilers
 
CS17604_TOP Parser Compiler Design Techniques
CS17604_TOP Parser Compiler Design TechniquesCS17604_TOP Parser Compiler Design Techniques
CS17604_TOP Parser Compiler Design Techniques
 
01 stack 20160908_jintaek_seo
01 stack 20160908_jintaek_seo01 stack 20160908_jintaek_seo
01 stack 20160908_jintaek_seo
 
3b. LMD & RMD.pdf
3b. LMD & RMD.pdf3b. LMD & RMD.pdf
3b. LMD & RMD.pdf
 
Chapter-3 compiler.pptx course materials
Chapter-3 compiler.pptx course materialsChapter-3 compiler.pptx course materials
Chapter-3 compiler.pptx course materials
 
12IRGeneration.pdf
12IRGeneration.pdf12IRGeneration.pdf
12IRGeneration.pdf
 

More from Sunita Milind Dol

Assignment No. 10 on Unit-IV Set Theory, Relations and Function
Assignment No. 10 on Unit-IV Set Theory, Relations and FunctionAssignment No. 10 on Unit-IV Set Theory, Relations and Function
Assignment No. 10 on Unit-IV Set Theory, Relations and Function
Sunita Milind Dol
 
Assignment No. 9 on Unit-IV Set Theory, Relations and Function
Assignment No. 9 on Unit-IV Set Theory, Relations and FunctionAssignment No. 9 on Unit-IV Set Theory, Relations and Function
Assignment No. 9 on Unit-IV Set Theory, Relations and Function
Sunita Milind Dol
 
Assignment No. 8 on Unit-IV Set Theory, Relations and Function
Assignment No. 8 on Unit-IV Set Theory, Relations and FunctionAssignment No. 8 on Unit-IV Set Theory, Relations and Function
Assignment No. 8 on Unit-IV Set Theory, Relations and Function
Sunita Milind Dol
 
Assignment No. 7 on Unit-IV - Set Theory, Relations and Function
Assignment No. 7 on Unit-IV - Set Theory, Relations and FunctionAssignment No. 7 on Unit-IV - Set Theory, Relations and Function
Assignment No. 7 on Unit-IV - Set Theory, Relations and Function
Sunita Milind Dol
 
Assignment No. 6 on Representation of Expression
Assignment No. 6 on Representation of ExpressionAssignment No. 6 on Representation of Expression
Assignment No. 6 on Representation of Expression
Sunita Milind Dol
 
Assignment No. 5 on Unit-III Representation of Expression
Assignment No. 5 on Unit-III Representation of ExpressionAssignment No. 5 on Unit-III Representation of Expression
Assignment No. 5 on Unit-III Representation of Expression
Sunita Milind Dol
 
Assignment No. 4 on Unit-II Mathematical Logic
Assignment No. 4 on Unit-II Mathematical LogicAssignment No. 4 on Unit-II Mathematical Logic
Assignment No. 4 on Unit-II Mathematical Logic
Sunita Milind Dol
 
Assignment No. 3 on Unit-II Mathematical Logic
Assignment No. 3 on Unit-II Mathematical LogicAssignment No. 3 on Unit-II Mathematical Logic
Assignment No. 3 on Unit-II Mathematical Logic
Sunita Milind Dol
 
Assignment No. 2 on Unit-I Mathematical Induction
Assignment No. 2 on Unit-I Mathematical InductionAssignment No. 2 on Unit-I Mathematical Induction
Assignment No. 2 on Unit-I Mathematical Induction
Sunita Milind Dol
 
Assignment No. 1 on Unit-I Fundamental Principles of Counting
Assignment No. 1 on Unit-I Fundamental Principles of CountingAssignment No. 1 on Unit-I Fundamental Principles of Counting
Assignment No. 1 on Unit-I Fundamental Principles of Counting
Sunita Milind Dol
 
Unit Number 5 - Research Ethics, IPR and Publishing
Unit Number 5 - Research Ethics, IPR and PublishingUnit Number 5 - Research Ethics, IPR and Publishing
Unit Number 5 - Research Ethics, IPR and Publishing
Sunita Milind Dol
 
Unit Number 4 - Research reports and Thesis writing
Unit Number 4 - Research reports and Thesis writingUnit Number 4 - Research reports and Thesis writing
Unit Number 4 - Research reports and Thesis writing
Sunita Milind Dol
 
Unit Number 3 - Data collection and Statistical Analysis
Unit Number 3 - Data collection and Statistical AnalysisUnit Number 3 - Data collection and Statistical Analysis
Unit Number 3 - Data collection and Statistical Analysis
Sunita Milind Dol
 
Unit Number 2 - Research Problem Formulation and Methods
Unit Number 2 - Research Problem Formulation and MethodsUnit Number 2 - Research Problem Formulation and Methods
Unit Number 2 - Research Problem Formulation and Methods
Sunita Milind Dol
 
Unit Number 1 - Introduction to Research
Unit Number 1 - Introduction to ResearchUnit Number 1 - Introduction to Research
Unit Number 1 - Introduction to Research
Sunita Milind Dol
 
Unit Number 5 - Research Ethics, IPR and Publishing
Unit Number 5 - Research Ethics, IPR and PublishingUnit Number 5 - Research Ethics, IPR and Publishing
Unit Number 5 - Research Ethics, IPR and Publishing
Sunita Milind Dol
 
Unit Number 5 - Research reports and Thesis writing
Unit Number 5 - Research reports and Thesis writingUnit Number 5 - Research reports and Thesis writing
Unit Number 5 - Research reports and Thesis writing
Sunita Milind Dol
 
Unit Number 3 - Data collection and Statistical Analysis
Unit Number 3 - Data collection and Statistical AnalysisUnit Number 3 - Data collection and Statistical Analysis
Unit Number 3 - Data collection and Statistical Analysis
Sunita Milind Dol
 
Unit Number 2 - Research Problem Formulation and Methods
Unit Number 2 - Research Problem Formulation and MethodsUnit Number 2 - Research Problem Formulation and Methods
Unit Number 2 - Research Problem Formulation and Methods
Sunita Milind Dol
 
Unit Number 1 : Introduction to Research
Unit Number 1 : Introduction to ResearchUnit Number 1 : Introduction to Research
Unit Number 1 : Introduction to Research
Sunita Milind Dol
 

More from Sunita Milind Dol (20)

Assignment No. 10 on Unit-IV Set Theory, Relations and Function
Assignment No. 10 on Unit-IV Set Theory, Relations and FunctionAssignment No. 10 on Unit-IV Set Theory, Relations and Function
Assignment No. 10 on Unit-IV Set Theory, Relations and Function
 
Assignment No. 9 on Unit-IV Set Theory, Relations and Function
Assignment No. 9 on Unit-IV Set Theory, Relations and FunctionAssignment No. 9 on Unit-IV Set Theory, Relations and Function
Assignment No. 9 on Unit-IV Set Theory, Relations and Function
 
Assignment No. 8 on Unit-IV Set Theory, Relations and Function
Assignment No. 8 on Unit-IV Set Theory, Relations and FunctionAssignment No. 8 on Unit-IV Set Theory, Relations and Function
Assignment No. 8 on Unit-IV Set Theory, Relations and Function
 
Assignment No. 7 on Unit-IV - Set Theory, Relations and Function
Assignment No. 7 on Unit-IV - Set Theory, Relations and FunctionAssignment No. 7 on Unit-IV - Set Theory, Relations and Function
Assignment No. 7 on Unit-IV - Set Theory, Relations and Function
 
Assignment No. 6 on Representation of Expression
Assignment No. 6 on Representation of ExpressionAssignment No. 6 on Representation of Expression
Assignment No. 6 on Representation of Expression
 
Assignment No. 5 on Unit-III Representation of Expression
Assignment No. 5 on Unit-III Representation of ExpressionAssignment No. 5 on Unit-III Representation of Expression
Assignment No. 5 on Unit-III Representation of Expression
 
Assignment No. 4 on Unit-II Mathematical Logic
Assignment No. 4 on Unit-II Mathematical LogicAssignment No. 4 on Unit-II Mathematical Logic
Assignment No. 4 on Unit-II Mathematical Logic
 
Assignment No. 3 on Unit-II Mathematical Logic
Assignment No. 3 on Unit-II Mathematical LogicAssignment No. 3 on Unit-II Mathematical Logic
Assignment No. 3 on Unit-II Mathematical Logic
 
Assignment No. 2 on Unit-I Mathematical Induction
Assignment No. 2 on Unit-I Mathematical InductionAssignment No. 2 on Unit-I Mathematical Induction
Assignment No. 2 on Unit-I Mathematical Induction
 
Assignment No. 1 on Unit-I Fundamental Principles of Counting
Assignment No. 1 on Unit-I Fundamental Principles of CountingAssignment No. 1 on Unit-I Fundamental Principles of Counting
Assignment No. 1 on Unit-I Fundamental Principles of Counting
 
Unit Number 5 - Research Ethics, IPR and Publishing
Unit Number 5 - Research Ethics, IPR and PublishingUnit Number 5 - Research Ethics, IPR and Publishing
Unit Number 5 - Research Ethics, IPR and Publishing
 
Unit Number 4 - Research reports and Thesis writing
Unit Number 4 - Research reports and Thesis writingUnit Number 4 - Research reports and Thesis writing
Unit Number 4 - Research reports and Thesis writing
 
Unit Number 3 - Data collection and Statistical Analysis
Unit Number 3 - Data collection and Statistical AnalysisUnit Number 3 - Data collection and Statistical Analysis
Unit Number 3 - Data collection and Statistical Analysis
 
Unit Number 2 - Research Problem Formulation and Methods
Unit Number 2 - Research Problem Formulation and MethodsUnit Number 2 - Research Problem Formulation and Methods
Unit Number 2 - Research Problem Formulation and Methods
 
Unit Number 1 - Introduction to Research
Unit Number 1 - Introduction to ResearchUnit Number 1 - Introduction to Research
Unit Number 1 - Introduction to Research
 
Unit Number 5 - Research Ethics, IPR and Publishing
Unit Number 5 - Research Ethics, IPR and PublishingUnit Number 5 - Research Ethics, IPR and Publishing
Unit Number 5 - Research Ethics, IPR and Publishing
 
Unit Number 5 - Research reports and Thesis writing
Unit Number 5 - Research reports and Thesis writingUnit Number 5 - Research reports and Thesis writing
Unit Number 5 - Research reports and Thesis writing
 
Unit Number 3 - Data collection and Statistical Analysis
Unit Number 3 - Data collection and Statistical AnalysisUnit Number 3 - Data collection and Statistical Analysis
Unit Number 3 - Data collection and Statistical Analysis
 
Unit Number 2 - Research Problem Formulation and Methods
Unit Number 2 - Research Problem Formulation and MethodsUnit Number 2 - Research Problem Formulation and Methods
Unit Number 2 - Research Problem Formulation and Methods
 
Unit Number 1 : Introduction to Research
Unit Number 1 : Introduction to ResearchUnit Number 1 : Introduction to Research
Unit Number 1 : Introduction to Research
 

Recently uploaded

一比一原版(爱大毕业证书)爱荷华大学毕业证如何办理
一比一原版(爱大毕业证书)爱荷华大学毕业证如何办理一比一原版(爱大毕业证书)爱荷华大学毕业证如何办理
一比一原版(爱大毕业证书)爱荷华大学毕业证如何办理
nedcocy
 
一比一原版(osu毕业证书)美国俄勒冈州立大学毕业证如何办理
一比一原版(osu毕业证书)美国俄勒冈州立大学毕业证如何办理一比一原版(osu毕业证书)美国俄勒冈州立大学毕业证如何办理
一比一原版(osu毕业证书)美国俄勒冈州立大学毕业证如何办理
upoux
 
Zener Diode and its V-I Characteristics and Applications
Zener Diode and its V-I Characteristics and ApplicationsZener Diode and its V-I Characteristics and Applications
Zener Diode and its V-I Characteristics and Applications
Shiny Christobel
 
Call For Paper -3rd International Conference on Artificial Intelligence Advan...
Call For Paper -3rd International Conference on Artificial Intelligence Advan...Call For Paper -3rd International Conference on Artificial Intelligence Advan...
Call For Paper -3rd International Conference on Artificial Intelligence Advan...
ijseajournal
 
一比一原版(uoft毕业证书)加拿大多伦多大学毕业证如何办理
一比一原版(uoft毕业证书)加拿大多伦多大学毕业证如何办理一比一原版(uoft毕业证书)加拿大多伦多大学毕业证如何办理
一比一原版(uoft毕业证书)加拿大多伦多大学毕业证如何办理
sydezfe
 
Blood finder application project report (1).pdf
Blood finder application project report (1).pdfBlood finder application project report (1).pdf
Blood finder application project report (1).pdf
Kamal Acharya
 
Introduction to Computer Networks & OSI MODEL.ppt
Introduction to Computer Networks & OSI MODEL.pptIntroduction to Computer Networks & OSI MODEL.ppt
Introduction to Computer Networks & OSI MODEL.ppt
Dwarkadas J Sanghvi College of Engineering
 
DEEP LEARNING FOR SMART GRID INTRUSION DETECTION: A HYBRID CNN-LSTM-BASED MODEL
DEEP LEARNING FOR SMART GRID INTRUSION DETECTION: A HYBRID CNN-LSTM-BASED MODELDEEP LEARNING FOR SMART GRID INTRUSION DETECTION: A HYBRID CNN-LSTM-BASED MODEL
DEEP LEARNING FOR SMART GRID INTRUSION DETECTION: A HYBRID CNN-LSTM-BASED MODEL
ijaia
 
Transformers design and coooling methods
Transformers design and coooling methodsTransformers design and coooling methods
Transformers design and coooling methods
Roger Rozario
 
Digital Twins Computer Networking Paper Presentation.pptx
Digital Twins Computer Networking Paper Presentation.pptxDigital Twins Computer Networking Paper Presentation.pptx
Digital Twins Computer Networking Paper Presentation.pptx
aryanpankaj78
 
Object Oriented Analysis and Design - OOAD
Object Oriented Analysis and Design - OOADObject Oriented Analysis and Design - OOAD
Object Oriented Analysis and Design - OOAD
PreethaV16
 
AI + Data Community Tour - Build the Next Generation of Apps with the Einstei...
AI + Data Community Tour - Build the Next Generation of Apps with the Einstei...AI + Data Community Tour - Build the Next Generation of Apps with the Einstei...
AI + Data Community Tour - Build the Next Generation of Apps with the Einstei...
Paris Salesforce Developer Group
 
原版制作(Humboldt毕业证书)柏林大学毕业证学位证一模一样
原版制作(Humboldt毕业证书)柏林大学毕业证学位证一模一样原版制作(Humboldt毕业证书)柏林大学毕业证学位证一模一样
原版制作(Humboldt毕业证书)柏林大学毕业证学位证一模一样
ydzowc
 
smart pill dispenser is designed to improve medication adherence and safety f...
smart pill dispenser is designed to improve medication adherence and safety f...smart pill dispenser is designed to improve medication adherence and safety f...
smart pill dispenser is designed to improve medication adherence and safety f...
um7474492
 
Generative AI Use cases applications solutions and implementation.pdf
Generative AI Use cases applications solutions and implementation.pdfGenerative AI Use cases applications solutions and implementation.pdf
Generative AI Use cases applications solutions and implementation.pdf
mahaffeycheryld
 
ITSM Integration with MuleSoft.pptx
ITSM  Integration with MuleSoft.pptxITSM  Integration with MuleSoft.pptx
ITSM Integration with MuleSoft.pptx
VANDANAMOHANGOUDA
 
NATURAL DEEP EUTECTIC SOLVENTS AS ANTI-FREEZING AGENT
NATURAL DEEP EUTECTIC SOLVENTS AS ANTI-FREEZING AGENTNATURAL DEEP EUTECTIC SOLVENTS AS ANTI-FREEZING AGENT
NATURAL DEEP EUTECTIC SOLVENTS AS ANTI-FREEZING AGENT
Addu25809
 
An Introduction to the Compiler Designss
An Introduction to the Compiler DesignssAn Introduction to the Compiler Designss
An Introduction to the Compiler Designss
ElakkiaU
 
一比一原版(CalArts毕业证)加利福尼亚艺术学院毕业证如何办理
一比一原版(CalArts毕业证)加利福尼亚艺术学院毕业证如何办理一比一原版(CalArts毕业证)加利福尼亚艺术学院毕业证如何办理
一比一原版(CalArts毕业证)加利福尼亚艺术学院毕业证如何办理
ecqow
 
AI-Based Home Security System : Home security
AI-Based Home Security System : Home securityAI-Based Home Security System : Home security
AI-Based Home Security System : Home security
AIRCC Publishing Corporation
 

Recently uploaded (20)

一比一原版(爱大毕业证书)爱荷华大学毕业证如何办理
一比一原版(爱大毕业证书)爱荷华大学毕业证如何办理一比一原版(爱大毕业证书)爱荷华大学毕业证如何办理
一比一原版(爱大毕业证书)爱荷华大学毕业证如何办理
 
一比一原版(osu毕业证书)美国俄勒冈州立大学毕业证如何办理
一比一原版(osu毕业证书)美国俄勒冈州立大学毕业证如何办理一比一原版(osu毕业证书)美国俄勒冈州立大学毕业证如何办理
一比一原版(osu毕业证书)美国俄勒冈州立大学毕业证如何办理
 
Zener Diode and its V-I Characteristics and Applications
Zener Diode and its V-I Characteristics and ApplicationsZener Diode and its V-I Characteristics and Applications
Zener Diode and its V-I Characteristics and Applications
 
Call For Paper -3rd International Conference on Artificial Intelligence Advan...
Call For Paper -3rd International Conference on Artificial Intelligence Advan...Call For Paper -3rd International Conference on Artificial Intelligence Advan...
Call For Paper -3rd International Conference on Artificial Intelligence Advan...
 
一比一原版(uoft毕业证书)加拿大多伦多大学毕业证如何办理
一比一原版(uoft毕业证书)加拿大多伦多大学毕业证如何办理一比一原版(uoft毕业证书)加拿大多伦多大学毕业证如何办理
一比一原版(uoft毕业证书)加拿大多伦多大学毕业证如何办理
 
Blood finder application project report (1).pdf
Blood finder application project report (1).pdfBlood finder application project report (1).pdf
Blood finder application project report (1).pdf
 
Introduction to Computer Networks & OSI MODEL.ppt
Introduction to Computer Networks & OSI MODEL.pptIntroduction to Computer Networks & OSI MODEL.ppt
Introduction to Computer Networks & OSI MODEL.ppt
 
DEEP LEARNING FOR SMART GRID INTRUSION DETECTION: A HYBRID CNN-LSTM-BASED MODEL
DEEP LEARNING FOR SMART GRID INTRUSION DETECTION: A HYBRID CNN-LSTM-BASED MODELDEEP LEARNING FOR SMART GRID INTRUSION DETECTION: A HYBRID CNN-LSTM-BASED MODEL
DEEP LEARNING FOR SMART GRID INTRUSION DETECTION: A HYBRID CNN-LSTM-BASED MODEL
 
Transformers design and coooling methods
Transformers design and coooling methodsTransformers design and coooling methods
Transformers design and coooling methods
 
Digital Twins Computer Networking Paper Presentation.pptx
Digital Twins Computer Networking Paper Presentation.pptxDigital Twins Computer Networking Paper Presentation.pptx
Digital Twins Computer Networking Paper Presentation.pptx
 
Object Oriented Analysis and Design - OOAD
Object Oriented Analysis and Design - OOADObject Oriented Analysis and Design - OOAD
Object Oriented Analysis and Design - OOAD
 
AI + Data Community Tour - Build the Next Generation of Apps with the Einstei...
AI + Data Community Tour - Build the Next Generation of Apps with the Einstei...AI + Data Community Tour - Build the Next Generation of Apps with the Einstei...
AI + Data Community Tour - Build the Next Generation of Apps with the Einstei...
 
原版制作(Humboldt毕业证书)柏林大学毕业证学位证一模一样
原版制作(Humboldt毕业证书)柏林大学毕业证学位证一模一样原版制作(Humboldt毕业证书)柏林大学毕业证学位证一模一样
原版制作(Humboldt毕业证书)柏林大学毕业证学位证一模一样
 
smart pill dispenser is designed to improve medication adherence and safety f...
smart pill dispenser is designed to improve medication adherence and safety f...smart pill dispenser is designed to improve medication adherence and safety f...
smart pill dispenser is designed to improve medication adherence and safety f...
 
Generative AI Use cases applications solutions and implementation.pdf
Generative AI Use cases applications solutions and implementation.pdfGenerative AI Use cases applications solutions and implementation.pdf
Generative AI Use cases applications solutions and implementation.pdf
 
ITSM Integration with MuleSoft.pptx
ITSM  Integration with MuleSoft.pptxITSM  Integration with MuleSoft.pptx
ITSM Integration with MuleSoft.pptx
 
NATURAL DEEP EUTECTIC SOLVENTS AS ANTI-FREEZING AGENT
NATURAL DEEP EUTECTIC SOLVENTS AS ANTI-FREEZING AGENTNATURAL DEEP EUTECTIC SOLVENTS AS ANTI-FREEZING AGENT
NATURAL DEEP EUTECTIC SOLVENTS AS ANTI-FREEZING AGENT
 
An Introduction to the Compiler Designss
An Introduction to the Compiler DesignssAn Introduction to the Compiler Designss
An Introduction to the Compiler Designss
 
一比一原版(CalArts毕业证)加利福尼亚艺术学院毕业证如何办理
一比一原版(CalArts毕业证)加利福尼亚艺术学院毕业证如何办理一比一原版(CalArts毕业证)加利福尼亚艺术学院毕业证如何办理
一比一原版(CalArts毕业证)加利福尼亚艺术学院毕业证如何办理
 
AI-Based Home Security System : Home security
AI-Based Home Security System : Home securityAI-Based Home Security System : Home security
AI-Based Home Security System : Home security
 

Assignment10

  • 1. Compiler Construction AIM: Implement the non-recursive THEORY: Top down parsing Top-down parsing can be viewed as an attempt to find a leftmost derivation for an input string. Equivalently, it can be viewed as an attempt to for the input starting from the root and creating the nodes of the parse tree in preorder. Following are the examples of top • Recursive decent parser • Predictive parser • Non-recursive predictive parser Non- Recursive Predictive Figure 1: Model of non It is possible to build a non explicitly. The key problem during predictive parsing is that of determining the production to be applied for a nonterminal. The non production to be applied in a parsing table. Sunita M. Dol, CSE Dept Assignment No.10 recursive predictive parser for the language. down parsing can be viewed as an attempt to find a leftmost derivation for an input string. Equivalently, it can be viewed as an attempt to construct a parse tree for the input starting from the root and creating the nodes of the parse tree in Following are the examples of top-down parser Recursive decent parser Predictive parser recursive predictive parser Recursive Predictive parser : Model of non-recursive predictive parser It is possible to build a non-recursive predictive parser by maintaining a stack explicitly. The key problem during predictive parsing is that of determining the production to be applied for a nonterminal. The non-recursive parser looks up the production to be applied in a parsing table. Sunita M. Dol, CSE Dept Page 1 down parsing can be viewed as an attempt to find a leftmost derivation for an construct a parse tree for the input starting from the root and creating the nodes of the parse tree in recursive predictive parser by maintaining a stack explicitly. The key problem during predictive parsing is that of determining the recursive parser looks up the
  • 2. Compiler Construction Sunita M. Dol, CSE Dept Page 2 A table-driven predictive parser has an input buffer, a stack, a parsing table, and an output stream. The input buffer contains the string to be parsed, followed by $, a symbol used as a right end-marker to indicate the end of the input string. The stack contains a sequence of grammar symbols with $ on the bottom, indicating the bottom of the stack. Initially, the stack contains the start symbol of the grammar on top of $. The parsing table is a two dimensional array M[A, a], where capital A is a nonterminal, and small a is a terminal or the symbol $. In parsing table, each row is a non-terminal symbol, each column is a terminal symbol or the special symbol $ and each entry holds a production rule. 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 determine the action of the parser. There are four possible parser actions. 1. If X = a = $ then the parser halts and announces successful completion of parsing 2. If X and a are the same terminal symbol (different from $) that is X = a which is not equal to $ then parser pops X from the stack, and advances the input pointer to the next input symbol, 3. If X is a non-terminal, the program consults the parsing table entry M[X,a]. If M[X,a] holds a production rule X→Y1Y2...Yk, it pops X from the stack and pushes Yk,Yk-1,...,Y1 into the stack. The parser also outputs the production rule X→Y1Y2...Yk to represent a step of the derivation. 4. If none of the above then error. All empty entries in the parsing table are errors and the parser calls an error recovery routine. If X is a terminal symbol different from a, this is also an error case. Non- Recursive Predictive parser Algorithm INPUT: A string w and a parsing table M for grammar G. OUTPUT: If w is in L(G), a leftmost derivation of w; otherwise, an error indication. METHOD: Initially, the parser is in a configuration with w$ in the input buffer and the start symbol S of grammar G on top of the stack, above $. The flowchart shown below uses the predictive parsing table M to produce a predictive parse for the input. set ip to point to the first symbol of w;
  • 3. Compiler Construction Sunita M. Dol, CSE Dept Page 3 repeat Let X be the top stack symbol and a the symbol pointed by ip; if X is a terminal or $ then if X=a then pop X from the stack and advance ip else error() else /* X is a non-terminal */ if M[X,a] = X -> Y1Y2 •••Yk then begin pop X from the stack push Yk, Yk-i,... ,Y1 onto the stack, with Y1 on top; output the production X -> Y1 Y2 • • • Yk; end else error() until X=$ /* stack is empty */ Consider the grammar given below. A predictive parsing table for this grammar is shown in Fig. In parsing table, Blanks are error entries while non-blanks indicate a production with which to expand the top nonterminal on the stack. The input string is id+id. With input id + id; the predictive parser makes the sequence of moves shown below. Initially, the parser is in a configuration with w$ that is id+id$ in the input buffer and the start symbol E of grammar G on top of the stack, above $. The input pointer points to the leftmost symbol of the string in the INPUT column. The parser traces out a Leftmost derivation for the Input, that is, the productions output are those of a leftmost derivation. The input symbols that have already been scanned, followed by the grammar symbol on the stack (from the top to bottom), make up the left-sentential forms in the derivation. Finally stack as well as input contains the $ hence the parser halts and announces successful completion of parsing
  • 4. Compiler Construction Sunita M. Dol, CSE Dept Page 4 Example 1: E → T E’ E’ → +T E’ | ε T → F T’ T’ → *F T’ | ε F → id | (E) Input String : id + id stack input output $E id+id$ E → TE’ $E’T id+id$ T → FT’ $E’ T’F id+id$ F → id $ E’ T’id id+id$ $ E’ T’ +id$ T’ → ε $ E’ +id$ E’ → +TE’ $ E’ T+ +id$ $ E’ T id$ T → FT’ $ E’ T’ F id$ F → id $ E’ T’id id$ $ E’ T’ $ T’ → ε $ E’ $ E’ → ε $ $ accept
  • 5. Compiler Construction Sunita M. Dol, CSE Dept Page 5 PROGRAM: INPUT: This parser has been made for the grammar given by E --> Te e --> +Te | N T --> Ft t --> *Ft | N F --> (E) | i E , F , T , t , e , N are nonterminals * , + , i , ( , ) are terminals OUTPUT: Top down parsing using the TABLE DRIVEN/PREDICTIVE/LL(1) PARSER ============================================ First of E is given by (i First of e is given by +N First of T is given by (i First of t is given by *N First of F is given by (i First of i is given by i First of + is given by + First of * is given by * First of ( is given by ( First of ) is given by ) First of $ is given by $ Follow of E is given by )$ Follow of e is given by )$ Follow of T is given by +)$ Follow of t is given by +)$ Follow of F is given by *+)$
  • 6. Compiler Construction Sunita M. Dol, CSE Dept Page 6 Enter the string(Use i for an identifier) (i+i)*i $E (i+i)*i$ $eT (i+i)*i$ $etF (i+i)*i$ $et)E( (i+i)*i$ $et)E i+i)*i$ $et)eT i+i)*i$ $et)etF i+i)*i$ $et)eti i+i)*i$ $et)et +i)*i$ $et)e +i)*i$ $et)eT+ +i)*i$ $et)eT i)*i$ $et)etF i)*i$ $et)eti i)*i$ $et)et )*i$ $et)e )*i$ $et) )*i$ $et *i$ $etF* *i$ $etF i$ $eti i$ $et $ $E (i+i)*i$ $eT (i+i)*i$ $etF (i+i)*i$ $et)E( (i+i)*i$ $et)E i+i)*i$ $et)eT i+i)*i$ $et)etF i+i)*i$ $et)eti i+i)*i$ $et)et +i)*i$ $et)e +i)*i$ $et)eT+ +i)*i$
  • 7. Compiler Construction Sunita M. Dol, CSE Dept Page 7 $et)eT i)*i$ $et)etF i)*i$ $et)eti i)*i$ $et)et )*i$ $et)e )*i$ $et) )*i$ $et *i$ $etF* *i$ $etF i$ $eti i$ $et $ $E (i+i)*i$ $eT (i+i)*i$ $etF (i+i)*i$ $et)E( (i+i)*i$ $et)E i+i)*i$ $et)eT i+i)*i$ $et)etF i+i)*i$ $et)eti i+i)*i$ $et)et +i)*i$ $et)e +i)*i$ $et)eT+ +i)*i$ $et)eT i)*i$ $et)etF i)*i$ $et)eti i)*i$ $et)et )*i$ $et)e )*i$ $et) )*i$ $et *i$ $etF* *i$ $etF i$ $eti i$ $et $ $e $ Accepted
  • 8. Compiler Construction Sunita M. Dol, CSE Dept Page 8 CONCLUSION: Thus the non-recursive predictive parser for given grammar is implemented. REFERENCES:  Compilers - Principles, Techniques and Tools - A.V. Aho, R. Shethi and J. D. Ullman (Pearson Education)