ascode 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/ascode/functions.csv +2 -0
- data/lib/ascode/functions.rb +26 -0
- data/lib/ascode/interpreter.rb +10 -2
- data/lib/ascode/parser.rb +13 -2
- data/lib/ascode.rb +1 -1
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6d5613388e1c1d1ed16df6f3a7dffc7cda13942828766e128686657c1c79e516
|
4
|
+
data.tar.gz: deea5d3e304c6b0a57e2f644d19fe403a48d4b0a97eaf939591de46a470267f8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 81de49c8a02e3168dda1eea4fad57da817a925ccf1db0b259e3e286cedba9a446a7383a6cc42e6aa7c9843670f66b2ec81a213d28623cc3ad8443a7c2cd2878e
|
7
|
+
data.tar.gz: b1ab700a996cab9d82f1bf3b42ea4569eebee10340a37a468c195fa6c2f2374a9fe886d51a618ea0753f7e202d220ff39b5de21ed105cc50158c205ff11f439f
|
@@ -0,0 +1,26 @@
|
|
1
|
+
module Ascode
|
2
|
+
class Functions
|
3
|
+
attr_reader :csv_data
|
4
|
+
|
5
|
+
def initialize
|
6
|
+
@csv_data = []
|
7
|
+
read_csv
|
8
|
+
end
|
9
|
+
|
10
|
+
def read_csv
|
11
|
+
file = File.open('ascode/functions.csv', 'r')
|
12
|
+
|
13
|
+
until (line = file.gets).nil?
|
14
|
+
src = line.strip.split(',')
|
15
|
+
data = { short: src[0], long: src[1],
|
16
|
+
pop: src[2], push: src[3],
|
17
|
+
desc: src[4] }
|
18
|
+
|
19
|
+
@csv_data.push data
|
20
|
+
end
|
21
|
+
|
22
|
+
file.close
|
23
|
+
@csv_data.delete_at 0
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
data/lib/ascode/interpreter.rb
CHANGED
@@ -2,11 +2,19 @@ module Ascode
|
|
2
2
|
class Interpreter
|
3
3
|
def initialize(ast)
|
4
4
|
@ast = ast
|
5
|
+
|
6
|
+
@stack = []
|
5
7
|
end
|
6
8
|
|
7
9
|
def run
|
8
|
-
|
9
|
-
|
10
|
+
@ast.each do |action|
|
11
|
+
name = action[:action]
|
12
|
+
send(name)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
def output
|
17
|
+
puts @stack.pop
|
10
18
|
end
|
11
19
|
end
|
12
20
|
end
|
data/lib/ascode/parser.rb
CHANGED
@@ -1,14 +1,25 @@
|
|
1
|
+
require_relative 'functions'
|
2
|
+
|
1
3
|
module Ascode
|
2
4
|
class Parser
|
3
5
|
def initialize(code)
|
6
|
+
@fun = Functions.new
|
4
7
|
@code = code
|
5
8
|
end
|
6
9
|
|
7
10
|
def parse
|
11
|
+
ast = []
|
8
12
|
@code.split('').to_enum.each do |char|
|
9
|
-
|
10
|
-
|
13
|
+
name = (@fun.csv_data.each { |value| value[:short] == char })[0]
|
14
|
+
data = {
|
15
|
+
action: name[:long]
|
16
|
+
# TODO: also add :what (when 'push')
|
17
|
+
}
|
18
|
+
|
19
|
+
ast.push data
|
11
20
|
end
|
21
|
+
|
22
|
+
ast
|
12
23
|
end
|
13
24
|
end
|
14
25
|
end
|
data/lib/ascode.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ascode
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Artem Varaksa
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-01-
|
11
|
+
date: 2018-01-13 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description:
|
14
14
|
email:
|
@@ -19,6 +19,8 @@ files:
|
|
19
19
|
- LICENSE.md
|
20
20
|
- README.md
|
21
21
|
- lib/ascode.rb
|
22
|
+
- lib/ascode/functions.csv
|
23
|
+
- lib/ascode/functions.rb
|
22
24
|
- lib/ascode/interpreter.rb
|
23
25
|
- lib/ascode/parser.rb
|
24
26
|
homepage: https://github.com/sudoio/ascode
|