0% found this document useful (0 votes)
13 views20 pages

CD Unit1 L1

The document provides an overview of compiler design, focusing on the roles and functions of compilers, including lexical analysis and the translation of source programs into machine code. It discusses the necessity of programming languages and the challenges in compiler writing, highlighting the complexities involved in generating optimal target code. Additionally, it touches on the importance of symbol tables and the various components of a language translator, such as preprocessors and loaders.

Uploaded by

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

CD Unit1 L1

The document provides an overview of compiler design, focusing on the roles and functions of compilers, including lexical analysis and the translation of source programs into machine code. It discusses the necessity of programming languages and the challenges in compiler writing, highlighting the complexities involved in generating optimal target code. Additionally, it touches on the importance of symbol tables and the various components of a language translator, such as preprocessors and loaders.

Uploaded by

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

Compiler Design

• Course Code: CS105101CS


• Unit 1: Introduction and Lexical
Analysis
• Lecture 1: Introduction to Compilers,
Analysis of the source program
Languages

Wall of Love, Paris


Source: Google Images
Languages
§ Why do we need languages?
§ Humans communicate
• Sign language, Body language, Braille
§ Birds communicate
• Mark territories, Attract for mating, Warn danger
§ Animals communicate
• Mark territories, Convey need, Preparation for attack
§ Aliens?
Programming Languages
§ Why do we need programming languages?
§ And why so many?
• What is your first language?
• Telugu?, Hindi?, Yours?
• C.

Source: Google Images


Programming Languages
§ There are some special purpose languages
§ HTML for web pages
§ Latex for document formatting
§ Makefile has a language: smtp
§ How about google search?
§ Filetype: pdf, link:www.cse.nitrr.ac.in
§ Gmail: in:unread, in:starred
Compiler
§ When do we need a Compiler?
Jobs of a Compiler
§ Translate: input language, output language
§ Maintain correctness

§ Be efficient

§ Generate a good language


Good Language (2015)
Good Language (2018)
Good Language (2020)
Compilers work with Strings
§ Characters, words / Tokens, sentences, programs
§ Fun with Strings
§ quick brown fox jumps over the lazy dog
§ stewardesses
§ typewriter
§ skepticisms
§ quine Programs as Data
Analysis of the Source Program
Language Translator
§ Preprocessor: collects source programs, expands macros.
§ Compiler: Translates source program into a low-level assembly.
§ Assembler: Produces (relocatable) machine code.
§ Linker: Resolves external references statically, combines multiple
machine codes.
§ Loader: Loads executable codes into memory, resolves external
references dynamically.
C Language Processing System
Symbol Table
§ Records variable names
§ Collects their attributes
§ Type (int, char)
§ Storage requirement ([30], 1)
§ Type modifiers (const, static)
§ Scope (global, static)
§ Information about arguments (for functions)
§ Efficient insertion, search (sometimes deletion)
§ C: int x, y, z;
§ Pascal: var x, y, z: integer;
Ideal World

Reality
Reality getting Worse
§ I don't have a compiler for this platform.
§ My program compiles with an older version of gcc.
§ My program compiles with the new version but does not run on this new
platform.
§ My program compiles with an older gcc if you disable optimizations.
§ My program compiles if you have llvm 5.4, clang 5.5, gcc 5.0.1 on
x86_64 with lonestar 1.2 or above on Ubuntu 16 or below.
Compiler Writing
§ is challenging.
§ A compiler is a large program.
§ A compiler must translate correctly potentially infinite set of programs
that could be written in the source language.
§ The problem of generating the optimal target code from a source
program is undecidable.
§ Heuristics and Trade-offs.
§ Compilers is an area where Theory meets Practice.

You might also like