CS Atlas GATE 2027
Compiler Design course
0 / 90 complete

Compiler Design/Phase 7 · Integration & Final Test

Chapter review LI.0.1 · Item 5 of 90

What a compiler is

Read at your own pace. Try the questions before opening the answers.

On this page

ACompressed recap

🧾

People write programs in high-level languages; processors run only machine code, so programs must be translated. A compiler translates the whole program once into a target program; an interpreter executes the source directly every run. In C, the compiler sits in a toolchain: preprocessor → compiler → assembler → linker → loader. Inside, the compiler has six phases: lexical, syntax, semantic (front end) and intermediate code, optimization, code generation (back end), all sharing a symbol table and an error handler. Each kind of error is caught by a specific phase, and some errors are invisible to every phase.

BMerged rule card

0.1.1 Programs, machine code and why we translate; compiler vs interpreter

  • Compiler: whole source → equivalent target program, before running; reports source errors at compile time.
  • Interpreter: source + input → results directly, statement by statement; no target program.
  • Compiled code is usually faster; interpreted code is easier to change and test.
  • Break-even: compile when the number of runs n > C / (i − r).
  • Target can be machine code, assembly-like text, bytecode or another high-level language.

0.1.2 The toolchain: preprocessor, compiler, assembler, linker, loader

  • Order: preprocessor → compiler → assembler → linker → loader.
  • Files: .c → .i → .s → .o → executable.
  • Preprocessor: #include, #define, textual only.
  • Assembler output: relocatable object code with unresolved external references.
  • Linker: joins objects + libraries, resolves references → executable; “undefined reference” errors.
  • Loader (OS): copies into memory, relocates if needed, starts execution.

0.1.3 The phases of a compiler; symbol table; error handler; which phase catches which error

  • Phases: lexical → syntax → semantic → intermediate code → optimizer → code generator.
  • Front end (analysis) = first three, language-dependent; back end (synthesis) = last three, machine-dependent.
  • Symbol table: one entry per name (type, location, …), shared by all phases.
  • Errors: illegal character → lexical; shape/brackets/semicolon → syntax; undeclared/types/argument count → semantic; input-dependent → run time.
  • A misspelled keyword is an identifier to the scanner.
  • m languages × n machines: m × n compilers vs m + n parts.

CInterleaved GATE-style questions

Q1MCQ1 markToolchain

An “undefined reference to sqroot” message comes from the:

  • (A) preprocessor
  • (B) compiler’s syntax analyzer
  • (C) linker
  • (D) loader

Q2MCQ1 markError phase

int x = 3 @ 4; in C. The first phase to report it is:

  • (A) lexical analysis
  • (B) syntax analysis
  • (C) semantic analysis
  • (D) run time

Q3MSQ1 markCompiler vs interpreter

Which are true?

  • (A) A compiler can translate one high-level language into another.
  • (B) An interpreter finds every syntax error before the program starts running.
  • (C) Compiled machine code depends on the processor family.
  • (D) Java uses both compilation (to bytecode) and interpretation.

Q4NAT1 markMacro

Given #define DBL(x) x+x, what is 3*DBL(4)?

Numerical answer: ________

Q5MCQ1 markPhases

Which phase produces machine-independent code with temporaries such as t1, t2?

  • (A) lexical analysis
  • (B) semantic analysis
  • (C) intermediate code generation
  • (D) code generation

Q6MCQ2 marksError phase

Consider int a; float b; a = b + ;. Which phase reports the error?

  • (A) lexical
  • (B) syntax
  • (C) semantic
  • (D) none, it compiles

Q7NAT1 markBreak-even

Compiling takes 10 s, each compiled run 1 s, each interpreted run 3 s. Smallest number of runs where compiling is strictly cheaper in total?

Numerical answer: ________

Q8MSQ2 marksSymbol table

Which pieces of information are typically stored in a symbol table entry?

  • (A) the name’s type
  • (B) where the name was declared
  • (C) the memory location assigned to it
  • (D) the number of times the program will be run

Answer Vault

Try the questions first. Open when you are ready to check.

Q1 Answer: (C)1 mark

A function used but defined nowhere is found missing when object files and libraries are joined.

  • (A) is wrong: The preprocessor only expands # lines.
  • (B) is wrong: The call is well formed, so the parser accepts it.
  • (D) is wrong: The program never becomes an executable to load.

Re-read: Lesson 0.1.2 — The toolchain: preprocessor, compiler, assembler, linker, loader

Q2 Answer: (A)1 mark

@ cannot begin any C token, so the scanner reports it first.

  • (B) is wrong: The scanner rejects the character before the parser sees a token.
  • (C) is wrong: Meaning is never reached.
  • (D) is wrong: The program does not compile.

Re-read: Lesson 0.1.3 — The phases of a compiler; symbol table; error handler; which phase catches which error

Q3 Answer: (A) (C) (D)1 mark

Interpreters find an error only when execution reaches it, so (B) is false.

Re-read: Lesson 0.1.1 — Programs, machine code and why we translate; compiler vs interpreter

Q4 Answer: 161 mark

Expansion: 3*4+4 = 12 + 4 = 16, not 24.

Re-read: Lesson 0.1.2 — The toolchain: preprocessor, compiler, assembler, linker, loader

Q5 Answer: (C)1 mark

The intermediate code generator emits one-operation-per-line code with temporaries.

  • (A) is wrong: It produces tokens.
  • (B) is wrong: It checks meaning and inserts conversions.
  • (D) is wrong: Its output is machine-specific target code.

Re-read: Lesson 0.1.3 — The phases of a compiler; symbol table; error handler; which phase catches which error

Q6 Answer: (B)2 marks

An expression is missing after +: a shape problem.

  • (A) is wrong: All characters form valid tokens.
  • (C) is wrong: Even the int/float mix would be legal C; the real problem is the missing operand.
  • (D) is wrong: The statement is malformed.

Re-read: Lesson 0.1.3 — The phases of a compiler; symbol table; error handler; which phase catches which error

Q7 Answer: 61 mark

10 + n < 3n ⇒ n > 5 ⇒ 6.

Re-read: Lesson 0.1.1 — Programs, machine code and why we translate; compiler vs interpreter

Q8 Answer: (A) (B) (C)2 marks

Type, declaration position, location and parameter information are stored; run counts are unknown to the compiler.

Re-read: Lesson 0.1.3 — The phases of a compiler; symbol table; error handler; which phase catches which error

Ready for the next idea?

Mark this item complete when you’ve finished reading and working through it.