Translators – compiler, interpreter and assembler
Computer ScienceAlgorithms & Problem SolvingAges 15–16
Loading…
Sign in to playThe same short program is translated by a compiler, which checks the whole program, lists every syntax error and builds an executable, and by an interpreter, which translates and runs one statement at a time and stops at the first error. A low-level version of the program goes through a two-pass assembler that turns mnemonics into binary machine code. Insert a syntax, run-time or logic error and see when each one is found, then compare the time for repeated runs. An IDE tab shows syntax highlighting, error diagnostics, auto-complete, breakpoints and a variable watch.
Lesson: Programming languages and translators: high-level and low-level languages, compilers, interpreters, assemblers and IDEs
What it shows
A processor can only run machine code, so programs written in other languages must be translated. A compiler translates the whole source code in advance through lexical analysis, syntax analysis, code generation and optimisation, and produces an executable that runs fast without the source code. An interpreter translates and runs one statement at a time, so it starts at once and stops at the first error, but it is slower and is needed every time. An assembler turns each assembly-language mnemonic into one machine-code instruction. Syntax errors break the rules of the language, run-time errors happen while the program runs, and logic errors give wrong results without any message.
How to use
In Translate and run, choose a Translator, a Program and an Inserted error, set the Input value, then press Compile, Interpret or Assemble and watch the stages, the source line being worked on and the Error diagnostics. After a successful compile or assembly press Run program, and press it again to compare runs in the time chart and the results table. In the IDE tab, click line numbers to set breakpoints, use Run / Continue and Step, and type in the auto-complete box.
Parameters you can change
- Starting tab Translate and run, IDE
- Translator Compiler, Interpreter, Assembler
- Program Fuel report (sequence), Sum of squares (loop)
- Inserted error No error, One syntax error, Two syntax errors, Logic error
- Input value typed by the user 0–20
Questions to explore
- With two syntax errors, why does the compiler list both while the interpreter only reports the first one?
- Why does a fuel value of 0 give an error with every translator, even though the code has no syntax error?
- After three runs of the loop program, why is the compiled version so much faster than the interpreted one?