GithubHelp home page GithubHelp logo

georgesittas / regex-interpreter Goto Github PK

View Code? Open in Web Editor NEW
3.0 1.0 1.0 30 KB

Simple regular expression interpreter

Haskell 100.00%
regex interpreter parsec haskell thompson-construction regular-expression

regex-interpreter's Introduction

Regex Interpreter

The interpreter consists of the following phases:

  1. Parse a regular expression
  2. Create an NFA for it by walking the produced parse tree
  3. Convert the NFA to an equivalent DFA
  4. Compute the DFA's result by feeding it the input string

The following algorithms have been implemented:

Syntax

The interpreter expects regular expressions to conform to the following syntax:

  • x, a single character.
  • "_", the empty symbol.
  • ".", any character.
  • (r), r is a regular expression.
  • r1 | r2, r1 and r2 are regular expressions (Union).
  • r1r2, r1 and r2 are regular expressions (Concatenation).
  • r*, r is a regular expression (Kleene star).

Functions

The following functions can be used after loading RegInterpreter.hs:

  • makeNfa receives a regular expression ([Char]) & returns an NFA (Fsa).
  • nfaToDfa receives an NFA (Fsa) & returns a DFA (Fsa).
  • regexFullMatch receives a tuple (regex, string) & returns True if string is accepted by regex.
  • regexPartMatch receives a tuple (regex, string) & returns all prefixes in string accepted by regex.

Testing

  Regex-Interpreter git:(main) ghci testSuite.hs
GHCi, version 9.2.4: https://www.haskell.org/ghc/  :? for help
[1 of 3] Compiling RegParser        ( RegParser.hs, interpreted )
[2 of 3] Compiling RegInterpreter   ( RegInterpreter.hs, interpreted )
[3 of 3] Compiling Main             ( testSuite.hs, interpreted )
Ok, three modules loaded.
ghci> testAll
True

Contributors

George Sittas
Jim Rontogiannis

regex-interpreter's People

Contributors

georgesittas avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar

Forkers

rondojim

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.