alan 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: ca3577036be5423cfaf0b645727252b483c84989
4
+ data.tar.gz: aa9560d6af65aaccd0c62b875e02055545f014fa
5
+ SHA512:
6
+ metadata.gz: d0cfb6bc533d5edbec2434d8cc47ec905b1768084643910113130dc647d49581609e6a60b53cd1e052b63e0aa6aa291549f463634fbe022d545da8c9f2f6dbf0
7
+ data.tar.gz: 625d25d82e00a3e02513258e10f3b0a09748705486ab29f32d814660de1f9a1c980e771f9c014b87d8feebc65f1c31b06ae09ca4d9e90bdcba426dbabbef8eeb
data/Gemfile ADDED
@@ -0,0 +1,2 @@
1
+ source 'https://rubygems.org'
2
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Mikael Konutgan
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,80 @@
1
+ # Alan
2
+
3
+ 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.
4
+
5
+ ## Installation
6
+
7
+ $ gem install alan
8
+
9
+ ## Usage
10
+
11
+ ### Example 1: A fsm
12
+
13
+ ```ruby
14
+ # example1.rb
15
+ require 'alan'
16
+
17
+ # Accept a*ba+
18
+ Alan::FSM.define do
19
+ start :s
20
+
21
+ state :s do |x|
22
+ if x == 'a'
23
+ goto :s
24
+ elsif x == 'b'
25
+ goto :p
26
+ end
27
+ end
28
+
29
+ state :p do |x|
30
+ if x == 'a'
31
+ goto :q
32
+ end
33
+ end
34
+
35
+ state :q do |x|
36
+ if x == 'a'
37
+ goto :q
38
+ elsif x == nil
39
+ accept
40
+ end
41
+ end
42
+ end
43
+ ```
44
+
45
+ Example run: `ruby example1.rb aaaaba`
46
+
47
+ ### Example 2: A dpa
48
+
49
+ ```ruby
50
+ # example2.rb
51
+ require 'alan'
52
+
53
+ # Accept 0^n 1^n
54
+ Alan::DPA.define do
55
+ start :s
56
+
57
+ state :s do |x|
58
+ if x == '0'
59
+ push 'Z'
60
+ goto :s
61
+ elsif x == '1'
62
+ y = pop
63
+ if y == 'Z'
64
+ goto :q
65
+ end
66
+ end
67
+ end
68
+
69
+ state :q do |x|
70
+ y = pop
71
+ if x == '1' && y == 'Z'
72
+ goto :q
73
+ elsif x == nil && y == nil
74
+ accept
75
+ end
76
+ end
77
+ end
78
+ ```
79
+
80
+ Example run: `ruby example2.rb 00001111`
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,23 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'alan/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "alan"
8
+ spec.version = Alan::VERSION
9
+ spec.authors = ["Mikael Konutgan"]
10
+ spec.email = ["mkonutgan@gmail.com"]
11
+ spec.description = %q{DSL for creating and running different automations}
12
+ spec.summary = %q{DSL for creating and running different automations}
13
+ spec.homepage = ''
14
+ spec.license = 'MIT'
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ['lib']
20
+
21
+ spec.add_development_dependency 'bundler', '~> 1.3'
22
+ spec.add_development_dependency 'rake'
23
+ end
@@ -0,0 +1,6 @@
1
+ require 'alan/version'
2
+ require 'alan/fsm'
3
+ require 'alan/dpa'
4
+
5
+ module Alan
6
+ end
@@ -0,0 +1,16 @@
1
+ module Alan
2
+ class DPA < FSM
3
+ def initialize
4
+ super
5
+ @stack = []
6
+ end
7
+
8
+ def push(s)
9
+ @stack.push s
10
+ end
11
+
12
+ def pop
13
+ @stack.pop
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,51 @@
1
+ module Alan
2
+ class FSM
3
+ def self.define(&block)
4
+ word = ARGV.first
5
+ unless word
6
+ puts 'Error: You must enter a word to process'
7
+ exit 1
8
+ end
9
+
10
+ fsm = new
11
+ fsm.instance_eval &block
12
+ fsm.run(word)
13
+ end
14
+
15
+ def initialize
16
+ @states = {}
17
+ end
18
+
19
+ def next_symbol
20
+ @symbols.shift
21
+ end
22
+
23
+ def start(s)
24
+ @initial_state = s
25
+ end
26
+
27
+ def state(s, &block)
28
+ @states[s] = block
29
+ end
30
+
31
+ def goto(s)
32
+ @states[s].call(next_symbol)
33
+ reject
34
+ end
35
+
36
+ def run(symbols)
37
+ @symbols = symbols.chars.to_a
38
+ goto @initial_state
39
+ end
40
+
41
+ def accept
42
+ puts 'ACCEPTED'
43
+ exit 0
44
+ end
45
+
46
+ def reject
47
+ puts 'REJECTED'
48
+ exit 0
49
+ end
50
+ end
51
+ end
@@ -0,0 +1,3 @@
1
+ module Alan
2
+ VERSION = '0.0.1'
3
+ end
metadata ADDED
@@ -0,0 +1,82 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: alan
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Mikael Konutgan
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-06-02 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: '1.3'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '1.3'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ description: DSL for creating and running different automations
42
+ email:
43
+ - mkonutgan@gmail.com
44
+ executables: []
45
+ extensions: []
46
+ extra_rdoc_files: []
47
+ files:
48
+ - Gemfile
49
+ - LICENSE.txt
50
+ - README.md
51
+ - Rakefile
52
+ - alan.gemspec
53
+ - lib/alan.rb
54
+ - lib/alan/dpa.rb
55
+ - lib/alan/fsm.rb
56
+ - lib/alan/version.rb
57
+ homepage: ''
58
+ licenses:
59
+ - MIT
60
+ metadata: {}
61
+ post_install_message:
62
+ rdoc_options: []
63
+ require_paths:
64
+ - lib
65
+ required_ruby_version: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - '>='
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ required_rubygems_version: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - '>='
73
+ - !ruby/object:Gem::Version
74
+ version: '0'
75
+ requirements: []
76
+ rubyforge_project:
77
+ rubygems_version: 2.0.3
78
+ signing_key:
79
+ specification_version: 4
80
+ summary: DSL for creating and running different automations
81
+ test_files: []
82
+ has_rdoc: