A compiler keeps one shared record of every name in your program, reports what it cannot translate, and splits its work across passes. Examiners test the seams between those three. Memorising the six phase names is not enough, because the options turn on what each structure or stage actually does.
Work through each question before reading the answer under it. This subtopic carries more than 20 previous-year questions, so use the twelve here to find the distinctions you still need to revise, then continue through GATE CS Exam Preparation for connected practice.
1. Symbol table records, density and search cost
Suppose int count; is global and float count; is declared inside block level 2:
Stored field | Example value | Who writes or updates it | Who reads it |
|---|---|---|---|
Name |
| Lexer and declarations | Name resolution |
Type |
| Semantic analysis | Type checking and code generation |
Width |
| Storage layout | Address and code generation |
Scope |
| Declaration processing | Name lookup |
Address |
| Storage layout | Code generation |
The entries are {name: count, type: int, width: 4 bytes, scope: global, address: 4000} and {name: count, type: float, width: 4 bytes, scope: block-2, address: 8000}. From block 2, lookup returns address 8000; after the block closes, count resolves to 4000.
Symbol tables store identifier attributes beyond parsing. Hashing normally gives fast average lookup. Density is occupied entries / table length; unsuccessful sequential search may inspect all L entries. For wider practice, use Compiler Design MCQs.
2. Symbol table MCQs 1-2: what it stores and when it is used
An abstract syntax tree stores program structure. A symbol table stores facts attached to names, and it keeps serving them long after the parser is done.
Question 1: what the symbol table is actually used for
UGC NET 2020, Computer Science | Solution
Which of the following are applications of symbol table?
(A) Storage allocation
(B) Checking type compatibility
(C) Suppressing duplicate error messages
Choose the correct answer from the options given below:A. (A) and (B) Only
B. (A) and (C) Only
C. (B) and (C) Only
D. (A), (B) and (C)Answer: D. (A), (B) and (C).
All three are symbol-table work. The address column drives storage allocation, the type column drives type-compatibility checking, and marking a name as already reported keeps the compiler from repeating the same complaint at every later use. The two count entries above carry exactly those fields.
Question 2: when the symbol table stops being useful
GATE 2025, Computer Science | Solution
Which ONE of the following statements is FALSE regarding the symbol table?A. Symbol table is responsible for keeping track of the scope of variables.
B. Symbol table can be implemented using a binary search tree.
C. Symbol table is not required after the parsing phase.
D. Symbol table is created during the lexical analysis phase.Answer: C. Symbol table is not required after the parsing phase.
Parsing is not the end of symbol-table use. Semantic analysis reads names and types, and later phases read widths, offsets and locations. Scope tracking, tree implementations and creation during lexical analysis all remain valid, so C is the false statement.
3. Symbol table MCQs 3-5: implementation, occupation density and search cost
Eight names in a table of length 16 give density 8/16 = 0.5. Do not confuse density with empty positions or with comparisons.
Question 3: the implementation with minimum access time
UGC NET 2023, Computer Science | Solution
Which of the following symbol table implementation is best suited if access time is to be minimum ?A. Linear list
B. Search tree
C. Hash Table
D. Self organisation listAnswer: C. Hash Table.
With good distribution and controlled collisions, hashing gives expected constant-time insertion and lookup. A linear list can take O(n) comparisons and a balanced tree O(log n). Hashing is not constant-time in the worst case, but it is the fastest of the four on average.
Question 4: calculate symbol-table occupation density
Indian Space Research Organization 2011, Computer Science | Solution
A symbol table of length 152 is processing 25 entries at any instant. What is occupation density?A. 0.164
B. 127
C. 8.06
D. 6.08Answer: A. 0.164.
occupation density = entries / table length = 25 / 152 = 0.16447..., which rounds to 0.164. The value 152 - 25 = 127 counts unused positions rather than density, so B is the subtraction trap.
Question 5: count comparisons in an unsuccessful sequential search
Indian Space Research Organization 2011, Computer Science | Solution
Number of comparisons required for an unsuccessful search of an element in a sequential search, organized, fixed length, symbol table of length L isA. L
B. L/2
C. (L+1)/2
D. 2LAnswer: A. L.
For L = 8, an absent name requires checks at entries 1, 2, 3, 4, 5, 6, 7, 8. Only after all 8 = L comparisons can failure be reported. The L/2 answer is the average position of a successful search, not this case.
4. Compiler error MCQs 6-7: lexical, syntactic and semantic
The error class is decided by how far the source gets. If the scanner cannot finish a token, the report is lexical. If the tokens are legal but their arrangement is not, it is syntactic. If only the meaning fails, it is semantic.
Question 6: place each faulty C statement in its error class
GATE 2026, Computer Science | Solution
Consider the following C statements:
char str1 = "Hello; /* Statement S1 */
char str2 = "Hello;"; /* Statement S2 */
int str3 = "Hello"; /* Statement S3 */
Which of the following options is/are correct?A. S1 and S2 have syntactic errors
B. S2 has a lexical error and S3 has a syntactic error
C. S1 has a lexical error and S3 has a semantic error
D. S1 has a syntactic error and S3 has a semantic errorAnswer: C. S1 has a lexical error and S3 has a semantic error.
S1 never closes its string literal, so the scanner reaches the end of the line holding a token it cannot finish, which is a lexical error. S3 tokenises and parses cleanly, and only type checking rejects assigning a string literal to an int, which makes it semantic. A and D misclassify S1, and B misclassifies S2, whose literal is well formed.
Question 7: what a compiler reports during translation
HPSC 2021, Computer Science | Solution
In the translation process, compiler always reports the existence of which of the following?A. Objects
B. Classes
C. Errors
D. TextAnswer: C. Errors.
Errors are the category a compiler always reports on, even when the count is zero. Objects, classes and text may be constructs the program declares or input the compiler reads, but none is a reporting category.
For token-level errors, try Lexical Analysis MCQs: 10 Solved Compiler Design Questions; for grammar, try Parsing MCQs: 12 Solved Top-Down and Bottom-Up Questions.
5. Compiler pass MCQ 8: what the first pass produces
Compiler work splits two ways. The front end does the target-independent work of scanning, parsing and semantic checking; the back end does the target-specific work of instruction selection, register allocation and addressing. A two-pass translator splits along time instead: pass 1 fixes addresses, pass 2 emits code using them. Trace START = 100 and LOOP = 116 in the assembler below: pass 1 records both, and pass 2 uses LOOP = 116 to encode a branch operand.
Question 8: the pass that generates the symbol table
UGC NET 2014, Computer Science | Solution
In a two-pass assembler, symbol table isA. Generated in first pass
B. Generated in second pass
C. Not generated at all
D. Generated and used only in second passAnswer: A. Generated in first pass.
Pass 1 assigns addresses and builds the table, which is what gives forward references their values. Pass 2 consumes it while producing machine code, including the LOOP = 116 operand. Option D confuses where the table is used with where it is created.
6. Compiler variants and relocation MCQs 9-12
Incremental compilation controls how much source is recompiled. Cross compilation separates the machine running the compiler from the machine its output targets. Relocation adjusts addresses after placement.
Question 9: what an incremental compiler recompiles
Indian Space Research Organization 2018, Computer Science | Solution
Incremental-Compiler is a compilerA. which is written in a language that is different from the source language
B. compiles the whole source code to generate object code afresh
C. compiles only those portion of source code that have been modified
D. that runs on one machine but produces object code for another machineAnswer: C. compiles only those portion of source code that have been modified.
A project has 40 files, but a change touches parser.c and the dependent ast.c. An incremental build recompiles those 2 units, not all 40. Option B describes a clean full rebuild, and option D describes the variant named next.
Question 10: the compiler whose output runs on another machine
UGC NET 2023, Computer Science | Solution
The compiler for high level language that runs on one machine and produces code for another machine is calledA. Cross Compiler
B. Multipass Compiler
C. Optimizing Compiler
D. One pass CompilerAnswer: A. Cross Compiler.
Host and target are separate roles. A cross compiler executes on the host, say x86-64 Linux, and emits code for a different target, say ARM64. Multipass and one-pass count traversals of the source, and optimizing describes what the back end does with it, so none of them answers a host-versus-target question.
Question 11: the cross-compiler construction technique
Indian Space Research Organization 2020, Computer Science | Solution
Which one indicates a Technics of building cross compilers ?A. Beta cross
B. Canadian cross
C. Mexican cross
D. X-crossAnswer: B. Canadian cross.
Build on x86-64 Linux, make the compiler itself run on ARM64 Linux, and target RISC-V output. Those are the roles of build, host and target, and separating all three is what the Canadian cross names. The other options are invented labels.
Question 12: address adjustment after placement
UGC NET 2013, Computer Science | Solution
The process of assigning load addresses to the various parts of the program and adjusting the code and data in the program to reflect the assigned addresses is called _______.A. Symbol resolution
B. Parsing
C. Assembly
D. RelocationAnswer: D. Relocation.
An object reference sits at offset 0x20. Loaded at address 0x1000, relocation rewrites it to 0x1000 + 0x20 = 0x1020. Symbol resolution picks which definition a name refers to; relocation adjusts the address for the placement it got.
7. Final answer map and next practice step
Answer strip: 1-D, 2-C, 3-C, 4-A, 5-A, 6-C, 7-C, 8-A, 9-C, 10-A, 11-B, 12-D.
The short version: the symbol table follows names across every phase, the error handler sorts problems into lexical, syntactic and semantic, and passes and variants change when and where the work happens. Retry only the questions you missed, without looking at the strip.
For a structured next step across Compiler Design, continue with GATE Guidance by Sanchit Sir.




