Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Hello,I really appreciate your work guys!! I Need some more explanation and deta

ID: 3673931 • Letter: H

Question

Hello,I really appreciate your work guys!!
I Need some more explanation and details pleas regarding on
3.3.1 Static Scoping ,3.3.6 Dynamic Scoping , 3.3.3 Declaration order
3.3.1 Static Scoping

here is the original text.
Lexical scoping (sometimes known as static scoping ) is a convention used with many programming languages that sets the scope (range of functionality) of a variable so that it may only be called (referenced) from within the block of code in which it is defined. The scope is determined when the code is compiled. A variable declared in this fashion is sometimes called a private variable.
3.3.6 Dynamic Scoping
The opposite approach of static scoping is known as dynamic scoping . Dynamic scoping creates variables that can be called from outside the block of code in which they are defined. A variable declared in this fashion is sometimes called a public variable.

Explanation / Answer

Lexical scope assigns the scope to variable based on code written. In other words, programmers define the scope of variables when they are coding. Example will be much clearifying, we will try to understand these concepts based on following example:

def func1():
int a, b;
func2();

def func2():
int c, d;
func3();

def fund3():
int e, f;
print ('Hello!');

func1() declares a, b and calls func2()

func2() declares c, d and calls func3()

func3() declares e,f and prints 'Hello!'

When we execute this code with lexical scoping variable a and b are only accessible to func1(), similarly c and c accessible to func2(), e and f accessible to func3() because they are locked in scope (defined by indentation like python).

When we execute this code with dynamic scoping variable a and b are accessible to func1(). As func2() is called from func1() it will have access to its variables a, b and total access to variables a, b, c, d. Similarly, func3 is called from func2() which has access to a, b, c, d so finally func3 will have access to a, b, c,d, e and f. Hence variables are being accessed outside the block of code in which they are defined.

Declaration order

Some languages forces lexical declaration of functions before they are used like C, C++. Whereas, Java like programming languages allow function to be used before they are declared lexically. That's it!

Hope it helps! :)