SlideShare uma empresa Scribd logo
1 de 15
TOP DOWN PARSING
MADE BY : PRANKIT MISHRA(141CC00007)
UNDER THE GUIDANCE OF DR. AMIT DAS(FACULTY INCHARGE)
5/7/2017Prankit Mishra, ICFAI Tech School
1
CONTENT
 Introduction
 Programming Language Applications
 Relationship between Parser Types
 Recursive Descent
 The Parsing Tables & Parsing Program
 Predictive Parser
 Building a Predictive Parse Table
 For First
 For Follow
 LL(1) Grammars
 Model of a Non-Recursive Predictive
Parser
 Non-Recursive Predictive Parsing
 Parsing Table M for Grammar
5/7/2017Prankit Mishra, ICFAI Tech School
2
Introduction
 In computer science, top-down parsing is a parsing strategy where one first looks at the
highest level of the parse tree and works down the parse tree by using the rewriting rules of
a formal grammar.
 LL parsers are a type of parser that uses a top-down parsing strategy.
 Top-down parsing is a strategy of analysing unknown data relationships by hypothesizing
general parse tree structures and then considering whether the known fundamental
structures are compatible with the hypothesis. It occurs in the analysis of both
natural languages and computer languages.
5/7/2017Prankit Mishra, ICFAI Tech School
3
Programming Language Application
 A compiler parses input from a programming language to assembly language or an internal
representation by matching the incoming symbols to production rules.
 Production rules are commonly defined using Backus-Naur form.
 An LL parser is a type of parser that does top-down parsing by applying each production
rule to the incoming symbols, working from the left-most symbol yielded on a production
rule and then proceeding to the next production rule for each non-terminal symbol
encountered.
 In this way the parsing starts on the Left of the result side (right side) of the production rule
and evaluates non-terminals from the Left first and, thus, proceeds down the parse tree for
each new non-terminal before continuing to the next symbol for a production rule.
5/7/2017Prankit Mishra, ICFAI Tech School
4
Relationship Between Parser Types
5/7/2017Prankit Mishra, ICFAI Tech School
5
Recursive Descent
 Recursive descent parsers simply try to build a top-down parse tree.
 It would be better if we always knew the correct action to take.
 It would be better if we could avoid recursive procedure calls during parsing.
5/7/2017Prankit Mishra, ICFAI Tech School
6
The Parsing Table & Parsing Program
 The table is a 2D array M[A,a] where A is a nonterminal symbol and a is a terminal or $.
 At each step, the parser considers the top-of-stack symbol X and input symbol a:
 If both are $, accept
 If they are the same (nonterminal), pop X, advance input
 If X is a nonterminal, consult M[X,a].
 If M[X,a] is “ERROR” call an error recovery routine. Otherwise, if M[X,a] is a production
of the grammar X -> UVW, replace X on the stack with WVU (U on top)
5/7/2017Prankit Mishra, ICFAI Tech School
7
Predictive Parsers
 A predictive parser always knows which production to use, ( to avoid backtracking )
 Example: for the productions
stmt -> if ( expr ) stmt else stmt
| while ( expr ) stmt
| for ( stmt expr stmt ) stmt
 A recursive descent parser would always know which production to use, depending on the
input token.
5/7/2017Prankit Mishra, ICFAI Tech School
8
Building a predictive parse table
 The construction requires two functions:
 1. FIRST
 2. FOLLOW
5/7/2017Prankit Mishra, ICFAI Tech School
9
For First
 For a string of grammar symbols α, FIRST(α) is the set of terminals that begin
all possible strings derived from α. If α =*> ε, then ε is also in FIRST(α).
 E -> T E’
 E’ -> + T E’ | ε
 T -> F T’
 T’ -> * F T’ | ε
 F -> ( E ) | id
FIRST(E) = FIRST (T) = FIRST (F) = {( , id }
FIRST(E’) = {+ , e}
FIRST(T) = {( , id}
FIRST(T’) = { *, e}
FIRST(F) = {( , id }
5/7/2017Prankit Mishra, ICFAI Tech School
10
For Follow
 FOLLOW(A) for non terminal A is the set of terminals that can appear immediately
to the right of A in some sentential form. If A can be the last symbol in a sentential
form, then $ is also in FOLLOW(A).
 E -> T E’
 E’ -> + T E’ | ε
 T -> F T’
 T’ -> * F T’ | ε
 F -> ( E ) | id
Follow (E) = { ) , $ }
Follow (E’) = Follow (E)= { ) ,$ }
Follow (T) = { +, Follow (E)}= {+ , ) , $}
Follow (T’) = {+, ) ,$}
Follow ( F) = {*, +, ), $ }
5/7/2017Prankit Mishra, ICFAI Tech School
11
LL(1) grammars
 In computer science, an LL parser is a top-down parser for a subset of context-free
