際際滷

際際滷Share a Scribd company logo
Welcome to
our
Presentation
Sadia Akter
The role of the parser
Error Recovery Strategies
Group Member:
The role of the parser
Role of the Parser
 The parser obtains a string of tokens from the lexical
analyzer, and verifies that the string can be generated by the
grammar for the source language.
 The parser returns any syntax error for the source language
Types of parsers
 The task of the parser is essentially to determine if and how
the input can be derived from the start symbol of the
grammar.
 This can be done in essentially two ways
a. Top-down parser
b. Bottom-up parser
Top-down parser:
 Top-down parsers build parse trees from the top (root) to
the bottom (leaves).
 Input to the parser is scanned from left to right.
 One symbol at a time.
 Always expand the leftmostnon-terminal
Bottom-up parser:
 Bottom-up parsers build parse trees from the leaves and work up to
the root.
 Input to the parser is scanned from left to right.
 One symbol at a time.
 And just as efficient
The role of parser
interm
repres
errors
lexical
analyzer
parser
rest of
front end
symbol
table
source
program
parse
tree
token
get next
token
regular
expressions
also technically part or
parsing
includes augmenting info on
tokens in source, type
checking, semantic analysis
uses a grammar to check
structure of tokens
produces a parse tree
syntactic errors and recovery
recognize correct syntax
report errors
Parsing Responsibilities
Syntax Error Handling:
a. Lexical: Misspellings
b. Syntactic: Omission, wrong order of tokens
c. Semantic: Incompatible types
d. Logical: Infinite loop / recursive call
Error Recovery Strategies
Error-Recovery Strategies
 The simplest approach is for the parser to quit with an informative
error message when it detects the first error.
 Panic-mode recovery.
 Phrase-level recovery.
 Error-productions.
 Global-correction.
Panic-Mode Recovery
 This is used by most parsing methods.
 The synchronizing tokens are usually delimiters, such as ; or }.
 Skips a considerable amount of input without checking for additional
errors
 It has the advantage of simplicity, and is guaranteed not to go
into an infinite loop.
Phrase-Level Recovery
 Perform local correction on the remaining input;
 A typical local correction is to replace a comma by asemicolon.
 Delete an extraneous semicolon.
 Insert a missing semicolon.
 Disadvantage in coping with situations in which the actual error has
occurred before the point of detection.
Error Productions
 Expand the grammar for the language at hand with productions that
generatethe
 erroneous constructs.
Global Correction
 Compiler to make as few changes as possible in processing an
incorrect input string.
 Given an incorrect input string x and grammar G, algorithms will find a
parse tree for a related string y, such that the number of insertions,
deletions, and changes of tokens required to transform x into y is as
small as possible.
 Not implemented.
Any Question?
Thank you

More Related Content

What's hot (20)

Compiler Chapter 1
Compiler Chapter 1Compiler Chapter 1
Compiler Chapter 1
Huawei Technologies
Type Checking(Compiler Design) #ShareThisIfYouLike
Type Checking(Compiler Design) #ShareThisIfYouLikeType Checking(Compiler Design) #ShareThisIfYouLike
Type Checking(Compiler Design) #ShareThisIfYouLike
United International University
Design and Analysis of Algorithms.pptx
Design and Analysis of Algorithms.pptxDesign and Analysis of Algorithms.pptx
Design and Analysis of Algorithms.pptx
Syed Zaid Irshad
Peephole Optimization
Peephole OptimizationPeephole Optimization
Peephole Optimization
United International University
Language processors
Language processorsLanguage processors
Language processors
Ganesh Wedpathak
Operator precedence
Operator precedenceOperator precedence
Operator precedence
Akshaya Arunan
Introduction to Compiler design
Introduction to Compiler design Introduction to Compiler design
Introduction to Compiler design
Dr. C.V. Suresh Babu
Input-BufferingInput-Buffering
Input-Buffering
Dattatray Gandhmal
Lexical analyzer generator lex
Lexical analyzer generator lexLexical analyzer generator lex
Lexical analyzer generator lex
Anusuya123
Code generation in Compiler Design
Code generation in Compiler DesignCode generation in Compiler Design
Code generation in Compiler Design
Kuppusamy P
Intermediate code generation (Compiler Design)
Intermediate code generation (Compiler Design)   Intermediate code generation (Compiler Design)
Intermediate code generation (Compiler Design)
Tasif Tanzim
1.Role lexical Analyzer
1.Role lexical Analyzer1.Role lexical Analyzer
1.Role lexical Analyzer
Radhakrishnan Chinnusamy
Top down and botttom up Parsing
Top down     and botttom up ParsingTop down     and botttom up Parsing
Top down and botttom up Parsing
Gerwin Ocsena
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
Code optimization in compiler design
Code optimization in compiler designCode optimization in compiler design
Code optimization in compiler design
Kuppusamy P
Passes of compilers
Passes of compilersPasses of compilers
Passes of compilers
Vairavel C
Lexical analysis - Compiler Design
Lexical analysis - Compiler DesignLexical analysis - Compiler Design
Lexical analysis - Compiler Design
Muhammed Afsal Villan
Three Address code
Three Address code Three Address code
Three Address code
Pooja Dixit
Algorithms Lecture 2: Analysis of Algorithms I
Algorithms Lecture 2: Analysis of Algorithms IAlgorithms Lecture 2: Analysis of Algorithms I
Algorithms Lecture 2: Analysis of Algorithms I
Mohamed Loey
Stacks and Queue - Data Structures
Stacks and Queue - Data StructuresStacks and Queue - Data Structures
Stacks and Queue - Data Structures
Dr. Jasmine Beulah Gnanadurai
Design and Analysis of Algorithms.pptx
Design and Analysis of Algorithms.pptxDesign and Analysis of Algorithms.pptx
Design and Analysis of Algorithms.pptx
Syed Zaid Irshad
Operator precedence
Operator precedenceOperator precedence
Operator precedence
Akshaya Arunan
Introduction to Compiler design
Introduction to Compiler design Introduction to Compiler design
Introduction to Compiler design
Dr. C.V. Suresh Babu
Input-BufferingInput-Buffering
Input-Buffering
Dattatray Gandhmal
Lexical analyzer generator lex
Lexical analyzer generator lexLexical analyzer generator lex
Lexical analyzer generator lex
Anusuya123
Code generation in Compiler Design
Code generation in Compiler DesignCode generation in Compiler Design
Code generation in Compiler Design
Kuppusamy P
Intermediate code generation (Compiler Design)
Intermediate code generation (Compiler Design)   Intermediate code generation (Compiler Design)
Intermediate code generation (Compiler Design)
Tasif Tanzim
Top down and botttom up Parsing
Top down     and botttom up ParsingTop down     and botttom up Parsing
Top down and botttom up Parsing
Gerwin Ocsena
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
Code optimization in compiler design
Code optimization in compiler designCode optimization in compiler design
Code optimization in compiler design
Kuppusamy P
Passes of compilers
Passes of compilersPasses of compilers
Passes of compilers
Vairavel C
Lexical analysis - Compiler Design
Lexical analysis - Compiler DesignLexical analysis - Compiler Design
Lexical analysis - Compiler Design
Muhammed Afsal Villan
Three Address code
Three Address code Three Address code
Three Address code
Pooja Dixit
Algorithms Lecture 2: Analysis of Algorithms I
Algorithms Lecture 2: Analysis of Algorithms IAlgorithms Lecture 2: Analysis of Algorithms I
Algorithms Lecture 2: Analysis of Algorithms I
Mohamed Loey

Similar to The role of the parser and Error recovery strategies ppt in compiler design (20)

