Programming Languages: High-Level vs. Low-Level
A compiler translates an entire program from high-level source code to machine language in one complete pass, then saves the result to an executable file for later execution.
From Human-Friendly Code to CPU Instructions
When programmers write code in a high-level language, they use instructions designed to be practical for humans to write and read. A compiler translates an entire program from high-level source code into machine language in one complete pass. It then saves the translated result in an executable file that can be run later.
The key change is the level of representation. The source file contains high-level statements, while the compiled output contains low-level byte sequences intended for direct CPU execution. The compiler performs the translation before the program is executed.
A Complete Compilation Pass
- 1Write the program in a text editor and save it as a source file.
- 2Run the compiler on that source file.
- 3The compiler reads the entire file and checks it for errors.
- 4The compiler translates every statement into machine instructions.
- 5The compiler outputs a new file containing machine language.
Compiling a C Program
Imagine that you have written a program in C and want to run it.
- 1Write
You create the C source code in a text editor and save it as a file.
- 2Submit
You provide the source file to a compiler.
- 3Check
The compiler reads the entire file and checks it for errors.
- 4Translate
The compiler translates every statement into machine instructions.
- 5Save
The compiler creates a new executable file containing the translated machine language.
The resulting file can be executed later by the operating system.
What an Executable Contains
After compilation, the output file contains machine language. Machine language is made of low-level byte sequences designed for CPU execution rather than human interpretation. It can represent the translated form of high-level constructs such as loops, conditionals, and function calls.
If you open an executable file in a text editor, you may see strange symbols, control characters, and unreadable text. This is not necessarily corruption. The file is being viewed as text even though its contents are machine language intended for the CPU.
| Operating system | How an executable is identified | What the file contains |
|---|---|---|
| Windows | .exe or .dll suffixes | Machine language |
| Linux | File permissions | Machine language |
| macOS | File permissions | Machine language |
The identifying convention differs, but the executable content is machine language.
Compiler Workflow and Interpreter Workflow
A compiler receives the complete source program, translates it, and saves the result before execution. An interpreter instead reads a program and interprets its statements while the program runs. The source describes Python as an interpreted language in this sense.
| Compiler workflow | Interpreter workflow |
|---|---|
| The entire source file is submitted to the compiler. | The interpreter reads and interprets Python statements while the program runs. |
| Machine language is saved in an executable file. | The program is interpreted during execution. |
| A compilation error must be fixed before execution. | A runtime error can occur after execution has started. |
These workflows describe when translation occurs and when errors can appear.
The Compiled Program Behind Python
The Python interpreter is itself a compiled program written in C. Python developers used a C compiler to compile that interpreter. When you type python in a terminal or click the Python application, you launch this compiled C program. That program then reads and interprets Python code.
This creates two different translation stages. First, the Python interpreter is created by compiling C source code. Later, when you run Python, that already-compiled interpreter reads and interprets your Python program. Calling Python interpreted does not mean that every part of the Python system was created without compilation.
Mistakes Beginners Make
Common mistake Assuming that an executable must always end in .exe.
What it looks likeA learner sees a runnable file without a suffix on Linux or macOS and concludes that it cannot be executable.
Why it failsWindows uses .exe or .dll suffixes, but Linux and macOS use file permissions instead of suffixes to mark files as runnable.
Do this insteadCheck the operating system's convention. The absence of a suffix does not by itself mean that a file is not executable.
Common mistake Expecting machine language to be readable like source code.
What it looks likeA learner opens an executable in a text editor and treats the strange symbols as evidence that the file is damaged.
Why it failsMachine language consists of low-level byte sequences designed for CPU execution, not human interpretation.
Do this insteadUnderstand that unreadable characters are expected when machine-language data is displayed as text.
Common mistake Thinking that Python has no compiled component.
What it looks likeA learner assumes that because Python code is interpreted, the Python program used to run it must also be written in Python.
Why it failsThe Python interpreter is a compiled program written in C.
Do this insteadSeparate the compiled C interpreter from the Python code that the interpreter reads and interprets.
Common mistake Treating compilation errors and runtime errors as the same failure.
What it looks likeA learner expects a compiled program to begin running even though its source failed to translate.
Why it failsA compilation error occurs before successful translation, while a runtime error occurs after an interpreted program has started running.
Do this insteadFirst ask whether the failure happened during compilation or during execution.
Check Your Understanding
Explain the complete path from a C source file to a running program. Include the role of the compiler, the machine-language output, and the executable file.
Hints
- Start with the source file in a text editor.
- State that the compiler reads the entire file, checks for errors, and translates every statement.
- End with the operating system running the saved executable file.
A learner says, "Python is interpreted, so the Python interpreter cannot be compiled." Explain why this statement is incorrect.
Hints
- Distinguish the Python interpreter from the Python program.
- Identify the language in which the interpreter is written.
- Describe what happens when the interpreter is launched.
Compare how Windows identifies an executable file with how Linux and macOS identify one. Then explain whether this difference changes the machine-language content of the executable.
Hints
- Recall the Windows suffixes.
- Recall the Linux and macOS use of file permissions.
- Separate file identification from file contents.
Key Takeaways
- 1A compiler translates an entire high-level program into machine language in one complete pass.
- 2The compiler saves the machine-language result in an executable file for later execution.
- 3Windows commonly identifies executable files with .exe or .dll suffixes, while Linux and macOS use file permissions.
- 4Machine language is made of low-level byte sequences intended for CPU execution and is not designed to be read by humans.
- 5The Python interpreter is a compiled program written in C that reads and interprets Python code.
At a glance
- A compiler processes the entire source program, checks it, translates it into machine language, and saves the result in an executable file.
- Executable identification differs by operating system: Windows commonly uses .exe or .dll suffixes, while Linux and macOS use file permissions.
- Machine language is intended for CPU execution, so it appears unreadable when opened as text.
- The Python interpreter is itself a compiled C program that interprets Python code.
- Compilation happens before execution, while interpretation occurs as the interpreter runs the program.