lecture06

lecture06 - Announcements PA1 Error Handling...

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

View Full Document Right Arrow Icon
1 Prof. Aiken CS 143 Lecture 6 1 Error Handling Syntax-Directed Translation Recursive Descent Parsing Lecture 6 Prof. Aiken CS 143 Lecture 6 2 Announcements • PA1 – Due today at midnight – README, test case – Your name(s)! • WA1 – Due today at 5pm • PA2 – Assigned today • WA2 – Assigned Tuesday Prof. Aiken CS 143 Lecture 6 3 Outline • Extensions of CFG for parsing – Precedence declarations – Error handling – Semantic actions • Constructing a parse tree • Recursive descent Prof. Aiken 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 Prof. Aiken 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 Prof. Aiken 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 1

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

View Full DocumentRight Arrow Icon
2 Prof. Aiken 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 Prof. Aiken 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 ) Prof. Aiken 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 Prof. Aiken 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 Prof. Aiken 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
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 9

lecture06 - Announcements PA1 Error Handling...

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

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