Grouping Symbols into Scopes

A scope is a code region with a well-defined boundary that groups symbol definitions (in a dictionary associated with that code region). For example, class scopes group members; function scopes group parameters and local variables. Scope boundaries usually coincide with begin and end tokens such as curly braces (sort of like the “hello” and “goodbye” of a phone conversation). We call this lexical scoping because the extent of a scope is lexically delimited. Perhaps a better term is static scoping because we can track scopes just by looking at the source code; that is, without executing it. Here’s a list of scope characteristics that often differ between languages:

  • Static vs. dynamic scoping: Most languages have static ...

Get Language Implementation Patterns now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.