3
0
mirror of https://github.com/ergochat/ergo.git synced 2024-11-26 22:09:24 +01:00
ergo/vendor/github.com/goshuirc/e-nfa
2020-02-12 13:19:23 -05:00
..
.travis.yml fix #782 (bring vendor into the main tree) 2020-02-12 13:19:23 -05:00
enfa.go fix #782 (bring vendor into the main tree) 2020-02-12 13:19:23 -05:00
README.md fix #782 (bring vendor into the main tree) 2020-02-12 13:19:23 -05:00

ε-NFA: Epsilon-Nondeterministic finite automaton

GitHub license GoDoc Build Status

image

What is Epsilon-Nondeterministic finite automaton

ε-NFA: Epsilon-Nondeterministic finite automaton (so call:Nondeterministic finite automaton with ε-moves)

In the automata theory, a nondeterministic finite automaton with ε-moves (NFA-ε)(also known as NFA-λ) is an extension of nondeterministic finite automaton(NFA), which allows a transformation to a new state without consuming any input symbols. The transitions without consuming an input symbol are called ε-transitions or λ-transitions. In the state diagrams, they are usually labeled with the Greek letter ε or λ.

(sited from here)

Looking for DFA implement?

I also write a DFA implenent in Go here. https://github.com/kkdai/dfa

Looking for NFA implement?

I also write a NFA implenent in Go here. https://github.com/kkdai/nfa

Installation and Usage

Install

go get github.com/kkdai/e-nfa

Usage

Following is sample code to implement a epsilon-NFA automata diagram as follow:

image

package main

import (
    "github.com/kkdai/enfa"
    "fmt"
)

func main() {

    nfa := NewENFA(0, false)
    nfa.AddState(1, false)
    nfa.AddState(2, false)
    nfa.AddState(3, true)
    nfa.AddState(4, false)
    nfa.AddState(5, false)

    nfa.AddTransition(0, "1", 1)
    nfa.AddTransition(0, "0", 4)

    nfa.AddTransition(1, "1", 2)
    nfa.AddTransition(1, "", 3) //epsilon
    nfa.AddTransition(2, "1", 3)
    nfa.AddTransition(4, "0", 5)
    nfa.AddTransition(4, "", 1, 2) //E -> epsilon B C
    nfa.AddTransition(5, "0", 3)

    nfa.PrintTransitionTable()

    if !nfa.VerifyInputs([]string{"1"}) {
        fmt.Printf("Verify inputs is failed")
    }

    nfa.Reset()

    if !nfa.VerifyInputs([]string{"1", "1", "1"}) {
        fmt.Printf("Verify inputs is failed")
    }

    nfa.Reset()

    if !nfa.VerifyInputs([]string{"0", "1"}) {
        fmt.Printf"Verify inputs is failed")
    }

    nfa.Reset()
    if !nfa.VerifyInputs([]string{"0", "0", "0"}) {
        fmt.Printf("Verify inputs is failed")
    }
}

Inspired By

Project52

It is one of my project 52.

License

This package is licensed under MIT license. See LICENSE for details.