ERROR HANDLING Lecture on 27/08/2013 PPT: 11CS10037 SAHIL ARORA.

Slides:



Advertisements
Similar presentations
Error Handling A compiler should: detect errors locate errors recover from errors Errors may occur in any of the three main analysis phases of compiling:
Advertisements

Joey Paquet, 2000, 2002, 2008, Lecture 7 Bottom-Up Parsing II.
1 Error detection in LR parsing Errors are discovered when a slot in the action table is blank. Canonical LR(1) parsers detect and report the error as.
Lecture # 7 Chapter 4: Syntax Analysis. What is the job of Syntax Analysis? Syntax Analysis is also called Parsing or Hierarchical Analysis. A Parser.
Syntax Analysis Mooly Sagiv html:// Textbook:Modern Compiler Implementation in C Chapter 3.
ISBN Chapter 4 Lexical and Syntax Analysis The Parsing Problem Recursive-Descent Parsing.
Environments and Evaluation
Syntax Analysis Mooly Sagiv html:// Textbook:Modern Compiler Design Chapter 2.2 (Partial) Hashlama 11:00-14:00.
Compiler Constreuction 1 Chapter 4 Syntax Analysis Topics to cover: Context-Free Grammars: Concepts and Notation Writing and rewriting a grammar Syntax.
Syntax Analysis Mooly Sagiv Textbook:Modern Compiler Design Chapter 2.2 (Partial)
9/27/2006Prof. Hilfinger, Lecture 141 Parsing Odds and Ends Lecture 14 (P. N. Hilfinger, plus slides adapted from R. Bodik)
CSC3315 (Spring 2009)1 CSC 3315 Lexical and Syntax Analysis Hamid Harroud School of Science and Engineering, Akhawayn University
UNIT 3 TEMPLATE AND EXCEPTION HANDLING. Introduction  Program errors are also referred to as program bugs.  A C program may have one or more of four.
1 October 2, October 2, 2015October 2, 2015October 2, 2015 Azusa, CA Sheldon X. Liang Ph. D. Computer Science at Azusa Pacific University Azusa.
Chapter 10: Compilers and Language Translation Invitation to Computer Science, Java Version, Third Edition.
Chapter 4 Syntax Analysis. Syntax Error Handling Example: 1. program prmax(input,output) 2. var 3. x,y:integer; 4. function max(i:integer, j:integer)
Lexical Analysis Hira Waseem Lecture
Profs. Necula CS 164 Lecture Top-Down Parsing ICOM 4036 Lecture 5.
Lesson 3 CDT301 – Compiler Theory, Spring 2011 Teacher: Linus Källberg.
D. M. Akbar Hussain: Department of Software & Media Technology 1 Compiler is tool: which translate notations from one system to another, usually from source.
SYNTAX ANALYSIS & ERROR RECOVERY By: Sarthak Swaroop.
Interpretation Environments and Evaluation. CS 354 Spring Translation Stages Lexical analysis (scanning) Parsing –Recognizing –Building parse tree.
Review 1.Lexical Analysis 2.Syntax Analysis 3.Semantic Analysis 4.Code Generation 5.Code Optimization.
Lesson 5 CDT301 – Compiler Theory, Spring 2011 Teacher: Linus Källberg.
Errors “Computer says no..”. Types of Errors Many different types of errors new ones are being invented every day by industrious programming students..
Chapter 4. Syntax Analysis (1). 2 Application of a production  A  in a derivation step  i   i+1.
Joey Paquet, 2000, Lecture 5 Error Recovery Techniques in Top-Down Predictive Syntactic Analysis.
1 Problems with Top Down Parsing  Left Recursion in CFG May Cause Parser to Loop Forever.  Indeed:  In the production A  A  we write the program procedure.
UNIT - 2 -Compiled by: Namratha Nayak | Website for Students | VTU - Notes - Question Papers.
1 Compiler Construction (CS-636) Muhammad Bilal Bashir UIIT, Rawalpindi.
The Functions and Purposes of Translators Syntax (& Semantic) Analysis.
Chapter 4 Top-Down Parsing Recursive-Descent Gang S. Liu College of Computer Science & Technology Harbin Engineering University.
Recursive Descent Parsers Lecture 6 Mon, Feb 2, 2004.
Chapter 1 Introduction Major Data Structures in Compiler
Overview of Previous Lesson(s) Over View  Syntax-directed translation is done by attaching rules or program fragments to productions in a grammar. 
Overview of Previous Lesson(s) Over View  In our compiler model, the parser obtains a string of tokens from the lexical analyzer & verifies that the.
What am I? while b != 0 if a > b a := a − b else b := b − a return a AST == Abstract Syntax Tree.
1 Compiler Construction (CS-636) Muhammad Bilal Bashir UIIT, Rawalpindi.
CS 330 Programming Languages 09 / 25 / 2007 Instructor: Michael Eckmann.
Parser: CFG, BNF Backus-Naur Form is notational variant of Context Free Grammar. Invented to specify syntax of ALGOL in late 1950’s Uses ::= to indicate.
1 Topic #4: Syntactic Analysis (Parsing) CSC 338 – Compiler Design and implementation Dr. Mohamed Ben Othman ( )
Chapter 2 (part) + Chapter 4: Syntax Analysis S. M. Farhad 1.
Joey Paquet, 2000, 2002, 2008, 2012, Lecture 5 Error Recovery Techniques in Top-Down Predictive Syntactic Analysis.
CS 404Ahmed Ezzat 1 CS 404 Introduction to Compiler Design Lecture Ahmed Ezzat.
Syntax Analysis Or Parsing. A.K.A. Syntax Analysis –Recognize sentences in a language. –Discover the structure of a document/program. –Construct (implicitly.
Concordia University Department of Computer Science and Software Engineering Click to edit Master title style COMPILER DESIGN Error recovery in top-down.
Parsing COMP 3002 School of Computer Science. 2 The Structure of a Compiler syntactic analyzer code generator program text interm. rep. machine code tokenizer.
Error recovery in predictive parsing An error is detected during the predictive parsing when the terminal on top of the stack does not match the next input.
Syntax error handling –Errors can occur at many levels lexical: unknown operator syntactic: unbalanced parentheses semantic: variable never declared runtime:
Semantic analysis Jakub Yaghob
LESSON 16.
Unit-3 Bottom-Up-Parsing.
Textbook:Modern Compiler Design
Introduction to Top Down Parser
Chapter 4 Syntax Analysis.
Syntax Analysis Chapter 4.
Shift Reduce Parsing Unit -3
Syntax Analysis Sections :.
Subject Name:COMPILER DESIGN Subject Code:10CS63
Lecture 15 (Notes by P. N. Hilfinger and R. Bodik)
Detecting and Resolving Model Errors
Top-Down Parsing The parse tree is created top to bottom.
Chapter 4 Top Down Parser.
Ambiguity in Grammar, Error Recovery
Compiler design Error recovery in top-down predictive parsing
Bottom-Up Parsing “Shift-Reduce” Parsing
Computing Follow(A) : All Non-Terminals
Chapter 10: Compilers and Language Translation
Compilers Principles, Techniques, & Tools Taught by Jing Zhang
Predictive Parsing Program
Presentation transcript:

ERROR HANDLING Lecture on 27/08/2013 PPT: 11CS10037 SAHIL ARORA

Syntax Error Handling Next few lectures will focus on the nature of syntactic errors and general strategies for error-recovery. If a compiler had to process only correct programs, its design would be extremely simple. However it is expected to Assist the programmer in locating and tracking errors. One should note that a programming language does not specify how a compiler should respond to errors. It is actually left entirely to the compiler designer. 2

Review: Common Programming Errors Semantic Errors: Type mismatches between operators and operands. Like, a return statements with return type void. Syntactic Errors: Misplaced semicolons, extra or missing braces. Lexical errors: Misspellings of keywords, identifiers, and operators. Logical Errors : Incorrect reasoning or plain carelessness might result in errors like interchangeably using = and == operators.

Challenges of Error Handling Viable-Fixable property: detecting an error as soon as a prefix of the input cannot be completed to form a string of the language. Goals of an Error Handler: Reporting presence of errors, clearly and accurately. Recovering from errors quickly enough to detect subsequent errors. Add minimal overhead to the processing of correct programs.

Error recovery There is no universally acceptable method. The simplest method is for the parser to quit with the appropriate error message, at the first instance of an error. Problem? Subsequent errors will not be detected. Solution? If the parser can restore itself to a state where processing can continue, future errors can be detected. In some cases compiler stops if errors pileup.

Error Recovery Strategies Panic Mode Recovery: The parser discovers an error. It then discards input symbols till a designated set of synchronizing token is found. Synchronizing tokens selected are such that their role in the program is unambiguous, like Delimiters ; } etc. Advantage? Simple and never goes into an infinite loop. Drawback: Skips considerable amount of input when checking for additional errors How long will a tree walk take? Prove that inorder walk prints in monotonically increasing order

Phrase-level Recovery Local Correction by parser on remaining input, by some string which allows parser to continue. Replacing comma by semicolon, inserting extra semicolon etc. Drawbacks: Improper replacement might lead to infinite loops. More importantly, if the error has occurred before the point of detection. Advantage: It can correct any input string.

Error Productions A method of anticipating common errors that might be encountered. Augmenting the grammar for the language at hand, with productions that generate erroneous constructs. Such a parser will detect anticipated errors when an error production is used. Advantage: Error diagnostics will be readily available for such anticipated errors.

Global Corrections Ideally minimum changes should be made to the input string. Given an input string x, algorithm finds parse tree for a related string y, such that number of insertions, deletions, and token changes required for converting x to y is minimum. Drawback: Too costly to implement in terms of both time and space, and only theoretical. It is however used as a yardstick for evaluating error-recovery techniques.