Read the Book of Dragons compilation Principle hand-written lexical generator (3) ...

Source: Internet
Author: User

Today, a night has been finished, it feels like to say the experience it ... In fact, the course itself has provided the relevant algorithm pseudo-code, then there should be no problem in the thinking, then finally I used a night to complete the final Hopcroft algorithm ... In fact, the difficulty lies in the use of data structures, this side of the graph theory algorithm familiar words should feel relaxed some ... (Unfortunately I have not yet learned the algorithm ...) In terms of the specific code implementation itself, the first difficulty lies in how to split the existing state, compared to say that it is a splitting, but the actual operation is a bunch of DFA, I just started to prepare a state (for the third question of the representation of the data structure, Similar to the 12th step of Nfastate and dfastate) in the detection process will belong to a different state set of nodes to save, and then to guide the different states of the node in a different state node (actually here is a string instead of one), In a node that directs the same state, it is saved with next in Dfastate, and then I overlook a problem that was the fatal flaw in my original design that directly led me to debug for 2 hours, that is, if I save it this way, Then the information of next in the node will change, because in the final state it still depends on saving the first dfastate by the Dfastate's next to connect the other dfastate to connect the whole node graph, then two places actually use next to save the information, The result of the conflict is an infinite loop, and I debug for 2 hours in a baffling wireless-based cycle ... My tears fell when I found this problem ... Finally I used the ArrayList to save the 2 nodes I'm going to split ... Another difficulty is that you have to constantly in the 3, 4 layers of nested loops to stay awake, my advice is to draw the analysis side of the writing, otherwise it is easy to come back to the toilet of their own confused forced ... The reason that can be done so quickly thanks to the Java GC mechanism, I feel that if it is C or C + +, then I this program, OH da ...

Finally, attach the code link and test results:

Https://github.com/zhang77595103/lexerGenerator

Read the Book of Dragons compilation Principle hand-written lexical generator (3) ...

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.