Turn: Let's talk about the Compilation Principle and Its Application in Web development 3

Source: Internet
Author: User

The last two examples of JSON analysis illustrate the process of lexical analysis and syntax analysis. In this article, I will talk about some of my ideas.

The theoretical basis of lexical analysis and syntax analysis is the theory of automatic machines. Some people may think that the theory is hard to learn and difficult to use. In fact, we don't have to stick to its theory. As long as we know that in a large loop, we need to use a large number of IF Statements to determine, according to the object to be analyzed to generate the corresponding object boundary conditions. The most difficult part of lexical or Syntax Parsing is how we can understand the lexical or syntax. To prove this, we need to draw a DFA or NFA diagram, once these images are implemented, the coding process is purely mechanical.

During years of development, we often hear the idea that compilation principles are useless. But to be honest, in the Web (. net) in development, we really seldom need to parse something on our own, because. net itself has provided us with enough parsing tools and good tests. However, if we want to grasp the bottom layer and process all the Web requests on our own, it is really necessary to implement something similar to the compiler, it is also necessary to parse something.

For example, the most popular MVC development methods, the major MVC frameworks on the Internet all have their own template syntax, to implement such a type of template syntax, you need to use the knowledge of compilation principles. For C #ProgramFor example, the template syntax of class C # syntax requires the least time to learn, but at that time I could not find it suitable, so I implemented a parsing of the template syntax.Algorithm. At the beginning, I also experienced a lot of detours. At the beginning, it took me a lot of time to implement an abstract syntax tree as described in the textbook, in addition, the structure of the self-implemented tree is not very reasonable, and it is not easy to expand. In the end, I almost confused myself. With the continuous summarization and reference of a large number of existing CompilersCodeGradually, I found this method of Object-based construction. Its advantage is that the algorithm is concise, easy to implement, and easy to expand.

Let's talk about some messy things. There is no theme here.

Reconstruction is very important in our daily development, and the reconstruction tools provided by the development environment are also very powerful, however, it cannot be completely reconstructed based on the organization of our current project. Therefore, if we can implement custom refactoring tools based on the organization form and the characteristics of our projects, we will be able to cope with the changes well, instead of being passive.

I have been searching for a parser for analyzing SQL statements, but I have not found an open source parser. Maybe one day I will try to implement such a tool, the main task for future project development is to write the stored procedure.

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.