GithubHelp home page GithubHelp logo

2188886665 / glushkov-algorithm-in-lua Goto Github PK

View Code? Open in Web Editor NEW

This project forked from dzchoi/glushkov-algorithm-in-lua

0.0 1.0 0.0 5 KB

A regular expression matcher in Lua using Glushkov's algorithm

Lua 100.00%

glushkov-algorithm-in-lua's Introduction

Glushkov's algorithm in Lua

In computer science theory - particularly formal language theory - the Glushkov Construction Algorithm (GCA) transforms a given regular expression into an equivalent nondeterministic finite automaton (NFA). Thus, it forms a bridge between regular expressions and nondeterministic finite automata: two abstract representations of formal languages.

The NFA format is better suited for execution on a computer when regular expressions are used. These expressions may be used to describe advanced search patterns in "find and replace" like operations of text processing utilities. This algorithm can be considered a compiler from a regular expression to an NFA, which is why this algorithm is of practical interest. Furthermore, the automaton is small by nature as the number of states is equal to the number of letters of the regular expression, plus one.

This program does:

  • implement the Glushkov's algorithm in Lua,
  • use OOP technique of the inheritance and the derivation written in Lua for defining a Glushkov NFA internally, and
  • include a regular expression engine only (does not include a text parser for regular expressions.)

Supported regular expressions are:

  • "c" (for a single character)
  • "." (for any character)
  • "[abc]" (character class)
  • "[^abc]" (negated character class)
  • "r*" (Kleene closure)
  • "r?" (zero or one)
  • "r+" (positive closure)
  • "pq" (concat)
  • "p|q" (alternation)
  • "p&q" (and)

Quick example

  • For example, to match "[abc]*a|." against "ccaab"
-- generate a RE for "[abc]*a|."
re1 = regex_ccl:new{ s = {a = true, b = true, c = true} }  
re2 = regex_rep:new{ r = re1 }  
re3 = regex_lit:new{ c = 'a' }  
re4 = regex_seq:new{ p = re2, q = re3 }  
re5 = regex_any:new{}  
re  = regex_alt:new{ p = re4, q = re5 }  

-- match the RE against "ccaab"
print( match(re, "ccaab") )

glushkov-algorithm-in-lua's People

Contributors

dzchoi avatar

Watchers

James Cloos 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.