Coder Social home page Coder Social logo

formaltheory's People

Contributors

kendallhopkins avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

Forkers

witrin limexs

formaltheory's Issues

Allow providing an alphabet in ...Token::getNFA and ::getDFA

Allow the user to provide an explicit alphabet for FormalTheory_RegularExpression_Token::getNFA and FormalTheory_RegularExpression_Token::getDFA. You don't necessarily want the set [\0..\x7F].

Here's a patch that implements the idea:

diff --git a/lib/FormalTheory/RegularExpression/Token.php b/lib/FormalTheory/RegularExpression/Token.php
index 1e6899d..763b4c4 100644
--- a/lib/FormalTheory/RegularExpression/Token.php
+++ b/lib/FormalTheory/RegularExpression/Token.php
@@ -42,8 +42,11 @@ abstract class FormalTheory_RegularExpression_Token
 	
 	abstract function getFiniteAutomataClosure();
 	
-	function getNFA()
+	function getNFA( array $alphabet = null )
 	{
+		if( is_null( $alphabet ) ) {
+			$alphabet = array_map( "chr", range( 0, 127 ) );
+		}
 		$create_loop_state = function( FormalTheory_FiniteAutomata $fa ) {
 			$state = $fa->createState();
 			foreach( $fa->getAlphabet() as $symbol ) {
@@ -52,7 +55,7 @@ abstract class FormalTheory_RegularExpression_Token
 			return $state;
 		};
 		
-		$fa = new FormalTheory_FiniteAutomata( array_map( "chr", range( 0, 127 ) ) );
+		$fa = new FormalTheory_FiniteAutomata( $alphabet );
 		
 		$start_states = $fa->createStates( 4 );
 		$end_states = $fa->createStates( 4 );
@@ -76,9 +79,9 @@ abstract class FormalTheory_RegularExpression_Token
 		return $fa;
 	}
 	
-	function getDFA()
+	function getDFA( array $alphabet = null )
 	{
-		$nfa = $this->getNFA();
+		$nfa = $this->getNFA( $alphabet );
 		$dfa = $nfa->isDeterministic() ? $nfa : FormalTheory_FiniteAutomata::determinize( $nfa );
 		unset( $nfa );
 		$dfa->minimize();

Release

Could you tag the latest commit as a stable release?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.