seems to work fine There is one important distinction where the analogy breaks down: lexical environments are created from static code analysis, and do not change their shape. They are records, not dynamic objects. This both helps the interpreter/compiler to optimise lookups, and prevents them from being exposed as objects. There are only two little things that introduce dynamic scoping: eval and with. (The latter allows to actually put dynamic objects in the scope chain). They're both despised because of this.
Does that help Create an error token rule for each known error and an "catchall" error token rule at the end like this:
// valid tokens first!
Number : [0-9]+;
Identifier : [a-zA-Z] [a-zA-Z0-9]*;
// "error" tokens
// don't use these tokens in your grammar; They will show up as extraneous tokens during parsing and can be handled if desired.
InvalidIdentifier : [0-9]([0-9a-zA-Z])+;
ACommonInvalidToken : '^'; // if you want to be more specific for certain cases
// add more to address common mistakes
UnknownToken : . ; // the "catch-all" error token; be sure not to be too greedy...
ignore parent/ancestor environments inside function (disable lexical scoping)
fixed the issue. Will look into that further Your points 2 to 5 are correct. In your point 1, f and make-account do not "have" pointers to global environment - they do not need to, by themselves. They are both entries, bindings, in the global environment. Both "refer to", or "point at" simple values, functions in both cases. bank-account with respect to e2 actually points to the value to which paul-acc points (which is the same value to which peter-acc points, or refers). In Scheme, (define n1 n2) means "set up new binding in the current environment, named n1, and pointing at the value of the expression n2". If n2 happens to be a variable, its value is just what that variable's value is. That's why we're talking about Scheme's evaluation semantics.
seems to work fine 18.104.22.168 - 22.214.171.124 are the ways that a new lexical environment is created. You can find all the places those are used in the spec by searching for the name. Eg. if you search for NewFunctionEnvironment, you will find that one is created in 126.96.36.199 PrepareForOrdinaryCall. There is only one place in the spec where each of Global, Module, Function, and Object environments are created. There are several places where Declarative environments are created.