December 2009
Intermediate to advanced
380 pages
9h 2m
English
| Pattern 17 | Symbol Table for Nested Scopes |
This pattern tracks symbols and builds a scope tree for languages with multiple, possibly nested scopes.
Programming language functions are a good example of nested scopes. Each function has its own scope that is nested within a global or class scope. Some languages even support nested function definitions or multiple local scopes. Many DSLs have nested scopes as well. The DOT[22] graphics language, for example, has subgraphs within graphs. This pattern handles them all gracefully.
To discuss nested scopes, let’s add functions to our Cymbol C++ subset. That means we’ll need a function (method) Symbol and scopes for globals, parameters, and local variables. Let’s take a look at some sample ...