What is the compiler
To a certain kind of language program (called the source language program) equivalently converted
into another language program program (called the target language program) of
high-level language compiler translation program needs to become a machine language program (object program) The machine can run the results become
Compiler:
1. Diagnosis compiler (Compiler the Diagnostic)
2. optimizing compiler (Optimizing Compiler)
3. cross compiler (Compiler Cross)
4. variable target compiler (Retargetable Compiler)
interpreter (Interpreter)
to write the source language as the input source, but do not produce the target
program, but rather execute the source side edge interpretation
Why study compiler theory
Understand computing system
Design Computing System
Training of computational thinking (Computational Thinking)
The basic concept of computational thinking
Jeannette M. Wing, Computational Thinking,
Communications of ACM, Vol.49, No. 3, 2006,
pp.33-35.
Is considered the most basic, long-term over the past decade produced
academic thought , 21st century computer science research and education hot
spot
- Computational thinking is the use of the basic concepts of computer science to solving problems,
designing systems and understanding human behavior, which includes a wide range
of computer science way of thinking - Computational thinking and reading, writing and arithmetic, as is everyone in the 21st century
people's basic skills, not just part of computer scientists - Computational thinking in biology, physics, chemistry, economics, statistics, etc.
affect other disciplines have appeared
computational thinking includes a broad range of computer science way of thinking: - abstract
- Ignore those aspects of a topic unrelated to the current problem (or goal),
in order to more fully pay attention to aspects related to the current problem (or goal) - Drawn from a number of things in common the characteristic, essential, rounded
abandon its non-essential features - Is a general grasp from the individual, from the phenomenon of cognitive grasp the essence over
the process and thinking - Turing machine is a kind of abstract
- Translation principle of "abstract"
- Finite Automata
- Formal grammar
- automation
- The result of abstract thinking on the computer to achieve, is a calculated
thought the results of physical and chemical process, but also the theoretical results applied technology
practice - Automated way of thinking is not only reflected in the work of the compiler itself
on the mechanism, but also in the research and generation tools, compiler
design - Translation principle of "automation"
- Finite Automata
- Predictive analysis program
- Operator priority analysis
- LR analysis
- …
- Problem decomposition
- Decomposition (Decomposition)
- The massive complex problem into if
dry a smaller, simpler to ask
questions to be addressed - A clear description of the problem itself, and ask
questions to make global decisions Solution - The problem is decomposed into relatively independent sub-problems
- In the same way again into sub-questions for each
step precise, until the problem
clear answer - Decomposition (Decomposition)
- Hierarchical management
- Translation principle "problem decomposition"
- Why compiler intermediate language introduced?
- Why does the compiler into phases?
- Why analysis process is divided into many times?
- …
- Recursion
- Recursion (Recursion)
- Solve the problem depends on solving similar problems, but the latter's
complexity or scale smaller than the original problem - Once the complexity and scale of Jane enough hours to ask questions of
the theme is actually very simple solution - Translation principle of "recursion"
- Recursive descent analysis
- Calculated based on the attribute tree traversal
- Syntax-directed translation
- …
- trade off
- Weigh (compromise, Tradeoff)
- Vs. theory can be achieved realistically achievable
- The method of problem solving theoretical research focuses on exploring for theoretical results
of the research they need to make use of the ability to weigh in and use of - Translation principle of "trade-offs"
- With the context-free grammar to describe and deal with high-level programming language
- The choice of optimization measures
- ...
- Protection, redundancy, fault tolerance, error correction and recovery
- Heuristic reasoning to seek answers
- In the uncertainty of planning, scheduling and learning
...
Compiler theory
- Compiler theory and technology
- Computer Science and Technology in the best example of the combination of theory and practice
- ACM Turing Award
- Awarded scientists have made outstanding contributions in the field of computer technology
- Programming language, compiler-related winners are the most
- Compiler theory and technology
- Computer Science and Technology in the best example of the combination of theory and practice
- It embodies a lot of the typical methods of computational thinking
- Compiler theory and methods of application
- Html / XML analysis
- Language processing tools
search engine
Compilation
The compiler is how the high-level languages (such as C ++) translated into low- Level language (machine instructions)?
- The English translated into Chinese
- Identified sentence of a word --- lexical analysis
- Analysis of the grammatical structure of the sentence --- parsing
- Preliminary translation --- intermediate code is generated according to the meaning of the sentence
- Modified to optimize the translation ---
- Write the final object code generated translation ---
These are the five stages of the compiler work - Compiling process - Lexical Analysis
- Task: input source program, the source of character strings is
scanned and decomposed, recognized word symbols - Follow the principle: word formation rules
- Description tools: Finite Automata
for i: = 1 to 100 do
substantially constant integer number word identifier assignment substantially constant substantially the entire word word - Compilation - parsing
- Tasks: On the basis of lexical analysis, according to the rules of grammar
word symbol string broken down into various types of grammatical unit (grammatical category) - Follow the principle: the rules of grammar
- Description Tool: context-free grammar
Z: = X + 0.618 * Y ( arithmetic expression - "arithmetic expression -" assignment) - Compilation process - the intermediate code generator
- Task: all kinds of grammatical unit according to preliminary translation language semantics
- Follow the principle: semantic rules
- Description tools: attribute grammars
- Intermediate code: Formula three yuan, quaternary formula, trees, ...
- Z: = X + 0.618 * Y is translated into four yuan
| ID | OPR | OPN1 | OPN2 | RESULT | comment |
|: -: |: -: |: -: |: -: |: - -: |: -: |: -: |
| (. 1) | * | 0.618 | the Y | Tl | Tl: the Y = 0.618 * |
| (2) | + | X-| Tl | T2 | T2: = X- Tl + |
| (. 3) |: = | T2 | | the Z | the Z: T2 = | - Compilation process - optimization (; e.g. multiplication becomes addition)
- Task: the intermediate stage before the code generated by conversion processing,
in order to produce more efficient object code in the last stage Follow the principle: the equivalent transformation rules of procedure
- Compilation - object code generated
- Task: The intermediate code into object code for a particular machine
- Dependent on the hardware structure and meaning of machine instructions
- Object code three forms
- Assembler instruction code: subject to assembly
- Absolute command codes: Can be directly run
Relocatable instruction codes: need to connect
Structure compiler
- The total box compiler
- ------ lexical analyzer source
- ------ parser intermediate code (quaternion type)
- And semantic analysis grammar intermediate code generator unit ------
- Optimized object code segment ------
- ------ object code intermediate code generator (quaternion type)
- Error handling
- Error Handler
- Discover the source of the error, the error related information is reported to the user
- Grammatical errors
- Error source program does not comply with the syntax (or lexical) rules
- Illegal character, the brackets do not match, missing;, ...
- Semantic errors
- Error source program does not comply with the rules of semantics
- Description of the error, the scope of errors, inconsistencies type, ...
- all over
- The so-called "over" is an intermediate representation of the source code or source code
from start to finish scanning again - All over the stage and is a different concept
- Again it may consist of several segments
- A stage can be divided into several times to complete
- Front-end and back-end compiler
- Compiler front-end
- For the source language, such as lexical analysis, syntax analysis, and semantic analysis of
the intermediate code generation, machine independent optimizations - Compiler backend
- And target-related, related to the target machine optimization, object code generated
- Benefits
- Clear and logical structure of the program
- Optimization fuller, conducive to transplant
A compiled program
- In assembly language and machine language as a tool
- Advantage: for a specific machine, a full computer system
functionality; high efficiency program generated - Disadvantages: the program difficult to read, difficult to write, error-prone, difficult to maintain, production efficiency
is low - Written in high-level language
- The program easy to read, easy to understand, easy maintenance, high production efficiency
- Use of existing compilers implement a language other languages compiled
translation program - Transplantation
- The compiler on a machine to another machine transplanted
- Since the compilation method
- The compiler automatically generates
- Compiler - compilers, compiler generator, compiler book
writing system - LEX: lexical analyzer generator
- YACC: parser generator