principles of compiler design - github pages · •the first compiler had a huge impact on the...
TRANSCRIPT
![Page 1: Principles of Compiler Design - GitHub Pages · •The first compiler had a huge impact on the programming languages and computer science. The whole new field of compiler design was](https://reader033.vdocument.in/reader033/viewer/2022041800/5e50fdad8ffaf21a1a2492ca/html5/thumbnails/1.jpg)
1
Principles of Compiler Design
Amey Karkare Department of Computer Science and
Engineering, IIT Kanpur [email protected]
http://www.cse.iitk.ac.in/~karkare/cs335/
![Page 2: Principles of Compiler Design - GitHub Pages · •The first compiler had a huge impact on the programming languages and computer science. The whole new field of compiler design was](https://reader033.vdocument.in/reader033/viewer/2022041800/5e50fdad8ffaf21a1a2492ca/html5/thumbnails/2.jpg)
Acknowledgements
• Most of the text in the slide is based on classic text Compilers: Principles, Techniques, and Tools by Aho, Sethi, Ullman and Lam
• Slides are modified version of those created by Prof S K Aggarwal, IITK
2
![Page 3: Principles of Compiler Design - GitHub Pages · •The first compiler had a huge impact on the programming languages and computer science. The whole new field of compiler design was](https://reader033.vdocument.in/reader033/viewer/2022041800/5e50fdad8ffaf21a1a2492ca/html5/thumbnails/3.jpg)
3
Motivation
• Language processing is an important component of programming
![Page 4: Principles of Compiler Design - GitHub Pages · •The first compiler had a huge impact on the programming languages and computer science. The whole new field of compiler design was](https://reader033.vdocument.in/reader033/viewer/2022041800/5e50fdad8ffaf21a1a2492ca/html5/thumbnails/4.jpg)
3
Motivation
• Language processing is an important component of programming
• A large number of systems software and application programs require structured input – Operating Systems (command line processing) – Databases (Query language processing) – Type setting systems like Latex
![Page 5: Principles of Compiler Design - GitHub Pages · •The first compiler had a huge impact on the programming languages and computer science. The whole new field of compiler design was](https://reader033.vdocument.in/reader033/viewer/2022041800/5e50fdad8ffaf21a1a2492ca/html5/thumbnails/5.jpg)
3
Motivation
• Language processing is an important component of programming
• A large number of systems software and application programs require structured input – Operating Systems (command line processing) – Databases (Query language processing) – Type setting systems like Latex
• Software quality assurance and
software testing
![Page 6: Principles of Compiler Design - GitHub Pages · •The first compiler had a huge impact on the programming languages and computer science. The whole new field of compiler design was](https://reader033.vdocument.in/reader033/viewer/2022041800/5e50fdad8ffaf21a1a2492ca/html5/thumbnails/6.jpg)
4
• Where ever input has a structure one can think of language processing
Motivation
![Page 7: Principles of Compiler Design - GitHub Pages · •The first compiler had a huge impact on the programming languages and computer science. The whole new field of compiler design was](https://reader033.vdocument.in/reader033/viewer/2022041800/5e50fdad8ffaf21a1a2492ca/html5/thumbnails/7.jpg)
4
• Where ever input has a structure one can think of language processing
• Why study compilers?
– Compilers use the whole spectrum of language processing technology
Motivation
![Page 8: Principles of Compiler Design - GitHub Pages · •The first compiler had a huge impact on the programming languages and computer science. The whole new field of compiler design was](https://reader033.vdocument.in/reader033/viewer/2022041800/5e50fdad8ffaf21a1a2492ca/html5/thumbnails/8.jpg)
5
Expectations?
• What will we learn in the course?
![Page 9: Principles of Compiler Design - GitHub Pages · •The first compiler had a huge impact on the programming languages and computer science. The whole new field of compiler design was](https://reader033.vdocument.in/reader033/viewer/2022041800/5e50fdad8ffaf21a1a2492ca/html5/thumbnails/9.jpg)
6
What do we expect to achieve by the end of the course?
• Knowledge to design, develop, understand, modify/enhance, and maintain compilers for (even complex!) programming languages
![Page 10: Principles of Compiler Design - GitHub Pages · •The first compiler had a huge impact on the programming languages and computer science. The whole new field of compiler design was](https://reader033.vdocument.in/reader033/viewer/2022041800/5e50fdad8ffaf21a1a2492ca/html5/thumbnails/10.jpg)
6
What do we expect to achieve by the end of the course?
• Knowledge to design, develop, understand, modify/enhance, and maintain compilers for (even complex!) programming languages
• Confidence to use language processing technology for software development
![Page 11: Principles of Compiler Design - GitHub Pages · •The first compiler had a huge impact on the programming languages and computer science. The whole new field of compiler design was](https://reader033.vdocument.in/reader033/viewer/2022041800/5e50fdad8ffaf21a1a2492ca/html5/thumbnails/11.jpg)
7
Organization of the course •Assignments 10%
•Mid semester exam 20%
•End semester exam 35%
•Course Project 35% – Group of 2/3/4 (to be decided)
•Tentative
![Page 12: Principles of Compiler Design - GitHub Pages · •The first compiler had a huge impact on the programming languages and computer science. The whole new field of compiler design was](https://reader033.vdocument.in/reader033/viewer/2022041800/5e50fdad8ffaf21a1a2492ca/html5/thumbnails/12.jpg)
8
Bit of History • How are programming languages implemented? Two
major strategies: – Interpreters (old and much less studied) – Compilers (very well understood with
mathematical foundations)
![Page 13: Principles of Compiler Design - GitHub Pages · •The first compiler had a huge impact on the programming languages and computer science. The whole new field of compiler design was](https://reader033.vdocument.in/reader033/viewer/2022041800/5e50fdad8ffaf21a1a2492ca/html5/thumbnails/13.jpg)
8
Bit of History • How are programming languages implemented? Two
major strategies: – Interpreters (old and much less studied) – Compilers (very well understood with
mathematical foundations)
• Some environments provide both interpreter and compiler. Lisp, scheme etc. provide – Interpreter for development – Compiler for deployment –
![Page 14: Principles of Compiler Design - GitHub Pages · •The first compiler had a huge impact on the programming languages and computer science. The whole new field of compiler design was](https://reader033.vdocument.in/reader033/viewer/2022041800/5e50fdad8ffaf21a1a2492ca/html5/thumbnails/14.jpg)
8
Bit of History • How are programming languages implemented? Two
major strategies: – Interpreters (old and much less studied) – Compilers (very well understood with
mathematical foundations)
• Some environments provide both interpreter and compiler. Lisp, scheme etc. provide – Interpreter for development – Compiler for deployment
• Java – Java compiler: Java to interpretable bytecode – Java JIT: bytecode to executable image
![Page 15: Principles of Compiler Design - GitHub Pages · •The first compiler had a huge impact on the programming languages and computer science. The whole new field of compiler design was](https://reader033.vdocument.in/reader033/viewer/2022041800/5e50fdad8ffaf21a1a2492ca/html5/thumbnails/15.jpg)
9
Some early machines and implementations
• IBM developed 704 in 1954. All programming was done in assembly language. Cost of software development far exceeded cost of hardware. Low productivity.
![Page 16: Principles of Compiler Design - GitHub Pages · •The first compiler had a huge impact on the programming languages and computer science. The whole new field of compiler design was](https://reader033.vdocument.in/reader033/viewer/2022041800/5e50fdad8ffaf21a1a2492ca/html5/thumbnails/16.jpg)
9
Some early machines and implementations
• IBM developed 704 in 1954. All programming was done in assembly language. Cost of software development far exceeded cost of hardware. Low productivity.
• Speedcoding interpreter: programs
ran about 10 times slower than hand written assembly code
![Page 17: Principles of Compiler Design - GitHub Pages · •The first compiler had a huge impact on the programming languages and computer science. The whole new field of compiler design was](https://reader033.vdocument.in/reader033/viewer/2022041800/5e50fdad8ffaf21a1a2492ca/html5/thumbnails/17.jpg)
9
Some early machines and implementations
• IBM developed 704 in 1954. All programming was done in assembly language. Cost of software development far exceeded cost of hardware. Low productivity.
• Speedcoding interpreter: programs
ran about 10 times slower than hand written assembly code
• John Backus (in 1954): Proposed a
program that translated high level expressions into native machine code. Skeptism all around. Most people thought it was impossible
![Page 18: Principles of Compiler Design - GitHub Pages · •The first compiler had a huge impact on the programming languages and computer science. The whole new field of compiler design was](https://reader033.vdocument.in/reader033/viewer/2022041800/5e50fdad8ffaf21a1a2492ca/html5/thumbnails/18.jpg)
9
Some early machines and implementations
• IBM developed 704 in 1954. All programming was done in assembly language. Cost of software development far exceeded cost of hardware. Low productivity.
• Speedcoding interpreter: programs
ran about 10 times slower than hand written assembly code
• John Backus (in 1954): Proposed a
program that translated high level expressions into native machine code. Skeptism all around. Most people thought it was impossible
• Fortran I project (1954-1957): The
first compiler was released
![Page 19: Principles of Compiler Design - GitHub Pages · •The first compiler had a huge impact on the programming languages and computer science. The whole new field of compiler design was](https://reader033.vdocument.in/reader033/viewer/2022041800/5e50fdad8ffaf21a1a2492ca/html5/thumbnails/19.jpg)
10
Fortran I • The first compiler had a huge impact on the
programming languages and computer science. The whole new field of compiler design was started
![Page 20: Principles of Compiler Design - GitHub Pages · •The first compiler had a huge impact on the programming languages and computer science. The whole new field of compiler design was](https://reader033.vdocument.in/reader033/viewer/2022041800/5e50fdad8ffaf21a1a2492ca/html5/thumbnails/20.jpg)
10
Fortran I • The first compiler had a huge impact on the
programming languages and computer science. The whole new field of compiler design was started
• More than half the programmers were using Fortran
by 1958
![Page 21: Principles of Compiler Design - GitHub Pages · •The first compiler had a huge impact on the programming languages and computer science. The whole new field of compiler design was](https://reader033.vdocument.in/reader033/viewer/2022041800/5e50fdad8ffaf21a1a2492ca/html5/thumbnails/21.jpg)
10
Fortran I • The first compiler had a huge impact on the
programming languages and computer science. The whole new field of compiler design was started
• More than half the programmers were using Fortran
by 1958 • The development time was cut down to half
![Page 22: Principles of Compiler Design - GitHub Pages · •The first compiler had a huge impact on the programming languages and computer science. The whole new field of compiler design was](https://reader033.vdocument.in/reader033/viewer/2022041800/5e50fdad8ffaf21a1a2492ca/html5/thumbnails/22.jpg)
10
Fortran I • The first compiler had a huge impact on the
programming languages and computer science. The whole new field of compiler design was started
• More than half the programmers were using Fortran
by 1958 • The development time was cut down to half • Led to enormous amount of theoretical work (lexical
analysis, parsing, optimization, structured programming, code generation, error recovery etc.)
![Page 23: Principles of Compiler Design - GitHub Pages · •The first compiler had a huge impact on the programming languages and computer science. The whole new field of compiler design was](https://reader033.vdocument.in/reader033/viewer/2022041800/5e50fdad8ffaf21a1a2492ca/html5/thumbnails/23.jpg)
10
Fortran I • The first compiler had a huge impact on the
programming languages and computer science. The whole new field of compiler design was started
• More than half the programmers were using Fortran
by 1958 • The development time was cut down to half • Led to enormous amount of theoretical work (lexical
analysis, parsing, optimization, structured programming, code generation, error recovery etc.)
• Modern compilers preserve the basic structure of
the Fortran I compiler !!!
![Page 24: Principles of Compiler Design - GitHub Pages · •The first compiler had a huge impact on the programming languages and computer science. The whole new field of compiler design was](https://reader033.vdocument.in/reader033/viewer/2022041800/5e50fdad8ffaf21a1a2492ca/html5/thumbnails/24.jpg)
11
The big picture • Compiler is part of program
development environment • The other typical components of this
environment are editor, assembler, linker, loader, debugger, profiler etc.
• The compiler (and all other tools)
must support each other for easy program development
![Page 25: Principles of Compiler Design - GitHub Pages · •The first compiler had a huge impact on the programming languages and computer science. The whole new field of compiler design was](https://reader033.vdocument.in/reader033/viewer/2022041800/5e50fdad8ffaf21a1a2492ca/html5/thumbnails/25.jpg)
12
Editor
Programmer Source Program
![Page 26: Principles of Compiler Design - GitHub Pages · •The first compiler had a huge impact on the programming languages and computer science. The whole new field of compiler design was](https://reader033.vdocument.in/reader033/viewer/2022041800/5e50fdad8ffaf21a1a2492ca/html5/thumbnails/26.jpg)
12
Editor Compiler
Programmer Source Program
Assembly code
![Page 27: Principles of Compiler Design - GitHub Pages · •The first compiler had a huge impact on the programming languages and computer science. The whole new field of compiler design was](https://reader033.vdocument.in/reader033/viewer/2022041800/5e50fdad8ffaf21a1a2492ca/html5/thumbnails/27.jpg)
12
Editor Compiler Assembler
Programmer Source Program
Assembly code
Machine Code
![Page 28: Principles of Compiler Design - GitHub Pages · •The first compiler had a huge impact on the programming languages and computer science. The whole new field of compiler design was](https://reader033.vdocument.in/reader033/viewer/2022041800/5e50fdad8ffaf21a1a2492ca/html5/thumbnails/28.jpg)
12
Editor Compiler Assembler
Linker
Programmer Source Program
Assembly code
Machine Code
Resolved Machine Code
![Page 29: Principles of Compiler Design - GitHub Pages · •The first compiler had a huge impact on the programming languages and computer science. The whole new field of compiler design was](https://reader033.vdocument.in/reader033/viewer/2022041800/5e50fdad8ffaf21a1a2492ca/html5/thumbnails/29.jpg)
12
Editor Compiler Assembler
Linker
Loader
Programmer Source Program
Assembly code
Machine Code
Resolved Machine Code
Executable Image
Execution on the target machine
![Page 30: Principles of Compiler Design - GitHub Pages · •The first compiler had a huge impact on the programming languages and computer science. The whole new field of compiler design was](https://reader033.vdocument.in/reader033/viewer/2022041800/5e50fdad8ffaf21a1a2492ca/html5/thumbnails/30.jpg)
12
Editor Compiler Assembler
Linker
Loader
Programmer Source Program
Assembly code
Machine Code
Resolved Machine Code
Executable Image
Execution on the target machine
Normally end up with error
![Page 31: Principles of Compiler Design - GitHub Pages · •The first compiler had a huge impact on the programming languages and computer science. The whole new field of compiler design was](https://reader033.vdocument.in/reader033/viewer/2022041800/5e50fdad8ffaf21a1a2492ca/html5/thumbnails/31.jpg)
12
Editor Compiler Assembler
Linker
Loader Debugger
Programmer Source Program
Assembly code
Machine Code
Resolved Machine Code
Executable Image
Debugging results
Execution on the target machine
Normally end up with error
Execute under Control of debugger
![Page 32: Principles of Compiler Design - GitHub Pages · •The first compiler had a huge impact on the programming languages and computer science. The whole new field of compiler design was](https://reader033.vdocument.in/reader033/viewer/2022041800/5e50fdad8ffaf21a1a2492ca/html5/thumbnails/32.jpg)
12
Editor Compiler Assembler
Linker
Loader Debugger
Programmer Source Program
Assembly code
Machine Code
Resolved Machine Code
Executable Image
Debugging results
Programmer does manual correction of the code
Execution on the target machine
Normally end up with error
Execute under Control of debugger