lecture 1 Flashcards

(11 cards)

1
Q

What are the major compiler phases?

A

Lexical Analysis (Scanning) – breaks source code into tokens.

Syntactic Analysis (Parsing) – constructs a parse tree from tokens.

Semantic Analysis – checks for type errors, undeclared variables, etc.

Intermediate Code Generation – produces platform-independent code.

Optimization – improves code performance or size.

Target Code Generation – translates intermediate code into assembly/machine code.

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

What is the difference between the analysis and synthesis phases?

A

Analysis phase: Converts source code into an internal representation.

Synthesis phase: Converts the internal representation into target code.

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

Why do we use intermediate code?

A

It allows for:

Easier optimization.

Reuse of the front-end for multiple target platforms.

Reuse of the back-end for multiple source languages.

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

What is the advantage of separating the front and back ends?

A

Promotes modularity and reuse:

Front-end (e.g., parsing, semantics): source language-specific.

Back-end (e.g., code generation): target machine-specific.

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

What is a lexeme?

A

A sequence of characters in the source code that matches the pattern for a token.

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

What is a token?

A

A symbolic representation of a lexeme, possibly with attributes (e.g., ID(“x”)).

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

What is a parse tree?

A

A tree that represents the entire grammar structure of the input source code, including all syntactic rules and tokens.

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

What is an abstract syntax tree (AST)?

A

A simplified version of the parse tree:

Removes unnecessary grammar rules and tokens.

Focuses only on the meaningful structure of the code.

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

What is intermediate code?

A

Independent of source and target language.

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

What is the difference between assembly code, object code, and executable code?

A

Assembly code: Human-readable instructions for a specific CPU.

Object code: Machine-readable code, output by the assembler, with placeholders for addresses (not executable yet).

Executable code: Final code after linking, with all addresses resolved.

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

What is bytecode, an interpreter

A

Bytecode: Platform-independent low-level code (e.g., Java bytecode).

Interpreter: Executes code directly without compiling to machine code.

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