languages.
 It parses the input from Left to right, performing Leftmost derivation of the sentence.
 An LL parser is called an LL(k) parser if it uses k tokens of look ahead when parsing a
sentence.
 The predictive parser algorithm can be applied to ANY grammar.
5/7/2017Prankit Mishra, ICFAI Tech School
12
Model of a non recursive predictive parser
a + b $
X
Y
Z
$
Input buffer
stack
Predictive parsing
program/driver
Parsing Table M
5/7/2017Prankit Mishra, ICFAI Tech School
13
NoN recursive Predictive Parsing
 If X = a = $, the parser halts and announces successful completion of parsing.
 If X = a  $, the parser pops X off the stack and advances the input pointer to the next input
symbol.
 If X is a nonterminal, the program consults entry M[X, a] of the parsing table M. This entry
will be either an X-production of the grammar or an error entry. If, for example, M[X, a] =
{X  UVW}, the parser replaces X on top of the stack by WVU (with U on top).
 As output, we shall assume that the parser just prints the production used; any other code
could be executed here. If M[X, a] = error, the parser calls an error recovery routine.
5/7/2017Prankit Mishra, ICFAI Tech School
14
THANK YOU
5/7/2017Prankit Mishra, ICFAI Tech School
15

Mais conteúdo relacionado

Mais procurados

Mais procurados (20)

Role-of-lexical-analysis
Role-of-lexical-analysisRole-of-lexical-analysis
Role-of-lexical-analysis
 
Cs419 lec10 left recursion and left factoring
Cs419 lec10   left recursion and left factoringCs419 lec10   left recursion and left factoring
Cs419 lec10 left recursion and left factoring
 
Lecture 04 syntax analysis
Lecture 04 syntax analysisLecture 04 syntax analysis
Lecture 04 syntax analysis
 
First and follow set
First and follow setFirst and follow set
First and follow set
 
Lexical analysis - Compiler Design
Lexical analysis - Compiler DesignLexical analysis - Compiler Design
Lexical analysis - Compiler Design
 
Compiler unit 2&3
Compiler unit 2&3Compiler unit 2&3
Compiler unit 2&3
 
Compiler design syntax analysis
Compiler design syntax analysisCompiler design syntax analysis
Compiler design syntax analysis
 
Syntax directed translation
Syntax directed translationSyntax directed translation
Syntax directed translation
 
LR Parsing
LR ParsingLR Parsing
LR Parsing
 
Bottom - Up Parsing
Bottom - Up ParsingBottom - Up Parsing
Bottom - Up Parsing
 
Parsing
ParsingParsing
Parsing
 
RECURSIVE DESCENT PARSING
RECURSIVE DESCENT PARSINGRECURSIVE DESCENT PARSING
RECURSIVE DESCENT PARSING
 
Parsing LL(1), SLR, LR(1)
Parsing LL(1), SLR, LR(1)Parsing LL(1), SLR, LR(1)
Parsing LL(1), SLR, LR(1)
 
Lexical analyzer
Lexical analyzerLexical analyzer
Lexical analyzer
 
Compiler Design LR parsing SLR ,LALR CLR
Compiler Design LR parsing SLR ,LALR CLRCompiler Design LR parsing SLR ,LALR CLR
Compiler Design LR parsing SLR ,LALR CLR
 
Introduction TO Finite Automata
Introduction TO Finite AutomataIntroduction TO Finite Automata
Introduction TO Finite Automata
 
LR(1) and SLR(1) parsing
LR(1) and SLR(1) parsingLR(1) and SLR(1) parsing
LR(1) and SLR(1) parsing
 
CLR AND LALR PARSER
CLR AND LALR PARSERCLR AND LALR PARSER
CLR AND LALR PARSER
 
COMPILER DESIGN- Syntax Directed Translation
COMPILER DESIGN- Syntax Directed TranslationCOMPILER DESIGN- Syntax Directed Translation
COMPILER DESIGN- Syntax Directed Translation
 
Bottom up parser
Bottom up parserBottom up parser
Bottom up parser
 

Semelhante a Top down parsing

4 lexical and syntax analysis
4 lexical and syntax analysis4 lexical and syntax analysis
4 lexical and syntax analysis
jigeno
 
Perl 101 - The Basics of Perl Programming
Perl  101 - The Basics of Perl ProgrammingPerl  101 - The Basics of Perl Programming
Perl 101 - The Basics of Perl Programming
Utkarsh Sengar
 
