Giter Site home page Giter Site logo

rtd's Introduction

rtd

Tool for generating a DFA for a given regular expression. It can either print the DFA's 5-tuple components, or output the DFA as a DOT file.

Steps:

  • Convert the input regex from infix to postfix notation using the shunting yard algorithm.
  • Convert the regex to a λ-NFA using Thompson's construction algorithm.
  • Convert the λ-NFA to a DFA using the powerset construction algorithm.

Operators

  • <s1>|<s2> - Matches either the subexpression <s1> or <s2>
  • <s1><s2> - Matches the subexpression <s1> concatenated with <s2>
  • <s>* - Matches zero or more occurrences of <s>
  • <s>+ - Matches one or more occurrences of <s>
  • <s>? - Matches zero or one occurance of <s>

Building

Dependencies:

  • GCC release >= 10.1 or Clang release >= 16.0.0
  • make
  • graphviz
  • pkg-config

On Debian-based systems, they can usually be installed as follows:

$ sudo apt install g++ make pkg-config libgraphviz-dev

To clone and build the program, run:

$ git clone https://github.com/niculaionut/rtd.git
$ cd rtd
$ make

Examples:

  • Get usage info:
$ ./rtd -h
USAGE:
    rtd [FLAGS/OPTIONS] <regex>

FLAGS:
    -h
        Print help info.
    -a
        Set the alphabet of the regex as all alphanumericals.
    -e
        Export the graph in DOT language (by default, only the DFA components will be printed).

OPTIONS:
    -s <alphabet>
        Set the alphabet of the regex (only alphanumericals allowed).
    -o <output_file>
        Set the path at which the graph file will be written (default is stdout).
  • Get the DFA components for (a|b)*abb:
$ ./rtd '(a|b)*abb'
STATES = {q0, q1, q2, q3, q4}
SIGMA = {a, b}
TRANSITIONS:
        δ(q0, a) = q1
        δ(q0, b) = q2
        δ(q1, a) = q1
        δ(q1, b) = q3
        δ(q2, a) = q1
        δ(q2, b) = q2
        δ(q3, a) = q1
        δ(q3, b) = q4
        δ(q4, a) = q1
        δ(q4, b) = q2
START STATE = q0
FINAL STATES = {q4}
  • Get the visual DFA representation for (a|b)*abb:
$ ./rtd -e '(a|b)*abb' >graph.dot
$ dot -Tsvg graph.dot >graph.svg
$ firefox graph.svg

  • Get the visual DFA representation for the expressions provided as tests:
$ make tests
$ firefox output/*

Resources

rtd's People

Watchers

Nicula Ionuț 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.