Which data structure in a compiler is used for managing information about…

2010

Which data structure in a compiler is used for managing information about variables and their attributes?

  1. A.

    Abstract syntax tree

  2. B.

    Symbol table

  3. C.

    Semantic stack

  4. D.

    Parse table

Attempted by 374 students.

Show answer & explanation

Correct answer: B

Answer: Symbol table — the symbol table is used to manage information about variables and their attributes.

  • What the symbol table stores: identifier names, data types, scope level (where each identifier is visible), memory location or offset, and other attributes such as parameter lists, array sizes, and declaration position.

  • Typical implementations: often implemented with hash tables for fast lookup; compilers also use a stack or nested tables to represent scope nesting and support insertion/removal when entering or leaving scopes.

  • When it is used: during semantic analysis for type checking and scope resolution, and later during intermediate-code generation and code generation to determine addresses, types, and calling conventions.

  • How it differs from related structures: an abstract syntax tree represents program structure (syntax), a semantic stack holds temporary values during parsing or semantic actions, and a parse table guides parser decisions. None of those serve as the persistent repository of identifier attributes like the symbol table does.

Key takeaway: use the symbol table to look up and record identifier attributes across compiler phases; other structures serve different, complementary roles.

Explore the full course: Gate Guidance By Sanchit Sir