module 2 introduction to syntax analysis
module 2  introduction to syntax analysismodule 2  introduction to syntax analysis
module 2 introduction to syntax analysis
ElakkiaU
COMPILER DESIGN LECTURES -UNIT-2 ST.pptx
COMPILER DESIGN LECTURES -UNIT-2 ST.pptxCOMPILER DESIGN LECTURES -UNIT-2 ST.pptx
COMPILER DESIGN LECTURES -UNIT-2 ST.pptx
Ranjeet Reddy
chapter4 end.pptx
chapter4 end.pptxchapter4 end.pptx
chapter4 end.pptx
Maryam522887
match the following attributes to the parts of a compilerstrips ou.pdf
match the following attributes to the parts of a compilerstrips ou.pdfmatch the following attributes to the parts of a compilerstrips ou.pdf
match the following attributes to the parts of a compilerstrips ou.pdf
arpitaeron555
Chapter-3 compiler.pptx course materials
Chapter-3 compiler.pptx course materialsChapter-3 compiler.pptx course materials
Chapter-3 compiler.pptx course materials
gadisaAdamu
Module 11
Module 11Module 11
Module 11
bittudavis
8-Practice problems on operator precedence parser-24-05-2023.docx
8-Practice problems on operator precedence parser-24-05-2023.docx8-Practice problems on operator precedence parser-24-05-2023.docx
8-Practice problems on operator precedence parser-24-05-2023.docx
venkatapranaykumarGa
Pcd question bank
Pcd question bank Pcd question bank
Pcd question bank
Sumathi Gnanasekaran
Compiler design important questions
Compiler design   important questionsCompiler design   important questions
Compiler design important questions
akila viji
SYNTAX ANALYSIS, PARSING, BACKTRACKING IN COMPILER DESIGN
SYNTAX ANALYSIS, PARSING, BACKTRACKING  IN COMPILER DESIGNSYNTAX ANALYSIS, PARSING, BACKTRACKING  IN COMPILER DESIGN
SYNTAX ANALYSIS, PARSING, BACKTRACKING IN COMPILER DESIGN
nithya g
Parsing
ParsingParsing
Parsing
Dayananda Sagar University
International journal of compiling
International journal of compilingInternational journal of compiling
International journal of compiling
Andivann
International journal of compiling
International journal of compilingInternational journal of compiling
International journal of compiling
Mgcal D. Saul Magfield
Symbol Table, Error Handler & Code Generation
Symbol Table, Error Handler & Code GenerationSymbol Table, Error Handler & Code Generation
Symbol Table, Error Handler & Code Generation
Akhil Kaushik
Ch3_Syntax Analysis.pptx
Ch3_Syntax Analysis.pptxCh3_Syntax Analysis.pptx
Ch3_Syntax Analysis.pptx
TameneTamire
Syntax analysis and Run time Environment
Syntax analysis and Run time EnvironmentSyntax analysis and Run time Environment
Syntax analysis and Run time Environment
cscprabh
compiler introduction vtu syllabus 1st chapter.pptx
compiler introduction vtu syllabus 1st chapter.pptxcompiler introduction vtu syllabus 1st chapter.pptx
compiler introduction vtu syllabus 1st chapter.pptx
ranjan317165
Error Recovery strategies and yacc | Compiler Design
Error Recovery strategies and yacc | Compiler DesignError Recovery strategies and yacc | Compiler Design
Error Recovery strategies and yacc | Compiler Design
Shamsul Huda
1._Introduction_.pptx
1._Introduction_.pptx1._Introduction_.pptx
1._Introduction_.pptx
Anbarasan Radhakrishnan R
Phases of Compiler.pptx
Phases of Compiler.pptxPhases of Compiler.pptx
Phases of Compiler.pptx
ssuser3b4934
module 2 introduction to syntax analysis
module 2  introduction to syntax analysismodule 2  introduction to syntax analysis
module 2 introduction to syntax analysis
ElakkiaU
COMPILER DESIGN LECTURES -UNIT-2 ST.pptx
COMPILER DESIGN LECTURES -UNIT-2 ST.pptxCOMPILER DESIGN LECTURES -UNIT-2 ST.pptx
COMPILER DESIGN LECTURES -UNIT-2 ST.pptx
Ranjeet Reddy
chapter4 end.pptx
chapter4 end.pptxchapter4 end.pptx
chapter4 end.pptx
Maryam522887
match the following attributes to the parts of a compilerstrips ou.pdf
match the following attributes to the parts of a compilerstrips ou.pdfmatch the following attributes to the parts of a compilerstrips ou.pdf
match the following attributes to the parts of a compilerstrips ou.pdf
arpitaeron555
Chapter-3 compiler.pptx course materials
Chapter-3 compiler.pptx course materialsChapter-3 compiler.pptx course materials
Chapter-3 compiler.pptx course materials
gadisaAdamu
8-Practice problems on operator precedence parser-24-05-2023.docx
8-Practice problems on operator precedence parser-24-05-2023.docx8-Practice problems on operator precedence parser-24-05-2023.docx
8-Practice problems on operator precedence parser-24-05-2023.docx
venkatapranaykumarGa
Compiler design important questions
Compiler design   important questionsCompiler design   important questions
Compiler design important questions
akila viji
SYNTAX ANALYSIS, PARSING, BACKTRACKING IN COMPILER DESIGN
SYNTAX ANALYSIS, PARSING, BACKTRACKING  IN COMPILER DESIGNSYNTAX ANALYSIS, PARSING, BACKTRACKING  IN COMPILER DESIGN
SYNTAX ANALYSIS, PARSING, BACKTRACKING IN COMPILER DESIGN
nithya g
International journal of compiling
International journal of compilingInternational journal of compiling
International journal of compiling
Andivann
Symbol Table, Error Handler & Code Generation
Symbol Table, Error Handler & Code GenerationSymbol Table, Error Handler & Code Generation
Symbol Table, Error Handler & Code Generation
Akhil Kaushik
Ch3_Syntax Analysis.pptx
Ch3_Syntax Analysis.pptxCh3_Syntax Analysis.pptx
Ch3_Syntax Analysis.pptx
TameneTamire
Syntax analysis and Run time Environment
Syntax analysis and Run time EnvironmentSyntax analysis and Run time Environment
Syntax analysis and Run time Environment
cscprabh
compiler introduction vtu syllabus 1st chapter.pptx
compiler introduction vtu syllabus 1st chapter.pptxcompiler introduction vtu syllabus 1st chapter.pptx
compiler introduction vtu syllabus 1st chapter.pptx
ranjan317165
Error Recovery strategies and yacc | Compiler Design
Error Recovery strategies and yacc | Compiler DesignError Recovery strategies and yacc | Compiler Design
Error Recovery strategies and yacc | Compiler Design
Shamsul Huda
Phases of Compiler.pptx
Phases of Compiler.pptxPhases of Compiler.pptx
Phases of Compiler.pptx
ssuser3b4934

