Detailed explanation of PC-side WeChat code scanning registration and login example code

高洛峰
Release: 2017-03-14 13:37:30
Original
5699 people have browsed it

This article explains in detail the PC-side WeChat code scanning registration and login example code

After writing the lexical part, there are a lot of chores, and I finally have time on the weekend to implement the great grammar parsing part.

After finishing the code, I found that the program was too short. Not counting the state machine, it only had 186 lines (including comments), and the key code was less than 100 lines. After running Debugging, I found that it was OK. It can actually parse function.php in OneThink. This file can be called the master of Php programs. There are all kinds of monsters and monsters in it. It is really painful to debug it. Of course I won’t tell you, haha

Detailed explanation of PC-side WeChat code scanning registration and login example code

Since the program is too short, I’m going to explain it in detail in case everyone doesn’t understand. The secret:)

We know that grammar analysis generally includes LL(1), LR(0), SLR(1), LALR(1), LR(1) and other analysis methods. The more common ones are LL(1),LR(0)

. This analysis method scans from left to right and deduces to the far left; LR scans from left to right and deduces to the right; LL adopts LR uses a prediction table, while LR uses an analysis table; the difficulty of LR is higher than that of LL, and its analytical ability is also higher than that of LL. Moreover, LR has more changes. Therefore, for such a fun project, of course, LR must be used to steadily create (zhuang) new (bi).

The model of the LR analyzer is as shown below.

Detailed explanation of PC-side WeChat code scanning registration and login example code

Includes two stacks, the most important of which is generating LR analysis tables. Of course, I am not going to follow the classic methods in the textbook honestly. How to create (tou) new (lan)? This is the key.

We see that SLR(1), LALR(1), and LR(1) are all improvements to LR(0). The most important one is (1), which represents looking forward. Why look forward? To reduce the size of the analysis table. There are countless possibilities in the future. Looking forward, the possibilities decrease and the scale of analysis will also be greatly reduced. If we want to reduce the scale of analysis, we must look forward, and the more we look, the smaller the analysis table will be, and conversely, the more difficult programming will be. So, is there a way for me to make money while standing without looking forward, without increasing the difficulty and reducing the analysis table?

Yes, there really is. This is not a problem for a senior lazy man. We know that the need to look forward comes from grammarexpression: such as A → Abc, the longer the length of its single expression, the greater the uncertainty. Therefore, limiting the maximum length of method expressions can ensure 100% certainty within this length, and there is no need to look ahead at all. I named this method limited length LR, that is, LLLR(0,n), n>=3.

So, this time I naturally chose LLLR(0,3) as the analysis method, and for the convenience of implementation, I decided not to save the state, so there is no need to generate an analysis table, and the table will not be generated. The table is no longer generated...

Damn it! This is too lazy. Not saving the state means that you need to search from the beginning every time. Efficiency is the life of a programmer!

Don't worry, the maximum length of the expression is 3, and the maximum search step is 3 steps. Don't worry, that's it. :)

This is the secret of the 100-line ultra-simple Php compiler. How about, let’s create something new (bi). The source code is here: converterV0.4.

zip Enjoy!

The above is the detailed content of Detailed explanation of PC-side WeChat code scanning registration and login example code. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template