The meaning of constructs in a programming language, including their permitted values and execution behavior. Programming language syntax organizes constructs; a type system and execution rules give further constraints and meaning.
A program variable is a named binding or storage abstraction used to supply a value during execution of a computer program. Its precise meaning belongs to the programming language semantics: some languages describe mutable storage locations, while others emphasize names associated with values. The current semantic environment and program state determine what an occurrence denotes. A mathematical variable and a program variable consequently need not obey the same rules.
For example, in Python, executing x = 3 followed by x = x + 1 first evaluates the right-hand program expression using the old binding and then binds x to the resulting integer 4. This variable assignment is a change in the program state, not the equation .[ref]
Binding a second name does not necessarily copy the underlying data. After a = list() and b = a, executing b.append(7) changes the list also reached through a. By contrast, b = list() rebinds only b. Distinguishing changes to data from changes to names makes shared mutable structures easier to reason about.[ref]
A local variable is a variable whose binding belongs to a limited program region, such as a procedure invocation or block. The language's scope rules determine where its name denotes that binding. Its storage need not be a fixed physical location: a compiler can use processor registers or eliminate storage when permitted by the programming language semantics.
For example, a recursive procedure can have a separate local accumulator for each invocation, even though every invocation uses the same source-level name. A nested function may retain access to a binding through a programming closure. Scope and lifetime must consequently be distinguished. In Python, binding a name anywhere in a function block normally makes it local throughout that block unless a global or nonlocal declaration applies; using it before it has a value raises an error.[ref]
Undefined behavior is behavior for which a programming language specification imposes no requirements when a specified erroneous condition occurs. It is not a promise to select one arbitrary but otherwise constrained result. The C programming language uses this category for conditions including signed integer overflow.[ref]
For example, evaluating x+1 as signed int when x is the largest representable int has undefined behavior in that model. A compiler can therefore reason that x+1 exceeds x on executions where the addition is defined, instead of preserving an assumed wraparound case. Unsigned integer arithmetic in C has different rules. Observing a particular result in one build is insufficient to establish a contract; correctness needs range checks, suitable representations or another explicitly defined operation.
A mapping from identifiers to their semantic values. A programming closure retains its defining semantic environment; extending it for parameters preserves lexical scope and lets those parameters shadow outer bindings.
A representation of the rest of a computation. In continuation-passing style, a computation receives a function telling it how to use its result. An explicit computer memory argument can be supplied when the continuation is invoked, so capturing control need not capture a snapshot of computer memory.
A computation that can suspend and later resume. A first-class continuation can represent its suspended control state while mutable computer memory remains shared.
Tasks transfer control at explicit suspension points. A FIFO queue of runnable continuations implements round-robin scheduling; a task that never transfers control can prevent others from running.
A continuation represented as an ordinary language value that can be stored and later invoked. Whether it may be invoked once or repeatedly, and whether mutable program state is restored, are separate semantic choices.
Supply the current continuation to a user function. A language can expose this as an escape function or as a separate continuation value with its own invocation primitive; those interfaces need corresponding semantic definitions.
Pass the remaining computation explicitly as a continuation. Returning a value means invoking that continuation; a different control destination can be selected by invoking a different continuation.
A variable used within a procedure but declared outside it. Under lexical scope, its binding is determined by enclosing declarations and the associated runtime environment, often accessed through a static chain or programming closure.
Name resolution determined by the nesting of declarations in the source program. An activation of a nested procedure obtains its nonlocal variables from its defining environment, which can differ from the newest activation of the same enclosing procedure when procedural parameters are used.
A suspended computation together with the information needed to evaluate it later. In lazy evaluation by need, forcing a thunk computes and records its result, so subsequent demands can reuse it. Deferral and memoization are distinct: a merely delayed computation need not share its result unless its evaluation mechanism provides that sharing.
The convention relating a procedure's formal parameters to its arguments. Copying a large array at every recursive call can dominate running time, even when the procedure never modifies the argument.
Evaluate argument expressions before invoking a function. A monadic interpreter must also specify the order of those evaluations when its computational monad represents effects.
A parameter initialized from the actual argument's value. Whether passing an aggregate copies all elements or merely a reference is language-dependent; in whole-array copying semantics, a length- argument costs per call. This differs from a language that passes an object reference by value.
A reference parameter designates the caller's actual storage. Assigning through it can change what the caller subsequently observes; passing a complete independent copy would instead change only the local copy. A value parameter containing an object reference is another case: copying that reference does not copy the referenced software object.
In Oberon, a variable parameter is marked VAR and stands for the supplied actual variable. For example, a procedure accepting VAR x: INTEGER can increment the caller's integer through x.[ref]
A read-only algorithm can use a reference parameter to avoid copying a large array, while its formal specification still prohibits writes. Reference aliasing remains relevant: two parameters can designate overlapping storage. A proof of algorithm correctness must account for the actual aliasing rules rather than assume that different parameter names denote independent values.
Evaluation that skips a later operand once an earlier operand determines the result. In Scala, p != null && p.field == x does not dereference p when it is null, and i < n && a(i) != x avoids an out-of-range access at . The order is part of the safety argument: exchanging these operands can preserve a Boolean formula in mathematics while changing whether a program raises an exception.
Evaluation delayed until a result is demanded, with sharing of the delayed computation's result. A lazy list can expose a constructor before computing its tail; this permits productive infinite structures and lazy feedback streams. A non-strict language can implement its semantics this way without making every function non-strict.
Represent a cursor by an underlying consuming iterator plus an optional cached head. Without a cache, its abstract sequence is the iterator's sequence; with cached , it is concatenated with the remaining iterator sequence. current fetches and caches exactly one value when needed, repeated reads reuse it, and advance discards it. Availability testing need not fetch a value, and construction need not query the input. This avoids forcing a future stream element that the client may never request.
An undefined or nonterminating computation in the denotational account of Haskell. A structured value may contain bottom values while retaining a defined outer constructor: undefined : [] is distinguishable from an entirely undefined list.[ref]
A description of the information needed to determine a program's next permitted step. In the summation loop verification, this includes the current variable values and the position in the instructions.
An integer arithmetic result outside the range of its chosen representation. A programming language may specify wrapping, trapping or another behavior; a proof over mathematical integers must account for that difference.
Hoare logic proves properties of programs through Hoare triples . A precondition constrains initial states and a postcondition constrains returned states. The basic rules establish partial correctness; termination requires a further argument.[ref]
For a program expression whose evaluation is defined and has no side effects, the assignment rule is
The substitution replaces the free occurrences of in the desired postcondition. For example, obtaining after x := x+1 requires beforehand, so suffices. Integer overflow must be excluded or handled by the stated arithmetic model.
Sequential composition joins a first postcondition to the next precondition. For a while loop, proving establishes
Here is the loop invariant. For while x > 0 do x := x-1, starting with an exact nonnegative integer, is preserved and the false exit guard yields . The decreasing nonnegative integer is also a loop variant, establishing total correctness for this example.[ref]
A partial correctness claim connecting a precondition , a program and a postcondition : every terminating execution begun with ends with . State separately whether total correctness is intended.

Articles by others on the same topic (1)

Programming language semantics is a subfield of computer science that focuses on the meaning of programming languages and their constructs. While syntax deals with the formal rules that govern the structure of programs (how code is written), semantics is concerned with the meaning behind that code—what the code actually does when executed. Semantics can be categorized into several different types: 1. **Operational Semantics**: This approach defines the meaning of a program in terms of the operations that take place during execution.