
In computing, language primitives are the simplest elements available in a
programming language
A programming language is a system of notation for writing computer programs.
Programming languages are described in terms of their Syntax (programming languages), syntax (form) and semantics (computer science), semantics (meaning), usually def ...
. A primitive is the smallest 'unit of processing' available to a programmer of a given machine, or can be an
atomic element of an
expression in a language.
Primitives are units with a meaning, i.e., a
semantic
Semantics is the study of linguistic Meaning (philosophy), meaning. It examines what meaning is, how words get their meaning, and how the meaning of a complex expression depends on its parts. Part of this process involves the distinction betwee ...
value in the language. Thus they are different from
tokens in a
parser
Parsing, syntax analysis, or syntactic analysis is a process of analyzing a string of symbols, either in natural language, computer languages or data structures, conforming to the rules of a formal grammar by breaking it into parts. The term '' ...
, which are the minimal elements of
syntax
In linguistics, syntax ( ) is the study of how words and morphemes combine to form larger units such as phrases and sentences. Central concerns of syntax include word order, grammatical relations, hierarchical sentence structure (constituenc ...
.
Types of primitives
Machine-level primitives
A
machine instruction, usually generated by an
assembler program, is often considered the smallest unit of processing although this is not always the case. It typically performs what is perceived to be one operation such as copying a
byte
The byte is a unit of digital information that most commonly consists of eight bits. Historically, the byte was the number of bits used to encode a single character of text in a computer and for this reason it is the smallest addressable un ...
or
string of bytes from one
computer memory
Computer memory stores information, such as data and programs, for immediate use in the computer. The term ''memory'' is often synonymous with the terms ''RAM,'' ''main memory,'' or ''primary storage.'' Archaic synonyms for main memory include ...
location to another or adding one
processor register
A processor register is a quickly accessible location available to a computer's processor. Registers usually consist of a small amount of fast storage, although some registers have specific hardware functions, and may be read-only or write-onl ...
to another.
Microcode primitives
Many of today's
computer
A computer is a machine that can be Computer programming, programmed to automatically Execution (computing), carry out sequences of arithmetic or logical operations (''computation''). Modern digital electronic computers can perform generic set ...
s, however, actually embody an even lower unit of processing known as
microcode
In processor design, microcode serves as an intermediary layer situated between the central processing unit (CPU) hardware and the programmer-visible instruction set architecture of a computer. It consists of a set of hardware-level instructions ...
which interprets the ''machine code'' and it is then that the microcode instructions would be the ''genuine'' primitives. These instructions would typically be available for modification only by the
hardware vendor's programmers.
High-level language primitives
A
high-level programming language
A high-level programming language is a programming language with strong Abstraction (computer science), abstraction from the details of the computer. In contrast to low-level programming languages, it may use natural language ''elements'', be ea ...
(HLL) program is composed of discrete
statements and
primitive data types that may also be ''perceived'' to perform a single operation or represent a single data item, but at a higher semantic level than those provided by the machine. Copying a data item from one location to another may actually involve many
machine instructions that, for instance,
* calculate the address of both
operand
In mathematics, an operand is the object of a mathematical operation, i.e., it is the object or quantity that is operated on.
Unknown operands in equalities of expressions can be found by equation solving.
Example
The following arithmetic expres ...
s in
memory
Memory is the faculty of the mind by which data or information is encoded, stored, and retrieved when needed. It is the retention of information over time for the purpose of influencing future action. If past events could not be remembe ...
, based on their positions within a
data structure
In computer science, a data structure is a data organization and storage format that is usually chosen for Efficiency, efficient Data access, access to data. More precisely, a data structure is a collection of data values, the relationships amo ...
,
* convert from one
data type
In computer science and computer programming, a data type (or simply type) is a collection or grouping of data values, usually specified by a set of possible values, a set of allowed operations on these values, and/or a representation of these ...
to another
before finally
* performing the final store operation to the target destination.
Some HLL statements, particularly those involving
loops, can generate thousands or even millions of primitives in a
low-level programming language
A low-level programming language is a programming language that provides little or no Abstraction (computer science), abstraction from a computer's instruction set architecture, memory or underlying physical hardware; commands or functions in the ...
(LLL), which comprise the genuine
instruction path length
In computer performance, the instruction path length is the number of machine code instructions required to execute a section of a computer program. The total path length for the entire program could be deemed a measure of the algorithm's perfor ...
the processor has to execute at the lowest level. This perception has been referred to as the ''abstraction penalty''.
Interpreted language primitives
An
interpreted language
In computer science, an interpreter is a computer program that directly executes instructions written in a programming or scripting language, without requiring them previously to have been compiled into a machine language program. An inter ...
statement has similarities to the HLL primitives, but with a further added ''layer''. Before the statement can be executed in a manner very similar to an HLL statement: it must first be processed by an
interpreter, a process that may involve many primitives in the target machine language.
Fourth and fifth-generation language primitives
Fourth-generation programming language
A fourth-generation programming language (4GL) is a high-level programming language, high-level computer programming language that belongs to a class of languages envisioned as an advancement upon third-generation programming languages (3GL). Each ...
s (4GL) and
fifth-generation programming languages (5GL) do not have a simple one-to-many correspondence from high-to-low level primitives. There are some elements of interpreted language primitives embodied in 4GL and 5GL specifications, but the approach to the original problem is less a
procedural language
Procedural programming is a programming paradigm, classified as imperative programming, that involves implementing the behavior of a computer program as procedures (a.k.a. functions, subroutines) that call each other. The resulting program is a ...
construct and are more oriented toward
problem solving
Problem solving is the process of achieving a goal by overcoming obstacles, a frequent part of most activities. Problems in need of solutions range from simple personal tasks (e.g. how to turn on an appliance) to complex issues in business an ...
and
systems engineering
Systems engineering is an interdisciplinary field of engineering and engineering management that focuses on how to design, integrate, and manage complex systems over their Enterprise life cycle, life cycles. At its core, systems engineering uti ...
.
See also
*
*
References
{{Reflist
Programming language topics