add: NFA定义
This commit is contained in:
		@@ -5,4 +5,9 @@
 | 
				
			|||||||
    <GenerateDocumentationFile>true</GenerateDocumentationFile>
 | 
					    <GenerateDocumentationFile>true</GenerateDocumentationFile>
 | 
				
			||||||
  </PropertyGroup>
 | 
					  </PropertyGroup>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  <ItemGroup>
 | 
				
			||||||
 | 
					    <Compile Include="LexicalAnalyzer\RegularExpression.fs" />
 | 
				
			||||||
 | 
					    <Compile Include="LexicalAnalyzer\NondeterministicFiniteAutomation.fs" />
 | 
				
			||||||
 | 
					  </ItemGroup>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
</Project>
 | 
					</Project>
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -0,0 +1,38 @@
 | 
				
			|||||||
 | 
					module CanonSharp.Parser.LexicalAnalyzer.NondeterministicFiniteAutomation
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					open System
 | 
				
			||||||
 | 
					open System.Collections.Generic
 | 
				
			||||||
 | 
					open CanonSharp.Parser.LexicalAnalyzer.RegularExpression
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					type NondeterministicState(id: Guid, transaction: Option<char> -> list<NondeterministicState>) =
 | 
				
			||||||
 | 
					    member val id = id
 | 
				
			||||||
 | 
					    member val transaction = transaction
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    override this.GetHashCode() = this.id.GetHashCode()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    new() = NondeterministicState(Guid.NewGuid(), fun a -> list.Empty)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					type NondeterministicFiniteAutomation(states: HashSet<NondeterministicState>, entryTransaction: Option<char> -> list<NondeterministicState>) =
 | 
				
			||||||
 | 
					    member val states = states
 | 
				
			||||||
 | 
					    member val entryTransaction = entryTransaction
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					let convertEmptyToNonDeterministicFiniteAutomation (expression: EmptyExpression) =
 | 
				
			||||||
 | 
					    let final = NondeterministicState()
 | 
				
			||||||
 | 
					    let transaction (a: Option<char>) =
 | 
				
			||||||
 | 
					        match a with
 | 
				
			||||||
 | 
					        | Some _ -> list.Empty
 | 
				
			||||||
 | 
					        | None -> [final]
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    let states = HashSet()
 | 
				
			||||||
 | 
					    let _ = states.Add(final)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    NondeterministicFiniteAutomation(states, transaction)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					let convertToNondeterministicFiniteAutomation expression: RegularExpression =
 | 
				
			||||||
 | 
					    match expression with
 | 
				
			||||||
 | 
					        | EmptyExpression ->
 | 
				
			||||||
							
								
								
									
										12
									
								
								CanonSharp.Parser/LexicalAnalyzer/RegularExpression.fs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										12
									
								
								CanonSharp.Parser/LexicalAnalyzer/RegularExpression.fs
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,12 @@
 | 
				
			|||||||
 | 
					module CanonSharp.Parser.LexicalAnalyzer.RegularExpression
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					type RegularExpression =
 | 
				
			||||||
 | 
					    | EmptyExpression
 | 
				
			||||||
 | 
					    | SymbolExpression of symbol: char
 | 
				
			||||||
 | 
					    | AlternationExpression of left: RegularExpression * right : RegularExpression
 | 
				
			||||||
 | 
					    | ConcatenationExpression of first: RegularExpression * second : RegularExpression
 | 
				
			||||||
 | 
					    | KleeneExpression of expression: RegularExpression
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					let convertToNondeterministicFiniteAutomation expression =
 | 
				
			||||||
 | 
					    match expression with
 | 
				
			||||||
 | 
					    | EmptyExpression emptyExpression ->
 | 
				
			||||||
		Reference in New Issue
	
	Block a user