Recently uploaded (20)

Structural QA/QC Inspection in KRP 401600 | Copper Processing Plant-3 (MOF-3)...
Structural QA/QC Inspection in KRP 401600 | Copper Processing Plant-3 (MOF-3)...Structural QA/QC Inspection in KRP 401600 | Copper Processing Plant-3 (MOF-3)...
Structural QA/QC Inspection in KRP 401600 | Copper Processing Plant-3 (MOF-3)...
slayshadow705
RAMSES- EDITORIAL SAMPLE FOR DSSPC C.pptx
RAMSES- EDITORIAL SAMPLE FOR DSSPC C.pptxRAMSES- EDITORIAL SAMPLE FOR DSSPC C.pptx
RAMSES- EDITORIAL SAMPLE FOR DSSPC C.pptx
JenTeruel1
Multi objective genetic approach with Ranking
Multi objective genetic approach with RankingMulti objective genetic approach with Ranking
Multi objective genetic approach with Ranking
namisha18
Water Industry Process Automation & Control Monthly - March 2025.pdf
Water Industry Process Automation & Control Monthly - March 2025.pdfWater Industry Process Automation & Control Monthly - March 2025.pdf
Water Industry Process Automation & Control Monthly - March 2025.pdf
Water Industry Process Automation & Control
autonomous vehicle project for engineering.pdf
autonomous vehicle project for engineering.pdfautonomous vehicle project for engineering.pdf
autonomous vehicle project for engineering.pdf
JyotiLohar6
CS3451-OPERATING-SYSTEM NOTES ALL123.pdf
CS3451-OPERATING-SYSTEM NOTES ALL123.pdfCS3451-OPERATING-SYSTEM NOTES ALL123.pdf
CS3451-OPERATING-SYSTEM NOTES ALL123.pdf
PonniS7
Gauges are a Pump's Best Friend - Troubleshooting and Operations - v.07
Gauges are a Pump's Best Friend - Troubleshooting and Operations - v.07Gauges are a Pump's Best Friend - Troubleshooting and Operations - v.07
Gauges are a Pump's Best Friend - Troubleshooting and Operations - v.07
Brian Gongol
How Engineering Model Making Brings Designs to Life.pdf
How Engineering Model Making Brings Designs to Life.pdfHow Engineering Model Making Brings Designs to Life.pdf
How Engineering Model Making Brings Designs to Life.pdf
Maadhu Creatives-Model Making Company
Frankfurt University of Applied Science urkunde
Frankfurt University of Applied Science urkundeFrankfurt University of Applied Science urkunde
Frankfurt University of Applied Science urkunde
Lisa Emerson
CFOT Fiber Optics FOA CERTIFICATION.pptx
CFOT Fiber Optics FOA CERTIFICATION.pptxCFOT Fiber Optics FOA CERTIFICATION.pptx
CFOT Fiber Optics FOA CERTIFICATION.pptx
MohamedShabana37
UNIT 1FUNDAMENTALS OF OPERATING SYSTEMS.pptx
UNIT 1FUNDAMENTALS OF OPERATING SYSTEMS.pptxUNIT 1FUNDAMENTALS OF OPERATING SYSTEMS.pptx
UNIT 1FUNDAMENTALS OF OPERATING SYSTEMS.pptx
KesavanT10
Engineering at Lovely Professional University (LPU).pdf
Engineering at Lovely Professional University (LPU).pdfEngineering at Lovely Professional University (LPU).pdf
Engineering at Lovely Professional University (LPU).pdf
Sona
How to Make an RFID Door Lock System using Arduino
How to Make an RFID Door Lock System using ArduinoHow to Make an RFID Door Lock System using Arduino
How to Make an RFID Door Lock System using Arduino
CircuitDigest
Turbocor Product and Technology Review.pdf
Turbocor Product and Technology Review.pdfTurbocor Product and Technology Review.pdf
Turbocor Product and Technology Review.pdf
Totok Sulistiyanto
google_developer_group_ramdeobaba_university_EXPLORE_PPT
google_developer_group_ramdeobaba_university_EXPLORE_PPTgoogle_developer_group_ramdeobaba_university_EXPLORE_PPT
google_developer_group_ramdeobaba_university_EXPLORE_PPT
JayeshShete1
Lecture -3 Cold water supply system.pptx
Lecture -3 Cold water supply system.pptxLecture -3 Cold water supply system.pptx
Lecture -3 Cold water supply system.pptx
rabiaatif2
04 MAINTENANCE OF CONCRETE PAVEMENTS.ppt
04  MAINTENANCE OF CONCRETE PAVEMENTS.ppt04  MAINTENANCE OF CONCRETE PAVEMENTS.ppt
04 MAINTENANCE OF CONCRETE PAVEMENTS.ppt
sreenath seenu
Syntax Directed Definitions Synthesized Attributes and Inherited Attributes
Syntax Directed Definitions  Synthesized Attributes  and  Inherited AttributesSyntax Directed Definitions  Synthesized Attributes  and  Inherited Attributes
Syntax Directed Definitions Synthesized Attributes and Inherited Attributes
GunjalSanjay
Lectureof nano 1588236675-biosensors (1).ppt
Lectureof nano 1588236675-biosensors (1).pptLectureof nano 1588236675-biosensors (1).ppt
Lectureof nano 1588236675-biosensors (1).ppt
SherifElGohary7
only history of java.pptx real bihind the name java
only history of java.pptx real bihind the name javaonly history of java.pptx real bihind the name java
only history of java.pptx real bihind the name java
mushtaqsaliq9
Structural QA/QC Inspection in KRP 401600 | Copper Processing Plant-3 (MOF-3)...
Structural QA/QC Inspection in KRP 401600 | Copper Processing Plant-3 (MOF-3)...Structural QA/QC Inspection in KRP 401600 | Copper Processing Plant-3 (MOF-3)...
Structural QA/QC Inspection in KRP 401600 | Copper Processing Plant-3 (MOF-3)...
slayshadow705
RAMSES- EDITORIAL SAMPLE FOR DSSPC C.pptx
RAMSES- EDITORIAL SAMPLE FOR DSSPC C.pptxRAMSES- EDITORIAL SAMPLE FOR DSSPC C.pptx
RAMSES- EDITORIAL SAMPLE FOR DSSPC C.pptx
JenTeruel1
Multi objective genetic approach with Ranking
Multi objective genetic approach with RankingMulti objective genetic approach with Ranking
Multi objective genetic approach with Ranking
namisha18
autonomous vehicle project for engineering.pdf
autonomous vehicle project for engineering.pdfautonomous vehicle project for engineering.pdf
autonomous vehicle project for engineering.pdf
JyotiLohar6
CS3451-OPERATING-SYSTEM NOTES ALL123.pdf
CS3451-OPERATING-SYSTEM NOTES ALL123.pdfCS3451-OPERATING-SYSTEM NOTES ALL123.pdf
CS3451-OPERATING-SYSTEM NOTES ALL123.pdf
PonniS7
Gauges are a Pump's Best Friend - Troubleshooting and Operations - v.07
Gauges are a Pump's Best Friend - Troubleshooting and Operations - v.07Gauges are a Pump's Best Friend - Troubleshooting and Operations - v.07
Gauges are a Pump's Best Friend - Troubleshooting and Operations - v.07
Brian Gongol
Frankfurt University of Applied Science urkunde
Frankfurt University of Applied Science urkundeFrankfurt University of Applied Science urkunde
Frankfurt University of Applied Science urkunde
Lisa Emerson
CFOT Fiber Optics FOA CERTIFICATION.pptx
CFOT Fiber Optics FOA CERTIFICATION.pptxCFOT Fiber Optics FOA CERTIFICATION.pptx
CFOT Fiber Optics FOA CERTIFICATION.pptx
MohamedShabana37
UNIT 1FUNDAMENTALS OF OPERATING SYSTEMS.pptx
UNIT 1FUNDAMENTALS OF OPERATING SYSTEMS.pptxUNIT 1FUNDAMENTALS OF OPERATING SYSTEMS.pptx
UNIT 1FUNDAMENTALS OF OPERATING SYSTEMS.pptx
KesavanT10
Engineering at Lovely Professional University (LPU).pdf
Engineering at Lovely Professional University (LPU).pdfEngineering at Lovely Professional University (LPU).pdf
Engineering at Lovely Professional University (LPU).pdf
Sona
How to Make an RFID Door Lock System using Arduino
How to Make an RFID Door Lock System using ArduinoHow to Make an RFID Door Lock System using Arduino
How to Make an RFID Door Lock System using Arduino
CircuitDigest
Turbocor Product and Technology Review.pdf
Turbocor Product and Technology Review.pdfTurbocor Product and Technology Review.pdf
Turbocor Product and Technology Review.pdf
Totok Sulistiyanto
google_developer_group_ramdeobaba_university_EXPLORE_PPT
google_developer_group_ramdeobaba_university_EXPLORE_PPTgoogle_developer_group_ramdeobaba_university_EXPLORE_PPT
google_developer_group_ramdeobaba_university_EXPLORE_PPT
JayeshShete1
Lecture -3 Cold water supply system.pptx
Lecture -3 Cold water supply system.pptxLecture -3 Cold water supply system.pptx
Lecture -3 Cold water supply system.pptx
rabiaatif2
04 MAINTENANCE OF CONCRETE PAVEMENTS.ppt
04  MAINTENANCE OF CONCRETE PAVEMENTS.ppt04  MAINTENANCE OF CONCRETE PAVEMENTS.ppt
04 MAINTENANCE OF CONCRETE PAVEMENTS.ppt
sreenath seenu
Syntax Directed Definitions Synthesized Attributes and Inherited Attributes
Syntax Directed Definitions  Synthesized Attributes  and  Inherited AttributesSyntax Directed Definitions  Synthesized Attributes  and  Inherited Attributes
Syntax Directed Definitions Synthesized Attributes and Inherited Attributes
GunjalSanjay
Lectureof nano 1588236675-biosensors (1).ppt
Lectureof nano 1588236675-biosensors (1).pptLectureof nano 1588236675-biosensors (1).ppt
Lectureof nano 1588236675-biosensors (1).ppt
SherifElGohary7
only history of java.pptx real bihind the name java
only history of java.pptx real bihind the name javaonly history of java.pptx real bihind the name java
only history of java.pptx real bihind the name java
mushtaqsaliq9

