Which data structure is used by the compiler for managing variables and their…

2019

Which data structure is used by the compiler for managing variables and their attributes?

  1. A.

    Binary tree

  2. B.

    Link list

  3. C.

    Symbol table

  4. D.

    Parse table

Attempted by 436 students.

Show answer & explanation

Correct answer: C

Answer: Symbol table

Why this is correct: The symbol table is the compiler's central data structure for storing identifiers (variable names, function names, etc.) and their attributes. It provides a mapping from each name to metadata the compiler needs.

  • Common attributes stored: type information, scope level, memory location or offset, declaration line, and other semantic information.

  • Core operations supported: insert (on declaration), lookup (on use), and delete (on scope exit if needed).

  • Typical implementations: hash tables for fast average-case lookup; balanced trees or scoped chaining when ordering or worst-case guarantees are required.

How the compiler uses it across phases:

  1. During parsing and semantic analysis: insert declarations and perform lookups for type checking and scope resolution.

  2. During code generation: use stored memory locations and type/layout information to allocate storage and generate correct addressing.

Why the other choices are not correct:

  • Binary tree: a possible low-level implementation detail in some cases, but not the conceptual structure used by compilers for managing identifiers and their attributes. The correct conceptual answer is symbol table.

  • Link list: inefficient for name-based lookup because it requires linear search; not used as the primary structure for symbol management.

  • Parse table: used by parsers to decide parsing actions based on grammar rules and states; it does not store variable attributes.

Explore the full course: Mppsc Assistant Professor