본문바로가기

Technology

  • Technology
  • Compile
About Compile

Code compilation refers to the process of converting a program
written in a high-level language (source code), understandable by humans,
into a machine language program that a computer can execute.

이미지
Compile Concept

Computers only understand binary code consisting of 0s and 1s,
necessitating the compilation of source code into machine language.
This process enables the computer to execute the program.

  • Programmer

    High-level language
    : Source code languages that are easier
    for humans to understand

    C C++­Java, Source Code etc.
    아이콘 아이콘
  • Compiler

    Software that converts the high-level
    language into machine-readable language

    C, C++, Java 01
    아이콘 아이콘
  • Computer (CPU)

    Machine language
    : Language that machines can understand

    0 1
    아이콘 아이콘
Compilation Stages

Code compilation involves a compiler software and typically follows four stages

  • Step 01 Source Code Writing

    Writing the source code in a specific programming language

    Easy for humans to understand but not directly executable
    by a computer

    아이콘
  • Step 02 Compilation

    Compiler processes the
    written source code

    Analysis, checking for syntax errors, and translating into intermediate or machine code

    아이콘
  • Step 03 Linking

    Some programming languages require a linking process after compilation

    Source files combined into
    a single executable file
    (integrating modularized code
    and linking libraries)

    아이콘
  • Step 04 Execution

    Final compiled code

    Converted into machine
    language and executed
    by the computer's CPU

    아이콘
Detailed Compilation Process

The compiler analyzes and converts the source code,
creating an executable program through the steps listed below. The compiler detects errors at
each stage and performs optimization, enhancing the quality of the final executable code.

이미지
Source Program

Source code written by a programmer

Lexical Analysis

Breaking down the source code into a token stream

Removing spaces/comments and extracting identifiers,
operators, constants, etc.

Syntax Analysis

Checking the structure and syntax (grammar) of the source code

Converting the token stream into a parse tree or an abstract syntax tree (AST)

Generating error messages if grammatical errors are found

Semantic Analysis

Checking the meaning and intent of the code

Verifying variable definitions and uses, data type consistency, and function calls

Identifying code logic errors or integrity issues and reporting relevant errors

Symbol Table Management

Storing information defined in the source code such as variables, functions, constants, and data types; creating and managing tables to track and manage these identifiers

Error Handling

Processing and reporting errors that may occur during semantic analysis

Identifying errors for debugging and correction

Code Optimization

Optimizing code performance

Applying techniques such as removing duplicate code, constant folding, and eliminating unnecessary operations

Enhancing code execution speed and optimizing memory usage

Code Generation

Creating the final executable code

Compiler generates the target code based on the intermediate code or AST

Tailoring to specific hardware architecture or operating systems

Object Program

The final output that is executable, such as program files or libraries