Compiler
Table of Contents
1. Abstract
A compiler is a program that translates source code written in a high-level programming language into machine code or an intermediate code.
2. Functionalities
2.1. Main Functions
- Lexical Analysis
- Converts a sequence of characters into a sequence of tokens.
- Syntax Analysis (Parsing)
- Checks the source code for correct syntax and generates an abstract syntax tree (AST).
- Semantic Analysis
- Ensures the code adheres to semantic rules.
2.2. Ancillary functions
- Optimization
- Improves performance through code transformation while preserving functionality.
- Code Generation
- Produces machine code or intermediate code from the optimized AST.
- Code Linking (Sometimes)
- Combines various code modules into a single runnable program.
3. Types
- Single-pass Compiler
- Processes the input code in one pass.
- Multi-pass Compiler
- Processes the input code multiple times for better optimization and error checking.
- Just-In-Time (JIT) Compiler
- Compiles code at runtime, commonly used in managed runtime environments like Java and .NET.
- Cross Compiler
- Generates executable code for a platform different from the one on which the compiler is running.
4. Connections
- Interpreters
- Unlike compilers, interpreters execute high-level code without translating it to machine code. Offers flexibility with a trade-off in performance.
- Virtual Machines
- Some compilers generate intermediate code that runs on virtual machines, enabling platform independence (e.g., Java Bytecode for JVM).