Lecture 2 Flashcards

1
Q

What are the phases of a compiler

A

It consists of the analysis and synthesis phases:

Analysis phase:
1. Lexical Analysis
2. Syntax Analysis
3. Semantic Analysis

Synthesis Analysis
1. Intermediate Code Generation
2. Code Optimization
3. Target Code Generation

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Tasks of lexical analysis

A
  1. Read input characters of the source program
  2. Group them into lexemes
  3. Produce as output a sequence of tokens for each output
  4. Stripping off comments and whitespaces
  5. Correlate error messages with line number in the source program
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Master the diagram of the lexical analysis

A
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What is the job of the syntax analyser

A

The parser uses the first components of the tokens produced by the lexical analyzer to create a tree-like intermediate representation that depicts the grammatical structure of the token stream.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What is the job of semantic analysis?

A
  1. The semantic analyzer uses the syntax tree and the information in the symbol table to check the source program for semantic consistency with the language definition.
  2. It also gathers type information and saves it in either the syntax tree or the symbol table, for subsequent use during intermediate-code generation.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

An example of intermediate representation

A

Syntax trees are a form of intermediate representation; they are commonly used during syntax and semantic analysis.

three-address code, which consists of a sequence of assembly-like instructions with three operands per instruction.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Mention the two properties of intermediate representation

A
  1. it should be easy to produce
  2. it should be easy to translate into the target machine.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What happens in the code optimization phase

A

The machine-independent code-optimization phase attempts to improve the intermediate code so that a better target code will result.

Usually better means faster, but other objectives may be desired, such as shorter code, or target code that consumes less power

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What is the job of the code generator

A

The code generator takes as input an intermediate representation of the source program and maps it into the target language.

If the target language is machine code, registers or memory locations are selected for each of the variables used by the program.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Describe the job of the analysis part of the compiler

A

If the analysis part detects that the source program is either syntactically ill formed or semantically unsound, then it must provide informative messages, so the user can take corrective action.

The analysis part also collects information about the source program and stores it in a data structure called a symbol table, which is passed along with the intermediate representation to the synthesis part.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

Describe the job of the synthesis part

A

The synthesis part constructs the desired target program from the intermediate representation and the information in the symbol table. It is commonly called the back end of the compiler

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

The front end is split into two parts

A

Scanner: Responsible for converting character stream to token stream
—Also strips out white space, comments

Parser: Reads token stream; generates Intermediate Representation

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

Give examples of token stream

A

Operators & Punctuation: {}[]!+-=*;: …
Keywords: if, while, return
Identifiers: id & actual name
Constants: int, floating-point character, string, …

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q
A
How well did you know this?
1
Not at all
2
3
4
5
Perfectly