How compilers & interpreters work (concept)
Computer Science · Computer architecture & systems
Question 1 of 10
0The front end of a compiler usually includes which phases?
Stuck? Read the explanation
Unlocks at a streak of 5 correct answers in a row.
Embed this practice on your site or class page
Paste this HTML into your page. Students practise right there; it is free and needs no account.
How compilers & interpreters work (concept) explained
A compiler translates a whole program written in a high-level language into machine code or another lower-level form before it runs. An interpreter translates and runs the program one statement at a time instead. Both turn code that people can read into instructions that a processor can carry out.
With a compiler, the translation happens once and produces a separate program that can be run again without the original source code. Errors that the compiler finds are reported before anything runs. With an interpreter, the program starts straight away and each statement is translated as it is reached. This makes testing quick, but the running program is often slower.
Some languages use both approaches. Java, for example, compiles source code to bytecode, which a virtual machine then runs. A common mistake is to say that a language is a compiled language or an interpreted language. Whether a program is compiled or interpreted depends on the tool used, so the same language can have both kinds of implementation.
Worked example
Imagine a program whose third line contains a syntax error, such as a missing bracket.
- A compiler reads the whole program first, reports the error, and produces no runnable program.
- A line-by-line interpreter may run the first two lines, printing their output, before it reaches the error.
- Some interpreters check the whole file before running any of it, so the exact behaviour depends on the tool being used.
What you will practise
102 multiple-choice questions (Easy, Medium, Hard). Each answer is followed by an explanation.
Example questions
- A compiler translates code:
- An interpreter runs code:
- Compiled programs are typically:
- Interpreters make development:
- Bytecode is:
- Lexical analysis, the first phase of a compiler, turns the source text into:
- Parsing checks a token stream against a grammar and builds a:
- The output of the code generation phase is usually:
…and 94 more.