Learning ObjectivesGain some experience using dynamic data structu.docx
Learning ObjectivesGain some experience using dynamic data structu.docxLearning ObjectivesGain some experience using dynamic data structu.docx
Learning ObjectivesGain some experience using dynamic data structu.docx
jesseniasaddler
 

Semelhante a Top down parsing (20)

Chapter-3 compiler.pptx course materials
Chapter-3 compiler.pptx course materialsChapter-3 compiler.pptx course materials
Chapter-3 compiler.pptx course materials
 
Module 11
Module 11Module 11
Module 11
 
Cd2 [autosaved]
Cd2 [autosaved]Cd2 [autosaved]
Cd2 [autosaved]
 
Syntax Analysis.pptx
Syntax Analysis.pptxSyntax Analysis.pptx
Syntax Analysis.pptx
 
Assignment10
Assignment10Assignment10
Assignment10
 
Ch2 (1).ppt
Ch2 (1).pptCh2 (1).ppt
Ch2 (1).ppt
 
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
 
Parsing
ParsingParsing
Parsing
 
Top Down Parsing, Predictive Parsing
Top Down Parsing, Predictive ParsingTop Down Parsing, Predictive Parsing
Top Down Parsing, Predictive Parsing
 
LL(1) Parsers
LL(1) ParsersLL(1) Parsers
LL(1) Parsers
 
Cs6660 compiler design may june 2016 Answer Key
Cs6660 compiler design may june 2016 Answer KeyCs6660 compiler design may june 2016 Answer Key
Cs6660 compiler design may june 2016 Answer Key
 
LR PARSE.pptx
LR PARSE.pptxLR PARSE.pptx
LR PARSE.pptx
 
Data Structures (BE)
Data Structures (BE)Data Structures (BE)
Data Structures (BE)
 
Lecture 24Recursive decent parsing and back tracking.pptx
Lecture 24Recursive decent parsing and back tracking.pptxLecture 24Recursive decent parsing and back tracking.pptx
Lecture 24Recursive decent parsing and back tracking.pptx
 
Overview of Language Processor : Fundamentals of LP , Symbol Table , Data Str...
Overview of Language Processor : Fundamentals of LP , Symbol Table , Data Str...Overview of Language Processor : Fundamentals of LP , Symbol Table , Data Str...
Overview of Language Processor : Fundamentals of LP , Symbol Table , Data Str...
 
4 lexical and syntax analysis
4 lexical and syntax analysis4 lexical and syntax analysis
4 lexical and syntax analysis
 
Perl 101 - The Basics of Perl Programming
Perl  101 - The Basics of Perl ProgrammingPerl  101 - The Basics of Perl Programming
Perl 101 - The Basics of Perl Programming
 
3. Syntax Analyzer.pptx
3. Syntax Analyzer.pptx3. Syntax Analyzer.pptx
3. Syntax Analyzer.pptx
 
Learning ObjectivesGain some experience using dynamic data structu.docx
Learning ObjectivesGain some experience using dynamic data structu.docxLearning ObjectivesGain some experience using dynamic data structu.docx
Learning ObjectivesGain some experience using dynamic data structu.docx
 
Ch06
Ch06Ch06
Ch06
 

Mais de Prankit Mishra (11)

Tourist management system using .NET
Tourist management system using .NETTourist management system using .NET
Tourist management system using .NET
 
Remote Method Innovation (RMI) In JAVA
Remote Method Innovation (RMI) In JAVARemote Method Innovation (RMI) In JAVA
Remote Method Innovation (RMI) In JAVA
 
Fog computing : The new age Technology
Fog computing : The new age TechnologyFog computing : The new age Technology
Fog computing : The new age Technology
 
Distributed operating system
Distributed operating systemDistributed operating system
Distributed operating system
 
Ajanta and Ellora Caves
Ajanta and Ellora CavesAjanta and Ellora Caves
Ajanta and Ellora Caves
 
Probability In Discrete Structure of Computer Science
Probability In Discrete Structure of Computer ScienceProbability In Discrete Structure of Computer Science
Probability In Discrete Structure of Computer Science
 
Cryptography using probability
Cryptography using probabilityCryptography using probability
Cryptography using probability
 
Bipolar Junction Transistor
Bipolar Junction TransistorBipolar Junction Transistor
Bipolar Junction Transistor
 
Autotransformers
AutotransformersAutotransformers
Autotransformers
 
Forward error correction
Forward error correctionForward error correction
Forward error correction
 
DDR SDRAMs
DDR SDRAMsDDR SDRAMs
DDR SDRAMs
 

Último

Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
Christo Ananth
 
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
Dr.Costas Sachpazis
 

