Git Product home page Git Product logo

deterministic-nondeterministic-finite-automata's Introduction

Deterministic & Nondeterministic Finite Automata

A program to determine acceptance of a word



About it

The purpose of this program is to determine whether a word is accepted by a given DFA or NFA.



How to use it

It has builtin a CLI with 3 options:

  • Read a DFA
  • Read a NFA
  • - Both of them open a window to select a text file that contains the graph for the automata.

  • Process a word - read from the STDIN a word and prints whether is it accepted or not.

The text format

The automata expects the input to have this specific format:

node_number _ is_final _ next_node _ letter _ ...

Where:

  • the node number - represents a positive integer for that specific node
  • Note that the node 0 will be always consider the starting node!
  • is_final - a boolean that marks if the node is a terminal one. This should be written as f for a final one and n for a non-terminal one.
  • next_node - represents a positive integer for the next node adjacent
  • letter - is the corresponding letter from the automata's alphabet(it could be also any symbol) that lies on the edge of the connection
  • The three dots marks that we can have any number of nodes linked to this node.

Every node along with its content should be written on a different line.

The program accepts non-completed automata, but must have all nodes declared at least.

Example

Suppose that we have this automata:

The input file for this would be:

0 n 0 1 1 0
1 f 2 0 0 1
2 n 3 2
3 f

But if we wanted a complete automata we would complete the edges with a -1 node that coresponds for the abort state.

0 n 0 1 1 0 -1 2
1 f 2 0 0 1 -1 2
2 n 3 2 -1 0 -1 1
3 f -1 0 -1 1 -1 2



How it works

The program simulates an automata behavior, taking one letter at a time and decides the next node.



Tech specs

It has implemented 2 main classes:

  • Node class - that represents a node in the automata's graph
  • FA class(stands for Finate Automata) - storing the component nodes

The DFA and NFA classes inherits from the FA and adds the main functionallity, validate_word method, which differs between them.

The word validation in a NFA is done by running a backtracking through all nondeterministic nodes, whereas in a DFA is a liniar lookup.

The adjacent nodes are stored as an array of indices that corresponds to the node.
Example:
0 coresponds to node 0, 1 to node 1, ...

The file selector is done using the tkinter module, the root windows is hidden.

deterministic-nondeterministic-finite-automata's People

Contributors

w-i-l avatar

Watchers

 avatar

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.