Machine-translated by Google. Questions are authored in English.
Top

Discussion

Symbol table lookup is usually implemented with a hash table because

  • A.names must be found quickly and are looked up very frequently
  • B.hash tables preserve the order in which names were declared
  • C.the language standard requires that particular data structure
  • D.a hash table is the only structure that can store attributes

Answer: A

Correct answer: names must be found quickly and are looked up very frequently

Every identifier in the program is looked up at least once and usually several times, across several phases, so the lookup is on the compiler's hot path.

A hash table gives near constant time, where a linear list would give time proportional to the number of names. The trade is that ordering is lost, which is why scope handling uses a stack of tables or a chain of them alongside. No standard prescribes the structure; speed alone recommends it.

No comment is present. Be the first to comment.
Loading…

Post your comment

Please log in or register to post a comment.