Project

alan

0.0
No commit activity in last 3 years
No release in over 3 years
DSL for creating and running different automations
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
 Dependencies

Development

~> 1.3
>= 0
 Project Readme

Alan

Alan is a simple DSL for creating and running different automations. Currently a finite state machine and a deterministic pushdown automata is available. A program in the fsm or the dpa language is also a ruby program and can be run from the command-line, supply the word to process as a command-line argument.

Installation

$ gem install alan

Usage

Example 1: A fsm

# example1.rb
require 'alan'

# Accept a*ba+
Alan::FSM.define do
  start :s
  
  state :s do |x|
    if x == 'a'
      goto :s
    elsif x == 'b'
      goto :p
    end
  end
  
  state :p do |x|
    if x == 'a'
      goto :q
    end
  end
      
  state :q do |x|
    if x == 'a'
      goto :q
    elsif x == nil
      accept
    end
  end
end

Example run: ruby example1.rb aaaaba

Example 2: A dpa

# example2.rb
require 'alan'
    
# Accept 0^n 1^n
Alan::DPA.define do
  start :s
  
  state :s do |x|
    if x == '0'
      push 'Z'
      goto :s
    elsif x == '1'
      y = pop
      if y == 'Z'
        goto :q
      end
    end
  end
  
  state :q do |x|
    y = pop
    if x == '1' && y == 'Z'
      goto :q
    elsif x == nil && y == nil
      accept
    end
  end
end

Example run: ruby example2.rb 00001111