lecture 1 Flashcards
(11 cards)
What are the major compiler phases?
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.
What is the difference between the analysis and synthesis phases?
Analysis phase: Converts source code into an internal representation.
Synthesis phase: Converts the internal representation into target code.
Why do we use intermediate code?
It allows for:
Easier optimization.
Reuse of the front-end for multiple target platforms.
Reuse of the back-end for multiple source languages.
What is the advantage of separating the front and back ends?
Promotes modularity and reuse:
Front-end (e.g., parsing, semantics): source language-specific.
Back-end (e.g., code generation): target machine-specific.
What is a lexeme?
A sequence of characters in the source code that matches the pattern for a token.
What is a token?
A symbolic representation of a lexeme, possibly with attributes (e.g., ID(“x”)).
What is a parse tree?
A tree that represents the entire grammar structure of the input source code, including all syntactic rules and tokens.
What is an abstract syntax tree (AST)?
A simplified version of the parse tree:
Removes unnecessary grammar rules and tokens.
Focuses only on the meaningful structure of the code.
What is intermediate code?
Independent of source and target language.
What is the difference between assembly code, object code, and executable code?
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.
What is bytecode, an interpreter
Bytecode: Platform-independent low-level code (e.g., Java bytecode).
Interpreter: Executes code directly without compiling to machine code.