Último (20)

CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete Record
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete RecordCCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete Record
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete Record
 
BSides Seattle 2024 - Stopping Ethan Hunt From Taking Your Data.pptx
BSides Seattle 2024 - Stopping Ethan Hunt From Taking Your Data.pptxBSides Seattle 2024 - Stopping Ethan Hunt From Taking Your Data.pptx
BSides Seattle 2024 - Stopping Ethan Hunt From Taking Your Data.pptx
 
Russian Call Girls in Nagpur Grishma Call 7001035870 Meet With Nagpur Escorts
Russian Call Girls in Nagpur Grishma Call 7001035870 Meet With Nagpur EscortsRussian Call Girls in Nagpur Grishma Call 7001035870 Meet With Nagpur Escorts
Russian Call Girls in Nagpur Grishma Call 7001035870 Meet With Nagpur Escorts
 
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
 
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
 
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur EscortsHigh Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
 
MANUFACTURING PROCESS-II UNIT-1 THEORY OF METAL CUTTING
MANUFACTURING PROCESS-II UNIT-1 THEORY OF METAL CUTTINGMANUFACTURING PROCESS-II UNIT-1 THEORY OF METAL CUTTING
MANUFACTURING PROCESS-II UNIT-1 THEORY OF METAL CUTTING
 
(INDIRA) Call Girl Aurangabad Call Now 8617697112 Aurangabad Escorts 24x7
(INDIRA) Call Girl Aurangabad Call Now 8617697112 Aurangabad Escorts 24x7(INDIRA) Call Girl Aurangabad Call Now 8617697112 Aurangabad Escorts 24x7
(INDIRA) Call Girl Aurangabad Call Now 8617697112 Aurangabad Escorts 24x7
 
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdf
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdfONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdf
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdf
 
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLSMANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
 
Roadmap to Membership of RICS - Pathways and Routes
Roadmap to Membership of RICS - Pathways and RoutesRoadmap to Membership of RICS - Pathways and Routes
Roadmap to Membership of RICS - Pathways and Routes
 
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
 
Booking open Available Pune Call Girls Koregaon Park 6297143586 Call Hot Ind...
Booking open Available Pune Call Girls Koregaon Park  6297143586 Call Hot Ind...Booking open Available Pune Call Girls Koregaon Park  6297143586 Call Hot Ind...
Booking open Available Pune Call Girls Koregaon Park 6297143586 Call Hot Ind...
 
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
 
Introduction to IEEE STANDARDS and its different types.pptx
Introduction to IEEE STANDARDS and its different types.pptxIntroduction to IEEE STANDARDS and its different types.pptx
Introduction to IEEE STANDARDS and its different types.pptx
 
Introduction to Multiple Access Protocol.pptx
Introduction to Multiple Access Protocol.pptxIntroduction to Multiple Access Protocol.pptx
Introduction to Multiple Access Protocol.pptx
 
Water Industry Process Automation & Control Monthly - April 2024
Water Industry Process Automation & Control Monthly - April 2024Water Industry Process Automation & Control Monthly - April 2024
Water Industry Process Automation & Control Monthly - April 2024
 
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
 
Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...
Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...
Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...
 
Call Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service Nashik
Call Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service NashikCall Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service Nashik
Call Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service Nashik
 

