Homework1-sol - COP 5555 Programming Language Principles...

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

View Full Document Right Arrow Icon
COP 5555 Programming Language Principles Homework 1 1. Problem 1 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-line. 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 characters of the program. So if an illegal character is found, the scanner will be the first 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
Background image of page 1

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

View Full DocumentRight Arrow Icon
Image of page 2
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 5

Homework1-sol - COP 5555 Programming Language Principles...

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

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