lecture06 - Error Handling Syntax-Directed Translation...

Info iconThis preview shows pages 1–13. Sign up to view the full content.

View Full Document Right Arrow Icon
CS 143 Lecture 6 1 Error Handling Syntax-Directed Translation Recursive Descent Parsing Lecture 6
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
CS 143 Lecture 6 2 Announcements PA1 (called PA2) Due tomorrow at midnight README, test case Your name(s)! WA1 Due Wednesday in class
Background image of page 2
CS 143 Lecture 6 3 Outline Extensions of CFG for parsing Precedence declarations Error handling Semantic actions Constructing a parse tree Recursive descent
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
CS 143 Lecture 6 4 Error Handling Purpose of the compiler is To detect non-valid programs To translate the valid ones Many kinds of possible errors (e.g. in C) Error kind Example Detected by … Lexical … $ … Lexer Syntax … x *% … Parser Semantic … int x; y = x(3); … Type checker Correctness your favorite program Tester/User
Background image of page 4
CS 143 Lecture 6 5 Syntax Error Handling Error handler should Report errors accurately and clearly Recover from an error quickly Not slow down compilation of valid code Good error handling is not easy to achieve
Background image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
CS 143 Lecture 6 6 Approaches to Syntax Error Recovery From simple to complex Panic mode Error productions Automatic local or global correction Not all are supported by all parser generators
Background image of page 6
CS 143 Lecture 6 7 Error Recovery: Panic Mode Simplest, most popular method When an error is detected: Discard tokens until one with a clear role is found Continue from there Such tokens are called synchronizing tokens Typically the statement or expression terminators
Background image of page 7

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
CS 143 Lecture 6 8 Syntax Error Recovery: Panic Mode (Cont.) Consider the erroneous expression (1 + + 2) + 3 Panic-mode recovery: Skip ahead to next integer and then continue Bison: use the special terminal error to describe how much input to skip E int | E + E | ( E ) | error int | ( error )
Background image of page 8
CS 143 Lecture 6 9 Syntax Error Recovery: Error Productions Idea: specify in the grammar known common mistakes Essentially promotes common errors to alternative syntax Example: Write 5 x instead of 5 * x Add the production E … | E E Disadvantage Complicates the grammar
Background image of page 9

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
CS 143 Lecture 6 10 Error Recovery: Local and Global Correction Idea: find a correct “nearby” program Try token insertions and deletions Exhaustive search Disadvantages: Hard to implement Slows down parsing of correct programs “Nearby” is not necessarily “the intended” program Not all tools support it
Background image of page 10
CS 143 Lecture 6 11 Syntax Error Recovery: Past and Present Past Slow recompilation cycle (even once a day) Find as many errors in one cycle as possible Researchers could not let go of the topic Present Quick recompilation cycle Users tend to correct one error/cycle Complex error recovery is less compelling Panic-mode seems enough
Background image of page 11

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
CS 143 Lecture 6 12 Abstract Syntax Trees So far a parser traces the derivation of a sequence of tokens The rest of the compiler needs a structural representation of
Background image of page 12
Image of page 13
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 05/05/2010 for the course COMPILER AC 1 taught by Professor Sergio during the Spring '10 term at Institute of Management Technology.

Page1 / 48

lecture06 - Error Handling Syntax-Directed Translation...

This preview shows document pages 1 - 13. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online