System Software Viva Questions
i want you to generate question and answers for oral practical - viva for subject "SYSTEM
PROGRAMMIN AND COMPILER CONSTRUCTION". i will provide you with the syllabus and you have
to generate 10 to 15 questions on each topic of each module. the questions must include define,
explain, classify, give types, applications, advantages, disadvantages, etc type of questions and
more if possible.
the module wise topics are:
MODULE 1. Introduction to System Software (2 hrs)
- 1.1 Concept of System Software, Goals of system software, system program and system
programming.
- Introduction to various system programs such as:
- Assembler
- Macro processor
- Loader
- Linker
- Compiler
- Interpreter
- Device Drivers
- Operating system
- Editors
- Debuggers
MODULE 2. Assemblers (7 hrs)
- 2.1 Elements of Assembly Language programming, Assembly scheme, pass structure of assembler.
- Assembler Design:
- Two-pass assembler Design
- Single-pass Assembler Design for X86 processor, data structures used.
Module 1
Topic 1.1: Concept of System Software, Goals of System Software, System Program
and System Programming
1. Define system software.
Answer: Software that provides services and an environment for application software, managing
hardware resources and offering utility programs.
2. Explain the primary goals of system software.
Answer: Efficiency (maximizing hardware utilization), portability (across hardware/OS), reliability
(robust operation), and user productivity (ease of development and maintenance).
3. Differentiate between system programs and application programs.
Answer: System programs provide a platform for running applications (e.g., OS, compilers), while
application programs perform user-oriented tasks (e.g., word processors).
Printed using ChatGPT to PDF, powered by PDFCrowd HTML to PDF API. 1/18
4. Classify the levels of system programming.
Answer: (1) Low-level programming (assembly, driver development); (2) Mid-level (compilers,
linkers); (3) High-level utilities (editors, debuggers).
5. List and explain four characteristics of good system software.
Answer: Portability (runs on multiple platforms), efficiency (minimal overhead), reliability (fault-
tolerant), maintainability (easy to update).
6. What is system programming? Give two examples.
Answer: Writing software that implements system services or development tools (e.g., assembler,
debugger).
7. Give two advantages of separating system software from application software.
Answer: (1) Modularity—easier maintenance and updates. (2) Security—system-level code can be
hardened separately.
8. State two disadvantages or challenges in system software design.
Answer: (1) Complexity—closely interacts with hardware. (2) Portability issues—hardware
dependencies.
9. Explain how system software enhances user productivity.
Answer: By automating routine tasks (editing, linking), providing error-checking tools (debuggers),
and offering a stable development environment.
10. Define the term “utility program” and give two examples.
Answer: A small system program performing a specific task (e.g., file compressor, disk formatter).
11. Why must system software be reliable?
Answer: Failures in system software can crash the entire system, leading to data loss and
downtime.
12. Classify system programming languages by level, and cite an example for each.
Answer: Low-level (Assembly), mid-level (C), high-level (Python for scripting utilities).
Topic 1.2: Introduction to Various System Programs
1. Define an assembler and state its purpose.
Answer: Translates assembly language code into machine code.
2. What are macros? Explain the role of a macro processor.
Answer: Macros are reusable code templates; a macro processor expands macro calls into their
definitions before assembly.
3. Classify loaders by relocation strategy and give examples.
Answer: Absolute loader (no relocation), relocating loader (adjusts addresses), dynamic loader (on-
demand loading).
4. Explain the difference between a linker and a loader.
Answer: A linker combines object files into an executable; a loader places the executable into
memory and prepares it for execution.
5. List three types of compilers and briefly describe each.
Answer: Single-pass (one pass, limited optimizations), multi-pass (multiple passes, extensive
optimizations), just-in-time (compiles at runtime).
Printed using ChatGPT to PDF, powered by PDFCrowd HTML to PDF API. 2/18
6. What is an interpreter? State one advantage and one disadvantage.
Answer: Executes source code line by line. Advantage: easy debugging; Disadvantage: slower
execution.
7. Define device driver and its role in system software.
Answer: A device-specific module that enables the operating system to communicate with
hardware devices.
8. Give two functions of an operating system as a system program.
Answer: Process scheduling, memory management.
9. Classify text editors into two categories and give an example of each.
Answer: Line editors (e.g., `ed`), screen editors (e.g., `vi`, `Notepad++`).
10. Explain the purpose of a debugger.
Answer: Helps developers find and fix runtime errors by allowing step-wise execution, breakpoints,
and inspection of variables.
11. List two advantages of using a compiler over an interpreter.
Answer: Faster execution, better global optimization.
12. What disadvantages might interpreters have compared to compilers?
Answer: Slower performance, repeated parsing overhead on each run.
13. Give an application scenario for macro processors.
Answer: Generating standardized boilerplate code across multiple source files.
14. Explain how dynamic loaders improve program start-up times.
Answer: By loading only required modules at runtime, reducing initial load.
15. Compare device drivers and interpreters in terms of abstraction level.
Answer: Device drivers operate at a low level close to hardware; interpreters operate at a high level
on source code.
Module 2
Topic 2.1: Elements of Assembly Language Programming, Assembly Scheme, Pass
Structure of Assembler
1. Define mnemonic in assembly language.
Answer: A symbolic name representing an opcode (e.g., `MOV`, `ADD`).
2. Explain the role of symbolic labels.
Answer: Human-readable names for memory addresses to simplify code.
3. List three elements common to all assembly languages.
Answer: Opcodes, operands, directives (pseudo-ops).
4. What is an assembly scheme?
Answer: The overall plan for translating assembly code, including symbol tables, literal pools, and
location counters.
5. Describe the two main passes in a two-pass assembler.
Answer: Pass 1 builds the symbol table and computes addresses; Pass 2 generates machine code
Printed using ChatGPT to PDF, powered by PDFCrowd HTML to PDF API. 3/18
using that table.
6. Explain the purpose of the location counter.
Answer: Keeps track of memory addresses of instructions/data during assembly.
7. Classify assembler directives into two types with examples.
Answer: Data definition directives (`DB`, `DW`), control directives (`ORG`, `END`).
8. What are forward references and how does an assembler handle them?
Answer: References to symbols not yet defined; handled by recording them in a list and resolving
in Pass 2.
9. Give two advantages of the two-pass structure.
Answer: Simpler symbol resolution, supports forward references.
10. State two disadvantages of a single-pass assembler compared to two-pass.
Answer: Typically less flexible in handling forward references, more complex bookkeeping.
11. Explain the function of the literal pool.
Answer: A storage area for constant values encountered in the code.
12. Why are comments important in assembly code?
Answer: They improve readability and maintainability of low-level code.
13. Describe the role of the symbol table in assembly.
Answer: Maps symbol names to addresses or values used in code generation.
14. Classify data definitions and control directives and cite one example each.
Answer: (1) Data definitions: `DS` (define storage); (2) Control directives: `EQU` (symbol equate).
15. What is the significance of the END directive?
Answer: Marks the end of source code and may specify the entry point.
Topic 2.2: Two-Pass Assembler Design
1. Outline the main tasks of Pass 1 in a two-pass assembler.
Answer: Scan source, assign addresses, collect symbol definitions, build intermediate file.
2. What tasks are performed in Pass 2?
Answer: Translate mnemonics to machine code, resolve symbols, generate object code.
3. Explain how forward references are resolved.
Answer: Entries created in Pass 1; Pass 2 uses symbol table to fill in addresses.
4. List and describe two data structures used in Pass 1.
Answer: Symbol table (map names to addresses), literal table (constants to addresses).
5. What is an intermediate file? Why is it important?
Answer: Temporary representation containing parsed instructions and metadata; enables
separation of address calculation and code generation.
6. Give two advantages of the two-pass design.
Answer: Handles forward references easily; simpler code generation logic.
7. Mention one disadvantage of two-pass design.
Answer: Requires additional I/O for the intermediate file.
Printed using ChatGPT to PDF, powered by PDFCrowd HTML to PDF API. 4/18
8. How does the assembler detect undefined symbols?
Answer: At end of Pass 2, any symbol references not in the symbol table signal an error.
9. Explain the role of error handling in Pass 1.
Answer: Checks for syntactic errors, invalid directives, and duplicate labels.
10. What information does the location counter maintain?
Answer: The address for the next instruction or data to be allocated.
11. Describe how literal pools are managed across passes.
Answer: Collected in Pass 1; assigned addresses just like symbols; processed in Pass 2.
12. Classify two common intermediate file formats.
Answer: Textual (source-like with annotations), binary (compact tokenized form).
13. Why might an assembler combine Pass 1 and Pass 2 into a single pass?
Answer: To reduce I/O overhead at the cost of more complex bookkeeping.
14. Give an example of an optimization that can be done in Pass 2.
Answer: Peephole optimization to replace instruction sequences with shorter equivalents.
15. Explain how relocation information is generated in Pass 2.
Answer: By recording addresses needing adjustment when linking or loading.
Topic 2.3: Single-Pass Assembler Design for X86 Processor, Data Structures Used
1. Define single-pass assembly.
Answer: Translating source to object code in one traversal without an intermediate file.
2. Explain the main challenge in single-pass design.
Answer: Handling forward references without precomputed symbol table.
3. List three data structures used in a single-pass assembler.
Answer: Symbol table (with undefined entries), forward-reference queue, literal table.
4. How are forward references managed on x86 in one pass?
Answer: Placeholder entries created; fix‐up records emitted for linkage or later patching.
5. Describe what a fix-up record contains.
Answer: The location of the unresolved reference and the type/size of relocation needed.
6. Give two advantages of single-pass assemblers.
Answer: Lower memory and I/O overhead, faster assembly.
7. State two disadvantages of single-pass design.
Answer: Complex symbol management, limited support for some optimizations.
8. Explain the role of the forward-reference list.
Answer: Tracks symbol uses before definitions; entries are resolved when symbol gets defined.
9. What is backpatching?
Answer: Inserting correct addresses into code once symbol definitions become available.
10. How does the literal table differ in single-pass versus two-pass?
Answer: In single-pass, literals may be placed in code immediately with fix-ups required later.
Printed using ChatGPT to PDF, powered by PDFCrowd HTML to PDF API. 5/18
11. Classify relocation types on x86 and give examples.
Answer: PC-relative (e.g., jumps), absolute (e.g., data addresses).
12. Explain how the symbol table is updated when a label is defined.
Answer: The symbol’s address field is filled, and any pending forward references are patched.
13. Give one optimization that is more difficult in single-pass assemblers.
Answer: Global peephole optimizations requiring look-ahead or multiple instruction contexts.
14. Why is memory usage typically lower in single-pass assemblers?
Answer: No need to store an intermediate file; symbol table and fix-up records suffice.
15. Describe the overall workflow of a single-pass x86 assembler.
Answer: Read each line, update location counter, emit code or directive, record fix-ups for
undefined symbols, output object records immediately.
i want you to generate question and answers for oral practical - viva for subject "SYSTEM
PROGRAMMIN AND COMPILER CONSTRUCTION". i will provide you with the syllabus and you have
to generate 10 to 15 questions on each topic of each module. the questions must include define,
explain, classify, give types, applications, advantages, disadvantages, etc type of questions and
more if possible. give proper questions and answers
the module wise topics are:
MODULE 3. Macros and Macro Processor (6 hrs)
- 3.1 Introduction, Macro definition and call.
- Features of Macro facility:
- Simple
- Parameterized
- Conditional
- Nested
- Design of Two-pass macro processor, data structures used.
MODULE 4. Loaders and Linkers (6 hrs)
- 4.1 Introduction, functions of loaders, Relocation and Linking concept.
- Different loading schemes:
- Relocating loader
- Direct Linking Loader
- Dynamic linking and loading
Module 3. Macros and Macro Processor
Topic 3.1: Introduction, Macro Definition and Call
1. Define a macro.
Answer: A macro is a sequence of instructions or code templates identified by a name, which the
assembler expands in place of each macro call.
2. Explain the difference between a macro definition and a macro call.
Answer: A macro definition specifies the macro’s name, parameters, and replacement text. A
Printed using ChatGPT to PDF, powered by PDFCrowd HTML to PDF API. 6/18
macro call invokes the macro by name (with arguments, if any), triggering expansion.
3. Classify macros based on parameter usage.
Answer: (a) Positional macros – parameters referenced by position (e.g., &1, &2), (b) Keyword
macros – parameters referenced by name, (c) Mixed macros – combine positional and keyword.
4. What are the advantages of using macros in assembly programming?
Answer: (1) Code reuse and reduced duplication; (2) Improved readability; (3) Easier maintenance;
(4) Ability to parameterize common patterns.
5. List two disadvantages or pitfalls of excessive macro use.
Answer: (1) Code bloat due to repeated expansions; (2) Obscured control flow complicating
debugging.
6. Give two application scenarios where macros are particularly useful.
Answer: (1) Generating repetitive I/O or register-save sequences; (2) Abstracting calling
conventions across platforms.
7. Explain how a macro call is processed by the assembler.
Answer: The assembler recognizes the macro name, substitutes actual arguments for formal
parameters, and outputs the expanded code inline before further assembly.
8. Define “macro expansion.”
Answer: The process of replacing a macro call with the body of its definition, with parameters
substituted.
9. What is the purpose of the `&DEFAULT` directive (or equivalent) in macro definitions?
Answer: It specifies default values for parameters when actual arguments are omitted at the call
site.
10. Compare macros to subroutines in terms of overhead and flexibility.
Answer: Macros incur no call/return overhead (inlined code) but increase code size; subroutines
minimize size but have runtime overhead and less compile-time flexibility.
Topic 3.2: Features of Macro Facility
Simple Macros
1. Define a simple macro and give an example.
Answer: A macro without parameters; e.g.,
asm
`MYMSG MACRO
DB 'Hello, World!',0
ENDM
`
2. State one advantage and one disadvantage of simple macros.
Answer: + Very easy to define/use; − Cannot be customized without modifying the definition.
Parameterized Macros
Printed using ChatGPT to PDF, powered by PDFCrowd HTML to PDF API. 7/18
3. Explain parameterized macros and list their benefits.
Answer: Macros that accept arguments to customize expansions. Benefits: code generalization
and fewer definitions.
4. Classify parameter passing modes in macros.
Answer: (a) By position, (b) By keyword, (c) By default (with default values).
5. Give an example of a positional parameterized macro.
Answer:
asm
`PUSHREG MACRO reg
PUSH \reg
ENDM
`
Conditional Macros
6. Define conditional macro expansion.
Answer: Macros that include directives (`IF`, `ELSE`, `ENDIF`) to choose among alternative
expansions based on parameters or assembler expressions.
7. What are the applications of conditional macros?
Answer: Targeting different architectures or modes (e.g., 16-bit vs. 32-bit), enabling/disabling
debugging code.
8. Discuss one disadvantage of complex conditional macros.
Answer: Complexity can make definitions hard to read and maintain.
Nested Macros
9. Explain nested macros.
Answer: Macro definitions that invoke other macros (or themselves) within their bodies.
10. Give an example scenario where nested macros are useful.
Answer: Building higher-level constructs (e.g., a `PRINTLN` macro that calls a lower-level
`PRINTCHAR` macro in a loop).
11. State one challenge in implementing nested macro expansion.
Answer: Avoiding infinite recursion and managing levels of expansion.
12. Classify macro nesting depth considerations.
Answer: (a) Shallow nesting – a few levels, easy to manage; (b) Deep nesting – many levels,
requires careful expansion control and stack management.
Topic 3.3: Design of Two-Pass Macro Processor, Data Structures Used
1. Outline the two passes of a two-pass macro processor.
Answer:
Pass 1: Scans definitions, builds macro definition table (MDT) and macro name table (MNT).
Pass 2: Processes calls, expands macros using MDT/MNT, outputs expanded source.
Printed using ChatGPT to PDF, powered by PDFCrowd HTML to PDF API. 8/18
2. Define the Macro Definition Table (MDT).
Answer: Stores the body of each macro with placeholders for parameters.
3. What is the Macro Name Table (MNT)?
Answer: Lists macro names along with pointers to their definitions in the MDT.
4. Describe the argument list array (ALA).
Answer: A temporary table in Pass 2 that maps formal parameters to actual arguments for each
macro call.
5. Explain how conditional directives are handled in Pass 1 versus Pass 2.
Answer: Pass 1 simply records the lines; Pass 2 evaluates conditions and chooses the correct
expansion.
6. List two advantages of the two-pass design for macro processing.
Answer: (1) Simplifies forward reference handling (macro calls before definitions), (2) Separates
definition storage from expansion logic.
7. Name one disadvantage of a two-pass macro processor.
Answer: Requires storing entire definitions in memory (MDT), increasing memory usage.
8. What data structure tracks nested macro call levels?
Answer: A call stack, storing return points and local ALA contexts.
9. Explain the role of the Definition Name Table (DNT) if used.
Answer: An alternative to MNT; provides quick lookup for macro parameters and names.
10. How does the processor detect and prevent recursive macro calls?
Answer: By checking the call stack for the current macro name before expansion; raising an error
if already present.
11. Give two optimizations possible in Pass 2.
Answer: (1) Skipping expansion of unused macros, (2) Caching expanded blocks for repeated
identical calls.
12. Describe how the processor handles default parameter values.
Answer: In Pass 1, records default values in MDT; in Pass 2, when argument missing, substitutes
default from MDT.
Module 4. Loaders and Linkers
Topic 4.1: Introduction, Functions of Loaders, Relocation and Linking Concept
1. Define a loader.
Answer: A system program that loads an executable into memory, resolves addresses, and
transfers control to the program.
2. List the primary functions of a loader.
Answer:
1. Reading object modules,
2. Relocation (adjusting addresses),
3. Linking (resolving external references),
Printed using ChatGPT to PDF, powered by PDFCrowd HTML to PDF API. 9/18
4. Loading into memory,
5. Initializing registers and control transfer.
3. Explain the concept of relocation.
Answer: Modifying address-dependent code and data so that a program can execute at different
memory locations.
4. Classify relocation types with examples.
Answer:
Static relocation: All addresses fixed at load time.
Dynamic relocation: Addresses adjusted at runtime via base register or MMU.
5. What is linking?
Answer: Combining separately compiled object modules, resolving symbol references among
them.
6. Compare static linking and dynamic linking.
Answer:
Static linking: Combines libraries into the executable, larger file size.
Dynamic linking: References library code at runtime, smaller executables, shared memory
usage.
7. Give one advantage and one disadvantage of static linking.
Answer: + Self-contained executable; − Larger disk/memory footprint, harder to update libraries.
8. Why is symbol resolution important in linking?
Answer: Ensures each external reference in one module points to the correct definition in another.
9. Explain the role of the linker loader record (e.g., in an [Link] or COFF file).
Answer: Provides the loader with metadata: segment sizes, symbol tables, relocation entries.
10. What happens if the loader encounters an undefined symbol?
Answer: It signals an error and aborts loading.
11. Classify link-time versus load-time versus run-time linking.
Answer:
Link-time: Performed by the linker before execution.
Load-time: Performed by the loader when the program is loaded.
Run-time (dynamic): Performed during execution on demand.
12. Explain address binding and its three stages.
Answer:
1. Compile-time binding: Fixed at compile time.
2. Load-time binding: Fixed when loaded.
3. Execution-time binding: Resolved during execution (e.g., paging).
Topic 4.2: Different Loading Schemes
Relocating Loader
Printed using ChatGPT to PDF, powered by PDFCrowd HTML to PDF API. 10/18
1. Define a relocating loader.
Answer: A loader that adjusts program addresses at load time so the program may reside at any
memory location.
2. Explain how a relocating loader uses relocation bits.
Answer: Each object record includes flags indicating which fields need modification by adding the
program’s load address.
3. Give one advantage of relocating loaders.
Answer: Allows multiple programs to coexist in memory without fixed address constraints.
4. State one disadvantage.
Answer: Additional overhead in computing address adjustments during loading.
Direct Linking Loader
5. What is a direct linking loader?
Answer: A loader that performs linking between object modules on the fly, resolving external
references without a separate linker phase.
6. Explain the process of direct linking as modules are loaded.
Answer: As each module is read, its external references are immediately matched to previously
loaded symbols and patched.
7. List one advantage of direct linking loaders.
Answer: Eliminates separate link step, reducing I/O and overall load time.
8. Mention one challenge when using direct linking loaders.
Answer: Requires maintaining a global symbol table in memory during the loading of multiple
modules.
Dynamic Linking and Loading
9. Define dynamic linking.
Answer: Linking library routines at runtime rather than at load time.
10. Explain the role of the dynamic linker/loader (e.g., `[Link]`).
Answer: Locates shared libraries, resolves their symbols, maps them into memory, and patches
references when a program starts (or on-demand).
11. Give two advantages of dynamic linking.
Answer: (1) Smaller executables; (2) Shared libraries reduce overall memory usage and simplify
updates.
12. List two disadvantages of dynamic linking.
Answer: (1) Potential runtime failures if required libraries are missing; (2) Slight startup
performance overhead.
13. What is position-independent code (PIC)? Why is it required in dynamic linking?
Answer: Code that can execute correctly regardless of its absolute address; required so shared
libraries can be loaded at arbitrary addresses.
14. Compare immediate versus lazy binding in dynamic linking.
Answer:
Printed using ChatGPT to PDF, powered by PDFCrowd HTML to PDF API. 11/18
Immediate binding: All symbols resolved before execution begins.
Lazy binding: Symbols resolved on first use, reducing startup time but possibly deferring
errors.
15. Describe how symbol versioning helps in dynamic linking.
Answer: Allows multiple library versions to coexist by tagging symbols with version identifiers,
preventing conflicts at runtime.
i want you to generate question and answers for oral practical - viva for subject "SYSTEM
PROGRAMMIN AND COMPILER CONSTRUCTION". i will provide you with the syllabus and you have
to generate 10 to 15 questions on each topic of each module. the questions must include define,
explain, classify, give types, applications, advantages, disadvantages, etc type of questions and
more if possible.
the module wise topics are:
MODULE 5. Compilers: Analysis Phase (10 hrs)
- 5.1 Introduction to compilers, Phases of compilers:
- Lexical Analysis: Role of Finite State Automata in Lexical Analysis, Design of Lexical analyzer, data
structures used.
- Syntax Analysis: Role of Context Free Grammar in Syntax analysis, Types of Parsers: Top down
parser - LL(1), Bottom up parser - SR Parser, Operator precedence parser, SLR.
- Semantic Analysis: Syntax directed definitions.
MODULE 6. Compilers: Synthesis phase (8 hrs)
- 6.1 Intermediate Code Generation:
- Types of Intermediate codes: Syntax tree, Postfix notation, three address codes: Triples and
Quadruples, indirect triple.
- Code Optimization:
- Need and sources of optimization.
- Code optimization techniques: Machine Dependent and Machine Independent.
- Code Generation:
- Issues in the design of code generator, code generation algorithm.
- Basic block and flow graph.
Module 5. Compilers: Analysis Phase
5.1 Lexical Analysis
1. Define lexical analysis.
Answer: The phase of a compiler that reads the source code, groups characters into tokens
(identifiers, keywords, literals, operators), and removes whitespace and comments.
2. Explain the role of finite state automata (FSA) in lexical analysis.
Answer: FSAs model the patterns of tokens via state transitions; each token’s regular expression is
converted into a DFA/NFA guiding the lexer’s recognition process.
Printed using ChatGPT to PDF, powered by PDFCrowd HTML to PDF API. 12/18
3. Classify the types of input buffering schemes used in lexical analyzers.
Answer: (a) Single-buffer (sentinel-based), (b) Two-buffer (double buffering with sentinels), (c)
Input juggling techniques.
4. What data structures are commonly used in the design of a lexical analyzer?
Answer: Symbol table (hash table or trie), token buffer (character array with pointers), finite
automaton tables (transition tables), literal table.
5. Describe the design of a table-driven lexical analyzer.
Answer: Precomputes DFA transition tables; the scanner uses a next-state table indexed by current
state and input character to decide transitions and token acceptance.
6. List two advantages and two disadvantages of a generated lexer (e.g., via Flex).
Answer:
Advantages: rapid development, optimized automata.
– Disadvantages: larger code size, less fine-grained control.
7. Give an application scenario for hand-written versus generator-based lexical analyzers.
Answer: Hand-written for complex context-sensitive lexing; generator-based for standard token
sets in general-purpose languages.
8. Explain the “maximal munch” rule in lexical scanning.
Answer: At each step, the lexer matches the longest possible sequence of characters that forms a
valid token.
9. What is backtracking in lexical analysis, and why should it be avoided?
Answer: Re-examining input to resolve ambiguous matches; avoided because it degrades
performance and complicates the DFA design.
10. Define a regular expression and its importance in lexical analysis.
Answer: A concise notation for describing regular languages; used to specify token patterns that
are converted into FSAs.
5.2 Syntax Analysis
1. Define context-free grammar (CFG).
Answer: A set of production rules where each rule has a single nonterminal on the left-hand side,
describing the syntactic structure of a language.
2. Explain the role of CFGs in syntax analysis.
Answer: CFGs define the language’s syntax; parsers use them to build parse trees and verify that
token sequences conform to grammatical rules.
3. Classify parsers into top-down and bottom-up categories with examples.
Answer:
Top-down: LL(1), recursive-descent.
Bottom-up: LR(0), SLR(1), LR(1), LALR(1).
4. What is an LL(1) parser? Describe its table construction steps.
Answer: A predictive single-token-lookahead parser; constructs FIRST and FOLLOW sets, builds an
LL(1) parse table mapping nonterminals and lookahead tokens to productions.
Printed using ChatGPT to PDF, powered by PDFCrowd HTML to PDF API. 13/18
5. List two advantages and two disadvantages of LL(1) parsing.
Answer:
Advantages: simple implementation, fast parsing.
– Disadvantages: cannot handle left recursion, limited grammar class.
6. Define shift-reduce parsing.
Answer: A bottom-up parsing method that shifts input tokens onto a stack and reduces sequences
matching the right-hand side of productions back to their nonterminal.
7. Explain the SLR(1) parsing technique.
Answer: Simple LR parser using LR(0) automaton plus FOLLOW sets to resolve reduce actions,
generating an SLR parsing table.
8. What is an operator precedence parser? Give one usage advantage.
Answer: A bottom-up parser that uses precedence relations among operators to guide reductions;
advantage: handles expressions without explicit grammar transformations.
9. Discuss one disadvantage of operator precedence parsing.
Answer: Limited to grammars without ambiguous or non-operator constructs; cannot handle all
CFGs.
10. Compare SLR(1) with LR(1) parsers in terms of power and table size.
Answer: LR(1) can handle a larger class of grammars but produces much larger parse tables;
SLR(1) is simpler and smaller but less powerful.
5.3 Semantic Analysis
1. Define semantic analysis in a compiler.
Answer: The phase that enforces language semantics, checks type consistency, resolves identifiers,
and annotates the parse tree with type and scope information.
2. What are syntax-directed definitions (SDDs)?
Answer: Grammars augmented with semantic rules (attributes and actions) that compute
semantic information during parsing.
3. Classify attributes in SDDs.
Answer:
Synthesized attributes: Computed from children nodes.
Inherited attributes: Computed from parent or siblings.
4. Explain how a compiler performs type checking using SDDs.
Answer: Semantic rules on productions compare operand types (e.g., in expressions) and
propagate type information as attributes to detect mismatches.
5. List two common semantic errors detected during this phase.
Answer: Type mismatches (e.g., adding integer and string), undeclared variable usage.
6. Describe the role of the symbol table in semantic analysis.
Answer: Records identifiers’ attributes (type, scope, memory location), enabling lookups and
ensuring correct declarations and scoping rules.
Printed using ChatGPT to PDF, powered by PDFCrowd HTML to PDF API. 14/18
7. Give one advantage and one disadvantage of syntax-directed translation.
Answer:
Advantage: modular and grammar-directed.
– Disadvantage: may require grammar restructuring to avoid circular attribute dependencies.
8. Explain how scope and lifetime of variables are managed in semantic analysis.
Answer: Using symbol table stacks: entering a new scope pushes a new table, exiting pops it,
thereby controlling visibility and lifetimes.
9. What is type inference? Provide an example language feature that uses it.
Answer: Automatically deducing variable types without explicit annotations; e.g., ML’s `let x = 5`
infers `x` as integer.
10. How are semantic actions executed in an LR parser?
Answer: Attached to grammar productions; triggered when a reduction occurs, performing
attribute calculations or intermediate code emission.
Module 6. Compilers: Synthesis Phase
6.1 Intermediate Code Generation
1. Define intermediate code (IC) in a compiler.
Answer: A low-level, machine-independent representation of source code (e.g., three-address
code) used between analysis and synthesis phases.
2. Classify types of intermediate code with examples.
Answer:
Syntax tree: Hierarchical tree representation.
Postfix notation (RPN): e.g., `ab+c*`.
Three-address code: Triples (`(op, arg1, arg2)`) and Quadruples (`(result, op, arg1,
arg2)`), indirect triples.
3. Explain the structure and use of triples.
Answer: Each instruction is a tuple `(operator, operand1, operand2)`; results are referred to by the
instruction’s index.
4. What advantages do quadruples have over triples?
Answer: Explicit result field simplifies code generation and backpatching, at the cost of extra
storage.
5. Define an indirect triple. When is it useful?
Answer: Uses a pointer table to triples, allowing easy insertion and deletion of instructions (useful
in optimization).
6. List two advantages and one disadvantage of using three-address code.
Answer:
Advantages: clear, easy to manipulate; machine-independent.
– Disadvantage: Not directly executable, requires further translation.
Printed using ChatGPT to PDF, powered by PDFCrowd HTML to PDF API. 15/18
7. Give an example of generating intermediate code for the expression `a + b * c`.
Answer:
ini
`t1 = b * c
t2 = a + t1
`
8. Explain how abstract syntax trees differ from concrete syntax trees.
Answer: ASTs omit syntactic sugar (e.g., parentheses, separators) representing only essential
structure; CSTs include all grammar details.
9. What role does intermediate code play in machine-independent optimization?
Answer: Provides a uniform representation on which optimizations (e.g., common subexpression
elimination) can be applied before machine-specific code generation.
10. Describe how control flow constructs (e.g., `if`, `while`) are represented in intermediate
code.
Answer: Using labels and conditional/unconditional jumps, e.g.,
vbnet
`if a < b goto L1
goto L2
L1: ...
L2: ...
`
6.2 Code Optimization
1. Why is code optimization necessary in compilers?
Answer: To improve runtime performance, reduce code size, and decrease resource usage
(memory, power).
2. Classify sources of optimization into machine-independent and machine-dependent.
Answer:
Machine-independent: Performed on intermediate code (e.g., algebraic simplification).
Machine-dependent: Performed during code generation (e.g., register allocation, instruction
scheduling).
3. Explain common subexpression elimination.
Answer: Identifies and reuses previously computed expressions to avoid redundant calculations.
4. Define loop-invariant code motion.
Answer: Moves computations that yield the same result on each loop iteration outside the loop.
5. List two machine-independent and two machine-dependent optimizations.
Answer:
Machine-independent: dead code elimination, constant propagation.
Machine-dependent: register allocation, instruction scheduling.
Printed using ChatGPT to PDF, powered by PDFCrowd HTML to PDF API. 16/18
6. What is peephole optimization? Give an example.
Answer: Local optimization on a small window of target code; e.g., replacing `MOV R1, R1` with no-
op.
7. Discuss one advantage and one disadvantage of aggressive optimization.
Answer:
Advantage: can yield highly efficient code.
– Disadvantage: longer compilation time and harder debugging.
8. Explain register allocation via graph coloring.
Answer: Constructs an interference graph of temporaries; colors nodes (registers) so adjacent
nodes differ, spilling if necessary.
9. What is strength reduction? Provide an example.
Answer: Replaces expensive operations with cheaper ones, e.g., replacing multiplication by 2 with
addition: `i * 2` → `i + i`.
10. Why must compilers balance optimization level and compilation time?
Answer: Higher optimization levels improve performance but increase compile-time cost; a trade-
off depends on development needs.
6.3 Code Generation
1. Define code generation in compiler design.
Answer: The phase that translates optimized intermediate code into target machine code or
assembly instructions.
2. List three key issues in the design of a code generator.
Answer: Instruction selection, register allocation, and instruction scheduling.
3. Explain the concept of a basic block.
Answer: A sequence of instructions with a single entry and exit point; no jumps or labels inside
except at ends.
4. What is a control flow graph (CFG)?
Answer: A directed graph where nodes are basic blocks and edges represent possible control
transfers.
5. Describe a simple code generation algorithm using DAGs.
Answer: Build a DAG for expressions within a basic block, identify common subexpressions, and
emit code by traversing the DAG.
6. Give one advantage of DAG-based code generation.
Answer: Automatically eliminates common subexpressions and redundant computations within a
block.
7. Explain register allocation using a bottom-up approach (e.g., register as variable allocation).
Answer: Allocates registers greedily as instructions are emitted, spilling to memory when registers
run out.
8. What is instruction selection by tree pattern matching?
Answer: Matches subtrees of the intermediate representation to machine instruction patterns to
generate optimal code sequences.
Printed using ChatGPT to PDF, powered by PDFCrowd HTML to PDF API. 17/18
9. Discuss one challenge in instruction scheduling on pipelined architectures.
Answer: Avoiding pipeline hazards (data, control) by ordering instructions to maintain throughput.
10. Why is it important to consider calling conventions during code generation?
Answer: To ensure proper arrangement of arguments, return values, and callee-saved registers
across function calls.
Printed using ChatGPT to PDF, powered by PDFCrowd HTML to PDF API. 18/18