Tracking Symbols in High-Level Interpreters

Given a variable reference x in a program, we need to figure out which memory space it lives in so we can load or store its value. The interpreter figures this out by resolving x and asking for its surrounding scope. That scope tells the interpreter in what kind of scope the variable belongs: global, function, or data aggregate instance. Once the interpreter knows the kind of memory space, it can pick the proper dictionary in physical memory.

If the symbol table says x is a global variable, the interpreter loads it from the global space. If x resolves to a local variable or parameter, the interpreter loads it from the function space on the top of the function space stack.

If x is a field of a class, ...

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.