Unit I - Introduction to Language Processing
As computers have become an essential part of human life, numerous
programming languages have evolved to help users communicate effectively with
machines. However, since humans and computers understand vastly different
forms of language, special software tools known as **language processors** are
needed to bridge the gap. This process of converting one form of language into
another that a computer can understand is known as **Language Processing**.
Language Translators
A **language translator** is a computer program that converts a program written in
one (source) language into an equivalent program in another (target) language.
The source language is typically a high-level language (like C, Java, or Python),
while the target language could be assembly, machine code, or another high-level
language.
Two main types of translators are:
1. Compiler
A **compiler** reads a complete source program and translates it into an
equivalent target program, usually in machine code. If the target program is
executable, it can then be run by the user to produce desired outputs. Compilers
also identify and report syntax or semantic errors in the source code.
Example: The C compiler translates `.c` files into machine code executables
(`.exe` or `.out` files).
2. Interpreter
An **interpreter** directly executes the source program without producing an
intermediate machine code file. It reads one instruction at a time, translates it, and
executes it immediately. This makes debugging easier but execution slower
compared to compiled code.
Example: Python and JavaScript use interpreters to execute source code line by
line.
Language Processing System
A **Language Processing System** consists of several components that together
convert a high-level language program into an executable machine-level program.
Depending on the tools involved, these components may include preprocessors,
compilers, assemblers, loaders, and linkers.
Main Components:
1. **Preprocessor:** Expands macros, includes header files, and prepares code for
compilation. *Example:* The C preprocessor handles directives like `#include` and
`#define`.
2. **Compiler:** Converts high-level language into assembly or machine code and
reports errors.
3. **Assembler:** Converts assembly language into machine code (binary
instructions).
4. **Loader/Linker:** Combines multiple object files, adjusts memory addresses,
and prepares the final executable.
Steps in a Typical Language Processing System
1. **Source Code (e.g., `program.c`)** 2. **Preprocessor →** Expands macros and
headers → produces modified source. 3. **Compiler →** Generates target
assembly code. 4. **Assembler →** Converts assembly to object code
(`[Link]`). 5. **Linker/Loader →** Links libraries and object files → produces
executable (`[Link]`).
Types of Compilers
1. **Traditional Compilers:** Convert high-level language (HLL) to native machine
code. *Example:* C, C++ compilers.
2. **Interpreters:** Convert and execute intermediate code step-by-step.
*Example:* LISP, Java (early versions), Python.
3. **Cross Compilers:** Run on one machine but generate code for another.
*Example:* Compiling embedded code for ARM processors on a desktop PC.
4. **Incremental Compilers:** Compile parts of a program step-by-step for faster
feedback during development.
5. **Converters:** Translate from one high-level language to another. *Example:*
COBOL to C++ converter.
6. **Just-In-Time (JIT) Compilers:** Used in environments like Java or .NET,
converting intermediate bytecode to machine code at runtime for improved
performance.
7. **Ahead-of-Time (AOT) Compilers:** Compile intermediate code to native code
before runtime to improve startup performance. *Example:* .NET NGen.
8. **Binary Compilers:** Translate object code from one platform to another.
Conclusion
Language processing is fundamental for converting human-understandable code
into machine-understandable instructions. From preprocessing and compiling to
linking and execution, each stage ensures that the final executable program runs
efficiently and accurately. Understanding this process helps programmers write
optimized, error-free, and portable software.