SYNTAX ANALYSIS & ERROR RECOVERY By: Sarthak Swaroop.

Slides:



Advertisements
Similar presentations
Topics Introduction Types of Errors Exceptions Exception Handling
Advertisements

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:
Translator Architecture Code Generator ParserTokenizer string of characters (source code) string of tokens abstract program string of integers (object.
Lecture # 7 Chapter 4: Syntax Analysis. What is the job of Syntax Analysis? Syntax Analysis is also called Parsing or Hierarchical Analysis. A Parser.
1 Pass Compiler 1. 1.Introduction 1.1 Types of compilers 2.Stages of 1 Pass Compiler 2.1 Lexical analysis 2.2. syntactical analyzer 2.3. Code generation.
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.
CS 330 Programming Languages 09 / 23 / 2008 Instructor: Michael Eckmann.
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)
CSC3315 (Spring 2009)1 CSC 3315 Lexical and Syntax Analysis Hamid Harroud School of Science and Engineering, Akhawayn University
ERROR HANDLING Lecture on 27/08/2013 PPT: 11CS10037 SAHIL ARORA.
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.
CSC 338: Compiler design and implementation
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.
Joey Paquet, Lecture 12 Review. Joey Paquet, Course Review Compiler architecture –Lexical analysis, syntactic analysis, semantic.
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.
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 Bottom-Up Parsing  “Shift-Reduce” Parsing  Reduce a string to the start symbol of the grammar.  At every step a particular substring is matched (in.
CPS 506 Comparative Programming Languages Syntax Specification.
The Functions and Purposes of Translators Syntax (& Semantic) Analysis.
Recursive Descent Parsers Lecture 6 Mon, Feb 2, 2004.
Muhammad Idrees, Lecturer University of Lahore 1 Top-Down Parsing Top down parsing can be viewed as an attempt to find a leftmost derivation for an input.
INTRODUCTION TO COMPILERS(cond….) Prepared By: Mayank Varshney(04CS3019)
Compiler Construction By: Muhammad Nadeem Edited By: M. Bilal Qureshi.
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.
CSE 425: Syntax I Syntax and Semantics Syntax gives the structure of statements in a language –Allowed ordering, nesting, repetition, omission of symbols.
Syntax Analyzer (Parser)
C H A P T E R T W O Linking Syntax And Semantics Programming Languages – Principles and Paradigms by Allen Tucker, Robert Noonan.
1 Structure of a Compiler Source Language Target Language Semantic Analyzer Syntax Analyzer Lexical Analyzer Front End Code Optimizer Target Code Generator.
COMP 3438 – Part II-Lecture 5 Syntax Analysis II Dr. Zili Shao Department of Computing The Hong Kong Polytechnic Univ.
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 ( )
Joey Paquet, 2000, 2002, 2008, 2012, Lecture 5 Error Recovery Techniques in Top-Down Predictive Syntactic Analysis.
Overview of Compilation Prepared by Manuel E. Bermúdez, Ph.D. Associate Professor University of Florida Programming Language Principles Lecture 2.
Compiler Construction Lecture Five: Parsing - Part Two CSC 2103: Compiler Construction Lecture Five: Parsing - Part Two Joyce Nakatumba-Nabende 1.
Syntax Analysis Or Parsing. A.K.A. Syntax Analysis –Recognize sentences in a language. –Discover the structure of a document/program. –Construct (implicitly.
Syntax Analysis By Noor Dhia Syntax analysis:- Syntax analysis or parsing is the most important phase of a compiler. The syntax analyzer considers.
CS 2130 Lecture 18 Bottom-Up Parsing or Shift-Reduce Parsing Warning: The precedence table given for the Wff grammar is in error.
Concordia University Department of Computer Science and Software Engineering Click to edit Master title style COMPILER DESIGN Error recovery in top-down.
Semantic analysis Jakub Yaghob
LESSON 16.
Lexical and Syntax Analysis
CS510 Compiler Lecture 4.
Parsing and Parser Parsing methods: top-down & bottom-up
Unit-3 Bottom-Up-Parsing.
Textbook:Modern Compiler Design
Chapter 4 Syntax Analysis.
Syntax Analysis Chapter 4.
Stack application: postponing data usage
Shift Reduce Parsing Unit -3
Syntax Analysis Sections :.
Compiler Design 4. Language Grammars
Detecting and Resolving Model Errors
Compiler design Error recovery in top-down predictive parsing
LL and Recursive-Descent Parsing Hal Perkins Autumn 2011
Bottom-Up Parsing “Shift-Reduce” Parsing
High-Level Programming Language
Compilers Principles, Techniques, & Tools Taught by Jing Zhang
Predictive Parsing Program
Parsing CSCI 432 Computer Science Theory
Presentation transcript:

SYNTAX ANALYSIS & ERROR RECOVERY By: Sarthak Swaroop

SYNTAX ANALYSIS The main features of syntax analysis, which is done by parser, are as follows:  Checks the Grammar  Parse Tree Production  Output Errors

Types of Error There are mainly four types of error. They are as follows: There are mainly four types of error. They are as follows:  Lexical Error : Such as misspelling an identifier, keyword or operator.  Syntactic Error : Such as an arithmetic expression with unbalanced parentheses.  Semantic Error : Such as operator applied to an incompatible operand.  Logical Error : Such as infinitely recursive call.

ERROR HANDLING TECHNIQUES

1. Panic Mode In case of an error like: In case of an error like: a=b + c // no semi-colon a=b + c // no semi-colon d=e + f ; d=e + f ; The compiler will discard all subsequent tokens till a semi-colon is encountered. The compiler will discard all subsequent tokens till a semi-colon is encountered.  This is a crude method but often turns out to be the best method.

 This method often skips a considerable amount of input without checking it for additional errors, it has an advantage of simplicity  In situations where multiple errors in the same statements are rare, this method may be quite adequate.

2. Phrase Level Recovery  On discovering an error, a parser may perform local correction on the remaining input; that is, it may replace a prefix of the remaining input by some string that allows the parser to continue.  For example, in case of an error like the one above, it will report the error, generate the “;” and continue.

3. Error Production If we have an idea of common errors that might occur, we can include the errors in the grammar at hand. For example if we have a production rule like: If we have an idea of common errors that might occur, we can include the errors in the grammar at hand. For example if we have a production rule like: E  +E | -E | *E | /E E  +E | -E | *E | /E Then, a=+b; Then, a=+b; a=-b; a=-b; a=*b; a=*b; a=/b; a=/b;

Here, the last two are error situations. Here, the last two are error situations. Now, we change the grammar as: Now, we change the grammar as: E  +E | -E | *A | /A E  +E | -E | *A | /A A  E A  E Hence, once it encounters *A, it sends an error Hence, once it encounters *A, it sends an error message asking the user if he is sure he wants message asking the user if he is sure he wants to use a unary “*”. to use a unary “*”.

4. Global Correction  We would like compiler to make as few changes as possible in processing an incorrect input string.  There are algorithms for choosing a minimal amount of changes to obtain a globally least-cost correction. Suppose we have a line like this: THIS IS A OCMPERIL SCALS. THIS IS A OCMPERIL SCALS.

 To correct this, there is an attractor, which checks how different tokens are from the initial inputs, checks the closest attractor to the incorrect token is.  This is more of a probabilistic type of error correction. Unfortunately, these methods are in general too costly to implement in terms of space and time.