How is Lexical Scoping implemented? [closed]
A couple of years ago I started writing an interpreter for a little Domain Specific Language which included programmer-defined functions. At first I implemented variable scope using a simple stack of symbol-tables. But now I want to move to proper lexical scoping (with the option of closures). Can anyone explain the data-structure and algorithm behind lexical scope? To get correct lexical scoping and closures in an interpreter, all you need to do is follow these rules: In your interpreter, variables are always looked up in an environment table passed in by the caller or kept as a variable ,