Which of the following is a programming language that translates code one line at a time?

Computers only understand machine code (binary), this is an issue because programmers prefer to use a variety of high and low-level programming languages instead.

To get around the issue, the high-level and low-level program code (source code) needs to pass through a translator.

A translator will convert the source code into machine code (object code).

There are several types of translator programs, each able to perform different tasks.

Compiler

Which of the following is a programming language that translates code one line at a time?

Compilers are used to translate a program written in a high-level language into machine code (object code).

Once compiled (all in one go), the translated program file can then be directly used by the computer and is independently executable.

Compiling may take some time but the translated program can be used again and again without the need for recompilation.

An error report is often produced after the full program has been translated.  Errors in the program code may cause a computer to crash.  These errors can only be fixed by changing the original source code and compiling the program again.

If you need to learn more about high-level languages, visit our Languages page.

Interpreter

Which of the following is a programming language that translates code one line at a time?

Interpreter programs are able to read, translate and execute one statement at a time from a high-level language program.

The interpreter stops when a line of code is reached that contains an error.

Interpreters are often used during the development of a program.  They make debugging easier as each line of code is analysed and checked before execution.

Interpreted programs will launch immediately, but your program may run slower then a complied file.

No executable file is produced.  The program is interpreted again from scratch every time you launch it.

If you need to learn more about high-level languages, visit our Languages page.

Assembler

Assemblers are used to translate a program written in a low-level assembly language into a machine code (object code) file so it can be used and executed by the computer.

Once assembled, the program file can be used again and again without re-assembly.

If you need to learn more about low-level languages, visit our Languages page.

Summary of translators

CompilerInterpreterAssembler
Translates high-level languages into machine code Temporarily executes high-level languages, one statement at a time Translates low-level assembly code into machine code
An executable file of machine code is produced (object code) No executable file of machine code is produced (no object code) An executable file of machine code is produced (object code)
Compiled programs no longer need the compiler Interpreted programs cannot be used without the interpreter Assembled programs no longer need the assembler
Error report produced once entire program is compiled.  These errors may cause your program to crash Error message produced immediately (and program stops at that point) One low-level language statement is usually translated into one machine code instruction
Compiling may be slow, but the resulting program code will run quick (directly on the processor) Interpreted code is run through the interpreter (IDE), so it may be slow, e.g. to execute program loops
One high-level language statement may be several lines of machine code when compiled

What is a compiler?

A compiler is a special program that translates a programming language's source code into machine code, bytecode or another programming language. The source code is typically written in a high-level, human-readable language such as Java or C++. A programmer writes the source code in a code editor or an integrated development environment (IDE) that includes an editor, saving the source code to one or more text files. A compiler that supports the source programming language reads the files, analyzes the code, and translates it into a format suitable for the target platform.

Compilers that translate source code to machine code target specific operating systems and computer architectures. This type of output is sometimes referred to as object code (which is not related to object-oriented programming). The outputted machine code is made up entirely of binary bits -- 1s and 0s -- so it can be read and executed by the processors on the target computers. For example, a compiler might output machine code for the Linux x64 platform or Linux ARM 64-bit platform.

Some compilers can translate source code to bytecode instead machine code. Bytecode, which was first introduced in the Java programming language, is an intermediate language that can be executed on any system platform running a Java virtual machine (JVM) or bytecode interpreter. The JVM or interpreter converts the bytecode into instructions that can be executed by the hardware processor. A JVM also makes it possible for the bytecode to be recompiled by a just-in-time compiler. (See also: Java compiler)

Some compilers can translate source code into another high-level programming language, rather than machine code or bytecode. This type of compiler might be referred to as a transpiler, transcompiler, source-to-source translator or it might go by another name. For example, a developer might use a transpiler to convert COBOL to Java.

Regardless of the source language or the type of output, a compiler must ensure that the logic of the output code always matches that of the input code and that nothing is lost when converting the code. A compiler is, in the strictest sense, a translator and must ensure that the output is correct and preserves all the original logic.

How does a compiler work?

Compilers vary in the methods they use for analyzing and converting source code to output code. Despite their differences, they typically carry out the following steps:

  • Lexical analysis. The compiler splits the source code into lexemes, which are individual code fragments that represent specific patterns in the code. The lexemes are then tokenized in preparation for syntax and semantic analyses.
  • Syntax analysis. The compiler verifies that the code's syntax is correct, based on the rules for the source language. This process is also referred to as parsing. During this step, the compiler typically creates abstract syntax trees that represent the logical structures of specific code elements.
  • Semantic analysis. The compiler verifies the validity of the code's logic. This step goes beyond syntax analysis by validating the code's accuracy. For example, the semantic analysis might check whether variables have been assigned the right types or have been properly declared.
  • IR code generation. After the code passes through all three analysis phases, the compiler generates an intermediate representation (IR) of the source code. The IR code makes it easier to translate the source code into a different format. However, it must accurately represent the source code in every respect, without omitting any functionality.
  • Optimization. The compiler optimizes the IR code in preparation for the final code generation. The type and extent of optimization depends on the compiler. Some compilers let users configure the degree of optimization.
  • Output code generation. The compiler generates the final output code, using the optimized IR code.
Which of the following is a programming language that translates code one line at a time?
Diagram illustrating the order of typical compiler steps.

Compilers are sometimes confused with programs called interpreters. Although the two are similar, they differ in important ways. Compilers analyze and convert source code written in languages such as Java, C++, C# or Swift. They're commonly used to generate machine code or bytecode that can be executed by the target host system.

Interpreters do not generate IR code or save generated machine code. They process the code one statement at a time at runtime, without pre-converting the code or preparing it in advance for a particular platform. Interpreters are used for code written in scripting languages such as Perl, PHP, Ruby or Python.

See also: decompile, yet another compiler compiler, parser, software toolchain, native code, assembler

This was last updated in April 2022

Continue Reading About compiler

  • Interpreted vs. compiled languages: What's the difference?
  • The functional programming paradigm at enterprise scale
  • 5 dead programming languages we should never forget
  • Static vs. dynamic typing: The details and differences
  • A comparison of 6 top programming languages

What programming language translates code one line at a time?

The below table explains the major differences between the two:.

Which of the following translates one line at a time?

The correct answer is Interpreter. A computer program that translates one program's instructions at a time into machine language is called an Interpreter. An interpreter translates one instruction at a time and executes that instruction immediately.

Which type of programming language translates all lines of code?

A compiler translates all lines of code together and then executes them at once. This is more like translating an entire book into a different language. You wouldn't do just part of it - you would translate the whole thing and then release it all at once. Java is an example of a compiled language.

Which type of programming language translates and executes program code line by line into machine code?

Difference between Compiler and Interpreter –.