Skip to content

A library for regular languages: Converting regexen into state machines

License

GPL-3.0, MIT licenses found

Licenses found

GPL-3.0
GPL_LICENSE
MIT
MIT_LICENSE
Notifications You must be signed in to change notification settings

smtlaissezfaire/hopcroft

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Hopcroft

A library for dealing with regular languages: Regexes and State Machines.

Example

If you can understand the following, welcome to the club!

ruby-1.8.6-p383 > Hopcroft::Regex.parse("a|b")
 => #<Hopcroft::Regex::Alternation:0x122698c @expressions=[#<Hopcroft::Regex::Char:0x12240ec @expression="a">, #<Hopcroft::Regex::Char:0x1224a4c @expression="b">]>
ruby-1.8.6-p383 > Hopcroft::Regex.parse("a|b").to_machine
 => #<Hopcroft::Machine::StateMachine:0x121f074 @start_state=State 1 {start: true, final: false, transitions: 2}>
ruby-1.8.6-p383 > Hopcroft::Regex.parse("a|b").to_machine.to_dfa
 => #<Hopcroft::Machine::StateMachine:0x120d630 @start_state=State 12 {start: true, final: false, transitions: 2}>

ruby-1.8.6-p383 > Hopcroft::Regex.parse("a|b").to_machine
 => #<Hopcroft::Machine::StateMachine:0x5f1b1c @start_state=State 24 {start: true, final: false, transitions: 2}>
ruby-1.8.6-p383 > Hopcroft::Regex.parse("a|b").to_machine.state_table
 =>
+-------------+------------+------------+--------------------------------------+
|             | b          | a          | Hopcroft::Machine::EpsilonTransition |
+-------------+------------+------------+--------------------------------------+
| State 32    | * State 33 |            |                                      |
| State 30    |            | * State 31 |                                      |
| -> State 29 |            |            | State 30, State 32                   |
+-------------+------------+------------+--------------------------------------+

ruby-1.8.6-p383 > Hopcroft::Regex.parse("a|b").to_machine.to_dfa.state_table
 =>
+-------------+----------+----------+
|             | a        | b        |
+-------------+----------+----------+
| -> State 21 | State 22 | State 23 |
+-------------+----------+----------+

About

A library for regular languages: Converting regexen into state machines

Resources

License

GPL-3.0, MIT licenses found

Licenses found

GPL-3.0
GPL_LICENSE
MIT
MIT_LICENSE

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages