In static scoping, the identifiers can be determined by analyzing/parsing the source code (versus dynamic scoping which needs to, more or less, know the callers environment).
My question is this, since static scoping simply needs to parse the source code to know the scoping and identifier bindings, is the scope environment/identifier bindings made at compilation time, or are these bindings determined when each function (or new scope) is accessed.
JavaScript example:
var globalVar;
function fooFunc() {
var fooVar;
function barFunc() {
var barVar;
}
}
In this simple JavaScript example, I can visually determine by examining the program that the barFunc environment will have a variable of barVar, and that has a parent environment that has fooVar as well as the barFunc function, and that has a parent environment of the global scope which has globalVar. I'm curious if the compiler/interpreter reads the source code as a whole and makes the bindings, or if these determinations are made at a function by function (or scope by scope) basis.
If I am unclear, please let me know.
Thank You,
Edit: Although my example is in JavaScript (which I'm particularlly curious about), I also am curious if this differs between languages (i.e. JavaScript, C/C++, C#/VB, etc.)