This preview shows pages 1–2. Sign up to view the full content.
This preview has intentionally blurred sections. Sign up to view the full version.View Full Document
Unformatted text preview: COP 5555 Programming Language Principles Homework 1 - Solution 1 Problem 1 (25 points) Which compiler phase (e.g. scanner, parser, constrainer, code generator) would be responsible for catching each of the following errors, respectively? explain why. 1. An illegal character. 2. Premature end-of- le. 3. A undeclared variable. 4. An unknown library function. 5. Division by zero. Solution(5 points each): 1. The scanner. The scanner is the only phase of compilation that deals with the actual charac- ters of the program. So if an illegal character is found, the scanner will be the rst to discover it. 2. The parser. When the scanner discover an EOF, it has no way of knowing whether the EOF is premature or not. It would require the further knowledge of the syntax of the program, which is the responsibility of the parser. 3. The constrainer An undeclared variable is a semantic error, and should be handled by the con- strainer. 4. constrainer / link time Depends on the language implementation. If library functions are analyzed at compile time, then the constrainer (through the symbol table) would catch the error. Quite often, however, the errors is caught at link time, when externalerror....
View Full Document
- Fall '08