{
// Obtain the NFA that contains the current status.
Nfa;
// Obtain the index in the current state.
Int Index;
// Obtain or set the symbol index in the current state.
Int SymbolIndex;
// Obtain or set the type of the current status.
NfaStateType StateType;
// Obtain the list of character classes corresponding to the transfer of character
is defined to support forward-looking symbols. It may be one of normal, trailinghead, and trailing enumerated values. This attribute will be described in detail in the forward-looking symbols section.
The nfastate class is defined as follows:
Namespace cyjb. compiler. lexer {class nfastate {// obtain the NFA that contains the current status. NFA; // obtain the index of the current status. Int index; //
The DFA (deterministic finite automata), a deterministic finite automaton, refers to a unique next state for each state that is determined by the input alphabet, and the NFA (Nondeterminisic finite Automata) is an indeterminate finite automaton, which means that for any state, when the state obtains the input alphabet, it is possible that the resulting state is not one, but multiple, that is, a set of states. In a sense, DFA is a special form of
the current state.
int symbolindex;
Gets or sets the type of the current state.
Nfastatetype Statetype;
Gets a list of character classes that correspond to the transfer of the character class.
iset
The two attributes I have added to the Nfastate class Nfa and Index are purely for the convenience of state use. $\epsilon$ transfers are defined dire
Before always think oneself is also good, in look at the times of cobalt carbonate, Barret Lee and other great gods are playing the perfect after the superb found I was only a war five slag.To embrace the thigh, to seek the great God,I had an impression that there were a lot of engines, but I didn't know what the engines were.Today read "Proficient in regular expression" only to find traditional nfa,posix NFA
, which greatly extends and enhances the functions of regular expressions. Later, he and Brian kernighan, author of C programming language, have invented the popular awk text editing language. By 1986, regular expressions had a leap. First, Henry Spencer, a top-level hacker in C language, released a library of Regular Expressions written in C Language (not called open source at the time) in the form of source code, so as to bring the mysteries of regular expressions into the ordinary house, then
the figure:
Figure 3.2
A determined state machine representation of the regular expression ba*b
Figure 3.3
An indeterminate state machine representation of the regular expression ba*b
The starting state of the state machine in Figure 3.3 reads the character B and jumps to the middle two states, so the state machine is nondeterministic. In contrast, the state machine in Figure 3.2, although the function is consistent with the state machine in Figure 3.3, is OK. We can also use a special edge f
.
2.DFA and NFA understand DFA and NFAThe regular expression engine is divided into two categories, a class called DFA (deterministic with poor automata), and another class called NFA (non-deterministic with poor automata). Two types of engines to work smoothly, must have a regular and a text string, a pinch in the hand, a eat down. DFA pinch the text string to compare the regular style, see a sub-regular t
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,
know the principle, it is difficult to write highly efficient regular expressions without any hidden risks. Therefore, it is necessary for people who often use regular expressions or are interested in learning Regular Expressions in depth to understand the matching principles of the regular engine.
2. Regular Expression Engine
The RegEx engine can be divided into two types: DFA and NFA, while NFA can be di
1. Why should we understand the Engine Matching Principle?
Note-by-note disorganized combination, the playing may be noise. The same note can be produced through the hands of the composer, A player can also play beautiful music according to music scores, but he/she may not know how to change the combination of music notes to make music more beautiful.
The same applies to regular expressions. If you do not understand the Regular Expression Engine Principle, you can also write regular expressions
1 Why you should know the engine matching principleA combination of notes jumbled together, playing may be the noise, the same notes through the composer's hand, you can draw a very beautiful music, a performer can also play a beautiful music music, but he/she may not know how to change the combination of notes, making the music more beautiful.As a regular user also, do not understand the principle of the regular engine, the same can be written to meet the requirements of the regular, but do not
The NFA that constructs the half (L)Self-handling Baidu space
Original article, paste please stick to the sourceoccasionally some purely theoretical question. This is an advanced algorithm work problem,L is the regular language, and language b is the first half of all the strings in L, proving that B is also regular. objective to define and construct B An NFA, non-deterministic finite state machine.
A program to be converted into a lexical analyzer, the task of the lexical analyzer is to convert the character stream into lexical notation flow, the core of the transformation is a poor automaton representation, there is a poor self-motive and state conversion diagram a bit similar, but it is not a graph, but a recognizer, it is the character of each input to identify and judge, In order to determine the final state or state set and path that it can reach, there are two kinds of poor automata,
Algorithm-Compiler Principle-lexical analyzer-state machine SM. deterministic finite automatic machine DFA. non-deterministic finite automatic machine NFA-Linux general technology-Linux programming and kernel information. See the following for details. /*************************************** ********
Title: StateMachine-NFA-DFA.c
Author:
Time:
**************************************** ********/
/**********
Excerpt from http://www.cnblogs.com/hush/archive/2004/09/06/40361.htmlYesterday and Sumtec talked about automata and grammar analysis, suddenly brain a little confused, put some concepts confused, read a half-day Tsinghua's compiled book also did not understand ... I got up this morning and watched the automata part of discrete mathematics and its applications. It's a foreigner's book that speaks clearly.
Yesterday is mainly the NFA and grammar Analy
1 Why to understand engine matching principle
A jumble of notes, may be the noise, the same note through the composer's hand, you can draw a very beautiful music, a performer can also play the music of the melody, but he/she may not know how to change the combination of notes, make the music more beautiful.
As regular users also, do not understand the principle of the engine, the same can be written to meet the needs of the regular, but do not know the principle, but it is difficult to write e
Use java to convert regular expressions to NFAI used java to implement a conversion program from a regular expression to NFA. below is my code
package com.siwanghu.regextoNFA;public class Node { private int id; private static int ID=0; public Node(){ this.id=ID++; } public int getId() { return id; } public static void reset(){ ID=0; } @Override public String toString() { return id+"";
the starting state, and the second State is the ending state. When the status ends, if you encounter a string that can be accepted by the rule, return to the end status again. In this way, you can use a status chart to represent repetition. For repetition, we can construct a state chart as follows:
??
5: Optional
??
Creating a status chart for optional operations is relatively simple. To complete the optional operations, we need to take the status chart of the current rule if the string prefix
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.