SlideShare ist ein Scribd-Unternehmen logo
1 von 12
PREDICTIVE PARSER
BY
JOTHI LAKSHMI
• Predictive parsers
• Transition diagrams for predictive parsers
• Non recursive predictive parser
• Construction of predictive parsing tables
CONTENT
• It is top – down parsing
• An efficient non-backtracking form of top-down parser
called a predictive parser.
• LL(1) grammars from which predictive parsers can be
constructed automatically.
PREDICTIVE PARSER
•To construct a predictive parser we must know
• Input symbol a
• Non terminal A to be expanded
• Alternatives of production A-->a1|a2|….|an
• That derives a string beginning with a
• Proper alternative must be detectable by looking at
only first symbol it derives.
• Flow of control constructs most programming
language with their keywords that are detected.
PREDICTIVE PARSERS
• Recursive descent parser that needs no
backtracking i.e (predictive parser).
• Eg:- stmt  if expr then stmt else stmt
while expr do stmt
begin stmt_list end
• Keywords tells us which alternative is the one
that could find the statement.
PREDICTIVE PARSERS
• To construct the transition diagram of a
predictive parser from a grammar.
 Eliminate LR from the grammar
Then left factor the grammar
Then for each non terminalA do the following
 Create an initial and final state
 For each production A  x1 ,x2….xn.
 Create a path from initial to final state
 With edges labeled x1,x2,….xn
TRANSITION DIAGRAMS FOR PREDICTIVE PARSERS
NON RECURSIVE PREDICTIVE PARSER
• it is possible to build a non recursive predictive parser
by maintaining stack-explicit
recursive calls – implicit
• key problem – determining production to be
applied for a non terminal
• predictive parser has :-
input - contain string to parser followed by $
stack - sequence of grammar symbols with $
parsing table - 2 dimension array M[A,a]
output stream - gives output
NON RECURSIVE PREDICTIVE PARSER
• $ - right endmarker to indicate end of string
• A – non terminal , a – terminal
• program considers X – top of the stack
a – current input symbol
• the behavior of the parser can be described in
terms of its configuration which gives the stack
contents and the remaining input
NON RECURSIVE PREDICTIVE PARSER
• two symbols determine the action of the parser.
• there are 3 possibilities
 if X=a=$ , parser halts and announces
successful completion of parsing.
 If X=a!=$ , parser deletes X off the stack and
the input pointer to next input symbol.
 If X is non terminal , program consults entry
M[X,a]Of the parsing table M
NON RECURSIVE PREDICTIVE PARSER
• The following rules are used to construct the
predictive parsing table:
1. for each terminal a in FIRST(α),
add A → α to matrix M[A,a]
2. if λ is in FIRST(α), then
for each terminal b in FOLLOW(A),
add A → α to matrix M[A,b]
Construction of predictive parsing tables
Predictive parser

Weitere ähnliche Inhalte

Was ist angesagt?

Was ist angesagt? (20)

Parsing in Compiler Design
Parsing in Compiler DesignParsing in Compiler Design
Parsing in Compiler Design
 
Types of Parser
Types of ParserTypes of Parser
Types of Parser
 
A Role of Lexical Analyzer
A Role of Lexical AnalyzerA Role of Lexical Analyzer
A Role of Lexical Analyzer
 
Lexical analysis - Compiler Design
Lexical analysis - Compiler DesignLexical analysis - Compiler Design
Lexical analysis - Compiler Design
 
Code optimization in compiler design
Code optimization in compiler designCode optimization in compiler design
Code optimization in compiler design
 
1.Role lexical Analyzer
1.Role lexical Analyzer1.Role lexical Analyzer
1.Role lexical Analyzer
 
Ll(1) Parser in Compilers
Ll(1) Parser in CompilersLl(1) Parser in Compilers
Ll(1) Parser in Compilers
 
Parsing
ParsingParsing
Parsing
 
Recognition-of-tokens
Recognition-of-tokensRecognition-of-tokens
Recognition-of-tokens
 
LISP: Introduction to lisp
LISP: Introduction to lispLISP: Introduction to lisp
LISP: Introduction to lisp
 
Top down and botttom up Parsing
Top down     and botttom up ParsingTop down     and botttom up Parsing
Top down and botttom up Parsing
 
Top down parsing
Top down parsingTop down parsing
Top down parsing
 
Top down parsing
Top down parsingTop down parsing
Top down parsing
 
Post Machine
Post MachinePost Machine
Post Machine
 
Parsing
ParsingParsing
Parsing
 
Hashing
HashingHashing
Hashing
 
Symbol table in compiler Design
Symbol table in compiler DesignSymbol table in compiler Design
Symbol table in compiler Design
 
Input-Buffering
Input-BufferingInput-Buffering
Input-Buffering
 
