> For the complete documentation index, see [llms.txt](https://vick7-education.gitbook.io/freshforfresh/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://vick7-education.gitbook.io/freshforfresh/programming/compiler.md).

# Compiler

1 compiler là 1 computer program thực hiện việc chuyển 1 Source từ 2-level-lang (HLL) sang machine language - Low-level-lang (LLL) mà vẫn giữ nguyên ý nghĩa của source.

<figure><img src="https://buggyprogrammer.com/wp-content/uploads/2021/04/Compiler.gif" alt=""><figcaption></figcaption></figure>

## Có nhiều loại compiler và dưới đây là vài ví dụ phổ biến

<details>

<summary><strong>Source-to-source compiler</strong></summary>

Quá trình compiler này sẽ dịch source code từ ngôn ngữ này sang 1 ngôn ngữ khác.\
Ví dụ: CoffeeScript và Haxe

</details>

<details>

<summary><strong>Cross compiler</strong></summary>

Trong compiler này, mã nguồn có thể viết ở 1 máy và thực thi ở 1 máy khác.\
Ví dụ: [GNU Compiler Collection (GCC)](https://en.wikipedia.org/wiki/GNU_Compiler_Collection) is a good example of a cross compiler.

</details>

<details>

<summary><strong>JIT (just in time) compiler</strong></summary>

Quá trình compiler diễn ra tại thời điểm runtime.

Nó được áp dụng trong các ngôn ngữ lập trình hiện đại như: Java, Python, Javascript...

</details>

<details>

<summary><strong>Hardware compiler</strong></summary>

Sử dụng phần cứng để tạo ra đầu ra thay vì 1 chuỗi instructions.

Ví dụ: [Xilinx Synthesis Tool (XST)](https://www.xilinx.com/products/design-tools/xst.html)

</details>

Cùng tìm hiểu các thêm về chủ đề này nhé

{% content-ref url="/pages/chvPVeFim47i08m34QT5" %}
[Tại sao phải cần compiler?](/freshforfresh/programming/compiler/tai-sao-phai-can-compiler.md)
{% endcontent-ref %}

{% content-ref url="/pages/w7toNoUOzGDwxjZDfbFD" %}
[Java Virtual Machine](/freshforfresh/programming/compiler/java-virtual-machine.md)
{% endcontent-ref %}
