Operating Systems · UGC NET: System Software
Language Processors and Translators
Overview
Language processors are system programs that translate a program from one form to another or execute it directly.
This lesson covers preprocessors, compilers, interpreters, assemblers, macroprocessors, linkers, loaders and debuggers, together with the standard source-to-executable pipeline.
UGC NET asks direct definitions, tool identification, phase outputs, linker/loader functions, relocation, assembler directives, macro expansion, cross compilers and bootstrapping.
Before this topic, know basic computer organisation, machine instructions, addressing modes and the idea of high-level versus assembly versus machine language.
Key concepts
- A language processor is system software that accepts a source program and produces a target form or executes it.
A translator converts source to target; a compiler, assembler and source-to-source translator are translators. An interpreter executes source without producing a separate object file. - A compiler reads a complete high-level program and translates it into machine code or an intermediate representation. It reports errors after analysis and usually produces an object module.
Its major phases are lexical analysis, syntax analysis, semantic analysis, intermediate code generation, optimisation and code generation; the symbol table and error handler are used throughout. - A cross compiler runs on one machine, called the host, and produces code for a different machine, called the target. Example: a compiler running on an x86-64 laptop that emits ARM code is a cross compiler.
It is useful when a new machine has no native compiler yet. - An interpreter reads and executes a source program line by line or statement by statement. It does not create a permanent object file, generally executes more slowly than compiled code, and gives immediate diagnostics at the point of execution.
- An assembler translates an assembly-language program into relocatable machine code. It translates mnemonics, symbolic labels, literals and assembler directives.
It is hardware-dependent, because opcodes, registers and addressing modes belong to a particular instruction set. - An assembly program contains imperative statements (actual machine instructions), declarative statements (data definitions and storage reservation) and assembler directives/pseudo-instructions (commands to the assembler, not executable machine instructions).
Common directives include EQU, ORIGIN/ORG, START, END, DS and DC. - A single ordinary assembly instruction statement normally corresponds to one machine-code instruction. A macro call, however, can expand into many instructions; a directive does not become an executable instruction.
- A macroprocessor is software that performs systematic text substitution. A macro is a named block of source statements with parameters. A macro call is replaced by the macro body with arguments substituted.
This is inline expansion, unlike a subroutine call. - A linker or linkage editor combines several object modules into one load module/executable. It resolves external symbolic references and assigns linked addresses.
It may relocate code if the linked origin differs from the translated origin. - A loader transfers the executable image from disk to main memory.
Loader functions are allocation, linking, relocation and loading. An absolute loader simply loads at fixed addresses and itself does no allocation, linking or relocation. - Relocation means assigning load addresses and adjusting addresses in code/data to match. If the actual address differs from the assumed address, relocation is required.
The linker handles the difference between translated origin and linked origin; the loader handles the difference between linked origin and load origin. - A debugger is an interactive tool: it allows breakpoints, single-stepping, executing a chosen segment, and examining or modifying registers and memory. It is not a translator.
- Bootstrapping is developing a compiler for language L using an existing compiler, often a compiler for L on another machine or a compiler for a simpler subset.
A cross compiler can first generate a compiler for the new machine from the host. - A source-to-source translator translates a program in one high-level language into another high-level language, or into a different dialect of the same language.
- In lexical analysis, a lexeme is the actual character sequence matched, and a token is its classified name.
The scanner uses regular expressions and finite automata, often a DFA, and follows longest match/maximal munch; identifiers are stored in the symbol table. - In parsing, a handle is a substring that matches the right side of a production in the current sentential form; a reduction replaces that handle by the nonterminal on the left side of the production.
- A peephole optimiser is a local optimiser that examines a small sliding window of instructions and replaces inefficient sequences by shorter or faster equivalents. It is not a global optimiser.
- Front end of a compiler = lexical, syntax, semantic analysis and often intermediate code generation;
it is largely machine-independent.
Back end = optimisation and final code generation;
it is target-machine-dependent. - Two-pass compiler: pass 1 performs analysis/front-end work such as scanning, syntax checking, semantic checking and symbol-table construction; pass 2 performs synthesis such as code generation and optimisation.
A pass is a complete reading of the source or intermediate form, not the same as a phase. - Object code is the machine-level or relocatable form produced by a compiler or assembler. The linker consumes object modules; the loader consumes a load module.
How it works
The standard build-and-run pipeline is:
- The preprocessor performs textual work before compilation: include files, macro substitution, conditional compilation and line control. It does not perform full type checking.
- The compiler processes the preprocessed source through lexical, syntax, semantic, intermediate-code, optimisation and code-generation phases. A symbol table records identifiers and attributes.
- The assembler translates assembly code to relocatable object code. In a two-pass assembler, pass 1 scans labels and builds the symbol table; pass 2 generates object code and resolves forward references.
- The linker combines object modules, resolves external references and creates a load module. Static linking copies library code into the executable at link time.
Dynamic linking postpones resolution of shared library routines until load time or run time. - The loader allocates memory, relocates if necessary and loads the executable into main memory for execution.
- A debugger controls execution after loading: breakpoints, stepping and inspection of registers/memory.
Assembler translation uses tables: the mnemonic table maps mnemonic to opcode and format; the symbol table stores labels and addresses; the forward reference table records symbols used before their definition, often as a linked list; the literal table stores constants; the segment register table may be an array.
The EQU directive defines a symbol equal to an expression or constant.
Linker relocation and loader relocation use origins.
Let the translated origin be the address assumed by the translator, the linked origin be the address assigned by the linker, and the load origin be the actual memory address.
If linked origin differs from translated origin, the linker adjusts addresses. If load origin differs from linked origin, the loader adjusts addresses.
Drawing the diagram…
Formulas
-
For relocation, use the convention: = translated origin assumed by translator, = linked origin assigned by linker, = actual load origin.
-
Linker relocation constant: .
-
Loader relocation constant: .
-
If an address was written as relative to the linked origin, its loaded address is .
-
If an offset from the translated origin is used, then linked address and loaded address .
-
For phase-time questions:
-
Total compiler time , the sum of times of all phases actually performed.
-
Front-end time .
-
Back-end time .
-
For lexical scanning:
-
Characters consumed by tokens , where is the number of tokens and is their average length.
-
Remaining characters total characters characters consumed by tokens, used for spaces, comments and other separators.
Worked examples
Example 1: Cross compiler identification.
A compiler installed on a host machine with x86-64 Linux generates executable code for an ARM target. The host is x86-64 Linux; the target is ARM. Since host and target are different, the tool is a cross compiler. If the compiler ran on ARM and generated ARM code, it would be a native compiler.
Example 2: Preprocessor macro substitution.
Consider:
#define SQR(x) x*x
int r = SQR(2+3);
The preprocessor substitutes text directly. So SQR(2+3) becomes:
2+3*2+3
By operator precedence, multiplication is done first:
.
If the macro is written safely as #define SQR(x) ((x)*(x)), then SQR(2+3) becomes ((2+3)*(2+3)) = 25. This shows that a macroprocessor works by textual substitution, not by normal function-call parameter passing.
Example 3: Match-the-list style.
Match compiler phases with typical outputs:
Lexical analysis → stream of tokens; syntax analysis → parse tree; semantic analysis → type-checked or annotated tree; intermediate code generation → three-address code or other IR; code generation → target assembly/machine instructions.
The key distinction is that syntax analysis checks grammar and builds a parse tree, while semantic analysis checks meaning such as type compatibility, declarations and scope.
Example 4: Two-step relocation.
A program is translated assuming origin . An address in the object code is stored as offset from the translated origin. The linker assigns linked origin , and the program is actually loaded at .
- Linked address .
- Loader relocation constant .
- Actual loaded address .
The linker had to relocate because ; the loader had to relocate because .
Example 5: Statement type.
Statement I: “The symbol table is created only during semantic analysis.” False. Entries begin to be made during lexical analysis and the table is maintained and used across all phases.
Statement II: “An interpreter executes a source program line by line.” True. It does not necessarily produce a separate object file.
Thus only Statement II is true.
Comparison
| Point | Compiler | Interpreter |
|---|---|---|
| Input | Whole high-level program | Source program |
| Output | Target/object code | Direct execution, no permanent object file |
| Execution speed | Faster after compilation | Usually slower because source is interpreted |
| Error reporting | After analysis, often lists several errors | At the current line/statement; immediate |
| Portability of output | Target-specific object code | Interpreter itself must exist on machine |
| Tool | Main input | Main output or action |
|---|---|---|
| Preprocessor | Source text | Expanded source text |
| Compiler | High-level source | Assembly, object code or IR |
| Assembler | Assembly language | Relocatable machine code/object module |
| Macroprocessor | Source with macro definitions/calls | Expanded source without macro calls |
| Linker | Object modules | Load module/executable |
| Loader | Load module | Program in main memory |
| Debugger | Running/loaded program | Control and inspection |
| Directive/statement | Meaning |
|---|---|
| Imperative statement | Actual machine instruction expressed in mnemonic form |
| Declarative statement | Reserves/stores data, constants or storage |
| EQU | Defines a symbol equal to a value or expression |
| ORIGIN/ORG | Sets the location counter |
| START | Specifies the starting address or beginning |
| END | Marks end of source module |
| Static linking | Dynamic linking |
|---|---|
| Library code copied into executable at link time | Shared library resolved at load time or run time |
| Larger executable/disk use | Smaller executable, shared library in memory |
| Updates require relinking | Library update can be used without relinking |
| Usually less run-time resolution overhead | May add first-call or startup overhead |
| Linker | Loader |
|---|---|
| Combines object modules | Brings load module into memory |
| Resolves external references | Performs allocation, relocation and loading |
| Produces load module | Produces running process image |
| May relocate translated-to-linked origin | May relocate linked-to-load origin |
| Macro | Subroutine |
|---|---|
| Expanded inline at each call | Single body called by control transfer |
| No return address/stack frame for macro itself | Uses call/return and stack conventions |
| Increases code size if called many times | Saves space but has call overhead |
| Arguments substituted textually | Arguments passed by language rules |
Revision summary
- Host = machine where tool runs;
target = machine for which output is produced.
Different host and target → cross compiler. - Compiler phases: lexical → syntax → semantic → intermediate code → optimisation → code generation.
- Symbol table and error handler work throughout the compiler, not in one phase only.
- Lexical analysis produces tokens from lexemes; syntax analysis builds a parse tree; semantic analysis checks meaning.
- Assembler is hardware-dependent; assembler directives are not executable machine instructions.
- Single ordinary assembly instruction ≈ one machine instruction; a macro call may expand to many.
- Linker creates load module and resolves external references; loader loads and may relocate.
- If linked origin ≠ translated origin, linker relocation is needed; if load origin ≠ linked origin, loader relocation is needed.
- Absolute loader itself does no allocation, linking or relocation; these are fixed earlier.
- Dynamic linking saves disk/memory and eases updates, but it does not necessarily reduce execution time.
- Bootstrapping uses an existing or simpler compiler to build a compiler for the same or a new language/machine.
- Preprocessor macros are textual; missing parentheses in a macro can change the result.
Previous-year exam insights
- Direct definition questions ask you to identify cross compiler, compiler, interpreter, assembler, linker, loader, macroprocessor, debugger, spooler-like system tools.
- The build pipeline is tested by asking which tool transfers the executable from disk to memory, which creates a load module, and which produces object code.
- Linker/loader questions test the exact origin comparison: translated vs linked vs load, and whether linker or loader relocates.
- Assembler questions test statement types, directives such as EQU/ORIGIN/START/END, mnemonic and forward-reference tables, and hardware dependence.
- Macroprocessor questions test that it performs expansion and argument substitution and can be integrated with an assembler or built as an independent one-pass/two-pass processor.
- Compiler-phase questions test first-pass analysis, parse-tree construction, semantic checks, front-end/back-end division and symbol-table lifetime.
- Statement I/II and assertion-reason questions often contain one false absolute word: “only”, “always”, “must”, “no need”. Check whether the statement is conditional.
- Match-the-list questions mix tools with outputs and phases with activities; first fix the unique item, then eliminate.
Practice at PARIKSHA
You are ready for the PARIKSHA tests of this sub-topic when you can:
- Identify compiler, interpreter, assembler, linker, loader, macroprocessor, preprocessor, debugger and cross compiler from a one-line description.
- Explain the difference between host and target and classify a compiler as native or cross.
- List compiler phases in order and state the input/output of each phase.
- Explain why the symbol table is not created only in semantic analysis.
- Distinguish imperative statements, declarative statements and assembler directives with examples.
- Explain macro expansion, argument substitution and the parenthesisation trap in
#define. - Decide whether linker relocation or loader relocation is needed from translated, linked and load origins.
- Compare static and dynamic linking, including at least three benefits and one cost of dynamic linking.
- Describe the functions of a linker and a loader and identify what an absolute loader does not do.
- Explain bootstrapping, cross-compiler use for a new machine, and source-to-source translation.
Attempt the sub-topic test first, then the subject test on PARIKSHA.