Syntax analysis
Syntax analysisSyntax analysis
Syntax analysis
 
Applications of data structures
Applications of data structuresApplications of data structures
Applications of data structures
 

Ähnlich wie Predictive parser

Ähnlich wie Predictive parser (20)

Non- Recursive Predictive Parsing.pptx
Non- Recursive Predictive Parsing.pptxNon- Recursive Predictive Parsing.pptx
Non- Recursive Predictive Parsing.pptx
 
Control structure
Control structureControl structure
Control structure
 
Compiler unit 2&3
Compiler unit 2&3Compiler unit 2&3
Compiler unit 2&3
 
Unitiv 111206005201-phpapp01
Unitiv 111206005201-phpapp01Unitiv 111206005201-phpapp01
Unitiv 111206005201-phpapp01
 
Lexical analysis - Compiler Design
Lexical analysis - Compiler DesignLexical analysis - Compiler Design
Lexical analysis - Compiler Design
 
Introduction
IntroductionIntroduction
Introduction
 
Introduction
IntroductionIntroduction
Introduction
 
3. Syntax Analyzer.pptx
3. Syntax Analyzer.pptx3. Syntax Analyzer.pptx
3. Syntax Analyzer.pptx
 
Compiler Design
Compiler Design Compiler Design
Compiler Design
 
Lecture 12 Bottom-UP Parsing.pptx
Lecture 12 Bottom-UP Parsing.pptxLecture 12 Bottom-UP Parsing.pptx
Lecture 12 Bottom-UP Parsing.pptx
 
Compier Design_Unit I.ppt
Compier Design_Unit I.pptCompier Design_Unit I.ppt
Compier Design_Unit I.ppt
 
Compier Design_Unit I.ppt
Compier Design_Unit I.pptCompier Design_Unit I.ppt
Compier Design_Unit I.ppt
 
Syntactic analysis in NLP
Syntactic analysis in NLPSyntactic analysis in NLP
Syntactic analysis in NLP
 
Parsing (Automata)
Parsing (Automata)Parsing (Automata)
Parsing (Automata)
 
Regular Expression to Finite Automata
Regular Expression to Finite AutomataRegular Expression to Finite Automata
Regular Expression to Finite Automata
 
Comiler construction Notes
Comiler construction NotesComiler construction Notes
Comiler construction Notes
 
Compilers
CompilersCompilers
Compilers
 
phases of compiler
phases of compilerphases of compiler
phases of compiler
 
Compiler unit 1
Compiler unit 1Compiler unit 1
Compiler unit 1
 
LR PARSE.pptx
LR PARSE.pptxLR PARSE.pptx
LR PARSE.pptx
 

Mehr von Jothi Lakshmi

Mehr von Jothi Lakshmi (8)

Yoga for beauty
Yoga for beautyYoga for beauty
Yoga for beauty
 
