Conversion between NFA and DFA

Source: Internet
Author: User
Statement

This article summarizes NFA-to-DFA conversion in compilation principles. The code references lexical analysis in compilation principles.

Conversion Method

NFA is not sure about the finite state machine, while DFA is about the finite state machine.

In essence, NFA is equivalent to the DFA constructed by NFA, but there may be multiple paths that exit from a certain state of NFA, therefore, the preceding state set is often abstracted after NFA is constructed to build a DFA with only one exit path for each State.

The NFA-to-DFA constructor is commonly used to construct two points, I .e., subset constructor and closure transfer.

Pseudocode description
1.0-closure (s) the NFA status set 2.0-closure (t) that can be reached from the NFA status s only through 0 Conversion) set of NFA states that can be converted from a certain NFA State S in t only through 0. 3. move (t, a) can be triggered from a certain State in t s only through the conversion of label a to the NFA state set/** subset Construction Method */NFA-DFA-CONVERT (NFA, DFA) S0-> NFA start state U-> 0-closure (S0) push u into DFA without markwhile (t-> find one in DFA without mark) {Mark T; for (every possible intput A) U'-> 0-closure (move (t, a) if (U' is not in DFA) push u'into DFA without markset DFA [t, a]-> U'}/** calculate the closure transfer of 0-closure (t) */closure (t) push all status in T into Stack spush all status in T into uwhile (S is not empty) {T-> pop one from S; for (each status U' that can be converted from the T State through an empty string) if (U' is not in U) {push u'into U; push U' into S ;}} return U;

Summary
Each status of DFA is a secondary abstraction of the NFA status set, so that there is only one exit path for each status.

Conversion between NFA and DFA

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.