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

Source: Internet
Author: User

Today AI test is still smooth, no will do, at present also did not find the wrong, in this way also talk about AI, I do not choose AI, always feel theory is too strong, learn not to go, experienced sophomore this semester of theoretical study, this AI is God class Ah, really afraid, junior to the United Kingdom certainly not choose AI ... In fact, even in this afternoon in the exam I have been thinking about my lexical generator ... 6 points after the test, rest a wave of about 8 points began to continue to write my lexical generator of the second part (from the NFA to DFA), the process is still smooth, 2 hours or so finished, after brushing the brush to the present, is really a waste of time ah ... I'll write it tomorrow. The last part of this simple lexical analyzer generator is even finished ... Because you want to share the code with some friends in the group ... So today in advance on the GitHub, links posted below, interested friends can go to see ...

Https://github.com/zhang77595103/lexerGenerator

This is the test result ...

Talk about this part of the experience, the difficulty is not in the algorithm, but around the algorithm how reasonable use of data structures, such as I used a hashset inside the dfastate to manage the dfastate inside the nfastate, The goal is to determine whether the state has been added to the dfastate when a new production is made, because Java default hashset has rewritten the Equals () method, and two hashset are equal as long as the elements inside are equal. Of course, you can also directly in the DFA structure to change the state to HashSet is also possible, while in the subset of the construction of the worklist I used the stack, the purpose is not to repeat the scan dfastate, think of these data structure if you use C, you have to do it all yourself, The amount of work is not a little bit more than two ... There are also some small details that could lead to a wireless loop, for example, when you add Nfastate to Dfastate, you must now assign the Nfastate.next value to null (because you'll see that it's actually nfastate the nodes that were left in the previous process. No, it turns out to be wrong, not to say, and it could be a dead loop ...

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

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.