Teach you to do a C language compiler (9): summary

Source: Internet
Author: User
Tags function definition

Congratulations on completing your own C-language compiler, in this chapter we grumble and say something about the problems that should be noted in compiling the compiler. Some of the challenges encountered while writing the compiler.

This series: Hands-on teaching you to do a C language compiler (0): Preface teaches you to do a C language compiler (1): Design hands-on teach you to do a C language compiler (2): Virtual machine hands-on teach you to do a C language compiler (3): Lexical analyzer hands-on teach you to do a C language compiler (4): Hand Fall down hands-on teach you to do a C language compiler (5): variable definition The hand teaches you to do a C language compiler (6): function definition hands-on teach you to do a C language compiler (7): The statement hands-on teach you to do a C language compiler (8): expression virtual machine and target code

In the beginning of the whole series, we started the implementation of the virtual machine. I do not know whether you feel the same, this part of the entire compiler is actually very important to write. I think it accounts for at least 50% of the important level.

To illustrate this point, learning the compiler principle often focuses on lexical analysis and parsing, ignoring the same important code generation. For the study or examination may be, but the actual compilation project, the most important thing is to be able to "run up", so we need to give code generation a high priority.

At the same time, we see that when parsing statements and expressions later, the difficulty is no longer a parsing, but rather how to generate the appropriate assembly code for the operator. Lexical Analysis

We have used very violent means to write our lexical analyzer, I think it is not.

But you can still learn the relevant knowledge, understand the principle of automatic generation of lexical analyzer, it involves "regular expression", "state machine" and so on knowledge. Believe that this part of the knowledge can greatly improve your programming level.

Also, if you still want to write compilers in the future, try these automatic generation tools. Grammar Analysis

For a long time, grammar analysis has been a mystery to me until it is actually implemented in a recursive descent way.

We used a special chapter to explain the relationship between "recursive descent" and BNF grammar. Hope to reduce your aversion to theory. At the very least, it is not too difficult to achieve.

If you are interested, you can learn to learn these grammars because there are many tools that are automatically generated to support them. So you don't have to reinvent the wheel. Can look at YACC and other tools, more advanced version is bsion. Other languages also have a lot of similar support.

Digression, recently known a "PEG grammar" method of expression, whether it is read up, or to achieve, are easier than BNF, you can also learn to see. About Coding

This is also my own feeling it. No matter how good a tutorial, want to fully understand it, the best way I am afraid to do it yourself.

Only in the process of writing code, we will encounter many setbacks, such as the need to consider a lot of details, or debugging is very difficult. But also only really calm down to overcome it, we can grow it.

For example, when writing the parsing of an expression, a large number of repetitive code is especially crashing. There is debugging compiler, simply painful to say nothing.

P.S. If you write your own code in this series, it is helpful to remember to write some of the functions for outputting the assembly code beforehand.

There is to write this series of articles, the beginning of the impulse after, every write a particular upset, I hope the article itself is not affected by my emotions it. Conclusion

Programming fun and boring, only in which we can experience it.

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.