Final answer:
In static-scoped programs, a nonlocal variable is connected to its definition based on where it's defined in the code relative to the reference. It's governed by the block structure and handled by name binding during compilation.
Step-by-step explanation:
In a static-scoped program, a reference to a nonlocal variable is connected to its definition based on the program's block structure. Static (or lexical) scoping determines the scope of a variable by its position in the source code. Thus, when a function or a block of code references a nonlocal variable, the connection to the variable's definition is made according to where it is defined in the code, in relation to the referencing context.
The most closely nested, enclosing block where the variable is defined dictates the linkage. For example, if a function A defined inside another function B references a nonlocal variable x, static scoping will connect that reference to the definition of x that is visible within function B's scope, or further out, but not inside a nested function within A.
Compilers use a process called name binding to link references to their respective definitions by looking at the static structure of the source code. Therefore, the runtime environment maintains a stack-like structure that reflects the nested block hierarchy of the code to look up nonlocal variable references.