Compiler
Компилятор
A program that translates source code into another form, such as machine instructions, bytecode, or a different programming language. It also reports certain errors it can detect without running the code.
What a compiler does
A compiler turns code written for people into code in a target language or format, while preserving the behavior defined by the source language. That target might be instructions for a CPU, bytecode for a virtual machine, or source code for another tool to run or process. For example, javac produces JVM bytecode, while the TypeScript compiler can emit JavaScript. Neither output is itself a native executable.
What happens inside
The front end recognizes tokens such as names, numbers, and operators, then parses them to work out how they fit together. For example, it recognizes a + b * c as an addition whose right-hand operand is a multiplication. It also resolves names and performs checks required by the language, such as whether a function call supplies an argument of the right type.
Many compilers then lower the program to an intermediate representation (IR), an internal form that makes the code easier to analyze and transform. An optimization pass might replace 2 + 3 with 5 rather than leave an addition to do at runtime. The back end turns the result into code for the target. For a native target, this can include choosing CPU instructions and deciding which values to keep in registers.
Example: compiling is not linking
cc -c main.c -o main.o
cc main.o -o app
The first command creates an object file and stops before linking. That file can contain machine instructions and references to functions defined elsewhere. The second command uses the compiler driver, cc, to invoke the linker and produce an executable. If main.c calls a declared function whose definition isn't available to the linker, the first command can succeed and the second can fail with an undefined-symbol error.
Where compilers fit at runtime
Ahead-of-time (AOT) compilation happens before execution. Just-in-time (JIT) compilation happens while the program is running. A JVM can start by interpreting bytecode and later compile frequently executed methods to native code. Translation and interpretation are different jobs, but a single runtime can do both. Calling a language “compiled” or “interpreted” is often shorthand for how a particular implementation runs it.
What interviewers look for
Be ready to say which tool detects a problem and when. An undeclared identifier is typically caught by the compiler in C; a missing definition for a referenced function can show up at link time; a calculation that uses the wrong formula can build and run without a diagnostic. A successful build tells you that the build tools accepted the program, not that it meets its requirements.