CHAPTER 1 Flashcards

1
Q

what is compiler?

A

is a program that converts source code written in a high-level programming language (e.g., Java, C++) into machine code that a computer can understand.

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

Difference Between Compilers and Interpreters

A

Compiler: Translates the whole program at once (e.g., C, Java).
Interpreter: Translates and executes line by line (e.g., Python).

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

what is JIT compiler?

A

A hybrid that compiles parts of code while the program runs (used in Java’s JVM).

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q
  1. What are the major compiler phases?
A

Lexical analysis (Scanning) – Converts source code into tokens.
Syntactic analysis (Parsing) – Checks syntax and constructs a parse tree.
Semantic analysis – Ensures meaningfulness, such as type checking.
Intermediate code generation – Converts the parsed code into an intermediate representation (IR).
Optimization – Improves performance without altering functionality.
Target code generation – Converts intermediate code into machine code.

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

What is the difference between the analysis and synthesis phases?

A

Analysis phase: Breaks down source code into structures (lexical analysis, parsing, and semantic analysis).
Synthesis phase: Converts the analyzed representation into executable code (intermediate code generation, optimization, and target code generation).

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

Why do we use intermediate code?

A

It is independent of both source and target machines.

Enables optimizations before generating machine code.

Allows multiple frontends (source languages) to work with multiple backends (target architectures).

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

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

A

The frontend (language-specific) and backend (machine-specific) separation makes the compiler modular.

A single frontend can support multiple target architectures.

Easier debugging and maintenance.

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

Lexeme

A

A sequence of characters forming a meaningful unit (e.g., while in while (x < y)).

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

Token

A

A symbolic representation of a lexeme, often with attributes (e.g., WHILE for while).

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

Parse tree

A

A tree representation of the syntactic structure of a program.

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

Abstract syntax tree (AST)

A

A simplified version of the parse tree, removing unnecessary syntax details.

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

Intermediate code

A

A low-level representation between source and machine code, often resembling assembly.

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

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

A

Assembly code: Human-readable low-level code generated from source code.

Object code: Machine code with unresolved references, produced after assembly.

Executable code: Fully linked machine code ready for execution.

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

What is bytecode, an interpreter, a virtual machine?

A

Bytecode: Platform-independent low-level code executed by a virtual machine.

Interpreter: Directly executes code without converting it to machine language beforehand.

Virtual machine (VM): Software that emulates a physical machine, executing bytecode.

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

What kind of errors can be caught by a compiler? A runtime system?

A

Compiler: Catches lexical, syntactic, and static-semantic errors (e.g., undeclared variables, type mismatches).
Runtime system: Catches runtime errors such as null pointer exceptions, division by zero, and stack overflows.

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

what is transpiler

A

A transpiler (or source-to-source translator) translates code from one high-level language to another.
Example: Transpiling Typescript source code to Javascript.

17
Q

Applications of compiler construction

A

Traditional compilers from source to assembly
* Source-to-source translators, transpilers, preprocessors
* Interpreters and virtual machines
* Integrated programming environments
* Program analysis tools
* Refactoring and other program transformation tools
* Domain-specific languages