(floyd's algm)
(floyd's algm)(floyd's algm)
(floyd's algm)
 
IPV6 ADDRESS
IPV6 ADDRESSIPV6 ADDRESS
IPV6 ADDRESS
 
SOA
SOASOA
SOA
 
Soa business centric and soap basic
Soa business centric and soap basicSoa business centric and soap basic
Soa business centric and soap basic
 
frame relay
frame relayframe relay
frame relay
 
external sorting
external sortingexternal sorting
external sorting
 
Dag representation of basic blocks
Dag representation of basic blocksDag representation of basic blocks
Dag representation of basic blocks
 

Kürzlich hochgeladen

Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17  How to Extend Models Using Mixin ClassesMixin Classes in Odoo 17  How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17 How to Extend Models Using Mixin ClassesCeline George
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingTechSoup
 
Class 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdfClass 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdfAyushMahapatra5
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104misteraugie
 
ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701bronxfugly43
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsTechSoup
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdfQucHHunhnh
 
Making and Justifying Mathematical Decisions.pdf
Making and Justifying Mathematical Decisions.pdfMaking and Justifying Mathematical Decisions.pdf
Making and Justifying Mathematical Decisions.pdfChris Hunter
 
On National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsOn National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsMebane Rash
 
PROCESS RECORDING FORMAT.docx
PROCESS      RECORDING        FORMAT.docxPROCESS      RECORDING        FORMAT.docx
PROCESS RECORDING FORMAT.docxPoojaSen20
 
Micro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfMicro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfPoh-Sun Goh
 
Role Of Transgenic Animal In Target Validation-1.pptx
Role Of Transgenic Animal In Target Validation-1.pptxRole Of Transgenic Animal In Target Validation-1.pptx
Role Of Transgenic Animal In Target Validation-1.pptxNikitaBankoti2
 
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...Nguyen Thanh Tu Collection
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Celine George
 
How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17Celine George
 
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...Shubhangi Sonawane
 
Energy Resources. ( B. Pharmacy, 1st Year, Sem-II) Natural Resources
Energy Resources. ( B. Pharmacy, 1st Year, Sem-II) Natural ResourcesEnergy Resources. ( B. Pharmacy, 1st Year, Sem-II) Natural Resources
Energy Resources. ( B. Pharmacy, 1st Year, Sem-II) Natural ResourcesShubhangi Sonawane
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfciinovamais
 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhikauryashika82
 

Kürzlich hochgeladen (20)

Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17  How to Extend Models Using Mixin ClassesMixin Classes in Odoo 17  How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy Consulting
 
Asian American Pacific Islander Month DDSD 2024.pptx
Asian American Pacific Islander Month DDSD 2024.pptxAsian American Pacific Islander Month DDSD 2024.pptx
Asian American Pacific Islander Month DDSD 2024.pptx
 
Class 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdfClass 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdf
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104
 
ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The Basics
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
 
Making and Justifying Mathematical Decisions.pdf
Making and Justifying Mathematical Decisions.pdfMaking and Justifying Mathematical Decisions.pdf
Making and Justifying Mathematical Decisions.pdf
 
On National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsOn National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan Fellows
 
PROCESS RECORDING FORMAT.docx
PROCESS      RECORDING        FORMAT.docxPROCESS      RECORDING        FORMAT.docx
PROCESS RECORDING FORMAT.docx
 
Micro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfMicro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdf
 
Role Of Transgenic Animal In Target Validation-1.pptx
Role Of Transgenic Animal In Target Validation-1.pptxRole Of Transgenic Animal In Target Validation-1.pptx
Role Of Transgenic Animal In Target Validation-1.pptx
 
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17
 
How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17
 
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...
 
Energy Resources. ( B. Pharmacy, 1st Year, Sem-II) Natural Resources
Energy Resources. ( B. Pharmacy, 1st Year, Sem-II) Natural ResourcesEnergy Resources. ( B. Pharmacy, 1st Year, Sem-II) Natural Resources
Energy Resources. ( B. Pharmacy, 1st Year, Sem-II) Natural Resources
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
 

Predictive parser

  • 2. • Predictive parsers • Transition diagrams for predictive parsers • Non recursive predictive parser • Construction of predictive parsing tables CONTENT
  • 3. • It is top – down parsing • An efficient non-backtracking form of top-down parser called a predictive parser. • LL(1) grammars from which predictive parsers can be constructed automatically. PREDICTIVE PARSER
  • 4. •To construct a predictive parser we must know • Input symbol a • Non terminal A to be expanded • Alternatives of production A-->a1|a2|….|an • That derives a string beginning with a • Proper alternative must be detectable by looking at only first symbol it derives. • Flow of control constructs most programming language with their keywords that are detected. PREDICTIVE PARSERS
  • 5. • Recursive descent parser that needs no backtracking i.e (predictive parser). • Eg:- stmt  if expr then stmt else stmt while expr do stmt begin stmt_list end • Keywords tells us which alternative is the one that could find the statement. PREDICTIVE PARSERS
  • 6. • To construct the transition diagram of a predictive parser from a grammar.  Eliminate LR from the grammar Then left factor the grammar Then for each non terminalA do the following  Create an initial and final state  For each production A  x1 ,x2….xn.  Create a path from initial to final state  With edges labeled x1,x2,….xn TRANSITION DIAGRAMS FOR PREDICTIVE PARSERS
  • 8. • it is possible to build a non recursive predictive parser by maintaining stack-explicit recursive calls – implicit • key problem – determining production to be applied for a non terminal • predictive parser has :- input - contain string to parser followed by $ stack - sequence of grammar symbols with $ parsing table - 2 dimension array M[A,a] output stream - gives output NON RECURSIVE PREDICTIVE PARSER
  • 9. • $ - right endmarker to indicate end of string • A – non terminal , a – terminal • program considers X – top of the stack a – current input symbol • the behavior of the parser can be described in terms of its configuration which gives the stack contents and the remaining input NON RECURSIVE PREDICTIVE PARSER
  • 10. • two symbols determine the action of the parser. • there are 3 possibilities  if X=a=$ , parser halts and announces successful completion of parsing.  If X=a!=$ , parser deletes X off the stack and the input pointer to next input symbol.  If X is non terminal , program consults entry M[X,a]Of the parsing table M NON RECURSIVE PREDICTIVE PARSER
  • 11. • The following rules are used to construct the predictive parsing table: 1. for each terminal a in FIRST(α), add A → α to matrix M[A,a] 2. if λ is in FIRST(α), then for each terminal b in FOLLOW(A), add A → α to matrix M[A,b] Construction of predictive parsing tables