Download presentation
Presentation is loading. Please wait.
1
课程名 编译原理 Compiling Techniques
浙江大学计算机学院与软件学院 编译原理课程组
2
Information Instructor 李莹 cnliying@zju.edu.cn 13335880866
Teacher Assistant 孙煦雪
3
Text Books The Dragon Book: Compilers Principles, Techniques, & Tools, Second Edition, Alfred V. Aho The Tiger Book: Modern Compiler Implementation in C, Andrew Appel
4
Grade Distribution attend class 10% Homework
Class test or Mid-Term Exam 15% Final during exam period: 65%
5
Course Structure Course has theoretical and practical aspects
Compiling Techniques Compiler Design
6
Compiler: why? 1940’s The first electronic computers
Programming in machine language Slow , tedious and error prone 1954 IBM develops the 704 All programming done in assembly Software costs exceeded hardware costs!
7
Compiler: why? Emerge of higher-level languages
with higher-level notations more easily programming Fortran Scientific computation Cobol Business data processing Lisp Symbolic computation
8
Higher-level Language
A compiler For machine Higher-level Language Machine Language For human Compiler
9
Why Study Compilers Basic idea for constructing translators.
Principle and Techniques reusable in other CS domains. Influences hardware design, e.g., RISC, VLIW. Tools (mostly “optimization”) for enhancing software reliability and security. Excellent software-engineering example --- theory meets practice. Essential software tool.
10
A compiler A compiler is a program that can read a program in one language and translate it into an equivalent program in another language Compiler Target Program Source Program Input Output
11
A Interpreter An interpreter directly execute the operations of source program on inputs Interpreter Source program Input Output
12
A language-processing system
13
The structure Two parts of a compiler operate as a sequence of phases
Analysis, front end Synthesis,back end operate as a sequence of phases
14
Lexical Analysis Reads stream of characters
Group the characters into lexemes For each lexemes, output a Token <token-name, attribute-value>
15
Syntax Analysis Reads Token stream
Create tree-like intermediate representation (syntax tree) The grammatical structure of the token stream
16
Semantic Analysis Uses syntax tree information in Symbol table
understand the meaning of program Too hard for compilers only check Semantic consistency Type checking Type conversions (Coercions)
17
Intermediate Code Geneartion
For portability and reuse Before generate target program Generate intermediate representations first Three address code Code sequence One operator Three operands (max)
18
Code Optimization To improve the intermediate code Run faster
Use less memory Consume less power
19
Code Generation Takes an intermediate representation as input
Maps it to target language Registers and memory allocation Translate IR instructions into machine instructions
20
Symbol-Table Management
An essential function of a compiler Records variable names various attributes of them
21
Passes Several phases may be grouped into a pass
A pass reads an input file and writes an output file An example of a pass including: Lexical analysis, parsing, semantic analysis IR generation.
22
Compiler construction tools-1
Some tools could be used to help compiler construction Parser Generators. automatically produce syntax analyzers from a grammatical description of a programming language.Yacc Scanner Generators. produce lexical analyzers from a regular-expression description of the tokens of a language.Lex Syntax-directed translation engines. produce collections of routines for walking a parse tree and generating intermediate code.
23
Compiler construction tools-2
Code-generator generators. produce a code generator from a collection of rules for translating each operation of the intermediate language into the machine language for a target machine. Data-flow analysis engines. facilitate the gathering of information about how values are transmitted from one part of a program to each other part. Compiler-construction toolkit. provide an integrated set of routines for constructing various phases of a compiler.
24
The move to Higher-level Languages
First generation languages: machine languages. Second generation: assembly languages. Third generation: higher-level languages, Fortran, Cobol, Lisp, C…. Forth generation: languages designed for specific applications, NOMAD, SQL Fifth generation: logic- and constraint-based languages, Prolog and OPS5
25
Another classification of languages
Imperative how a computation is to be done C, C++, C#, Java Declarative what computation is to be done ML, Haskell, Prolog Von neumann languages Object-oriented languages Scripting languages
26
Impacts on Compilers Can help promote the use of high-level languages
Compiler writing is challenging. A compiler must translate correctly the potentially infinite set of programs
27
Application of Compiler Technology
Implementation of higher-level programming languages Optimizations for computer architectures Design of new computer architectures Program translations Software productivity tools
28
Optimizations for computer architecture
Parallelism Multi-core, many-core VLIW (very long instruction word), issue multiple operations in parallel Memory hierarchies Several levels of storage The closer, the faster Registers, CPU cache Main memory disks
29
Design of new computer architecture
RISC Specialized architecture VLIW SIMD
30
Program translation Binary translation x86 →Sparc x86 →arm
Hardware synthesis VHDL RTL Database query interpreters Compiled simulation
31
Software Productivity Tools
Type checking Bounds Checking Memory-Management tools Code generators
32
Summary Language Processors Compiler Phases
Machine and Assembly languages Modeling in Compiler Design Code Optimization Higher-level Languages Compilers and Computer Architecture Software Productivity and Software Security Programming Language Basics: Scope Rules, Environments, Block Structure, Parameter Passing, Aliasing
33
The end of Lecture01
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.