Compiler Construction VO Flashcards
What is the usual general flow
Source program → compilation (errors) → Target program
Classification
Single-pass, multi-pass, debugging or optimizing
Optimization - test
compile the program first, then with optimization
result should be the same
Concept of compilation - Phases
Splitting into two phases
1 ANALYSIS: split into tokens and then generate intemediate code (code from which you can extract information)
2 SYNTHESIS: close to the machine, uses the intermediate code to generate the target program
resuable: e.g. nalysis phase remains the same, can be reused
Analysis - overview
hierarchical structures (trees) storing syntactical information that comes from the source program used also for: structure editors, pretty printers, static checkers, web browser, interpreters, …
Analysis - flow
skeletal source program → preprocessor → source program → [compiler → target assembly language → assembler → relocatable machine code
after that (by the operating system):
relocatable machine code → loader/linker-editor → absolute machine code
components of a compiler
source code
lexical analyzer
syntax analyzer
semantic analyzer
intermediate code generator
code optimizer
code generator
target code
lexical analysis
sequence of characters are converted to tokens
Tokens:
identifier
assignment symbols
operators
…
Syntax analysis
grammatical analysis
based on rules of grammar
taking tokens (based on symbols)
generating parse tree where we see how the derivation of the grammar rules is done
Semantic analysis
check for semantic errors
type checking
example: conversion between types
intermediate code generation
representing the original program
usually done via three-address code (three is the maximum number of adresses)
using symbol table
Code Optimizer
Goal: faster machine code
e.g. combinig things together, …