Language Processing System Interview Questions and Answers: Trace Source to Execution

Trace two C files from preprocessing to execution, then explain why compilation can succeed while linking fails. Practise short answers using the same example.

KnowledgeGate Team

Exam prep & CS education

Updated 12 Nov 20266 min read
Language Processing System Interview Questions and Answers: Trace Source to Execution

You can define a compiler, but can you explain why valid C source still fails to build? Language processing system interview questions become easier when you follow the files through each stage. The two-file trace and model answers focus on build-stage reasoning that interviewers can probe, without assuming a fixed question list. Keep the broader Compiler Design notes alongside this example for revision.

The earlier Language Processing System in Compiler Design post owns the complete stage-by-stage concept map; this post uses a two-file C build to rehearse interview explanations, link failures and short answers.

What is a language processing system, and where does the compiler fit?

A language processing system is the wider collection of tools that prepares, translates and combines a program, then supports its execution. In a conventional C toolchain, the compiler proper is one part of that system.

Component

Input → output or result

Preprocessor

C source → preprocessed C

Compiler proper

Preprocessed C → target-specific assembly

Assembler

Assembly → relocatable object file

Linker

Objects and required libraries → executable

Loader and runtime startup

Executable → program loaded and execution started in a process

An object file can contain machine code and still have unresolved external references. It is an intermediate build product, so its existence does not prove that an executable can be produced.

Separate these toolchain stages from the compiler's internal lexical analysis, syntax analysis, semantic analysis, intermediate-code generation, optimisation and code generation. The six internal compiler phases explain that inner translation work. Loading belongs to execution preparation, outside GCC's four build stages.

Can you trace a two-file C program through every build stage?

Two C files pass through preprocessing, compilation, assembly, linking, loading, and exit status 15.

Save these two files in the same directory:

c
/* main.c */
#define BASE 10
int add(int, int);
int main(void) {
    return add(BASE, 5);
}
c
/* add.c */
int add(int a, int b) {
    return a + b;
}

The declaration in main.c supplies the function's return and parameter types. The definition in add.c supplies its body. There is no printing function: main returns a value used as the process exit status.

According to GCC's manual, Options Controlling the Kind of Output, the build order is preprocessing, compilation proper, assembly and linking. -E stops after preprocessing, -S before assembly, and -c before linking. Here, .i holds preprocessed C, .s assembly and .o object code; -o names each output.

Run these commands in a POSIX shell:

sh
gcc -E main.c -o main.i
gcc -S main.i -o main.s
gcc -c main.s -o main.o
gcc -c add.c -o add.o
gcc main.o add.o -o demo
./demo
echo $?

Preprocessing replaces BASE, making the call add(10, 5). It leaves the function call intact. The compiler proper checks the declaration and translates the preprocessed source into target-specific assembly; assembly then produces main.o.

The fourth command takes add.c through preprocessing, compilation and assembly. Conceptually, main.o references add, while add.o defines it. The GCC driver links both objects and supplies platform startup components and required libraries. These commands expose stage boundaries; implementations can combine work internally.

Loading and runtime startup ultimately invoke main. Its call gives a = 10 and b = 5, so a + b = 10 + 5 = 15. The result returns through main, producing exit status 15 in this shell. The final echo $? displays 15; the C program itself prints nothing.

Flow diagram of main.c and add.c through preprocessing, compilation, assembly, linking with startup components, loading, and exit status 15.

Why does compilation succeed but linking fail?

Question: What happens if you run gcc main.o -o demo without add.o?

Answer: This ordinary native link fails because main.o references add, but no supplied input defines it. The declaration allowed type checking during compilation. It did not supply an implementation. Diagnostic wording varies by toolchain, but the missing definition is the underlying problem.

Repair it with gcc main.o add.o -o demo. Adding another declaration cannot replace the missing function body.

This is also the purpose of separate compilation. If only the body in add.c changes and its interface remains compatible, rebuild add.o and relink. The unchanged main.o can be reused.

Follow-up: Does the linker simply concatenate files?

No. It combines sections, resolves symbols and applies relocations, adjusting references for the resulting layout. With dynamic linking, some resolution and relocation work remains for the dynamic linker. That does not remove the distinction between declaring a function and providing its definition.

Which stage should you inspect when a program fails?

Try each change independently, restoring the original before the next case.

Change

Stage or outcome

Smallest repair

Add #include "missing_local_header.h" when no such header is available

Preprocessing cannot find the requested file

Supply the intended header or correct the include

Remove the semicolon after return add(BASE, 5)

Compilation reports invalid syntax

Restore the semicolon

Omit add.o from the link command

Linking cannot resolve add

Include add.o

Replace return a + b; with return a - b;

Build succeeds, but the result is wrong

Restore addition

For the last case, the arguments remain 10 and 5. Subtraction computes 10 - 5 = 5, so the program returns 5 instead of the intended 15. Successful translation proves neither that the chosen operation is correct nor that the program meets its requirements.

Use this reasoning pattern aloud: name the stage, identify the missing or invalid artefact, then propose the smallest repair.

How do compilation, interpretation and JIT execution differ?

Compilation translates a representation. Interpretation executes operations from a representation. Just-in-time (JIT) compilation translates selected code during execution. One implementation can combine these mechanisms.

Consider a hypothetical virtual machine that compiles the source expression 10 + 5 into:

Code
PUSH 10
PUSH 5
ADD
RETURN

Its interpreter first pushes 10, giving stack [10]. It pushes 5, giving [10, 5]. ADD removes both operands and pushes their sum, leaving [15]; RETURN returns 15. A JIT could translate this bytecode into native instructions while preserving the result.

This invented instruction set is neither JVM bytecode nor GCC output. Its purpose is to separate translation from execution. “Interpreted” does not mean every implementation reads source one line at a time, and the labels alone do not establish speed. For more detail, read about compiled, interpreted and JIT execution.

How can an interview or written test probe the same concept?

These are practice questions, not employer reports or past-paper questions.

  • Put preprocessing, linking, compilation and assembly in order. Preprocessing, compilation proper, assembly, linking.

  • Which GCC flag stops before assembly? -S. By contrast, -c still permits assembly but stops before linking.

  • Why is an object file not necessarily runnable? It may still need external definitions, relocation, executable layout and startup support.

  • Is the loader another internal compiler phase? No. Its role is to prepare the executable for execution in a process.

Build each spoken response in two levels: give the definition first, then defend it with the example. For instance, explain that main.o contains a reference to add, and add.o supplies the definition needed by the link. This makes your answer concrete without turning it into a memorised list of tool names.

What should you say in a 30-second answer, and practise next?

“The language processing system preprocesses source, compiles it, assembles object files, links them and prepares execution through loading and startup. A declaration permits type checking; a definition supplies the implementation. Our example returns 15 after both objects are linked.”

Now reproduce the build, omit add.o, explain the failure aloud and restore it. For structured study beyond this trace, the Compiler Design course is an optional next step.