Instruction (programming)
An instruction or statement ( borrowed from English statement ) is a central element of many imperative programming languages in computer science in the field of programming . The programs of such languages are mainly composed of one or more instructions. An instruction represents a single regulation formulated in the syntax of a programming language, which is to be executed within the framework of the execution of the program. How an instruction has to look syntactically is determined by the respective programming language or its specification and cannot (usually) be changed within a program.
In machine-level programming, instructions are often referred to as command , instruction (from English instruction ) or command (from English command ).
Statements are usually assignments , control statements (such as jumps, loops and conditional statements) and procedure calls . Depending on the programming language, assurances , declarations , class and function definitions are sometimes statements.
Unlike expressions , statements don't always have value. However, some instructions can also be expressions, such as: B. Assignments, increment operators or function calls. Conversely, many types of expressions such as comparisons or arithmetic expressions are not syntactically complete statements.
Sequences of instructions are often grouped together in blocks.
Examples
Assembler instruction |
MOV AX,BX
|
Assertion |
assert(ptr != NULL);
|
Conditional statement |
if A > 3 then WRITELN(A) else WRITELN("NOT YET") end
|
block |
begin WRITE('Number? '); READLN(NUMBER); end
|
declaration |
VAR A:INTEGER;
|
Do-while loop |
do computation(&i); while (i < 10);
|
For loop |
for A:=1 to 10 do WRITELN(A) end;
|
GOTO statement |
goto 1;
|
initialization |
TYPE SALARY = INTEGER; or long i = 0;
|
Return statement |
return 5;
|
Switch case statement |
switch (c) { case 'a': alert(); break; case 'q': quit(); break; }
|
Subroutine call |
CLEARSCREEN();
|
While-do loop |
while NOT EOF DO begin READLN end;
|
allocation |
A := A + 1;
|
see also programming language elements
syntax
The appearance of a program is determined by the appearance of the instructions. Therefore, programming languages are often differentiated according to the nature of their instructions (e.g. languages with curly brackets). Many statements begin with an identifier such as if , while, or repeat . Often the instruction keywords are reserved so that they cannot be used as the name of a variable or function . Imperative programming languages usually use a special syntax for their instructions, which differs significantly from a function call. Common methods of describing the syntax of instructions are Backus-Naur-Form and Syntax Diagram .
semantics
Semantically, many instructions from subroutines differ in the way their parameters are handled . Usually an actual parameter is evaluated before the subroutine is called. This differs from the parameters of many statements, which are evaluated several times (e.g. the condition of a while loop ) or not at all (e.g. the body of a while loop). From a technical point of view, such instruction parameters are closures , which are executed when necessary (see also Lazy Evaluation ). If closure parameters are available for subroutines, the behavior of a statement can be implemented by subroutines (see Lisp ). For languages without a closure parameter, the semantic description of a loop or conditional statement goes beyond the capabilities of the language. That is why specifications often use semantic descriptions in natural language.
literature
- James Gosling , Bill Joy , Guy Steele, Gilad Bracha: The Java Language Specification, Third Edition . (PDF; 6.2 MB) Addison-Wesley, Upper Saddle River 2005, ISBN 0-321-24678-0
- 6. Expressions . The Python Language Reference.
Individual evidence
- ^ Statement - Duden , Bibliographisches Institut ; 2016
- ^ Command - Duden , Bibliographisches Institut ; 2016
- ↑ instruction ( Memento of the original from December 22, 2016 in the Internet Archive ) Info: The archive link was automatically inserted and not yet checked. Please check the original and archive link according to the instructions and then remove this notice. (English-German) - Duden , Langenscheidt ; 2015
- ↑ command ( Memento of the original from December 22, 2016 in the Internet Archive ) Info: The archive link was automatically inserted and not yet checked. Please check the original and archive link according to the instructions and then remove this notice. (English-German) - Duden , Langenscheidt ; 2015