theta 0.1.1 → 0.1.2
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.
- data/README.rdoc +1 -1
- data/VERSION +1 -1
- data/lib/theta/interpreter.rb +3 -3
- data/lib/theta/library/equality.scm +11 -0
- data/lib/theta/library/greater_than.scm +13 -0
- data/lib/theta/library/greater_than_or_equal.scm +13 -0
- data/lib/theta/library/if.scm +13 -0
- data/lib/theta/library/less_than.scm +13 -0
- data/lib/theta/library/less_than_or_equal.scm +13 -0
- data/lib/theta/library/set.scm +10 -0
- data/lib/theta/parser.rb +13 -0
- data/lib/theta.rb +7 -4
- data/theta.gemspec +8 -1
- metadata +17 -10
data/README.rdoc
CHANGED
@@ -19,6 +19,6 @@ After installation, simply type theta to get to the interactive interpreter prom
|
|
19
19
|
theta> (square 3)
|
20
20
|
9
|
21
21
|
|
22
|
-
To exit, simply
|
22
|
+
To exit, simply type 'exit' at the prompt.
|
23
23
|
|
24
24
|
It's a little low on features currently, but I'll be adding more eventually!
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.1.
|
1
|
+
0.1.2
|
data/lib/theta/interpreter.rb
CHANGED
@@ -22,10 +22,10 @@ module Theta
|
|
22
22
|
end
|
23
23
|
end
|
24
24
|
|
25
|
-
# run
|
25
|
+
# run some code
|
26
26
|
def run(program)
|
27
|
-
|
28
|
-
return evaluate(
|
27
|
+
expression = parse(program)
|
28
|
+
return evaluate(expression)
|
29
29
|
end
|
30
30
|
|
31
31
|
# call the parser to make a string interpretable
|
@@ -0,0 +1,13 @@
|
|
1
|
+
(define >
|
2
|
+
(ruby_func "
|
3
|
+
lambda { |arguments, interpreter|
|
4
|
+
args_to_compare = arguments[1, arguments.length]
|
5
|
+
args_to_compare.each do |arg|
|
6
|
+
if not interpreter.evaluate(arguments[0]) > interpreter.evaluate(arg)
|
7
|
+
return false
|
8
|
+
end
|
9
|
+
end
|
10
|
+
return true
|
11
|
+
}
|
12
|
+
")
|
13
|
+
)
|
@@ -0,0 +1,13 @@
|
|
1
|
+
(define >=
|
2
|
+
(ruby_func "
|
3
|
+
lambda { |arguments, interpreter|
|
4
|
+
args_to_compare = arguments[1, arguments.length]
|
5
|
+
args_to_compare.each do |arg|
|
6
|
+
if not interpreter.evaluate(arguments[0]) >= interpreter.evaluate(arg)
|
7
|
+
return false
|
8
|
+
end
|
9
|
+
end
|
10
|
+
return true
|
11
|
+
}
|
12
|
+
")
|
13
|
+
)
|
@@ -0,0 +1,13 @@
|
|
1
|
+
(define <
|
2
|
+
(ruby_func "
|
3
|
+
lambda { |arguments, interpreter|
|
4
|
+
args_to_compare = arguments[1, arguments.length]
|
5
|
+
args_to_compare.each do |arg|
|
6
|
+
if not interpreter.evaluate(arguments[0]) < interpreter.evaluate(arg)
|
7
|
+
return false
|
8
|
+
end
|
9
|
+
end
|
10
|
+
return true
|
11
|
+
}
|
12
|
+
")
|
13
|
+
)
|
@@ -0,0 +1,13 @@
|
|
1
|
+
(define <=
|
2
|
+
(ruby_func "
|
3
|
+
lambda { |arguments, interpreter|
|
4
|
+
args_to_compare = arguments[1, arguments.length]
|
5
|
+
args_to_compare.each do |arg|
|
6
|
+
if not interpreter.evaluate(arguments[0]) <= interpreter.evaluate(arg)
|
7
|
+
return false
|
8
|
+
end
|
9
|
+
end
|
10
|
+
return true
|
11
|
+
}
|
12
|
+
")
|
13
|
+
)
|
@@ -0,0 +1,10 @@
|
|
1
|
+
(define set!
|
2
|
+
(ruby_func "
|
3
|
+
lambda { |arguments, interpreter|
|
4
|
+
if interpreter.current_environment.find(arguments[0]).nil?
|
5
|
+
raise 'Variable ' + arguments[0] + ' is undefined'
|
6
|
+
end
|
7
|
+
interpreter.current_environment.define(arguments[0], arguments[1])
|
8
|
+
}
|
9
|
+
")
|
10
|
+
)
|
data/lib/theta/parser.rb
CHANGED
@@ -12,7 +12,11 @@ module Theta
|
|
12
12
|
tokens = []
|
13
13
|
found_string = false
|
14
14
|
temp = ""
|
15
|
+
# loop through each character passed
|
15
16
|
string.each_char do |char|
|
17
|
+
# if we're currently in a string and we hit the quote,
|
18
|
+
# it's the end of the string.
|
19
|
+
# move the string into the token array
|
16
20
|
if found_string
|
17
21
|
if char == "\""
|
18
22
|
found_string = false
|
@@ -21,10 +25,13 @@ module Theta
|
|
21
25
|
tokens << temp
|
22
26
|
end
|
23
27
|
temp = ""
|
28
|
+
# otherwise add the character to the temporary variable
|
24
29
|
else
|
25
30
|
temp << char
|
26
31
|
end
|
27
32
|
else
|
33
|
+
# if we hit parentheses, add whatever's in temp as a token
|
34
|
+
# then add the parentheses as a token
|
28
35
|
if char == "(" || char == ")"
|
29
36
|
if not temp.empty?
|
30
37
|
tokens << temp
|
@@ -32,19 +39,25 @@ module Theta
|
|
32
39
|
end
|
33
40
|
tokens << char
|
34
41
|
next
|
42
|
+
# if we hit a quote, we're beginning a string
|
43
|
+
# flip the found_string flag and begin adding to the temp variable
|
35
44
|
elsif char == "\""
|
36
45
|
found_string = true
|
37
46
|
temp << char
|
47
|
+
# space signals the end of a token, push the temp variable on the token queue
|
38
48
|
elsif char == " "
|
39
49
|
if not temp.empty?
|
40
50
|
tokens << temp
|
41
51
|
end
|
42
52
|
temp = ""
|
53
|
+
# ignore tabs or newlines, unless there's something in temp
|
54
|
+
# push that onto tokens
|
43
55
|
elsif char == "\t" || char == "\n"
|
44
56
|
if not temp.empty?
|
45
57
|
tokens << temp
|
46
58
|
end
|
47
59
|
temp = ""
|
60
|
+
# add the character to temp to build a token
|
48
61
|
else
|
49
62
|
temp << char
|
50
63
|
end
|
data/lib/theta.rb
CHANGED
@@ -20,11 +20,14 @@ module Theta
|
|
20
20
|
def repl
|
21
21
|
while true
|
22
22
|
print "theta> "
|
23
|
-
input =
|
24
|
-
input.strip
|
25
|
-
if input
|
23
|
+
input = ""
|
24
|
+
input << gets.strip
|
25
|
+
if input == "exit"
|
26
26
|
puts "Exiting..."
|
27
|
-
|
27
|
+
return
|
28
|
+
end
|
29
|
+
if input.empty?
|
30
|
+
next
|
28
31
|
end
|
29
32
|
value = @interpreter.run(input)
|
30
33
|
unless value.nil?
|
data/theta.gemspec
CHANGED
@@ -5,7 +5,7 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{theta}
|
8
|
-
s.version = "0.1.
|
8
|
+
s.version = "0.1.2"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Chris O'Neal"]
|
@@ -31,8 +31,15 @@ Gem::Specification.new do |s|
|
|
31
31
|
"lib/theta/interpreter.rb",
|
32
32
|
"lib/theta/library/add.scm",
|
33
33
|
"lib/theta/library/divide.scm",
|
34
|
+
"lib/theta/library/equality.scm",
|
35
|
+
"lib/theta/library/greater_than.scm",
|
36
|
+
"lib/theta/library/greater_than_or_equal.scm",
|
37
|
+
"lib/theta/library/if.scm",
|
34
38
|
"lib/theta/library/lambda.scm",
|
39
|
+
"lib/theta/library/less_than.scm",
|
40
|
+
"lib/theta/library/less_than_or_equal.scm",
|
35
41
|
"lib/theta/library/multiply.scm",
|
42
|
+
"lib/theta/library/set.scm",
|
36
43
|
"lib/theta/library/subtract.scm",
|
37
44
|
"lib/theta/parser.rb",
|
38
45
|
"test/helper.rb",
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: theta
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -14,7 +14,7 @@ default_executable:
|
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: shoulda
|
17
|
-
requirement: &
|
17
|
+
requirement: &9485220 !ruby/object:Gem::Requirement
|
18
18
|
none: false
|
19
19
|
requirements:
|
20
20
|
- - ! '>='
|
@@ -22,10 +22,10 @@ dependencies:
|
|
22
22
|
version: '0'
|
23
23
|
type: :development
|
24
24
|
prerelease: false
|
25
|
-
version_requirements: *
|
25
|
+
version_requirements: *9485220
|
26
26
|
- !ruby/object:Gem::Dependency
|
27
27
|
name: bundler
|
28
|
-
requirement: &
|
28
|
+
requirement: &9484644 !ruby/object:Gem::Requirement
|
29
29
|
none: false
|
30
30
|
requirements:
|
31
31
|
- - ~>
|
@@ -33,10 +33,10 @@ dependencies:
|
|
33
33
|
version: 1.0.0
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
|
-
version_requirements: *
|
36
|
+
version_requirements: *9484644
|
37
37
|
- !ruby/object:Gem::Dependency
|
38
38
|
name: jeweler
|
39
|
-
requirement: &
|
39
|
+
requirement: &9483744 !ruby/object:Gem::Requirement
|
40
40
|
none: false
|
41
41
|
requirements:
|
42
42
|
- - ~>
|
@@ -44,10 +44,10 @@ dependencies:
|
|
44
44
|
version: 1.5.2
|
45
45
|
type: :development
|
46
46
|
prerelease: false
|
47
|
-
version_requirements: *
|
47
|
+
version_requirements: *9483744
|
48
48
|
- !ruby/object:Gem::Dependency
|
49
49
|
name: rcov
|
50
|
-
requirement: &
|
50
|
+
requirement: &9483072 !ruby/object:Gem::Requirement
|
51
51
|
none: false
|
52
52
|
requirements:
|
53
53
|
- - ! '>='
|
@@ -55,7 +55,7 @@ dependencies:
|
|
55
55
|
version: '0'
|
56
56
|
type: :development
|
57
57
|
prerelease: false
|
58
|
-
version_requirements: *
|
58
|
+
version_requirements: *9483072
|
59
59
|
description: Theta was created as a learning project based off of lis.py and flea
|
60
60
|
email: ctoneal@gmail.com
|
61
61
|
executables:
|
@@ -79,8 +79,15 @@ files:
|
|
79
79
|
- lib/theta/interpreter.rb
|
80
80
|
- lib/theta/library/add.scm
|
81
81
|
- lib/theta/library/divide.scm
|
82
|
+
- lib/theta/library/equality.scm
|
83
|
+
- lib/theta/library/greater_than.scm
|
84
|
+
- lib/theta/library/greater_than_or_equal.scm
|
85
|
+
- lib/theta/library/if.scm
|
82
86
|
- lib/theta/library/lambda.scm
|
87
|
+
- lib/theta/library/less_than.scm
|
88
|
+
- lib/theta/library/less_than_or_equal.scm
|
83
89
|
- lib/theta/library/multiply.scm
|
90
|
+
- lib/theta/library/set.scm
|
84
91
|
- lib/theta/library/subtract.scm
|
85
92
|
- lib/theta/parser.rb
|
86
93
|
- test/helper.rb
|
@@ -101,7 +108,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
101
108
|
version: '0'
|
102
109
|
segments:
|
103
110
|
- 0
|
104
|
-
hash:
|
111
|
+
hash: -933902079
|
105
112
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
106
113
|
none: false
|
107
114
|
requirements:
|