Intermediate Topic 18 of 50 Languages & Compilers
Symbol Tables
Compiler maps tracking identifiers and their attributes.
How it works
A symbol table is a compiler data structure that maps names, such as variables, functions, types and classes, to information about them: type, scope, storage location, visibility and declaration position. Scopes are typically handled with a stack of tables or a tree of tables, where lookups search from the innermost scope outward and declarations insert into the current one. Hash tables provide fast lookup, and some languages need multiple namespaces.
Step-by-step walkthrough
- The compiler records every identifier it sees.
- Each entry stores type, scope and location.
- Nested scopes make a stack of tables.
- Looking up a name searches inner to outer scopes.
- It is used for undefined variable and duplicate declaration errors.
Where it is used
Name resolution, type checking, detecting undeclared or duplicate variables, code generation and IDE features such as go-to-definition and autocomplete depend on symbol tables.
Common pitfall
Scope handling errors, such as forgetting to pop a scope, produce wrong bindings. Shadowing, forward references, overloading, imports and nested functions complicate lookup. Redeclaration checks must be per scope. Keep symbol information immutable once resolved where possible and design clear rules for lifetimes and visibility.
Where it fits in the course
Symbol Tables is topic 18 of 50 in Languages & Compilers, rated Intermediate. It follows Abstract Syntax Trees. The next topic is Semantic Analysis.
Practice and explore
- Open the interactive lesson, with a mini quiz.
- Take the Languages & Compilers quiz.
How to study this topic
- Read the explanation above and restate the definition in your own words.
- Open the interactive lesson and answer its mini quiz.
- Read the common pitfall, then write a short example that avoids it.
- Check your understanding in the Languages & Compilers quiz, and revisit the topic if you miss a question.
Frequently asked questions
What is Symbol Tables?
Where do people use Symbol Tables?
What is the most common mistake with Symbol Tables?
What should I learn before this topic?
How can I practice it?
Is Symbol Tables hard to learn?
How long does it take to learn Symbol Tables?
Which topics are related to Symbol Tables?
What should I study after Symbol Tables?
Related topics
- Abstract Syntax Trees (Languages & Compilers)
- Semantic Analysis (Languages & Compilers)
- Parsing (Languages & Compilers)
- Type Inference (Languages & Compilers)
- Tables, Rows and Columns (Databases)
- Truth Tables (Computer Architecture & Logic)
- Hash Tables (Data Structures)