Write your own compiler, linker author preface

Source: Internet
Author: User

"Write your own compiler, linker" Purchase URL

The paper came to the end of the light, I know this matter to preach.
--Lu You

The whole set of theories of compiling theory and technology occupies a very important position in the field of computer science, and learning it is very helpful to the program designers. We look at history will find that everyone praised the program Design Master is a master in the field of compilation, like the basic language of Bill Gates, Sun's Java father, etc., in the field of compilation has a deep attainments. Bill Gates, who had been sitting on the throne of the world's richest man for years, also started by writing basic language compilers to microcomputers, and it was this basic compiler that laid the groundwork for Bill Gates and Paul Allen's Microsoft Empire. The experience of writing a basic language compiler has opened Bill Gates ' brilliant career.
The compiler is a fairly complex program, writing and even reading a program like this is not easy, and most computer scientists and professionals have never written a complete compiler. However, almost all forms of computation are used by compilers, and any professional working with a computer should have the basic structure and operation of the compiler. In addition, a task frequently encountered in computer applications is the development of command interpreter and interface program, which is smaller than the compiler, but the same technique is used. Therefore, mastering this technology is of great practical significance.
Li Guojie Academician said: "With the rapid development of microprocessor technology, processor performance depends largely on the quality of the compiler, the compiler technology becomes the core technology of the computer, the status becomes more and more important." China should develop its own microprocessor business, must have its own compiler technology as the backing. ”
Back to say what was the reason for my initiation of the idea of writing such a book. The author learns other computer course feeling is not particularly difficult to understand, only see the compiling principle of the textbook, read the foggy, feel smattering, I feel may be learning textbooks too theoretical, so to the bookstore to all the books related to the compilation of the book All Buy home, Of course, this also includes the people generally accepted the compilation of three classic books (Long Shu, Tiger Book, Whale book), each of which I have to go through, as if all understand, and feel to really write a compiler is still only the master to complete, to himself or elusive things. And the author also learned many pessimistic arguments about the practice of compiling principles: "The existing compilers are constructed with Lex and yacc, and it is almost impossible to manually write a complete compiler from scratch." "But the author is the kind of" knowing, undeterred "people, to know that the early compiler can be purely handmade, bitter sour sweet journey began, but write a language compiler? How is this compiler positioned? All this is very vacant.
I began to look at the sample compilation principles, hoping to find inspiration to find the answer to the above questions. The compiler of pl/0 language compiled by world famous computer scientist N.worth is the first compiler to study, it is simple in function, clear in structure and readable, it is considered to be a very suitable learning model of small compiling program, but this compiler does not support array, struct, string, And it is written as an example of a hypothetical stack machine, rather than directly generating a target language program that can run directly in a certain CPU or operating system environment. "pl/0 language Compiler" as a compiler learning model, but also can only be counted "Shorty inside pull General", because no better, also had to use. At this point, the compiler positioning problem is a little bit, the author wants to construct a more suitable for learning compiler. However, another problem ensued, why are so many open source compilers not directly used as a compiler learning model? I started researching the source code for each open source compiler, including the source code for GCC, since GCC supports multiple front-end languages and various backend machine platforms, AST (Abstract Syntax Tree), and RTL (Register Transfer Language) Also become a bypass, have not learned how to write a source language, a target machine compiler, it is necessary to learn to support a variety of source language multiple machine platform compiler, like a baby has not learned to walk to learn to run, it is doomed to fall.
Preface to write the compiler, the linker side is a simplistic compiler learning model, the other side is overly complex open source compilers, as a learning model is not appropriate. Here, the compiler positioning problem is completely thought out, the author wants to construct a learning model to teach you how to write your own compiler. This model consists of two parts, the first part is the language definition, the second part is the implementation of the language compiler, the compiler supports only one source language, and the target language supports only one. The language should have the most important features of the current high-level language. This compiler should be structurally clear, with as little code as possible, to embody the complete process and technique of writing a practical compiler. This compiler can generate EXE files that run directly in the operating system, as long as you double-click or execute on the command line to see the results.
Then the author begins to think about another question, what language compiler to write? The author studies the current most popular programming languages C, C + +, C #, Objectivec, Java, where C is the simplest, only 32 keywords, but the author found that C language is still a lot of redundant components, as a learning model can be more simple. The author finally modeled the C language, making the appropriate simplification to define a new language, with only 15 keywords, called the SC language. Target language Select the familiar Intel x86 machine language and the compiler is named SCC compiler.
In this book, readers will see the complete process from the SC language definition to the development of the SCC compiler. After reading this book you will know how a new language is defined, how a real compiler is written, which will no longer be mysterious to you, the theory of compiling principles and the definition of SC language in this book and the development process of SCC compiler are the best explanations in the field of compiling theory with practice.
As this book as the compiling principle of practical teaching materials, the author proposed to arrange 10 hours teaching.
After the book was submitted, CSDN and "Programmer" magazine editor-in-chief, Liu Jiang teacher read the first draft of this book, and for this book preface, here to Liu Teacher express the most heartfelt thanks.
The book is near the publication, courtesy of Tsinghua University Mr. Wang's original teacher read the final draft, and the manuscript made a fair evaluation: "The book features distinct, content depth, writing is also very good, it is worth publishing." The most important feature of this book is the selected target platform, namely the x86 processor and the COFF target file format of Microsoft System, which is seldom seen in the textbook, which can provide a unique material for compiling teaching practice in China. At the same time, Mr. Wang also made valuable suggestions for the book. Here, to teacher Wang to express their heartfelt respect and the most sincere thanks.
I would also like to thank my family, whose support and encouragement is the guarantee of the completion of this book.
It is impossible to list all the names of people who are helpful in the publication of this book, because some of the difficulties are solved through the Internet, and I don't even know their names. Here, I would like to express my thanks to them!
Finally, recalling this book 6 years of writing process, is willing to pu songling a pair of couplets and readers to share:
There are those who are interested, the things have become, the end of the Hyakuji Qin Guan Chu;
Painstaking people, the days are not negative, hardships, 3,000 more can swallow Wu.

Wang Bojun
January 2015


Write your own compiler, linker author preface

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.