Top down parsing

  • 1. TOP DOWN PARSING MADE BY : PRANKIT MISHRA(141CC00007) UNDER THE GUIDANCE OF DR. AMIT DAS(FACULTY INCHARGE) 5/7/2017Prankit Mishra, ICFAI Tech School 1
  • 2. CONTENT  Introduction  Programming Language Applications  Relationship between Parser Types  Recursive Descent  The Parsing Tables & Parsing Program  Predictive Parser  Building a Predictive Parse Table  For First  For Follow  LL(1) Grammars  Model of a Non-Recursive Predictive Parser  Non-Recursive Predictive Parsing  Parsing Table M for Grammar 5/7/2017Prankit Mishra, ICFAI Tech School 2
  • 3. Introduction  In computer science, top-down parsing is a parsing strategy where one first looks at the highest level of the parse tree and works down the parse tree by using the rewriting rules of a formal grammar.  LL parsers are a type of parser that uses a top-down parsing strategy.  Top-down parsing is a strategy of analysing unknown data relationships by hypothesizing general parse tree structures and then considering whether the known fundamental structures are compatible with the hypothesis. It occurs in the analysis of both natural languages and computer languages. 5/7/2017Prankit Mishra, ICFAI Tech School 3
  • 4. Programming Language Application  A compiler parses input from a programming language to assembly language or an internal representation by matching the incoming symbols to production rules.  Production rules are commonly defined using Backus-Naur form.  An LL parser is a type of parser that does top-down parsing by applying each production rule to the incoming symbols, working from the left-most symbol yielded on a production rule and then proceeding to the next production rule for each non-terminal symbol encountered.  In this way the parsing starts on the Left of the result side (right side) of the production rule and evaluates non-terminals from the Left first and, thus, proceeds down the parse tree for each new non-terminal before continuing to the next symbol for a production rule. 5/7/2017Prankit Mishra, ICFAI Tech School 4
  • 5. Relationship Between Parser Types 5/7/2017Prankit Mishra, ICFAI Tech School 5
  • 6. Recursive Descent  Recursive descent parsers simply try to build a top-down parse tree.  It would be better if we always knew the correct action to take.  It would be better if we could avoid recursive procedure calls during parsing. 5/7/2017Prankit Mishra, ICFAI Tech School 6
  • 7. The Parsing Table & Parsing Program  The table is a 2D array M[A,a] where A is a nonterminal symbol and a is a terminal or $.  At each step, the parser considers the top-of-stack symbol X and input symbol a:  If both are $, accept  If they are the same (nonterminal), pop X, advance input  If X is a nonterminal, consult M[X,a].  If M[X,a] is “ERROR” call an error recovery routine. Otherwise, if M[X,a] is a production of the grammar X -> UVW, replace X on the stack with WVU (U on top) 5/7/2017Prankit Mishra, ICFAI Tech School 7
  • 8. Predictive Parsers  A predictive parser always knows which production to use, ( to avoid backtracking )  Example: for the productions stmt -> if ( expr ) stmt else stmt | while ( expr ) stmt | for ( stmt expr stmt ) stmt  A recursive descent parser would always know which production to use, depending on the input token. 5/7/2017Prankit Mishra, ICFAI Tech School 8
  • 9. Building a predictive parse table  The construction requires two functions:  1. FIRST  2. FOLLOW 5/7/2017Prankit Mishra, ICFAI Tech School 9
  • 10. For First  For a string of grammar symbols α, FIRST(α) is the set of terminals that begin all possible strings derived from α. If α =*> ε, then ε is also in FIRST(α).  E -> T E’  E’ -> + T E’ | ε  T -> F T’  T’ -> * F T’ | ε  F -> ( E ) | id FIRST(E) = FIRST (T) = FIRST (F) = {( , id } FIRST(E’) = {+ , e} FIRST(T) = {( , id} FIRST(T’) = { *, e} FIRST(F) = {( , id } 5/7/2017Prankit Mishra, ICFAI Tech School 10
  • 11. For Follow  FOLLOW(A) for non terminal A is the set of terminals that can appear immediately to the right of A in some sentential form. If A can be the last symbol in a sentential form, then $ is also in FOLLOW(A).  E -> T E’  E’ -> + T E’ | ε  T -> F T’  T’ -> * F T’ | ε  F -> ( E ) | id Follow (E) = { ) , $ } Follow (E’) = Follow (E)= { ) ,$ } Follow (T) = { +, Follow (E)}= {+ , ) , $} Follow (T’) = {+, ) ,$} Follow ( F) = {*, +, ), $ } 5/7/2017Prankit Mishra, ICFAI Tech School 11
  • 12. LL(1) grammars  In computer science, an LL parser is a top-down parser for a subset of context-free languages.  It parses the input from Left to right, performing Leftmost derivation of the sentence.  An LL parser is called an LL(k) parser if it uses k tokens of look ahead when parsing a sentence.  The predictive parser algorithm can be applied to ANY grammar. 5/7/2017Prankit Mishra, ICFAI Tech School 12
  • 13. Model of a non recursive predictive parser a + b $ X Y Z $ Input buffer stack Predictive parsing program/driver Parsing Table M 5/7/2017Prankit Mishra, ICFAI Tech School 13
  • 14. NoN recursive Predictive Parsing  If X = a = $, the parser halts and announces successful completion of parsing.  If X = a  $, the parser pops X off the stack and advances the input pointer to the next input symbol.  If X is a nonterminal, the program consults entry M[X, a] of the parsing table M. This entry will be either an X-production of the grammar or an error entry. If, for example, M[X, a] = {X  UVW}, the parser replaces X on top of the stack by WVU (with U on top).  As output, we shall assume that the parser just prints the production used; any other code could be executed here. If M[X, a] = error, the parser calls an error recovery routine. 5/7/2017Prankit Mishra, ICFAI Tech School 14
  • 15. THANK YOU 5/7/2017Prankit Mishra, ICFAI Tech School 15