The role of the parser and Error recovery strategies ppt in compiler design

  • 2. The role of the parser Error Recovery Strategies
  • 4. The role of the parser
  • 5. Role of the Parser The parser obtains a string of tokens from the lexical analyzer, and verifies that the string can be generated by the grammar for the source language. The parser returns any syntax error for the source language
  • 6. Types of parsers The task of the parser is essentially to determine if and how the input can be derived from the start symbol of the grammar. This can be done in essentially two ways a. Top-down parser b. Bottom-up parser
  • 7. Top-down parser: Top-down parsers build parse trees from the top (root) to the bottom (leaves). Input to the parser is scanned from left to right. One symbol at a time. Always expand the leftmostnon-terminal
  • 8. Bottom-up parser: Bottom-up parsers build parse trees from the leaves and work up to the root. Input to the parser is scanned from left to right. One symbol at a time. And just as efficient
  • 9. The role of parser interm repres errors lexical analyzer parser rest of front end symbol table source program parse tree token get next token regular expressions also technically part or parsing includes augmenting info on tokens in source, type checking, semantic analysis uses a grammar to check structure of tokens produces a parse tree syntactic errors and recovery recognize correct syntax report errors
  • 10. Parsing Responsibilities Syntax Error Handling: a. Lexical: Misspellings b. Syntactic: Omission, wrong order of tokens c. Semantic: Incompatible types d. Logical: Infinite loop / recursive call
  • 12. Error-Recovery Strategies The simplest approach is for the parser to quit with an informative error message when it detects the first error. Panic-mode recovery. Phrase-level recovery. Error-productions. Global-correction.
  • 13. Panic-Mode Recovery This is used by most parsing methods. The synchronizing tokens are usually delimiters, such as ; or }. Skips a considerable amount of input without checking for additional errors It has the advantage of simplicity, and is guaranteed not to go into an infinite loop.
  • 14. Phrase-Level Recovery Perform local correction on the remaining input; A typical local correction is to replace a comma by asemicolon. Delete an extraneous semicolon. Insert a missing semicolon. Disadvantage in coping with situations in which the actual error has occurred before the point of detection.
  • 15. Error Productions Expand the grammar for the language at hand with productions that generatethe erroneous constructs.
  • 16. Global Correction Compiler to make as few changes as possible in processing an incorrect input string. Given an incorrect input string x and grammar G, algorithms will find a parse tree for a related string y, such that the number of insertions, deletions, and changes of tokens required to transform x into y is as small as possible. Not implemented.

Editor's Notes

  • #7: Top-down parser: Top-down parsing expands a parse tree from the start symbol to the leaves Always expand the leftmost non-terminal Bottom-up parser: Start at the leaves and grow toward root And just as efficient Builds on ideas in top-down parsing Preferred method in practice Also called LR parsing L means that tokens are read left to right R means that it constructs a rightmost derivation -->
  • #11: Majority of error processing occurs during syntax analysis NOTE: Not all errors are identifiable !! Which ones?