0% found this document useful (0 votes)
5 views2 pages

Compiler Design Unit1 Summary

The document outlines the phases of compiler design, including lexical analysis, syntax analysis, semantic analysis, intermediate code generation, code optimization, and code generation, using examples to illustrate each phase. It also compares compilers, interpreters, and translators, and lists tools for compiler construction along with the roles of preprocessors, assemblers, linkers, and loaders. Additionally, it discusses regular expressions for keywords and delimiters, the language processing system, and common errors encountered in compiler phases.

Uploaded by

mansoorphotos42
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views2 pages

Compiler Design Unit1 Summary

The document outlines the phases of compiler design, including lexical analysis, syntax analysis, semantic analysis, intermediate code generation, code optimization, and code generation, using examples to illustrate each phase. It also compares compilers, interpreters, and translators, and lists tools for compiler construction along with the roles of preprocessors, assemblers, linkers, and loaders. Additionally, it discusses regular expressions for keywords and delimiters, the language processing system, and common errors encountered in compiler phases.

Uploaded by

mansoorphotos42
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

Compiler Design - Unit I Summary

1. Phases of Compiler with Example: i = i * 70 + j + 2

Lexical Analysis: Breaks into tokens → id(i), *, num(70), etc.


Syntax Analysis: Constructs a parse tree using grammar rules.
Semantic Analysis: Checks for type errors, symbol declaration.
Intermediate Code Generation: Produces code like t1 = i * 70; t2 = j + 2; i = t1 + t2
Code Optimization: Eliminates redundancy, reuses expressions.
Code Generation: Generates assembly/machine code.
Linking & Loading: Combines object code into an executable.

2. Input/Output of Phases for: amount = principle + rate * 36.0

Lexical: Tokens: id(amount), =, id(principle), +, id(rate), *, num(36.0)


Syntax: Builds valid parse tree.
Semantic: Type compatibility check.
Intermediate Code: t1 = rate * 36.0; t2 = principle + t1; amount = t2
Optimization: Code simplification.
Code Generation: Converts into assembly.
Linker/Loader: Produces executable.

3. a = 2 * (b + c) * (b + c) Through Compiler Phases

Lexical Analysis: Tokens → id(a), =, num(2), *, (, id(b), +, id(c), ), *


Syntax Analysis: Builds parse tree.
Semantic Analysis: Type check on b, c.
Intermediate Code: t1 = b + c; t2 = 2 * t1; t3 = t1 * t2; a = t3
Optimizer: Removes duplicate b+c.
Code Generator: Generates low-level code.

4. i) Compiler vs Interpreter vs Translator

Compiler: Translates entire code to machine code at once.


Interpreter: Executes code line-by-line.
Translator: Converts from one programming language to another.

4. ii) Compiler Construction Tools


 Lex: Lexical analyzer generator.
 YACC: Syntax parser generator.
 AST Builders: Generate abstract syntax trees.
 Debuggers & Profilers: Test and analyze programs.
 Intermediate Code Generators & Optimizers.

5. i) Cousins of the Compiler


 Preprocessor: Handles directives like #define, #include.
 Assembler: Converts assembly to object code.
 Linker: Combines object files into an executable.
 Loader: Loads program into memory for execution.

5. ii) Regular Expressions for Keywords and Delimiters

Keywords: if|else|int|return
Delimiters: [;,\(\)\{\}]
Transition Diagrams:
if → i → f → [accept]
; → ; → [accept]

6. i) Language Processing System

Source Code → Preprocessor → Compiler → Assembler → Linker → Loader → Execution

6. ii) Errors in Compiler Phases


 Lexical: Invalid tokens.
 Syntax: Missing semicolons, brackets.
 Semantic: Type mismatch, undeclared variables.
 Code Generation: Register errors.
 Linker: Undefined symbols.
 Loader: Address resolution failure.

You might also like