COMPILER CONSTRUCTION EXAM
1 QUESTIONS AND ANSWERS
Name all of the phases of a compiler - ANSWER 1. lexical analysis
2. syntax analysis
3. semantic analysis
4. intermediate code generation
5. code optimization
6. code generation
Briefly describe lexical analysis - ANSWER Conversion of input from
lexemes to a stream of tokens
Briefly describe syntax analysis - ANSWER Makes sure the tokens
occur in a meaningful order (ensures syntactically correct program)
Briefly describe semantic analysis - ANSWER A check for meaning
among the "sentences" created by syntax analysis
Briefly describe intermediate code generation - ANSWER Creation of a
machine-independent representation of the source code
Briefly describe code optimization - ANSWER Removal of unnecessary
instructions in an attempt to increase speed or decrease program size
Briefly describe code generation - ANSWER Creation of a machine-
dependent translation from the intermediate code to the target language
Single Line vs Multiline Comment: Advantages and Disadvantages -
ANSWER Single line: easy for lex analyzer to process since its
presence tells the analyzer to ignore the rest of the line, but more difficult
to implement since it can easily be mistaken for an operation instead of
something to ignore
1 QUESTIONS AND ANSWERS
Name all of the phases of a compiler - ANSWER 1. lexical analysis
2. syntax analysis
3. semantic analysis
4. intermediate code generation
5. code optimization
6. code generation
Briefly describe lexical analysis - ANSWER Conversion of input from
lexemes to a stream of tokens
Briefly describe syntax analysis - ANSWER Makes sure the tokens
occur in a meaningful order (ensures syntactically correct program)
Briefly describe semantic analysis - ANSWER A check for meaning
among the "sentences" created by syntax analysis
Briefly describe intermediate code generation - ANSWER Creation of a
machine-independent representation of the source code
Briefly describe code optimization - ANSWER Removal of unnecessary
instructions in an attempt to increase speed or decrease program size
Briefly describe code generation - ANSWER Creation of a machine-
dependent translation from the intermediate code to the target language
Single Line vs Multiline Comment: Advantages and Disadvantages -
ANSWER Single line: easy for lex analyzer to process since its
presence tells the analyzer to ignore the rest of the line, but more difficult
to implement since it can easily be mistaken for an operation instead of
something to ignore